gh-143732: add specialization for FOR_ITER (GH-148745)

This commit is contained in:
Neko Asakura 2026-05-05 00:29:10 +08:00 committed by GitHub
parent 952784af47
commit 9846407eaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 1569 additions and 1176 deletions

View file

@ -1452,6 +1452,28 @@ dummy_func(void) {
}
}
op(_FOR_ITER_TIER_TWO, (iter, null_or_index -- iter, null_or_index, next)) {
bool definite = true;
PyTypeObject *type = sym_get_type(iter);
if (type == NULL) {
type = sym_get_probable_type(iter);
definite = false;
}
if (type != NULL && type != &PyGen_Type && type->tp_iternext != NULL) {
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
_Py_BloomFilter_Add(dependencies, type);
if (!definite) {
sym_set_type(iter, type);
assert((this_instr - 1)->opcode == _RECORD_NOS_TYPE);
int32_t orig_target = (this_instr - 1)->target;
ADD_OP(_GUARD_TYPE_ITER, 0, (uintptr_t)type);
uop_buffer_last(&ctx->out_buffer)->target = orig_target;
}
ADD_OP(_ITER_NEXT_INLINE, 0, (uintptr_t)type->tp_iternext);
}
next = sym_new_not_null(ctx);
}
op(_GUARD_ITERATOR, (iterable -- iterable)) {
bool definite = true;
PyTypeObject *tp = sym_get_type(iterable);