Skip to content

Commit 6ea3f8c

Browse files
authored
gh-144289: Remove ENABLE_SPECIALIZATION_FT (gh-144290)
Now that the specializing interpreter works with free threading, replace ENABLE_SPECIALIZATION_FT with ENABLE_SPECIALIZATION and replace requires_specialization_ft with requires_specialization. Also limit the uniquely referenced check to FOR_ITER_RANGE. It's not necessary for FOR_ITER_GEN and would cause test_for_iter_gen to fail.
1 parent 6b45381 commit 6ea3f8c

File tree

13 files changed

+166
-188
lines changed

13 files changed

+166
-188
lines changed

Include/internal/pycore_code.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,7 @@ extern int _PyCode_SafeAddr2Line(PyCodeObject *co, int addr);
292292
extern void _PyCode_Clear_Executors(PyCodeObject *code);
293293

294294

295-
#ifdef Py_GIL_DISABLED
296-
// gh-115999 tracks progress on addressing this.
297-
#define ENABLE_SPECIALIZATION 0
298-
// Use this to enable specialization families once they are thread-safe. All
299-
// uses will be replaced with ENABLE_SPECIALIZATION once all families are
300-
// thread-safe.
301-
#define ENABLE_SPECIALIZATION_FT 1
302-
#else
303295
#define ENABLE_SPECIALIZATION 1
304-
#define ENABLE_SPECIALIZATION_FT ENABLE_SPECIALIZATION
305-
#endif
306296

307297
/* Specialization functions, these are exported only for other re-generated
308298
* interpreters to call */

Lib/test/support/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,11 +1459,6 @@ def requires_specialization(test):
14591459
_opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
14601460

14611461

1462-
def requires_specialization_ft(test):
1463-
return unittest.skipUnless(
1464-
_opcode.ENABLE_SPECIALIZATION_FT, "requires specialization")(test)
1465-
1466-
14671462
def reset_code(f: types.FunctionType) -> types.FunctionType:
14681463
"""Clear all specializations, local instrumentation, and JIT code for the given function."""
14691464
f.__code__ = f.__code__.replace()

Lib/test/test_monitoring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import unittest
1313

1414
import test.support
15-
from test.support import import_helper, requires_specialization_ft, script_helper
15+
from test.support import import_helper, requires_specialization, script_helper
1616

1717
_testcapi = import_helper.import_module("_testcapi")
1818
_testinternalcapi = import_helper.import_module("_testinternalcapi")
@@ -1047,7 +1047,7 @@ def func():
10471047
)
10481048
self.assertEqual(events[0], ("throw", IndexError))
10491049

1050-
@requires_specialization_ft
1050+
@requires_specialization
10511051
def test_no_unwind_for_shim_frame(self):
10521052
class ValueErrorRaiser:
10531053
def __init__(self):

Lib/test/test_opcache.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import types
66
import unittest
77
from test.support import (threading_helper, check_impl_detail,
8-
requires_specialization, requires_specialization_ft,
8+
requires_specialization,
99
cpython_only, requires_jit_disabled, reset_code)
1010
from test.support.import_helper import import_module
1111

@@ -524,7 +524,7 @@ def f(x, y):
524524
f()
525525

526526
@requires_jit_disabled
527-
@requires_specialization_ft
527+
@requires_specialization
528528
def test_assign_init_code(self):
529529
class MyClass:
530530
def __init__(self):
@@ -547,7 +547,7 @@ def count_args(self, *args):
547547
instantiate()
548548

549549
@requires_jit_disabled
550-
@requires_specialization_ft
550+
@requires_specialization
551551
def test_push_init_frame_fails(self):
552552
def instantiate():
553553
return InitTakesArg()
@@ -576,7 +576,7 @@ def f():
576576
f()
577577

578578
@requires_jit_disabled
579-
@requires_specialization_ft
579+
@requires_specialization
580580
def test_specialize_call_function_ex_py(self):
581581
def ex_py(*args, **kwargs):
582582
return 1
@@ -592,7 +592,7 @@ def instantiate():
592592
self.assert_specialized(instantiate, "CALL_EX_PY")
593593

594594
@requires_jit_disabled
595-
@requires_specialization_ft
595+
@requires_specialization
596596
def test_specialize_call_function_ex_py_fail(self):
597597
def ex_py(*args, **kwargs):
598598
return 1
@@ -660,7 +660,7 @@ def assert_races_do_not_crash(
660660
for writer in writers:
661661
writer.join()
662662

663-
@requires_specialization_ft
663+
@requires_specialization
664664
def test_binary_subscr_getitem(self):
665665
def get_items():
666666
class C:
@@ -690,7 +690,7 @@ def write(items):
690690
opname = "BINARY_OP_SUBSCR_GETITEM"
691691
self.assert_races_do_not_crash(opname, get_items, read, write)
692692

693-
@requires_specialization_ft
693+
@requires_specialization
694694
def test_binary_subscr_list_int(self):
695695
def get_items():
696696
items = []
@@ -768,7 +768,7 @@ def write(items):
768768
opname = "FOR_ITER_LIST"
769769
self.assert_races_do_not_crash(opname, get_items, read, write)
770770

771-
@requires_specialization_ft
771+
@requires_specialization
772772
def test_load_attr_class(self):
773773
def get_items():
774774
class C:
@@ -798,7 +798,7 @@ def write(items):
798798
opname = "LOAD_ATTR_CLASS"
799799
self.assert_races_do_not_crash(opname, get_items, read, write)
800800

801-
@requires_specialization_ft
801+
@requires_specialization
802802
def test_load_attr_class_with_metaclass_check(self):
803803
def get_items():
804804
class Meta(type):
@@ -831,7 +831,7 @@ def write(items):
831831
opname = "LOAD_ATTR_CLASS_WITH_METACLASS_CHECK"
832832
self.assert_races_do_not_crash(opname, get_items, read, write)
833833

834-
@requires_specialization_ft
834+
@requires_specialization
835835
def test_load_attr_getattribute_overridden(self):
836836
def get_items():
837837
class C:
@@ -861,7 +861,7 @@ def write(items):
861861
opname = "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN"
862862
self.assert_races_do_not_crash(opname, get_items, read, write)
863863

864-
@requires_specialization_ft
864+
@requires_specialization
865865
def test_load_attr_instance_value(self):
866866
def get_items():
867867
class C:
@@ -885,7 +885,7 @@ def write(items):
885885
opname = "LOAD_ATTR_INSTANCE_VALUE"
886886
self.assert_races_do_not_crash(opname, get_items, read, write)
887887

888-
@requires_specialization_ft
888+
@requires_specialization
889889
def test_load_attr_method_lazy_dict(self):
890890
def get_items():
891891
class C(Exception):
@@ -915,7 +915,7 @@ def write(items):
915915
opname = "LOAD_ATTR_METHOD_LAZY_DICT"
916916
self.assert_races_do_not_crash(opname, get_items, read, write)
917917

918-
@requires_specialization_ft
918+
@requires_specialization
919919
def test_load_attr_method_no_dict(self):
920920
def get_items():
921921
class C:
@@ -946,7 +946,7 @@ def write(items):
946946
opname = "LOAD_ATTR_METHOD_NO_DICT"
947947
self.assert_races_do_not_crash(opname, get_items, read, write)
948948

949-
@requires_specialization_ft
949+
@requires_specialization
950950
def test_load_attr_method_with_values(self):
951951
def get_items():
952952
class C:
@@ -976,7 +976,7 @@ def write(items):
976976
opname = "LOAD_ATTR_METHOD_WITH_VALUES"
977977
self.assert_races_do_not_crash(opname, get_items, read, write)
978978

979-
@requires_specialization_ft
979+
@requires_specialization
980980
def test_load_attr_module(self):
981981
def get_items():
982982
items = []
@@ -1001,7 +1001,7 @@ def write(items):
10011001
opname = "LOAD_ATTR_MODULE"
10021002
self.assert_races_do_not_crash(opname, get_items, read, write)
10031003

1004-
@requires_specialization_ft
1004+
@requires_specialization
10051005
def test_load_attr_property(self):
10061006
def get_items():
10071007
class C:
@@ -1031,7 +1031,7 @@ def write(items):
10311031
opname = "LOAD_ATTR_PROPERTY"
10321032
self.assert_races_do_not_crash(opname, get_items, read, write)
10331033

1034-
@requires_specialization_ft
1034+
@requires_specialization
10351035
def test_load_attr_slot(self):
10361036
def get_items():
10371037
class C:
@@ -1058,7 +1058,7 @@ def write(items):
10581058
opname = "LOAD_ATTR_SLOT"
10591059
self.assert_races_do_not_crash(opname, get_items, read, write)
10601060

1061-
@requires_specialization_ft
1061+
@requires_specialization
10621062
def test_load_attr_with_hint(self):
10631063
def get_items():
10641064
class C:
@@ -1085,7 +1085,7 @@ def write(items):
10851085
opname = "LOAD_ATTR_WITH_HINT"
10861086
self.assert_races_do_not_crash(opname, get_items, read, write)
10871087

1088-
@requires_specialization_ft
1088+
@requires_specialization
10891089
def test_load_global_module(self):
10901090
if not have_dict_key_versions():
10911091
raise unittest.SkipTest("Low on dict key versions")
@@ -1158,7 +1158,7 @@ def write(items):
11581158
opname = "STORE_ATTR_WITH_HINT"
11591159
self.assert_races_do_not_crash(opname, get_items, read, write)
11601160

1161-
@requires_specialization_ft
1161+
@requires_specialization
11621162
def test_store_subscr_list_int(self):
11631163
def get_items():
11641164
items = []
@@ -1182,7 +1182,7 @@ def write(items):
11821182
opname = "STORE_SUBSCR_LIST_INT"
11831183
self.assert_races_do_not_crash(opname, get_items, read, write)
11841184

1185-
@requires_specialization_ft
1185+
@requires_specialization
11861186
def test_unpack_sequence_list(self):
11871187
def get_items():
11881188
items = []
@@ -1362,7 +1362,7 @@ def f(o, n):
13621362
class TestSpecializer(TestBase):
13631363

13641364
@cpython_only
1365-
@requires_specialization_ft
1365+
@requires_specialization
13661366
def test_binary_op(self):
13671367
def binary_op_add_int():
13681368
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
@@ -1497,7 +1497,7 @@ def binary_op_bitwise_extend():
14971497
self.assert_no_opcode(binary_op_bitwise_extend, "BINARY_OP")
14981498

14991499
@cpython_only
1500-
@requires_specialization_ft
1500+
@requires_specialization
15011501
def test_load_super_attr(self):
15021502
"""Ensure that LOAD_SUPER_ATTR is specialized as expected."""
15031503

@@ -1536,7 +1536,7 @@ def init(self):
15361536
self.assert_no_opcode(A.__init__, "LOAD_SUPER_ATTR_METHOD")
15371537

15381538
@cpython_only
1539-
@requires_specialization_ft
1539+
@requires_specialization
15401540
def test_contain_op(self):
15411541
def contains_op_dict():
15421542
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
@@ -1559,7 +1559,7 @@ def contains_op_set():
15591559
self.assert_no_opcode(contains_op_set, "CONTAINS_OP")
15601560

15611561
@cpython_only
1562-
@requires_specialization_ft
1562+
@requires_specialization
15631563
def test_send_with(self):
15641564
def run_async(coro):
15651565
while True:
@@ -1586,7 +1586,7 @@ async def send_with():
15861586
self.assert_specialized(send_with, "SEND_GEN")
15871587

15881588
@cpython_only
1589-
@requires_specialization_ft
1589+
@requires_specialization
15901590
def test_send_yield_from(self):
15911591
def g():
15921592
yield None
@@ -1601,7 +1601,7 @@ def send_yield_from():
16011601
self.assert_no_opcode(send_yield_from, "SEND")
16021602

16031603
@cpython_only
1604-
@requires_specialization_ft
1604+
@requires_specialization
16051605
def test_store_attr_slot(self):
16061606
class C:
16071607
__slots__ = ['x']
@@ -1622,7 +1622,7 @@ def set_slot(n):
16221622
self.assert_no_opcode(set_slot, "STORE_ATTR_SLOT")
16231623

16241624
@cpython_only
1625-
@requires_specialization_ft
1625+
@requires_specialization
16261626
def test_store_attr_instance_value(self):
16271627
class C:
16281628
pass
@@ -1644,7 +1644,7 @@ def set_value(n):
16441644
self.assert_no_opcode(set_value, "STORE_ATTR_INSTANCE_VALUE")
16451645

16461646
@cpython_only
1647-
@requires_specialization_ft
1647+
@requires_specialization
16481648
def test_store_attr_with_hint(self):
16491649
class C:
16501650
pass
@@ -1669,7 +1669,7 @@ def set_value(n):
16691669
self.assert_no_opcode(set_value, "STORE_ATTR_WITH_HINT")
16701670

16711671
@cpython_only
1672-
@requires_specialization_ft
1672+
@requires_specialization
16731673
def test_to_bool(self):
16741674
def to_bool_bool():
16751675
true_cnt, false_cnt = 0, 0
@@ -1737,7 +1737,7 @@ def to_bool_str():
17371737
self.assert_no_opcode(to_bool_str, "TO_BOOL")
17381738

17391739
@cpython_only
1740-
@requires_specialization_ft
1740+
@requires_specialization
17411741
def test_unpack_sequence(self):
17421742
def unpack_sequence_two_tuple():
17431743
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
@@ -1774,7 +1774,7 @@ def unpack_sequence_list():
17741774
self.assert_no_opcode(unpack_sequence_list, "UNPACK_SEQUENCE")
17751775

17761776
@cpython_only
1777-
@requires_specialization_ft
1777+
@requires_specialization
17781778
def test_binary_subscr(self):
17791779
def binary_subscr_list_int():
17801780
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
@@ -1844,7 +1844,7 @@ def __getitem__(self, item):
18441844
self.assert_no_opcode(binary_subscr_getitems, "BINARY_OP")
18451845

18461846
@cpython_only
1847-
@requires_specialization_ft
1847+
@requires_specialization
18481848
def test_compare_op(self):
18491849
def compare_op_int():
18501850
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
@@ -1878,7 +1878,7 @@ def compare_op_str():
18781878

18791879

18801880
@cpython_only
1881-
@requires_specialization_ft
1881+
@requires_specialization
18821882
def test_for_iter(self):
18831883
L = list(range(10))
18841884
def for_iter_list():
@@ -1916,7 +1916,7 @@ def for_iter_generator():
19161916
self.assert_no_opcode(for_iter_generator, "FOR_ITER")
19171917

19181918
@cpython_only
1919-
@requires_specialization_ft
1919+
@requires_specialization
19201920
def test_call_list_append(self):
19211921
# gh-141367: only exact lists should use
19221922
# CALL_LIST_APPEND instruction after specialization.
@@ -1943,7 +1943,7 @@ class MyList(list): pass
19431943
self.assert_no_opcode(my_list_append, "CALL")
19441944

19451945
@cpython_only
1946-
@requires_specialization_ft
1946+
@requires_specialization
19471947
def test_load_attr_module_with_getattr(self):
19481948
module = types.ModuleType("test_module_with_getattr")
19491949
module.__dict__["some_attr"] = "foo"

Lib/test/test_thread_local_bytecode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44

55
from test import support
6-
from test.support import cpython_only, import_helper, requires_specialization_ft
6+
from test.support import cpython_only, import_helper, requires_specialization
77
from test.support.script_helper import assert_python_ok
88
from test.support.threading_helper import requires_working_threading
99

@@ -15,7 +15,7 @@
1515
@requires_working_threading()
1616
@unittest.skipUnless(support.Py_GIL_DISABLED, "only in free-threaded builds")
1717
class TLBCTests(unittest.TestCase):
18-
@requires_specialization_ft
18+
@requires_specialization
1919
def test_new_threads_start_with_unspecialized_code(self):
2020
code = textwrap.dedent("""
2121
import dis
@@ -46,7 +46,7 @@ def f(a, b, q=None):
4646
""")
4747
assert_python_ok("-X", "tlbc=1", "-c", code)
4848

49-
@requires_specialization_ft
49+
@requires_specialization
5050
def test_threads_specialize_independently(self):
5151
code = textwrap.dedent("""
5252
import dis

0 commit comments

Comments
 (0)