-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify dynamic bytecode loading by having the runtime append RETURN 1 #12430
Simplify dynamic bytecode loading by having the runtime append RETURN 1 #12430
Conversation
abf17fe
to
1078abd
Compare
While working on #11996 I did encounter these bits of code. What I did
there was to factorize the patching of the bytecode done in Dynlink and
in the toplevel so that the patching function was shared, but the
solution proposed here definitely looks better than the one proposed
there so I joyfully approved this PR.
@stedolan when you will be updating the Changes entry, could you please
take this opportunity to also squash the two commits?
After that I think this will be ready to be merged.
|
Stephen Dolan (2023/07/26 03:55 -0700):
[*] actually this was done by only two of the three callers. The third
now gets a redundant `RETURN 1`, but an extra bytecode instruction
that's never executed isn't harmful.
If we wanted to, I am assuming we could also give `reify_bytecode` a
parameter to saywhether we want the RETURN 1 to be added or not, or some
variation of that.
|
1078abd
to
2bccae4
Compare
Removing the redundant return should be a simple matter of changing |
I think this is correct, and I would be happier with this PR if this was done, so that the "contract" for |
2bccae4
to
f9edd42
Compare
I agree this sounds better, but sadly turned out not to be correct because of some trickiness with how toplevel codegen worked. I refactored the toplevel slightly until this became correct, then applied the suggested change. (In principle, the most recent commit is "just" removing the |
If I understand correctly the new patch:
I think this PR also includes a change to the initial stack size for toplevel phrases from 1 to 0; this looks harmless at first glance but I wouldn't mind some confirmation. |
That summary is correct, thanks.
Well spotted! This change was accidental, I've reverted it. (I don't know why toplevel phrases specify 1 here, though) |
@lthls Are you happy with the current version? |
Yes, I am. |
There is a function
Meta.reify_bytecode
which is used to turn a sequence of bytecode instructions into a callable closure, used by the toplevel and by Dynlink. To do this, the bytecode sequence needs to end in aRETURN 1
instruction.Currently, this
RETURN 1
instruction is added by the caller ofreify_bytecode
[*]. This patch makesreify_bytecode
do this step instead. This seems cleaner, as it removes hardcoded binary strings from the callers ofreify_bytecode
, who need no longer care about endianness / opcode numbering, in particular removing a dependency fromDynlink
toOpcodes
. (The runtime now has to do this, but the runtime must already care about such things).[*] actually this was done by only two of the three callers. The third now gets a redundant
RETURN 1
, but an extra bytecode instruction that's never executed isn't harmful.cc @shindere