diff --git a/graalpython/com.oracle.graal.python.test/src/tests/__init__.py b/graalpython/com.oracle.graal.python.test/src/tests/__init__.py index eebb0d6d18..6f8357906c 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/__init__.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/__init__.py @@ -77,10 +77,7 @@ def get_setuptools(setuptools='setuptools==67.6.1'): py_executable = setuptools_path / 'Scripts' / 'python.exe' else: py_executable = setuptools_path / 'bin' / 'python3' - extra_args = [] - if sys.implementation.name == "graalpy" and not system_python and __graalpython__.is_bytecode_dsl_interpreter: - extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] - subprocess.run([py_executable, *extra_args, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True) + subprocess.run([py_executable, "-m", "pip", "install", "--target", str(setuptools_path), setuptools], check=True) print('setuptools is installed in %s' % setuptools_path) pyvenv_site = str(setuptools_path) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py index 111d06fb28..1c7a4fca16 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_shutdown.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -51,8 +51,8 @@ ARGS = [] if sys.implementation.name == 'graalpy': ARGS = ['--experimental-options', '--python.EnableDebuggingBuiltins'] - if not __graalpython__.is_native and __graalpython__.is_bytecode_dsl_interpreter: - ARGS += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] + if not __graalpython__.is_native: + ARGS += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] COMMAND = [sys.executable, *ARGS, str(MODULE_PATH)] diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py b/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py index 96f68b0030..88b51fff09 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_frame_tests.py @@ -38,7 +38,7 @@ # SOFTWARE. import os import sys - +from tests import util # IMPORTANT: DO NOT MOVE! # This test checks that lineno works on frames, @@ -46,7 +46,7 @@ def test_lineno(): assert sys._getframe(0).f_lineno == 47 -if not os.environ.get('BYTECODE_DSL_INTERPRETER'): # Blocked by GR-61955 +if not util.IS_BYTECODE_DSL: # Blocked by GR-61955 # IMPORTANT: DO NOT MOVE! def test_nested_lineno(): def test_nested(): diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py b/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py index bec89de817..f37a8843dd 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_generators.py @@ -6,6 +6,7 @@ import sys import os import unittest +from tests import util class ExceptionTest(unittest.TestCase): @@ -557,7 +558,7 @@ def gen(): assert f.f_globals is globals() assert f.f_locals == {'a': 1, 'b': 2, 'c': 3} # TODO GR-61955 - if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter: + if not util.IS_BYTECODE_DSL: assert f.f_lineno == gen.__code__.co_firstlineno + 5 assert not g.gi_frame @@ -591,7 +592,7 @@ def gen(): assert f.f_globals is globals() assert f.f_locals == {'a': 1, 'b': 2} # TODO GR-61955 - if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter: + if not util.IS_BYTECODE_DSL: assert f.f_lineno == gen.__code__.co_firstlineno + 3 diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py b/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py index f66661927d..3028614d89 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_pdb.py @@ -41,6 +41,7 @@ import doctest import sys import unittest +from tests import util # Copied from test_doctest @@ -69,8 +70,6 @@ def __exit__(self, *exc): if self.orig_trace: sys.settrace(self.orig_trace) - -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") def doctest_pdb_locals(): """ Test that locals get synced after breakpoint @@ -101,63 +100,61 @@ def doctest_pdb_locals(): """ -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") -def doctest_pdb_locals_generator(): - """ - Test that locals get synced after breakpoint in a generator - - >>> def test_function(): - ... a = 1 - ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() - ... a = 2 - ... yield - - >>> with PdbTestInput([ - ... 'p a', - ... 'next', - ... 'p a', - ... 'continue', - ... ]): - ... next(test_function()) - > (4)test_function() - -> a = 2 - (Pdb) p a - 1 - (Pdb) next - > (5)test_function() - -> yield - (Pdb) p a - 2 - (Pdb) continue - """ - - -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") -def doctest_pdb_locals_sync_back(): - """ - Test that locals set by debugger get propagated back into the frame. - - >>> def test_function(): - ... foo = 1 - ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() - ... return foo - - >>> with PdbTestInput([ - ... 'p foo', - ... 'foo = 5', - ... 'continue', - ... ]): - ... print(test_function()) - > (4)test_function() - -> return foo - (Pdb) p foo - 1 - (Pdb) foo = 5 - (Pdb) continue - 5 - """ +if not util.IS_BYTECODE_DSL: + def doctest_pdb_locals_generator(): + """ + Test that locals get synced after breakpoint in a generator + + >>> def test_function(): + ... a = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... a = 2 + ... yield + + >>> with PdbTestInput([ + ... 'p a', + ... 'next', + ... 'p a', + ... 'continue', + ... ]): + ... next(test_function()) + > (4)test_function() + -> a = 2 + (Pdb) p a + 1 + (Pdb) next + > (5)test_function() + -> yield + (Pdb) p a + 2 + (Pdb) continue + """ + + + def doctest_pdb_locals_sync_back(): + """ + Test that locals set by debugger get propagated back into the frame. + + >>> def test_function(): + ... foo = 1 + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + ... return foo + + >>> with PdbTestInput([ + ... 'p foo', + ... 'foo = 5', + ... 'continue', + ... ]): + ... print(test_function()) + > (4)test_function() + -> return foo + (Pdb) p foo + 1 + (Pdb) foo = 5 + (Pdb) continue + 5 + """ -@unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: FrameSlotTypeException with reparsing") def test_run_doctests(): doctest.testmod(sys.modules[__name__], raise_on_error=True) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py b/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py index d2860db5d1..05f1fce96f 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_repl.py @@ -45,6 +45,7 @@ import sys import tempfile import unittest +from tests import util from dataclasses import dataclass from textwrap import dedent @@ -191,7 +192,7 @@ def test_continuation(): ''')) - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: vs in traceback") + @util.skipIfBytecodeDSL("TODO: vs in traceback") def test_exceptions(): validate_repl(dedent("""\ >>> 1 / 0 diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py b/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py index b1f6c1e63d..87a4394767 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_venv.py @@ -83,12 +83,14 @@ def test_venv_launcher(self): assert f"Hello {tmpfile}" in out, out assert f'Original "{sys.executable}"' in out, out - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses") def test_create_and_use_basic_venv(self): run = None run_output = '' try: - subprocess.check_output([sys.executable, "-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT) + extra_args = [] + if sys.implementation.name == "graalpy": + extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] + subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir, "--without-pip"], stderr=subprocess.STDOUT) run = subprocess.getoutput(f"{self.env_dir}/{BINDIR}/python{EXESUF} -m site") except subprocess.CalledProcessError as err: if err.output: @@ -98,12 +100,14 @@ def test_create_and_use_basic_venv(self): if sys.platform != 'win32': assert self.env_dir in run, run - @unittest.skipIf(os.environ.get('BYTECODE_DSL_INTERPRETER'), "TODO: issue with passing Bytecode DSL flag to subprocesses") def test_create_and_use_venv_with_pip(self): run = None msg = '' try: - subprocess.check_output([sys.executable, "-m", "venv", self.env_dir2], stderr=subprocess.STDOUT) + extra_args = [] + if sys.implementation.name == "graalpy": + extra_args = [f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] + subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", self.env_dir2], stderr=subprocess.STDOUT) run = subprocess.getoutput(f"{self.env_dir2}/{BINDIR}/python{EXESUF} -m pip list") except subprocess.CalledProcessError as err: if err.output: diff --git a/graalpython/com.oracle.graal.python.test/src/tests/util.py b/graalpython/com.oracle.graal.python.test/src/tests/util.py index 07ce36ae5c..b28238c01b 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/util.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/util.py @@ -1,4 +1,4 @@ -# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # The Universal Permissive License (UPL), Version 1.0 @@ -37,6 +37,24 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import sys +import unittest + +IS_BYTECODE_DSL = sys.implementation.name == 'graalpy' and __graalpython__.is_bytecode_dsl_interpreter + +def skipIfBytecodeDSL(reason=''): + def wrapper(test): + if IS_BYTECODE_DSL: + return unittest.skip(f"Skipped on Bytecode DSL interpreter. {reason}")(test) + return test + return wrapper + + +def skipUnlessBytecodeDSL(reason=''): + def wrapper(test): + if sys.implementation.name == 'graalpy' and not __graalpython__.is_bytecode_dsl_interpreter: + return unittest.skip(f"Skipped on manual interpreter. {reason}")(test) + return test + return wrapper def storage_to_native(s): diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java index 5c1c55fa17..f2cff89968 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java @@ -3607,11 +3607,10 @@ public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int in @Specialization(replaces = "doObject") public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index, @Bind BytecodeNode bytecodeNode) { - try { - return accessor.getObject(bytecodeNode, frame); - } catch (FrameSlotTypeException e) { + if (accessor.isCleared(bytecodeNode, frame)) { throw raiseUnbound(bytecodeNode, index); } + return accessor.getObject(bytecodeNode, frame); } }