Skip to content
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-115709: Invalidate executors when a local variable is changed via frame.f_locals #118639

Merged
merged 5 commits into from
May 6, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented May 6, 2024

Skipping news as this is fixing a hypothetical bug, rather than a reported bug.

The new test causes a C assertion failure in a debug build of main.

@markshannon markshannon changed the title GH-115709: Invlidate executors when a local variable in changed via frame.f_locals GH-115709: Invalidate executors when a local variable in changed via frame.f_locals May 6, 2024
@markshannon markshannon changed the title GH-115709: Invalidate executors when a local variable in changed via frame.f_locals GH-115709: Invalidate executors when a local variable is changed via frame.f_locals May 6, 2024
@markshannon markshannon requested a review from gvanrossum as a code owner May 6, 2024 11:05
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this isn't incorrect I'm not super happy with the inconsistency of sometimes #ifdefing out the call and other times relying on the dummy version existing. But this works, so do what's expedient to make it into beta 1.

Comment on lines +2427 to +2429
if (_PyOpcode_Caches[_PyOpcode_Deopt[opcode]]) {
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it connect to the purpose of the PR? Or is it just a drive-by bugfix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unconnected.
This PR uncovered the bug, so I'll need to fix it before merging this. Might as well do it here.

@@ -148,8 +148,9 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
if (PyUnicode_CheckExact(key)) {
int i = framelocalsproxy_getkeyindex(frame, key, false);
if (i >= 0) {
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
_Py_Executors_InvalidateDependency(PyInterpreterState_Get(), co, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I solved the _Py_TIER2 dependency elsewhere is to put this call itself inside #ifdef _Py_TIER2. Then you don't need the dummy version you added to optimizer.c.

#else

void
_Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is_invalidation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super keen on having a dummy version here -- and if we do this we should probably make a few more dummy versions and remove the occasional #if _Py_TIER2 sprinkled around elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer this in optimizer.h

#else
#define _Py_Executors_InvalidateDependency(A, B, C) ((void)0)
#endif _Py_TIER2

and leave optimizer.c alone?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's better. Though if this is what Brandt asks about maybe we should split it and put that bugfix in beta1 even if the f_locals bugfix goes to beta2.

@brandtbucher
Copy link
Member

Is this the same failure that we're seeing on GH-118661?

Assertion failed: instruction->op.code == ENTER_EXECUTOR, file C:\Users\brandtbucher\cpython\Python\optimizer.c, line 1610

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will merge this ASAP since CI is currently broken and this fixes it.

@gvanrossum gvanrossum enabled auto-merge (squash) May 6, 2024 20:45
@gvanrossum gvanrossum merged commit 616b745 into python:main May 6, 2024
51 of 52 checks passed
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
…d via frame.f_locals (python#118639)

Also fix unrelated assert in debug Tier2/JIT builds.
@markshannon markshannon deleted the invalidate_on_flocals_change branch August 6, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants