Skip to content

Commit 565507e

Browse files
committed
gh-148380: revert _GUARD_TYPE_VERSION
1 parent a65ab7c commit 565507e

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Python/optimizer_bytecodes.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,19 @@ dummy_func(void) {
236236
if (sym_matches_type_version(owner, type_version)) {
237237
ADD_OP(_NOP, 0, 0);
238238
} else {
239-
PyTypeObject *probable_type = sym_get_probable_type(owner);
240-
if (probable_type->tp_version_tag == type_version && sym_set_type_version(owner, type_version)) {
241-
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)probable_type);
242-
_Py_BloomFilter_Add(dependencies, probable_type);
239+
// add watcher so that whenever the type changes we invalidate this
240+
PyTypeObject *type = _PyType_LookupByVersion(type_version);
241+
// if the type is null, it was not found in the cache (there was a conflict)
242+
// with the key, in which case we can't trust the version
243+
if (type) {
244+
// if the type version was set properly, then add a watcher
245+
// if it wasn't this means that the type version was previously set to something else
246+
// and we set the owner to bottom, so we don't need to add a watcher because we must have
247+
// already added one earlier.
248+
if (sym_set_type_version(owner, type_version)) {
249+
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
250+
_Py_BloomFilter_Add(dependencies, type);
251+
}
243252
}
244253
}
245254
}

Python/optimizer_cases.c.h

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)