-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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-93143: Don't turn LOAD_FAST
into LOAD_FAST_CHECK
#99075
Conversation
I can look closer this evening, but mutating co_code is not ideal, so I think this is probably a good idea. |
There are two cases when we need to set locals to
In the first case we can set the local to However when jumping, trying to decide which locals need to be set to |
I've updated the code to skip scanning the bytecode for |
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.
👍
This feels safer and more robust than what we have now.
@@ -0,0 +1,4 @@ | |||
Rather than changing :attr:`~types.CodeType.co_code`, the interpreter will | |||
now display a :exc:`RuntimeWarning` and assign :const:`None` to any fast | |||
locals that are incorrectly left unbound after jumps or :keyword:`del` |
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.
There aren't necessarily incorrect, so maybe just "locals that are unbound after ..."
Objects/frameobject.c
Outdated
PyErr_WriteUnraisable((PyObject *)frame->frame_obj); | ||
} | ||
value = Py_NewRef(Py_None); | ||
} | ||
Py_XINCREF(value); |
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.
Py_XINCREF(value); | |
Py_INCREF(value); |
When you're done making the requested changes, leave the comment: |
The compiler's dataflow analysis for fast locals can be invalidated by jumps or deletions while tracing. When this happens, rather than changing
co_code
(which users assume to be constant) to use the less-efficientLOAD_FAST_CHECK
everywhere, just display aRuntimeWarning
and set any problematic locals toNone
instead.