Commit e441cb71 authored by Neil Schemenauer's avatar Neil Schemenauer

Issue #1754094: Improve the stack depth calculation in the compiler.

There should be no other effect than a small decrease in memory use.
parent 46afef33
...@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 1? ...@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
- Issue #7065: Fix a crash in bytes.maketrans and bytearray.maketrans when - Issue #7065: Fix a crash in bytes.maketrans and bytearray.maketrans when
using byte values greater than 127. Patch by egreen. using byte values greater than 127. Patch by egreen.
......
...@@ -772,7 +772,7 @@ opcode_stack_effect(int opcode, int oparg) ...@@ -772,7 +772,7 @@ opcode_stack_effect(int opcode, int oparg)
case UNPACK_EX: case UNPACK_EX:
return (oparg&0xFF) + (oparg>>8); return (oparg&0xFF) + (oparg>>8);
case FOR_ITER: case FOR_ITER:
return 1; return 1; /* or -1, at end of iterator */
case STORE_ATTR: case STORE_ATTR:
return -2; return -2;
...@@ -799,7 +799,7 @@ opcode_stack_effect(int opcode, int oparg) ...@@ -799,7 +799,7 @@ opcode_stack_effect(int opcode, int oparg)
case COMPARE_OP: case COMPARE_OP:
return -1; return -1;
case IMPORT_NAME: case IMPORT_NAME:
return 0; return -1;
case IMPORT_FROM: case IMPORT_FROM:
return 1; return 1;
...@@ -3546,7 +3546,7 @@ dfs(struct compiler *c, basicblock *b, struct assembler *a) ...@@ -3546,7 +3546,7 @@ dfs(struct compiler *c, basicblock *b, struct assembler *a)
static int static int
stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth) stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
{ {
int i; int i, target_depth;
struct instr *instr; struct instr *instr;
if (b->b_seen || b->b_startdepth >= depth) if (b->b_seen || b->b_startdepth >= depth)
return maxdepth; return maxdepth;
...@@ -3559,8 +3559,17 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth) ...@@ -3559,8 +3559,17 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
maxdepth = depth; maxdepth = depth;
assert(depth >= 0); /* invalid code or bug in stackdepth() */ assert(depth >= 0); /* invalid code or bug in stackdepth() */
if (instr->i_jrel || instr->i_jabs) { if (instr->i_jrel || instr->i_jabs) {
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) {
target_depth = depth+3;
if (target_depth > maxdepth)
maxdepth = target_depth;
}
maxdepth = stackdepth_walk(c, instr->i_target, maxdepth = stackdepth_walk(c, instr->i_target,
depth, maxdepth); target_depth, maxdepth);
if (instr->i_opcode == JUMP_ABSOLUTE || if (instr->i_opcode == JUMP_ABSOLUTE ||
instr->i_opcode == JUMP_FORWARD) { instr->i_opcode == JUMP_FORWARD) {
goto out; /* remaining code is dead */ goto out; /* remaining code is dead */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment