summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-11-02 17:42:57 (GMT)
committerGitHub <noreply@github.com>2022-11-02 17:42:57 (GMT)
commit276d77724f2373cc03838448a3e62977aa28bf0d (patch)
treeaeb2f83a896f02a3f38ace9d6ecb65b9620be8e3 /Lib/test/test_embed.py
parent18fc232e07c14536d99f07821e338ebddfd8cb63 (diff)
downloadcpython-276d77724f2373cc03838448a3e62977aa28bf0d.zip
cpython-276d77724f2373cc03838448a3e62977aa28bf0d.tar.gz
cpython-276d77724f2373cc03838448a3e62977aa28bf0d.tar.bz2
GH-98686: Quicken everything (GH-98687)
Diffstat (limited to 'Lib/test/test_embed.py')
-rw-r--r--Lib/test/test_embed.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index fa9815c..f5cda15 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -346,33 +346,41 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
out, err = self.run_embedded_interpreter("test_repeated_simple_init")
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
- def test_quickened_static_code_gets_unquickened_at_Py_FINALIZE(self):
+ def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
# https://github.com/python/cpython/issues/92031
- # Do these imports outside of the code string to avoid using
- # importlib too much from within the code string, so that
- # _handle_fromlist doesn't get quickened until we intend it to.
- from dis import _all_opmap
- resume = _all_opmap["RESUME"]
- resume_quick = _all_opmap["RESUME_QUICK"]
- from test.test_dis import QUICKENING_WARMUP_DELAY
-
- code = textwrap.dedent(f"""\
+ code = textwrap.dedent("""\
+ import dis
import importlib._bootstrap
+ import opcode
+ import test.test_dis
+
+ def is_specialized(f):
+ for instruction in dis.get_instructions(f, adaptive=True):
+ opname = instruction.opname
+ if (
+ opname in opcode._specialized_instructions
+ # Exclude superinstructions:
+ and "__" not in opname
+ # Exclude adaptive instructions:
+ and not opname.endswith("_ADAPTIVE")
+ # Exclude "quick" instructions:
+ and not opname.endswith("_QUICK")
+ ):
+ return True
+ return False
+
func = importlib._bootstrap._handle_fromlist
- code = func.__code__
- # Assert initially unquickened.
- # Use sets to account for byte order.
- if set(code._co_code_adaptive[:2]) != set([{resume}, 0]):
- raise AssertionError()
+ # "copy" the code to un-specialize it:
+ func.__code__ = func.__code__.replace()
+
+ assert not is_specialized(func), "specialized instructions found"
- for i in range({QUICKENING_WARMUP_DELAY}):
+ for i in range(test.test_dis.ADAPTIVE_WARMUP_DELAY):
func(importlib._bootstrap, ["x"], lambda *args: None)
- # Assert quickening worked
- if set(code._co_code_adaptive[:2]) != set([{resume_quick}, 0]):
- raise AssertionError()
+ assert is_specialized(func), "no specialized instructions found"
print("Tests passed")
""")