summaryrefslogtreecommitdiffstats
path: root/Python/codegen.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-01-23 09:26:25 (GMT)
committerGitHub <noreply@github.com>2025-01-23 09:26:25 (GMT)
commita10f99375e7912df863cf101a38e9703cfcd72f1 (patch)
tree7909c7896fe256427c1149d2416fb7912ad3ba48 /Python/codegen.c
parentd7d066c3ab6842117f9e0fb1c9dde4bce00fa1e3 (diff)
downloadcpython-a10f99375e7912df863cf101a38e9703cfcd72f1.zip
cpython-a10f99375e7912df863cf101a38e9703cfcd72f1.tar.gz
cpython-a10f99375e7912df863cf101a38e9703cfcd72f1.tar.bz2
Revert "GH-128914: Remove conditional stack effects from `bytecodes.c` and the code generators (GH-128918)" (GH-129202)
The commit introduced a ~2.5-3% regression in the free threading build. This reverts commit ab61d3f4303d14a413bc9ae6557c730ffdf7579e.
Diffstat (limited to 'Python/codegen.c')
-rw-r--r--Python/codegen.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index b3f8455..61707ba 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -348,6 +348,8 @@ codegen_addop_o(compiler *c, location loc,
RETURN_IF_ERROR_IN_SCOPE((C), ret); \
} while (0)
+#define LOAD_METHOD -1
+#define LOAD_SUPER_METHOD -2
#define LOAD_ZERO_SUPER_ATTR -3
#define LOAD_ZERO_SUPER_METHOD -4
@@ -364,11 +366,20 @@ codegen_addop_name(compiler *c, location loc,
if (arg < 0) {
return ERROR;
}
+ if (opcode == LOAD_ATTR) {
+ arg <<= 1;
+ }
+ if (opcode == LOAD_METHOD) {
+ opcode = LOAD_ATTR;
+ arg <<= 1;
+ arg |= 1;
+ }
if (opcode == LOAD_SUPER_ATTR) {
arg <<= 2;
arg |= 2;
}
if (opcode == LOAD_SUPER_METHOD) {
+ opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 3;
}
@@ -377,7 +388,7 @@ codegen_addop_name(compiler *c, location loc,
arg <<= 2;
}
if (opcode == LOAD_ZERO_SUPER_METHOD) {
- opcode = LOAD_SUPER_METHOD;
+ opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 1;
}
@@ -3154,6 +3165,9 @@ codegen_nameop(compiler *c, location loc,
assert(op);
Py_DECREF(mangled);
+ if (op == LOAD_GLOBAL) {
+ arg <<= 1;
+ }
ADDOP_I(c, loc, op, arg);
return SUCCESS;
@@ -4094,10 +4108,7 @@ ex_call:
}
assert(have_dict);
}
- if (nkwelts == 0) {
- ADDOP(c, loc, PUSH_NULL);
- }
- ADDOP(c, loc, CALL_FUNCTION_EX);
+ ADDOP_I(c, loc, CALL_FUNCTION_EX, nkwelts > 0);
return SUCCESS;
}
@@ -4830,10 +4841,8 @@ codegen_async_with(compiler *c, stmt_ty s, int pos)
SETUP_WITH E
<code to store to VAR> or POP_TOP
<code for BLOCK>
- LOAD_CONST None
- LOAD_CONST None
- LOAD_CONST None
- CALL 3
+ LOAD_CONST (None, None, None)
+ CALL_FUNCTION_EX 0
JUMP EXIT
E: WITH_EXCEPT_START (calls EXPR.__exit__)
POP_JUMP_IF_TRUE T: