8000 gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher by saulshanabrook · Pull Request #119365 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher #119365

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e7b7d5d
Add type version and offset to optimizer header
saulshanabrook May 20, 2024
c902276
Start adding type version
saulshanabrook May 20, 2024
89e3649
Add type version functions and struct initialization
saulshanabrook May 20, 2024
b8525be
fix typo
saulshanabrook May 20, 2024
4bd1608
Add failing test case
saulshanabrook May 20, 2024
ddbfd94
breakpoints and prints
dpdani May 20, 2024
f22130b
Add function definitions
saulshanabrook May 20, 2024
77bc293
wooohoooo
dpdani May 20, 2024
a2ebc49
unprint
dpdani May 20, 2024
e982837
Remove generated printf
saulshanabrook May 20, 2024
0e7e7eb
Remove test breakpoints
saulshanabrook May 20, 2024
4060ab8
📜🤖 Added by blurb_it.
blurb-it[bot] May 20, 2024
1520928
Revert "📜🤖 Added by blurb_it."
saulshanabrook May 20, 2024
5e0792b
Use global type watcher to invalidate type versions
saulshanabrook May 21, 2024
fd979f0
Revert formatting changes to tests
saulshanabrook May 21, 2024
5da1a40
Add additional test
saulshanabrook May 21, 2024
84860ea
Remove printf and make slightly more threadsafe
saulshanabrook May 21, 2024
c12bb90
fix typo
saulshanabrook May 21, 2024
53ab262
Update type watcher ID in test bc we know have a default one at 0
saulshanabrook May 22, 2024
88e2e59
Fix panic and add test for it
saulshanabrook May 22, 2024
1eabca9
add manual cast
saulshanabrook May 22, 2024
1f7cc74
Properly fixed the frame creation with discussion with Ken Jin
saulshanabrook May 22, 2024
f892ea7
Change type_assign_specific_version_unsafe to use safe setting
saulshanabrook May 23, 2024
06ed18f
📜🤖 Added by blurb_it.
blurb-it[bot] May 23, 2024
1343571
Fix more places where tp_version_tag is being set manually
brandtbucher May 23, 2024
2ee5126
Merge branch 'main' into optimizer-type-version-watcher
brandtbucher May 23, 2024
37aeea5
_PyType_ClearCodeByVersion isn't necessary
brandtbucher May 23, 2024
9d6171d
Merge branch 'main' into optimizer-type-version-watcher
Fidget-Spinner May 28, 2024
545c40b
Merge branch 'main' into optimizer-type-version-watcher
saulshanabrook May 29, 2024
c4436eb
Rename typ_version to type_version
saulshanabrook Jun 4, 2024
0d0c647
Change type of type_version to unsigned int
saulshanabrook Jun 4, 2024
9b80acb
C formatting fix
saulshanabrook Jun 4, 2024
6ddb1e7
Rephrase test names
saulshanabrook Jun 4, 2024
9d3f914
Rephrase comments
saulshanabrook Jun 4, 2024
3e0a1e7
Make existing inline test clear
saulshanabrook Jun 4, 2024
3420a42
Add a test for escaping behavior, but allow it to fail for now
saulshanabrook Jun 4, 2024
6886b36
Verify that expected type version is non zero
saulshanabrook Jun 4, 2024
376bb5e
Fix typo
saulshanabrook Jun 4, 2024
e025cc7
Assert pytype watch never errors
saulshanabrook Jun 4, 2024
88f2d89
Fix assertion
saulshanabrook Jun 4, 2024
82bc177
Remove unnecessary assert
saulshanabrook Jun 4, 2024
bdf0a4a
Handle if type versions are different
saulshanabrook Jun 7, 2024
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
Prev Previous commit
Next Next commit
Change type_assign_specific_version_unsafe to use safe setting
We need to move type_assign_specific_version_unsafe to a different module
so we can use the private API to set the type version now, so it tracks
cleanup
  • Loading branch information
saulshanabrook committed May 23, 2024
commit f892ea738072f73e25a44a814eedbcf22a548b72
3 changes: 2 additions & 1 deletion Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

# Skip this test if the _testcapi module isn't available.
_testcapi = import_helper.import_module("_testcapi")
_testinternalcapi = import_helper.import_module("_testinternalcapi")
type_get_version = _testcapi.type_get_version
type_assign_specific_version_unsafe = _testcapi.type_assign_specific_version_unsafe
type_assign_specific_version_unsafe = _testinternalcapi.type_assign_specific_version_unsafe
type_assign_version = _testcapi.type_assign_version
type_modified = _testcapi.type_modified

Expand Down
17 changes: 0 additions & 17 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2395,21 +2395,6 @@ type_modified(PyObject *self, PyObject *type)
Py_RETURN_NONE;
}

// Circumvents standard version assignment machinery - use with caution and only on
// short-lived heap types
static PyObject *
type_assign_specific_version_unsafe(PyObject *self, PyObject *args)
{
PyTypeObject *type;
unsigned int version;
if (!PyArg_ParseTuple(args, "Oi:type_assign_specific_version_unsafe", &type, &version)) {
return NULL;
}
assert(!PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE));
type->tp_version_tag = version;
type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
Py_RETURN_NONE;
}

static PyObject *
type_assign_version(PyObject *self, PyObject *type)
Expand Down Expand Up @@ -3418,8 +3403,6 @@ static PyMethodDef TestMethods[] = {
{"test_py_is_funcs", test_py_is_funcs, METH_NOARGS},
{"type_get_version", type_get_version, METH_O, PyDoc_STR("type->tp_version_tag")},
{"type_modified", type_modified, METH_O, PyDoc_STR("PyType_Modified")},
{"type_assign_specific_version_unsafe", type_assign_specific_version_unsafe, METH_VARARGS,
PyDoc_STR("forcefully assign type->tp_version_tag")},
{"type_assign_version", type_assign_version, METH_O, PyDoc_STR("PyUnstable_Type_AssignVersionTag")},
{"type_get_tp_bases", type_get_tp_bases, METH_O},
{"type_get_tp_mro", type_get_tp_mro, METH_O},
Expand Down
20 changes: 20 additions & 0 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,23 @@ has_inline_values(PyObject *self, PyObject *obj)
Py_RETURN_FALSE;
}


// Circumvents standard version assignment machinery - use with caution and only on
// short-lived heap types
static PyObject *
type_assign_specific_version_unsafe(PyObject *self, PyObject *args)
{
PyTypeObject *type;
unsigned int version;
if (!PyArg_ParseTuple(args, "Oi:type_assign_specific_version_unsafe", &type, &version)) {
return NULL;
}
assert(!PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE));
_PyType_SetVersion(type, version);
type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
Py_RETURN_NONE;
}

static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
Expand Down Expand Up @@ -2088,6 +2105,9 @@ static PyMethodDef module_functions[] = {
{"get_rare_event_counters", get_rare_event_counters, METH_NOARGS},
{"reset_rare_event_counters", reset_rare_event_counters, METH_NOARGS},
{"has_inline_values", has_inline_values, METH_O},
{"type_assign_specific_version_unsafe", type_assign_specific_version_unsafe, METH_VARARGS,
PyDoc_STR("forcefully assign type->tp_version_tag")},

#ifdef Py_GIL_DISABLED
{"py_thread_id", get_py_thread_id, METH_NOARGS},
#endif
Expand Down
0