gh-100712: make it possible to disable specialization (for debugging) (#100713)

This commit is contained in:
Irit Katriel 2023-01-19 18:14:55 +00:00 committed by GitHub
parent a1e051a237
commit e9ccfe4a63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 87 additions and 3 deletions

View file

@ -33,6 +33,9 @@ hascompare = []
hasfree = []
hasexc = []
ENABLE_SPECIALIZATION = True
def is_pseudo(op):
return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE

View file

@ -6,6 +6,7 @@ if __name__ != 'test.support':
import contextlib
import functools
import getpass
import opcode
import os
import re
import stat
@ -46,7 +47,7 @@ __all__ = [
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_if_buggy_ucrt_strfptime",
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
"requires_limited_api",
"requires_limited_api", "requires_specialization",
# sys
"is_jython", "is_android", "is_emscripten", "is_wasi",
"check_impl_detail", "unix_shell", "setswitchinterval",
@ -1077,6 +1078,8 @@ def requires_limited_api(test):
return unittest.skipUnless(
_testcapi.LIMITED_API_AVAILABLE, 'needs Limited API support')(test)
def requires_specialization(test):
return unittest.skipUnless(opcode.ENABLE_SPECIALIZATION, "requires specialization")
def _filter_suite(suite, pred):
"""Recursively filter test cases in a suite based on a predicate."""

View file

@ -10,7 +10,8 @@ import types
import textwrap
import warnings
from test import support
from test.support import script_helper, requires_debug_ranges
from test.support import (script_helper, requires_debug_ranges,
requires_specialization)
from test.support.os_helper import FakePath
@ -1251,6 +1252,7 @@ f(
self.assertOpcodeSourcePositionIs(compiled_code, 'CALL',
line=1, end_line=3, column=0, end_column=1)
@requires_specialization
def test_multiline_boolean_expression(self):
snippet = """\
if (a or

View file

@ -7,7 +7,8 @@ import re
import sys
import types
import unittest
from test.support import captured_stdout, requires_debug_ranges, cpython_only
from test.support import (captured_stdout, requires_debug_ranges,
requires_specialization, cpython_only)
from test.support.bytecode_helper import BytecodeTestCase
import opcode
@ -1086,12 +1087,14 @@ class DisTests(DisTestBase):
f()
@cpython_only
@requires_specialization
def test_super_instructions(self):
self.code_quicken(lambda: load_test(0, 0))
got = self.get_disassembly(load_test, adaptive=True)
self.do_disassembly_compare(got, dis_load_test_quickened_code, True)
@cpython_only
@requires_specialization
def test_binary_specialize(self):
binary_op_quicken = """\
0 0 RESUME 0
@ -1130,6 +1133,7 @@ class DisTests(DisTestBase):
self.do_disassembly_compare(got, binary_subscr_quicken % "BINARY_SUBSCR_DICT", True)
@cpython_only
@requires_specialization
def test_load_attr_specialize(self):
load_attr_quicken = """\
0 0 RESUME 0
@ -1144,6 +1148,7 @@ class DisTests(DisTestBase):
self.do_disassembly_compare(got, load_attr_quicken, True)
@cpython_only
@requires_specialization
def test_call_specialize(self):
call_quicken = """\
0 RESUME 0
@ -1160,6 +1165,7 @@ class DisTests(DisTestBase):
self.do_disassembly_compare(got, call_quicken)
@cpython_only
@requires_specialization
def test_loop_quicken(self):
# Loop can trigger a quicken where the loop is located
self.code_quicken(loop_test, 1)

View file

@ -2,6 +2,7 @@
from test import support
from test.support import import_helper
from test.support import os_helper
from test.support import requires_specialization
import unittest
from collections import namedtuple
@ -346,6 +347,7 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
out, err = self.run_embedded_interpreter("test_repeated_simple_init")
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
@requires_specialization
def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
# https://github.com/python/cpython/issues/92031