-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-128682: Stronger checking of PyStackRef_CLOSE
and DEAD
.
#128683
Conversation
DEAD
and DECREF_INPUTS
PyStackRef_CLOSE
and DEAD
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression was that, rather than enforcing a closing order, we would instead have the code generator insert NULL
assignments to the stack where necessary. I vaguely remember situations where that would be really useful, such as when pushing or popping multiple stack items that are created or freed in the "wrong order", or where overlapping lifetimes would force us to convert things to heap references (and back again) to move things around on the stack.
Are we abandoning that idea, or is this a step towards that?
(Either way, the code in this PR seems correct.)
int total_args = oparg; | ||
_PyStackRef *arguments = args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning behind this alias? I see we do this in a couple of places now...
If the reasoning is that the analysis chokes on array accesses, maybe we should teach it to ignore them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We modify arguments
, but the code generator assumes that args
is a fixed array on the stack.
@@ -116,7 +116,7 @@ def __init__(self, out: CWriter): | |||
"SAVE_STACK": self.save_stack, | |||
"RELOAD_STACK": self.reload_stack, | |||
"PyStackRef_CLOSE": self.stackref_close, | |||
"PyStackRef_CLOSE_SPECIALIZED": self.stackref_close, | |||
"PyStackRef_CLOSE_SPECIALIZED": self.stackref_close_no_escape, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to have this one "inherit" it's escaping-ness from its second arg? I could see us adding something for tuples or whatever and breaking this by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
That only applies when several references are removed from the stack at once, by If references are popped individually, they must be popped in the right order. |
Stronger checking of the stack state for
PyStackRef_CLOSE
. Only allow references to be closed from top to bottom, to ensure stack is valid when closing a reference.Fix up bytecodes.c accordingly.