[Python-ideas] Bytecode JIT
victor.stinner at gmail.com
Mon Jul 3 07:48:12 EDT 2017
2017-07-02 14:13 GMT+02:00 Steven D'Aprano <steve at pearwood.info>:
> That only solves the problem of mysum being modified, not whether the
> arguments are ints. You still need to know whether it is safe to call
> some low-level (fast) integer addition routine, or whether you have to
> go through the (slow) high-level Python code.
> In any case, guards are a kind of runtime check. It might not be an
> explicit isinstance() check, but it is logically implies one. If x was
> an int, and nothing has changed, then x is still an int.
> If Victor is around, he might like to comment on how his FAT Python
> handles this.
FAT Python design is generic, you are free to implement any kind of
check. A check is an object which provides a C callback.
FAT Python provides the following guards:
About "mysym being modified", it's handled by this guard:
Right now, only the func.__code__ is watched. It's not enought, but
it's a compromise to keep my implementation simple :-)
Tomorrow, if FAT Python becomes a real thing, the builtin function
type can be modified to add a version as we have for dictionaries, and
the version will be increased for any function modification: argument
defaults, arguments, name, etc.
We would only have to modify GuardFunc implementation, not users of this guard.
To really respect the Python semantics, guards became more complex
than expected. GuardBuiltins doesn't only check that len() is still
the same function in builtins. It only has to the globals name of the
current frame, globals()[name] and builtins of the current frame.
Python allows crazy stuff like running a single function with custom
builtin functions: see exec() function.
More information about the Python-ideas