Thanks to visit codestin.com
Credit goes to github.com

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
Prev Previous commit
Next Next commit
handle probable and non-probable cases
  • Loading branch information
Fidget-Spinner committed Apr 12, 2026
commit 13e2608def0f8385d5056fce8bb6c7c0f301e638
47 changes: 23 additions & 24 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,40 +1071,39 @@ dummy_func(void) {
op(_CHECK_OBJECT, (type_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
PyObject *probable_callable = sym_get_probable_value(callable);
assert(probable_callable != NULL);
PyTypeObject *tp = (PyTypeObject *)probable_callable;
if (tp->tp_version_tag == type_version) {
// If the type version has not changed since we last saw it,
// then we know this __init__ is definitely the same one as in the cache.
// We can promote callable to a known constant. This does not need a
// type watcher, as we do not remove this _CHECK_AND_ALLOCATE_OBJECT guard.
if (sym_is_null(self_or_null) && sym_matches_type(callable, &PyType_Type)) {
PyObject *const_callable = sym_get_const(ctx, callable);
bool is_probable = const_callable == NULL && probable_callable != NULL;
PyObject *callable_o = const_callable != NULL ? const_callable : probable_callable;
if (sym_is_null(self_or_null) &&
callable_o != NULL &&
PyType_Check(callable_o) &&
((PyTypeObject *)callable_o)->tp_version_tag == type_version) {
// Probable types need the guard.
if (!is_probable) {
ADD_OP(_NOP, 0, 0);
}
PyHeapTypeObject *cls = (PyHeapTypeObject *)probable_callable;
else {
// Promote the probable type, as we have
// guarded on it.
sym_set_const(callable, callable_o);
}
PyHeapTypeObject *cls = (PyHeapTypeObject *)callable_o;
PyObject *init = cls->_spec_cache.init;
assert(init != NULL);
assert(PyFunction_Check(init));
sym_set_const(callable, init);
callable = sym_new_const(ctx, init);
PyType_Watch(TYPE_WATCHER_ID, callable_o);
_Py_BloomFilter_Add(dependencies, callable_o);;
}
else {
// add watcher so that whenever the type changes we invalidate this
PyTypeObject *type = _PyType_LookupByVersion(type_version);
// if the type is null, it was not found in the cache (there was a conflict)
// with the key, in which case we can't trust the version
if (type) {
// if the type version was set properly, then add a watcher
// if it wasn't this means that the type version was previously set to something else
// and we set the callable to bottom, so we don't need to add a watcher because we must have
// already added one earlier.
if (sym_set_type_version(callable, type_version)) {
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
_Py_BloomFilter_Add(dependencies, type);
}
}
self_or_null = sym_new_not_null(ctx);
callable = sym_new_not_null(ctx);
}
}

op(_ALLOCATE_OBJECT, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
self_or_null = sym_new_not_null(ctx);
}

op(_CREATE_INIT_FRAME, (init, self, args[oparg] -- init_frame)) {
ctx->frame->stack_pointer = stack_pointer - oparg - 2;
_Py_UOpsAbstractFrame *shim = frame_new(ctx, (PyCodeObject *)&_Py_InitCleanup, NULL, 0);
Expand Down
34 changes: 22 additions & 12 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading