-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-98831: Update generate_cases.py: register inst, opcode_metadata.h #100735
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
Conversation
(These aren't used yet, but may be coming soon, and it's easier to keep this tool the same between branches.)
Python/opcode_metadata.h
Outdated
[BINARY_OP] = { 2, 1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[SWAP] = { -1, -1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[EXTENDED_ARG] = { -1, -1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[CACHE] = { -1, -1, DIR_NONE, DIR_NONE, DIR_NONE }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
END_FOR is missing, I think we need something to handle macros.
Also, note that missing entries default to 0. Would be safer if they defaulted to -1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that missing entries default to 0. Would be safer if they defaulted to -1.
The code generator doesn't know the numeric values of the opcodes (yet) so it doesn't have enough info to generate explicit entries filled with -1
for missing values. The best we can do is add an additional flag valid_entry
.
Python/opcode_metadata.h
Outdated
[GET_AWAITABLE] = { 1, 1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[SEND] = { -1, -1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[ASYNC_GEN_WRAP] = { 1, 1, DIR_NONE, DIR_NONE, DIR_NONE }, | ||
[YIELD_VALUE] = { 1, 0, DIR_NONE, DIR_NONE, DIR_NONE }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stack_effect of YIELD_VALUE is 0. Why is it here 1 popped, 0 pushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be a bug in bytecodes.c. The code ends with goto resume_frame
so the push sequence at the end is never executed. I can fix it by making the IO effect (retval -- retval)
(indicating that it doesn't change) or perhaps (retval -- unused)
, indicating that we don't write it here. I presume it's written in some weird way when the frame is resumed.
This is the sanity check I used to find those two issues: --- a/Python/compile.c
+++ b/Python/compile.c
@@ -8854,6 +8854,26 @@ assemble(struct compiler *c, int addNone)
assert(no_redundant_jumps(g));
+ for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
+ for (int j = 0; j < b->b_iused; j++) {
+ struct instr *instr = &b->b_instr[j];
+ int opcode = instr->i_opcode;
+ assert(opcode < 256);
+ int pushed = _PyOpcode_opcode_metadata[opcode].n_pushed;
+ int popped = _PyOpcode_opcode_metadata[opcode].n_popped;
+ if (pushed >= 0 && popped >= 0) {
+ int oparg = instr->i_oparg;
+ int effect = stack_effect(opcode, oparg, -1);
+ if (effect != pushed-popped) {
+ fprintf(stderr, "opcode = %d oparg = %d effect = %d pushed = %d popped = %d\n",
+ opcode, oparg, effect, pushed, popped);
+ }
+ assert(effect == pushed-popped);
+ }
+ }
+ }
+
+
|
Maybe we should include that in the code as a helper function and call it in an |
|
|
|
|
|
|
|
|
Have to revert, see #100777 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bot failures fixed by #100778 |
(These aren't used yet, but may be coming soon,
and it's easier to keep this tool the same between branches.)