mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
gh-115999: Add free-threaded specialization for CONTAINS_OP (gh-126450)
- The specialization logic determines the appropriate specialization using only the operand's type, which is safe to read non-atomically (changing it requires stopping the world). We are guaranteed that the type will not change in between when it is checked and when we specialize the bytecode because the types involved are immutable (you cannot assign to `__class__` for exact instances of `dict`, `set`, or `frozenset`). The bytecode is mutated atomically using helpers. - The specialized instructions rely on the operand type not changing in between the `DEOPT_IF` checks and the calls to the appropriate type-specific helpers (e.g. `_PySet_Contains`). This is a correctness requirement in the default builds and there are no changes to the opcodes in the free-threaded builds that would invalidate this.
This commit is contained in:
parent
a204c63919
commit
4ea214ea98
4 changed files with 29 additions and 6 deletions
|
@ -1335,6 +1335,27 @@ class DisTests(DisTestBase):
|
|||
got = self.get_disassembly(co, adaptive=True)
|
||||
self.do_disassembly_compare(got, call_quicken)
|
||||
|
||||
@cpython_only
|
||||
@requires_specialization_ft
|
||||
def test_contains_specialize(self):
|
||||
contains_op_quicken = """\
|
||||
0 RESUME_CHECK 0
|
||||
|
||||
1 LOAD_NAME 0 (a)
|
||||
LOAD_NAME 1 (b)
|
||||
%s
|
||||
RETURN_VALUE
|
||||
"""
|
||||
co_dict = compile('a in b', "<dict>", "eval")
|
||||
self.code_quicken(lambda: exec(co_dict, {}, {'a': 1, 'b': {1: 5}}))
|
||||
got = self.get_disassembly(co_dict, adaptive=True)
|
||||
self.do_disassembly_compare(got, contains_op_quicken % "CONTAINS_OP_DICT 0 (in)")
|
||||
|
||||
co_set = compile('a in b', "<set>", "eval")
|
||||
self.code_quicken(lambda: exec(co_set, {}, {'a': 1.0, 'b': {1, 2, 3}}))
|
||||
got = self.get_disassembly(co_set, adaptive=True)
|
||||
self.do_disassembly_compare(got, contains_op_quicken % "CONTAINS_OP_SET 0 (in)")
|
||||
|
||||
@cpython_only
|
||||
@requires_specialization
|
||||
def test_loop_quicken(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue