gh-118335: Configure Tier 2 interpreter at build time (#118339)

The code for Tier 2 is now only compiled when configured
with `--enable-experimental-jit[=yes|interpreter]`.

We drop support for `PYTHON_UOPS` and -`Xuops`,
but you can disable the interpreter or JIT
at runtime by setting `PYTHON_JIT=0`.
You can also build it without enabling it by default
using `--enable-experimental-jit=yes-off`;
enable with `PYTHON_JIT=1`.

On Windows, the `build.bat` script supports
`--experimental-jit`, `--experimental-jit-off`,
`--experimental-interpreter`.

In the C code, `_Py_JIT` is defined as before
when the JIT is enabled; the new variable
`_Py_TIER2` is defined when the JIT *or* the
interpreter is enabled. It is actually a bitmask:
1: JIT; 2: default-off; 4: interpreter.
This commit is contained in:
Guido van Rossum 2024-04-30 18:26:34 -07:00 committed by GitHub
parent 9c468e2c5d
commit 7d83f7bcc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 181 additions and 42 deletions

View file

@ -2539,17 +2539,17 @@ Py_TRACE_REFS = hasattr(sys, 'getobjects')
# Decorator to disable optimizer while a function run
def without_optimizer(func):
try:
import _testinternalcapi
from _testinternalcapi import get_optimizer, set_optimizer
except ImportError:
return func
@functools.wraps(func)
def wrapper(*args, **kwargs):
save_opt = _testinternalcapi.get_optimizer()
save_opt = get_optimizer()
try:
_testinternalcapi.set_optimizer(None)
set_optimizer(None)
return func(*args, **kwargs)
finally:
_testinternalcapi.set_optimizer(save_opt)
set_optimizer(save_opt)
return wrapper

View file

@ -34,6 +34,8 @@ def clear_executors(func):
@requires_specialization
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
class TestOptimizerAPI(unittest.TestCase):
def test_new_counter_optimizer_dealloc(self):
@ -136,6 +138,8 @@ def get_opnames(ex):
@requires_specialization
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
class TestExecutorInvalidation(unittest.TestCase):
def setUp(self):
@ -215,6 +219,8 @@ class TestExecutorInvalidation(unittest.TestCase):
@requires_specialization
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
@unittest.skipIf(os.getenv("PYTHON_UOPS_OPTIMIZE") == "0", "Needs uop optimizer to run.")
class TestUops(unittest.TestCase):
@ -579,6 +585,8 @@ class TestUops(unittest.TestCase):
@requires_specialization
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
"Requires optimizer infrastructure")
@unittest.skipIf(os.getenv("PYTHON_UOPS_OPTIMIZE") == "0", "Needs uop optimizer to run.")
class TestUopsOptimization(unittest.TestCase):

View file

@ -1831,15 +1831,17 @@ class TestOptimizer(MonitoringTestBase, unittest.TestCase):
def setUp(self):
_testinternalcapi = import_module("_testinternalcapi")
self.old_opt = _testinternalcapi.get_optimizer()
opt = _testinternalcapi.new_counter_optimizer()
_testinternalcapi.set_optimizer(opt)
if hasattr(_testinternalcapi, "get_optimizer"):
self.old_opt = _testinternalcapi.get_optimizer()
opt = _testinternalcapi.new_counter_optimizer()
_testinternalcapi.set_optimizer(opt)
super(TestOptimizer, self).setUp()
def tearDown(self):
super(TestOptimizer, self).tearDown()
import _testinternalcapi
_testinternalcapi.set_optimizer(self.old_opt)
if hasattr(_testinternalcapi, "get_optimizer"):
_testinternalcapi.set_optimizer(self.old_opt)
def test_for_loop(self):
def test_func(x):

View file

@ -16,6 +16,8 @@ _testinternalcapi = import_module("_testinternalcapi")
def disabling_optimizer(func):
def wrapper(*args, **kwargs):
if not hasattr(_testinternalcapi, "get_optimizer"):
return func(*args, **kwargs)
old_opt = _testinternalcapi.get_optimizer()
_testinternalcapi.set_optimizer(None)
try:

View file

@ -80,6 +80,8 @@ class TestRareEventCounters(unittest.TestCase):
class TestOptimizerSymbols(unittest.TestCase):
@unittest.skipUnless(hasattr(_testinternalcapi, "uop_symbols_test"),
"requires _testinternalcapi.uop_symbols_test")
def test_optimizer_symbols(self):
_testinternalcapi.uop_symbols_test()

View file

@ -17,6 +17,7 @@ from test.support import script_helper, ALWAYS_EQ, suppress_immortalization
from test.support import gc_collect
from test.support import import_helper
from test.support import threading_helper
from test.support import is_wasi, Py_DEBUG
# Used in ReferencesTestCase.test_ref_created_during_del() .
ref_from_del = None
@ -960,6 +961,7 @@ class ReferencesTestCase(TestBase):
self.assertEqual(hash(a), hash(42))
self.assertRaises(TypeError, hash, b)
@unittest.skipIf(is_wasi and Py_DEBUG, "requires deep stack")
def test_trashcan_16602(self):
# Issue #16602: when a weakref's target was part of a long
# deallocation chain, the trashcan mechanism could delay clearing