Skip to content

gh-131798: Split _CHECK_AND_ALLOCATE_OBJECT into smaller uops#148433

Draft
Sacul0457 wants to merge 3 commits intopython:mainfrom
Sacul0457:Split-_CHECK_AND_ALLOCATE_OBJECT
Draft

gh-131798: Split _CHECK_AND_ALLOCATE_OBJECT into smaller uops#148433
Sacul0457 wants to merge 3 commits intopython:mainfrom
Sacul0457:Split-_CHECK_AND_ALLOCATE_OBJECT

Conversation

@Sacul0457
Copy link
Copy Markdown
Contributor

@Sacul0457 Sacul0457 commented Apr 12, 2026

@Sacul0457
Copy link
Copy Markdown
Contributor Author

Hey @Fidget-Spinner, I'm a little lost here
From my understanding:

  1. In _CHECK_OBJECT if tp->tp_version_tag == type_version is true, we remove the guard.
  2. Do we set callable to a const here like it currently does?
  3. If 1. is false, we need to add a type watcher.

assert(init != NULL);
assert(PyFunction_Check(init));
callable = sym_new_const(ctx, init);
sym_set_const(callable, init);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This should go into the new _ALLOCATE_OBJECT
  2. It should be callable = sym_new_const(ctx, init); not sym_set_const(callable, init);. There's a difference --- the first overrides the current callable with a new one, the second sets the current callable to a known constant. If you read the code in bytecodes.c, you'll see it's the first one.

// type watcher, as we do not remove this _CHECK_AND_ALLOCATE_OBJECT guard.
// TODO: split up _CHECK_AND_ALLOCATE_OBJECT to the check then alloate, so we can
// eliminate the check.
if (sym_is_not_null(self_or_null) && sym_matches_type(callable, &PyType_Type)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure self_or_null is null like bytecodes.c

Suggested change
if (sym_is_not_null(self_or_null) && sym_matches_type(callable, &PyType_Type)) {
if (sym_is_null(self_or_null) && sym_matches_type(callable, &PyType_Type)) {

PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
_Py_BloomFilter_Add(dependencies, type);
}
}
Copy link
Copy Markdown
Member

@cocolato cocolato Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same to bytecodes.c:

Suggested change
}
}
self_or_null = sym_new_not_null(ctx);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants