gh-143732: allow dict subclasses to be specialized (GH-148128)

This commit is contained in:
Kumar Aditya
2026-05-04 14:09:03 +05:30
committed by GitHub
parent de1769f700
commit 5847931d11
15 changed files with 461 additions and 206 deletions
+35 -7
View File
@@ -2166,17 +2166,45 @@ dummy_func(void) {
}
}
op(_GUARD_NOS_DICT, (nos, unused -- nos, unused)) {
if (sym_matches_type(nos, &PyDict_Type)) {
ADD_OP(_NOP, 0, 0);
op(_GUARD_NOS_DICT_SUBSCRIPT, (nos, unused -- nos, unused)) {
PyTypeObject *tp = sym_get_type(nos);
bool definite = true;
if (!tp) {
tp = sym_get_probable_type(nos);
definite = false;
}
if (tp && tp->tp_as_mapping &&
tp->tp_as_mapping->mp_subscript == _PyDict_Subscript) {
if (definite) {
ADD_OP(_NOP, 0, 0);
}
else {
ADD_OP(_GUARD_TYPE, 0, (uintptr_t)tp);
sym_set_type(nos, tp);
}
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)tp);
_Py_BloomFilter_Add(dependencies, tp);
}
sym_set_type(nos, &PyDict_Type);
}
op(_GUARD_NOS_ANY_DICT, (nos, unused -- nos, unused)) {
op(_GUARD_NOS_DICT_STORE_SUBSCRIPT, (unused, nos, unused -- unused, nos, unused)) {
PyTypeObject *tp = sym_get_type(nos);
if (tp == &PyDict_Type || tp == &PyFrozenDict_Type) {
ADD_OP(_NOP, 0, 0);
bool definite = true;
if (!tp) {
tp = sym_get_probable_type(nos);
definite = false;
}
if (tp && tp->tp_as_mapping &&
tp->tp_as_mapping->mp_ass_subscript == _PyDict_StoreSubscript) {
if (definite) {
ADD_OP(_NOP, 0, 0);
}
else {
ADD_OP(_GUARD_TYPE, 0, (uintptr_t)tp);
sym_set_type(nos, tp);
}
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)tp);
_Py_BloomFilter_Add(dependencies, tp);
}
}