gh-141367: Use CALL_LIST_APPEND instruction only for lists, not for list subclasses (GH-141398)

Co-authored-by: Ken Jin <kenjin4096@gmail.com>
This commit is contained in:
Mikhail Efimov 2025-11-15 00:38:39 +03:00 committed by GitHub
parent f26ed455d5
commit 1281be1caf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 44 additions and 20 deletions

View file

@ -1872,6 +1872,33 @@ def for_iter_generator():
self.assert_specialized(for_iter_generator, "FOR_ITER_GEN")
self.assert_no_opcode(for_iter_generator, "FOR_ITER")
@cpython_only
@requires_specialization_ft
def test_call_list_append(self):
# gh-141367: only exact lists should use
# CALL_LIST_APPEND instruction after specialization.
r = range(_testinternalcapi.SPECIALIZATION_THRESHOLD)
def list_append(l):
for _ in r:
l.append(1)
list_append([])
self.assert_specialized(list_append, "CALL_LIST_APPEND")
self.assert_no_opcode(list_append, "CALL_METHOD_DESCRIPTOR_O")
self.assert_no_opcode(list_append, "CALL")
def my_list_append(l):
for _ in r:
l.append(1)
class MyList(list): pass
my_list_append(MyList())
self.assert_specialized(my_list_append, "CALL_METHOD_DESCRIPTOR_O")
self.assert_no_opcode(my_list_append, "CALL_LIST_APPEND")
self.assert_no_opcode(my_list_append, "CALL")
if __name__ == "__main__":
unittest.main()