Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Invlidate executors when a local variable in changed via frame.f_locals
  • Loading branch information
markshannon committed May 6, 2024
commit 2e43f75c0975aa3b7f66f0a42762888f795808eb
13 changes: 13 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,5 +1321,18 @@ def testfunc(n):
self.assertIsNotNone(ex)
self.assertIn("_FOR_ITER_GEN_FRAME", get_opnames(ex))

def test_modified_local_is_seen_by_optimized_code(self):
l = sys._getframe().f_locals
a = 1
s = 0
for j in range(1 << 10):
a + a
l["xa"[j >> 9]] = 1.0
s += a
self.assertIs(type(a), float)
self.assertIs(type(s), float)
self.assertEqual(s, 1024.0)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ framelocalsproxy_setitem(PyObject *self, PyObject *key, PyObject *value)
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);
PyObject *oldvalue = fast[i];
PyObject *cell = NULL;
if (kind == CO_FAST_FREE) {
Expand Down