summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-05-23 11:47:32 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2014-05-23 11:47:32 +0200
commita2acbea2044cce4b87d305070e1b6cefaa49fe43 (patch)
tree1a23fa49a85fc4a403d402abad2cd579e1e03574 /Python/compile.c
parent68fc0e460efbfc7ee734117bc1f10c1af0c7785d (diff)
parent5fee46c5717b4d9d86cdbe10252195a1989d4313 (diff)
downloadcpython-a2acbea2044cce4b87d305070e1b6cefaa49fe43.tar.gz
Issue #21523: Fix over-pessimistic computation of the stack effect of some opcodes in the compiler.
This also fixes a quadratic compilation time issue noticeable when compiling code with a large number of "and" and "or" operators.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 9d3646eb91..9cc13995ef 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3862,12 +3862,16 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
target_depth = depth;
if (instr->i_opcode == FOR_ITER) {
target_depth = depth-2;
- } else if (instr->i_opcode == SETUP_FINALLY ||
- instr->i_opcode == SETUP_EXCEPT) {
+ }
+ else if (instr->i_opcode == SETUP_FINALLY ||
+ instr->i_opcode == SETUP_EXCEPT) {
target_depth = depth+3;
if (target_depth > maxdepth)
maxdepth = target_depth;
}
+ else if (instr->i_opcode == JUMP_IF_TRUE_OR_POP ||
+ instr->i_opcode == JUMP_IF_FALSE_OR_POP)
+ depth = depth - 1;
maxdepth = stackdepth_walk(c, instr->i_target,
target_depth, maxdepth);
if (instr->i_opcode == JUMP_ABSOLUTE ||