Skip to content

Commit 19f90d6

Browse files
authored
gh-98831: add variable stack effect support to cases generator (#101309)
1 parent a178ba8 commit 19f90d6

File tree

3 files changed

+924
-194
lines changed

3 files changed

+924
-194
lines changed

Python/compile.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
3737
#include "pycore_symtable.h" // PySTEntryObject
3838

39-
#include "opcode_metadata.h" // _PyOpcode_opcode_metadata
39+
#include "opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed
4040

4141

4242
#define DEFAULT_BLOCK_SIZE 16
@@ -8651,13 +8651,15 @@ no_redundant_jumps(cfg_builder *g) {
86518651

86528652
static bool
86538653
opcode_metadata_is_sane(cfg_builder *g) {
8654+
bool result = true;
86548655
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
86558656
for (int i = 0; i < b->b_iused; i++) {
86568657
struct instr *instr = &b->b_instr[i];
86578658
int opcode = instr->i_opcode;
8659+
int oparg = instr->i_oparg;
86588660
assert(opcode <= MAX_REAL_OPCODE);
8659-
int pushed = _PyOpcode_opcode_metadata[opcode].n_pushed;
8660-
int popped = _PyOpcode_opcode_metadata[opcode].n_popped;
8661+
int popped = _PyOpcode_num_popped(opcode, oparg);
8662+
int pushed = _PyOpcode_num_pushed(opcode, oparg);
86618663
assert((pushed < 0) == (popped < 0));
86628664
if (pushed >= 0) {
86638665
assert(_PyOpcode_opcode_metadata[opcode].valid_entry);
@@ -8666,12 +8668,12 @@ opcode_metadata_is_sane(cfg_builder *g) {
86668668
fprintf(stderr,
86678669
"op=%d: stack_effect (%d) != pushed (%d) - popped (%d)\n",
86688670
opcode, effect, pushed, popped);
8669-
return false;
8671+
result = false;
86708672
}
86718673
}
86728674
}
86738675
}
8674-
return true;
8676+
return result;
86758677
}
86768678

86778679
static bool

0 commit comments

Comments
 (0)