summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-10-07 13:56:39 (GMT)
committerGitHub <noreply@github.com>2024-10-07 13:56:39 (GMT)
commitda071fa3e8e01e0cacf13d632aae0835a2203eb2 (patch)
treeebd70c16c871dee470785be5aed0bccbb1e3cbaf /Python/optimizer_bytecodes.c
parentcda3b5a576412a8671bbe4c68bb792ec14f1a4b1 (diff)
downloadcpython-da071fa3e8e01e0cacf13d632aae0835a2203eb2.zip
cpython-da071fa3e8e01e0cacf13d632aae0835a2203eb2.tar.gz
cpython-da071fa3e8e01e0cacf13d632aae0835a2203eb2.tar.bz2
GH-119866: Spill the stack around escaping calls. (GH-124392)
* Spill the evaluation around escaping calls in the generated interpreter and JIT. * The code generator tracks live, cached values so they can be saved to memory when needed. * Spills the stack pointer around escaping calls, so that the exact stack is visible to the cycle GC.
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index bf8f075..c73b632 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -182,7 +182,9 @@ dummy_func(void) {
res = sym_new_type(ctx, &PyFloat_Type);
}
}
- res = sym_new_unknown(ctx);
+ else {
+ res = sym_new_unknown(ctx);
+ }
}
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
@@ -448,8 +450,10 @@ dummy_func(void) {
top = bottom;
}
- op(_SWAP, (bottom, unused[oparg-2], top --
- top, unused[oparg-2], bottom)) {
+ op(_SWAP, (bottom_in, unused[oparg-2], top_in --
+ top_out, unused[oparg-2], bottom_out)) {
+ bottom_out = bottom_in;
+ top_out = top_in;
}
op(_LOAD_ATTR_INSTANCE_VALUE, (offset/1, owner -- attr, null if (oparg & 1))) {
@@ -479,9 +483,7 @@ dummy_func(void) {
op(_LOAD_ATTR, (owner -- attr, self_or_null if (oparg & 1))) {
(void)owner;
attr = sym_new_not_null(ctx);
- if (oparg & 1) {
- self_or_null = sym_new_unknown(ctx);
- }
+ self_or_null = sym_new_unknown(ctx);
}
op(_LOAD_ATTR_MODULE, (index/1, owner -- attr, null if (oparg & 1))) {
@@ -570,7 +572,6 @@ dummy_func(void) {
op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
int argcount = oparg;
-
(void)callable;
PyCodeObject *co = NULL;
@@ -647,11 +648,10 @@ dummy_func(void) {
}
op(_RETURN_VALUE, (retval -- res)) {
- SYNC_SP();
+ SAVE_STACK();
ctx->frame->stack_pointer = stack_pointer;
frame_pop(ctx);
stack_pointer = ctx->frame->stack_pointer;
- res = retval;
/* Stack space handling */
assert(corresponding_check_stack == NULL);
@@ -666,6 +666,8 @@ dummy_func(void) {
// might be impossible, but bailing is still safe
ctx->done = true;
}
+ RELOAD_STACK();
+ res = retval;
}
op(_RETURN_GENERATOR, ( -- res)) {