setting attribute of JitHookInterface instance

Hi, I’m attempting to use the JitHookInterface to implement something like the PyPy JIT hooks in pycket. However, I’m struggling to do anything other than print information to stdout. From what I understand in pypy, the pypyjit.hooks.pypy_hooks object is instantiated, and then after the ObjSpace is initialised, it is assigned to pypy_hooks.space in setup_after_space_initialization. In my case, when I assign anything to an attribute of my JitHookInterface instance, translation blows up with [translation:ERROR] MissingRTypeAttribute: on_abort [translation:ERROR] .. (rpython.jit.metainterp.pyjitpl:2224)MetaInterp.aborted_tracing [translation:ERROR] .. block@59 with 2 exits(v1678) [translation:ERROR] .. v1680 = getattr(v1679, ('on_abort')) If any pycket people are reading this, what I’m trying to do at the moment is give a JitHookInterface instance access to the module table somehow. Copying the pypy JIT hooks approach is not strictly necessary - I’d be happy with being able to update anything from within a JitHookInterface callback which could then be accessed by application level code. Obviously, my understanding of what’s going on here is lacking somewhat. If anyone could point me in the correct general direction, I’d be very grateful. Best regards, Magnus

Hi Magnus, On 15 March 2016 at 03:32, Magnus Morton <m@magnusmorton.com> wrote:
[translation:ERROR] MissingRTypeAttribute: on_abort [translation:ERROR] .. (rpython.jit.metainterp.pyjitpl:2224)MetaInterp.aborted_tracing [translation:ERROR] .. block@59 with 2 exits(v1678) [translation:ERROR] .. v1680 = getattr(v1679, ('on_abort'))
This says that 'on_abort' is not found. Are you sure you have, like pypy/module/pypyjit/hooks.py, written a JitHookInterface subclass which provides all the same 'on_*' methods? A bientôt, Armin.

Hi Amin, Yes, it has all the methods defined. If I take out the assignment, but still define a JitPolicy with the hooks, it translates fine. Cheers, Magnus
On 15 Mar 2016, at 10:48, Armin Rigo <arigo@tunes.org> wrote:
Hi Magnus,
On 15 March 2016 at 03:32, Magnus Morton <m@magnusmorton.com> wrote:
[translation:ERROR] MissingRTypeAttribute: on_abort [translation:ERROR] .. (rpython.jit.metainterp.pyjitpl:2224)MetaInterp.aborted_tracing [translation:ERROR] .. block@59 with 2 exits(v1678) [translation:ERROR] .. v1680 = getattr(v1679, ('on_abort'))
This says that 'on_abort' is not found. Are you sure you have, like pypy/module/pypyjit/hooks.py, written a JitHookInterface subclass which provides all the same 'on_*' methods?
A bientôt,
Armin.

Hi Magnus, On 15 March 2016 at 15:45, Magnus Morton <m@magnusmorton.com> wrote:
Yes, it has all the methods defined. If I take out the assignment, but still define a JitPolicy with the hooks, it translates fine.
Can't help, I would need to reproduce the problem first. Please give step-by-step instructions about how to reach that error. Armin

Hi Armin, You can recreate it in PyPy by putting the following two lines pretty much anywhere in interpreter level code other than the setup_after_space_initialization methods from pypy.module.pypyjit.hooks import pypy_hooks pypy_hooks.foo = “foo” What I can’t understand is what is special about the setup_after_space_initialization methods that makes it work there. Cheers, Magnus
On 15 Mar 2016, at 15:32, Armin Rigo <arigo@tunes.org> wrote:
Hi Magnus,
On 15 March 2016 at 15:45, Magnus Morton <m@magnusmorton.com> wrote:
Yes, it has all the methods defined. If I take out the assignment, but still define a JitPolicy with the hooks, it translates fine.
Can't help, I would need to reproduce the problem first. Please give step-by-step instructions about how to reach that error.
Armin

Hi Magnus, On 16 March 2016 at 01:37, Magnus Morton <m@magnusmorton.com> wrote:
You can recreate it in PyPy by putting the following two lines pretty much anywhere in interpreter level code other than the setup_after_space_initialization methods
from pypy.module.pypyjit.hooks import pypy_hooks pypy_hooks.foo = “foo”
What I can’t understand is what is special about the setup_after_space_initialization methods that makes it work there.
Reproduced and figured it out. Added some docs in eda9fd6a0601: + # WARNING: You should make a single prebuilt instance of a subclass + # of this class. You can, before translation, initialize some + # attributes on this instance, and then read or change these + # attributes inside the methods of the subclass. But this prebuilt + # instance *must not* be seen during the normal annotation/rtyping + # of the program! A line like ``pypy_hooks.foo = ...`` must not + # appear inside your interpreter's RPython code. In PyPy, setup_after_space_initialization() is not RPython (which means it is executed before translation). A bientôt, Armin.

Hi Armin, Thanks for looking into this. Is this pre-translation code a general thing possible with any RPython based compiler, or is it very PyPy specific? Cheers, Magnus
On 16 Mar 2016, at 08:45, Armin Rigo <arigo@tunes.org> wrote:
Hi Magnus,
On 16 March 2016 at 01:37, Magnus Morton <m@magnusmorton.com> wrote:
You can recreate it in PyPy by putting the following two lines pretty much anywhere in interpreter level code other than the setup_after_space_initialization methods
from pypy.module.pypyjit.hooks import pypy_hooks pypy_hooks.foo = “foo”
What I can’t understand is what is special about the setup_after_space_initialization methods that makes it work there.
Reproduced and figured it out. Added some docs in eda9fd6a0601:
+ # WARNING: You should make a single prebuilt instance of a subclass + # of this class. You can, before translation, initialize some + # attributes on this instance, and then read or change these + # attributes inside the methods of the subclass. But this prebuilt + # instance *must not* be seen during the normal annotation/rtyping + # of the program! A line like ``pypy_hooks.foo = ...`` must not + # appear inside your interpreter's RPython code.
In PyPy, setup_after_space_initialization() is not RPython (which means it is executed before translation).
A bientôt,
Armin.

It's general. You can do whatever you like before runtime (during import time for example) as long as the presented world to rpython is static enough - in other words Python is a meta-programming language for RPython On Wed, Mar 16, 2016 at 1:34 PM, Magnus Morton <m@magnusmorton.com> wrote:
Hi Armin,
Thanks for looking into this. Is this pre-translation code a general thing possible with any RPython based compiler, or is it very PyPy specific?
Cheers, Magnus
On 16 Mar 2016, at 08:45, Armin Rigo <arigo@tunes.org> wrote:
Hi Magnus,
On 16 March 2016 at 01:37, Magnus Morton <m@magnusmorton.com> wrote:
You can recreate it in PyPy by putting the following two lines pretty much anywhere in interpreter level code other than the setup_after_space_initialization methods
from pypy.module.pypyjit.hooks import pypy_hooks pypy_hooks.foo = “foo”
What I can’t understand is what is special about the setup_after_space_initialization methods that makes it work there.
Reproduced and figured it out. Added some docs in eda9fd6a0601:
+ # WARNING: You should make a single prebuilt instance of a subclass + # of this class. You can, before translation, initialize some + # attributes on this instance, and then read or change these + # attributes inside the methods of the subclass. But this prebuilt + # instance *must not* be seen during the normal annotation/rtyping + # of the program! A line like ``pypy_hooks.foo = ...`` must not + # appear inside your interpreter's RPython code.
In PyPy, setup_after_space_initialization() is not RPython (which means it is executed before translation).
A bientôt,
Armin.
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
participants (3)
-
Armin Rigo
-
Maciej Fijalkowski
-
Magnus Morton