From fd32e4affb7bce5b86dc8f0e196eb3bf10852140 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:31:30 +0200 Subject: [PATCH 01/20] Drop manual bytecode interpreter CI variants --- ci.jsonnet | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ci.jsonnet b/ci.jsonnet index 02b45a26a0..04056ada0c 100644 --- a/ci.jsonnet +++ b/ci.jsonnet @@ -134,18 +134,6 @@ tags :: name, }), - // Manual interpreter variants (DSL disabled) - local manual_interpreter_env = task_spec({ - environment +: { - BYTECODE_DSL_INTERPRETER: "false" - }, - }), - local manual_interpreter_gate(name) = manual_interpreter_env + task_spec({ - tags :: name, - }), - local manual_interpreter_bench = manual_interpreter_env + task_spec({ - name_suffix +:: ["manual-interpreter"], - }), local with_compiler = task_spec({ dynamic_imports +:: ["/compiler"], }), @@ -178,11 +166,6 @@ "python-unittest-native-debug-build": gpgate + platform_spec(no_jobs) + native_debug_build_gate("python-unittest") + platform_spec({ "linux:amd64:jdk-latest" : tier3, }), - "python-unittest-manual-interpreter": gpgate + platform_spec(no_jobs) + manual_interpreter_gate("python-unittest") + platform_spec({ - "linux:amd64:jdk-latest" : daily + t("01:00:00"), - "linux:aarch64:jdk-latest" : daily + t("01:00:00"), - "darwin:aarch64:jdk-latest" : daily + t("01:00:00"), - }), "python-unittest-multi-context": gpgate + require(GPY_NATIVE_STANDALONE) + platform_spec(no_jobs) + platform_spec({ "linux:amd64:jdk-latest" : tier3, "linux:aarch64:jdk-latest" : daily + t("02:00:00"), @@ -218,9 +201,6 @@ "darwin:aarch64:jdk-latest" : tier3 + require(GRAAL_JDK_LATEST) + with_compiler, "windows:amd64:jdk-latest" : tier3 + require(GRAAL_JDK_LATEST) + with_compiler, }), - "python-junit-manual-interpreter": gpgate + platform_spec(no_jobs) + manual_interpreter_gate("python-junit") + platform_spec({ - "linux:amd64:jdk-latest" : tier3 + require(GRAAL_JDK_LATEST) + with_compiler, - }), "python-junit-maven": gpgate_maven + platform_spec(no_jobs) + platform_spec({ "linux:amd64:jdk21" : daily + t("00:30:00"), "linux:aarch64:jdk21" : daily + t("01:00:00"), @@ -259,9 +239,6 @@ "darwin:aarch64:jdk-latest" : tier3 + require(GPY_NATIVE_STANDALONE), "windows:amd64:jdk-latest" : tier3 + require(GPY_NATIVE_STANDALONE) + batches(2), }), - "python-svm-unittest-manual-interpreter": gpgate + platform_spec(no_jobs) + manual_interpreter_gate("python-svm-unittest") + platform_spec({ - "linux:amd64:jdk-latest" : tier2, - }), "python-tagged-unittest": gpgate + require(GPY_NATIVE_STANDALONE) + batches(TAGGED_UNITTESTS_SPLIT) + platform_spec(no_jobs) + platform_spec({ "linux:amd64:jdk-latest" : tier2, "linux:aarch64:jdk-latest" : tier3, From 5f8634f99c4caac59e82ea10f4d53695eaaaeb6f Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:31:48 +0200 Subject: [PATCH 02/20] Remove bytecode DSL interpreter build switch --- .../freeze_modules.py | 10 +---- mx.graalpython/mx_graalpython.py | 42 +++---------------- mx.graalpython/mx_graalpython_benchmark.py | 2 - 3 files changed, 8 insertions(+), 46 deletions(-) diff --git a/graalpython/com.oracle.graal.python.frozen/freeze_modules.py b/graalpython/com.oracle.graal.python.frozen/freeze_modules.py index 62415caaad..7f75af6ee8 100644 --- a/graalpython/com.oracle.graal.python.frozen/freeze_modules.py +++ b/graalpython/com.oracle.graal.python.frozen/freeze_modules.py @@ -11,7 +11,6 @@ import ntpath import os import posixpath -import shutil import sys from collections import namedtuple from io import StringIO @@ -646,13 +645,8 @@ def main(): STDLIB_DIR = os.path.abspath(parsed_args.python_lib) FROZEN_MODULES_DIR = os.path.abspath(parsed_args.binary_dir) - if __graalpython__.is_bytecode_dsl_interpreter: - suffix = "bin_dsl" - assert os.path.isdir(parsed_args.binary_dir), "Frozen modules for the DSL should be built after the manual bytecode interpreter." - else: - suffix = "bin" - shutil.rmtree(parsed_args.binary_dir, ignore_errors=True) - os.makedirs(parsed_args.binary_dir) + suffix = "bin_dsl" + os.makedirs(parsed_args.binary_dir, exist_ok=True) # create module specs modules = list(parse_frozen_specs(suffix)) diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py index 9dd98d2aa2..e58c7db92f 100644 --- a/mx.graalpython/mx_graalpython.py +++ b/mx.graalpython/mx_graalpython.py @@ -150,7 +150,6 @@ def get_boolean_env(name, default=False): GITHUB_CI = get_boolean_env("GITHUB_CI") WIN32 = sys.platform == "win32" BUILD_NATIVE_IMAGE_WITH_ASSERTIONS = get_boolean_env('BUILD_WITH_ASSERTIONS', CI) -BYTECODE_DSL_INTERPRETER = get_boolean_env('BYTECODE_DSL_INTERPRETER', True) GRAALPY_WITH_BOUNCYCASTLE = get_boolean_env("GRAALPY_WITH_BOUNCYCASTLE", True) mx_gate.add_jacoco_excludes([ @@ -480,7 +479,7 @@ def github_ci_build_args(): ] def libpythonvm_build_args(): - build_args = bytecode_dsl_build_args() + build_args = [] if os.environ.get("GITHUB_CI"): build_args += github_ci_build_args() @@ -942,7 +941,6 @@ def __post_init__(self): vm_args = ['-Dpolyglot.engine.WarnInterpreterOnly=false'] if mx.suite('compiler', fatalIfMissing=False): vm_args.append('-Dpolyglot.engine.CompilationFailureAction=ExitVM') - vm_args += bytecode_dsl_build_args() # Note: we must use filters instead of --regex so that mx correctly processes the unit test configs, # but it is OK to apply --regex on top of the filters @@ -1018,7 +1016,7 @@ def verify_junit_compilation_failure(): '--suite', 'graalpython', '--verbose', '-Dpolyglot.engine.CompilationFailureAction=ExitVM', - ] + bytecode_dsl_build_args() + [ + ] + [ compiler_failure_exit_test, ] output = mx.OutputCapture() @@ -1163,19 +1161,6 @@ def graalpy_standalone_home(standalone_type, enterprise=False, dev=False, build= mx.abort(f"GRAALPY_HOME is not compatible with the requested JDK version.\n" f"actual version: '{actual_jdk_version}', version string: {line}, requested version: {jdk_version}.") - launcher = os.path.join(python_home, 'bin', _graalpy_launcher()) - out = mx.OutputCapture() - mx.run([launcher, "-c", "print('__GRAALPY_BYTECODE_DSL_INTERPRETER__ =', __graalpython__.is_bytecode_dsl_interpreter)"], nonZeroIsFatal=False, out=out, err=out) - is_bytecode_dsl_interpreter = "__GRAALPY_BYTECODE_DSL_INTERPRETER__ = True" in out.data - if is_bytecode_dsl_interpreter != BYTECODE_DSL_INTERPRETER: - requested = "Bytecode DSL" if BYTECODE_DSL_INTERPRETER else "Manual" - actual = "Bytecode DSL" if is_bytecode_dsl_interpreter else "Manual" - mx.abort(f"GRAALPY_HOME is not compatible with requested interpreter kind ({requested=}, {actual=})\n" - f"Used launcher: {launcher}\n" - f"Found Python home: {python_home}\n" - f"GRAALPY_HOME env variable: {os.environ.get('GRAALPY_HOME', None)}\n" - f"Raw output:\n\n{out}\n\n") - return python_home # Build @@ -1223,10 +1208,9 @@ def graalpy_standalone_home(standalone_type, enterprise=False, dev=False, build= mx_args.append("--extra-image-builder-argument=-J-ea") if mx_gate.get_jacoco_agent_args() or (build and not DISABLE_REBUILD): - mx_build_args = mx_args + bytecode_dsl_build_args(prefix="--extra-image-builder-argument=") # This build is purposefully done without the LATEST_JAVA_HOME in the # environment, so we can build JVM standalones on an older Graal JDK - run_mx(mx_build_args + ["build", "--target", standalone_dist]) + run_mx(mx_args + ["build", "--target", standalone_dist]) python_home = os.path.join(SUITE.dir, 'mxbuild', f"{mx.get_os()}-{mx.get_arch()}", standalone_dist) @@ -1580,9 +1564,6 @@ def graalpytest(args): gp_args += ["--vm.ea", "--vm.esa"] mx.log(f"Executable seems to be GraalPy, prepending arguments: {gp_args}") python_args = [*gp_args, *python_args] - if is_graalpy and not BYTECODE_DSL_INTERPRETER: - python_args.insert(0, "--vm.Dpython.EnableBytecodeDSLInterpreter=false") - runner_args.append(f'--subprocess-args={shlex.join(arg for arg in python_args if arg != "-repeated-run")}') if is_graalpy: runner_args.append(f'--append-path={os.path.join(_dev_pythonhome(), "lib-python", "3")}') @@ -1633,8 +1614,6 @@ def run_python_unittests(python_binary, args=None, paths=None, exclude=None, env # index in in that case env["PIP_EXTRA_INDEX_URL"] = pip_index - if not BYTECODE_DSL_INTERPRETER: - args += ['--vm.Dpython.EnableBytecodeDSLInterpreter=false'] args += [_python_test_runner(), "run", "--durations", "10", "-n", parallelism, f"--subprocess-args={shlex.join(args)}"] if runner_args: @@ -2777,10 +2756,6 @@ def _python_checkpatchfiles(): stability="experimental", )) - -def bytecode_dsl_build_args(prefix=''): - return [] if BYTECODE_DSL_INTERPRETER else [prefix + '-Dpython.EnableBytecodeDSLInterpreter=false'] - mx_sdk.register_graalvm_component(mx_sdk.GraalVmLanguage( suite=SUITE, name='GraalVM Python', @@ -2822,7 +2797,7 @@ def bytecode_dsl_build_args(prefix=''): '-Dpolyglot.python.Sha3ModuleBackend=native', '-Dpolyglot.python.CompressionModulesBackend=native', '-Dpolyglot.python.UnicodeCharacterDatabaseNativeFallback=true', - ] + bytecode_dsl_build_args(), + ], language='python', default_vm_args=[ '--vm.Xss16777216', # request 16M of stack @@ -3247,16 +3222,11 @@ def getBuildEnv(self, replaceVar=mx_subst.path_substitutions): class GraalpythonFrozenModuleBuildTask(GraalpythonBuildTask): def build(self): - # We freeze modules twice: once for the manual Bytecode interpreter and once for the DSL interpreter. args = [mx_subst.path_substitutions.substitute(a, dependency=self) for a in cast(GraalpythonProject, self.subject).args] - manual_vm_args = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000"] if 'DEBUG_FROZEN' in os.environ else [] - dsl_vm_args = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000"] if 'DEBUG_FROZEN_BCI' in os.environ else [] + vm_args = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000"] if 'DEBUG_FROZEN' in os.environ else [] - return bool( - self.run_for(args, "manual bytecode", extra_vm_args=manual_vm_args + ["-Dpython.EnableBytecodeDSLInterpreter=false"]) or - self.run_for(args, "dsl", extra_vm_args=dsl_vm_args + ["-Dpython.EnableBytecodeDSLInterpreter=true"]) - ) + return bool(self.run_for(args, "dsl", extra_vm_args=vm_args)) def run_for(self, args, interpreter_kind, extra_vm_args=None): mx.log(f"Building frozen modules for {interpreter_kind} interpreter.") diff --git a/mx.graalpython/mx_graalpython_benchmark.py b/mx.graalpython/mx_graalpython_benchmark.py index efa07b36cd..d559edb87e 100644 --- a/mx.graalpython/mx_graalpython_benchmark.py +++ b/mx.graalpython/mx_graalpython_benchmark.py @@ -670,7 +670,6 @@ def _build_standalone(self, host, runner, instrumented): BUILD_NATIVE_IMAGE_WITH_ASSERTIONS, GITHUB_CI, _graalpy_launcher, - bytecode_dsl_build_args, run_mx, set_env, ) @@ -692,7 +691,6 @@ def _build_standalone(self, host, runner, instrumented): elif BUILD_NATIVE_IMAGE_WITH_ASSERTIONS and not use_product_profile: mx_args.append("--extra-image-builder-argument=-ea") mx_args.append("--extra-image-builder-argument=-J-ea") - mx_args += bytecode_dsl_build_args(prefix="--extra-image-builder-argument=") for arg in self._mx_extra_image_builder_args(self._image_build_args(host)): mx_args.append(f"--extra-image-builder-argument={arg}") From 7ac112501e1f10c5d7bab7926b5d001379720511 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:32:52 +0200 Subject: [PATCH 03/20] Remove manual compiler tests --- .../test/advanced/NodeFootprintAnalyzer.java | 10 +- .../python/test/compiler/CompilerTests.java | 1167 --------------- .../python/test/compiler/SourceMapTests.java | 73 - .../python/test/compiler/UnparserTests.java | 24 +- .../src/tests/__init__.py | 9 +- .../src/tests/cpyext/test_capi_logging.py | 3 - .../src/tests/cpyext/test_shutdown.py | 3 - .../src/tests/test_ssl_java_integration.py | 8 +- .../src/tests/test_venv.py | 15 +- .../CompilerTests/testAnnAssignment.co | 10 - .../CompilerTests/testArgAnnotations.co | 29 - .../CompilerTests/testArgsCombination.co | 18 - .../CompilerTests/testAssignment.co | 5 - .../CompilerTests/testAugAssignment.co | 7 - .../CompilerTests/testAugAssignmentAttr.co | 10 - .../CompilerTests/testAugAssignmentSubscr.co | 13 - .../CompilerTests/testBenchmark.co | 83 -- .../CompilerTests/testBenchmark2.co | 40 - .../goldenFiles/CompilerTests/testBinaryOp.co | 5 - .../CompilerTests/testBreakFromExcept.co | 37 - .../CompilerTests/testBreakFromFinally.co | 42 - .../CompilerTests/testBreakFromTry.co | 28 - .../CompilerTests/testBreakFromWith.co | 20 - .../goldenFiles/CompilerTests/testCall.co | 5 - .../CompilerTests/testCallKeyword.co | 9 - .../CompilerTests/testCallMultiStarArgs.co | 14 - .../CompilerTests/testCallMultiStarKwargs.co | 21 - .../goldenFiles/CompilerTests/testClass.co | 28 - .../CompilerTests/testClassAnnotations.co | 24 - .../testClassAnnotationsFuture.co | 28 - .../goldenFiles/CompilerTests/testClosure.co | 34 - .../CompilerTests/testComplexNumber.co | 5 - .../CompilerTests/testCoroutine.co | 20 - .../goldenFiles/CompilerTests/testDefun.co | 13 - .../goldenFiles/CompilerTests/testDel.co | 4 - .../goldenFiles/CompilerTests/testDelItem.co | 6 - .../CompilerTests/testDictComprehension.co | 21 - .../CompilerTests/testDictLiteral.co | 7 - .../CompilerTests/testDictLiteralExpand.co | 12 - .../CompilerTests/testEmptyDict.co | 3 - .../CompilerTests/testEmptyList.co | 3 - .../CompilerTests/testEmptyTuple.co | 3 - .../goldenFiles/CompilerTests/testEval.co | 3 - .../CompilerTests/testExtendedArgs.co | 1322 ----------------- .../goldenFiles/CompilerTests/testFString.co | 18 - .../CompilerTests/testFinallyCancelReturn.co | 30 - .../goldenFiles/CompilerTests/testFor.co | 9 - .../CompilerTests/testForBreakContinue.co | 22 - .../testGeneratorComprehension.co | 32 - .../goldenFiles/CompilerTests/testGetItem.co | 5 - .../goldenFiles/CompilerTests/testGuard.co | 16 - .../goldenFiles/CompilerTests/testIf.co | 14 - .../CompilerTests/testIfExpression.co | 7 - .../goldenFiles/CompilerTests/testImport.co | 68 - .../goldenFiles/CompilerTests/testImportAs.co | 12 - .../CompilerTests/testImportFrom.co | 11 - .../CompilerTests/testImportStar.co | 5 - .../goldenFiles/CompilerTests/testLambda.co | 9 - .../CompilerTests/testListComprehension.co | 29 - .../CompilerTests/testListLiteral.co | 3 - .../CompilerTests/testListLiteralExpand.co | 10 - .../CompilerTests/testLoadClassDefRef.co | 30 - .../CompilerTests/testLogicOperators.co | 8 - .../goldenFiles/CompilerTests/testManyArgs.co | 42 - .../goldenFiles/CompilerTests/testMatchAs.co | 14 - .../goldenFiles/CompilerTests/testMatchAs2.co | 26 - .../CompilerTests/testMatchAsDefault.co | 17 - .../CompilerTests/testMatchAsGuard.co | 18 - .../CompilerTests/testMatchClass.co | 17 - .../CompilerTests/testMatchMapping.co | 30 - .../CompilerTests/testMatchMappingStar.co | 22 - .../testMatchMappingSubpattern.co | 30 - .../goldenFiles/CompilerTests/testMatchOr.co | 19 - .../CompilerTests/testMatchOrRot.co | 38 - .../testMatchSingletonBoolean.co | 9 - .../CompilerTests/testMatchSingletonNone.co | 9 - .../CompilerTests/testMatchValue.co | 11 - .../CompilerTests/testMatchValueConst.co | 9 - .../testMatchValueWithDefault.co | 13 - .../CompilerTests/testMinusFolding.co | 5 - .../CompilerTests/testNamedExpr.co | 12 - .../testNestedListComprehension.co | 33 - .../CompilerTests/testReturnFromAsyncWith.co | 45 - .../CompilerTests/testReturnFromAsyncWithT.co | 78 - .../CompilerTests/testReturnFromExcept.co | 46 - .../CompilerTests/testReturnFromFinally.co | 59 - .../CompilerTests/testReturnFromTry.co | 36 - .../CompilerTests/testReturnFromWith.co | 29 - .../CompilerTests/testReturnPlain.co | 9 - .../goldenFiles/CompilerTests/testSeq.co | 17 - .../CompilerTests/testSeqWildcard.co | 14 - .../CompilerTests/testSeqWildcardStar.co | 10 - .../testSeqWildcardStarSubscript.co | 22 - .../CompilerTests/testSeqWildcardSubscript.co | 18 - .../CompilerTests/testSetComprehension.co | 26 - .../goldenFiles/CompilerTests/testSetItem.co | 7 - .../CompilerTests/testSetLiteral.co | 6 - .../CompilerTests/testSetLiteralExpand.co | 10 - .../goldenFiles/CompilerTests/testSingle.co | 5 - .../goldenFiles/CompilerTests/testSlice.co | 7 - .../CompilerTests/testSliceStep.co | 8 - .../CompilerTests/testStringSurrogates.co | 5 - .../goldenFiles/CompilerTests/testSuper.co | 57 - .../CompilerTests/testTryExcept.co | 51 - .../CompilerTests/testTryExceptBare.co | 41 - .../CompilerTests/testTryExceptElse.co | 56 - .../CompilerTests/testTryExceptElseFinally.co | 72 - .../CompilerTests/testTryExceptFinally.co | 67 - .../CompilerTests/testTryFinally.co | 25 - .../CompilerTests/testTryFinallyNested.co | 46 - .../CompilerTests/testTupleLiteralBooleans.co | 3 - .../CompilerTests/testTupleLiteralDoubles.co | 3 - .../CompilerTests/testTupleLiteralExpand.co | 11 - .../CompilerTests/testTupleLiteralInts.co | 3 - .../CompilerTests/testTupleLiteralMixed.co | 3 - .../testTupleLiteralMixedIntegers.co | 3 - .../testTupleLiteralNonConstant.co | 6 - .../CompilerTests/testTupleLiteralObjects.co | 3 - .../goldenFiles/CompilerTests/testUnpack.co | 7 - .../goldenFiles/CompilerTests/testUnpackEx.co | 8 - .../goldenFiles/CompilerTests/testVarArgs.co | 14 - .../CompilerTests/testVarKwargs.co | 15 - .../goldenFiles/CompilerTests/testWhile.co | 7 - .../CompilerTests/testWhileBreakContinue.co | 25 - .../goldenFiles/CompilerTests/testWildcard.co | 7 - .../goldenFiles/CompilerTests/testWith.co | 21 - .../CompilerTests/testWithMultiple.co | 28 - .../CompilerTests/testYieldExpression.co | 14 - .../CompilerTests/testYieldFrom.co | 20 - .../CompilerTests/testYieldPlain.co | 14 - .../CompilerTests/testYieldValue.co | 16 - 131 files changed, 33 insertions(+), 5026 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java delete mode 100644 graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/SourceMapTests.java delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAnnAssignment.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgAnnotations.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgsCombination.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAssignment.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignment.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentAttr.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentSubscr.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark2.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBinaryOp.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromExcept.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromFinally.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromTry.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromWith.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCall.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallKeyword.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarArgs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarKwargs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClass.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotations.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotationsFuture.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClosure.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testComplexNumber.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCoroutine.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDefun.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDel.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDelItem.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictComprehension.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteral.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteralExpand.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyDict.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyList.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyTuple.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEval.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testExtendedArgs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFString.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFinallyCancelReturn.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFor.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testForBreakContinue.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGeneratorComprehension.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGetItem.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGuard.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIf.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIfExpression.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImport.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportAs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportFrom.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportStar.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLambda.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListComprehension.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteral.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteralExpand.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLoadClassDefRef.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLogicOperators.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testManyArgs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs2.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsDefault.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsGuard.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchClass.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMapping.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingStar.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingSubpattern.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOr.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOrRot.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonBoolean.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonNone.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValue.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueConst.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueWithDefault.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMinusFolding.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNamedExpr.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNestedListComprehension.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWith.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWithT.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromExcept.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromFinally.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromTry.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromWith.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnPlain.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeq.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcard.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStar.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStarSubscript.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardSubscript.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetComprehension.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetItem.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteral.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteralExpand.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSingle.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSlice.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSliceStep.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testStringSurrogates.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSuper.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExcept.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptBare.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElse.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElseFinally.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptFinally.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinally.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinallyNested.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralBooleans.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralDoubles.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralExpand.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralInts.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixed.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixedIntegers.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralNonConstant.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralObjects.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpack.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpackEx.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarArgs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarKwargs.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhile.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhileBreakContinue.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWildcard.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWith.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWithMultiple.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldExpression.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldFrom.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldPlain.co delete mode 100644 graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldValue.co diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java index 8e2f58c5a3..6a396599a7 100644 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java +++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, 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 @@ -71,19 +71,19 @@ import org.netbeans.lib.profiler.heap.ObjectArrayInstance; import org.netbeans.lib.profiler.heap.PrimitiveArrayInstance; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; +import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; import com.oracle.truffle.api.strings.TruffleString; /** * Standalone tool that can be run via {@code mx python-nodes-footprint heap_dump1 heap_dump2}. - * + * * It creates a mapping between root nodes instances in two heap dumps according to their source * sections. The tool provides comparison of retained sizes of root nodes with the same source * sections. * * It is recommended to run GraalPy with the following options when taking the heap dumps. - * + * *
  *     --engine.Splitting=false --engine.OSR=false --python.BuiltinsInliningMaxCallerSize=0 --python.ForceInitializeSourceSections=true
  * 
@@ -356,7 +356,7 @@ private static Map processDump(String dumpFile) throws IOExcep Heap heap = HeapFactory.createHeap(new File(dumpFile)); Iterator instancesIt = heap.getAllInstancesIterator(); - JavaClass bytecodeRootNodeClass = heap.getJavaClassByName(PBytecodeRootNode.class.getName()); + JavaClass bytecodeRootNodeClass = heap.getJavaClassByName(PBytecodeDSLRootNode.class.getName()); JavaClass builtinRootNodeClass = heap.getJavaClassByName(BuiltinFunctionRootNode.class.getName()); Map roots = Stream.concat( StreamSupport.stream(Spliterators.spliteratorUnknownSize(instancesIt, Spliterator.ORDERED), diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java deleted file mode 100644 index 607a0237a1..0000000000 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/CompilerTests.java +++ /dev/null @@ -1,1167 +0,0 @@ -/* - * Copyright (c) 2019, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.test.compiler; - -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.EnumSet; - -import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.compiler.CompilationUnit; -import com.oracle.graal.python.compiler.Compiler; -import com.oracle.graal.python.pegparser.FutureFeature; -import com.oracle.graal.python.pegparser.InputType; -import com.oracle.graal.python.pegparser.Parser; -import com.oracle.graal.python.pegparser.ParserCallbacks; -import com.oracle.graal.python.pegparser.sst.ModTy; -import com.oracle.graal.python.pegparser.tokenizer.SourceRange; -import com.oracle.graal.python.runtime.PythonOptions; -import com.oracle.graal.python.test.GraalPythonEnvVars; -import com.oracle.graal.python.test.PythonTests; - -public class CompilerTests extends PythonTests { - public CompilerTests() { - } - - @Before - public void beforeTest() { - // These tests are coupled to the manual bytecode interpreter. They shouldn't run if we're - // using the Bytecode DSL interpreter. - Assume.assumeFalse(PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER); - } - - @Rule public TestName name = new TestName(); - - @Test - public void testBinaryOp() { - doTest("1 + 1"); - } - - @Test - public void testComplexNumber() { - doTest("-2 + 3j"); - } - - @Test - public void testMinusFolding() { - doTest("-1 * -7.0"); - } - - @Test - public void testAssignment() { - doTest("a = 12"); - } - - @Test - public void testAugAssignment() { - doTest("a += 12.0"); - } - - @Test - public void testAugAssignmentAttr() { - doTest("a.b += 12.0"); - } - - @Test - public void testAugAssignmentSubscr() { - doTest("a[b] += 12.0"); - } - - @Test - public void testAnnAssignment() { - doTest("a: int = 12"); - } - - @Test - public void testDel() { - doTest("del a"); - } - - @Test - public void testGetItem() { - doTest("a[3]"); - } - - @Test - public void testSetItem() { - doTest("a[3] = 1"); - } - - @Test - public void testDelItem() { - doTest("del a[3]"); - } - - @Test - public void testSlice() { - doTest("a[3:9]"); - } - - @Test - public void testSliceStep() { - doTest("a[3:9:2]"); - } - - @Test - public void testCall() { - doTest("range(num)"); - } - - @Test - public void testLogicOperators() { - doTest("a and b or not c"); - } - - @Test - public void testManyArgs() { - // Test collecting more args that a single COLLECT_FROM_STACK instruction can handle - String source = "print(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36)"; - doTest(source); - } - - @Test - public void testCallKeyword() { - doTest("print('test', end=';')"); - } - - @Test - public void testCallMultiStarArgs() { - doTest("foo(1, *a, 2, *b, 3)"); - } - - @Test - public void testCallMultiStarKwargs() { - doTest("foo(a=1, **a, b=2, **b, c=3)"); - } - - @Test - public void testVarArgs() { - String source = "def foo(*args):\n" + - " print(*args)\n"; - doTest(source); - } - - @Test - public void testVarKwargs() { - String source = "def foo(**kwargs):\n" + - " print(**kwargs)\n"; - doTest(source); - } - - @Test - public void testArgsCombination() { - String source = "def foo(a, /, b, *c, d, **e):\n" + - " print(a, b, c, d, e)\n"; - doTest(source); - } - - @Test - public void testArgAnnotations() { - String source = "def foo(a:1, /, b:2, *c:3, d:4, **e:5):\n" + - " print(a, b, c, d, e)\n"; - doTest(source); - } - - @Test - public void testClassAnnotations() { - String source = "class Foo:\n" + - " attr: a[str]"; - doTest(source); - } - - @Test - public void testClassAnnotationsFuture() { - String source = "from __future__ import annotations\n" + - "class Foo:\n" + - " attr: a[str]"; - doTest(source); - } - - @Test - public void testFor() { - doTest("for i in [1,2]:\n pass"); - } - - @Test - public void testWhile() { - doTest("while False: pass"); - } - - @Test - public void testForBreakContinue() { - String source = "for i in range(10):\n" + - " if i == 3:\n" + - " break\n" + - " else:\n" + - " continue\n" + - "else:\n" + - " print('else')"; - doTest(source); - } - - @Test - public void testWhileBreakContinue() { - String source = "i = 0\n" + - "while i < 10:\n" + - " if i == 3:\n" + - " break\n" + - " else:\n" + - " i += 1\n" + - " continue\n" + - "else:\n" + - " print('else')"; - doTest(source); - } - - @Test - public void testBreakFromWith() { - String source = "for i in range(10):\n" + - " with foo() as cm:\n" + - " break\n"; - doTest(source); - } - - @Test - public void testBreakFromTry() { - String source = "for i in range(10):\n" + - " try:\n" + - " break\n" + - " finally:" + - " print('finally')"; - doTest(source); - } - - @Test - public void testBreakFromExcept() { - String source = "for i in range(10):\n" + - " try:\n" + - " 1 / 0\n" + - " except RuntimeError as e:" + - " break"; - doTest(source); - } - - @Test - public void testBreakFromFinally() { - String source = "for i in range(10):\n" + - " try:\n" + - " if i:\n" + - " break\n" + - " print(i)\n" + - " finally:\n" + - " print('finally')\n" + - " break"; - doTest(source); - } - - @Test - public void testReturnFromWith() { - String source = "def foo():\n" + - " for i in range(10):\n" + - " with foo() as cm:\n" + - " return a\n"; - doTest(source); - } - - @Test - public void testReturnFromTry() { - String source = "def foo():\n" + - " for i in range(10):\n" + - " try:\n" + - " return a\n" + - " finally:" + - " print('finally')"; - doTest(source); - } - - @Test - public void testReturnFromExcept() { - String source = "def foo():\n" + - " for i in range(10):\n" + - " try:\n" + - " 1 / 0\n" + - " except RuntimeError as e:" + - " return a"; - doTest(source); - } - - @Test - public void testReturnFromFinally() { - String source = "def foo():\n" + - " for i in range(10):\n" + - " try:\n" + - " if i:\n" + - " return a\n" + - " print(i)\n" + - " finally:\n" + - " print('finally')\n" + - " return b"; - doTest(source); - } - - @Test - public void testFinallyCancelReturn() { - String source = "def foo():\n" + - " for i in range(10):\n" + - " try:\n" + - " return a\n" + - " finally:" + - " continue"; - doTest(source); - } - - @Test - public void testTryExcept() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "except TypeError as e:\n" + - " print('except1')\n" + - "except ValueError as e:\n" + - " print('except2')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testTryExceptBare() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "except TypeError as e:\n" + - " print('except1')\n" + - "except:\n" + - " print('except bare')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testTryFinally() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "finally:\n" + - " print('finally')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testTryFinallyNested() { - String source = "def foo(obj):\n" + - " for x in obj:\n" + - " print(x)\n" + - " try:\n" + - " try:\n" + - " print('try')\n" + - " finally:\n" + - " print('finally1')\n" + - " finally:\n" + - " print('finally2')\n"; - doTest(source); - } - - @Test - public void testTryExceptFinally() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "except TypeError as e:\n" + - " print('except1')\n" + - "except ValueError as e:\n" + - " print('except2')\n" + - "finally:\n" + - " print('finally')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testTryExceptElse() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "except TypeError as e:\n" + - " print('except1')\n" + - "except ValueError as e:\n" + - " print('except2')\n" + - "else:\n" + - " print('else')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testTryExceptElseFinally() { - String s = "print('before')\n" + - "try:\n" + - " print('try')\n" + - "except TypeError as e:\n" + - " print('except1')\n" + - "except ValueError as e:\n" + - " print('except2')\n" + - "else:\n" + - " print('else')\n" + - "finally:\n" + - " print('finally')\n" + - "print('after')\n"; - doTest(s); - } - - @Test - public void testWith() { - String s = "print('before')\n" + - "with open('/dev/null') as f:\n" + - " f.write('foo')\n" + - "print('after')"; - doTest(s); - } - - @Test - public void testWithMultiple() { - String s = "print('before')\n" + - "with open('/dev/null') as f, open('/tmp/foo'):\n" + - " f.write('foo')\n" + - "print('after')"; - doTest(s); - } - - @Test - public void testDefun() { - String source = "def docompute(num, num2=5):\n" + - " return (num, num2)\n"; - doTest(source); - } - - @Test - public void testReturnPlain() { - String source = "def foo():\n" + - " return\n"; - doTest(source); - } - - @Test - public void testClosure() { - String s = "def foo():\n" + - " x = 1\n" + - " def bar():\n" + - " nonlocal x\n" + - " print(x)\n" + - " x = 2\n" + - " bar()\n" + - " print(x)\n" + - " x = 3\n"; - doTest(s); - } - - @Test - public void testIf() { - String source = "if False:\n" + - " print(True)\n" + - "else:\n" + - " print(False)\n"; - doTest(source); - } - - @Test - public void testIfExpression() { - doTest("t if cond else f\n"); - } - - @Test - public void testClass() { - String source = "class Foo:\n" + - " c = 64\n" + - " def __init__(self, arg):\n" + - " self.var = arg\n"; - doTest(source); - } - - @Test - public void testSuper() { - String source = "class Foo:\n" + - " def boo(self):\n" + - " print('boo')\n" + - "class Bar(Foo):\n" + - " def boo(self):\n" + - " super().boo()\n"; - doTest(source); - } - - @Test - public void testEmptyList() { - doTest("[]"); - } - - @Test - public void testEmptyTuple() { - doTest("()"); - } - - @Test - public void testEmptyDict() { - doTest("{}"); - } - - @Test - public void testTupleLiteralInts() { - doTest("(1, 2, 3)"); - } - - @Test - public void testTupleLiteralDoubles() { - doTest("(1.0, 2.0, 3.0)"); - } - - @Test - public void testTupleLiteralBooleans() { - doTest("(False, True)"); - } - - @Test - public void testTupleLiteralObjects() { - doTest("('a', 1, None)"); - } - - @Test - public void testTupleLiteralMixed() { - doTest("(1, 2, 3.0)"); - } - - @Test - public void testTupleLiteralNonConstant() { - doTest("(1, 2, [3])"); - } - - @Test - public void testTupleLiteralMixedIntegers() { - doTest("(1, 17179869184, 3)"); - } - - @Test - public void testTupleLiteralExpand() { - doTest("(1, 2, 3, *a, 5)"); - } - - @Test - public void testListLiteral() { - doTest("[1, 2, 3]"); - } - - @Test - public void testListLiteralExpand() { - doTest("[1, 2, 3, *a, 5]"); - } - - @Test - public void testSetLiteral() { - doTest("{1, 2, 3}"); - } - - @Test - public void testSetLiteralExpand() { - doTest("{1, 2, 3, *a, 5}"); - } - - @Test - public void testDictLiteral() { - doTest("{'a': 'b', 1: 2}"); - } - - @Test - public void testDictLiteralExpand() { - doTest("{'a': 'b', 1: 2, **a, None: True}"); - } - - @Test - public void testUnpack() { - doTest("a, b = 1, 2"); - } - - @Test - public void testUnpackEx() { - doTest("a, *b, c = 1, 2, 3, 4, 5"); - } - - @Test - public void testListComprehension() { - String source = "[str(x) for y in [[1, 2, 3], [4, 5, 6]] for x in y if x < 5]"; - doTest(source); - } - - @Test - public void testFString() { - doTest("f'before{a}middle{b!r:5}after'"); - } - - @Test - public void testStringSurrogates() { - doTest("'\\U00010400' != '\\uD801\\uDC00'"); - } - - @Test - public void testNestedListComprehension() { - String source = "[[x for x in range(5)] for y in range(3)]"; - doTest(source); - } - - @Test - public void testSetComprehension() { - String source = "{x * 2 for x in range(10) if x % 2 == 0}"; - doTest(source); - } - - @Test - public void testDictComprehension() { - String source = "{x: str(x) for x in range(10)}"; - doTest(source); - } - - @Test - public void testLambda() { - doTest("lambda x, *args: args[x]"); - } - - @Test - public void testYieldPlain() { - String source = "def gen(a):\n" + - " yield\n"; - doTest(source); - } - - @Test - public void testYieldValue() { - String source = "def gen(a):\n" + - " yield a + 1\n"; - doTest(source); - } - - @Test - public void testYieldFrom() { - String source = "def gen(a):\n" + - " yield from a\n"; - doTest(source); - } - - @Test - public void testCoroutine() { - String source = "async def foo(a):\n" + - " await a\n"; - doTest(source); - } - - @Test - public void testYieldExpression() { - String source = "def gen(a):\n" + - " b = yield a\n"; - doTest(source); - } - - @Test - public void testGeneratorComprehension() { - String source = "(str(x) for y in [[1, 2, 3], [4, 5, 6]] for x in y if x < 5)"; - doTest(source); - } - - @Test - public void testExtendedArgs() { - StringBuilder source = new StringBuilder(); - source.append("if a:\n"); - for (int i = 0; i < 260; i++) { - source.append(String.format(" a.f%d('%d')\n", i, i)); - } - source.append("else:\n"); - source.append(" print('else')"); - doTest(source.toString()); - } - - @Test - public void testBenchmark() { - String source = "def docompute(num):\n" + - " for i in range(num):\n" + - " sum_ = 0.0\n" + - " j = 0\n" + - " while j < num:\n" + - " sum_ += 1.0 / (((i + j) * (i + j + 1) >> 1) + i + 1)\n" + - " j += 1\n" + - "\n" + - " return sum_\n" + - "\n" + - "\n" + - "def measure(num):\n" + - " for run in range(num):\n" + - " sum_ = docompute(10000) # 10000\n" + - " print('sum', sum_)\n" + - "\n" + - "\n" + - "def __benchmark__(num=5):\n" + - " measure(num)\n"; - doTest(source); - } - - @Test - public void testBenchmark2() { - String source = "" + - "class HandlerTask(Task):\n" + - " def __init__(self,i,p,w,s,r):\n" + - " global Task\n" + - " x = 0\n" + - " raise ValueError\n" + - // " def f():\n" + - // " nonlocal x\n" + - // " x = 1\n" + - " Task.__init__(self,i,p,w,s,r)\n"; - doTest(source); - } - - @Test - public void testImport() { - String source = "" + - "if __name__ == '__main__':\n" + - " import sys\n" + - " if not (len(sys.argv) == 1 and sys.argv[0] == 'java_embedding_bench'):\n" + - " import time\n" + - " start = time.time()\n" + - " if len(sys.argv) >= 2:\n" + - " num = int(sys.argv[1])\n" + - " __benchmark__(num)\n" + - " else:\n" + - " __benchmark__()\n" + - " print(\"%s took %s s\" % (__file__, time.time() - start))\n"; - doTest(source); - } - - @Test - public void testImportAs() { - doTest("import a.b.c as d"); - } - - @Test - public void testImportFrom() { - doTest("from math import sqrt, sin as sine"); - } - - @Test - public void testImportStar() { - doTest("from a.b import *"); - } - - @Test - public void testEval() { - doTest("1", InputType.EVAL); - } - - @Test - public void testSingle() { - doTest("1", InputType.SINGLE); - } - - @Test - public void testLoadClassDefRef() { - String s = "def f(x): \n" + - " class C: y = x\n" + - "f(1)"; - doTest(s); - } - - @Test - public void testNamedExpr() { - String s = "if x := g():\n print(x)\n"; - doTest(s); - } - - @Test - public void testMatchValueConst() { - String source = "" + - "match 1:\n" + - " case 1:\n" + - " pass\n"; - doTest(source); - } - - @Test - public void testMatchValue() { - String source = "" + - "s = 1\n" + - "match s:\n" + - " case 1:\n" + - " pass\n"; - doTest(source); - } - - @Test - public void testMatchValueWithDefault() { - String source = "" + - "s = 1\n" + - "match s:\n" + - " case 1:\n" + - " pass\n" + - " case _:\n" + - " pass\n"; - doTest(source); - } - - @Test - public void testMatchSingletonBoolean() { - String source = "" + - "match 1:\n" + - " case True:\n" + - " pass\n"; - doTest(source); - } - - @Test - public void testMatchSingletonNone() { - String source = "" + - "match 1:\n" + - " case None:\n" + - " pass\n"; - doTest(source); - } - - @Test - public void testGuard() { - String source = "" + - "x = 1\n" + - "match 1:\n" + - " case 1 if x == 1:\n" + - " x\n"; - doTest(source); - } - - @Test - public void testMatchAs() { - String source = "" + - "match 1:\n" + - " case 1 as x:\n" + - " x\n"; - doTest(source); - } - - @Test - public void testMatchAs2() { - String source = "" + - "match 1:\n" + - " case 1 as x:\n" + - " x\n" + - " case 2 as y:\n" + - " x\n"; - doTest(source); - } - - @Test - public void testMatchAsDefault() { - String source = "" + - "match 1:\n" + - " case 1 as x:\n" + - " x\n" + - " case _:\n" + - " x\n"; - doTest(source); - } - - @Test - public void testMatchAsGuard() { - String source = "" + - "match 1:\n" + - " case 1 as x if x == 1:\n" + - " x\n"; - doTest(source); - } - - @Test - public void testWildcard() { - String source = "" + - "match 1:\n" + - " case _:\n" + - " pass"; - doTest(source); - } - - @Test - public void testSeq() { - String source = "" + - "match (1):\n" + - " case [1]:\n" + - " pass"; - doTest(source); - } - - @Test - public void testSeqWildcard() { - String source = "" + - "match (1):\n" + - " case [_]:\n" + - " pass"; - doTest(source); - } - - @Test - public void testSeqWildcardStar() { - String source = "" + - "match (1):\n" + - " case [*_]:\n" + - " pass"; - doTest(source); - } - - @Test - public void testSeqWildcardSubscript() { - String source = "" + - "match (1, 2):\n" + - " case [_, x]:\n" + - " x"; - doTest(source); - } - - @Test - public void testSeqWildcardStarSubscript() { - String source = "" + - "match (1, 2, 3):\n" + - " case [*_, y]:\n" + - " y"; - doTest(source); - } - - @Test - public void testMatchClass() { - String source = "" + - "match 1:\n" + - " case int(x):\n" + - " pass"; - doTest(source); - } - - @Test - public void testMatchOr() { - String source = "" + - "match 0:\n" + - " case 0 | 1:\n" + - " pass"; - doTest(source); - } - - @Test - public void testMatchOrRot() { - String source = "" + - "match (0, 1):\n" + - " case ((a, b) | (b, a)):\n" + - " pass"; - doTest(source); - } - - @Test - public void testMatchMapping() { - String source = "" + - "match {1:1}:\n" + - " case {1:1}:\n" + - " pass"; - doTest(source); - } - - @Test - public void testMatchMappingSubpattern() { - String source = "" + - "match {1:1}:\n" + - " case {1:x}:\n" + - " x"; - doTest(source); - } - - @Test - public void testMatchMappingStar() { - String source = "" + - "match {1:1}:\n" + - " case {**z}:\n" + - " z"; - doTest(source); - } - - @Test - public void testAssignToDebug() { - checkSyntaxErrorMessage("obj.__debug__ = 1", "cannot assign to __debug__"); - checkSyntaxErrorMessage("__debug__ = 1", "cannot assign to __debug__"); - checkSyntaxErrorMessage("(a, __debug__, c) = (1, 2, 3)", "cannot assign to __debug__"); - checkSyntaxErrorMessage("(a, *__debug__, c) = (1, 2, 3)", "cannot assign to __debug__"); - checkSyntaxErrorMessage("f(__debug__=1)", "cannot assign to __debug__"); - checkSyntaxErrorMessage("__debug__: int", "cannot assign to __debug__"); - checkSyntaxErrorMessage("__debug__ += 1", "cannot assign to __debug__"); - checkSyntaxErrorMessage("def f(*, x=lambda __debug__:0): pass", "cannot assign to __debug__"); - checkSyntaxErrorMessage("def f(*args:(lambda __debug__:0)): pass", "cannot assign to __debug__"); - checkSyntaxErrorMessage("def f(**kwargs:(lambda __debug__:0)): pass", "cannot assign to __debug__"); - checkSyntaxErrorMessage("def f(**__debug__): pass", "cannot assign to __debug__"); - checkSyntaxErrorMessage("def f(*xx, __debug__): pass", "cannot assign to __debug__"); - checkSyntaxErrorMessage("match 1:\n\tcase 1 as __debug__:\n\t\tpass", "cannot assign to __debug__"); - } - - @Test - public void testNoStarredExprHere() { - checkSyntaxErrorMessage("*[1,2,3]", "can't use starred expression here"); - checkSyntaxErrorMessage("*a = range(5)", "starred assignment target must be in a list or tuple"); - checkSyntaxErrorMessage("b = *a", "can't use starred expression here"); - } - - @Test - public void testRepeatedKwArg() { - checkSyntaxErrorMessage("f(p, k1=50, *(1,2), k1=100)", "keyword argument repeated: k1"); - } - - @Test - public void testYieldOutsideFunction() { - checkSyntaxErrorMessage("yield", "'yield' outside function"); - checkSyntaxErrorMessage("class foo:yield 1", "'yield' outside function"); - checkSyntaxErrorMessage("class foo:yield from ()", "'yield from' outside function"); - checkSyntaxErrorMessage("def g(a:(yield)): pass", "'yield' outside function"); - checkSyntaxErrorMessage("yield x", "'yield' outside function"); - checkSyntaxErrorMessage("class C: yield 1", "'yield' outside function"); - } - - @Test - public void testReturnFromAsyncWith() { - String source = "async def f():\n" + - " async with a:\n" + - " return"; - doTest(source); - } - - @Test - public void testReturnFromAsyncWithT() { - String source = "async def f():\n" + - " async with a:\n" + - " async with b:\n" + - " return"; - doTest(source); - - } - - private void doTest(String src) { - doTest(src, InputType.FILE); - } - - private void doTest(String src, InputType type) { - checkCodeUnit(assemble(src, type)); - } - - private static void checkSyntaxErrorMessage(String src, String msg) { - try { - assemble(src, InputType.FILE); - fail("Expected SyntaxError: " + msg); - } catch (SyntaxError e) { - Assert.assertEquals(ParserCallbacks.ErrorType.Syntax, e.errorType); - MatcherAssert.assertThat(e.message, CoreMatchers.containsString(msg)); - } - } - - private static CodeUnit assemble(String src, InputType type) { - ParserCallbacks parserCallbacks = new TestParserCallbacksImpl(); - Parser parser = Compiler.createParser(src, parserCallbacks, type, false, false); - ModTy result = (ModTy) parser.parse(); - Compiler compiler = new Compiler(parserCallbacks); - CompilationUnit cu = compiler.compile(result, EnumSet.noneOf(Compiler.Flags.class), 2, EnumSet.noneOf(FutureFeature.class)); - return cu.assemble(); - } - - private void checkCodeUnit(CodeUnit co) { - String coString = co.toString(); - Path goldenFile = Paths.get(GraalPythonEnvVars.graalPythonTestsHome(), - "com.oracle.graal.python.test", "testData", "goldenFiles", - this.getClass().getSimpleName(), - name.getMethodName() + ".co"); - try { - if (!Files.exists(goldenFile)) { - Files.createDirectories(goldenFile.getParent()); - Files.writeString(goldenFile, coString); - } else { - Assert.assertEquals(Files.readString(goldenFile), coString); - } - } catch (IOException ex) { - fail(ex.getMessage()); - } - } - - static class TestParserCallbacksImpl implements ParserCallbacks { - @Override - public void safePointPoll() { - } - - @Override - public RuntimeException reportIncompleteSource(int line) { - fail("Unexpected call to reportIncompleteSource"); - throw new IllegalStateException("unreachable"); - } - - @Override - public RuntimeException onError(ErrorType errorType, SourceRange sourceRange, String message) { - throw new SyntaxError(errorType, message); - } - - @Override - public void onWarning(WarningType warningType, SourceRange sourceRange, String message) { - throw new AssertionError("Unexpected " + warningType + " warning: " + message); - } - } - - private static final class SyntaxError extends RuntimeException { - private static final long serialVersionUID = 6182610312044069775L; - - final ParserCallbacks.ErrorType errorType; - final String message; - - SyntaxError(ParserCallbacks.ErrorType errorType, String message) { - this.errorType = errorType; - this.message = message; - } - } -} diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/SourceMapTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/SourceMapTests.java deleted file mode 100644 index 90436d7fa6..0000000000 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/SourceMapTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.test.compiler; - -import java.util.Arrays; - -import org.junit.Assert; -import org.junit.Test; - -import com.oracle.graal.python.compiler.OpCodes; -import com.oracle.graal.python.compiler.SourceMap; - -public class SourceMapTests { - @Test - public void testRoundTrip() { - int[] startLines = new int[]{50, 50, 51, 51, 56, 256}; - int[] startColumns = new int[]{0, 128, 0, 129, 5, 597}; - int[] endLines = new int[]{50, 51, 51, 53, 59, 350}; - int[] endColumns = new int[]{10, 129, 1024, 130, 134, 598}; - int startLine = 49; - int startColumn = 0; - SourceMap.Builder builder = new SourceMap.Builder(startLine, startColumn); - byte[] code = new byte[6]; - Arrays.fill(code, (byte) OpCodes.NOP.ordinal()); - for (int i = 0; i < code.length; i++) { - builder.appendLocation(startLines[i], startColumns[i], endLines[i], endColumns[i]); - } - byte[] table = builder.build(); - SourceMap map = new SourceMap(code, table, startLine, startColumn); - Assert.assertArrayEquals(startLines, map.startLineMap); - Assert.assertArrayEquals(startColumns, map.startColumnMap); - Assert.assertArrayEquals(endLines, map.endLineMap); - Assert.assertArrayEquals(endColumns, map.endColumnMap); - } -} diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java index 43688cc1cd..49c8f8444a 100644 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java +++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -56,7 +56,6 @@ import com.oracle.graal.python.pegparser.tokenizer.CodePoints; import com.oracle.graal.python.pegparser.tokenizer.SourceRange; import com.oracle.graal.python.test.PythonTests; -import com.oracle.graal.python.test.compiler.CompilerTests.TestParserCallbacksImpl; public class UnparserTests extends PythonTests { @@ -110,4 +109,25 @@ private static String unparseConstant(ConstantValue constantValue) { private static String unparseConstant(ConstantValue constantValue, String kind) { return unparse(new ExprTy.Constant(constantValue, kind, SourceRange.ARTIFICIAL_RANGE)); } + + static class TestParserCallbacksImpl implements ParserCallbacks { + @Override + public void safePointPoll() { + } + + @Override + public RuntimeException reportIncompleteSource(int line) { + throw new AssertionError("Unexpected call to reportIncompleteSource"); + } + + @Override + public RuntimeException onError(ParserCallbacks.ErrorType errorType, SourceRange sourceRange, String message) { + throw new AssertionError(errorType + ": " + message); + } + + @Override + public void onWarning(ParserCallbacks.WarningType warningType, SourceRange sourceRange, String message) { + throw new AssertionError("Unexpected " + warningType + " warning: " + message); + } + } } 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 0d5bb0ea69..454d5678dc 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/__init__.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/__init__.py @@ -127,14 +127,7 @@ def ensure_packages(**package_specs): print(f'installing {package_specs} in {venv_dir}') system_python = install_venv(venv_dir) site_packages_dir = _venv_site_packages(venv_dir, py_executable) - extra_args = [] - if system_python or sys.implementation.name != "graalpy": - pass - elif __graalpython__.is_bytecode_dsl_interpreter: - extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] - else: - extra_args = ['--vm.Dpython.EnableBytecodeDSLInterpreter=false'] - subprocess.run([py_executable, *extra_args, "-m", "pip", "install", *package_specs], check=True) + subprocess.run([py_executable, "-m", "pip", "install", *package_specs], check=True) print(f'{package_specs} installed in {venv_dir}') pyvenv_site = str(site_packages_dir) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capi_logging.py b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capi_logging.py index 3b4a9e5ab5..1a032d5a22 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capi_logging.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capi_logging.py @@ -107,9 +107,6 @@ def test_private_log_handles_long_formatted_messages(): print("done") """) args = [sys.executable, "--experimental-options=true", "--python.EnableDebuggingBuiltins"] - if not __graalpython__.is_native: - bytecode_dsl = str(__graalpython__.is_bytecode_dsl_interpreter).lower() - args.append(f"--vm.Dpython.EnableBytecodeDSLInterpreter={bytecode_dsl}") args += ["--log.python.capi.PythonCextBuiltins.level=INFO", "-c", script] 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 75ff3a6377..012aaa0261 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 @@ -60,7 +60,6 @@ ARGS = ['--experimental-options', f'--log.file={os.devnull}', '--python.EnableDebuggingBuiltins'] if not __graalpython__.is_native: ARGS += [f'--vm.Djdk.graal.LogFile={os.devnull}'] - ARGS += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] COMMAND = [sys.executable, *ARGS, str(MODULE_PATH)] @@ -190,8 +189,6 @@ def test_native_weakref_shutdown_skips_c_retained_object(): '--experimental-options', '--python.EnableDebuggingBuiltins', ] - if not __graalpython__.is_native: - args += [f'--vm.Dpython.EnableBytecodeDSLInterpreter={str(__graalpython__.is_bytecode_dsl_interpreter).lower()}'] code = textwrap.dedent(""" import gc import weakref diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_ssl_java_integration.py b/graalpython/com.oracle.graal.python.test/src/tests/test_ssl_java_integration.py index 38da878874..ce6369ecb7 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_ssl_java_integration.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_ssl_java_integration.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2022, 2026, 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 @@ -64,8 +64,4 @@ def test_load_default_verify_keystore(): env = os.environ.copy() env['JAVA_TOOL_OPTIONS'] = f"-Djavax.net.ssl.trustStore={curdir}/ssldata/signing_keystore.jks" - args = [] - if __graalpython__.is_bytecode_dsl_interpreter: - args += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true'] - - subprocess.run([sys.executable, *args, '-c', src], env=env, check=True) + subprocess.run([sys.executable, '-c', src], env=env, check=True) 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 539d5d8d53..f68a1ba067 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 @@ -100,10 +100,7 @@ def test_nested_windows_venv_preserves_base_executable(self): expected_base = os.path.realpath(getattr(sys, "_base_executable", sys.executable)) with tempfile.TemporaryDirectory() as outer_dir, tempfile.TemporaryDirectory() as inner_root: inner_dir = os.path.join(inner_root, "inner") - extra_args = [ - f'--vm.Dpython.EnableBytecodeDSLInterpreter={repr(__graalpython__.is_bytecode_dsl_interpreter).lower()}' - ] - subprocess.check_output([sys.executable] + extra_args + ["-m", "venv", outer_dir, "--without-pip"], stderr=subprocess.STDOUT) + subprocess.check_output([sys.executable, "-m", "venv", outer_dir, "--without-pip"], stderr=subprocess.STDOUT) outer_python = os.path.join(outer_dir, BINDIR, f"python{EXESUF}") out = subprocess.check_output([ outer_python, @@ -166,10 +163,7 @@ def test_create_and_use_basic_venv(self): run = None run_output = '' try: - 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) + subprocess.check_output([sys.executable, "-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: @@ -185,10 +179,7 @@ def test_create_and_use_venv_with_pip(self): run = None msg = '' try: - 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) + subprocess.check_output([sys.executable, "-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/testData/goldenFiles/CompilerTests/testAnnAssignment.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAnnAssignment.co deleted file mode 100644 index 4264711d71..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAnnAssignment.co +++ /dev/null @@ -1,10 +0,0 @@ -Disassembly of : - 1:0 - 1:11 0 SETUP_ANNOTATIONS - 1:9 - 1:11 1 LOAD_BYTE 12 - 1:0 - 1:1 3 STORE_NAME 0 (a) - 1:3 - 1:6 5 LOAD_NAME 1 (int) - 1:0 - 1:11 7 LOAD_NAME 2 (__annotations__) - 1:0 - 1:11 9 LOAD_STRING 0 ('a') - 1:0 - 1:11 11 STORE_SUBSCR - 1:0 - 1:11 12 LOAD_NONE - 1:0 - 1:11 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgAnnotations.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgAnnotations.co deleted file mode 100644 index 28d20dd2b2..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgAnnotations.co +++ /dev/null @@ -1,29 +0,0 @@ -Disassembly of : - 1:0 - 2:22 0 LOAD_STRING 0 ('b') - 1:18 - 1:19 2 LOAD_BYTE 2 - 1:0 - 2:22 4 LOAD_STRING 1 ('a') - 1:10 - 1:11 6 LOAD_BYTE 1 - 1:0 - 2:22 8 LOAD_STRING 2 ('c') - 1:24 - 1:25 10 LOAD_BYTE 3 - 1:0 - 2:22 12 LOAD_STRING 3 ('d') - 1:29 - 1:30 14 LOAD_BYTE 4 - 1:0 - 2:22 16 LOAD_STRING 4 ('e') - 1:36 - 1:37 18 LOAD_BYTE 5 - 1:0 - 2:22 20 COLLECTION_FROM_STACK 10 (dict) - 1:0 - 2:22 22 MAKE_FUNCTION 4 (foo) - 1:0 - 2:22 25 STORE_NAME 0 (foo) - 1:0 - 2:22 27 LOAD_NONE - 1:0 - 2:22 28 RETURN_VALUE - -Disassembly of foo: - 2:2 - 2:7 0 LOAD_GLOBAL 0 (print) - 2:8 - 2:9 2 LOAD_FAST 0 (a) - 2:11 - 2:12 4 LOAD_FAST 1 (b) - 2:14 - 2:15 6 LOAD_FAST 3 (c) - 2:17 - 2:18 8 LOAD_FAST 2 (d) - 2:20 - 2:21 10 LOAD_FAST 4 (e) - 2:2 - 2:22 12 COLLECTION_FROM_STACK 5 (Object[]) - 2:2 - 2:22 14 CALL_FUNCTION_VARARGS - 2:2 - 2:22 15 POP_TOP - 2:2 - 2:22 16 LOAD_NONE - 2:2 - 2:22 17 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgsCombination.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgsCombination.co deleted file mode 100644 index f5d33fa42e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testArgsCombination.co +++ /dev/null @@ -1,18 +0,0 @@ -Disassembly of : - 1:0 - 2:22 0 MAKE_FUNCTION 0 (foo) - 1:0 - 2:22 3 STORE_NAME 0 (foo) - 1:0 - 2:22 5 LOAD_NONE - 1:0 - 2:22 6 RETURN_VALUE - -Disassembly of foo: - 2:2 - 2:7 0 LOAD_GLOBAL 0 (print) - 2:8 - 2:9 2 LOAD_FAST 0 (a) - 2:11 - 2:12 4 LOAD_FAST 1 (b) - 2:14 - 2:15 6 LOAD_FAST 3 (c) - 2:17 - 2:18 8 LOAD_FAST 2 (d) - 2:20 - 2:21 10 LOAD_FAST 4 (e) - 2:2 - 2:22 12 COLLECTION_FROM_STACK 5 (Object[]) - 2:2 - 2:22 14 CALL_FUNCTION_VARARGS - 2:2 - 2:22 15 POP_TOP - 2:2 - 2:22 16 LOAD_NONE - 2:2 - 2:22 17 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAssignment.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAssignment.co deleted file mode 100644 index a6e4468847..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAssignment.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:4 - 1:6 0 LOAD_BYTE 12 - 1:0 - 1:1 2 STORE_NAME 0 (a) - 1:0 - 1:6 4 LOAD_NONE - 1:0 - 1:6 5 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignment.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignment.co deleted file mode 100644 index 8c2821cb4a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignment.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:5 - 1:9 2 LOAD_DOUBLE 0 (12.0) - 1:0 - 1:9 4 BINARY_OP 1 (INPLACE_ADD) - 1:0 - 1:1 6 STORE_NAME 0 (a) - 1:0 - 1:1 8 LOAD_NONE - 1:0 - 1:1 9 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentAttr.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentAttr.co deleted file mode 100644 index 9a0480198c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentAttr.co +++ /dev/null @@ -1,10 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:0 - 1:3 2 DUP_TOP - 1:0 - 1:3 3 LOAD_ATTR 1 (b) - 1:7 - 1:11 5 LOAD_DOUBLE 0 (12.0) - 1:0 - 1:11 7 BINARY_OP 1 (INPLACE_ADD) - 1:0 - 1:3 9 ROT_TWO - 1:0 - 1:3 10 STORE_ATTR 1 (b) - 1:0 - 1:3 12 LOAD_NONE - 1:0 - 1:3 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentSubscr.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentSubscr.co deleted file mode 100644 index 7550560a3b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testAugAssignmentSubscr.co +++ /dev/null @@ -1,13 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:0 - 1:4 2 DUP_TOP - 1:2 - 1:3 3 LOAD_NAME 1 (b) - 1:0 - 1:4 5 DUP_TOP - 1:0 - 1:4 6 ROT_THREE - 1:0 - 1:4 7 BINARY_SUBSCR - 1:8 - 1:12 8 LOAD_DOUBLE 0 (12.0) - 1:0 - 1:12 10 BINARY_OP 1 (INPLACE_ADD) generalizes: 8, 7 - 1:0 - 1:4 12 ROT_THREE - 1:0 - 1:4 13 STORE_SUBSCR - 1:0 - 1:4 14 LOAD_NONE - 1:0 - 1:4 15 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark.co deleted file mode 100644 index 4555d4fa51..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark.co +++ /dev/null @@ -1,83 +0,0 @@ -Disassembly of : - 1:0 - 9:15 0 MAKE_FUNCTION 0 (docompute) - 1:0 - 9:15 3 STORE_NAME 0 (docompute) - 12:0 - 15:22 5 MAKE_FUNCTION 0 (measure) - 12:0 - 15:22 8 STORE_NAME 1 (measure) - 18:22 - 18:23 10 LOAD_BYTE 5 - 18:0 - 19:16 12 COLLECTION_FROM_STACK 1 (Object[]) - 18:0 - 19:16 14 MAKE_FUNCTION 1 (__benchmark__) - 18:0 - 19:16 17 STORE_NAME 2 (__benchmark__) - 18:0 - 19:16 19 LOAD_NONE - 18:0 - 19:16 20 RETURN_VALUE - -Disassembly of docompute: - 2:13 - 2:18 0 LOAD_GLOBAL 0 (range) - 2:19 - 2:22 2 LOAD_FAST 0 (num) - 2:13 - 2:23 4 CALL_FUNCTION 1 - 2:4 - 7:18 6 GET_ITER - 2:4 - 7:18 >> 7 FOR_ITER 74 (to 81) - 2:8 - 2:9 9 STORE_FAST 1 (i) generalizes: 7 - 3:15 - 3:18 11 LOAD_DOUBLE 0 (0.0) - 3:8 - 3:12 13 STORE_FAST 2 (sum_) generalizes: 11 - 4:12 - 4:13 15 LOAD_BYTE 0 - 4:8 - 4:9 17 STORE_FAST 3 (j) generalizes: 15 - 5:14 - 5:15 >> 19 LOAD_FAST 3 (j) - 5:18 - 5:21 21 LOAD_FAST 0 (num) - 5:14 - 5:21 23 BINARY_OP 14 (LT) generalizes: 21, 19 - 5:8 - 7:18 25 POP_AND_JUMP_IF_FALSE 54 (to 79) generalizes: 23 - 6:12 - 6:16 29 LOAD_FAST 2 (sum_) - 6:20 - 6:23 31 LOAD_DOUBLE 1 (1.0) - 6:29 - 6:30 33 LOAD_FAST 1 (i) - 6:33 - 6:34 35 LOAD_FAST 3 (j) - 6:29 - 6:34 37 BINARY_OP 0 (ADD) generalizes: 35, 33 - 6:39 - 6:40 39 LOAD_FAST 1 (i) - 6:43 - 6:44 41 LOAD_FAST 3 (j) - 6:39 - 6:44 43 BINARY_OP 0 (ADD) generalizes: 41, 39 - 6:47 - 6:48 45 LOAD_BYTE 1 - 6:39 - 6:48 47 BINARY_OP 0 (ADD) generalizes: 45, 43 - 6:28 - 6:49 49 BINARY_OP 4 (MUL) generalizes: 47, 37 - 6:53 - 6:54 51 LOAD_BYTE 1 - 6:28 - 6:54 53 BINARY_OP 20 (RSHIFT) generalizes: 51, 49 - 6:58 - 6:59 55 LOAD_FAST 1 (i) - 6:27 - 6:59 57 BINARY_OP 0 (ADD) generalizes: 55, 53 - 6:62 - 6:63 59 LOAD_BYTE 1 - 6:27 - 6:63 61 BINARY_OP 0 (ADD) generalizes: 59, 57 - 6:20 - 6:64 63 BINARY_OP 8 (TRUEDIV) generalizes: 61, 31 - 6:12 - 6:64 65 BINARY_OP 1 (INPLACE_ADD) generalizes: 63, 29 - 6:12 - 6:16 67 STORE_FAST 2 (sum_) generalizes: 65 - 7:12 - 7:13 69 LOAD_FAST 3 (j) - 7:17 - 7:18 71 LOAD_BYTE 1 - 7:12 - 7:18 73 BINARY_OP 1 (INPLACE_ADD) generalizes: 71, 69 - 7:12 - 7:13 75 STORE_FAST 3 (j) generalizes: 73 - 7:12 - 7:13 77 JUMP_BACKWARD 58 (to 19) - 7:12 - 7:13 >> 79 JUMP_BACKWARD 72 (to 7) - 9:11 - 9:15 >> 81 LOAD_FAST 2 (sum_) - 9:4 - 9:15 83 RETURN_VALUE - -Disassembly of measure: - 13:15 - 13:20 0 LOAD_GLOBAL 0 (range) - 13:21 - 13:24 2 LOAD_FAST 0 (num) - 13:15 - 13:25 4 CALL_FUNCTION 1 - 13:4 - 14:31 6 GET_ITER - 13:4 - 14:31 >> 7 FOR_ITER 14 (to 21) - 13:8 - 13:11 9 STORE_FAST 1 (run) generalizes: 7 - 14:15 - 14:24 11 LOAD_GLOBAL 1 (docompute) - 14:25 - 14:30 13 LOAD_INT 0 (10000) - 14:15 - 14:31 15 CALL_FUNCTION 1 - 14:8 - 14:12 17 STORE_FAST 2 (sum_) - 14:8 - 14:31 19 JUMP_BACKWARD 12 (to 7) - 15:4 - 15:9 >> 21 LOAD_GLOBAL 2 (print) - 15:10 - 15:15 23 LOAD_STRING 1 ('sum') - 15:17 - 15:21 25 LOAD_FAST 2 (sum_) - 15:4 - 15:22 27 CALL_FUNCTION 2 - 15:4 - 15:22 29 POP_TOP - 15:4 - 15:22 30 LOAD_NONE - 15:4 - 15:22 31 RETURN_VALUE - -Disassembly of __benchmark__: - 19:4 - 19:11 0 LOAD_GLOBAL 0 (measure) - 19:12 - 19:15 2 LOAD_FAST 0 (num) - 19:4 - 19:16 4 CALL_FUNCTION 1 - 19:4 - 19:16 6 POP_TOP - 19:4 - 19:16 7 LOAD_NONE - 19:4 - 19:16 8 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark2.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark2.co deleted file mode 100644 index adb838b533..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBenchmark2.co +++ /dev/null @@ -1,40 +0,0 @@ -Disassembly of : - 1:0 - 6:37 0 LOAD_BUILD_CLASS - 1:0 - 6:37 1 MAKE_FUNCTION 0 (HandlerTask) - 1:0 - 6:37 4 LOAD_STRING 1 ('HandlerTask') - 1:18 - 1:22 6 LOAD_GLOBAL 0 (Task) - 1:0 - 6:37 8 COLLECTION_FROM_STACK 3 (Object[]) - 1:0 - 6:37 10 CALL_FUNCTION_VARARGS - 1:0 - 6:37 11 STORE_NAME 1 (HandlerTask) - 1:0 - 6:37 13 LOAD_NONE - 1:0 - 6:37 14 RETURN_VALUE - -Disassembly of HandlerTask: - 1:0 - 6:37 0 LOAD_NAME 0 (__name__) - 1:0 - 6:37 2 STORE_NAME 1 (__module__) - 1:0 - 6:37 4 LOAD_STRING 0 ('HandlerTask') - 1:0 - 6:37 6 STORE_NAME 2 (__qualname__) - 2:4 - 6:37 8 MAKE_FUNCTION 0 (HandlerTask.__init__) - 2:4 - 6:37 11 STORE_NAME 3 (__init__) - 2:4 - 6:37 13 LOAD_NONE - 2:4 - 6:37 14 RETURN_VALUE - -Disassembly of HandlerTask.__init__: - 4:12 - 4:13 0 LOAD_BYTE 0 - 4:8 - 4:9 2 STORE_FAST 6 (x) generalizes: 0 - 5:14 - 5:24 4 LOAD_GLOBAL 0 (ValueError) - 5:8 - 5:24 6 RAISE_VARARGS 1 - 6:8 - 6:12 8 LOAD_GLOBAL 1 (Task) - 6:8 - 6:37 10 LOAD_METHOD 2 (__init__) - 6:8 - 6:37 12 ROT_TWO - 6:22 - 6:26 13 LOAD_FAST 0 (self) - 6:27 - 6:28 15 LOAD_FAST 1 (i) - 6:29 - 6:30 17 LOAD_FAST 2 (p) - 6:31 - 6:32 19 LOAD_FAST 3 (w) - 6:33 - 6:34 21 LOAD_FAST 4 (s) - 6:35 - 6:36 23 LOAD_FAST 5 (r) - 6:8 - 6:37 25 COLLECTION_FROM_STACK 7 (Object[]) - 6:8 - 6:37 27 CALL_METHOD_VARARGS - 6:8 - 6:37 28 POP_TOP - 6:8 - 6:37 29 LOAD_NONE - 6:8 - 6:37 30 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBinaryOp.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBinaryOp.co deleted file mode 100644 index 0e69065fd0..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBinaryOp.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 1 - 1:0 - 1:5 4 BINARY_OP 0 (ADD) generalizes: 2, 0 - 1:0 - 1:5 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromExcept.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromExcept.co deleted file mode 100644 index 553fa6b234..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromExcept.co +++ /dev/null @@ -1,37 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_NAME 0 (range) - 1:15 - 1:17 2 LOAD_BYTE 10 - 1:9 - 1:18 4 CALL_FUNCTION 1 - 1:0 - 4:36 6 GET_ITER - 1:0 - 4:36 >> 7 FOR_ITER 50 (to 57) - 1:4 - 1:5 9 STORE_NAME 1 (i) - 2:2 - 4:36 11 NOP - 3:4 - 3:5 12 LOAD_BYTE 1 - 3:8 - 3:9 14 LOAD_BYTE 0 - 3:4 - 3:9 16 BINARY_OP 8 (TRUEDIV) generalizes: 14, 12 - 3:4 - 3:9 18 POP_TOP - 3:4 - 3:9 19 JUMP_FORWARD 36 (to 55) - 3:4 - 3:9 21 PUSH_EXC_INFO (exc handler 12 - 21; stack: 1) - 4:9 - 4:21 22 LOAD_NAME 2 (RuntimeError) - 4:2 - 4:36 24 MATCH_EXC_OR_JUMP 30 (to 54) - 4:2 - 4:36 28 UNWRAP_EXC - 4:2 - 4:36 29 STORE_NAME 3 (e) - 4:31 - 4:36 31 LOAD_NONE - 4:31 - 4:36 32 STORE_NAME 3 (e) - 4:31 - 4:36 34 DELETE_NAME 3 (e) - 4:31 - 4:36 36 POP_EXCEPT - 4:31 - 4:36 37 POP_TOP - 4:31 - 4:36 38 JUMP_FORWARD 19 (to 57) - 4:31 - 4:36 40 LOAD_NONE - 4:31 - 4:36 41 STORE_NAME 3 (e) - 4:31 - 4:36 43 DELETE_NAME 3 (e) - 4:31 - 4:36 45 POP_EXCEPT - 4:31 - 4:36 46 JUMP_FORWARD 9 (to 55) - 4:31 - 4:36 48 LOAD_NONE (exc handler 31 - 40; stack: 2) - 4:31 - 4:36 49 STORE_NAME 3 (e) - 4:31 - 4:36 51 DELETE_NAME 3 (e) - 4:31 - 4:36 53 END_EXC_HANDLER - 4:31 - 4:36 >> 54 END_EXC_HANDLER (exc handler 22 - 31; stack: 2 | exc handler 40 - 54; stack: 2) - 4:31 - 4:36 >> 55 JUMP_BACKWARD 48 (to 7) - 4:31 - 4:36 >> 57 LOAD_NONE - 4:31 - 4:36 58 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromFinally.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromFinally.co deleted file mode 100644 index 7e9fd91c28..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromFinally.co +++ /dev/null @@ -1,42 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_NAME 0 (range) - 1:15 - 1:17 2 LOAD_BYTE 10 - 1:9 - 1:18 4 CALL_FUNCTION 1 - 1:0 - 8:9 6 GET_ITER - 1:0 - 8:9 >> 7 FOR_ITER 59 (to 66) - 1:4 - 1:5 9 STORE_NAME 1 (i) - 2:2 - 8:9 11 NOP - 3:7 - 3:8 12 LOAD_NAME 1 (i) - 3:4 - 4:11 14 POP_AND_JUMP_IF_FALSE 17 (to 31) - 7:4 - 7:9 18 LOAD_NAME 2 (print) - 7:10 - 7:19 20 LOAD_STRING 0 ('finally') - 7:4 - 7:20 22 CALL_FUNCTION 1 - 7:4 - 7:20 24 POP_TOP - 8:4 - 8:9 25 POP_TOP - 8:4 - 8:9 26 JUMP_FORWARD 40 (to 66) - 8:4 - 8:9 28 POP_TOP - 8:4 - 8:9 29 JUMP_FORWARD 37 (to 66) - 5:4 - 5:9 >> 31 LOAD_NAME 2 (print) - 5:10 - 5:11 33 LOAD_NAME 1 (i) - 5:4 - 5:12 35 CALL_FUNCTION 1 - 5:4 - 5:12 37 POP_TOP - 5:4 - 5:12 38 JUMP_FORWARD 16 (to 54) - 5:4 - 5:12 40 PUSH_EXC_INFO (exc handler 12 - 18; stack: 1 | exc handler 31 - 40; stack: 1) - 7:4 - 7:9 41 LOAD_NAME 2 (print) - 7:10 - 7:19 43 LOAD_STRING 0 ('finally') - 7:4 - 7:20 45 CALL_FUNCTION 1 - 7:4 - 7:20 47 POP_TOP - 8:4 - 8:9 48 POP_EXCEPT - 8:4 - 8:9 49 POP_TOP - 8:4 - 8:9 50 POP_TOP - 8:4 - 8:9 51 JUMP_FORWARD 15 (to 66) - 8:4 - 8:9 53 END_EXC_HANDLER (exc handler 41 - 53; stack: 2) - 7:4 - 7:9 >> 54 LOAD_NAME 2 (print) - 7:10 - 7:19 56 LOAD_STRING 0 ('finally') - 7:4 - 7:20 58 CALL_FUNCTION 1 - 7:4 - 7:20 60 POP_TOP - 8:4 - 8:9 61 POP_TOP - 8:4 - 8:9 62 JUMP_FORWARD 4 (to 66) - 8:4 - 8:9 64 JUMP_BACKWARD 57 (to 7) - 8:4 - 8:9 >> 66 LOAD_NONE - 8:4 - 8:9 67 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromTry.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromTry.co deleted file mode 100644 index b03b3df95b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromTry.co +++ /dev/null @@ -1,28 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_NAME 0 (range) - 1:15 - 1:17 2 LOAD_BYTE 10 - 1:9 - 1:18 4 CALL_FUNCTION 1 - 1:0 - 4:30 6 GET_ITER - 1:0 - 4:30 >> 7 FOR_ITER 35 (to 42) - 1:4 - 1:5 9 STORE_NAME 1 (i) - 2:2 - 4:30 11 NOP - 4:14 - 4:19 12 LOAD_NAME 2 (print) - 4:20 - 4:29 14 LOAD_STRING 0 ('finally') - 4:14 - 4:30 16 CALL_FUNCTION 1 - 4:14 - 4:30 18 POP_TOP - 4:14 - 4:30 19 POP_TOP - 4:14 - 4:30 20 JUMP_FORWARD 22 (to 42) - 4:14 - 4:30 22 JUMP_FORWARD 11 (to 33) - 4:14 - 4:30 24 PUSH_EXC_INFO - 4:14 - 4:19 25 LOAD_NAME 2 (print) - 4:20 - 4:29 27 LOAD_STRING 0 ('finally') - 4:14 - 4:30 29 CALL_FUNCTION 1 - 4:14 - 4:30 31 POP_TOP - 4:14 - 4:30 32 END_EXC_HANDLER (exc handler 25 - 32; stack: 2) - 4:14 - 4:19 >> 33 LOAD_NAME 2 (print) - 4:20 - 4:29 35 LOAD_STRING 0 ('finally') - 4:14 - 4:30 37 CALL_FUNCTION 1 - 4:14 - 4:30 39 POP_TOP - 4:14 - 4:30 40 JUMP_BACKWARD 33 (to 7) - 4:14 - 4:30 >> 42 LOAD_NONE - 4:14 - 4:30 43 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromWith.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromWith.co deleted file mode 100644 index 84ae10c9b5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testBreakFromWith.co +++ /dev/null @@ -1,20 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_NAME 0 (range) - 1:15 - 1:17 2 LOAD_BYTE 10 - 1:9 - 1:18 4 CALL_FUNCTION 1 - 1:0 - 3:9 6 GET_ITER - 1:0 - 3:9 >> 7 FOR_ITER 20 (to 27) - 1:4 - 1:5 9 STORE_NAME 1 (i) - 2:7 - 2:10 11 LOAD_NAME 2 (foo) - 2:7 - 2:12 13 CALL_FUNCTION 0 - 2:2 - 3:9 15 SETUP_WITH - 2:16 - 2:18 16 STORE_NAME 3 (cm) - 2:2 - 3:9 18 LOAD_NONE - 2:2 - 3:9 19 EXIT_WITH - 2:2 - 3:9 20 POP_TOP - 2:2 - 3:9 21 JUMP_FORWARD 6 (to 27) - 2:2 - 3:9 23 LOAD_NONE - 2:2 - 3:9 24 EXIT_WITH (exc handler 16 - 18; stack: 3) - 2:2 - 3:9 25 JUMP_BACKWARD 18 (to 7) - 2:2 - 3:9 >> 27 LOAD_NONE - 2:2 - 3:9 28 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCall.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCall.co deleted file mode 100644 index fea3bb5b57..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCall.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (range) - 1:6 - 1:9 2 LOAD_NAME 1 (num) - 1:0 - 1:10 4 CALL_FUNCTION 1 - 1:0 - 1:10 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallKeyword.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallKeyword.co deleted file mode 100644 index fffa23451d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallKeyword.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:12 2 LOAD_STRING 0 ('test') - 1:0 - 1:22 4 COLLECTION_FROM_STACK 1 (Object[]) - 1:18 - 1:21 6 LOAD_STRING 1 (';') - 1:14 - 1:21 8 MAKE_KEYWORD 2 ('end') - 1:0 - 1:22 10 COLLECTION_FROM_STACK 1 (PKeyword[]) - 1:0 - 1:22 12 CALL_FUNCTION_KW - 1:0 - 1:22 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarArgs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarArgs.co deleted file mode 100644 index 09da558c95..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarArgs.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:0 - 1:3 0 LOAD_NAME 0 (foo) - 1:4 - 1:5 2 LOAD_BYTE 1 - 1:0 - 1:20 4 COLLECTION_FROM_STACK 1 (Object[]) - 1:8 - 1:9 6 LOAD_NAME 1 (a) - 1:0 - 1:20 8 COLLECTION_ADD_COLLECTION 0 (Object[]) - 1:11 - 1:12 10 LOAD_BYTE 2 - 1:0 - 1:20 12 COLLECTION_ADD_STACK 1 (Object[]) - 1:15 - 1:16 14 LOAD_NAME 2 (b) - 1:0 - 1:20 16 COLLECTION_ADD_COLLECTION 0 (Object[]) - 1:18 - 1:19 18 LOAD_BYTE 3 - 1:0 - 1:20 20 COLLECTION_ADD_STACK 1 (Object[]) - 1:0 - 1:20 22 CALL_FUNCTION_VARARGS - 1:0 - 1:20 23 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarKwargs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarKwargs.co deleted file mode 100644 index 8df3eaf84b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCallMultiStarKwargs.co +++ /dev/null @@ -1,21 +0,0 @@ -Disassembly of : - 1:0 - 1:3 0 LOAD_NAME 0 (foo) - 1:0 - 1:28 2 COLLECTION_FROM_STACK 0 (Object[]) - 1:0 - 1:28 4 LOAD_STRING 0 ('a') - 1:6 - 1:7 6 LOAD_BYTE 1 - 1:0 - 1:28 8 COLLECTION_FROM_STACK 2 (dict) - 1:11 - 1:12 10 LOAD_NAME 1 (a) - 1:0 - 1:28 12 KWARGS_DICT_MERGE - 1:0 - 1:28 13 LOAD_STRING 1 ('b') - 1:16 - 1:17 15 LOAD_BYTE 2 - 1:0 - 1:28 17 COLLECTION_FROM_STACK 2 (dict) - 1:0 - 1:28 19 KWARGS_DICT_MERGE - 1:21 - 1:22 20 LOAD_NAME 2 (b) - 1:0 - 1:28 22 KWARGS_DICT_MERGE - 1:0 - 1:28 23 LOAD_STRING 2 ('c') - 1:26 - 1:27 25 LOAD_BYTE 3 - 1:0 - 1:28 27 COLLECTION_FROM_STACK 2 (dict) - 1:0 - 1:28 29 KWARGS_DICT_MERGE - 1:0 - 1:28 30 COLLECTION_FROM_COLLECTION 0 (PKeyword[]) - 1:0 - 1:28 32 CALL_FUNCTION_KW - 1:0 - 1:28 33 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClass.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClass.co deleted file mode 100644 index 935c1c0231..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClass.co +++ /dev/null @@ -1,28 +0,0 @@ -Disassembly of : - 1:0 - 4:22 0 LOAD_BUILD_CLASS - 1:0 - 4:22 1 MAKE_FUNCTION 0 (Foo) - 1:0 - 4:22 4 LOAD_STRING 1 ('Foo') - 1:0 - 4:22 6 COLLECTION_FROM_STACK 2 (Object[]) - 1:0 - 4:22 8 CALL_FUNCTION_VARARGS - 1:0 - 4:22 9 STORE_NAME 0 (Foo) - 1:0 - 4:22 11 LOAD_NONE - 1:0 - 4:22 12 RETURN_VALUE - -Disassembly of Foo: - 1:0 - 4:22 0 LOAD_NAME 0 (__name__) - 1:0 - 4:22 2 STORE_NAME 1 (__module__) - 1:0 - 4:22 4 LOAD_STRING 0 ('Foo') - 1:0 - 4:22 6 STORE_NAME 2 (__qualname__) - 2:8 - 2:10 8 LOAD_BYTE 64 - 2:4 - 2:5 10 STORE_NAME 3 (c) - 3:4 - 4:22 12 MAKE_FUNCTION 0 (Foo.__init__) - 3:4 - 4:22 15 STORE_NAME 4 (__init__) - 3:4 - 4:22 17 LOAD_NONE - 3:4 - 4:22 18 RETURN_VALUE - -Disassembly of Foo.__init__: - 4:19 - 4:22 0 LOAD_FAST 1 (arg) - 4:8 - 4:12 2 LOAD_FAST 0 (self) - 4:8 - 4:16 4 STORE_ATTR 0 (var) - 4:8 - 4:22 6 LOAD_NONE - 4:8 - 4:22 7 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotations.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotations.co deleted file mode 100644 index 8e726ca86a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotations.co +++ /dev/null @@ -1,24 +0,0 @@ -Disassembly of : - 1:0 - 2:14 0 LOAD_BUILD_CLASS - 1:0 - 2:14 1 MAKE_FUNCTION 0 (Foo) - 1:0 - 2:14 4 LOAD_STRING 1 ('Foo') - 1:0 - 2:14 6 COLLECTION_FROM_STACK 2 (Object[]) - 1:0 - 2:14 8 CALL_FUNCTION_VARARGS - 1:0 - 2:14 9 STORE_NAME 0 (Foo) - 1:0 - 2:14 11 LOAD_NONE - 1:0 - 2:14 12 RETURN_VALUE - -Disassembly of Foo: - 1:0 - 2:14 0 LOAD_NAME 0 (__name__) - 1:0 - 2:14 2 STORE_NAME 1 (__module__) - 1:0 - 2:14 4 LOAD_STRING 0 ('Foo') - 1:0 - 2:14 6 STORE_NAME 2 (__qualname__) - 1:0 - 2:14 8 SETUP_ANNOTATIONS - 2:8 - 2:9 9 LOAD_NAME 3 (a) - 2:10 - 2:13 11 LOAD_NAME 4 (str) - 2:8 - 2:14 13 BINARY_SUBSCR - 2:2 - 2:14 14 LOAD_NAME 5 (__annotations__) - 2:2 - 2:14 16 LOAD_STRING 1 ('attr') - 2:2 - 2:14 18 STORE_SUBSCR - 2:2 - 2:14 19 LOAD_NONE - 2:2 - 2:14 20 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotationsFuture.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotationsFuture.co deleted file mode 100644 index 9d65dabca4..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClassAnnotationsFuture.co +++ /dev/null @@ -1,28 +0,0 @@ -Disassembly of : - 1:0 - 1:34 0 LOAD_BYTE 0 - 1:0 - 1:34 2 LOAD_CONST 0 ([annotations]) - 1:0 - 1:34 4 IMPORT_NAME 0 (__future__) - 1:0 - 1:34 6 IMPORT_FROM 1 (annotations) - 1:0 - 1:34 8 STORE_NAME 1 (annotations) - 1:0 - 1:34 10 POP_TOP - 2:0 - 3:14 11 LOAD_BUILD_CLASS - 2:0 - 3:14 12 MAKE_FUNCTION 0 (Foo) - 2:0 - 3:14 15 LOAD_STRING 2 ('Foo') - 2:0 - 3:14 17 COLLECTION_FROM_STACK 2 (Object[]) - 2:0 - 3:14 19 CALL_FUNCTION_VARARGS - 2:0 - 3:14 20 STORE_NAME 2 (Foo) - 2:0 - 3:14 22 LOAD_NONE - 2:0 - 3:14 23 RETURN_VALUE - -Disassembly of Foo: - 2:0 - 3:14 0 LOAD_NAME 0 (__name__) - 2:0 - 3:14 2 STORE_NAME 1 (__module__) - 2:0 - 3:14 4 LOAD_STRING 0 ('Foo') - 2:0 - 3:14 6 STORE_NAME 2 (__qualname__) - 2:0 - 3:14 8 SETUP_ANNOTATIONS - 3:2 - 3:14 9 LOAD_STRING 1 ('a[str]') - 3:2 - 3:14 11 LOAD_NAME 3 (__annotations__) - 3:2 - 3:14 13 LOAD_STRING 2 ('attr') - 3:2 - 3:14 15 STORE_SUBSCR - 3:2 - 3:14 16 LOAD_NONE - 3:2 - 3:14 17 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClosure.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClosure.co deleted file mode 100644 index 56a9cbb2bf..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testClosure.co +++ /dev/null @@ -1,34 +0,0 @@ -Disassembly of : - 1:0 - 9:9 0 MAKE_FUNCTION 0 (foo) - 1:0 - 9:9 3 STORE_NAME 0 (foo) - 1:0 - 9:9 5 LOAD_NONE - 1:0 - 9:9 6 RETURN_VALUE - -Disassembly of foo: - 2:8 - 2:9 0 LOAD_BYTE 1 - 2:4 - 2:5 2 STORE_DEREF 0 (x) - 3:4 - 6:13 4 LOAD_CLOSURE 0 (x) - 3:4 - 6:13 6 CLOSURE_FROM_STACK 1 - 3:4 - 6:13 8 MAKE_FUNCTION 8 (foo..bar) - 3:4 - 6:13 11 STORE_FAST 0 (bar) - 7:4 - 7:7 13 LOAD_FAST 0 (bar) - 7:4 - 7:9 15 CALL_FUNCTION 0 - 7:4 - 7:9 17 POP_TOP - 8:4 - 8:9 18 LOAD_GLOBAL 0 (print) - 8:10 - 8:11 20 LOAD_DEREF 0 (x) - 8:4 - 8:12 22 CALL_FUNCTION 1 - 8:4 - 8:12 24 POP_TOP - 9:8 - 9:9 25 LOAD_BYTE 3 - 9:4 - 9:5 27 STORE_DEREF 0 (x) - 9:4 - 9:9 29 LOAD_NONE - 9:4 - 9:9 30 RETURN_VALUE - -Disassembly of foo..bar: - 5:8 - 5:13 0 LOAD_GLOBAL 0 (print) - 5:14 - 5:15 2 LOAD_DEREF 0 (x) - 5:8 - 5:16 4 CALL_FUNCTION 1 - 5:8 - 5:16 6 POP_TOP - 6:12 - 6:13 7 LOAD_BYTE 2 - 6:8 - 6:9 9 STORE_DEREF 0 (x) - 6:8 - 6:13 11 LOAD_NONE - 6:8 - 6:13 12 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testComplexNumber.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testComplexNumber.co deleted file mode 100644 index f9b44f3856..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testComplexNumber.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE -2 - 1:5 - 1:7 2 LOAD_COMPLEX 0 (3.00000j) - 1:0 - 1:7 4 BINARY_OP 0 (ADD) - 1:0 - 1:7 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCoroutine.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCoroutine.co deleted file mode 100644 index 20f443e1a5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testCoroutine.co +++ /dev/null @@ -1,20 +0,0 @@ -Disassembly of : - 1:0 - 2:11 0 MAKE_FUNCTION 0 (foo) - 1:0 - 2:11 3 STORE_NAME 0 (foo) - 1:0 - 2:11 5 LOAD_NONE - 1:0 - 2:11 6 RETURN_VALUE - -Disassembly of foo: -Flags: CO_COROUTINE - 2:10 - 2:11 0 LOAD_FAST 0 (a) - 2:4 - 2:11 2 GET_AWAITABLE - 2:4 - 2:11 3 LOAD_NONE - 2:4 - 2:11 >> 4 SEND 10 (to 14) - 2:4 - 2:11 >> 6 YIELD_VALUE - 2:4 - 2:11 7 RESUME_YIELD - 2:4 - 2:11 8 JUMP_BACKWARD 4 (to 4) - 2:4 - 2:11 10 THROW 4 (to 14) (exc handler 7 - 10; stack: 1) - 2:4 - 2:11 12 JUMP_BACKWARD 6 (to 6) - 2:4 - 2:11 >> 14 POP_TOP - 2:4 - 2:11 15 LOAD_NONE - 2:4 - 2:11 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDefun.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDefun.co deleted file mode 100644 index 4d1a263674..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDefun.co +++ /dev/null @@ -1,13 +0,0 @@ -Disassembly of : - 1:24 - 1:25 0 LOAD_BYTE 5 - 1:0 - 2:21 2 COLLECTION_FROM_STACK 1 (Object[]) - 1:0 - 2:21 4 MAKE_FUNCTION 1 (docompute) - 1:0 - 2:21 7 STORE_NAME 0 (docompute) - 1:0 - 2:21 9 LOAD_NONE - 1:0 - 2:21 10 RETURN_VALUE - -Disassembly of docompute: - 2:11 - 2:14 0 LOAD_FAST 0 (num) - 2:16 - 2:20 2 LOAD_FAST 1 (num2) - 2:10 - 2:21 4 COLLECTION_FROM_STACK 2 (tuple) - 2:3 - 2:21 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDel.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDel.co deleted file mode 100644 index 54d256fe6d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDel.co +++ /dev/null @@ -1,4 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 DELETE_NAME 0 (a) - 1:0 - 1:5 2 LOAD_NONE - 1:0 - 1:5 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDelItem.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDelItem.co deleted file mode 100644 index 49b399bb8e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDelItem.co +++ /dev/null @@ -1,6 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 LOAD_NAME 0 (a) - 1:6 - 1:7 2 LOAD_BYTE 3 - 1:4 - 1:8 4 DELETE_SUBSCR - 1:0 - 1:8 5 LOAD_NONE - 1:0 - 1:8 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictComprehension.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictComprehension.co deleted file mode 100644 index de3503cf13..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictComprehension.co +++ /dev/null @@ -1,21 +0,0 @@ -Disassembly of : - 1:0 - 1:30 0 MAKE_FUNCTION 0 () - 1:20 - 1:25 3 LOAD_NAME 0 (range) - 1:26 - 1:28 5 LOAD_BYTE 10 - 1:20 - 1:29 7 CALL_FUNCTION 1 - 1:0 - 1:30 9 GET_ITER - 1:0 - 1:30 10 CALL_COMPREHENSION - 1:0 - 1:30 11 RETURN_VALUE - -Disassembly of : - 1:0 - 1:30 0 COLLECTION_FROM_STACK 0 (dict) - 1:0 - 1:30 2 LOAD_FAST 0 (.0) - 1:0 - 1:30 >> 4 FOR_ITER 16 (to 20) - 1:15 - 1:16 6 STORE_FAST 1 (x) generalizes: 4 - 1:1 - 1:2 8 LOAD_FAST 1 (x) - 1:4 - 1:7 10 LOAD_GLOBAL 0 (str) - 1:8 - 1:9 12 LOAD_FAST 1 (x) - 1:4 - 1:10 14 CALL_FUNCTION 1 - 1:0 - 1:30 16 ADD_TO_COLLECTION 3 (dict) - 1:0 - 1:30 18 JUMP_BACKWARD 14 (to 4) - 1:0 - 1:30 >> 20 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteral.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteral.co deleted file mode 100644 index 6fcc93833c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteral.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:1 - 1:4 0 LOAD_STRING 0 ('a') - 1:6 - 1:9 2 LOAD_STRING 1 ('b') - 1:11 - 1:12 4 LOAD_BYTE 1 - 1:14 - 1:15 6 LOAD_BYTE 2 - 1:0 - 1:16 8 COLLECTION_FROM_STACK 4 (dict) - 1:0 - 1:16 10 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteralExpand.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteralExpand.co deleted file mode 100644 index 8627b412b5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testDictLiteralExpand.co +++ /dev/null @@ -1,12 +0,0 @@ -Disassembly of : - 1:1 - 1:4 0 LOAD_STRING 0 ('a') - 1:6 - 1:9 2 LOAD_STRING 1 ('b') - 1:11 - 1:12 4 LOAD_BYTE 1 - 1:14 - 1:15 6 LOAD_BYTE 2 - 1:0 - 1:33 8 COLLECTION_FROM_STACK 4 (dict) - 1:19 - 1:20 10 LOAD_NAME 0 (a) - 1:0 - 1:33 12 COLLECTION_ADD_COLLECTION 0 (dict) - 1:22 - 1:26 14 LOAD_NONE - 1:28 - 1:32 15 LOAD_TRUE - 1:0 - 1:33 16 COLLECTION_ADD_STACK 2 (dict) - 1:0 - 1:33 18 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyDict.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyDict.co deleted file mode 100644 index 8eff73d097..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyDict.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:2 0 COLLECTION_FROM_STACK 0 (dict) - 1:0 - 1:2 2 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyList.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyList.co deleted file mode 100644 index 43ec999614..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyList.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:2 0 COLLECTION_FROM_STACK 0 (list) - 1:0 - 1:2 2 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyTuple.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyTuple.co deleted file mode 100644 index b38bdc6c2b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEmptyTuple.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:2 0 COLLECTION_FROM_STACK 0 (tuple) - 1:0 - 1:2 2 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEval.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEval.co deleted file mode 100644 index 4bd594ac98..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testEval.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_BYTE 1 - 1:0 - 1:1 2 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testExtendedArgs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testExtendedArgs.co deleted file mode 100644 index 88a6ee8d82..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testExtendedArgs.co +++ /dev/null @@ -1,1322 +0,0 @@ -Disassembly of : - 1:3 - 1:4 0 LOAD_NAME 0 (a) - 1:0 - 263:17 2 EXTENDED_ARG - 1:0 - 263:17 4 POP_AND_JUMP_IF_FALSE 2364 (to 2368) - 2:3 - 2:4 8 LOAD_NAME 0 (a) - 2:3 - 2:12 10 LOAD_METHOD 1 (f0) - 2:8 - 2:11 12 LOAD_STRING 0 ('0') - 2:3 - 2:12 14 CALL_METHOD 1 - 2:3 - 2:12 16 POP_TOP - 3:3 - 3:4 17 LOAD_NAME 0 (a) - 3:3 - 3:12 19 LOAD_METHOD 2 (f1) - 3:8 - 3:11 21 LOAD_STRING 1 ('1') - 3:3 - 3:12 23 CALL_METHOD 1 - 3:3 - 3:12 25 POP_TOP - 4:3 - 4:4 26 LOAD_NAME 0 (a) - 4:3 - 4:12 28 LOAD_METHOD 3 (f2) - 4:8 - 4:11 30 LOAD_STRING 2 ('2') - 4:3 - 4:12 32 CALL_METHOD 1 - 4:3 - 4:12 34 POP_TOP - 5:3 - 5:4 35 LOAD_NAME 0 (a) - 5:3 - 5:12 37 LOAD_METHOD 4 (f3) - 5:8 - 5:11 39 LOAD_STRING 3 ('3') - 5:3 - 5:12 41 CALL_METHOD 1 - 5:3 - 5:12 43 POP_TOP - 6:3 - 6:4 44 LOAD_NAME 0 (a) - 6:3 - 6:12 46 LOAD_METHOD 5 (f4) - 6:8 - 6:11 48 LOAD_STRING 4 ('4') - 6:3 - 6:12 50 CALL_METHOD 1 - 6:3 - 6:12 52 POP_TOP - 7:3 - 7:4 53 LOAD_NAME 0 (a) - 7:3 - 7:12 55 LOAD_METHOD 6 (f5) - 7:8 - 7:11 57 LOAD_STRING 5 ('5') - 7:3 - 7:12 59 CALL_METHOD 1 - 7:3 - 7:12 61 POP_TOP - 8:3 - 8:4 62 LOAD_NAME 0 (a) - 8:3 - 8:12 64 LOAD_METHOD 7 (f6) - 8:8 - 8:11 66 LOAD_STRING 6 ('6') - 8:3 - 8:12 68 CALL_METHOD 1 - 8:3 - 8:12 70 POP_TOP - 9:3 - 9:4 71 LOAD_NAME 0 (a) - 9:3 - 9:12 73 LOAD_METHOD 8 (f7) - 9:8 - 9:11 75 LOAD_STRING 7 ('7') - 9:3 - 9:12 77 CALL_METHOD 1 - 9:3 - 9:12 79 POP_TOP - 10:3 - 10:4 80 LOAD_NAME 0 (a) - 10:3 - 10:12 82 LOAD_METHOD 9 (f8) - 10:8 - 10:11 84 LOAD_STRING 8 ('8') - 10:3 - 10:12 86 CALL_METHOD 1 - 10:3 - 10:12 88 POP_TOP - 11:3 - 11:4 89 LOAD_NAME 0 (a) - 11:3 - 11:12 91 LOAD_METHOD 10 (f9) - 11:8 - 11:11 93 LOAD_STRING 9 ('9') - 11:3 - 11:12 95 CALL_METHOD 1 - 11:3 - 11:12 97 POP_TOP - 12:3 - 12:4 98 LOAD_NAME 0 (a) - 12:3 - 12:14 100 LOAD_METHOD 11 (f10) - 12:9 - 12:13 102 LOAD_STRING 10 ('10') - 12:3 - 12:14 104 CALL_METHOD 1 - 12:3 - 12:14 106 POP_TOP - 13:3 - 13:4 107 LOAD_NAME 0 (a) - 13:3 - 13:14 109 LOAD_METHOD 12 (f11) - 13:9 - 13:13 111 LOAD_STRING 11 ('11') - 13:3 - 13:14 113 CALL_METHOD 1 - 13:3 - 13:14 115 POP_TOP - 14:3 - 14:4 116 LOAD_NAME 0 (a) - 14:3 - 14:14 118 LOAD_METHOD 13 (f12) - 14:9 - 14:13 120 LOAD_STRING 12 ('12') - 14:3 - 14:14 122 CALL_METHOD 1 - 14:3 - 14:14 124 POP_TOP - 15:3 - 15:4 125 LOAD_NAME 0 (a) - 15:3 - 15:14 127 LOAD_METHOD 14 (f13) - 15:9 - 15:13 129 LOAD_STRING 13 ('13') - 15:3 - 15:14 131 CALL_METHOD 1 - 15:3 - 15:14 133 POP_TOP - 16:3 - 16:4 134 LOAD_NAME 0 (a) - 16:3 - 16:14 136 LOAD_METHOD 15 (f14) - 16:9 - 16:13 138 LOAD_STRING 14 ('14') - 16:3 - 16:14 140 CALL_METHOD 1 - 16:3 - 16:14 142 POP_TOP - 17:3 - 17:4 143 LOAD_NAME 0 (a) - 17:3 - 17:14 145 LOAD_METHOD 16 (f15) - 17:9 - 17:13 147 LOAD_STRING 15 ('15') - 17:3 - 17:14 149 CALL_METHOD 1 - 17:3 - 17:14 151 POP_TOP - 18:3 - 18:4 152 LOAD_NAME 0 (a) - 18:3 - 18:14 154 LOAD_METHOD 17 (f16) - 18:9 - 18:13 156 LOAD_STRING 16 ('16') - 18:3 - 18:14 158 CALL_METHOD 1 - 18:3 - 18:14 160 POP_TOP - 19:3 - 19:4 161 LOAD_NAME 0 (a) - 19:3 - 19:14 163 LOAD_METHOD 18 (f17) - 19:9 - 19:13 165 LOAD_STRING 17 ('17') - 19:3 - 19:14 167 CALL_METHOD 1 - 19:3 - 19:14 169 POP_TOP - 20:3 - 20:4 170 LOAD_NAME 0 (a) - 20:3 - 20:14 172 LOAD_METHOD 19 (f18) - 20:9 - 20:13 174 LOAD_STRING 18 ('18') - 20:3 - 20:14 176 CALL_METHOD 1 - 20:3 - 20:14 178 POP_TOP - 21:3 - 21:4 179 LOAD_NAME 0 (a) - 21:3 - 21:14 181 LOAD_METHOD 20 (f19) - 21:9 - 21:13 183 LOAD_STRING 19 ('19') - 21:3 - 21:14 185 CALL_METHOD 1 - 21:3 - 21:14 187 POP_TOP - 22:3 - 22:4 188 LOAD_NAME 0 (a) - 22:3 - 22:14 190 LOAD_METHOD 21 (f20) - 22:9 - 22:13 192 LOAD_STRING 20 ('20') - 22:3 - 22:14 194 CALL_METHOD 1 - 22:3 - 22:14 196 POP_TOP - 23:3 - 23:4 197 LOAD_NAME 0 (a) - 23:3 - 23:14 199 LOAD_METHOD 22 (f21) - 23:9 - 23:13 201 LOAD_STRING 21 ('21') - 23:3 - 23:14 203 CALL_METHOD 1 - 23:3 - 23:14 205 POP_TOP - 24:3 - 24:4 206 LOAD_NAME 0 (a) - 24:3 - 24:14 208 LOAD_METHOD 23 (f22) - 24:9 - 24:13 210 LOAD_STRING 22 ('22') - 24:3 - 24:14 212 CALL_METHOD 1 - 24:3 - 24:14 214 POP_TOP - 25:3 - 25:4 215 LOAD_NAME 0 (a) - 25:3 - 25:14 217 LOAD_METHOD 24 (f23) - 25:9 - 25:13 219 LOAD_STRING 23 ('23') - 25:3 - 25:14 221 CALL_METHOD 1 - 25:3 - 25:14 223 POP_TOP - 26:3 - 26:4 224 LOAD_NAME 0 (a) - 26:3 - 26:14 226 LOAD_METHOD 25 (f24) - 26:9 - 26:13 228 LOAD_STRING 24 ('24') - 26:3 - 26:14 230 CALL_METHOD 1 - 26:3 - 26:14 232 POP_TOP - 27:3 - 27:4 233 LOAD_NAME 0 (a) - 27:3 - 27:14 235 LOAD_METHOD 26 (f25) - 27:9 - 27:13 237 LOAD_STRING 25 ('25') - 27:3 - 27:14 239 CALL_METHOD 1 - 27:3 - 27:14 241 POP_TOP - 28:3 - 28:4 242 LOAD_NAME 0 (a) - 28:3 - 28:14 244 LOAD_METHOD 27 (f26) - 28:9 - 28:13 246 LOAD_STRING 26 ('26') - 28:3 - 28:14 248 CALL_METHOD 1 - 28:3 - 28:14 250 POP_TOP - 29:3 - 29:4 251 LOAD_NAME 0 (a) - 29:3 - 29:14 253 LOAD_METHOD 28 (f27) - 29:9 - 29:13 255 LOAD_STRING 27 ('27') - 29:3 - 29:14 257 CALL_METHOD 1 - 29:3 - 29:14 259 POP_TOP - 30:3 - 30:4 260 LOAD_NAME 0 (a) - 30:3 - 30:14 262 LOAD_METHOD 29 (f28) - 30:9 - 30:13 264 LOAD_STRING 28 ('28') - 30:3 - 30:14 266 CALL_METHOD 1 - 30:3 - 30:14 268 POP_TOP - 31:3 - 31:4 269 LOAD_NAME 0 (a) - 31:3 - 31:14 271 LOAD_METHOD 30 (f29) - 31:9 - 31:13 273 LOAD_STRING 29 ('29') - 31:3 - 31:14 275 CALL_METHOD 1 - 31:3 - 31:14 277 POP_TOP - 32:3 - 32:4 278 LOAD_NAME 0 (a) - 32:3 - 32:14 280 LOAD_METHOD 31 (f30) - 32:9 - 32:13 282 LOAD_STRING 30 ('30') - 32:3 - 32:14 284 CALL_METHOD 1 - 32:3 - 32:14 286 POP_TOP - 33:3 - 33:4 287 LOAD_NAME 0 (a) - 33:3 - 33:14 289 LOAD_METHOD 32 (f31) - 33:9 - 33:13 291 LOAD_STRING 31 ('31') - 33:3 - 33:14 293 CALL_METHOD 1 - 33:3 - 33:14 295 POP_TOP - 34:3 - 34:4 296 LOAD_NAME 0 (a) - 34:3 - 34:14 298 LOAD_METHOD 33 (f32) - 34:9 - 34:13 300 LOAD_STRING 32 ('32') - 34:3 - 34:14 302 CALL_METHOD 1 - 34:3 - 34:14 304 POP_TOP - 35:3 - 35:4 305 LOAD_NAME 0 (a) - 35:3 - 35:14 307 LOAD_METHOD 34 (f33) - 35:9 - 35:13 309 LOAD_STRING 33 ('33') - 35:3 - 35:14 311 CALL_METHOD 1 - 35:3 - 35:14 313 POP_TOP - 36:3 - 36:4 314 LOAD_NAME 0 (a) - 36:3 - 36:14 316 LOAD_METHOD 35 (f34) - 36:9 - 36:13 318 LOAD_STRING 34 ('34') - 36:3 - 36:14 320 CALL_METHOD 1 - 36:3 - 36:14 322 POP_TOP - 37:3 - 37:4 323 LOAD_NAME 0 (a) - 37:3 - 37:14 325 LOAD_METHOD 36 (f35) - 37:9 - 37:13 327 LOAD_STRING 35 ('35') - 37:3 - 37:14 329 CALL_METHOD 1 - 37:3 - 37:14 331 POP_TOP - 38:3 - 38:4 332 LOAD_NAME 0 (a) - 38:3 - 38:14 334 LOAD_METHOD 37 (f36) - 38:9 - 38:13 336 LOAD_STRING 36 ('36') - 38:3 - 38:14 338 CALL_METHOD 1 - 38:3 - 38:14 340 POP_TOP - 39:3 - 39:4 341 LOAD_NAME 0 (a) - 39:3 - 39:14 343 LOAD_METHOD 38 (f37) - 39:9 - 39:13 345 LOAD_STRING 37 ('37') - 39:3 - 39:14 347 CALL_METHOD 1 - 39:3 - 39:14 349 POP_TOP - 40:3 - 40:4 350 LOAD_NAME 0 (a) - 40:3 - 40:14 352 LOAD_METHOD 39 (f38) - 40:9 - 40:13 354 LOAD_STRING 38 ('38') - 40:3 - 40:14 356 CALL_METHOD 1 - 40:3 - 40:14 358 POP_TOP - 41:3 - 41:4 359 LOAD_NAME 0 (a) - 41:3 - 41:14 361 LOAD_METHOD 40 (f39) - 41:9 - 41:13 363 LOAD_STRING 39 ('39') - 41:3 - 41:14 365 CALL_METHOD 1 - 41:3 - 41:14 367 POP_TOP - 42:3 - 42:4 368 LOAD_NAME 0 (a) - 42:3 - 42:14 370 LOAD_METHOD 41 (f40) - 42:9 - 42:13 372 LOAD_STRING 40 ('40') - 42:3 - 42:14 374 CALL_METHOD 1 - 42:3 - 42:14 376 POP_TOP - 43:3 - 43:4 377 LOAD_NAME 0 (a) - 43:3 - 43:14 379 LOAD_METHOD 42 (f41) - 43:9 - 43:13 381 LOAD_STRING 41 ('41') - 43:3 - 43:14 383 CALL_METHOD 1 - 43:3 - 43:14 385 POP_TOP - 44:3 - 44:4 386 LOAD_NAME 0 (a) - 44:3 - 44:14 388 LOAD_METHOD 43 (f42) - 44:9 - 44:13 390 LOAD_STRING 42 ('42') - 44:3 - 44:14 392 CALL_METHOD 1 - 44:3 - 44:14 394 POP_TOP - 45:3 - 45:4 395 LOAD_NAME 0 (a) - 45:3 - 45:14 397 LOAD_METHOD 44 (f43) - 45:9 - 45:13 399 LOAD_STRING 43 ('43') - 45:3 - 45:14 401 CALL_METHOD 1 - 45:3 - 45:14 403 POP_TOP - 46:3 - 46:4 404 LOAD_NAME 0 (a) - 46:3 - 46:14 406 LOAD_METHOD 45 (f44) - 46:9 - 46:13 408 LOAD_STRING 44 ('44') - 46:3 - 46:14 410 CALL_METHOD 1 - 46:3 - 46:14 412 POP_TOP - 47:3 - 47:4 413 LOAD_NAME 0 (a) - 47:3 - 47:14 415 LOAD_METHOD 46 (f45) - 47:9 - 47:13 417 LOAD_STRING 45 ('45') - 47:3 - 47:14 419 CALL_METHOD 1 - 47:3 - 47:14 421 POP_TOP - 48:3 - 48:4 422 LOAD_NAME 0 (a) - 48:3 - 48:14 424 LOAD_METHOD 47 (f46) - 48:9 - 48:13 426 LOAD_STRING 46 ('46') - 48:3 - 48:14 428 CALL_METHOD 1 - 48:3 - 48:14 430 POP_TOP - 49:3 - 49:4 431 LOAD_NAME 0 (a) - 49:3 - 49:14 433 LOAD_METHOD 48 (f47) - 49:9 - 49:13 435 LOAD_STRING 47 ('47') - 49:3 - 49:14 437 CALL_METHOD 1 - 49:3 - 49:14 439 POP_TOP - 50:3 - 50:4 440 LOAD_NAME 0 (a) - 50:3 - 50:14 442 LOAD_METHOD 49 (f48) - 50:9 - 50:13 444 LOAD_STRING 48 ('48') - 50:3 - 50:14 446 CALL_METHOD 1 - 50:3 - 50:14 448 POP_TOP - 51:3 - 51:4 449 LOAD_NAME 0 (a) - 51:3 - 51:14 451 LOAD_METHOD 50 (f49) - 51:9 - 51:13 453 LOAD_STRING 49 ('49') - 51:3 - 51:14 455 CALL_METHOD 1 - 51:3 - 51:14 457 POP_TOP - 52:3 - 52:4 458 LOAD_NAME 0 (a) - 52:3 - 52:14 460 LOAD_METHOD 51 (f50) - 52:9 - 52:13 462 LOAD_STRING 50 ('50') - 52:3 - 52:14 464 CALL_METHOD 1 - 52:3 - 52:14 466 POP_TOP - 53:3 - 53:4 467 LOAD_NAME 0 (a) - 53:3 - 53:14 469 LOAD_METHOD 52 (f51) - 53:9 - 53:13 471 LOAD_STRING 51 ('51') - 53:3 - 53:14 473 CALL_METHOD 1 - 53:3 - 53:14 475 POP_TOP - 54:3 - 54:4 476 LOAD_NAME 0 (a) - 54:3 - 54:14 478 LOAD_METHOD 53 (f52) - 54:9 - 54:13 480 LOAD_STRING 52 ('52') - 54:3 - 54:14 482 CALL_METHOD 1 - 54:3 - 54:14 484 POP_TOP - 55:3 - 55:4 485 LOAD_NAME 0 (a) - 55:3 - 55:14 487 LOAD_METHOD 54 (f53) - 55:9 - 55:13 489 LOAD_STRING 53 ('53') - 55:3 - 55:14 491 CALL_METHOD 1 - 55:3 - 55:14 493 POP_TOP - 56:3 - 56:4 494 LOAD_NAME 0 (a) - 56:3 - 56:14 496 LOAD_METHOD 55 (f54) - 56:9 - 56:13 498 LOAD_STRING 54 ('54') - 56:3 - 56:14 500 CALL_METHOD 1 - 56:3 - 56:14 502 POP_TOP - 57:3 - 57:4 503 LOAD_NAME 0 (a) - 57:3 - 57:14 505 LOAD_METHOD 56 (f55) - 57:9 - 57:13 507 LOAD_STRING 55 ('55') - 57:3 - 57:14 509 CALL_METHOD 1 - 57:3 - 57:14 511 POP_TOP - 58:3 - 58:4 512 LOAD_NAME 0 (a) - 58:3 - 58:14 514 LOAD_METHOD 57 (f56) - 58:9 - 58:13 516 LOAD_STRING 56 ('56') - 58:3 - 58:14 518 CALL_METHOD 1 - 58:3 - 58:14 520 POP_TOP - 59:3 - 59:4 521 LOAD_NAME 0 (a) - 59:3 - 59:14 523 LOAD_METHOD 58 (f57) - 59:9 - 59:13 525 LOAD_STRING 57 ('57') - 59:3 - 59:14 527 CALL_METHOD 1 - 59:3 - 59:14 529 POP_TOP - 60:3 - 60:4 530 LOAD_NAME 0 (a) - 60:3 - 60:14 532 LOAD_METHOD 59 (f58) - 60:9 - 60:13 534 LOAD_STRING 58 ('58') - 60:3 - 60:14 536 CALL_METHOD 1 - 60:3 - 60:14 538 POP_TOP - 61:3 - 61:4 539 LOAD_NAME 0 (a) - 61:3 - 61:14 541 LOAD_METHOD 60 (f59) - 61:9 - 61:13 543 LOAD_STRING 59 ('59') - 61:3 - 61:14 545 CALL_METHOD 1 - 61:3 - 61:14 547 POP_TOP - 62:3 - 62:4 548 LOAD_NAME 0 (a) - 62:3 - 62:14 550 LOAD_METHOD 61 (f60) - 62:9 - 62:13 552 LOAD_STRING 60 ('60') - 62:3 - 62:14 554 CALL_METHOD 1 - 62:3 - 62:14 556 POP_TOP - 63:3 - 63:4 557 LOAD_NAME 0 (a) - 63:3 - 63:14 559 LOAD_METHOD 62 (f61) - 63:9 - 63:13 561 LOAD_STRING 61 ('61') - 63:3 - 63:14 563 CALL_METHOD 1 - 63:3 - 63:14 565 POP_TOP - 64:3 - 64:4 566 LOAD_NAME 0 (a) - 64:3 - 64:14 568 LOAD_METHOD 63 (f62) - 64:9 - 64:13 570 LOAD_STRING 62 ('62') - 64:3 - 64:14 572 CALL_METHOD 1 - 64:3 - 64:14 574 POP_TOP - 65:3 - 65:4 575 LOAD_NAME 0 (a) - 65:3 - 65:14 577 LOAD_METHOD 64 (f63) - 65:9 - 65:13 579 LOAD_STRING 63 ('63') - 65:3 - 65:14 581 CALL_METHOD 1 - 65:3 - 65:14 583 POP_TOP - 66:3 - 66:4 584 LOAD_NAME 0 (a) - 66:3 - 66:14 586 LOAD_METHOD 65 (f64) - 66:9 - 66:13 588 LOAD_STRING 64 ('64') - 66:3 - 66:14 590 CALL_METHOD 1 - 66:3 - 66:14 592 POP_TOP - 67:3 - 67:4 593 LOAD_NAME 0 (a) - 67:3 - 67:14 595 LOAD_METHOD 66 (f65) - 67:9 - 67:13 597 LOAD_STRING 65 ('65') - 67:3 - 67:14 599 CALL_METHOD 1 - 67:3 - 67:14 601 POP_TOP - 68:3 - 68:4 602 LOAD_NAME 0 (a) - 68:3 - 68:14 604 LOAD_METHOD 67 (f66) - 68:9 - 68:13 606 LOAD_STRING 66 ('66') - 68:3 - 68:14 608 CALL_METHOD 1 - 68:3 - 68:14 610 POP_TOP - 69:3 - 69:4 611 LOAD_NAME 0 (a) - 69:3 - 69:14 613 LOAD_METHOD 68 (f67) - 69:9 - 69:13 615 LOAD_STRING 67 ('67') - 69:3 - 69:14 617 CALL_METHOD 1 - 69:3 - 69:14 619 POP_TOP - 70:3 - 70:4 620 LOAD_NAME 0 (a) - 70:3 - 70:14 622 LOAD_METHOD 69 (f68) - 70:9 - 70:13 624 LOAD_STRING 68 ('68') - 70:3 - 70:14 626 CALL_METHOD 1 - 70:3 - 70:14 628 POP_TOP - 71:3 - 71:4 629 LOAD_NAME 0 (a) - 71:3 - 71:14 631 LOAD_METHOD 70 (f69) - 71:9 - 71:13 633 LOAD_STRING 69 ('69') - 71:3 - 71:14 635 CALL_METHOD 1 - 71:3 - 71:14 637 POP_TOP - 72:3 - 72:4 638 LOAD_NAME 0 (a) - 72:3 - 72:14 640 LOAD_METHOD 71 (f70) - 72:9 - 72:13 642 LOAD_STRING 70 ('70') - 72:3 - 72:14 644 CALL_METHOD 1 - 72:3 - 72:14 646 POP_TOP - 73:3 - 73:4 647 LOAD_NAME 0 (a) - 73:3 - 73:14 649 LOAD_METHOD 72 (f71) - 73:9 - 73:13 651 LOAD_STRING 71 ('71') - 73:3 - 73:14 653 CALL_METHOD 1 - 73:3 - 73:14 655 POP_TOP - 74:3 - 74:4 656 LOAD_NAME 0 (a) - 74:3 - 74:14 658 LOAD_METHOD 73 (f72) - 74:9 - 74:13 660 LOAD_STRING 72 ('72') - 74:3 - 74:14 662 CALL_METHOD 1 - 74:3 - 74:14 664 POP_TOP - 75:3 - 75:4 665 LOAD_NAME 0 (a) - 75:3 - 75:14 667 LOAD_METHOD 74 (f73) - 75:9 - 75:13 669 LOAD_STRING 73 ('73') - 75:3 - 75:14 671 CALL_METHOD 1 - 75:3 - 75:14 673 POP_TOP - 76:3 - 76:4 674 LOAD_NAME 0 (a) - 76:3 - 76:14 676 LOAD_METHOD 75 (f74) - 76:9 - 76:13 678 LOAD_STRING 74 ('74') - 76:3 - 76:14 680 CALL_METHOD 1 - 76:3 - 76:14 682 POP_TOP - 77:3 - 77:4 683 LOAD_NAME 0 (a) - 77:3 - 77:14 685 LOAD_METHOD 76 (f75) - 77:9 - 77:13 687 LOAD_STRING 75 ('75') - 77:3 - 77:14 689 CALL_METHOD 1 - 77:3 - 77:14 691 POP_TOP - 78:3 - 78:4 692 LOAD_NAME 0 (a) - 78:3 - 78:14 694 LOAD_METHOD 77 (f76) - 78:9 - 78:13 696 LOAD_STRING 76 ('76') - 78:3 - 78:14 698 CALL_METHOD 1 - 78:3 - 78:14 700 POP_TOP - 79:3 - 79:4 701 LOAD_NAME 0 (a) - 79:3 - 79:14 703 LOAD_METHOD 78 (f77) - 79:9 - 79:13 705 LOAD_STRING 77 ('77') - 79:3 - 79:14 707 CALL_METHOD 1 - 79:3 - 79:14 709 POP_TOP - 80:3 - 80:4 710 LOAD_NAME 0 (a) - 80:3 - 80:14 712 LOAD_METHOD 79 (f78) - 80:9 - 80:13 714 LOAD_STRING 78 ('78') - 80:3 - 80:14 716 CALL_METHOD 1 - 80:3 - 80:14 718 POP_TOP - 81:3 - 81:4 719 LOAD_NAME 0 (a) - 81:3 - 81:14 721 LOAD_METHOD 80 (f79) - 81:9 - 81:13 723 LOAD_STRING 79 ('79') - 81:3 - 81:14 725 CALL_METHOD 1 - 81:3 - 81:14 727 POP_TOP - 82:3 - 82:4 728 LOAD_NAME 0 (a) - 82:3 - 82:14 730 LOAD_METHOD 81 (f80) - 82:9 - 82:13 732 LOAD_STRING 80 ('80') - 82:3 - 82:14 734 CALL_METHOD 1 - 82:3 - 82:14 736 POP_TOP - 83:3 - 83:4 737 LOAD_NAME 0 (a) - 83:3 - 83:14 739 LOAD_METHOD 82 (f81) - 83:9 - 83:13 741 LOAD_STRING 81 ('81') - 83:3 - 83:14 743 CALL_METHOD 1 - 83:3 - 83:14 745 POP_TOP - 84:3 - 84:4 746 LOAD_NAME 0 (a) - 84:3 - 84:14 748 LOAD_METHOD 83 (f82) - 84:9 - 84:13 750 LOAD_STRING 82 ('82') - 84:3 - 84:14 752 CALL_METHOD 1 - 84:3 - 84:14 754 POP_TOP - 85:3 - 85:4 755 LOAD_NAME 0 (a) - 85:3 - 85:14 757 LOAD_METHOD 84 (f83) - 85:9 - 85:13 759 LOAD_STRING 83 ('83') - 85:3 - 85:14 761 CALL_METHOD 1 - 85:3 - 85:14 763 POP_TOP - 86:3 - 86:4 764 LOAD_NAME 0 (a) - 86:3 - 86:14 766 LOAD_METHOD 85 (f84) - 86:9 - 86:13 768 LOAD_STRING 84 ('84') - 86:3 - 86:14 770 CALL_METHOD 1 - 86:3 - 86:14 772 POP_TOP - 87:3 - 87:4 773 LOAD_NAME 0 (a) - 87:3 - 87:14 775 LOAD_METHOD 86 (f85) - 87:9 - 87:13 777 LOAD_STRING 85 ('85') - 87:3 - 87:14 779 CALL_METHOD 1 - 87:3 - 87:14 781 POP_TOP - 88:3 - 88:4 782 LOAD_NAME 0 (a) - 88:3 - 88:14 784 LOAD_METHOD 87 (f86) - 88:9 - 88:13 786 LOAD_STRING 86 ('86') - 88:3 - 88:14 788 CALL_METHOD 1 - 88:3 - 88:14 790 POP_TOP - 89:3 - 89:4 791 LOAD_NAME 0 (a) - 89:3 - 89:14 793 LOAD_METHOD 88 (f87) - 89:9 - 89:13 795 LOAD_STRING 87 ('87') - 89:3 - 89:14 797 CALL_METHOD 1 - 89:3 - 89:14 799 POP_TOP - 90:3 - 90:4 800 LOAD_NAME 0 (a) - 90:3 - 90:14 802 LOAD_METHOD 89 (f88) - 90:9 - 90:13 804 LOAD_STRING 88 ('88') - 90:3 - 90:14 806 CALL_METHOD 1 - 90:3 - 90:14 808 POP_TOP - 91:3 - 91:4 809 LOAD_NAME 0 (a) - 91:3 - 91:14 811 LOAD_METHOD 90 (f89) - 91:9 - 91:13 813 LOAD_STRING 89 ('89') - 91:3 - 91:14 815 CALL_METHOD 1 - 91:3 - 91:14 817 POP_TOP - 92:3 - 92:4 818 LOAD_NAME 0 (a) - 92:3 - 92:14 820 LOAD_METHOD 91 (f90) - 92:9 - 92:13 822 LOAD_STRING 90 ('90') - 92:3 - 92:14 824 CALL_METHOD 1 - 92:3 - 92:14 826 POP_TOP - 93:3 - 93:4 827 LOAD_NAME 0 (a) - 93:3 - 93:14 829 LOAD_METHOD 92 (f91) - 93:9 - 93:13 831 LOAD_STRING 91 ('91') - 93:3 - 93:14 833 CALL_METHOD 1 - 93:3 - 93:14 835 POP_TOP - 94:3 - 94:4 836 LOAD_NAME 0 (a) - 94:3 - 94:14 838 LOAD_METHOD 93 (f92) - 94:9 - 94:13 840 LOAD_STRING 92 ('92') - 94:3 - 94:14 842 CALL_METHOD 1 - 94:3 - 94:14 844 POP_TOP - 95:3 - 95:4 845 LOAD_NAME 0 (a) - 95:3 - 95:14 847 LOAD_METHOD 94 (f93) - 95:9 - 95:13 849 LOAD_STRING 93 ('93') - 95:3 - 95:14 851 CALL_METHOD 1 - 95:3 - 95:14 853 POP_TOP - 96:3 - 96:4 854 LOAD_NAME 0 (a) - 96:3 - 96:14 856 LOAD_METHOD 95 (f94) - 96:9 - 96:13 858 LOAD_STRING 94 ('94') - 96:3 - 96:14 860 CALL_METHOD 1 - 96:3 - 96:14 862 POP_TOP - 97:3 - 97:4 863 LOAD_NAME 0 (a) - 97:3 - 97:14 865 LOAD_METHOD 96 (f95) - 97:9 - 97:13 867 LOAD_STRING 95 ('95') - 97:3 - 97:14 869 CALL_METHOD 1 - 97:3 - 97:14 871 POP_TOP - 98:3 - 98:4 872 LOAD_NAME 0 (a) - 98:3 - 98:14 874 LOAD_METHOD 97 (f96) - 98:9 - 98:13 876 LOAD_STRING 96 ('96') - 98:3 - 98:14 878 CALL_METHOD 1 - 98:3 - 98:14 880 POP_TOP - 99:3 - 99:4 881 LOAD_NAME 0 (a) - 99:3 - 99:14 883 LOAD_METHOD 98 (f97) - 99:9 - 99:13 885 LOAD_STRING 97 ('97') - 99:3 - 99:14 887 CALL_METHOD 1 - 99:3 - 99:14 889 POP_TOP -100:3 - 100:4 890 LOAD_NAME 0 (a) -100:3 - 100:14 892 LOAD_METHOD 99 (f98) -100:9 - 100:13 894 LOAD_STRING 98 ('98') -100:3 - 100:14 896 CALL_METHOD 1 -100:3 - 100:14 898 POP_TOP -101:3 - 101:4 899 LOAD_NAME 0 (a) -101:3 - 101:14 901 LOAD_METHOD 100 (f99) -101:9 - 101:13 903 LOAD_STRING 99 ('99') -101:3 - 101:14 905 CALL_METHOD 1 -101:3 - 101:14 907 POP_TOP -102:3 - 102:4 908 LOAD_NAME 0 (a) -102:3 - 102:16 910 LOAD_METHOD 101 (f100) -102:10 - 102:15 912 LOAD_STRING 100 ('100') -102:3 - 102:16 914 CALL_METHOD 1 -102:3 - 102:16 916 POP_TOP -103:3 - 103:4 917 LOAD_NAME 0 (a) -103:3 - 103:16 919 LOAD_METHOD 102 (f101) -103:10 - 103:15 921 LOAD_STRING 101 ('101') -103:3 - 103:16 923 CALL_METHOD 1 -103:3 - 103:16 925 POP_TOP -104:3 - 104:4 926 LOAD_NAME 0 (a) -104:3 - 104:16 928 LOAD_METHOD 103 (f102) -104:10 - 104:15 930 LOAD_STRING 102 ('102') -104:3 - 104:16 932 CALL_METHOD 1 -104:3 - 104:16 934 POP_TOP -105:3 - 105:4 935 LOAD_NAME 0 (a) -105:3 - 105:16 937 LOAD_METHOD 104 (f103) -105:10 - 105:15 939 LOAD_STRING 103 ('103') -105:3 - 105:16 941 CALL_METHOD 1 -105:3 - 105:16 943 POP_TOP -106:3 - 106:4 944 LOAD_NAME 0 (a) -106:3 - 106:16 946 LOAD_METHOD 105 (f104) -106:10 - 106:15 948 LOAD_STRING 104 ('104') -106:3 - 106:16 950 CALL_METHOD 1 -106:3 - 106:16 952 POP_TOP -107:3 - 107:4 953 LOAD_NAME 0 (a) -107:3 - 107:16 955 LOAD_METHOD 106 (f105) -107:10 - 107:15 957 LOAD_STRING 105 ('105') -107:3 - 107:16 959 CALL_METHOD 1 -107:3 - 107:16 961 POP_TOP -108:3 - 108:4 962 LOAD_NAME 0 (a) -108:3 - 108:16 964 LOAD_METHOD 107 (f106) -108:10 - 108:15 966 LOAD_STRING 106 ('106') -108:3 - 108:16 968 CALL_METHOD 1 -108:3 - 108:16 970 POP_TOP -109:3 - 109:4 971 LOAD_NAME 0 (a) -109:3 - 109:16 973 LOAD_METHOD 108 (f107) -109:10 - 109:15 975 LOAD_STRING 107 ('107') -109:3 - 109:16 977 CALL_METHOD 1 -109:3 - 109:16 979 POP_TOP -110:3 - 110:4 980 LOAD_NAME 0 (a) -110:3 - 110:16 982 LOAD_METHOD 109 (f108) -110:10 - 110:15 984 LOAD_STRING 108 ('108') -110:3 - 110:16 986 CALL_METHOD 1 -110:3 - 110:16 988 POP_TOP -111:3 - 111:4 989 LOAD_NAME 0 (a) -111:3 - 111:16 991 LOAD_METHOD 110 (f109) -111:10 - 111:15 993 LOAD_STRING 109 ('109') -111:3 - 111:16 995 CALL_METHOD 1 -111:3 - 111:16 997 POP_TOP -112:3 - 112:4 998 LOAD_NAME 0 (a) -112:3 - 112:16 1000 LOAD_METHOD 111 (f110) -112:10 - 112:15 1002 LOAD_STRING 110 ('110') -112:3 - 112:16 1004 CALL_METHOD 1 -112:3 - 112:16 1006 POP_TOP -113:3 - 113:4 1007 LOAD_NAME 0 (a) -113:3 - 113:16 1009 LOAD_METHOD 112 (f111) -113:10 - 113:15 1011 LOAD_STRING 111 ('111') -113:3 - 113:16 1013 CALL_METHOD 1 -113:3 - 113:16 1015 POP_TOP -114:3 - 114:4 1016 LOAD_NAME 0 (a) -114:3 - 114:16 1018 LOAD_METHOD 113 (f112) -114:10 - 114:15 1020 LOAD_STRING 112 ('112') -114:3 - 114:16 1022 CALL_METHOD 1 -114:3 - 114:16 1024 POP_TOP -115:3 - 115:4 1025 LOAD_NAME 0 (a) -115:3 - 115:16 1027 LOAD_METHOD 114 (f113) -115:10 - 115:15 1029 LOAD_STRING 113 ('113') -115:3 - 115:16 1031 CALL_METHOD 1 -115:3 - 115:16 1033 POP_TOP -116:3 - 116:4 1034 LOAD_NAME 0 (a) -116:3 - 116:16 1036 LOAD_METHOD 115 (f114) -116:10 - 116:15 1038 LOAD_STRING 114 ('114') -116:3 - 116:16 1040 CALL_METHOD 1 -116:3 - 116:16 1042 POP_TOP -117:3 - 117:4 1043 LOAD_NAME 0 (a) -117:3 - 117:16 1045 LOAD_METHOD 116 (f115) -117:10 - 117:15 1047 LOAD_STRING 115 ('115') -117:3 - 117:16 1049 CALL_METHOD 1 -117:3 - 117:16 1051 POP_TOP -118:3 - 118:4 1052 LOAD_NAME 0 (a) -118:3 - 118:16 1054 LOAD_METHOD 117 (f116) -118:10 - 118:15 1056 LOAD_STRING 116 ('116') -118:3 - 118:16 1058 CALL_METHOD 1 -118:3 - 118:16 1060 POP_TOP -119:3 - 119:4 1061 LOAD_NAME 0 (a) -119:3 - 119:16 1063 LOAD_METHOD 118 (f117) -119:10 - 119:15 1065 LOAD_STRING 117 ('117') -119:3 - 119:16 1067 CALL_METHOD 1 -119:3 - 119:16 1069 POP_TOP -120:3 - 120:4 1070 LOAD_NAME 0 (a) -120:3 - 120:16 1072 LOAD_METHOD 119 (f118) -120:10 - 120:15 1074 LOAD_STRING 118 ('118') -120:3 - 120:16 1076 CALL_METHOD 1 -120:3 - 120:16 1078 POP_TOP -121:3 - 121:4 1079 LOAD_NAME 0 (a) -121:3 - 121:16 1081 LOAD_METHOD 120 (f119) -121:10 - 121:15 1083 LOAD_STRING 119 ('119') -121:3 - 121:16 1085 CALL_METHOD 1 -121:3 - 121:16 1087 POP_TOP -122:3 - 122:4 1088 LOAD_NAME 0 (a) -122:3 - 122:16 1090 LOAD_METHOD 121 (f120) -122:10 - 122:15 1092 LOAD_STRING 120 ('120') -122:3 - 122:16 1094 CALL_METHOD 1 -122:3 - 122:16 1096 POP_TOP -123:3 - 123:4 1097 LOAD_NAME 0 (a) -123:3 - 123:16 1099 LOAD_METHOD 122 (f121) -123:10 - 123:15 1101 LOAD_STRING 121 ('121') -123:3 - 123:16 1103 CALL_METHOD 1 -123:3 - 123:16 1105 POP_TOP -124:3 - 124:4 1106 LOAD_NAME 0 (a) -124:3 - 124:16 1108 LOAD_METHOD 123 (f122) -124:10 - 124:15 1110 LOAD_STRING 122 ('122') -124:3 - 124:16 1112 CALL_METHOD 1 -124:3 - 124:16 1114 POP_TOP -125:3 - 125:4 1115 LOAD_NAME 0 (a) -125:3 - 125:16 1117 LOAD_METHOD 124 (f123) -125:10 - 125:15 1119 LOAD_STRING 123 ('123') -125:3 - 125:16 1121 CALL_METHOD 1 -125:3 - 125:16 1123 POP_TOP -126:3 - 126:4 1124 LOAD_NAME 0 (a) -126:3 - 126:16 1126 LOAD_METHOD 125 (f124) -126:10 - 126:15 1128 LOAD_STRING 124 ('124') -126:3 - 126:16 1130 CALL_METHOD 1 -126:3 - 126:16 1132 POP_TOP -127:3 - 127:4 1133 LOAD_NAME 0 (a) -127:3 - 127:16 1135 LOAD_METHOD 126 (f125) -127:10 - 127:15 1137 LOAD_STRING 125 ('125') -127:3 - 127:16 1139 CALL_METHOD 1 -127:3 - 127:16 1141 POP_TOP -128:3 - 128:4 1142 LOAD_NAME 0 (a) -128:3 - 128:16 1144 LOAD_METHOD 127 (f126) -128:10 - 128:15 1146 LOAD_STRING 126 ('126') -128:3 - 128:16 1148 CALL_METHOD 1 -128:3 - 128:16 1150 POP_TOP -129:3 - 129:4 1151 LOAD_NAME 0 (a) -129:3 - 129:16 1153 LOAD_METHOD 128 (f127) -129:10 - 129:15 1155 LOAD_STRING 127 ('127') -129:3 - 129:16 1157 CALL_METHOD 1 -129:3 - 129:16 1159 POP_TOP -130:3 - 130:4 1160 LOAD_NAME 0 (a) -130:3 - 130:16 1162 LOAD_METHOD 129 (f128) -130:10 - 130:15 1164 LOAD_STRING 128 ('128') -130:3 - 130:16 1166 CALL_METHOD 1 -130:3 - 130:16 1168 POP_TOP -131:3 - 131:4 1169 LOAD_NAME 0 (a) -131:3 - 131:16 1171 LOAD_METHOD 130 (f129) -131:10 - 131:15 1173 LOAD_STRING 129 ('129') -131:3 - 131:16 1175 CALL_METHOD 1 -131:3 - 131:16 1177 POP_TOP -132:3 - 132:4 1178 LOAD_NAME 0 (a) -132:3 - 132:16 1180 LOAD_METHOD 131 (f130) -132:10 - 132:15 1182 LOAD_STRING 130 ('130') -132:3 - 132:16 1184 CALL_METHOD 1 -132:3 - 132:16 1186 POP_TOP -133:3 - 133:4 1187 LOAD_NAME 0 (a) -133:3 - 133:16 1189 LOAD_METHOD 132 (f131) -133:10 - 133:15 1191 LOAD_STRING 131 ('131') -133:3 - 133:16 1193 CALL_METHOD 1 -133:3 - 133:16 1195 POP_TOP -134:3 - 134:4 1196 LOAD_NAME 0 (a) -134:3 - 134:16 1198 LOAD_METHOD 133 (f132) -134:10 - 134:15 1200 LOAD_STRING 132 ('132') -134:3 - 134:16 1202 CALL_METHOD 1 -134:3 - 134:16 1204 POP_TOP -135:3 - 135:4 1205 LOAD_NAME 0 (a) -135:3 - 135:16 1207 LOAD_METHOD 134 (f133) -135:10 - 135:15 1209 LOAD_STRING 133 ('133') -135:3 - 135:16 1211 CALL_METHOD 1 -135:3 - 135:16 1213 POP_TOP -136:3 - 136:4 1214 LOAD_NAME 0 (a) -136:3 - 136:16 1216 LOAD_METHOD 135 (f134) -136:10 - 136:15 1218 LOAD_STRING 134 ('134') -136:3 - 136:16 1220 CALL_METHOD 1 -136:3 - 136:16 1222 POP_TOP -137:3 - 137:4 1223 LOAD_NAME 0 (a) -137:3 - 137:16 1225 LOAD_METHOD 136 (f135) -137:10 - 137:15 1227 LOAD_STRING 135 ('135') -137:3 - 137:16 1229 CALL_METHOD 1 -137:3 - 137:16 1231 POP_TOP -138:3 - 138:4 1232 LOAD_NAME 0 (a) -138:3 - 138:16 1234 LOAD_METHOD 137 (f136) -138:10 - 138:15 1236 LOAD_STRING 136 ('136') -138:3 - 138:16 1238 CALL_METHOD 1 -138:3 - 138:16 1240 POP_TOP -139:3 - 139:4 1241 LOAD_NAME 0 (a) -139:3 - 139:16 1243 LOAD_METHOD 138 (f137) -139:10 - 139:15 1245 LOAD_STRING 137 ('137') -139:3 - 139:16 1247 CALL_METHOD 1 -139:3 - 139:16 1249 POP_TOP -140:3 - 140:4 1250 LOAD_NAME 0 (a) -140:3 - 140:16 1252 LOAD_METHOD 139 (f138) -140:10 - 140:15 1254 LOAD_STRING 138 ('138') -140:3 - 140:16 1256 CALL_METHOD 1 -140:3 - 140:16 1258 POP_TOP -141:3 - 141:4 1259 LOAD_NAME 0 (a) -141:3 - 141:16 1261 LOAD_METHOD 140 (f139) -141:10 - 141:15 1263 LOAD_STRING 139 ('139') -141:3 - 141:16 1265 CALL_METHOD 1 -141:3 - 141:16 1267 POP_TOP -142:3 - 142:4 1268 LOAD_NAME 0 (a) -142:3 - 142:16 1270 LOAD_METHOD 141 (f140) -142:10 - 142:15 1272 LOAD_STRING 140 ('140') -142:3 - 142:16 1274 CALL_METHOD 1 -142:3 - 142:16 1276 POP_TOP -143:3 - 143:4 1277 LOAD_NAME 0 (a) -143:3 - 143:16 1279 LOAD_METHOD 142 (f141) -143:10 - 143:15 1281 LOAD_STRING 141 ('141') -143:3 - 143:16 1283 CALL_METHOD 1 -143:3 - 143:16 1285 POP_TOP -144:3 - 144:4 1286 LOAD_NAME 0 (a) -144:3 - 144:16 1288 LOAD_METHOD 143 (f142) -144:10 - 144:15 1290 LOAD_STRING 142 ('142') -144:3 - 144:16 1292 CALL_METHOD 1 -144:3 - 144:16 1294 POP_TOP -145:3 - 145:4 1295 LOAD_NAME 0 (a) -145:3 - 145:16 1297 LOAD_METHOD 144 (f143) -145:10 - 145:15 1299 LOAD_STRING 143 ('143') -145:3 - 145:16 1301 CALL_METHOD 1 -145:3 - 145:16 1303 POP_TOP -146:3 - 146:4 1304 LOAD_NAME 0 (a) -146:3 - 146:16 1306 LOAD_METHOD 145 (f144) -146:10 - 146:15 1308 LOAD_STRING 144 ('144') -146:3 - 146:16 1310 CALL_METHOD 1 -146:3 - 146:16 1312 POP_TOP -147:3 - 147:4 1313 LOAD_NAME 0 (a) -147:3 - 147:16 1315 LOAD_METHOD 146 (f145) -147:10 - 147:15 1317 LOAD_STRING 145 ('145') -147:3 - 147:16 1319 CALL_METHOD 1 -147:3 - 147:16 1321 POP_TOP -148:3 - 148:4 1322 LOAD_NAME 0 (a) -148:3 - 148:16 1324 LOAD_METHOD 147 (f146) -148:10 - 148:15 1326 LOAD_STRING 146 ('146') -148:3 - 148:16 1328 CALL_METHOD 1 -148:3 - 148:16 1330 POP_TOP -149:3 - 149:4 1331 LOAD_NAME 0 (a) -149:3 - 149:16 1333 LOAD_METHOD 148 (f147) -149:10 - 149:15 1335 LOAD_STRING 147 ('147') -149:3 - 149:16 1337 CALL_METHOD 1 -149:3 - 149:16 1339 POP_TOP -150:3 - 150:4 1340 LOAD_NAME 0 (a) -150:3 - 150:16 1342 LOAD_METHOD 149 (f148) -150:10 - 150:15 1344 LOAD_STRING 148 ('148') -150:3 - 150:16 1346 CALL_METHOD 1 -150:3 - 150:16 1348 POP_TOP -151:3 - 151:4 1349 LOAD_NAME 0 (a) -151:3 - 151:16 1351 LOAD_METHOD 150 (f149) -151:10 - 151:15 1353 LOAD_STRING 149 ('149') -151:3 - 151:16 1355 CALL_METHOD 1 -151:3 - 151:16 1357 POP_TOP -152:3 - 152:4 1358 LOAD_NAME 0 (a) -152:3 - 152:16 1360 LOAD_METHOD 151 (f150) -152:10 - 152:15 1362 LOAD_STRING 150 ('150') -152:3 - 152:16 1364 CALL_METHOD 1 -152:3 - 152:16 1366 POP_TOP -153:3 - 153:4 1367 LOAD_NAME 0 (a) -153:3 - 153:16 1369 LOAD_METHOD 152 (f151) -153:10 - 153:15 1371 LOAD_STRING 151 ('151') -153:3 - 153:16 1373 CALL_METHOD 1 -153:3 - 153:16 1375 POP_TOP -154:3 - 154:4 1376 LOAD_NAME 0 (a) -154:3 - 154:16 1378 LOAD_METHOD 153 (f152) -154:10 - 154:15 1380 LOAD_STRING 152 ('152') -154:3 - 154:16 1382 CALL_METHOD 1 -154:3 - 154:16 1384 POP_TOP -155:3 - 155:4 1385 LOAD_NAME 0 (a) -155:3 - 155:16 1387 LOAD_METHOD 154 (f153) -155:10 - 155:15 1389 LOAD_STRING 153 ('153') -155:3 - 155:16 1391 CALL_METHOD 1 -155:3 - 155:16 1393 POP_TOP -156:3 - 156:4 1394 LOAD_NAME 0 (a) -156:3 - 156:16 1396 LOAD_METHOD 155 (f154) -156:10 - 156:15 1398 LOAD_STRING 154 ('154') -156:3 - 156:16 1400 CALL_METHOD 1 -156:3 - 156:16 1402 POP_TOP -157:3 - 157:4 1403 LOAD_NAME 0 (a) -157:3 - 157:16 1405 LOAD_METHOD 156 (f155) -157:10 - 157:15 1407 LOAD_STRING 155 ('155') -157:3 - 157:16 1409 CALL_METHOD 1 -157:3 - 157:16 1411 POP_TOP -158:3 - 158:4 1412 LOAD_NAME 0 (a) -158:3 - 158:16 1414 LOAD_METHOD 157 (f156) -158:10 - 158:15 1416 LOAD_STRING 156 ('156') -158:3 - 158:16 1418 CALL_METHOD 1 -158:3 - 158:16 1420 POP_TOP -159:3 - 159:4 1421 LOAD_NAME 0 (a) -159:3 - 159:16 1423 LOAD_METHOD 158 (f157) -159:10 - 159:15 1425 LOAD_STRING 157 ('157') -159:3 - 159:16 1427 CALL_METHOD 1 -159:3 - 159:16 1429 POP_TOP -160:3 - 160:4 1430 LOAD_NAME 0 (a) -160:3 - 160:16 1432 LOAD_METHOD 159 (f158) -160:10 - 160:15 1434 LOAD_STRING 158 ('158') -160:3 - 160:16 1436 CALL_METHOD 1 -160:3 - 160:16 1438 POP_TOP -161:3 - 161:4 1439 LOAD_NAME 0 (a) -161:3 - 161:16 1441 LOAD_METHOD 160 (f159) -161:10 - 161:15 1443 LOAD_STRING 159 ('159') -161:3 - 161:16 1445 CALL_METHOD 1 -161:3 - 161:16 1447 POP_TOP -162:3 - 162:4 1448 LOAD_NAME 0 (a) -162:3 - 162:16 1450 LOAD_METHOD 161 (f160) -162:10 - 162:15 1452 LOAD_STRING 160 ('160') -162:3 - 162:16 1454 CALL_METHOD 1 -162:3 - 162:16 1456 POP_TOP -163:3 - 163:4 1457 LOAD_NAME 0 (a) -163:3 - 163:16 1459 LOAD_METHOD 162 (f161) -163:10 - 163:15 1461 LOAD_STRING 161 ('161') -163:3 - 163:16 1463 CALL_METHOD 1 -163:3 - 163:16 1465 POP_TOP -164:3 - 164:4 1466 LOAD_NAME 0 (a) -164:3 - 164:16 1468 LOAD_METHOD 163 (f162) -164:10 - 164:15 1470 LOAD_STRING 162 ('162') -164:3 - 164:16 1472 CALL_METHOD 1 -164:3 - 164:16 1474 POP_TOP -165:3 - 165:4 1475 LOAD_NAME 0 (a) -165:3 - 165:16 1477 LOAD_METHOD 164 (f163) -165:10 - 165:15 1479 LOAD_STRING 163 ('163') -165:3 - 165:16 1481 CALL_METHOD 1 -165:3 - 165:16 1483 POP_TOP -166:3 - 166:4 1484 LOAD_NAME 0 (a) -166:3 - 166:16 1486 LOAD_METHOD 165 (f164) -166:10 - 166:15 1488 LOAD_STRING 164 ('164') -166:3 - 166:16 1490 CALL_METHOD 1 -166:3 - 166:16 1492 POP_TOP -167:3 - 167:4 1493 LOAD_NAME 0 (a) -167:3 - 167:16 1495 LOAD_METHOD 166 (f165) -167:10 - 167:15 1497 LOAD_STRING 165 ('165') -167:3 - 167:16 1499 CALL_METHOD 1 -167:3 - 167:16 1501 POP_TOP -168:3 - 168:4 1502 LOAD_NAME 0 (a) -168:3 - 168:16 1504 LOAD_METHOD 167 (f166) -168:10 - 168:15 1506 LOAD_STRING 166 ('166') -168:3 - 168:16 1508 CALL_METHOD 1 -168:3 - 168:16 1510 POP_TOP -169:3 - 169:4 1511 LOAD_NAME 0 (a) -169:3 - 169:16 1513 LOAD_METHOD 168 (f167) -169:10 - 169:15 1515 LOAD_STRING 167 ('167') -169:3 - 169:16 1517 CALL_METHOD 1 -169:3 - 169:16 1519 POP_TOP -170:3 - 170:4 1520 LOAD_NAME 0 (a) -170:3 - 170:16 1522 LOAD_METHOD 169 (f168) -170:10 - 170:15 1524 LOAD_STRING 168 ('168') -170:3 - 170:16 1526 CALL_METHOD 1 -170:3 - 170:16 1528 POP_TOP -171:3 - 171:4 1529 LOAD_NAME 0 (a) -171:3 - 171:16 1531 LOAD_METHOD 170 (f169) -171:10 - 171:15 1533 LOAD_STRING 169 ('169') -171:3 - 171:16 1535 CALL_METHOD 1 -171:3 - 171:16 1537 POP_TOP -172:3 - 172:4 1538 LOAD_NAME 0 (a) -172:3 - 172:16 1540 LOAD_METHOD 171 (f170) -172:10 - 172:15 1542 LOAD_STRING 170 ('170') -172:3 - 172:16 1544 CALL_METHOD 1 -172:3 - 172:16 1546 POP_TOP -173:3 - 173:4 1547 LOAD_NAME 0 (a) -173:3 - 173:16 1549 LOAD_METHOD 172 (f171) -173:10 - 173:15 1551 LOAD_STRING 171 ('171') -173:3 - 173:16 1553 CALL_METHOD 1 -173:3 - 173:16 1555 POP_TOP -174:3 - 174:4 1556 LOAD_NAME 0 (a) -174:3 - 174:16 1558 LOAD_METHOD 173 (f172) -174:10 - 174:15 1560 LOAD_STRING 172 ('172') -174:3 - 174:16 1562 CALL_METHOD 1 -174:3 - 174:16 1564 POP_TOP -175:3 - 175:4 1565 LOAD_NAME 0 (a) -175:3 - 175:16 1567 LOAD_METHOD 174 (f173) -175:10 - 175:15 1569 LOAD_STRING 173 ('173') -175:3 - 175:16 1571 CALL_METHOD 1 -175:3 - 175:16 1573 POP_TOP -176:3 - 176:4 1574 LOAD_NAME 0 (a) -176:3 - 176:16 1576 LOAD_METHOD 175 (f174) -176:10 - 176:15 1578 LOAD_STRING 174 ('174') -176:3 - 176:16 1580 CALL_METHOD 1 -176:3 - 176:16 1582 POP_TOP -177:3 - 177:4 1583 LOAD_NAME 0 (a) -177:3 - 177:16 1585 LOAD_METHOD 176 (f175) -177:10 - 177:15 1587 LOAD_STRING 175 ('175') -177:3 - 177:16 1589 CALL_METHOD 1 -177:3 - 177:16 1591 POP_TOP -178:3 - 178:4 1592 LOAD_NAME 0 (a) -178:3 - 178:16 1594 LOAD_METHOD 177 (f176) -178:10 - 178:15 1596 LOAD_STRING 176 ('176') -178:3 - 178:16 1598 CALL_METHOD 1 -178:3 - 178:16 1600 POP_TOP -179:3 - 179:4 1601 LOAD_NAME 0 (a) -179:3 - 179:16 1603 LOAD_METHOD 178 (f177) -179:10 - 179:15 1605 LOAD_STRING 177 ('177') -179:3 - 179:16 1607 CALL_METHOD 1 -179:3 - 179:16 1609 POP_TOP -180:3 - 180:4 1610 LOAD_NAME 0 (a) -180:3 - 180:16 1612 LOAD_METHOD 179 (f178) -180:10 - 180:15 1614 LOAD_STRING 178 ('178') -180:3 - 180:16 1616 CALL_METHOD 1 -180:3 - 180:16 1618 POP_TOP -181:3 - 181:4 1619 LOAD_NAME 0 (a) -181:3 - 181:16 1621 LOAD_METHOD 180 (f179) -181:10 - 181:15 1623 LOAD_STRING 179 ('179') -181:3 - 181:16 1625 CALL_METHOD 1 -181:3 - 181:16 1627 POP_TOP -182:3 - 182:4 1628 LOAD_NAME 0 (a) -182:3 - 182:16 1630 LOAD_METHOD 181 (f180) -182:10 - 182:15 1632 LOAD_STRING 180 ('180') -182:3 - 182:16 1634 CALL_METHOD 1 -182:3 - 182:16 1636 POP_TOP -183:3 - 183:4 1637 LOAD_NAME 0 (a) -183:3 - 183:16 1639 LOAD_METHOD 182 (f181) -183:10 - 183:15 1641 LOAD_STRING 181 ('181') -183:3 - 183:16 1643 CALL_METHOD 1 -183:3 - 183:16 1645 POP_TOP -184:3 - 184:4 1646 LOAD_NAME 0 (a) -184:3 - 184:16 1648 LOAD_METHOD 183 (f182) -184:10 - 184:15 1650 LOAD_STRING 182 ('182') -184:3 - 184:16 1652 CALL_METHOD 1 -184:3 - 184:16 1654 POP_TOP -185:3 - 185:4 1655 LOAD_NAME 0 (a) -185:3 - 185:16 1657 LOAD_METHOD 184 (f183) -185:10 - 185:15 1659 LOAD_STRING 183 ('183') -185:3 - 185:16 1661 CALL_METHOD 1 -185:3 - 185:16 1663 POP_TOP -186:3 - 186:4 1664 LOAD_NAME 0 (a) -186:3 - 186:16 1666 LOAD_METHOD 185 (f184) -186:10 - 186:15 1668 LOAD_STRING 184 ('184') -186:3 - 186:16 1670 CALL_METHOD 1 -186:3 - 186:16 1672 POP_TOP -187:3 - 187:4 1673 LOAD_NAME 0 (a) -187:3 - 187:16 1675 LOAD_METHOD 186 (f185) -187:10 - 187:15 1677 LOAD_STRING 185 ('185') -187:3 - 187:16 1679 CALL_METHOD 1 -187:3 - 187:16 1681 POP_TOP -188:3 - 188:4 1682 LOAD_NAME 0 (a) -188:3 - 188:16 1684 LOAD_METHOD 187 (f186) -188:10 - 188:15 1686 LOAD_STRING 186 ('186') -188:3 - 188:16 1688 CALL_METHOD 1 -188:3 - 188:16 1690 POP_TOP -189:3 - 189:4 1691 LOAD_NAME 0 (a) -189:3 - 189:16 1693 LOAD_METHOD 188 (f187) -189:10 - 189:15 1695 LOAD_STRING 187 ('187') -189:3 - 189:16 1697 CALL_METHOD 1 -189:3 - 189:16 1699 POP_TOP -190:3 - 190:4 1700 LOAD_NAME 0 (a) -190:3 - 190:16 1702 LOAD_METHOD 189 (f188) -190:10 - 190:15 1704 LOAD_STRING 188 ('188') -190:3 - 190:16 1706 CALL_METHOD 1 -190:3 - 190:16 1708 POP_TOP -191:3 - 191:4 1709 LOAD_NAME 0 (a) -191:3 - 191:16 1711 LOAD_METHOD 190 (f189) -191:10 - 191:15 1713 LOAD_STRING 189 ('189') -191:3 - 191:16 1715 CALL_METHOD 1 -191:3 - 191:16 1717 POP_TOP -192:3 - 192:4 1718 LOAD_NAME 0 (a) -192:3 - 192:16 1720 LOAD_METHOD 191 (f190) -192:10 - 192:15 1722 LOAD_STRING 190 ('190') -192:3 - 192:16 1724 CALL_METHOD 1 -192:3 - 192:16 1726 POP_TOP -193:3 - 193:4 1727 LOAD_NAME 0 (a) -193:3 - 193:16 1729 LOAD_METHOD 192 (f191) -193:10 - 193:15 1731 LOAD_STRING 191 ('191') -193:3 - 193:16 1733 CALL_METHOD 1 -193:3 - 193:16 1735 POP_TOP -194:3 - 194:4 1736 LOAD_NAME 0 (a) -194:3 - 194:16 1738 LOAD_METHOD 193 (f192) -194:10 - 194:15 1740 LOAD_STRING 192 ('192') -194:3 - 194:16 1742 CALL_METHOD 1 -194:3 - 194:16 1744 POP_TOP -195:3 - 195:4 1745 LOAD_NAME 0 (a) -195:3 - 195:16 1747 LOAD_METHOD 194 (f193) -195:10 - 195:15 1749 LOAD_STRING 193 ('193') -195:3 - 195:16 1751 CALL_METHOD 1 -195:3 - 195:16 1753 POP_TOP -196:3 - 196:4 1754 LOAD_NAME 0 (a) -196:3 - 196:16 1756 LOAD_METHOD 195 (f194) -196:10 - 196:15 1758 LOAD_STRING 194 ('194') -196:3 - 196:16 1760 CALL_METHOD 1 -196:3 - 196:16 1762 POP_TOP -197:3 - 197:4 1763 LOAD_NAME 0 (a) -197:3 - 197:16 1765 LOAD_METHOD 196 (f195) -197:10 - 197:15 1767 LOAD_STRING 195 ('195') -197:3 - 197:16 1769 CALL_METHOD 1 -197:3 - 197:16 1771 POP_TOP -198:3 - 198:4 1772 LOAD_NAME 0 (a) -198:3 - 198:16 1774 LOAD_METHOD 197 (f196) -198:10 - 198:15 1776 LOAD_STRING 196 ('196') -198:3 - 198:16 1778 CALL_METHOD 1 -198:3 - 198:16 1780 POP_TOP -199:3 - 199:4 1781 LOAD_NAME 0 (a) -199:3 - 199:16 1783 LOAD_METHOD 198 (f197) -199:10 - 199:15 1785 LOAD_STRING 197 ('197') -199:3 - 199:16 1787 CALL_METHOD 1 -199:3 - 199:16 1789 POP_TOP -200:3 - 200:4 1790 LOAD_NAME 0 (a) -200:3 - 200:16 1792 LOAD_METHOD 199 (f198) -200:10 - 200:15 1794 LOAD_STRING 198 ('198') -200:3 - 200:16 1796 CALL_METHOD 1 -200:3 - 200:16 1798 POP_TOP -201:3 - 201:4 1799 LOAD_NAME 0 (a) -201:3 - 201:16 1801 LOAD_METHOD 200 (f199) -201:10 - 201:15 1803 LOAD_STRING 199 ('199') -201:3 - 201:16 1805 CALL_METHOD 1 -201:3 - 201:16 1807 POP_TOP -202:3 - 202:4 1808 LOAD_NAME 0 (a) -202:3 - 202:16 1810 LOAD_METHOD 201 (f200) -202:10 - 202:15 1812 LOAD_STRING 200 ('200') -202:3 - 202:16 1814 CALL_METHOD 1 -202:3 - 202:16 1816 POP_TOP -203:3 - 203:4 1817 LOAD_NAME 0 (a) -203:3 - 203:16 1819 LOAD_METHOD 202 (f201) -203:10 - 203:15 1821 LOAD_STRING 201 ('201') -203:3 - 203:16 1823 CALL_METHOD 1 -203:3 - 203:16 1825 POP_TOP -204:3 - 204:4 1826 LOAD_NAME 0 (a) -204:3 - 204:16 1828 LOAD_METHOD 203 (f202) -204:10 - 204:15 1830 LOAD_STRING 202 ('202') -204:3 - 204:16 1832 CALL_METHOD 1 -204:3 - 204:16 1834 POP_TOP -205:3 - 205:4 1835 LOAD_NAME 0 (a) -205:3 - 205:16 1837 LOAD_METHOD 204 (f203) -205:10 - 205:15 1839 LOAD_STRING 203 ('203') -205:3 - 205:16 1841 CALL_METHOD 1 -205:3 - 205:16 1843 POP_TOP -206:3 - 206:4 1844 LOAD_NAME 0 (a) -206:3 - 206:16 1846 LOAD_METHOD 205 (f204) -206:10 - 206:15 1848 LOAD_STRING 204 ('204') -206:3 - 206:16 1850 CALL_METHOD 1 -206:3 - 206:16 1852 POP_TOP -207:3 - 207:4 1853 LOAD_NAME 0 (a) -207:3 - 207:16 1855 LOAD_METHOD 206 (f205) -207:10 - 207:15 1857 LOAD_STRING 205 ('205') -207:3 - 207:16 1859 CALL_METHOD 1 -207:3 - 207:16 1861 POP_TOP -208:3 - 208:4 1862 LOAD_NAME 0 (a) -208:3 - 208:16 1864 LOAD_METHOD 207 (f206) -208:10 - 208:15 1866 LOAD_STRING 206 ('206') -208:3 - 208:16 1868 CALL_METHOD 1 -208:3 - 208:16 1870 POP_TOP -209:3 - 209:4 1871 LOAD_NAME 0 (a) -209:3 - 209:16 1873 LOAD_METHOD 208 (f207) -209:10 - 209:15 1875 LOAD_STRING 207 ('207') -209:3 - 209:16 1877 CALL_METHOD 1 -209:3 - 209:16 1879 POP_TOP -210:3 - 210:4 1880 LOAD_NAME 0 (a) -210:3 - 210:16 1882 LOAD_METHOD 209 (f208) -210:10 - 210:15 1884 LOAD_STRING 208 ('208') -210:3 - 210:16 1886 CALL_METHOD 1 -210:3 - 210:16 1888 POP_TOP -211:3 - 211:4 1889 LOAD_NAME 0 (a) -211:3 - 211:16 1891 LOAD_METHOD 210 (f209) -211:10 - 211:15 1893 LOAD_STRING 209 ('209') -211:3 - 211:16 1895 CALL_METHOD 1 -211:3 - 211:16 1897 POP_TOP -212:3 - 212:4 1898 LOAD_NAME 0 (a) -212:3 - 212:16 1900 LOAD_METHOD 211 (f210) -212:10 - 212:15 1902 LOAD_STRING 210 ('210') -212:3 - 212:16 1904 CALL_METHOD 1 -212:3 - 212:16 1906 POP_TOP -213:3 - 213:4 1907 LOAD_NAME 0 (a) -213:3 - 213:16 1909 LOAD_METHOD 212 (f211) -213:10 - 213:15 1911 LOAD_STRING 211 ('211') -213:3 - 213:16 1913 CALL_METHOD 1 -213:3 - 213:16 1915 POP_TOP -214:3 - 214:4 1916 LOAD_NAME 0 (a) -214:3 - 214:16 1918 LOAD_METHOD 213 (f212) -214:10 - 214:15 1920 LOAD_STRING 212 ('212') -214:3 - 214:16 1922 CALL_METHOD 1 -214:3 - 214:16 1924 POP_TOP -215:3 - 215:4 1925 LOAD_NAME 0 (a) -215:3 - 215:16 1927 LOAD_METHOD 214 (f213) -215:10 - 215:15 1929 LOAD_STRING 213 ('213') -215:3 - 215:16 1931 CALL_METHOD 1 -215:3 - 215:16 1933 POP_TOP -216:3 - 216:4 1934 LOAD_NAME 0 (a) -216:3 - 216:16 1936 LOAD_METHOD 215 (f214) -216:10 - 216:15 1938 LOAD_STRING 214 ('214') -216:3 - 216:16 1940 CALL_METHOD 1 -216:3 - 216:16 1942 POP_TOP -217:3 - 217:4 1943 LOAD_NAME 0 (a) -217:3 - 217:16 1945 LOAD_METHOD 216 (f215) -217:10 - 217:15 1947 LOAD_STRING 215 ('215') -217:3 - 217:16 1949 CALL_METHOD 1 -217:3 - 217:16 1951 POP_TOP -218:3 - 218:4 1952 LOAD_NAME 0 (a) -218:3 - 218:16 1954 LOAD_METHOD 217 (f216) -218:10 - 218:15 1956 LOAD_STRING 216 ('216') -218:3 - 218:16 1958 CALL_METHOD 1 -218:3 - 218:16 1960 POP_TOP -219:3 - 219:4 1961 LOAD_NAME 0 (a) -219:3 - 219:16 1963 LOAD_METHOD 218 (f217) -219:10 - 219:15 1965 LOAD_STRING 217 ('217') -219:3 - 219:16 1967 CALL_METHOD 1 -219:3 - 219:16 1969 POP_TOP -220:3 - 220:4 1970 LOAD_NAME 0 (a) -220:3 - 220:16 1972 LOAD_METHOD 219 (f218) -220:10 - 220:15 1974 LOAD_STRING 218 ('218') -220:3 - 220:16 1976 CALL_METHOD 1 -220:3 - 220:16 1978 POP_TOP -221:3 - 221:4 1979 LOAD_NAME 0 (a) -221:3 - 221:16 1981 LOAD_METHOD 220 (f219) -221:10 - 221:15 1983 LOAD_STRING 219 ('219') -221:3 - 221:16 1985 CALL_METHOD 1 -221:3 - 221:16 1987 POP_TOP -222:3 - 222:4 1988 LOAD_NAME 0 (a) -222:3 - 222:16 1990 LOAD_METHOD 221 (f220) -222:10 - 222:15 1992 LOAD_STRING 220 ('220') -222:3 - 222:16 1994 CALL_METHOD 1 -222:3 - 222:16 1996 POP_TOP -223:3 - 223:4 1997 LOAD_NAME 0 (a) -223:3 - 223:16 1999 LOAD_METHOD 222 (f221) -223:10 - 223:15 2001 LOAD_STRING 221 ('221') -223:3 - 223:16 2003 CALL_METHOD 1 -223:3 - 223:16 2005 POP_TOP -224:3 - 224:4 2006 LOAD_NAME 0 (a) -224:3 - 224:16 2008 LOAD_METHOD 223 (f222) -224:10 - 224:15 2010 LOAD_STRING 222 ('222') -224:3 - 224:16 2012 CALL_METHOD 1 -224:3 - 224:16 2014 POP_TOP -225:3 - 225:4 2015 LOAD_NAME 0 (a) -225:3 - 225:16 2017 LOAD_METHOD 224 (f223) -225:10 - 225:15 2019 LOAD_STRING 223 ('223') -225:3 - 225:16 2021 CALL_METHOD 1 -225:3 - 225:16 2023 POP_TOP -226:3 - 226:4 2024 LOAD_NAME 0 (a) -226:3 - 226:16 2026 LOAD_METHOD 225 (f224) -226:10 - 226:15 2028 LOAD_STRING 224 ('224') -226:3 - 226:16 2030 CALL_METHOD 1 -226:3 - 226:16 2032 POP_TOP -227:3 - 227:4 2033 LOAD_NAME 0 (a) -227:3 - 227:16 2035 LOAD_METHOD 226 (f225) -227:10 - 227:15 2037 LOAD_STRING 225 ('225') -227:3 - 227:16 2039 CALL_METHOD 1 -227:3 - 227:16 2041 POP_TOP -228:3 - 228:4 2042 LOAD_NAME 0 (a) -228:3 - 228:16 2044 LOAD_METHOD 227 (f226) -228:10 - 228:15 2046 LOAD_STRING 226 ('226') -228:3 - 228:16 2048 CALL_METHOD 1 -228:3 - 228:16 2050 POP_TOP -229:3 - 229:4 2051 LOAD_NAME 0 (a) -229:3 - 229:16 2053 LOAD_METHOD 228 (f227) -229:10 - 229:15 2055 LOAD_STRING 227 ('227') -229:3 - 229:16 2057 CALL_METHOD 1 -229:3 - 229:16 2059 POP_TOP -230:3 - 230:4 2060 LOAD_NAME 0 (a) -230:3 - 230:16 2062 LOAD_METHOD 229 (f228) -230:10 - 230:15 2064 LOAD_STRING 228 ('228') -230:3 - 230:16 2066 CALL_METHOD 1 -230:3 - 230:16 2068 POP_TOP -231:3 - 231:4 2069 LOAD_NAME 0 (a) -231:3 - 231:16 2071 LOAD_METHOD 230 (f229) -231:10 - 231:15 2073 LOAD_STRING 229 ('229') -231:3 - 231:16 2075 CALL_METHOD 1 -231:3 - 231:16 2077 POP_TOP -232:3 - 232:4 2078 LOAD_NAME 0 (a) -232:3 - 232:16 2080 LOAD_METHOD 231 (f230) -232:10 - 232:15 2082 LOAD_STRING 230 ('230') -232:3 - 232:16 2084 CALL_METHOD 1 -232:3 - 232:16 2086 POP_TOP -233:3 - 233:4 2087 LOAD_NAME 0 (a) -233:3 - 233:16 2089 LOAD_METHOD 232 (f231) -233:10 - 233:15 2091 LOAD_STRING 231 ('231') -233:3 - 233:16 2093 CALL_METHOD 1 -233:3 - 233:16 2095 POP_TOP -234:3 - 234:4 2096 LOAD_NAME 0 (a) -234:3 - 234:16 2098 LOAD_METHOD 233 (f232) -234:10 - 234:15 2100 LOAD_STRING 232 ('232') -234:3 - 234:16 2102 CALL_METHOD 1 -234:3 - 234:16 2104 POP_TOP -235:3 - 235:4 2105 LOAD_NAME 0 (a) -235:3 - 235:16 2107 LOAD_METHOD 234 (f233) -235:10 - 235:15 2109 LOAD_STRING 233 ('233') -235:3 - 235:16 2111 CALL_METHOD 1 -235:3 - 235:16 2113 POP_TOP -236:3 - 236:4 2114 LOAD_NAME 0 (a) -236:3 - 236:16 2116 LOAD_METHOD 235 (f234) -236:10 - 236:15 2118 LOAD_STRING 234 ('234') -236:3 - 236:16 2120 CALL_METHOD 1 -236:3 - 236:16 2122 POP_TOP -237:3 - 237:4 2123 LOAD_NAME 0 (a) -237:3 - 237:16 2125 LOAD_METHOD 236 (f235) -237:10 - 237:15 2127 LOAD_STRING 235 ('235') -237:3 - 237:16 2129 CALL_METHOD 1 -237:3 - 237:16 2131 POP_TOP -238:3 - 238:4 2132 LOAD_NAME 0 (a) -238:3 - 238:16 2134 LOAD_METHOD 237 (f236) -238:10 - 238:15 2136 LOAD_STRING 236 ('236') -238:3 - 238:16 2138 CALL_METHOD 1 -238:3 - 238:16 2140 POP_TOP -239:3 - 239:4 2141 LOAD_NAME 0 (a) -239:3 - 239:16 2143 LOAD_METHOD 238 (f237) -239:10 - 239:15 2145 LOAD_STRING 237 ('237') -239:3 - 239:16 2147 CALL_METHOD 1 -239:3 - 239:16 2149 POP_TOP -240:3 - 240:4 2150 LOAD_NAME 0 (a) -240:3 - 240:16 2152 LOAD_METHOD 239 (f238) -240:10 - 240:15 2154 LOAD_STRING 238 ('238') -240:3 - 240:16 2156 CALL_METHOD 1 -240:3 - 240:16 2158 POP_TOP -241:3 - 241:4 2159 LOAD_NAME 0 (a) -241:3 - 241:16 2161 LOAD_METHOD 240 (f239) -241:10 - 241:15 2163 LOAD_STRING 239 ('239') -241:3 - 241:16 2165 CALL_METHOD 1 -241:3 - 241:16 2167 POP_TOP -242:3 - 242:4 2168 LOAD_NAME 0 (a) -242:3 - 242:16 2170 LOAD_METHOD 241 (f240) -242:10 - 242:15 2172 LOAD_STRING 240 ('240') -242:3 - 242:16 2174 CALL_METHOD 1 -242:3 - 242:16 2176 POP_TOP -243:3 - 243:4 2177 LOAD_NAME 0 (a) -243:3 - 243:16 2179 LOAD_METHOD 242 (f241) -243:10 - 243:15 2181 LOAD_STRING 241 ('241') -243:3 - 243:16 2183 CALL_METHOD 1 -243:3 - 243:16 2185 POP_TOP -244:3 - 244:4 2186 LOAD_NAME 0 (a) -244:3 - 244:16 2188 LOAD_METHOD 243 (f242) -244:10 - 244:15 2190 LOAD_STRING 242 ('242') -244:3 - 244:16 2192 CALL_METHOD 1 -244:3 - 244:16 2194 POP_TOP -245:3 - 245:4 2195 LOAD_NAME 0 (a) -245:3 - 245:16 2197 LOAD_METHOD 244 (f243) -245:10 - 245:15 2199 LOAD_STRING 243 ('243') -245:3 - 245:16 2201 CALL_METHOD 1 -245:3 - 245:16 2203 POP_TOP -246:3 - 246:4 2204 LOAD_NAME 0 (a) -246:3 - 246:16 2206 LOAD_METHOD 245 (f244) -246:10 - 246:15 2208 LOAD_STRING 244 ('244') -246:3 - 246:16 2210 CALL_METHOD 1 -246:3 - 246:16 2212 POP_TOP -247:3 - 247:4 2213 LOAD_NAME 0 (a) -247:3 - 247:16 2215 LOAD_METHOD 246 (f245) -247:10 - 247:15 2217 LOAD_STRING 245 ('245') -247:3 - 247:16 2219 CALL_METHOD 1 -247:3 - 247:16 2221 POP_TOP -248:3 - 248:4 2222 LOAD_NAME 0 (a) -248:3 - 248:16 2224 LOAD_METHOD 247 (f246) -248:10 - 248:15 2226 LOAD_STRING 246 ('246') -248:3 - 248:16 2228 CALL_METHOD 1 -248:3 - 248:16 2230 POP_TOP -249:3 - 249:4 2231 LOAD_NAME 0 (a) -249:3 - 249:16 2233 LOAD_METHOD 248 (f247) -249:10 - 249:15 2235 LOAD_STRING 247 ('247') -249:3 - 249:16 2237 CALL_METHOD 1 -249:3 - 249:16 2239 POP_TOP -250:3 - 250:4 2240 LOAD_NAME 0 (a) -250:3 - 250:16 2242 LOAD_METHOD 249 (f248) -250:10 - 250:15 2244 LOAD_STRING 248 ('248') -250:3 - 250:16 2246 CALL_METHOD 1 -250:3 - 250:16 2248 POP_TOP -251:3 - 251:4 2249 LOAD_NAME 0 (a) -251:3 - 251:16 2251 LOAD_METHOD 250 (f249) -251:10 - 251:15 2253 LOAD_STRING 249 ('249') -251:3 - 251:16 2255 CALL_METHOD 1 -251:3 - 251:16 2257 POP_TOP -252:3 - 252:4 2258 LOAD_NAME 0 (a) -252:3 - 252:16 2260 LOAD_METHOD 251 (f250) -252:10 - 252:15 2262 LOAD_STRING 250 ('250') -252:3 - 252:16 2264 CALL_METHOD 1 -252:3 - 252:16 2266 POP_TOP -253:3 - 253:4 2267 LOAD_NAME 0 (a) -253:3 - 253:16 2269 LOAD_METHOD 252 (f251) -253:10 - 253:15 2271 LOAD_STRING 251 ('251') -253:3 - 253:16 2273 CALL_METHOD 1 -253:3 - 253:16 2275 POP_TOP -254:3 - 254:4 2276 LOAD_NAME 0 (a) -254:3 - 254:16 2278 LOAD_METHOD 253 (f252) -254:10 - 254:15 2280 LOAD_STRING 252 ('252') -254:3 - 254:16 2282 CALL_METHOD 1 -254:3 - 254:16 2284 POP_TOP -255:3 - 255:4 2285 LOAD_NAME 0 (a) -255:3 - 255:16 2287 LOAD_METHOD 254 (f253) -255:10 - 255:15 2289 LOAD_STRING 253 ('253') -255:3 - 255:16 2291 CALL_METHOD 1 -255:3 - 255:16 2293 POP_TOP -256:3 - 256:4 2294 LOAD_NAME 0 (a) -256:3 - 256:16 2296 LOAD_METHOD 255 (f254) -256:10 - 256:15 2298 LOAD_STRING 254 ('254') -256:3 - 256:16 2300 CALL_METHOD 1 -256:3 - 256:16 2302 POP_TOP -257:3 - 257:4 2303 LOAD_NAME 0 (a) -257:3 - 257:16 2305 EXTENDED_ARG -257:3 - 257:16 2307 LOAD_METHOD 256 (f255) -257:10 - 257:15 2309 LOAD_STRING 255 ('255') -257:3 - 257:16 2311 CALL_METHOD 1 -257:3 - 257:16 2313 POP_TOP -258:3 - 258:4 2314 LOAD_NAME 0 (a) -258:3 - 258:16 2316 EXTENDED_ARG -258:3 - 258:16 2318 LOAD_METHOD 257 (f256) -258:10 - 258:15 2320 EXTENDED_ARG -258:10 - 258:15 2322 LOAD_STRING 256 ('256') -258:3 - 258:16 2324 CALL_METHOD 1 -258:3 - 258:16 2326 POP_TOP -259:3 - 259:4 2327 LOAD_NAME 0 (a) -259:3 - 259:16 2329 EXTENDED_ARG -259:3 - 259:16 2331 LOAD_METHOD 258 (f257) -259:10 - 259:15 2333 EXTENDED_ARG -259:10 - 259:15 2335 LOAD_STRING 257 ('257') -259:3 - 259:16 2337 CALL_METHOD 1 -259:3 - 259:16 2339 POP_TOP -260:3 - 260:4 2340 LOAD_NAME 0 (a) -260:3 - 260:16 2342 EXTENDED_ARG -260:3 - 260:16 2344 LOAD_METHOD 259 (f258) -260:10 - 260:15 2346 EXTENDED_ARG -260:10 - 260:15 2348 LOAD_STRING 258 ('258') -260:3 - 260:16 2350 CALL_METHOD 1 -260:3 - 260:16 2352 POP_TOP -261:3 - 261:4 2353 LOAD_NAME 0 (a) -261:3 - 261:16 2355 EXTENDED_ARG -261:3 - 261:16 2357 LOAD_METHOD 260 (f259) -261:10 - 261:15 2359 EXTENDED_ARG -261:10 - 261:15 2361 LOAD_STRING 259 ('259') -261:3 - 261:16 2363 CALL_METHOD 1 -261:3 - 261:16 2365 POP_TOP -261:3 - 261:16 2366 JUMP_FORWARD 13 (to 2379) -263:4 - 263:9 >> 2368 EXTENDED_ARG -263:4 - 263:9 2370 LOAD_NAME 261 (print) -263:10 - 263:16 2372 EXTENDED_ARG -263:10 - 263:16 2374 LOAD_STRING 260 ('else') -263:4 - 263:17 2376 CALL_FUNCTION 1 -263:4 - 263:17 2378 POP_TOP -263:4 - 263:17 >> 2379 LOAD_NONE -263:4 - 263:17 2380 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFString.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFString.co deleted file mode 100644 index 6be63e4cea..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFString.co +++ /dev/null @@ -1,18 +0,0 @@ -Disassembly of : - 1:0 - 1:30 0 LOAD_STRING 0 ('') - 1:0 - 1:30 2 LOAD_METHOD 0 (join) - 1:2 - 1:8 4 LOAD_STRING 1 ('before') - 1:9 - 1:10 6 LOAD_NAME 1 (a) - 1:8 - 1:11 8 FORMAT_VALUE 0 (NONE) - 1:11 - 1:17 10 LOAD_STRING 2 ('middle') - 1:18 - 1:19 12 LOAD_NAME 2 (b) - 1:21 - 1:23 14 LOAD_STRING 0 ('') - 1:21 - 1:23 16 LOAD_METHOD 0 (join) - 1:22 - 1:23 18 LOAD_STRING 3 ('5') - 1:21 - 1:23 20 COLLECTION_FROM_STACK 1 (list) - 1:21 - 1:23 22 CALL_METHOD 1 - 1:17 - 1:24 24 FORMAT_VALUE 6 (REPR + SPEC) - 1:24 - 1:29 26 LOAD_STRING 4 ('after') - 1:0 - 1:30 28 COLLECTION_FROM_STACK 5 (list) - 1:0 - 1:30 30 CALL_METHOD 1 - 1:0 - 1:30 32 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFinallyCancelReturn.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFinallyCancelReturn.co deleted file mode 100644 index 159868812a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFinallyCancelReturn.co +++ /dev/null @@ -1,30 +0,0 @@ -Disassembly of : - 1:0 - 5:26 0 MAKE_FUNCTION 0 (foo) - 1:0 - 5:26 3 STORE_NAME 0 (foo) - 1:0 - 5:26 5 LOAD_NONE - 1:0 - 5:26 6 RETURN_VALUE - -Disassembly of foo: - 2:11 - 2:16 0 LOAD_GLOBAL 0 (range) - 2:17 - 2:19 2 LOAD_BYTE 10 - 2:11 - 2:20 4 CALL_FUNCTION 1 - 2:2 - 5:26 6 GET_ITER - 2:2 - 5:26 >> 7 FOR_ITER 25 (to 32) - 2:6 - 2:7 9 STORE_FAST 0 (i) generalizes: 7 - 3:4 - 5:26 11 NOP - 4:13 - 4:14 12 LOAD_GLOBAL 1 (a) - 5:18 - 5:26 14 POP_TOP - 5:18 - 5:26 15 JUMP_BACKWARD 8 (to 7) - 5:18 - 5:26 17 ROT_TWO - 5:18 - 5:26 18 POP_TOP - 5:18 - 5:26 19 RETURN_VALUE - 5:18 - 5:26 20 JUMP_FORWARD 8 (to 28) - 5:18 - 5:26 22 PUSH_EXC_INFO (exc handler 12 - 14; stack: 1) - 5:18 - 5:26 23 POP_EXCEPT - 5:18 - 5:26 24 POP_TOP - 5:18 - 5:26 25 JUMP_BACKWARD 18 (to 7) - 5:18 - 5:26 27 END_EXC_HANDLER (exc handler 23 - 27; stack: 2) - 5:18 - 5:26 >> 28 JUMP_BACKWARD 21 (to 7) - 5:18 - 5:26 30 JUMP_BACKWARD 23 (to 7) - 5:18 - 5:26 >> 32 LOAD_NONE - 5:18 - 5:26 33 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFor.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFor.co deleted file mode 100644 index e4818c05ae..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testFor.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_CONST_COLLECTION 0 ([1, 2] type int into list) - 1:0 - 2:5 3 GET_ITER - 1:0 - 2:5 >> 4 FOR_ITER 7 (to 11) - 1:4 - 1:5 6 STORE_NAME 0 (i) - 2:1 - 2:5 8 NOP - 2:1 - 2:5 9 JUMP_BACKWARD 5 (to 4) - 2:1 - 2:5 >> 11 LOAD_NONE - 2:1 - 2:5 12 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testForBreakContinue.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testForBreakContinue.co deleted file mode 100644 index bba36bbb27..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testForBreakContinue.co +++ /dev/null @@ -1,22 +0,0 @@ -Disassembly of : - 1:9 - 1:14 0 LOAD_NAME 0 (range) - 1:15 - 1:17 2 LOAD_BYTE 10 - 1:9 - 1:18 4 CALL_FUNCTION 1 - 1:0 - 7:15 6 GET_ITER - 1:0 - 7:15 >> 7 FOR_ITER 23 (to 30) - 1:4 - 1:5 9 STORE_NAME 1 (i) - 2:5 - 2:6 11 LOAD_NAME 1 (i) - 2:10 - 2:11 13 LOAD_BYTE 3 - 2:5 - 2:11 15 BINARY_OP 12 (EQ) - 2:2 - 5:12 17 POP_AND_JUMP_IF_FALSE 9 (to 26) generalizes: 15 - 3:4 - 3:9 21 POP_TOP - 3:4 - 3:9 22 JUMP_FORWARD 15 (to 37) - 3:4 - 3:9 24 JUMP_FORWARD 4 (to 28) - 5:4 - 5:12 >> 26 JUMP_BACKWARD 19 (to 7) - 5:4 - 5:12 >> 28 JUMP_BACKWARD 21 (to 7) - 7:2 - 7:7 >> 30 LOAD_NAME 2 (print) - 7:8 - 7:14 32 LOAD_STRING 0 ('else') - 7:2 - 7:15 34 CALL_FUNCTION 1 - 7:2 - 7:15 36 POP_TOP - 7:2 - 7:15 >> 37 LOAD_NONE - 7:2 - 7:15 38 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGeneratorComprehension.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGeneratorComprehension.co deleted file mode 100644 index 8b3cc82ff4..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGeneratorComprehension.co +++ /dev/null @@ -1,32 +0,0 @@ -Disassembly of : - 1:0 - 1:60 0 MAKE_FUNCTION 0 () - 1:18 - 1:27 3 LOAD_CONST_COLLECTION 1 ([1, 2, 3] type int into list) - 1:29 - 1:38 6 LOAD_CONST_COLLECTION 2 ([4, 5, 6] type int into list) - 1:17 - 1:39 9 COLLECTION_FROM_STACK 2 (list) - 1:0 - 1:60 11 GET_ITER - 1:0 - 1:60 12 CALL_COMPREHENSION - 1:0 - 1:60 13 RETURN_VALUE - -Disassembly of : -Flags: CO_GENERATOR - 1:0 - 1:60 0 LOAD_FAST 0 (.0) - 1:0 - 1:60 >> 2 FOR_ITER 34 (to 36) - 1:12 - 1:13 4 STORE_FAST 1 (y) generalizes: 2 - 1:49 - 1:50 6 LOAD_FAST 1 (y) - 1:0 - 1:60 8 GET_ITER - 1:0 - 1:60 >> 9 FOR_ITER 25 (to 34) - 1:44 - 1:45 11 STORE_FAST 2 (x) generalizes: 9 - 1:54 - 1:55 13 LOAD_FAST 2 (x) - 1:58 - 1:59 15 LOAD_BYTE 5 - 1:54 - 1:59 17 BINARY_OP 14 (LT) generalizes: 15, 13 - 1:0 - 1:60 19 POP_AND_JUMP_IF_FALSE 13 (to 32) generalizes: 17 - 1:1 - 1:4 23 LOAD_GLOBAL 0 (str) - 1:5 - 1:6 25 LOAD_FAST 2 (x) - 1:1 - 1:7 27 CALL_FUNCTION 1 - 1:0 - 1:60 29 YIELD_VALUE - 1:0 - 1:60 30 RESUME_YIELD - 1:0 - 1:60 31 POP_TOP - 1:0 - 1:60 >> 32 JUMP_BACKWARD 23 (to 9) - 1:0 - 1:60 >> 34 JUMP_BACKWARD 32 (to 2) - 1:0 - 1:60 >> 36 LOAD_NONE - 1:0 - 1:60 37 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGetItem.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGetItem.co deleted file mode 100644 index fa810af466..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGetItem.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:2 - 1:3 2 LOAD_BYTE 3 - 1:0 - 1:4 4 BINARY_SUBSCR generalizes: 2 - 1:0 - 1:4 5 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGuard.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGuard.co deleted file mode 100644 index f16aa4fbfd..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testGuard.co +++ /dev/null @@ -1,16 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 LOAD_BYTE 1 - 1:0 - 1:1 2 STORE_NAME 0 (x) - 2:6 - 2:7 4 LOAD_BYTE 1 - 3:8 - 3:9 6 LOAD_BYTE 1 - 3:8 - 3:9 8 BINARY_OP 12 (EQ) generalizes: 6, 4 - 3:8 - 3:9 10 POP_AND_JUMP_IF_FALSE 19 (to 29) generalizes: 8 - 3:13 - 3:14 14 LOAD_NAME 0 (x) - 3:18 - 3:19 16 LOAD_BYTE 1 - 3:13 - 3:19 18 BINARY_OP 12 (EQ) - 3:8 - 3:9 20 POP_AND_JUMP_IF_FALSE 9 (to 29) generalizes: 18 - 4:7 - 4:8 24 LOAD_NAME 0 (x) - 4:7 - 4:8 26 POP_TOP - 4:7 - 4:8 27 JUMP_FORWARD 2 (to 29) - 3:3 - 4:8 >> 29 LOAD_NONE - 3:3 - 4:8 30 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIf.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIf.co deleted file mode 100644 index 9997d9a7c5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIf.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:3 - 1:8 0 LOAD_FALSE - 1:0 - 4:15 1 POP_AND_JUMP_IF_FALSE 12 (to 13) generalizes: 0 - 2:3 - 2:8 5 LOAD_NAME 0 (print) - 2:9 - 2:13 7 LOAD_TRUE - 2:3 - 2:14 8 CALL_FUNCTION 1 - 2:3 - 2:14 10 POP_TOP - 2:3 - 2:14 11 JUMP_FORWARD 8 (to 19) - 4:3 - 4:8 >> 13 LOAD_NAME 0 (print) - 4:9 - 4:14 15 LOAD_FALSE - 4:3 - 4:15 16 CALL_FUNCTION 1 - 4:3 - 4:15 18 POP_TOP - 4:3 - 4:15 >> 19 LOAD_NONE - 4:3 - 4:15 20 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIfExpression.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIfExpression.co deleted file mode 100644 index dcf6d3e7b3..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testIfExpression.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:5 - 1:9 0 LOAD_NAME 0 (cond) - 1:0 - 1:16 2 POP_AND_JUMP_IF_FALSE 8 (to 10) - 1:0 - 1:1 6 LOAD_NAME 1 (t) - 1:0 - 1:16 8 JUMP_FORWARD 4 (to 12) - 1:15 - 1:16 >> 10 LOAD_NAME 2 (f) - 1:0 - 1:16 >> 12 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImport.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImport.co deleted file mode 100644 index 65bcef9c36..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImport.co +++ /dev/null @@ -1,68 +0,0 @@ -Disassembly of : - 1:3 - 1:11 0 LOAD_NAME 0 (__name__) - 1:15 - 1:25 2 LOAD_STRING 0 ('__main__') - 1:3 - 1:25 4 BINARY_OP 12 (EQ) - 1:0 - 11:63 6 POP_AND_JUMP_IF_FALSE 127 (to 133) generalizes: 4 - 2:4 - 2:14 10 LOAD_BYTE 0 - 2:4 - 2:14 12 LOAD_CONST 1 ([]) - 2:4 - 2:14 14 IMPORT_NAME 1 (sys) - 2:4 - 2:14 16 STORE_NAME 1 (sys) - 3:12 - 3:15 18 LOAD_NAME 2 (len) - 3:16 - 3:19 20 LOAD_NAME 1 (sys) - 3:16 - 3:24 22 LOAD_ATTR 3 (argv) - 3:12 - 3:25 24 CALL_FUNCTION 1 - 3:29 - 3:30 26 LOAD_BYTE 1 - 3:12 - 3:30 28 BINARY_OP 12 (EQ) - 3:12 - 3:72 30 JUMP_IF_FALSE_OR_POP 15 (to 45) - 3:35 - 3:38 34 LOAD_NAME 1 (sys) - 3:35 - 3:43 36 LOAD_ATTR 3 (argv) - 3:44 - 3:45 38 LOAD_BYTE 0 - 3:35 - 3:46 40 BINARY_SUBSCR generalizes: 38 - 3:50 - 3:72 41 LOAD_STRING 2 ('java_embedding_bench') - 3:35 - 3:72 43 BINARY_OP 12 (EQ) - 3:7 - 3:73 >> 45 UNARY_OP 0 (NOT) generalizes: 43 - 3:4 - 11:63 47 POP_AND_JUMP_IF_FALSE 86 (to 133) generalizes: 45 - 4:8 - 4:19 51 LOAD_BYTE 0 - 4:8 - 4:19 53 LOAD_CONST 1 ([]) - 4:8 - 4:19 55 IMPORT_NAME 4 (time) - 4:8 - 4:19 57 STORE_NAME 4 (time) - 5:16 - 5:20 59 LOAD_NAME 4 (time) - 5:16 - 5:27 61 LOAD_METHOD 4 (time) - 5:16 - 5:27 63 CALL_METHOD 0 - 5:8 - 5:13 65 STORE_NAME 5 (start) - 6:11 - 6:14 67 LOAD_NAME 2 (len) - 6:15 - 6:18 69 LOAD_NAME 1 (sys) - 6:15 - 6:23 71 LOAD_ATTR 3 (argv) - 6:11 - 6:24 73 CALL_FUNCTION 1 - 6:28 - 6:29 75 LOAD_BYTE 2 - 6:11 - 6:29 77 BINARY_OP 17 (GE) - 6:8 - 10:27 79 POP_AND_JUMP_IF_FALSE 26 (to 105) generalizes: 77 - 7:18 - 7:21 83 LOAD_NAME 6 (int) - 7:22 - 7:25 85 LOAD_NAME 1 (sys) - 7:22 - 7:30 87 LOAD_ATTR 3 (argv) - 7:31 - 7:32 89 LOAD_BYTE 1 - 7:22 - 7:33 91 BINARY_SUBSCR generalizes: 89 - 7:18 - 7:34 92 CALL_FUNCTION 1 - 7:12 - 7:15 94 STORE_NAME 7 (num) - 8:12 - 8:25 96 LOAD_NAME 8 (__benchmark__) - 8:26 - 8:29 98 LOAD_NAME 7 (num) - 8:12 - 8:30 100 CALL_FUNCTION 1 - 8:12 - 8:30 102 POP_TOP - 8:12 - 8:30 103 JUMP_FORWARD 7 (to 110) - 10:12 - 10:25 >> 105 LOAD_NAME 8 (__benchmark__) - 10:12 - 10:27 107 CALL_FUNCTION 0 - 10:12 - 10:27 109 POP_TOP - 11:8 - 11:13 >> 110 LOAD_NAME 9 (print) - 11:14 - 11:28 112 LOAD_STRING 3 ('%s took %s s') - 11:32 - 11:40 114 LOAD_NAME 10 (__file__) - 11:42 - 11:46 116 LOAD_NAME 4 (time) - 11:42 - 11:53 118 LOAD_METHOD 4 (time) - 11:42 - 11:53 120 CALL_METHOD 0 - 11:56 - 11:61 122 LOAD_NAME 5 (start) - 11:42 - 11:61 124 BINARY_OP 2 (SUB) - 11:31 - 11:62 126 COLLECTION_FROM_STACK 2 (tuple) - 11:14 - 11:62 128 BINARY_OP 10 (MOD) - 11:8 - 11:63 130 CALL_FUNCTION 1 - 11:8 - 11:63 132 POP_TOP - 11:8 - 11:63 >> 133 LOAD_NONE - 11:8 - 11:63 134 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportAs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportAs.co deleted file mode 100644 index 4e95fa4091..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportAs.co +++ /dev/null @@ -1,12 +0,0 @@ -Disassembly of : - 1:0 - 1:17 0 LOAD_BYTE 0 - 1:0 - 1:17 2 LOAD_CONST 0 ([]) - 1:0 - 1:17 4 IMPORT_NAME 0 (a.b.c) - 1:0 - 1:17 6 IMPORT_FROM 1 (b) - 1:0 - 1:17 8 ROT_TWO - 1:0 - 1:17 9 POP_TOP - 1:0 - 1:17 10 IMPORT_FROM 2 (c) - 1:0 - 1:17 12 STORE_NAME 3 (d) - 1:0 - 1:17 14 POP_TOP - 1:0 - 1:17 15 LOAD_NONE - 1:0 - 1:17 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportFrom.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportFrom.co deleted file mode 100644 index c095a53d9e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportFrom.co +++ /dev/null @@ -1,11 +0,0 @@ -Disassembly of : - 1:0 - 1:34 0 LOAD_BYTE 0 - 1:0 - 1:34 2 LOAD_CONST 0 ([sqrt, sin]) - 1:0 - 1:34 4 IMPORT_NAME 0 (math) - 1:0 - 1:34 6 IMPORT_FROM 1 (sqrt) - 1:0 - 1:34 8 STORE_NAME 1 (sqrt) - 1:0 - 1:34 10 IMPORT_FROM 2 (sin) - 1:0 - 1:34 12 STORE_NAME 3 (sine) - 1:0 - 1:34 14 POP_TOP - 1:0 - 1:34 15 LOAD_NONE - 1:0 - 1:34 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportStar.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportStar.co deleted file mode 100644 index 20e4da9c4f..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testImportStar.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:17 0 LOAD_BYTE 0 - 1:0 - 1:17 2 IMPORT_STAR 0 - 1:0 - 1:17 4 LOAD_NONE - 1:0 - 1:17 5 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLambda.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLambda.co deleted file mode 100644 index 360517142e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLambda.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:0 - 1:24 0 MAKE_FUNCTION 0 () - 1:0 - 1:24 3 RETURN_VALUE - -Disassembly of : - 1:17 - 1:21 0 LOAD_FAST 1 (args) - 1:22 - 1:23 2 LOAD_FAST 0 (x) - 1:17 - 1:24 4 BINARY_SUBSCR generalizes: 2 - 1:0 - 1:24 5 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListComprehension.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListComprehension.co deleted file mode 100644 index e6cec7ba75..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListComprehension.co +++ /dev/null @@ -1,29 +0,0 @@ -Disassembly of : - 1:0 - 1:60 0 MAKE_FUNCTION 0 () - 1:18 - 1:27 3 LOAD_CONST_COLLECTION 1 ([1, 2, 3] type int into list) - 1:29 - 1:38 6 LOAD_CONST_COLLECTION 2 ([4, 5, 6] type int into list) - 1:17 - 1:39 9 COLLECTION_FROM_STACK 2 (list) - 1:0 - 1:60 11 GET_ITER - 1:0 - 1:60 12 CALL_COMPREHENSION - 1:0 - 1:60 13 RETURN_VALUE - -Disassembly of : - 1:0 - 1:60 0 COLLECTION_FROM_STACK 0 (list) - 1:0 - 1:60 2 LOAD_FAST 0 (.0) - 1:0 - 1:60 >> 4 FOR_ITER 33 (to 37) - 1:12 - 1:13 6 STORE_FAST 1 (y) generalizes: 4 - 1:49 - 1:50 8 LOAD_FAST 1 (y) - 1:0 - 1:60 10 GET_ITER - 1:0 - 1:60 >> 11 FOR_ITER 24 (to 35) - 1:44 - 1:45 13 STORE_FAST 2 (x) generalizes: 11 - 1:54 - 1:55 15 LOAD_FAST 2 (x) - 1:58 - 1:59 17 LOAD_BYTE 5 - 1:54 - 1:59 19 BINARY_OP 14 (LT) generalizes: 17, 15 - 1:0 - 1:60 21 POP_AND_JUMP_IF_FALSE 12 (to 33) generalizes: 19 - 1:1 - 1:4 25 LOAD_GLOBAL 0 (str) - 1:5 - 1:6 27 LOAD_FAST 2 (x) - 1:1 - 1:7 29 CALL_FUNCTION 1 - 1:0 - 1:60 31 ADD_TO_COLLECTION 3 (list) - 1:0 - 1:60 >> 33 JUMP_BACKWARD 22 (to 11) - 1:0 - 1:60 >> 35 JUMP_BACKWARD 31 (to 4) - 1:0 - 1:60 >> 37 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteral.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteral.co deleted file mode 100644 index 4384389afe..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteral.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:9 0 LOAD_CONST_COLLECTION 0 ([1, 2, 3] type int into list) - 1:0 - 1:9 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteralExpand.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteralExpand.co deleted file mode 100644 index c74da8e81d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testListLiteralExpand.co +++ /dev/null @@ -1,10 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 2 - 1:7 - 1:8 4 LOAD_BYTE 3 - 1:0 - 1:16 6 COLLECTION_FROM_STACK 3 (list) - 1:11 - 1:12 8 LOAD_NAME 0 (a) - 1:0 - 1:16 10 COLLECTION_ADD_COLLECTION 0 (list) - 1:14 - 1:15 12 LOAD_BYTE 5 - 1:0 - 1:16 14 COLLECTION_ADD_STACK 1 (list) - 1:0 - 1:16 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLoadClassDefRef.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLoadClassDefRef.co deleted file mode 100644 index 32325732d3..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLoadClassDefRef.co +++ /dev/null @@ -1,30 +0,0 @@ -Disassembly of : - 1:0 - 2:18 0 MAKE_FUNCTION 0 (f) - 1:0 - 2:18 3 STORE_NAME 0 (f) - 3:0 - 3:1 5 LOAD_NAME 0 (f) - 3:2 - 3:3 7 LOAD_BYTE 1 - 3:0 - 3:4 9 CALL_FUNCTION 1 - 3:0 - 3:4 11 RETURN_VALUE - -Disassembly of f: - 2:4 - 2:18 0 LOAD_BUILD_CLASS - 2:4 - 2:18 1 LOAD_CLOSURE 0 (x) - 2:4 - 2:18 3 CLOSURE_FROM_STACK 1 - 2:4 - 2:18 5 MAKE_FUNCTION 8 (f..C) - 2:4 - 2:18 8 LOAD_STRING 2 ('C') - 2:4 - 2:18 10 COLLECTION_FROM_STACK 2 (Object[]) - 2:4 - 2:18 12 CALL_FUNCTION_VARARGS - 2:4 - 2:18 13 STORE_FAST 1 (C) - 2:4 - 2:18 15 LOAD_NONE - 2:4 - 2:18 16 RETURN_VALUE - -Disassembly of f..C: - 2:4 - 2:18 0 LOAD_NAME 0 (__name__) - 2:4 - 2:18 2 STORE_NAME 1 (__module__) - 2:4 - 2:18 4 LOAD_STRING 0 ('f..C') - 2:4 - 2:18 6 STORE_NAME 2 (__qualname__) - 2:17 - 2:18 8 LOAD_LOCALS - 2:17 - 2:18 9 LOAD_FROM_DICT_OR_DEREF 0 (x) - 2:13 - 2:14 11 STORE_NAME 3 (y) - 2:13 - 2:18 13 LOAD_NONE - 2:13 - 2:18 14 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLogicOperators.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLogicOperators.co deleted file mode 100644 index 166d392970..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testLogicOperators.co +++ /dev/null @@ -1,8 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:0 - 1:7 2 JUMP_IF_FALSE_OR_POP 6 (to 8) - 1:6 - 1:7 6 LOAD_NAME 1 (b) - 1:0 - 1:16 >> 8 JUMP_IF_TRUE_OR_POP 8 (to 16) - 1:15 - 1:16 12 LOAD_NAME 2 (c) - 1:11 - 1:16 14 UNARY_OP 0 (NOT) - 1:0 - 1:16 >> 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testManyArgs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testManyArgs.co deleted file mode 100644 index 3bb02b5692..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testManyArgs.co +++ /dev/null @@ -1,42 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:7 2 LOAD_BYTE 1 - 1:9 - 1:10 4 LOAD_BYTE 2 - 1:12 - 1:13 6 LOAD_BYTE 3 - 1:15 - 1:16 8 LOAD_BYTE 4 - 1:18 - 1:19 10 LOAD_BYTE 5 - 1:21 - 1:22 12 LOAD_BYTE 6 - 1:24 - 1:25 14 LOAD_BYTE 7 - 1:27 - 1:28 16 LOAD_BYTE 8 - 1:30 - 1:31 18 LOAD_BYTE 9 - 1:33 - 1:35 20 LOAD_BYTE 10 - 1:37 - 1:39 22 LOAD_BYTE 11 - 1:41 - 1:43 24 LOAD_BYTE 12 - 1:45 - 1:47 26 LOAD_BYTE 13 - 1:49 - 1:51 28 LOAD_BYTE 14 - 1:53 - 1:55 30 LOAD_BYTE 15 - 1:57 - 1:59 32 LOAD_BYTE 16 - 1:61 - 1:63 34 LOAD_BYTE 17 - 1:65 - 1:67 36 LOAD_BYTE 18 - 1:69 - 1:71 38 LOAD_BYTE 19 - 1:73 - 1:75 40 LOAD_BYTE 20 - 1:77 - 1:79 42 LOAD_BYTE 21 - 1:81 - 1:83 44 LOAD_BYTE 22 - 1:85 - 1:87 46 LOAD_BYTE 23 - 1:89 - 1:91 48 LOAD_BYTE 24 - 1:93 - 1:95 50 LOAD_BYTE 25 - 1:97 - 1:99 52 LOAD_BYTE 26 - 1:101 - 1:103 54 LOAD_BYTE 27 - 1:105 - 1:107 56 LOAD_BYTE 28 - 1:109 - 1:111 58 LOAD_BYTE 29 - 1:113 - 1:115 60 LOAD_BYTE 30 - 1:117 - 1:119 62 LOAD_BYTE 31 - 1:0 - 1:140 64 COLLECTION_FROM_STACK 31 (Object[]) - 1:121 - 1:123 66 LOAD_BYTE 32 - 1:125 - 1:127 68 LOAD_BYTE 33 - 1:129 - 1:131 70 LOAD_BYTE 34 - 1:133 - 1:135 72 LOAD_BYTE 35 - 1:137 - 1:139 74 LOAD_BYTE 36 - 1:0 - 1:140 76 COLLECTION_ADD_STACK 5 (Object[]) - 1:0 - 1:140 78 CALL_FUNCTION_VARARGS - 1:0 - 1:140 79 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs.co deleted file mode 100644 index 2d56d9d956..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:3 - 3:8 2 DUP_TOP - 2:8 - 2:9 3 LOAD_BYTE 1 - 2:8 - 2:9 5 BINARY_OP 12 (EQ) - 2:8 - 2:9 7 POP_AND_JUMP_IF_FALSE 13 (to 20) generalizes: 5 - 2:8 - 2:9 11 ROT_N 1 - 2:8 - 2:9 13 STORE_NAME 0 (x) - 3:7 - 3:8 15 LOAD_NAME 0 (x) - 3:7 - 3:8 17 POP_TOP - 3:7 - 3:8 18 JUMP_FORWARD 3 (to 21) - 2:3 - 3:8 >> 20 POP_TOP - 2:3 - 3:8 >> 21 LOAD_NONE - 2:3 - 3:8 22 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs2.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs2.co deleted file mode 100644 index 57e070b06d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAs2.co +++ /dev/null @@ -1,26 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:3 - 3:8 2 DUP_TOP - 2:3 - 3:8 3 DUP_TOP - 2:8 - 2:9 4 LOAD_BYTE 1 - 2:8 - 2:9 6 BINARY_OP 12 (EQ) - 2:8 - 2:9 8 POP_AND_JUMP_IF_FALSE 14 (to 22) generalizes: 6 - 2:8 - 2:9 12 ROT_N 1 - 2:8 - 2:9 14 STORE_NAME 0 (x) - 2:8 - 2:9 16 POP_TOP - 3:7 - 3:8 17 LOAD_NAME 0 (x) - 3:7 - 3:8 19 POP_TOP - 3:7 - 3:8 20 JUMP_FORWARD 22 (to 42) - 2:3 - 3:8 >> 22 POP_TOP - 4:3 - 5:8 23 DUP_TOP - 4:8 - 4:9 24 LOAD_BYTE 2 - 4:8 - 4:9 26 BINARY_OP 12 (EQ) - 4:8 - 4:9 28 POP_AND_JUMP_IF_FALSE 13 (to 41) generalizes: 26 - 4:8 - 4:9 32 ROT_N 1 - 4:8 - 4:9 34 STORE_NAME 1 (y) - 5:7 - 5:8 36 LOAD_NAME 0 (x) - 5:7 - 5:8 38 POP_TOP - 5:7 - 5:8 39 JUMP_FORWARD 3 (to 42) - 4:3 - 5:8 >> 41 POP_TOP - 4:3 - 5:8 >> 42 LOAD_NONE - 4:3 - 5:8 43 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsDefault.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsDefault.co deleted file mode 100644 index 1d25930ad5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsDefault.co +++ /dev/null @@ -1,17 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:3 - 3:8 2 DUP_TOP - 2:8 - 2:9 3 LOAD_BYTE 1 - 2:8 - 2:9 5 BINARY_OP 12 (EQ) - 2:8 - 2:9 7 POP_AND_JUMP_IF_FALSE 13 (to 20) generalizes: 5 - 2:8 - 2:9 11 ROT_N 1 - 2:8 - 2:9 13 STORE_NAME 0 (x) - 3:7 - 3:8 15 LOAD_NAME 0 (x) - 3:7 - 3:8 17 POP_TOP - 3:7 - 3:8 18 JUMP_FORWARD 7 (to 25) - 2:3 - 3:8 >> 20 POP_TOP - 4:3 - 5:8 21 NOP - 5:7 - 5:8 22 LOAD_NAME 0 (x) - 5:7 - 5:8 24 POP_TOP - 5:7 - 5:8 >> 25 LOAD_NONE - 5:7 - 5:8 26 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsGuard.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsGuard.co deleted file mode 100644 index f3095d516f..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchAsGuard.co +++ /dev/null @@ -1,18 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:3 - 3:8 2 DUP_TOP - 2:8 - 2:9 3 LOAD_BYTE 1 - 2:8 - 2:9 5 BINARY_OP 12 (EQ) - 2:8 - 2:9 7 POP_AND_JUMP_IF_FALSE 23 (to 30) generalizes: 5 - 2:8 - 2:9 11 ROT_N 1 - 2:8 - 2:9 13 STORE_NAME 0 (x) - 2:18 - 2:19 15 LOAD_NAME 0 (x) - 2:23 - 2:24 17 LOAD_BYTE 1 - 2:18 - 2:24 19 BINARY_OP 12 (EQ) - 2:8 - 2:9 21 POP_AND_JUMP_IF_FALSE 10 (to 31) generalizes: 19 - 3:7 - 3:8 25 LOAD_NAME 0 (x) - 3:7 - 3:8 27 POP_TOP - 3:7 - 3:8 28 JUMP_FORWARD 3 (to 31) - 2:3 - 3:8 >> 30 POP_TOP - 2:3 - 3:8 >> 31 LOAD_NONE - 2:3 - 3:8 32 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchClass.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchClass.co deleted file mode 100644 index 600817af6c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchClass.co +++ /dev/null @@ -1,17 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:7 - 2:10 2 LOAD_NAME 0 (int) - 2:2 - 3:10 4 LOAD_CONST 0 ([]) - 2:2 - 3:10 6 MATCH_CLASS 1 - 2:2 - 3:10 8 POP_AND_JUMP_IF_FALSE 16 (to 24) - 2:2 - 3:10 12 DUP_TOP - 2:2 - 3:10 13 LOAD_BYTE 0 - 2:2 - 3:10 15 BINARY_SUBSCR generalizes: 13 - 2:2 - 3:10 16 ROT_N 2 - 2:2 - 3:10 18 POP_TOP - 2:2 - 3:10 19 STORE_NAME 1 (x) - 3:6 - 3:10 21 NOP - 3:6 - 3:10 22 JUMP_FORWARD 3 (to 25) - 2:2 - 3:10 >> 24 POP_TOP - 2:2 - 3:10 >> 25 LOAD_NONE - 2:2 - 3:10 26 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMapping.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMapping.co deleted file mode 100644 index 164d59cc8c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMapping.co +++ /dev/null @@ -1,30 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 1:9 - 1:10 2 LOAD_BYTE 1 - 1:6 - 1:11 4 COLLECTION_FROM_STACK 2 (dict) - 2:2 - 3:8 6 MATCH_MAPPING - 2:2 - 3:8 7 POP_AND_JUMP_IF_FALSE 42 (to 49) - 2:2 - 3:8 11 GET_LEN - 2:2 - 3:8 12 LOAD_BYTE 1 - 2:2 - 3:8 14 BINARY_OP 17 (GE) - 2:2 - 3:8 16 POP_AND_JUMP_IF_FALSE 33 (to 49) generalizes: 14 - 2:2 - 3:8 20 LOAD_BYTE 1 - 2:2 - 3:8 22 COLLECTION_FROM_STACK 1 (Object[]) - 2:2 - 3:8 24 MATCH_KEYS - 2:2 - 3:8 25 POP_AND_JUMP_IF_FALSE 22 (to 47) - 2:2 - 3:8 29 DUP_TOP - 2:2 - 3:8 30 LOAD_BYTE 0 - 2:2 - 3:8 32 BINARY_SUBSCR generalizes: 30 - 2:10 - 2:11 33 LOAD_BYTE 1 - 2:10 - 2:11 35 BINARY_OP 12 (EQ) generalizes: 33, 32 - 2:10 - 2:11 37 POP_AND_JUMP_IF_FALSE 10 (to 47) generalizes: 35 - 2:10 - 2:11 41 POP_TOP - 2:10 - 2:11 42 POP_TOP - 2:10 - 2:11 43 POP_TOP - 3:4 - 3:8 44 NOP - 3:4 - 3:8 45 JUMP_FORWARD 5 (to 50) - 2:2 - 3:8 >> 47 POP_TOP - 2:2 - 3:8 48 POP_TOP - 2:2 - 3:8 >> 49 POP_TOP - 2:2 - 3:8 >> 50 LOAD_NONE - 2:2 - 3:8 51 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingStar.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingStar.co deleted file mode 100644 index ba3a1c0b31..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingStar.co +++ /dev/null @@ -1,22 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 1:9 - 1:10 2 LOAD_BYTE 1 - 1:6 - 1:11 4 COLLECTION_FROM_STACK 2 (dict) - 2:2 - 3:5 6 MATCH_MAPPING - 2:2 - 3:5 7 POP_AND_JUMP_IF_FALSE 25 (to 32) - 2:2 - 3:5 11 COLLECTION_FROM_STACK 0 (Object[]) - 2:2 - 3:5 13 MATCH_KEYS - 2:2 - 3:5 14 POP_AND_JUMP_IF_FALSE 16 (to 30) - 2:2 - 3:5 18 POP_TOP - 2:2 - 3:5 19 COPY_DICT_WITHOUT_KEYS - 2:2 - 3:5 20 ROT_N 2 - 2:2 - 3:5 22 POP_TOP - 2:2 - 3:5 23 STORE_NAME 0 (z) - 3:4 - 3:5 25 LOAD_NAME 0 (z) - 3:4 - 3:5 27 POP_TOP - 3:4 - 3:5 28 JUMP_FORWARD 5 (to 33) - 2:2 - 3:5 >> 30 POP_TOP - 2:2 - 3:5 31 POP_TOP - 2:2 - 3:5 >> 32 POP_TOP - 2:2 - 3:5 >> 33 LOAD_NONE - 2:2 - 3:5 34 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingSubpattern.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingSubpattern.co deleted file mode 100644 index fcf539036f..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchMappingSubpattern.co +++ /dev/null @@ -1,30 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 1:9 - 1:10 2 LOAD_BYTE 1 - 1:6 - 1:11 4 COLLECTION_FROM_STACK 2 (dict) - 2:2 - 3:5 6 MATCH_MAPPING - 2:2 - 3:5 7 POP_AND_JUMP_IF_FALSE 40 (to 47) - 2:2 - 3:5 11 GET_LEN - 2:2 - 3:5 12 LOAD_BYTE 1 - 2:2 - 3:5 14 BINARY_OP 17 (GE) - 2:2 - 3:5 16 POP_AND_JUMP_IF_FALSE 31 (to 47) generalizes: 14 - 2:2 - 3:5 20 LOAD_BYTE 1 - 2:2 - 3:5 22 COLLECTION_FROM_STACK 1 (Object[]) - 2:2 - 3:5 24 MATCH_KEYS - 2:2 - 3:5 25 POP_AND_JUMP_IF_FALSE 20 (to 45) - 2:2 - 3:5 29 DUP_TOP - 2:2 - 3:5 30 LOAD_BYTE 0 - 2:2 - 3:5 32 BINARY_SUBSCR generalizes: 30 - 2:2 - 3:5 33 ROT_N 4 - 2:2 - 3:5 35 POP_TOP - 2:2 - 3:5 36 POP_TOP - 2:2 - 3:5 37 POP_TOP - 2:2 - 3:5 38 STORE_NAME 0 (x) - 3:4 - 3:5 40 LOAD_NAME 0 (x) - 3:4 - 3:5 42 POP_TOP - 3:4 - 3:5 43 JUMP_FORWARD 5 (to 48) - 2:2 - 3:5 >> 45 POP_TOP - 2:2 - 3:5 46 POP_TOP - 2:2 - 3:5 >> 47 POP_TOP - 2:2 - 3:5 >> 48 LOAD_NONE - 2:2 - 3:5 49 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOr.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOr.co deleted file mode 100644 index 0bba2db678..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOr.co +++ /dev/null @@ -1,19 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 0 - 2:7 - 2:8 2 DUP_TOP - 2:7 - 2:8 3 LOAD_BYTE 0 - 2:7 - 2:8 5 BINARY_OP 12 (EQ) - 2:7 - 2:8 7 POP_AND_JUMP_IF_FALSE 6 (to 13) generalizes: 5 - 2:7 - 2:8 11 JUMP_FORWARD 16 (to 27) - 2:11 - 2:12 >> 13 DUP_TOP - 2:11 - 2:12 14 LOAD_BYTE 1 - 2:11 - 2:12 16 BINARY_OP 12 (EQ) - 2:11 - 2:12 18 POP_AND_JUMP_IF_FALSE 6 (to 24) generalizes: 16 - 2:11 - 2:12 22 JUMP_FORWARD 5 (to 27) - 2:11 - 2:12 >> 24 POP_TOP - 2:11 - 2:12 25 JUMP_FORWARD 6 (to 31) - 2:11 - 2:12 >> 27 POP_TOP - 3:4 - 3:8 28 NOP - 3:4 - 3:8 29 JUMP_FORWARD 2 (to 31) - 2:2 - 3:8 >> 31 LOAD_NONE - 2:2 - 3:8 32 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOrRot.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOrRot.co deleted file mode 100644 index 403c110116..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchOrRot.co +++ /dev/null @@ -1,38 +0,0 @@ -Disassembly of : - 1:6 - 1:12 0 LOAD_CONST_COLLECTION 0 ([0, 1] type int into tuple) - 2:8 - 2:14 3 DUP_TOP - 2:8 - 2:14 4 MATCH_SEQUENCE - 2:8 - 2:14 5 POP_AND_JUMP_IF_FALSE 21 (to 26) - 2:8 - 2:14 9 GET_LEN - 2:8 - 2:14 10 LOAD_BYTE 2 - 2:8 - 2:14 12 BINARY_OP 12 (EQ) - 2:8 - 2:14 14 POP_AND_JUMP_IF_FALSE 12 (to 26) generalizes: 12 - 2:8 - 2:14 18 UNPACK_SEQUENCE 2 - 2:8 - 2:14 20 ROT_N 2 - 2:8 - 2:14 22 ROT_N 2 - 2:8 - 2:14 24 JUMP_FORWARD 32 (to 56) - 2:8 - 2:14 >> 26 POP_TOP - 2:17 - 2:23 27 DUP_TOP - 2:17 - 2:23 28 MATCH_SEQUENCE - 2:17 - 2:23 29 POP_AND_JUMP_IF_FALSE 23 (to 52) - 2:17 - 2:23 33 GET_LEN - 2:17 - 2:23 34 LOAD_BYTE 2 - 2:17 - 2:23 36 BINARY_OP 12 (EQ) - 2:17 - 2:23 38 POP_AND_JUMP_IF_FALSE 14 (to 52) generalizes: 36 - 2:17 - 2:23 42 UNPACK_SEQUENCE 2 - 2:17 - 2:23 44 ROT_N 2 - 2:17 - 2:23 46 ROT_N 2 - 2:17 - 2:23 48 ROT_N 2 - 2:17 - 2:23 50 JUMP_FORWARD 6 (to 56) - 2:17 - 2:23 >> 52 POP_TOP - 2:17 - 2:23 53 POP_TOP - 2:17 - 2:23 54 JUMP_FORWARD 14 (to 68) - 2:17 - 2:23 >> 56 ROT_N 3 - 2:17 - 2:23 58 ROT_N 3 - 2:17 - 2:23 60 POP_TOP - 2:17 - 2:23 61 STORE_NAME 0 (a) - 2:17 - 2:23 63 STORE_NAME 1 (b) - 3:4 - 3:8 65 NOP - 3:4 - 3:8 66 JUMP_FORWARD 2 (to 68) - 2:2 - 3:8 >> 68 LOAD_NONE - 2:2 - 3:8 69 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonBoolean.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonBoolean.co deleted file mode 100644 index ae6faa990a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonBoolean.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:8 - 2:12 2 LOAD_TRUE - 2:8 - 2:12 3 BINARY_OP 31 (IS) generalizes: 2, 0 - 2:8 - 2:12 5 POP_AND_JUMP_IF_FALSE 7 (to 12) generalizes: 3 - 3:7 - 3:11 9 NOP - 3:7 - 3:11 10 JUMP_FORWARD 2 (to 12) - 2:3 - 3:11 >> 12 LOAD_NONE - 2:3 - 3:11 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonNone.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonNone.co deleted file mode 100644 index e1f527dd61..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchSingletonNone.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:8 - 2:12 2 LOAD_NONE - 2:8 - 2:12 3 BINARY_OP 31 (IS) - 2:8 - 2:12 5 POP_AND_JUMP_IF_FALSE 7 (to 12) generalizes: 3 - 3:7 - 3:11 9 NOP - 3:7 - 3:11 10 JUMP_FORWARD 2 (to 12) - 2:3 - 3:11 >> 12 LOAD_NONE - 2:3 - 3:11 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValue.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValue.co deleted file mode 100644 index 2656c9d069..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValue.co +++ /dev/null @@ -1,11 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 LOAD_BYTE 1 - 1:0 - 1:1 2 STORE_NAME 0 (s) - 2:6 - 2:7 4 LOAD_NAME 0 (s) - 3:8 - 3:9 6 LOAD_BYTE 1 - 3:8 - 3:9 8 BINARY_OP 12 (EQ) - 3:8 - 3:9 10 POP_AND_JUMP_IF_FALSE 7 (to 17) generalizes: 8 - 4:7 - 4:11 14 NOP - 4:7 - 4:11 15 JUMP_FORWARD 2 (to 17) - 3:3 - 4:11 >> 17 LOAD_NONE - 3:3 - 4:11 18 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueConst.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueConst.co deleted file mode 100644 index 9424e386a6..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueConst.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:8 - 2:9 2 LOAD_BYTE 1 - 2:8 - 2:9 4 BINARY_OP 12 (EQ) generalizes: 2, 0 - 2:8 - 2:9 6 POP_AND_JUMP_IF_FALSE 7 (to 13) generalizes: 4 - 3:7 - 3:11 10 NOP - 3:7 - 3:11 11 JUMP_FORWARD 2 (to 13) - 2:3 - 3:11 >> 13 LOAD_NONE - 2:3 - 3:11 14 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueWithDefault.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueWithDefault.co deleted file mode 100644 index b168f84e89..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMatchValueWithDefault.co +++ /dev/null @@ -1,13 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 LOAD_BYTE 1 - 1:0 - 1:1 2 STORE_NAME 0 (s) - 2:6 - 2:7 4 LOAD_NAME 0 (s) - 3:8 - 3:9 6 LOAD_BYTE 1 - 3:8 - 3:9 8 BINARY_OP 12 (EQ) - 3:8 - 3:9 10 POP_AND_JUMP_IF_FALSE 7 (to 17) generalizes: 8 - 4:7 - 4:11 14 NOP - 4:7 - 4:11 15 JUMP_FORWARD 4 (to 19) - 5:3 - 6:11 >> 17 NOP - 6:7 - 6:11 18 NOP - 6:7 - 6:11 >> 19 LOAD_NONE - 6:7 - 6:11 20 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMinusFolding.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMinusFolding.co deleted file mode 100644 index 9b149493ca..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testMinusFolding.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE -1 - 1:6 - 1:9 2 LOAD_DOUBLE 0 (-7.0) - 1:0 - 1:9 4 BINARY_OP 4 (MUL) generalizes: 2, 0 - 1:0 - 1:9 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNamedExpr.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNamedExpr.co deleted file mode 100644 index d43041aae6..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNamedExpr.co +++ /dev/null @@ -1,12 +0,0 @@ -Disassembly of : - 1:8 - 1:9 0 LOAD_NAME 0 (g) - 1:8 - 1:11 2 CALL_FUNCTION 0 - 1:3 - 1:11 4 DUP_TOP - 1:3 - 1:4 5 STORE_NAME 1 (x) - 1:0 - 2:10 7 POP_AND_JUMP_IF_FALSE 11 (to 18) - 2:2 - 2:7 11 LOAD_NAME 2 (print) - 2:8 - 2:9 13 LOAD_NAME 1 (x) - 2:2 - 2:10 15 CALL_FUNCTION 1 - 2:2 - 2:10 17 POP_TOP - 2:2 - 2:10 >> 18 LOAD_NONE - 2:2 - 2:10 19 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNestedListComprehension.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNestedListComprehension.co deleted file mode 100644 index c1af1206cc..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testNestedListComprehension.co +++ /dev/null @@ -1,33 +0,0 @@ -Disassembly of : - 1:0 - 1:41 0 MAKE_FUNCTION 0 () - 1:32 - 1:37 3 LOAD_NAME 0 (range) - 1:38 - 1:39 5 LOAD_BYTE 3 - 1:32 - 1:40 7 CALL_FUNCTION 1 - 1:0 - 1:41 9 GET_ITER - 1:0 - 1:41 10 CALL_COMPREHENSION - 1:0 - 1:41 11 RETURN_VALUE - -Disassembly of : - 1:0 - 1:41 0 COLLECTION_FROM_STACK 0 (list) - 1:0 - 1:41 2 LOAD_FAST 0 (.0) - 1:0 - 1:41 >> 4 FOR_ITER 19 (to 23) - 1:27 - 1:28 6 STORE_FAST 1 (y) generalizes: 4 - 1:1 - 1:22 8 MAKE_FUNCTION 0 (.) - 1:13 - 1:18 11 LOAD_GLOBAL 0 (range) - 1:19 - 1:20 13 LOAD_BYTE 5 - 1:13 - 1:21 15 CALL_FUNCTION 1 - 1:1 - 1:22 17 GET_ITER - 1:1 - 1:22 18 CALL_COMPREHENSION - 1:0 - 1:41 19 ADD_TO_COLLECTION 2 (list) - 1:0 - 1:41 21 JUMP_BACKWARD 17 (to 4) - 1:0 - 1:41 >> 23 RETURN_VALUE - -Disassembly of .: - 1:1 - 1:22 0 COLLECTION_FROM_STACK 0 (list) - 1:1 - 1:22 2 LOAD_FAST 0 (.0) - 1:1 - 1:22 >> 4 FOR_ITER 10 (to 14) - 1:8 - 1:9 6 STORE_FAST 1 (x) generalizes: 4 - 1:2 - 1:3 8 LOAD_FAST 1 (x) - 1:1 - 1:22 10 ADD_TO_COLLECTION 2 (list) - 1:1 - 1:22 12 JUMP_BACKWARD 8 (to 4) - 1:1 - 1:22 >> 14 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWith.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWith.co deleted file mode 100644 index 608585272d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWith.co +++ /dev/null @@ -1,45 +0,0 @@ -Disassembly of : - 1:0 - 3:11 0 MAKE_FUNCTION 0 (f) - 1:0 - 3:11 3 STORE_NAME 0 (f) - 1:0 - 3:11 5 LOAD_NONE - 1:0 - 3:11 6 RETURN_VALUE - -Disassembly of f: -Flags: CO_COROUTINE - 2:13 - 2:14 0 LOAD_GLOBAL 0 (a) - 2:2 - 3:11 2 SETUP_AWITH - 2:2 - 3:11 3 GET_AWAITABLE - 2:2 - 3:11 4 LOAD_NONE - 2:2 - 3:11 >> 5 SEND 10 (to 15) - 2:2 - 3:11 >> 7 YIELD_VALUE - 2:2 - 3:11 8 RESUME_YIELD - 2:2 - 3:11 9 JUMP_BACKWARD 4 (to 5) - 2:2 - 3:11 11 THROW 4 (to 15) (exc handler 8 - 11; stack: 3) - 2:2 - 3:11 13 JUMP_BACKWARD 6 (to 7) - 2:2 - 3:11 >> 15 POP_TOP - 2:2 - 3:11 16 LOAD_NONE - 2:2 - 3:11 17 GET_AEXIT_CORO - 2:2 - 3:11 18 GET_AWAITABLE - 2:2 - 3:11 19 LOAD_NONE - 2:2 - 3:11 >> 20 SEND 10 (to 30) - 2:2 - 3:11 >> 22 YIELD_VALUE - 2:2 - 3:11 23 RESUME_YIELD - 2:2 - 3:11 24 JUMP_BACKWARD 4 (to 20) - 2:2 - 3:11 26 THROW 4 (to 30) (exc handler 23 - 26; stack: 2) - 2:2 - 3:11 28 JUMP_BACKWARD 6 (to 22) - 2:2 - 3:11 >> 30 EXIT_AWITH - 2:2 - 3:11 31 LOAD_NONE - 2:2 - 3:11 32 RETURN_VALUE - 2:2 - 3:11 33 LOAD_NONE - 2:2 - 3:11 34 GET_AEXIT_CORO (exc handler 3 - 8; stack: 2 | exc handler 11 - 16; stack: 2) - 2:2 - 3:11 35 GET_AWAITABLE - 2:2 - 3:11 36 LOAD_NONE - 2:2 - 3:11 >> 37 SEND 10 (to 47) - 2:2 - 3:11 >> 39 YIELD_VALUE - 2:2 - 3:11 40 RESUME_YIELD - 2:2 - 3:11 41 JUMP_BACKWARD 4 (to 37) - 2:2 - 3:11 43 THROW 4 (to 47) (exc handler 40 - 43; stack: 2) - 2:2 - 3:11 45 JUMP_BACKWARD 6 (to 39) - 2:2 - 3:11 >> 47 EXIT_AWITH - 2:2 - 3:11 48 LOAD_NONE - 2:2 - 3:11 49 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWithT.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWithT.co deleted file mode 100644 index 8df31dd466..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromAsyncWithT.co +++ /dev/null @@ -1,78 +0,0 @@ -Disassembly of : - 1:0 - 4:12 0 MAKE_FUNCTION 0 (f) - 1:0 - 4:12 3 STORE_NAME 0 (f) - 1:0 - 4:12 5 LOAD_NONE - 1:0 - 4:12 6 RETURN_VALUE - -Disassembly of f: -Flags: CO_COROUTINE - 2:13 - 2:14 0 LOAD_GLOBAL 0 (a) - 2:2 - 4:12 2 SETUP_AWITH - 2:2 - 4:12 3 GET_AWAITABLE - 2:2 - 4:12 4 LOAD_NONE - 2:2 - 4:12 >> 5 SEND 10 (to 15) - 2:2 - 4:12 >> 7 YIELD_VALUE - 2:2 - 4:12 8 RESUME_YIELD - 2:2 - 4:12 9 JUMP_BACKWARD 4 (to 5) - 2:2 - 4:12 11 THROW 4 (to 15) (exc handler 8 - 11; stack: 3) - 2:2 - 4:12 13 JUMP_BACKWARD 6 (to 7) - 2:2 - 4:12 >> 15 POP_TOP - 3:15 - 3:16 16 LOAD_GLOBAL 1 (b) - 3:4 - 4:12 18 SETUP_AWITH - 3:4 - 4:12 19 GET_AWAITABLE - 3:4 - 4:12 20 LOAD_NONE - 3:4 - 4:12 >> 21 SEND 10 (to 31) - 3:4 - 4:12 >> 23 YIELD_VALUE - 3:4 - 4:12 24 RESUME_YIELD - 3:4 - 4:12 25 JUMP_BACKWARD 4 (to 21) - 3:4 - 4:12 27 THROW 4 (to 31) (exc handler 24 - 27; stack: 5) - 3:4 - 4:12 29 JUMP_BACKWARD 6 (to 23) - 3:4 - 4:12 >> 31 POP_TOP - 3:4 - 4:12 32 LOAD_NONE - 3:4 - 4:12 33 GET_AEXIT_CORO - 3:4 - 4:12 34 GET_AWAITABLE - 3:4 - 4:12 35 LOAD_NONE - 3:4 - 4:12 >> 36 SEND 10 (to 46) - 3:4 - 4:12 >> 38 YIELD_VALUE - 3:4 - 4:12 39 RESUME_YIELD - 3:4 - 4:12 40 JUMP_BACKWARD 4 (to 36) - 3:4 - 4:12 42 THROW 4 (to 46) (exc handler 39 - 42; stack: 4) - 3:4 - 4:12 44 JUMP_BACKWARD 6 (to 38) - 3:4 - 4:12 >> 46 EXIT_AWITH - 2:2 - 4:12 47 LOAD_NONE - 2:2 - 4:12 48 GET_AEXIT_CORO - 2:2 - 4:12 49 GET_AWAITABLE - 2:2 - 4:12 50 LOAD_NONE - 2:2 - 4:12 >> 51 SEND 10 (to 61) - 2:2 - 4:12 >> 53 YIELD_VALUE - 2:2 - 4:12 54 RESUME_YIELD - 2:2 - 4:12 55 JUMP_BACKWARD 4 (to 51) - 2:2 - 4:12 57 THROW 4 (to 61) (exc handler 54 - 57; stack: 2) - 2:2 - 4:12 59 JUMP_BACKWARD 6 (to 53) - 2:2 - 4:12 >> 61 EXIT_AWITH - 2:2 - 4:12 62 LOAD_NONE - 2:2 - 4:12 63 RETURN_VALUE - 2:2 - 4:12 64 LOAD_NONE - 3:4 - 4:12 65 GET_AEXIT_CORO (exc handler 19 - 24; stack: 4 | exc handler 27 - 32; stack: 4) - 3:4 - 4:12 66 GET_AWAITABLE - 3:4 - 4:12 67 LOAD_NONE - 3:4 - 4:12 >> 68 SEND 10 (to 78) - 3:4 - 4:12 >> 70 YIELD_VALUE - 3:4 - 4:12 71 RESUME_YIELD - 3:4 - 4:12 72 JUMP_BACKWARD 4 (to 68) - 3:4 - 4:12 74 THROW 4 (to 78) (exc handler 71 - 74; stack: 4) - 3:4 - 4:12 76 JUMP_BACKWARD 6 (to 70) - 3:4 - 4:12 >> 78 EXIT_AWITH - 3:4 - 4:12 79 LOAD_NONE - 2:2 - 4:12 80 GET_AEXIT_CORO (exc handler 3 - 8; stack: 2 | exc handler 11 - 19; stack: 2 | exc handler 32 - 39; stack: 2 | exc handler 42 - 47; stack: 2 | exc handler 65 - 71; stack: 2 | exc handler 74 - 80; stack: 2) - 2:2 - 4:12 81 GET_AWAITABLE - 2:2 - 4:12 82 LOAD_NONE - 2:2 - 4:12 >> 83 SEND 10 (to 93) - 2:2 - 4:12 >> 85 YIELD_VALUE - 2:2 - 4:12 86 RESUME_YIELD - 2:2 - 4:12 87 JUMP_BACKWARD 4 (to 83) - 2:2 - 4:12 89 THROW 4 (to 93) (exc handler 86 - 89; stack: 2) - 2:2 - 4:12 91 JUMP_BACKWARD 6 (to 85) - 2:2 - 4:12 >> 93 EXIT_AWITH - 2:2 - 4:12 94 LOAD_NONE - 2:2 - 4:12 95 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromExcept.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromExcept.co deleted file mode 100644 index e7fc083850..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromExcept.co +++ /dev/null @@ -1,46 +0,0 @@ -Disassembly of : - 1:0 - 5:43 0 MAKE_FUNCTION 0 (foo) - 1:0 - 5:43 3 STORE_NAME 0 (foo) - 1:0 - 5:43 5 LOAD_NONE - 1:0 - 5:43 6 RETURN_VALUE - -Disassembly of foo: - 2:11 - 2:16 0 LOAD_GLOBAL 0 (range) - 2:17 - 2:19 2 LOAD_BYTE 10 - 2:11 - 2:20 4 CALL_FUNCTION 1 - 2:2 - 5:43 6 GET_ITER - 2:2 - 5:43 >> 7 FOR_ITER 53 (to 60) - 2:6 - 2:7 9 STORE_FAST 0 (i) generalizes: 7 - 3:4 - 5:43 11 NOP - 4:6 - 4:7 12 LOAD_BYTE 1 - 4:10 - 4:11 14 LOAD_BYTE 0 - 4:6 - 4:11 16 BINARY_OP 8 (TRUEDIV) generalizes: 14, 12 - 4:6 - 4:11 18 POP_TOP - 4:6 - 4:11 19 JUMP_FORWARD 39 (to 58) - 4:6 - 4:11 21 PUSH_EXC_INFO (exc handler 12 - 21; stack: 1) - 5:11 - 5:23 22 LOAD_GLOBAL 1 (RuntimeError) - 5:4 - 5:43 24 MATCH_EXC_OR_JUMP 33 (to 57) - 5:4 - 5:43 28 UNWRAP_EXC - 5:4 - 5:43 29 STORE_FAST 1 (e) - 5:42 - 5:43 31 LOAD_GLOBAL 2 (a) - 5:35 - 5:43 33 LOAD_NONE - 5:35 - 5:43 34 STORE_FAST 1 (e) - 5:35 - 5:43 36 DELETE_FAST 1 (e) - 5:35 - 5:43 38 ROT_TWO - 5:35 - 5:43 39 POP_EXCEPT - 5:35 - 5:43 40 ROT_TWO - 5:35 - 5:43 41 POP_TOP - 5:35 - 5:43 42 RETURN_VALUE - 5:35 - 5:43 43 LOAD_NONE - 5:35 - 5:43 44 STORE_FAST 1 (e) - 5:35 - 5:43 46 DELETE_FAST 1 (e) - 5:35 - 5:43 48 POP_EXCEPT - 5:35 - 5:43 49 JUMP_FORWARD 9 (to 58) - 5:35 - 5:43 51 LOAD_NONE (exc handler 31 - 43; stack: 2) - 5:35 - 5:43 52 STORE_FAST 1 (e) - 5:35 - 5:43 54 DELETE_FAST 1 (e) - 5:35 - 5:43 56 END_EXC_HANDLER - 5:35 - 5:43 >> 57 END_EXC_HANDLER (exc handler 22 - 31; stack: 2 | exc handler 43 - 57; stack: 2) - 5:35 - 5:43 >> 58 JUMP_BACKWARD 51 (to 7) - 5:35 - 5:43 >> 60 LOAD_NONE - 5:35 - 5:43 61 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromFinally.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromFinally.co deleted file mode 100644 index 403591fc5d..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromFinally.co +++ /dev/null @@ -1,59 +0,0 @@ -Disassembly of : - 1:0 - 9:14 0 MAKE_FUNCTION 0 (foo) - 1:0 - 9:14 3 STORE_NAME 0 (foo) - 1:0 - 9:14 5 LOAD_NONE - 1:0 - 9:14 6 RETURN_VALUE - -Disassembly of foo: - 2:11 - 2:16 0 LOAD_GLOBAL 0 (range) - 2:17 - 2:19 2 LOAD_BYTE 10 - 2:11 - 2:20 4 CALL_FUNCTION 1 - 2:2 - 9:14 6 GET_ITER - 2:2 - 9:14 >> 7 FOR_ITER 70 (to 77) - 2:6 - 2:7 9 STORE_FAST 0 (i) generalizes: 7 - 3:4 - 9:14 11 NOP - 4:9 - 4:10 12 LOAD_FAST 0 (i) - 4:6 - 5:16 14 POP_AND_JUMP_IF_FALSE 23 (to 37) generalizes: 12 - 5:15 - 5:16 18 LOAD_GLOBAL 1 (a) - 8:6 - 8:11 20 LOAD_GLOBAL 2 (print) - 8:12 - 8:21 22 LOAD_STRING 1 ('finally') - 8:6 - 8:22 24 CALL_FUNCTION 1 - 8:6 - 8:22 26 POP_TOP - 9:13 - 9:14 27 LOAD_GLOBAL 3 (b) - 9:6 - 9:14 29 ROT_TWO - 9:6 - 9:14 30 POP_TOP - 9:6 - 9:14 31 ROT_TWO - 9:6 - 9:14 32 POP_TOP - 9:6 - 9:14 33 RETURN_VALUE - 9:6 - 9:14 34 ROT_TWO - 9:6 - 9:14 35 POP_TOP - 9:6 - 9:14 36 RETURN_VALUE - 6:6 - 6:11 >> 37 LOAD_GLOBAL 2 (print) - 6:12 - 6:13 39 LOAD_FAST 0 (i) - 6:6 - 6:14 41 CALL_FUNCTION 1 - 6:6 - 6:14 43 POP_TOP - 6:6 - 6:14 44 JUMP_FORWARD 19 (to 63) - 6:6 - 6:14 46 PUSH_EXC_INFO (exc handler 12 - 20; stack: 1 | exc handler 37 - 46; stack: 1) - 8:6 - 8:11 47 LOAD_GLOBAL 2 (print) - 8:12 - 8:21 49 LOAD_STRING 1 ('finally') - 8:6 - 8:22 51 CALL_FUNCTION 1 - 8:6 - 8:22 53 POP_TOP - 9:13 - 9:14 54 LOAD_GLOBAL 3 (b) - 9:6 - 9:14 56 ROT_THREE - 9:6 - 9:14 57 POP_EXCEPT - 9:6 - 9:14 58 POP_TOP - 9:6 - 9:14 59 ROT_TWO - 9:6 - 9:14 60 POP_TOP - 9:6 - 9:14 61 RETURN_VALUE - 9:6 - 9:14 62 END_EXC_HANDLER (exc handler 47 - 62; stack: 2) - 8:6 - 8:11 >> 63 LOAD_GLOBAL 2 (print) - 8:12 - 8:21 65 LOAD_STRING 1 ('finally') - 8:6 - 8:22 67 CALL_FUNCTION 1 - 8:6 - 8:22 69 POP_TOP - 9:13 - 9:14 70 LOAD_GLOBAL 3 (b) - 9:6 - 9:14 72 ROT_TWO - 9:6 - 9:14 73 POP_TOP - 9:6 - 9:14 74 RETURN_VALUE - 9:6 - 9:14 75 JUMP_BACKWARD 68 (to 7) - 9:6 - 9:14 >> 77 LOAD_NONE - 9:6 - 9:14 78 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromTry.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromTry.co deleted file mode 100644 index cc6fd0cfbc..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromTry.co +++ /dev/null @@ -1,36 +0,0 @@ -Disassembly of : - 1:0 - 5:34 0 MAKE_FUNCTION 0 (foo) - 1:0 - 5:34 3 STORE_NAME 0 (foo) - 1:0 - 5:34 5 LOAD_NONE - 1:0 - 5:34 6 RETURN_VALUE - -Disassembly of foo: - 2:11 - 2:16 0 LOAD_GLOBAL 0 (range) - 2:17 - 2:19 2 LOAD_BYTE 10 - 2:11 - 2:20 4 CALL_FUNCTION 1 - 2:2 - 5:34 6 GET_ITER - 2:2 - 5:34 >> 7 FOR_ITER 37 (to 44) - 2:6 - 2:7 9 STORE_FAST 0 (i) generalizes: 7 - 3:4 - 5:34 11 NOP - 4:13 - 4:14 12 LOAD_GLOBAL 1 (a) - 5:18 - 5:23 14 LOAD_GLOBAL 2 (print) - 5:24 - 5:33 16 LOAD_STRING 1 ('finally') - 5:18 - 5:34 18 CALL_FUNCTION 1 - 5:18 - 5:34 20 POP_TOP - 5:18 - 5:34 21 ROT_TWO - 5:18 - 5:34 22 POP_TOP - 5:18 - 5:34 23 RETURN_VALUE - 5:18 - 5:34 24 JUMP_FORWARD 11 (to 35) - 5:18 - 5:34 26 PUSH_EXC_INFO (exc handler 12 - 14; stack: 1) - 5:18 - 5:23 27 LOAD_GLOBAL 2 (print) - 5:24 - 5:33 29 LOAD_STRING 1 ('finally') - 5:18 - 5:34 31 CALL_FUNCTION 1 - 5:18 - 5:34 33 POP_TOP - 5:18 - 5:34 34 END_EXC_HANDLER (exc handler 27 - 34; stack: 2) - 5:18 - 5:23 >> 35 LOAD_GLOBAL 2 (print) - 5:24 - 5:33 37 LOAD_STRING 1 ('finally') - 5:18 - 5:34 39 CALL_FUNCTION 1 - 5:18 - 5:34 41 POP_TOP - 5:18 - 5:34 42 JUMP_BACKWARD 35 (to 7) - 5:18 - 5:34 >> 44 LOAD_NONE - 5:18 - 5:34 45 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromWith.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromWith.co deleted file mode 100644 index 32dc5e86c5..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnFromWith.co +++ /dev/null @@ -1,29 +0,0 @@ -Disassembly of : - 1:0 - 4:14 0 MAKE_FUNCTION 0 (foo) - 1:0 - 4:14 3 STORE_NAME 0 (foo) - 1:0 - 4:14 5 LOAD_NONE - 1:0 - 4:14 6 RETURN_VALUE - -Disassembly of foo: - 2:11 - 2:16 0 LOAD_GLOBAL 0 (range) - 2:17 - 2:19 2 LOAD_BYTE 10 - 2:11 - 2:20 4 CALL_FUNCTION 1 - 2:2 - 4:14 6 GET_ITER - 2:2 - 4:14 >> 7 FOR_ITER 23 (to 30) - 2:6 - 2:7 9 STORE_FAST 0 (i) generalizes: 7 - 3:9 - 3:12 11 LOAD_GLOBAL 1 (foo) - 3:9 - 3:14 13 CALL_FUNCTION 0 - 3:4 - 4:14 15 SETUP_WITH - 3:18 - 3:20 16 STORE_FAST 1 (cm) - 4:13 - 4:14 18 LOAD_GLOBAL 2 (a) - 3:4 - 4:14 20 ROT_THREE - 3:4 - 4:14 21 LOAD_NONE - 3:4 - 4:14 22 EXIT_WITH - 3:4 - 4:14 23 ROT_TWO - 3:4 - 4:14 24 POP_TOP - 3:4 - 4:14 25 RETURN_VALUE - 3:4 - 4:14 26 LOAD_NONE - 3:4 - 4:14 27 EXIT_WITH (exc handler 16 - 20; stack: 3) - 3:4 - 4:14 28 JUMP_BACKWARD 21 (to 7) - 3:4 - 4:14 >> 30 LOAD_NONE - 3:4 - 4:14 31 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnPlain.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnPlain.co deleted file mode 100644 index 291fc8f437..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testReturnPlain.co +++ /dev/null @@ -1,9 +0,0 @@ -Disassembly of : - 1:0 - 2:9 0 MAKE_FUNCTION 0 (foo) - 1:0 - 2:9 3 STORE_NAME 0 (foo) - 1:0 - 2:9 5 LOAD_NONE - 1:0 - 2:9 6 RETURN_VALUE - -Disassembly of foo: - 2:3 - 2:9 0 LOAD_NONE - 2:3 - 2:9 1 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeq.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeq.co deleted file mode 100644 index 380acc7b0c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeq.co +++ /dev/null @@ -1,17 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 2:2 - 3:8 2 MATCH_SEQUENCE - 2:2 - 3:8 3 POP_AND_JUMP_IF_FALSE 26 (to 29) - 2:2 - 3:8 7 GET_LEN - 2:2 - 3:8 8 LOAD_BYTE 1 - 2:2 - 3:8 10 BINARY_OP 12 (EQ) - 2:2 - 3:8 12 POP_AND_JUMP_IF_FALSE 17 (to 29) generalizes: 10 - 2:2 - 3:8 16 UNPACK_SEQUENCE 1 - 2:8 - 2:9 18 LOAD_BYTE 1 - 2:8 - 2:9 20 BINARY_OP 12 (EQ) - 2:8 - 2:9 22 POP_AND_JUMP_IF_FALSE 8 (to 30) generalizes: 20 - 3:4 - 3:8 26 NOP - 3:4 - 3:8 27 JUMP_FORWARD 3 (to 30) - 2:2 - 3:8 >> 29 POP_TOP - 2:2 - 3:8 >> 30 LOAD_NONE - 2:2 - 3:8 31 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcard.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcard.co deleted file mode 100644 index c755afdae6..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcard.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 2:2 - 3:8 2 MATCH_SEQUENCE - 2:2 - 3:8 3 POP_AND_JUMP_IF_FALSE 17 (to 20) - 2:2 - 3:8 7 GET_LEN - 2:2 - 3:8 8 LOAD_BYTE 1 - 2:2 - 3:8 10 BINARY_OP 12 (EQ) - 2:2 - 3:8 12 POP_AND_JUMP_IF_FALSE 8 (to 20) generalizes: 10 - 2:2 - 3:8 16 POP_TOP - 3:4 - 3:8 17 NOP - 3:4 - 3:8 18 JUMP_FORWARD 3 (to 21) - 2:2 - 3:8 >> 20 POP_TOP - 2:2 - 3:8 >> 21 LOAD_NONE - 2:2 - 3:8 22 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStar.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStar.co deleted file mode 100644 index 85e815ed04..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStar.co +++ /dev/null @@ -1,10 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 2:2 - 3:8 2 MATCH_SEQUENCE - 2:2 - 3:8 3 POP_AND_JUMP_IF_FALSE 8 (to 11) - 2:2 - 3:8 7 POP_TOP - 3:4 - 3:8 8 NOP - 3:4 - 3:8 9 JUMP_FORWARD 3 (to 12) - 2:2 - 3:8 >> 11 POP_TOP - 2:2 - 3:8 >> 12 LOAD_NONE - 2:2 - 3:8 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStarSubscript.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStarSubscript.co deleted file mode 100644 index 38c1487e42..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardStarSubscript.co +++ /dev/null @@ -1,22 +0,0 @@ -Disassembly of : - 1:6 - 1:15 0 LOAD_CONST_COLLECTION 0 ([1, 2, 3] type int into tuple) - 2:2 - 3:5 3 MATCH_SEQUENCE - 2:2 - 3:5 4 POP_AND_JUMP_IF_FALSE 30 (to 34) - 2:2 - 3:5 8 GET_LEN - 2:2 - 3:5 9 LOAD_BYTE 1 - 2:2 - 3:5 11 BINARY_OP 17 (GE) - 2:2 - 3:5 13 POP_AND_JUMP_IF_FALSE 21 (to 34) generalizes: 11 - 2:2 - 3:5 17 DUP_TOP - 2:2 - 3:5 18 GET_LEN - 2:2 - 3:5 19 LOAD_BYTE 1 - 2:2 - 3:5 21 BINARY_OP 2 (SUB) - 2:2 - 3:5 23 BINARY_SUBSCR generalizes: 21 - 2:2 - 3:5 24 ROT_N 2 - 2:2 - 3:5 26 POP_TOP - 2:2 - 3:5 27 STORE_NAME 0 (y) - 3:4 - 3:5 29 LOAD_NAME 0 (y) - 3:4 - 3:5 31 POP_TOP - 3:4 - 3:5 32 JUMP_FORWARD 3 (to 35) - 2:2 - 3:5 >> 34 POP_TOP - 2:2 - 3:5 >> 35 LOAD_NONE - 2:2 - 3:5 36 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardSubscript.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardSubscript.co deleted file mode 100644 index d6b41a620c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSeqWildcardSubscript.co +++ /dev/null @@ -1,18 +0,0 @@ -Disassembly of : - 1:6 - 1:12 0 LOAD_CONST_COLLECTION 0 ([1, 2] type int into tuple) - 2:2 - 3:5 3 MATCH_SEQUENCE - 2:2 - 3:5 4 POP_AND_JUMP_IF_FALSE 25 (to 29) - 2:2 - 3:5 8 GET_LEN - 2:2 - 3:5 9 LOAD_BYTE 2 - 2:2 - 3:5 11 BINARY_OP 12 (EQ) - 2:2 - 3:5 13 POP_AND_JUMP_IF_FALSE 16 (to 29) generalizes: 11 - 2:2 - 3:5 17 UNPACK_SEQUENCE 2 - 2:2 - 3:5 19 POP_TOP - 2:2 - 3:5 20 ROT_N 1 - 2:2 - 3:5 22 STORE_NAME 0 (x) - 3:4 - 3:5 24 LOAD_NAME 0 (x) - 3:4 - 3:5 26 POP_TOP - 3:4 - 3:5 27 JUMP_FORWARD 3 (to 30) - 2:2 - 3:5 >> 29 POP_TOP - 2:2 - 3:5 >> 30 LOAD_NONE - 2:2 - 3:5 31 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetComprehension.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetComprehension.co deleted file mode 100644 index 64c0af8f46..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetComprehension.co +++ /dev/null @@ -1,26 +0,0 @@ -Disassembly of : - 1:0 - 1:40 0 MAKE_FUNCTION 0 () - 1:16 - 1:21 3 LOAD_NAME 0 (range) - 1:22 - 1:24 5 LOAD_BYTE 10 - 1:16 - 1:25 7 CALL_FUNCTION 1 - 1:0 - 1:40 9 GET_ITER - 1:0 - 1:40 10 CALL_COMPREHENSION - 1:0 - 1:40 11 RETURN_VALUE - -Disassembly of : - 1:0 - 1:40 0 COLLECTION_FROM_STACK 0 (set) - 1:0 - 1:40 2 LOAD_FAST 0 (.0) - 1:0 - 1:40 >> 4 FOR_ITER 28 (to 32) - 1:11 - 1:12 6 STORE_FAST 1 (x) generalizes: 4 - 1:29 - 1:30 8 LOAD_FAST 1 (x) - 1:33 - 1:34 10 LOAD_BYTE 2 - 1:29 - 1:34 12 BINARY_OP 10 (MOD) generalizes: 10, 8 - 1:38 - 1:39 14 LOAD_BYTE 0 - 1:29 - 1:39 16 BINARY_OP 12 (EQ) generalizes: 14, 12 - 1:0 - 1:40 18 POP_AND_JUMP_IF_FALSE 12 (to 30) generalizes: 16 - 1:1 - 1:2 22 LOAD_FAST 1 (x) - 1:5 - 1:6 24 LOAD_BYTE 2 - 1:1 - 1:6 26 BINARY_OP 4 (MUL) generalizes: 24, 22 - 1:0 - 1:40 28 ADD_TO_COLLECTION 2 (set) - 1:0 - 1:40 >> 30 JUMP_BACKWARD 26 (to 4) - 1:0 - 1:40 >> 32 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetItem.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetItem.co deleted file mode 100644 index dac3346455..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetItem.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:7 - 1:8 0 LOAD_BYTE 1 - 1:0 - 1:1 2 LOAD_NAME 0 (a) - 1:2 - 1:3 4 LOAD_BYTE 3 - 1:0 - 1:4 6 STORE_SUBSCR generalizes: 0, 4 - 1:0 - 1:8 7 LOAD_NONE - 1:0 - 1:8 8 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteral.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteral.co deleted file mode 100644 index bc3aee125b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteral.co +++ /dev/null @@ -1,6 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 2 - 1:7 - 1:8 4 LOAD_BYTE 3 - 1:0 - 1:9 6 COLLECTION_FROM_STACK 3 (set) - 1:0 - 1:9 8 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteralExpand.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteralExpand.co deleted file mode 100644 index 4ff8969b8a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSetLiteralExpand.co +++ /dev/null @@ -1,10 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 2 - 1:7 - 1:8 4 LOAD_BYTE 3 - 1:0 - 1:16 6 COLLECTION_FROM_STACK 3 (set) - 1:11 - 1:12 8 LOAD_NAME 0 (a) - 1:0 - 1:16 10 COLLECTION_ADD_COLLECTION 0 (set) - 1:14 - 1:15 12 LOAD_BYTE 5 - 1:0 - 1:16 14 COLLECTION_ADD_STACK 1 (set) - 1:0 - 1:16 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSingle.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSingle.co deleted file mode 100644 index 62346ae13e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSingle.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_BYTE 1 - 1:0 - 1:1 2 PRINT_EXPR - 1:0 - 1:1 3 LOAD_NONE - 1:0 - 1:1 4 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSlice.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSlice.co deleted file mode 100644 index ec9c3dbf75..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSlice.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:2 - 1:3 2 LOAD_BYTE 3 - 1:4 - 1:5 4 LOAD_BYTE 9 - 1:2 - 1:5 6 BUILD_SLICE 2 - 1:0 - 1:6 8 BINARY_SUBSCR - 1:0 - 1:6 9 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSliceStep.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSliceStep.co deleted file mode 100644 index ab48b5e23e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSliceStep.co +++ /dev/null @@ -1,8 +0,0 @@ -Disassembly of : - 1:0 - 1:1 0 LOAD_NAME 0 (a) - 1:2 - 1:3 2 LOAD_BYTE 3 - 1:4 - 1:5 4 LOAD_BYTE 9 - 1:6 - 1:7 6 LOAD_BYTE 2 - 1:2 - 1:7 8 BUILD_SLICE 3 - 1:0 - 1:8 10 BINARY_SUBSCR - 1:0 - 1:8 11 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testStringSurrogates.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testStringSurrogates.co deleted file mode 100644 index d3ce34c2e6..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testStringSurrogates.co +++ /dev/null @@ -1,5 +0,0 @@ -Disassembly of : - 1:0 - 1:12 0 LOAD_STRING 0 ('𐐀') - 1:16 - 1:30 2 LOAD_STRING 1 ('\ud801\udc00') - 1:0 - 1:30 4 BINARY_OP 13 (NE) - 1:0 - 1:30 6 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSuper.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSuper.co deleted file mode 100644 index 1b121739ed..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testSuper.co +++ /dev/null @@ -1,57 +0,0 @@ -Disassembly of : - 1:0 - 3:20 0 LOAD_BUILD_CLASS - 1:0 - 3:20 1 MAKE_FUNCTION 0 (Foo) - 1:0 - 3:20 4 LOAD_STRING 1 ('Foo') - 1:0 - 3:20 6 COLLECTION_FROM_STACK 2 (Object[]) - 1:0 - 3:20 8 CALL_FUNCTION_VARARGS - 1:0 - 3:20 9 STORE_NAME 0 (Foo) - 4:0 - 6:21 11 LOAD_BUILD_CLASS - 4:0 - 6:21 12 MAKE_FUNCTION 0 (Bar) - 4:0 - 6:21 15 LOAD_STRING 3 ('Bar') - 4:10 - 4:13 17 LOAD_NAME 0 (Foo) - 4:0 - 6:21 19 COLLECTION_FROM_STACK 3 (Object[]) - 4:0 - 6:21 21 CALL_FUNCTION_VARARGS - 4:0 - 6:21 22 STORE_NAME 1 (Bar) - 4:0 - 6:21 24 LOAD_NONE - 4:0 - 6:21 25 RETURN_VALUE - -Disassembly of Foo: - 1:0 - 3:20 0 LOAD_NAME 0 (__name__) - 1:0 - 3:20 2 STORE_NAME 1 (__module__) - 1:0 - 3:20 4 LOAD_STRING 0 ('Foo') - 1:0 - 3:20 6 STORE_NAME 2 (__qualname__) - 2:4 - 3:20 8 MAKE_FUNCTION 0 (Foo.boo) - 2:4 - 3:20 11 STORE_NAME 3 (boo) - 2:4 - 3:20 13 LOAD_NONE - 2:4 - 3:20 14 RETURN_VALUE - -Disassembly of Foo.boo: - 3:8 - 3:13 0 LOAD_GLOBAL 0 (print) - 3:14 - 3:19 2 LOAD_STRING 1 ('boo') - 3:8 - 3:20 4 CALL_FUNCTION 1 - 3:8 - 3:20 6 POP_TOP - 3:8 - 3:20 7 LOAD_NONE - 3:8 - 3:20 8 RETURN_VALUE - -Disassembly of Bar: - 4:0 - 6:21 0 LOAD_NAME 0 (__name__) - 4:0 - 6:21 2 STORE_NAME 1 (__module__) - 4:0 - 6:21 4 LOAD_STRING 0 ('Bar') - 4:0 - 6:21 6 STORE_NAME 2 (__qualname__) - 5:4 - 6:21 8 LOAD_CLOSURE 0 (__class__) - 5:4 - 6:21 10 CLOSURE_FROM_STACK 1 - 5:4 - 6:21 12 MAKE_FUNCTION 8 (Bar.boo) - 5:4 - 6:21 15 STORE_NAME 3 (boo) - 5:4 - 6:21 17 LOAD_CLOSURE 0 (__class__) - 5:4 - 6:21 19 DUP_TOP - 5:4 - 6:21 20 STORE_NAME 4 (__classcell__) - 5:4 - 6:21 22 RETURN_VALUE - -Disassembly of Bar.boo: - 6:8 - 6:13 0 LOAD_GLOBAL 0 (super) - 6:8 - 6:15 2 CALL_FUNCTION 0 - 6:8 - 6:21 4 LOAD_METHOD 1 (boo) - 6:8 - 6:21 6 CALL_METHOD 0 - 6:8 - 6:21 8 POP_TOP - 6:8 - 6:21 9 LOAD_NONE - 6:8 - 6:21 10 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExcept.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExcept.co deleted file mode 100644 index 6769371788..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExcept.co +++ /dev/null @@ -1,51 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 7:18 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 64 (to 79) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 4:7 - 4:16 18 LOAD_NAME 1 (TypeError) - 4:0 - 5:18 20 MATCH_EXC_OR_JUMP 28 (to 48) - 4:0 - 5:18 24 UNWRAP_EXC - 4:0 - 5:18 25 STORE_NAME 2 (e) - 5:2 - 5:7 27 LOAD_NAME 0 (print) - 5:8 - 5:17 29 LOAD_STRING 2 ('except1') - 5:2 - 5:18 31 CALL_FUNCTION 1 - 5:2 - 5:18 33 POP_TOP - 5:2 - 5:18 34 LOAD_NONE - 5:2 - 5:18 35 STORE_NAME 2 (e) - 5:2 - 5:18 37 DELETE_NAME 2 (e) - 5:2 - 5:18 39 POP_EXCEPT - 5:2 - 5:18 40 JUMP_FORWARD 39 (to 79) - 5:2 - 5:18 42 LOAD_NONE (exc handler 27 - 34; stack: 1) - 5:2 - 5:18 43 STORE_NAME 2 (e) - 5:2 - 5:18 45 DELETE_NAME 2 (e) - 5:2 - 5:18 47 END_EXC_HANDLER - 6:7 - 6:17 >> 48 LOAD_NAME 3 (ValueError) - 6:0 - 7:18 50 MATCH_EXC_OR_JUMP 28 (to 78) - 6:0 - 7:18 54 UNWRAP_EXC - 6:0 - 7:18 55 STORE_NAME 2 (e) - 7:2 - 7:7 57 LOAD_NAME 0 (print) - 7:8 - 7:17 59 LOAD_STRING 3 ('except2') - 7:2 - 7:18 61 CALL_FUNCTION 1 - 7:2 - 7:18 63 POP_TOP - 7:2 - 7:18 64 LOAD_NONE - 7:2 - 7:18 65 STORE_NAME 2 (e) - 7:2 - 7:18 67 DELETE_NAME 2 (e) - 7:2 - 7:18 69 POP_EXCEPT - 7:2 - 7:18 70 JUMP_FORWARD 9 (to 79) - 7:2 - 7:18 72 LOAD_NONE (exc handler 57 - 64; stack: 1) - 7:2 - 7:18 73 STORE_NAME 2 (e) - 7:2 - 7:18 75 DELETE_NAME 2 (e) - 7:2 - 7:18 77 END_EXC_HANDLER - 7:2 - 7:18 >> 78 END_EXC_HANDLER (exc handler 18 - 27; stack: 1 | exc handler 34 - 57; stack: 1 | exc handler 64 - 78; stack: 1) - 8:0 - 8:5 >> 79 LOAD_NAME 0 (print) - 8:6 - 8:13 81 LOAD_STRING 4 ('after') - 8:0 - 8:14 83 CALL_FUNCTION 1 - 8:0 - 8:14 85 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptBare.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptBare.co deleted file mode 100644 index 29deb62e59..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptBare.co +++ /dev/null @@ -1,41 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 7:22 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 45 (to 60) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 4:7 - 4:16 18 LOAD_NAME 1 (TypeError) - 4:0 - 5:18 20 MATCH_EXC_OR_JUMP 28 (to 48) - 4:0 - 5:18 24 UNWRAP_EXC - 4:0 - 5:18 25 STORE_NAME 2 (e) - 5:2 - 5:7 27 LOAD_NAME 0 (print) - 5:8 - 5:17 29 LOAD_STRING 2 ('except1') - 5:2 - 5:18 31 CALL_FUNCTION 1 - 5:2 - 5:18 33 POP_TOP - 5:2 - 5:18 34 LOAD_NONE - 5:2 - 5:18 35 STORE_NAME 2 (e) - 5:2 - 5:18 37 DELETE_NAME 2 (e) - 5:2 - 5:18 39 POP_EXCEPT - 5:2 - 5:18 40 JUMP_FORWARD 20 (to 60) - 5:2 - 5:18 42 LOAD_NONE (exc handler 27 - 34; stack: 1) - 5:2 - 5:18 43 STORE_NAME 2 (e) - 5:2 - 5:18 45 DELETE_NAME 2 (e) - 5:2 - 5:18 47 END_EXC_HANDLER - 6:0 - 7:22 >> 48 POP_TOP - 7:2 - 7:7 49 LOAD_NAME 0 (print) - 7:8 - 7:21 51 LOAD_STRING 3 ('except bare') - 7:2 - 7:22 53 CALL_FUNCTION 1 - 7:2 - 7:22 55 POP_TOP - 7:2 - 7:22 56 POP_EXCEPT - 7:2 - 7:22 57 JUMP_FORWARD 3 (to 60) - 7:2 - 7:22 59 END_EXC_HANDLER (exc handler 18 - 27; stack: 1 | exc handler 34 - 59; stack: 1) - 8:0 - 8:5 >> 60 LOAD_NAME 0 (print) - 8:6 - 8:13 62 LOAD_STRING 4 ('after') - 8:0 - 8:14 64 CALL_FUNCTION 1 - 8:0 - 8:14 66 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElse.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElse.co deleted file mode 100644 index c3dfb115e1..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElse.co +++ /dev/null @@ -1,56 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 9:15 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 64 (to 79) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 4:7 - 4:16 18 LOAD_NAME 1 (TypeError) - 4:0 - 5:18 20 MATCH_EXC_OR_JUMP 28 (to 48) - 4:0 - 5:18 24 UNWRAP_EXC - 4:0 - 5:18 25 STORE_NAME 2 (e) - 5:2 - 5:7 27 LOAD_NAME 0 (print) - 5:8 - 5:17 29 LOAD_STRING 2 ('except1') - 5:2 - 5:18 31 CALL_FUNCTION 1 - 5:2 - 5:18 33 POP_TOP - 5:2 - 5:18 34 LOAD_NONE - 5:2 - 5:18 35 STORE_NAME 2 (e) - 5:2 - 5:18 37 DELETE_NAME 2 (e) - 5:2 - 5:18 39 POP_EXCEPT - 5:2 - 5:18 40 JUMP_FORWARD 48 (to 88) - 5:2 - 5:18 42 LOAD_NONE (exc handler 27 - 34; stack: 1) - 5:2 - 5:18 43 STORE_NAME 2 (e) - 5:2 - 5:18 45 DELETE_NAME 2 (e) - 5:2 - 5:18 47 END_EXC_HANDLER - 6:7 - 6:17 >> 48 LOAD_NAME 3 (ValueError) - 6:0 - 7:18 50 MATCH_EXC_OR_JUMP 28 (to 78) - 6:0 - 7:18 54 UNWRAP_EXC - 6:0 - 7:18 55 STORE_NAME 2 (e) - 7:2 - 7:7 57 LOAD_NAME 0 (print) - 7:8 - 7:17 59 LOAD_STRING 3 ('except2') - 7:2 - 7:18 61 CALL_FUNCTION 1 - 7:2 - 7:18 63 POP_TOP - 7:2 - 7:18 64 LOAD_NONE - 7:2 - 7:18 65 STORE_NAME 2 (e) - 7:2 - 7:18 67 DELETE_NAME 2 (e) - 7:2 - 7:18 69 POP_EXCEPT - 7:2 - 7:18 70 JUMP_FORWARD 18 (to 88) - 7:2 - 7:18 72 LOAD_NONE (exc handler 57 - 64; stack: 1) - 7:2 - 7:18 73 STORE_NAME 2 (e) - 7:2 - 7:18 75 DELETE_NAME 2 (e) - 7:2 - 7:18 77 END_EXC_HANDLER - 7:2 - 7:18 >> 78 END_EXC_HANDLER (exc handler 18 - 27; stack: 1 | exc handler 34 - 57; stack: 1 | exc handler 64 - 78; stack: 1) - 9:2 - 9:7 >> 79 LOAD_NAME 0 (print) - 9:8 - 9:14 81 LOAD_STRING 4 ('else') - 9:2 - 9:15 83 CALL_FUNCTION 1 - 9:2 - 9:15 85 POP_TOP - 9:2 - 9:15 86 JUMP_FORWARD 2 (to 88) - 10:0 - 10:5 >> 88 LOAD_NAME 0 (print) - 10:6 - 10:13 90 LOAD_STRING 5 ('after') - 10:0 - 10:14 92 CALL_FUNCTION 1 - 10:0 - 10:14 94 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElseFinally.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElseFinally.co deleted file mode 100644 index 7ec445bf30..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptElseFinally.co +++ /dev/null @@ -1,72 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 11:18 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 73 (to 88) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 4:7 - 4:16 18 LOAD_NAME 1 (TypeError) - 4:0 - 5:18 20 MATCH_EXC_OR_JUMP 31 (to 51) - 4:0 - 5:18 24 UNWRAP_EXC - 4:0 - 5:18 25 STORE_NAME 2 (e) - 5:2 - 5:7 27 LOAD_NAME 0 (print) - 5:8 - 5:17 29 LOAD_STRING 2 ('except1') - 5:2 - 5:18 31 CALL_FUNCTION 1 - 5:2 - 5:18 33 POP_TOP - 5:2 - 5:18 34 LOAD_NONE - 5:2 - 5:18 35 STORE_NAME 2 (e) - 5:2 - 5:18 37 DELETE_NAME 2 (e) - 5:2 - 5:18 39 POP_EXCEPT - 5:2 - 5:18 40 JUMP_FORWARD 66 (to 106) - 5:2 - 5:18 42 LOAD_NONE (exc handler 27 - 34; stack: 1) - 5:2 - 5:18 43 STORE_NAME 2 (e) - 5:2 - 5:18 45 DELETE_NAME 2 (e) - 5:2 - 5:18 47 ROT_TWO - 5:2 - 5:18 48 POP_EXCEPT - 5:2 - 5:18 49 JUMP_FORWARD 48 (to 97) - 6:7 - 6:17 >> 51 LOAD_NAME 3 (ValueError) - 6:0 - 7:18 53 MATCH_EXC_OR_JUMP 45 (to 98) - 6:0 - 7:18 57 UNWRAP_EXC - 6:0 - 7:18 58 STORE_NAME 2 (e) - 7:2 - 7:7 60 LOAD_NAME 0 (print) - 7:8 - 7:17 62 LOAD_STRING 3 ('except2') - 7:2 - 7:18 64 CALL_FUNCTION 1 - 7:2 - 7:18 66 POP_TOP - 7:2 - 7:18 67 LOAD_NONE - 7:2 - 7:18 68 STORE_NAME 2 (e) - 7:2 - 7:18 70 DELETE_NAME 2 (e) - 7:2 - 7:18 72 POP_EXCEPT - 7:2 - 7:18 73 JUMP_FORWARD 33 (to 106) - 7:2 - 7:18 75 LOAD_NONE (exc handler 60 - 67; stack: 1) - 7:2 - 7:18 76 STORE_NAME 2 (e) - 7:2 - 7:18 78 DELETE_NAME 2 (e) - 7:2 - 7:18 80 ROT_TWO - 7:2 - 7:18 81 POP_EXCEPT - 7:2 - 7:18 82 JUMP_FORWARD 15 (to 97) - 7:2 - 7:18 84 ROT_TWO (exc handler 18 - 27; stack: 1 | exc handler 34 - 60; stack: 1 | exc handler 67 - 84; stack: 1) - 7:2 - 7:18 85 POP_EXCEPT - 7:2 - 7:18 86 JUMP_FORWARD 11 (to 97) - 9:2 - 9:7 >> 88 LOAD_NAME 0 (print) - 9:8 - 9:14 90 LOAD_STRING 4 ('else') - 9:2 - 9:15 92 CALL_FUNCTION 1 - 9:2 - 9:15 94 POP_TOP - 9:2 - 9:15 95 JUMP_FORWARD 11 (to 106) - 9:2 - 9:15 >> 97 PUSH_EXC_INFO (exc handler 17 - 18; stack: 0 | exc handler 84 - 97; stack: 0) - 11:2 - 11:7 >> 98 LOAD_NAME 0 (print) - 11:8 - 11:17 100 LOAD_STRING 5 ('finally') - 11:2 - 11:18 102 CALL_FUNCTION 1 - 11:2 - 11:18 104 POP_TOP - 11:2 - 11:18 105 END_EXC_HANDLER (exc handler 98 - 105; stack: 1) - 11:2 - 11:7 >> 106 LOAD_NAME 0 (print) - 11:8 - 11:17 108 LOAD_STRING 5 ('finally') - 11:2 - 11:18 110 CALL_FUNCTION 1 - 11:2 - 11:18 112 POP_TOP - 12:0 - 12:5 113 LOAD_NAME 0 (print) - 12:6 - 12:13 115 LOAD_STRING 6 ('after') - 12:0 - 12:14 117 CALL_FUNCTION 1 - 12:0 - 12:14 119 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptFinally.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptFinally.co deleted file mode 100644 index 4bfe40f408..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryExceptFinally.co +++ /dev/null @@ -1,67 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 9:18 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 82 (to 97) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 4:7 - 4:16 18 LOAD_NAME 1 (TypeError) - 4:0 - 5:18 20 MATCH_EXC_OR_JUMP 31 (to 51) - 4:0 - 5:18 24 UNWRAP_EXC - 4:0 - 5:18 25 STORE_NAME 2 (e) - 5:2 - 5:7 27 LOAD_NAME 0 (print) - 5:8 - 5:17 29 LOAD_STRING 2 ('except1') - 5:2 - 5:18 31 CALL_FUNCTION 1 - 5:2 - 5:18 33 POP_TOP - 5:2 - 5:18 34 LOAD_NONE - 5:2 - 5:18 35 STORE_NAME 2 (e) - 5:2 - 5:18 37 DELETE_NAME 2 (e) - 5:2 - 5:18 39 POP_EXCEPT - 5:2 - 5:18 40 JUMP_FORWARD 57 (to 97) - 5:2 - 5:18 42 LOAD_NONE (exc handler 27 - 34; stack: 1) - 5:2 - 5:18 43 STORE_NAME 2 (e) - 5:2 - 5:18 45 DELETE_NAME 2 (e) - 5:2 - 5:18 47 ROT_TWO - 5:2 - 5:18 48 POP_EXCEPT - 5:2 - 5:18 49 JUMP_FORWARD 39 (to 88) - 6:7 - 6:17 >> 51 LOAD_NAME 3 (ValueError) - 6:0 - 7:18 53 MATCH_EXC_OR_JUMP 36 (to 89) - 6:0 - 7:18 57 UNWRAP_EXC - 6:0 - 7:18 58 STORE_NAME 2 (e) - 7:2 - 7:7 60 LOAD_NAME 0 (print) - 7:8 - 7:17 62 LOAD_STRING 3 ('except2') - 7:2 - 7:18 64 CALL_FUNCTION 1 - 7:2 - 7:18 66 POP_TOP - 7:2 - 7:18 67 LOAD_NONE - 7:2 - 7:18 68 STORE_NAME 2 (e) - 7:2 - 7:18 70 DELETE_NAME 2 (e) - 7:2 - 7:18 72 POP_EXCEPT - 7:2 - 7:18 73 JUMP_FORWARD 24 (to 97) - 7:2 - 7:18 75 LOAD_NONE (exc handler 60 - 67; stack: 1) - 7:2 - 7:18 76 STORE_NAME 2 (e) - 7:2 - 7:18 78 DELETE_NAME 2 (e) - 7:2 - 7:18 80 ROT_TWO - 7:2 - 7:18 81 POP_EXCEPT - 7:2 - 7:18 82 JUMP_FORWARD 6 (to 88) - 7:2 - 7:18 84 ROT_TWO (exc handler 18 - 27; stack: 1 | exc handler 34 - 60; stack: 1 | exc handler 67 - 84; stack: 1) - 7:2 - 7:18 85 POP_EXCEPT - 7:2 - 7:18 86 JUMP_FORWARD 2 (to 88) - 7:2 - 7:18 >> 88 PUSH_EXC_INFO (exc handler 17 - 18; stack: 0 | exc handler 84 - 88; stack: 0) - 9:2 - 9:7 >> 89 LOAD_NAME 0 (print) - 9:8 - 9:17 91 LOAD_STRING 4 ('finally') - 9:2 - 9:18 93 CALL_FUNCTION 1 - 9:2 - 9:18 95 POP_TOP - 9:2 - 9:18 96 END_EXC_HANDLER (exc handler 89 - 96; stack: 1) - 9:2 - 9:7 >> 97 LOAD_NAME 0 (print) - 9:8 - 9:17 99 LOAD_STRING 4 ('finally') - 9:2 - 9:18 101 CALL_FUNCTION 1 - 9:2 - 9:18 103 POP_TOP - 10:0 - 10:5 104 LOAD_NAME 0 (print) - 10:6 - 10:13 106 LOAD_STRING 5 ('after') - 10:0 - 10:14 108 CALL_FUNCTION 1 - 10:0 - 10:14 110 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinally.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinally.co deleted file mode 100644 index ffa0641e17..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinally.co +++ /dev/null @@ -1,25 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:0 - 5:18 7 NOP - 3:2 - 3:7 8 LOAD_NAME 0 (print) - 3:8 - 3:13 10 LOAD_STRING 1 ('try') - 3:2 - 3:14 12 CALL_FUNCTION 1 - 3:2 - 3:14 14 POP_TOP - 3:2 - 3:14 15 JUMP_FORWARD 11 (to 26) - 3:2 - 3:14 17 PUSH_EXC_INFO (exc handler 8 - 17; stack: 0) - 5:2 - 5:7 18 LOAD_NAME 0 (print) - 5:8 - 5:17 20 LOAD_STRING 2 ('finally') - 5:2 - 5:18 22 CALL_FUNCTION 1 - 5:2 - 5:18 24 POP_TOP - 5:2 - 5:18 25 END_EXC_HANDLER (exc handler 18 - 25; stack: 1) - 5:2 - 5:7 >> 26 LOAD_NAME 0 (print) - 5:8 - 5:17 28 LOAD_STRING 2 ('finally') - 5:2 - 5:18 30 CALL_FUNCTION 1 - 5:2 - 5:18 32 POP_TOP - 6:0 - 6:5 33 LOAD_NAME 0 (print) - 6:6 - 6:13 35 LOAD_STRING 3 ('after') - 6:0 - 6:14 37 CALL_FUNCTION 1 - 6:0 - 6:14 39 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinallyNested.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinallyNested.co deleted file mode 100644 index 3bcbbe646a..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTryFinallyNested.co +++ /dev/null @@ -1,46 +0,0 @@ -Disassembly of : - 1:0 - 10:25 0 MAKE_FUNCTION 0 (foo) - 1:0 - 10:25 3 STORE_NAME 0 (foo) - 1:0 - 10:25 5 LOAD_NONE - 1:0 - 10:25 6 RETURN_VALUE - -Disassembly of foo: - 2:13 - 2:16 0 LOAD_FAST 0 (obj) - 2:4 - 3:16 2 GET_ITER - 2:4 - 3:16 >> 3 FOR_ITER 13 (to 16) - 2:8 - 2:9 5 STORE_FAST 1 (x) generalizes: 3 - 3:8 - 3:13 7 LOAD_GLOBAL 0 (print) - 3:14 - 3:15 9 LOAD_FAST 1 (x) - 3:8 - 3:16 11 CALL_FUNCTION 1 - 3:8 - 3:16 13 POP_TOP - 3:8 - 3:16 14 JUMP_BACKWARD 11 (to 3) - 4:4 - 10:25 >> 16 NOP - 5:8 - 8:29 17 NOP - 6:12 - 6:17 18 LOAD_GLOBAL 0 (print) - 6:18 - 6:23 20 LOAD_STRING 1 ('try') - 6:12 - 6:24 22 CALL_FUNCTION 1 - 6:12 - 6:24 24 POP_TOP - 6:12 - 6:24 25 JUMP_FORWARD 11 (to 36) - 6:12 - 6:24 27 PUSH_EXC_INFO (exc handler 18 - 27; stack: 0) - 8:12 - 8:17 28 LOAD_GLOBAL 0 (print) - 8:18 - 8:28 30 LOAD_STRING 2 ('finally1') - 8:12 - 8:29 32 CALL_FUNCTION 1 - 8:12 - 8:29 34 POP_TOP - 8:12 - 8:29 35 END_EXC_HANDLER (exc handler 28 - 35; stack: 1) - 8:12 - 8:17 >> 36 LOAD_GLOBAL 0 (print) - 8:18 - 8:28 38 LOAD_STRING 2 ('finally1') - 8:12 - 8:29 40 CALL_FUNCTION 1 - 8:12 - 8:29 42 POP_TOP - 8:12 - 8:29 43 JUMP_FORWARD 11 (to 54) - 8:12 - 8:29 45 PUSH_EXC_INFO (exc handler 17 - 18; stack: 0 | exc handler 27 - 28; stack: 0 | exc handler 35 - 45; stack: 0) - 10:8 - 10:13 46 LOAD_GLOBAL 0 (print) - 10:14 - 10:24 48 LOAD_STRING 3 ('finally2') - 10:8 - 10:25 50 CALL_FUNCTION 1 - 10:8 - 10:25 52 POP_TOP - 10:8 - 10:25 53 END_EXC_HANDLER (exc handler 46 - 53; stack: 1) - 10:8 - 10:13 >> 54 LOAD_GLOBAL 0 (print) - 10:14 - 10:24 56 LOAD_STRING 3 ('finally2') - 10:8 - 10:25 58 CALL_FUNCTION 1 - 10:8 - 10:25 60 POP_TOP - 10:8 - 10:25 61 LOAD_NONE - 10:8 - 10:25 62 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralBooleans.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralBooleans.co deleted file mode 100644 index 5fdd55aa7e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralBooleans.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:13 0 LOAD_CONST_COLLECTION 0 ([false, true] type boolean into tuple) - 1:0 - 1:13 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralDoubles.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralDoubles.co deleted file mode 100644 index 845f492125..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralDoubles.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:15 0 LOAD_CONST_COLLECTION 0 ([1.0, 2.0, 3.0] type double into tuple) - 1:0 - 1:15 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralExpand.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralExpand.co deleted file mode 100644 index ecd32ed199..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralExpand.co +++ /dev/null @@ -1,11 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 2 - 1:7 - 1:8 4 LOAD_BYTE 3 - 1:0 - 1:16 6 COLLECTION_FROM_STACK 3 (list) - 1:11 - 1:12 8 LOAD_NAME 0 (a) - 1:0 - 1:16 10 COLLECTION_ADD_COLLECTION 0 (list) - 1:14 - 1:15 12 LOAD_BYTE 5 - 1:0 - 1:16 14 COLLECTION_ADD_STACK 1 (list) - 1:0 - 1:16 16 TUPLE_FROM_LIST - 1:0 - 1:16 17 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralInts.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralInts.co deleted file mode 100644 index 5478405380..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralInts.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:9 0 LOAD_CONST_COLLECTION 0 ([1, 2, 3] type int into tuple) - 1:0 - 1:9 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixed.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixed.co deleted file mode 100644 index df41516ad1..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixed.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:11 0 LOAD_CONST_COLLECTION 0 ([1, 2, 3.0] type Object into tuple) - 1:0 - 1:11 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixedIntegers.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixedIntegers.co deleted file mode 100644 index 1e9eada3e2..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralMixedIntegers.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:19 0 LOAD_CONST_COLLECTION 0 ([1, 17179869184, 3] type long into tuple) - 1:0 - 1:19 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralNonConstant.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralNonConstant.co deleted file mode 100644 index 2c6a45a217..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralNonConstant.co +++ /dev/null @@ -1,6 +0,0 @@ -Disassembly of : - 1:1 - 1:2 0 LOAD_BYTE 1 - 1:4 - 1:5 2 LOAD_BYTE 2 - 1:7 - 1:10 4 LOAD_CONST_COLLECTION 0 ([3] type int into list) - 1:0 - 1:11 7 COLLECTION_FROM_STACK 3 (tuple) - 1:0 - 1:11 9 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralObjects.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralObjects.co deleted file mode 100644 index 93dcdfd34b..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testTupleLiteralObjects.co +++ /dev/null @@ -1,3 +0,0 @@ -Disassembly of : - 1:0 - 1:14 0 LOAD_CONST_COLLECTION 0 ([a, 1, None] type Object into tuple) - 1:0 - 1:14 3 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpack.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpack.co deleted file mode 100644 index a5566a969f..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpack.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:7 - 1:11 0 LOAD_CONST_COLLECTION 0 ([1, 2] type int into tuple) - 1:0 - 1:4 3 UNPACK_SEQUENCE 2 - 1:0 - 1:1 5 STORE_NAME 0 (a) - 1:3 - 1:4 7 STORE_NAME 1 (b) - 1:0 - 1:11 9 LOAD_NONE - 1:0 - 1:11 10 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpackEx.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpackEx.co deleted file mode 100644 index 9273354be9..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testUnpackEx.co +++ /dev/null @@ -1,8 +0,0 @@ -Disassembly of : - 1:11 - 1:24 0 LOAD_CONST_COLLECTION 0 ([1, 2, 3, 4, 5] type int into tuple) - 1:0 - 1:8 3 UNPACK_EX 1 (1, 1) - 1:0 - 1:1 6 STORE_NAME 0 (a) - 1:4 - 1:5 8 STORE_NAME 1 (b) - 1:7 - 1:8 10 STORE_NAME 2 (c) - 1:0 - 1:24 12 LOAD_NONE - 1:0 - 1:24 13 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarArgs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarArgs.co deleted file mode 100644 index 7ac7008413..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarArgs.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:0 - 2:14 0 MAKE_FUNCTION 0 (foo) - 1:0 - 2:14 3 STORE_NAME 0 (foo) - 1:0 - 2:14 5 LOAD_NONE - 1:0 - 2:14 6 RETURN_VALUE - -Disassembly of foo: - 2:2 - 2:7 0 LOAD_GLOBAL 0 (print) - 2:9 - 2:13 2 LOAD_FAST 0 (args) - 2:2 - 2:14 4 COLLECTION_FROM_COLLECTION 0 (Object[]) - 2:2 - 2:14 6 CALL_FUNCTION_VARARGS - 2:2 - 2:14 7 POP_TOP - 2:2 - 2:14 8 LOAD_NONE - 2:2 - 2:14 9 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarKwargs.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarKwargs.co deleted file mode 100644 index 0ff47bca5c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testVarKwargs.co +++ /dev/null @@ -1,15 +0,0 @@ -Disassembly of : - 1:0 - 2:17 0 MAKE_FUNCTION 0 (foo) - 1:0 - 2:17 3 STORE_NAME 0 (foo) - 1:0 - 2:17 5 LOAD_NONE - 1:0 - 2:17 6 RETURN_VALUE - -Disassembly of foo: - 2:2 - 2:7 0 LOAD_GLOBAL 0 (print) - 2:2 - 2:17 2 COLLECTION_FROM_STACK 0 (Object[]) - 2:10 - 2:16 4 LOAD_FAST 0 (kwargs) - 2:2 - 2:17 6 COLLECTION_FROM_COLLECTION 0 (PKeyword[]) - 2:2 - 2:17 8 CALL_FUNCTION_KW - 2:2 - 2:17 9 POP_TOP - 2:2 - 2:17 10 LOAD_NONE - 2:2 - 2:17 11 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhile.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhile.co deleted file mode 100644 index f4c6b7041c..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhile.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:6 - 1:11 >> 0 LOAD_FALSE - 1:0 - 1:17 1 POP_AND_JUMP_IF_FALSE 7 (to 8) generalizes: 0 - 1:13 - 1:17 5 NOP - 1:13 - 1:17 6 JUMP_BACKWARD 6 (to 0) - 1:13 - 1:17 >> 8 LOAD_NONE - 1:13 - 1:17 9 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhileBreakContinue.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhileBreakContinue.co deleted file mode 100644 index db5bf4f06e..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWhileBreakContinue.co +++ /dev/null @@ -1,25 +0,0 @@ -Disassembly of : - 1:4 - 1:5 0 LOAD_BYTE 0 - 1:0 - 1:1 2 STORE_NAME 0 (i) - 2:6 - 2:7 >> 4 LOAD_NAME 0 (i) - 2:10 - 2:12 6 LOAD_BYTE 10 - 2:6 - 2:12 8 BINARY_OP 14 (LT) - 2:0 - 9:15 10 POP_AND_JUMP_IF_FALSE 30 (to 40) generalizes: 8 - 3:5 - 3:6 14 LOAD_NAME 0 (i) - 3:10 - 3:11 16 LOAD_BYTE 3 - 3:5 - 3:11 18 BINARY_OP 12 (EQ) - 3:2 - 7:12 20 POP_AND_JUMP_IF_FALSE 8 (to 28) generalizes: 18 - 4:4 - 4:9 24 JUMP_FORWARD 23 (to 47) - 4:4 - 4:9 26 JUMP_FORWARD 12 (to 38) - 6:4 - 6:5 >> 28 LOAD_NAME 0 (i) - 6:9 - 6:10 30 LOAD_BYTE 1 - 6:4 - 6:10 32 BINARY_OP 1 (INPLACE_ADD) - 6:4 - 6:5 34 STORE_NAME 0 (i) - 7:4 - 7:12 36 JUMP_BACKWARD 32 (to 4) - 7:4 - 7:12 >> 38 JUMP_BACKWARD 34 (to 4) - 9:2 - 9:7 >> 40 LOAD_NAME 1 (print) - 9:8 - 9:14 42 LOAD_STRING 0 ('else') - 9:2 - 9:15 44 CALL_FUNCTION 1 - 9:2 - 9:15 46 POP_TOP - 9:2 - 9:15 >> 47 LOAD_NONE - 9:2 - 9:15 48 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWildcard.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWildcard.co deleted file mode 100644 index 3465c212ea..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWildcard.co +++ /dev/null @@ -1,7 +0,0 @@ -Disassembly of : - 1:6 - 1:7 0 LOAD_BYTE 1 - 2:2 - 3:8 2 POP_TOP - 3:4 - 3:8 3 NOP - 3:4 - 3:8 4 JUMP_FORWARD 2 (to 6) - 2:2 - 3:8 >> 6 LOAD_NONE - 2:2 - 3:8 7 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWith.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWith.co deleted file mode 100644 index 621b2bca20..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWith.co +++ /dev/null @@ -1,21 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:5 - 2:9 7 LOAD_NAME 1 (open) - 2:10 - 2:21 9 LOAD_STRING 1 ('/dev/null') - 2:5 - 2:22 11 CALL_FUNCTION 1 - 2:0 - 3:16 13 SETUP_WITH - 2:26 - 2:27 14 STORE_NAME 2 (f) - 3:2 - 3:3 16 LOAD_NAME 2 (f) - 3:2 - 3:16 18 LOAD_METHOD 3 (write) - 3:10 - 3:15 20 LOAD_STRING 2 ('foo') - 3:2 - 3:16 22 CALL_METHOD 1 - 3:2 - 3:16 24 POP_TOP - 3:2 - 3:16 25 LOAD_NONE - 2:0 - 3:16 26 EXIT_WITH (exc handler 14 - 26; stack: 2) - 4:0 - 4:5 27 LOAD_NAME 0 (print) - 4:6 - 4:13 29 LOAD_STRING 3 ('after') - 4:0 - 4:14 31 CALL_FUNCTION 1 - 4:0 - 4:14 33 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWithMultiple.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWithMultiple.co deleted file mode 100644 index 4d610c8ac8..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testWithMultiple.co +++ /dev/null @@ -1,28 +0,0 @@ -Disassembly of : - 1:0 - 1:5 0 LOAD_NAME 0 (print) - 1:6 - 1:14 2 LOAD_STRING 0 ('before') - 1:0 - 1:15 4 CALL_FUNCTION 1 - 1:0 - 1:15 6 POP_TOP - 2:5 - 2:9 7 LOAD_NAME 1 (open) - 2:10 - 2:21 9 LOAD_STRING 1 ('/dev/null') - 2:5 - 2:22 11 CALL_FUNCTION 1 - 2:0 - 3:16 13 SETUP_WITH - 2:26 - 2:27 14 STORE_NAME 2 (f) - 2:29 - 2:33 16 LOAD_NAME 1 (open) - 2:34 - 2:44 18 LOAD_STRING 2 ('/tmp/foo') - 2:29 - 2:45 20 CALL_FUNCTION 1 - 2:0 - 3:16 22 SETUP_WITH - 2:0 - 3:16 23 POP_TOP - 3:2 - 3:3 24 LOAD_NAME 2 (f) - 3:2 - 3:16 26 LOAD_METHOD 3 (write) - 3:10 - 3:15 28 LOAD_STRING 3 ('foo') - 3:2 - 3:16 30 CALL_METHOD 1 - 3:2 - 3:16 32 POP_TOP - 3:2 - 3:16 33 LOAD_NONE - 2:0 - 3:16 34 EXIT_WITH (exc handler 23 - 34; stack: 4) - 2:0 - 3:16 35 LOAD_NONE - 2:0 - 3:16 36 EXIT_WITH (exc handler 14 - 23; stack: 2 | exc handler 34 - 36; stack: 2) - 4:0 - 4:5 37 LOAD_NAME 0 (print) - 4:6 - 4:13 39 LOAD_STRING 4 ('after') - 4:0 - 4:14 41 CALL_FUNCTION 1 - 4:0 - 4:14 43 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldExpression.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldExpression.co deleted file mode 100644 index 9165015661..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldExpression.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:0 - 2:15 0 MAKE_FUNCTION 0 (gen) - 1:0 - 2:15 3 STORE_NAME 0 (gen) - 1:0 - 2:15 5 LOAD_NONE - 1:0 - 2:15 6 RETURN_VALUE - -Disassembly of gen: -Flags: CO_GENERATOR - 2:14 - 2:15 0 LOAD_FAST 0 (a) - 2:8 - 2:15 2 YIELD_VALUE - 2:8 - 2:15 3 RESUME_YIELD - 2:4 - 2:5 4 STORE_FAST 1 (b) - 2:4 - 2:15 6 LOAD_NONE - 2:4 - 2:15 7 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldFrom.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldFrom.co deleted file mode 100644 index 78fe04423f..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldFrom.co +++ /dev/null @@ -1,20 +0,0 @@ -Disassembly of : - 1:0 - 2:16 0 MAKE_FUNCTION 0 (gen) - 1:0 - 2:16 3 STORE_NAME 0 (gen) - 1:0 - 2:16 5 LOAD_NONE - 1:0 - 2:16 6 RETURN_VALUE - -Disassembly of gen: -Flags: CO_GENERATOR - 2:15 - 2:16 0 LOAD_FAST 0 (a) - 2:4 - 2:16 2 GET_YIELD_FROM_ITER - 2:4 - 2:16 3 LOAD_NONE - 2:4 - 2:16 >> 4 SEND 10 (to 14) - 2:4 - 2:16 >> 6 YIELD_VALUE - 2:4 - 2:16 7 RESUME_YIELD - 2:4 - 2:16 8 JUMP_BACKWARD 4 (to 4) - 2:4 - 2:16 10 THROW 4 (to 14) (exc handler 7 - 10; stack: 1) - 2:4 - 2:16 12 JUMP_BACKWARD 6 (to 6) - 2:4 - 2:16 >> 14 POP_TOP - 2:4 - 2:16 15 LOAD_NONE - 2:4 - 2:16 16 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldPlain.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldPlain.co deleted file mode 100644 index b4f0996851..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldPlain.co +++ /dev/null @@ -1,14 +0,0 @@ -Disassembly of : - 1:0 - 2:9 0 MAKE_FUNCTION 0 (gen) - 1:0 - 2:9 3 STORE_NAME 0 (gen) - 1:0 - 2:9 5 LOAD_NONE - 1:0 - 2:9 6 RETURN_VALUE - -Disassembly of gen: -Flags: CO_GENERATOR - 2:4 - 2:9 0 LOAD_NONE - 2:4 - 2:9 1 YIELD_VALUE - 2:4 - 2:9 2 RESUME_YIELD - 2:4 - 2:9 3 POP_TOP - 2:4 - 2:9 4 LOAD_NONE - 2:4 - 2:9 5 RETURN_VALUE diff --git a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldValue.co b/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldValue.co deleted file mode 100644 index 4b6689a313..0000000000 --- a/graalpython/com.oracle.graal.python.test/testData/goldenFiles/CompilerTests/testYieldValue.co +++ /dev/null @@ -1,16 +0,0 @@ -Disassembly of : - 1:0 - 2:15 0 MAKE_FUNCTION 0 (gen) - 1:0 - 2:15 3 STORE_NAME 0 (gen) - 1:0 - 2:15 5 LOAD_NONE - 1:0 - 2:15 6 RETURN_VALUE - -Disassembly of gen: -Flags: CO_GENERATOR - 2:10 - 2:11 0 LOAD_FAST 0 (a) - 2:14 - 2:15 2 LOAD_BYTE 1 - 2:10 - 2:15 4 BINARY_OP 0 (ADD) generalizes: 2, 0 - 2:4 - 2:15 6 YIELD_VALUE - 2:4 - 2:15 7 RESUME_YIELD - 2:4 - 2:15 8 POP_TOP - 2:4 - 2:15 9 LOAD_NONE - 2:4 - 2:15 10 RETURN_VALUE From a2d19944455da50de6502d988f56b85975db8bcb Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:33:59 +0200 Subject: [PATCH 04/20] Remove manual bytecode interpreter --- .../micro/virtualize-in-try-catch-oom.py | 4 +- .../graal/python/shell/GraalPythonMain.java | 5 - .../oracle/graal/python/PythonLanguage.java | 25 +- .../builtins/modules/BuiltinFunctions.java | 9 +- .../modules/GraalPythonModuleBuiltins.java | 15 +- .../modules/MarshalModuleBuiltins.java | 116 +- .../builtins/modules/SysModuleBuiltins.java | 2 +- .../builtins/objects/asyncio/PAsyncGen.java | 13 +- .../builtins/objects/code/CodeBuiltins.java | 85 +- .../builtins/objects/code/CodeNodes.java | 29 +- .../python/builtins/objects/code/PCode.java | 85 +- .../python/builtins/objects/frame/PFrame.java | 53 +- .../generator/CommonGeneratorBuiltins.java | 63 +- .../objects/generator/GeneratorBuiltins.java | 42 +- .../objects/generator/PGenerator.java | 179 +- .../objects/module/PythonFrozenModule.java | 9 +- .../objects/superobject/SuperBuiltins.java | 50 +- .../objects/traceback/PTraceback.java | 9 +- .../objects/traceback/TracebackBuiltins.java | 8 +- .../oracle/graal/python/compiler/Block.java | 91 - .../graal/python/compiler/BlockInfo.java | 164 - .../python/compiler/BytecodeCodeUnit.java | 687 -- .../graal/python/compiler/CodeUnit.java | 18 +- .../python/compiler/CompilationUnit.java | 548 -- .../graal/python/compiler/Compiler.java | 4086 +---------- .../graal/python/compiler/Instruction.java | 104 - .../graal/python/compiler/SourceMap.java | 217 - .../graal/python/lib/PyObjectIsTrueNode.java | 4 +- .../oracle/graal/python/nodes/PGuards.java | 5 - .../nodes/bytecode/BytecodeFrameInfo.java | 99 - .../bytecode/GeneratorReturnException.java | 53 - .../nodes/bytecode/GeneratorYieldResult.java | 56 - .../nodes/bytecode/MakeFunctionNode.java | 138 - .../python/nodes/bytecode/OSRException.java | 56 - .../nodes/bytecode/OSRInterpreterState.java | 52 - .../PBytecodeGeneratorFunctionRootNode.java | 127 - .../bytecode/PBytecodeGeneratorRootNode.java | 229 - .../nodes/bytecode/PBytecodeRootNode.java | 6283 ----------------- .../instrumentation/InstrumentationRoot.java | 71 - .../InstrumentationRootImpl.java | 88 - .../InstrumentationSupport.java | 205 - .../InstrumentedBytecodeNode.java | 86 - .../InstrumentedBytecodeStatement.java | 63 - .../InstrumentedBytecodeStatementImpl.java | 82 - .../bytecode_dsl/PBytecodeDSLRootNode.java | 2 +- .../exception/TopLevelExceptionHandler.java | 14 - .../nodes/frame/GetFrameLocalsNode.java | 93 +- .../nodes/frame/MaterializeFrameNode.java | 113 +- .../python/nodes/frame/ReadFrameNode.java | 11 +- .../nodes/util/ExceptionStateNodes.java | 5 +- .../graal/python/runtime/AsyncHandler.java | 2 +- .../python/runtime/ExecutionContext.java | 10 +- .../graal/python/runtime/PythonContext.java | 8 +- .../graal/python/runtime/PythonOptions.java | 30 - .../runtime/exception/ExceptionUtils.java | 36 +- .../python/runtime/exception/PException.java | 38 +- .../runtime/interop/PythonLocalScope.java | 3 +- .../graal/python/runtime/object/PFactory.java | 23 - .../oracle/graal/python/util/PythonUtils.java | 8 +- 59 files changed, 288 insertions(+), 14521 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Block.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BlockInfo.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BytecodeCodeUnit.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Instruction.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BytecodeFrameInfo.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorReturnException.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorYieldResult.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRException.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRInterpreterState.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRoot.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRootImpl.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatement.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatementImpl.java diff --git a/graalpython/com.oracle.graal.python.benchmarks/python/micro/virtualize-in-try-catch-oom.py b/graalpython/com.oracle.graal.python.benchmarks/python/micro/virtualize-in-try-catch-oom.py index c26308c1c9..c7a6ef0f6e 100644 --- a/graalpython/com.oracle.graal.python.benchmarks/python/micro/virtualize-in-try-catch-oom.py +++ b/graalpython/com.oracle.graal.python.benchmarks/python/micro/virtualize-in-try-catch-oom.py @@ -1,4 +1,4 @@ -# Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2024, 2026, 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 @@ -47,7 +47,7 @@ # Note2: we want to catch OutOfMemoryError and translate it to Python MemoryError, # so that we can attach a precise location to it if possible, but we accept that # under some circumstances the compiler may move the allocation out of the try-catch -# and we will catch it elsewhere (probably the catch-all in PBytecodeRootNode) and +# and we will catch it elsewhere (probably the bytecode root catch-all) and # attach imprecise location to it. Alternative is to force the allocation using # CompilerDirectives.ensureAllocatedHere, which would, however, prevent any virtualization, # which is deemed a price to high to pay for a precise location of MemoryError. diff --git a/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java b/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java index 9b137e1fb2..fb3c33a6fe 100644 --- a/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java +++ b/graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java @@ -499,11 +499,6 @@ protected List preprocessArguments(List givenArgs, Map futureFeatures) { - Compiler compiler = new Compiler(parserCallbacks); - CompilationUnit cu = compiler.compile(mod, EnumSet.noneOf(Compiler.Flags.class), optimize, futureFeatures); - BytecodeCodeUnit co = cu.assemble(); - return PBytecodeRootNode.create(this, co, source, source.isInternal(), parserCallbacks); - } - private RootNode compileForBytecodeDSLInterpreter(ModTy mod, Source source, int optimize, ParserCallbacksImpl parserCallbacks, EnumSet futureFeatures) { BytecodeDSLCompilerResult result = BytecodeDSLCompiler.compile(this, mod, source, optimize, parserCallbacks, futureFeatures); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java index 6c287f845f..ef9024a6fe 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java @@ -223,7 +223,6 @@ import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode; import com.oracle.graal.python.nodes.builtins.ListNodes; import com.oracle.graal.python.nodes.builtins.ListNodes.ConstructListNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallDispatchers; import com.oracle.graal.python.nodes.call.CallNode; @@ -1105,12 +1104,8 @@ Object generic(VirtualFrame frame, Object wSource, Object wFilename, TruffleStri private static PCode wrapRootCallTarget(RootCallTarget rootCallTarget, TruffleString filename) { RootNode rootNode = rootCallTarget.getRootNode(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (rootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { - bytecodeDSLRootNode.triggerDeferredDeprecationWarnings(); - } - } else if (rootNode instanceof PBytecodeRootNode bytecodeRootNode) { - bytecodeRootNode.triggerDeferredDeprecationWarnings(); + if (rootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { + bytecodeDSLRootNode.triggerDeferredDeprecationWarnings(); } return PFactory.createCode(PythonLanguage.get(null), rootCallTarget, filename); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java index 81bb52d4a2..86da1f32da 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java @@ -146,7 +146,6 @@ import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.arrow.ArrowArray; import com.oracle.graal.python.nodes.arrow.ArrowSchema; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.classes.IsSubtypeNode; @@ -236,7 +235,7 @@ protected List> getNodeFa public void initialize(Python3Core core) { super.initialize(core); addBuiltinConstant("is_native", TruffleOptions.AOT); - addBuiltinConstant("is_bytecode_dsl_interpreter", PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER); + addBuiltinConstant("is_bytecode_dsl_interpreter", true); PythonContext ctx = core.getContext(); PythonLanguage language = ctx.getLanguage(); // Engine options: if they differ from the values baked into the pre-initialized context, @@ -821,11 +820,7 @@ public Object doIt(VirtualFrame frame, PFunction func, @TruffleBoundary public synchronized PFunction convertToBuiltin(PFunction func) { RootNode rootNode = func.getCode().getRootNode(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (rootNode instanceof PBytecodeDSLRootNode r) { - r.setPythonInternal(true); - } - } else if (rootNode instanceof PBytecodeRootNode r) { + if (rootNode instanceof PBytecodeDSLRootNode r) { r.setPythonInternal(true); } func.setBuiltin(true); @@ -839,11 +834,7 @@ public abstract static class BuiltinMethodNode extends PythonUnaryBuiltinNode { @Specialization public Object doIt(PFunction func) { RootNode rootNode = func.getCode().getRootNode(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (rootNode instanceof PBytecodeDSLRootNode r) { - r.setPythonInternal(true); - } - } else if (rootNode instanceof PBytecodeRootNode r) { + if (rootNode instanceof PBytecodeDSLRootNode r) { r.setPythonInternal(true); } return func; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java index bde7a6a0cb..f477b48de2 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java @@ -100,9 +100,7 @@ import com.oracle.graal.python.builtins.objects.str.PString; import com.oracle.graal.python.builtins.objects.str.StringNodes.IsInternedStringNode; import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.compiler.Compiler; import com.oracle.graal.python.lib.PyComplexCheckExactNode; import com.oracle.graal.python.lib.PyDictCheckExactNode; import com.oracle.graal.python.lib.PyFloatCheckExactNode; @@ -939,13 +937,8 @@ private void writeComplexObject(Object v, int flag) { } writeBytes(lnotab); } else if (v instanceof CodeUnit) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT | flag); - writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) v); - } else { - writeByte(TYPE_GRAALPYTHON_CODE_UNIT | flag); - writeBytecodeCodeUnit((BytecodeCodeUnit) v); - } + writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT | flag); + writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) v); } else if (v instanceof Source s) { writeByte(TYPE_DSL_SOURCE | flag); writeSource(s); @@ -1161,7 +1154,7 @@ private Object readObject(int type, AddRefAndReturn addRef) throws NumberFormatE case TYPE_GRAALPYTHON_CODE: return addRef.run(readCode()); case TYPE_GRAALPYTHON_CODE_UNIT: - return addRef.run(readBytecodeCodeUnit()); + return addRef.run(readRemovedCodeUnitPayload()); case TYPE_GRAALPYTHON_DSL_CODE_UNIT: return addRef.run(readBytecodeDSLCodeUnit()); case TYPE_DSL_SOURCE: @@ -1352,67 +1345,19 @@ private Object[] readObjectArray() { private CodeUnit readCodeUnit() { int codeUnitType = readByte(); return switch (codeUnitType) { - case TYPE_GRAALPYTHON_CODE_UNIT -> readBytecodeCodeUnit(); + case TYPE_GRAALPYTHON_CODE_UNIT -> readRemovedCodeUnitPayload(); case TYPE_GRAALPYTHON_DSL_CODE_UNIT -> readBytecodeDSLCodeUnit(); default -> throw CompilerDirectives.shouldNotReachHere(); }; } - private BytecodeCodeUnit readBytecodeCodeUnit() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - throw new MarshalError(ValueError, - PythonUtils.tsLiteral( - "Attempted to deserialize a code object from the manual bytecode interpreter, but the DSL interpreter is enabled. Consider clearing or setting a different pycache folder.")); - } - - int fileVersion = readByte(); - if (fileVersion != Compiler.BYTECODE_VERSION) { - throw new MarshalError(ValueError, ErrorMessages.BYTECODE_VERSION_MISMATCH, Compiler.BYTECODE_VERSION, fileVersion); - } - TruffleString name = readString(true); - TruffleString qualname = readString(true); - int argCount = readInt(); - int kwOnlyArgCount = readInt(); - int positionalOnlyArgCount = readInt(); - int stacksize = readInt(); - byte[] code = readBytes(); - byte[] srcOffsetTable = readBytes(); - int flags = readInt(); - TruffleString[] names = readStringArray(true); - TruffleString[] varnames = readStringArray(true); - TruffleString[] cellvars = readStringArray(true); - TruffleString[] freevars = readStringArray(true); - int[] cell2arg = readIntArray(); - if (cell2arg.length == 0) { - cell2arg = null; - } - Object[] constants = readObjectArray(); - long[] primitiveConstants = readLongArray(); - int[] exceptionHandlerRanges = readIntArray(); - int conditionProfileCount = readInt(); - int startLine = readInt(); - int startColumn = readInt(); - int endLine = readInt(); - int endColumn = readInt(); - byte[] variableShouldUnbox = readBytes(); - int[] generalizeInputsKeys = readIntArray(); - int[] generalizeInputsIndices = readIntArray(); - int[] generalizeInputsValues = readIntArray(); - int[] generalizeVarsIndices = readIntArray(); - int[] generalizeVarsValues = readIntArray(); - return new BytecodeCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, - cellvars, freevars, cell2arg, constants, startLine, startColumn, endLine, endColumn, code, srcOffsetTable, - primitiveConstants, exceptionHandlerRanges, stacksize, conditionProfileCount, - variableShouldUnbox, generalizeInputsKeys, generalizeInputsIndices, generalizeInputsValues, generalizeVarsIndices, generalizeVarsValues); + private CodeUnit readRemovedCodeUnitPayload() { + throw new MarshalError(ValueError, + PythonUtils.tsLiteral( + "Attempted to deserialize a code object from the removed legacy bytecode interpreter. Consider clearing or setting a different pycache folder.")); } private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() { - if (!PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - throw new MarshalError(ValueError, - PythonUtils.tsLiteral( - "Attempted to deserialize a code object from the Bytecode DSL interpreter, but the manual interpreter is enabled. Consider clearing or setting a different pycache folder.")); - } - int bytecodeSize = readSize(); int bytecodeOffset = -1; if (in instanceof ByteBufferDataInput bufferIn) { @@ -1450,49 +1395,8 @@ private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() { } private void writeCodeUnit(CodeUnit code) throws IOException { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT); - writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) code); - } else { - writeByte(TYPE_GRAALPYTHON_CODE_UNIT); - writeBytecodeCodeUnit((BytecodeCodeUnit) code); - } - } - - private void writeBytecodeCodeUnit(BytecodeCodeUnit code) throws IOException { - writeByte(Compiler.BYTECODE_VERSION); - writeString(code.name); - writeString(code.qualname); - writeInt(code.argCount); - writeInt(code.kwOnlyArgCount); - writeInt(code.positionalOnlyArgCount); - writeInt(code.stacksize); - writeBytes(code.code); - writeBytes(code.srcOffsetTable); - writeInt(code.flags); - writeStringArray(code.names); - writeStringArray(code.varnames); - writeStringArray(code.cellvars); - writeStringArray(code.freevars); - if (code.cell2arg != null) { - writeIntArray(code.cell2arg); - } else { - writeIntArray(PythonUtils.EMPTY_INT_ARRAY); - } - writeObjectArray(code.constants); - writeLongArray(code.primitiveConstants); - writeIntArray(code.exceptionHandlerRanges); - writeInt(code.conditionProfileCount); - writeInt(code.startLine); - writeInt(code.startColumn); - writeInt(code.endLine); - writeInt(code.endColumn); - writeBytes(code.variableShouldUnbox); - writeIntArray(code.generalizeInputsKeys); - writeIntArray(code.generalizeInputsIndices); - writeIntArray(code.generalizeInputsValues); - writeIntArray(code.generalizeVarsIndices); - writeIntArray(code.generalizeVarsValues); + writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT); + writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) code); } private void writeBytecodeDSLCodeUnit(BytecodeDSLCodeUnit code) throws IOException { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java index 49272e8fd8..7eddea3b60 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java @@ -635,7 +635,7 @@ public void postInitialize0(Python3Core core) { } sys.setAttribute(tsInternedLiteral("dont_write_bytecode"), context.getOption(PythonOptions.DontWriteBytecodeFlag)); TruffleString pycachePrefix = context.getOption(PythonOptions.PyCachePrefix); - if (pycachePrefix.isEmpty() && PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && System.getenv("GRAALPY_BYTECODE_DSL_PYTHONPYCACHEPREFIX") != null) { + if (pycachePrefix.isEmpty() && System.getenv("GRAALPY_BYTECODE_DSL_PYTHONPYCACHEPREFIX") != null) { pycachePrefix = PythonUtils.toTruffleStringUncached(System.getenv("GRAALPY_BYTECODE_DSL_PYTHONPYCACHEPREFIX")); } sys.setAttribute(tsInternedLiteral("pycache_prefix"), pycachePrefix.isEmpty() ? PNone.NONE : pycachePrefix); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java index 32cd3d0b31..081ed1d10a 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, 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 @@ -44,9 +44,7 @@ import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; -import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.bytecode.ContinuationRootNode; import com.oracle.truffle.api.frame.MaterializedFrame; @@ -55,15 +53,6 @@ public final class PAsyncGen extends PGenerator { private boolean hookCalled = false; private boolean runningAsync = false; - public static PAsyncGen create(PythonLanguage lang, PFunction function, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) { - MaterializedFrame generatorFrame = rootNode.createGeneratorFrame(arguments); - return new PAsyncGen(lang, function, generatorFrame, rootNode, callTargets); - } - - private PAsyncGen(PythonLanguage lang, PFunction function, MaterializedFrame generatorFrame, PBytecodeRootNode rootNode, RootCallTarget[] callTargets) { - super(lang, function, generatorFrame, PythonBuiltinClassType.PAsyncGenerator, new BytecodeState(rootNode, callTargets)); - } - public PAsyncGen(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { super(language, function, continuationFrame, PythonBuiltinClassType.PAsyncGenerator, new BytecodeDSLState(rootNode, continuationFrame.getArguments(), continuationRootNode)); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java index dbf62ab8f0..5339860227 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java @@ -57,10 +57,7 @@ import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotHashFun.HashBuiltinNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotRichCompare.RichCmpBuiltinNode; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.compiler.OpCodes; -import com.oracle.graal.python.compiler.SourceMap; import com.oracle.graal.python.lib.PyBytesCheckNode; import com.oracle.graal.python.lib.PyObjectGetIter; import com.oracle.graal.python.lib.PyObjectHashNode; @@ -77,7 +74,6 @@ import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider; import com.oracle.graal.python.nodes.util.CastToTruffleStringNode; import com.oracle.graal.python.runtime.IndirectCallData.InteropCallData; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.util.PythonUtils; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -391,28 +387,9 @@ static Object lines(PCode self) { PTuple tuple; CodeUnit co = self.getCodeUnit(); if (co != null) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); - List lines = computeLinesForBytecodeDSLInterpreter(rootNode); - tuple = PFactory.createTuple(language, lines.toArray()); - } else { - BytecodeCodeUnit bytecodeCo = (BytecodeCodeUnit) co; - SourceMap map = bytecodeCo.getSourceMap(); - List lines = new ArrayList<>(); - if (map != null && map.startLineMap.length > 0) { - IteratorData data = new IteratorData(); - data.line = map.startLineMap[0]; - bytecodeCo.iterateBytecode((int bci, OpCodes op, int oparg, byte[] followingArgs) -> { - int nextStart = bci + op.length(); - if (map.startLineMap[bci] != data.line || nextStart == bytecodeCo.code.length) { - lines.add(PFactory.createTuple(language, new int[]{data.start, nextStart, data.line})); - data.line = map.startLineMap[bci]; - data.start = nextStart; - } - }); - } - tuple = PFactory.createTuple(language, lines.toArray()); - } + PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); + List lines = computeLinesForBytecodeDSLInterpreter(rootNode); + tuple = PFactory.createTuple(language, lines.toArray()); } else { tuple = PFactory.createEmptyTuple(language); } @@ -517,41 +494,29 @@ Object positions(PCode self) { CodeUnit co = self.getCodeUnit(); if (co != null) { List lines = new ArrayList<>(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); - BytecodeNode bytecodeNode = rootNode.getBytecodeNode(); - if (!bytecodeNode.hasSourceInformation()) { - bytecodeNode = bytecodeNode.ensureSourceInformation(); - } - for (Instruction instruction : bytecodeNode.getInstructions()) { - if (instruction.isInstrumentation()) { - // Skip instrumented instructions. The co_positions array should agree - // with the logical instruction index. - continue; - } - SourceSection section = rootNode.getSourceSectionForLocation(instruction.getLocation()); - if (section != null) { - lines.add(PFactory.createTuple(language, new int[]{ - section.getStartLine(), - section.getEndLine(), - // 1-based inclusive to 0-based inclusive - section.getStartColumn() - 1, - // 1-based inclusive to 0-based exclusive (-1 + 1 = 0) - section.getEndColumn() - })); - } else { - lines.add(PFactory.createTuple(language, new Object[]{PNone.NONE, PNone.NONE, PNone.NONE, PNone.NONE})); - } + PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); + BytecodeNode bytecodeNode = rootNode.getBytecodeNode(); + if (!bytecodeNode.hasSourceInformation()) { + bytecodeNode = bytecodeNode.ensureSourceInformation(); + } + for (Instruction instruction : bytecodeNode.getInstructions()) { + if (instruction.isInstrumentation()) { + // Skip instrumented instructions. The co_positions array should agree + // with the logical instruction index. + continue; } - } else { - BytecodeCodeUnit bytecodeCo = (BytecodeCodeUnit) co; - SourceMap map = bytecodeCo.getSourceMap(); - if (map != null && map.startLineMap.length > 0) { - byte[] bytecode = bytecodeCo.code; - for (int i = 0; i < bytecode.length;) { - lines.add(PFactory.createTuple(language, new int[]{map.startLineMap[i], map.endLineMap[i], map.startColumnMap[i], map.endColumnMap[i]})); - i += OpCodes.fromOpCode(bytecode[i]).length(); - } + SourceSection section = rootNode.getSourceSectionForLocation(instruction.getLocation()); + if (section != null) { + lines.add(PFactory.createTuple(language, new int[]{ + section.getStartLine(), + section.getEndLine(), + // 1-based inclusive to 0-based inclusive + section.getStartColumn() - 1, + // 1-based inclusive to 0-based exclusive (-1 + 1 = 0) + section.getEndColumn() + })); + } else { + lines.add(PFactory.createTuple(language, new Object[]{PNone.NONE, PNone.NONE, PNone.NONE, PNone.NONE})); } } tuple = PFactory.createTuple(language, lines.toArray()); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java index 5eacf40c31..c3fc35edc2 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java @@ -46,18 +46,14 @@ import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.nodes.PNodeWithContext; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorFunctionRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.util.BadOPCodeNode; import com.oracle.graal.python.runtime.ExecutionContext.BoundaryCallContext; import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.util.PythonUtils; import com.oracle.truffle.api.CompilerAsserts; @@ -176,28 +172,11 @@ private static PRootNode deserializeForBytecodeInterpreter(PythonLanguage langua CodeUnit codeUnit = MarshalModuleBuiltins.deserializeCodeUnit(null, language, data); RootNode rootNode; - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) codeUnit; - if (code.flags != flags) { - code = code.withFlags(flags); - } - rootNode = code.createRootNode(language, false); - } else { - BytecodeCodeUnit code = (BytecodeCodeUnit) codeUnit; - if (cellvars != null && !Arrays.equals(code.cellvars, cellvars) || freevars != null && !Arrays.equals(code.freevars, freevars) || flags != code.flags) { - code = new BytecodeCodeUnit(code.name, code.qualname, code.argCount, code.kwOnlyArgCount, code.positionalOnlyArgCount, flags, code.names, - code.varnames, cellvars != null ? cellvars : code.cellvars, freevars != null ? freevars : code.freevars, code.cell2arg, - code.constants, code.startLine, - code.startColumn, code.endLine, code.endColumn, code.code, code.srcOffsetTable, - code.primitiveConstants, code.exceptionHandlerRanges, code.stacksize, code.conditionProfileCount, - code.variableShouldUnbox, - code.generalizeInputsKeys, code.generalizeInputsIndices, code.generalizeInputsValues, code.generalizeVarsIndices, code.generalizeVarsValues); - } - rootNode = PBytecodeRootNode.create(language, code, PythonUtils.createFakeSource(), false); - if (code.isGeneratorOrCoroutine()) { - rootNode = new PBytecodeGeneratorFunctionRootNode(language, rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name); - } + BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) codeUnit; + if (code.flags != flags) { + code = code.withFlags(flags); } + rootNode = code.createRootNode(language, false); return (PRootNode) rootNode; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java index 084f871177..e596ca97a7 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java @@ -53,17 +53,12 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; import com.oracle.graal.python.builtins.objects.tuple.PTuple; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorFunctionRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.object.IsForeignObjectNode; import com.oracle.graal.python.runtime.GilNode; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage; import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage; @@ -236,15 +231,6 @@ private static TruffleString extractName(RootNode rootNode) { @TruffleBoundary private static int extractStackSize(RootNode rootNode) { RootNode funcRootNode = rootNodeForExtraction(rootNode); - if (funcRootNode instanceof PBytecodeRootNode bytecodeRootNode) { - BytecodeCodeUnit code = bytecodeRootNode.getCodeUnit(); - return code.stacksize + code.varnames.length + code.cellvars.length + code.freevars.length; - } - /* - * NB: This fallback case includes PBytecodeDSLRootNode. The Bytecode DSL stack does not - * mirror a CPython stack (it's an operand stack for its own instruction set), so the frame - * size is our best estimate. - */ return funcRootNode.getFrameDescriptor().getNumberOfSlots(); } @@ -287,17 +273,7 @@ private static TruffleString[] extractNames(RootNode node) { private static RootNode rootNodeForExtraction(RootNode rootNodeArg) { RootNode rootNode = PythonLanguage.unwrapRootNode(rootNodeArg); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return PGenerator.unwrapContinuationRoot(rootNode); - } else { - if (rootNode instanceof PBytecodeGeneratorFunctionRootNode generatorFunctionRootNode) { - return generatorFunctionRootNode.getBytecodeRootNode(); - } - if (rootNode instanceof PBytecodeGeneratorRootNode generatorRootNode) { - return generatorRootNode.getBytecodeRootNode(); - } - return rootNode; - } + return PGenerator.unwrapContinuationRoot(rootNode); } @TruffleBoundary @@ -312,12 +288,8 @@ private static int extractFlags(RootNode node) { private static CodeUnit getCodeUnit(RootNode node) { RootNode rootNode = rootNodeForExtraction(node); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (rootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { - return bytecodeDSLRootNode.getCodeUnit(); - } - } else if (rootNode instanceof PBytecodeRootNode bytecodeRootNode) { - return bytecodeRootNode.getCodeUnit(); + if (rootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { + return bytecodeDSLRootNode.getCodeUnit(); } return null; } @@ -379,13 +351,9 @@ public int getFirstLineNo() { @TruffleBoundary public int lastiToLine(int lasti) { RootNode funcRootNode = rootNodeForExtraction(getRootNode()); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (funcRootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { - BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode(); - return bytecodeDSLRootNode.bciToLine(PBytecodeDSLRootNode.lastiToBci(lasti, bytecodeNode), bytecodeNode); - } - } else if (funcRootNode instanceof PBytecodeRootNode bytecodeRootNode) { - return bytecodeRootNode.bciToLine(bytecodeRootNode.lastiToBci(lasti)); + if (funcRootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { + BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode(); + return bytecodeDSLRootNode.bciToLine(PBytecodeDSLRootNode.lastiToBci(lasti, bytecodeNode), bytecodeNode); } return -1; } @@ -484,41 +452,13 @@ private PCode createCode(BytecodeDSLCodeUnit codeUnit) { return PFactory.createCode(language, rN, rN.getSignature(), codeUnit, getFilename()); } - public PCode getOrCreateChildCode(int index, BytecodeCodeUnit codeUnit) { - Object[] cachedConstants = ensureConstants(); - PCode code = (PCode) cachedConstants[index]; - if (code == null) { - code = createCode(codeUnit); - cachedConstants[index] = code; - } - return code; - } - - @TruffleBoundary - private PCode createCode(BytecodeCodeUnit codeUnit) { - PBytecodeRootNode outerRootNode = (PBytecodeRootNode) getRootNodeForExtraction(); - PythonLanguage language = outerRootNode.getLanguage(); - PRootNode executableRootNode = language.createCachedRootNode( - l -> (PRootNode) PBytecodeRootNode.createMaybeGenerator(language, codeUnit, outerRootNode.getSource(), outerRootNode.isInternal()), codeUnit); - RootNode rN = executableRootNode; - if (executableRootNode instanceof PBytecodeGeneratorFunctionRootNode generatorRoot) { - rN = generatorRoot.getBytecodeRootNode(); - } - return PFactory.createCode(language, executableRootNode, ((PBytecodeRootNode) rN).getSignature(), codeUnit, getFilename()); - } - @TruffleBoundary private Object convertConstantToPythonSpace(int index) { Object o = getCodeUnit().constants[index]; PythonLanguage language = PythonLanguage.get(null); if (o instanceof CodeUnit) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) o; - return getOrCreateChildCode(index, code); - } else { - BytecodeCodeUnit code = (BytecodeCodeUnit) o; - return getOrCreateChildCode(index, code); - } + BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) o; + return getOrCreateChildCode(index, code); } else if (o instanceof BigInteger) { return PFactory.createInt(language, (BigInteger) o); } else if (o instanceof int[]) { @@ -654,15 +594,8 @@ public String toString() { @TruffleBoundary public String toDisassembledString(boolean quickened) { RootNode rN = getRootNode(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && rN instanceof PBytecodeDSLRootNode dslRoot) { + if (rN instanceof PBytecodeDSLRootNode dslRoot) { return dslRoot.getCodeUnit().toString(quickened, dslRoot); - } else if (rN instanceof PBytecodeGeneratorRootNode r) { - rN = r.getBytecodeRootNode(); - } else if (rN instanceof PBytecodeGeneratorFunctionRootNode r) { - rN = r.getBytecodeRootNode(); - } - if (rN instanceof PBytecodeRootNode bytecodeRootNode) { - return bytecodeRootNode.getCodeUnit().toString(quickened, bytecodeRootNode); } return J_EMPTY_STRING; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java index cf04a9fc5c..f0ff1569db 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java @@ -47,19 +47,14 @@ import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; import com.oracle.graal.python.builtins.objects.object.PythonObject; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode; -import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; import com.oracle.graal.python.nodes.frame.ReadFrameNode; import com.oracle.graal.python.runtime.CallerFlags; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.bytecode.BytecodeFrame; import com.oracle.truffle.api.bytecode.BytecodeNode; -import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; @@ -67,11 +62,6 @@ public final class PFrame extends PythonBuiltinObject { private static final int UNINITIALIZED_LINE = -2; - /** - * The manual interpreter exclusively uses this field, and the Bytecode DSL interpreter - * exclusively uses the {@link #bytecodeFrame} field. - */ - private MaterializedFrame locals; private BytecodeFrame bytecodeFrame; /** @@ -85,8 +75,7 @@ public final class PFrame extends PythonBuiltinObject { private final Reference virtualFrameInfo; private final Thread thread; /** - * For the manual bytecode interpreter the location can be the {@link PBytecodeRootNode} itself, - * but for the Bytecode DSL interpreter, the location must be an AST node connected to the + * The location must be an AST node connected to the * {@link BytecodeNode} that was executed at the time when the BCI was captured. */ private Node location; @@ -238,22 +227,6 @@ public PFrame(PythonLanguage lang, @SuppressWarnings("unused") long threadState, this.thread = null; } - /** - * Get the locals synced by {@link MaterializeFrameNode}. May be null when using custom locals. - * In most cases, you should use {@link GetFrameLocalsNode}. - */ - public MaterializedFrame getLocals() { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; - assert CallerFlags.needsLocals(lastCallerFlags) : "Missing frame locals sync"; - return locals; - } - - public void setLocals(MaterializedFrame locals) { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; - lastCallerFlags |= CallerFlags.NEEDS_LOCALS; - this.locals = locals; - } - /** * Get the locals synced by {@link BytecodeFrame}. May be null when using custom locals, but * null may also indicate that the locals were just not synced yet. Use @@ -261,12 +234,12 @@ public void setLocals(MaterializedFrame locals) { * you should use {@link GetFrameLocalsNode} instead of this method. */ public BytecodeFrame getBytecodeFrame() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; + assert true; return bytecodeFrame; } public void setBytecodeFrame(BytecodeFrame bytecodeFrame) { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; + assert true; this.bytecodeFrame = bytecodeFrame; } @@ -302,7 +275,7 @@ public boolean outdatedCallerFlags(int callerFlags) { // Custom locals don't need locals sync callerFlags &= ~CallerFlags.NEEDS_LOCALS; } - if (CallerFlags.needsLocals(callerFlags) && locals == null && bytecodeFrame == null) { + if (CallerFlags.needsLocals(callerFlags) && bytecodeFrame == null) { return true; } return (callerFlags & lastCallerFlags) != callerFlags; @@ -367,13 +340,11 @@ public int getLine() { if (line == UNINITIALIZED_LINE) { if (location == null) { line = -1; - } else if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { + } else { if (location instanceof BytecodeNode bytecodeNode) { PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) bytecodeNode.getRootNode(); return rootNode.bciToLine(getBci(), bytecodeNode); } - } else if (location instanceof PBytecodeRootNode bytecodeRootNode) { - return bytecodeRootNode.bciToLine(getBci()); } } return line; @@ -410,7 +381,7 @@ public Node getLocation() { } public BytecodeNode getBytecodeNode() { - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER ? BytecodeNode.get(location) : null; + return BytecodeNode.get(location); } public int getBci() { @@ -429,16 +400,8 @@ public int getLasti() { @TruffleBoundary public static int bciToLasti(int bci, Node location) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) { - return PBytecodeDSLRootNode.bciToLasti(bci, bytecodeNode); - } - } else { - if (location instanceof PBytecodeRootNode bytecodeRootNode) { - return bytecodeRootNode.bciToLasti(bci); - } else if (location instanceof PBytecodeGeneratorRootNode generatorRootNode) { - return generatorRootNode.getBytecodeRootNode().bciToLasti(bci); - } + if (bci >= 0 && location instanceof BytecodeNode bytecodeNode) { + return PBytecodeDSLRootNode.bciToLasti(bci, bytecodeNode); } return -1; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java index 59400c4693..043cb9310d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java @@ -66,14 +66,10 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.TpIterNextBuiltin; import com.oracle.graal.python.lib.IteratorExhausted; import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PGuards; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.PRootNode; import com.oracle.graal.python.nodes.bytecode.FrameInfo; -import com.oracle.graal.python.nodes.bytecode.GeneratorReturnException; -import com.oracle.graal.python.nodes.bytecode.GeneratorYieldResult; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; -import com.oracle.graal.python.nodes.call.CallDispatchers; import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; @@ -134,34 +130,11 @@ private static void checkResumable(Node inliningTarget, PGenerator self, PRaiseN @GenerateInline @GenerateCached(false) - @ImportStatic({PGuards.class, PythonOptions.class, CallDispatchers.class}) + @ImportStatic(PythonOptions.class) abstract static class ResumeGeneratorNode extends Node { public abstract Object execute(VirtualFrame frame, Node inliningTarget, PGenerator self, Object sendValue); - @Specialization(guards = {"!isBytecodeDSLInterpreter()", "sameCallTarget(self.getCurrentCallTarget(), callNode)"}, limit = "getCallSiteInlineCacheMaxDepth()") - static Object cached(VirtualFrame frame, Node inliningTarget, PGenerator self, Object sendValue, - @Cached(parameters = "self.getCurrentCallTarget()") DirectCallNode callNode, - @Exclusive @Cached CallDispatchers.SimpleDirectInvokeNode invoke, - @Exclusive @Cached InlinedBranchProfile returnProfile, - @Exclusive @Cached IsBuiltinObjectProfile errorProfile, - @Exclusive @Cached PRaiseNode raiseNode) { - self.setRunning(true); - Object[] arguments = self.getCallArguments(sendValue); - GeneratorYieldResult result; - try { - result = (GeneratorYieldResult) invoke.execute(frame, inliningTarget, callNode, arguments); - } catch (PException e) { - throw handleException(self, inliningTarget, errorProfile, raiseNode, e); - } catch (GeneratorReturnException e) { - returnProfile.enter(inliningTarget); - throw handleReturn(inliningTarget, self, e.value); - } finally { - self.setRunning(false); - } - return handleResult(inliningTarget, self, result); - } - - @Specialization(guards = {"isBytecodeDSLInterpreter()", "self.getBytecodeDSLContinuationRootNode() == continuationRootNode"}, limit = "getCallSiteInlineCacheMaxDepth()") + @Specialization(guards = "self.getBytecodeDSLContinuationRootNode() == continuationRootNode", limit = "getCallSiteInlineCacheMaxDepth()") static Object cachedBytecodeDSL(VirtualFrame frame, Node inliningTarget, PGenerator self, Object sendValue, @Cached("self.getBytecodeDSLContinuationRootNode()") ContinuationRootNode continuationRootNode, @Cached(parameters = "self.getCurrentCallTarget()") DirectCallNode callNode, @@ -218,30 +191,7 @@ static Object cachedBytecodeDSL(VirtualFrame frame, Node inliningTarget, PGenera } - @Specialization(replaces = "cached", guards = "!isBytecodeDSLInterpreter()") - @Megamorphic - static Object generic(VirtualFrame frame, Node inliningTarget, PGenerator self, Object sendValue, - @Exclusive @Cached CallDispatchers.SimpleIndirectInvokeNode invoke, - @Exclusive @Cached InlinedBranchProfile returnProfile, - @Exclusive @Cached IsBuiltinObjectProfile errorProfile, - @Exclusive @Cached PRaiseNode raiseNode) { - self.setRunning(true); - Object[] arguments = self.getCallArguments(sendValue); - GeneratorYieldResult result; - try { - result = (GeneratorYieldResult) invoke.execute(frame, inliningTarget, self.getCurrentCallTarget(), arguments); - } catch (PException e) { - throw handleException(self, inliningTarget, errorProfile, raiseNode, e); - } catch (GeneratorReturnException e) { - returnProfile.enter(inliningTarget); - throw handleReturn(inliningTarget, self, e.value); - } finally { - self.setRunning(false); - } - return handleResult(inliningTarget, self, result); - } - - @Specialization(replaces = "cachedBytecodeDSL", guards = "isBytecodeDSLInterpreter()") + @Specialization(replaces = "cachedBytecodeDSL") @Megamorphic static Object genericBytecodeDSL(VirtualFrame frame, Node inliningTarget, PGenerator self, Object sendValue, @Exclusive @Cached ExecutionContext.CallContext callContext, @@ -396,13 +346,8 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object // Instead, we throw the exception here and fake entering the generator by adding // its frame to the traceback manually. self.markAsFinished(); - Node location; RootNode rootNode = self.getCurrentCallTarget().getRootNode(); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - location = ((PBytecodeDSLRootNode) self.getRootNode()).getBytecodeNode(); - } else { - location = rootNode; - } + Node location = ((PBytecodeDSLRootNode) self.getRootNode()).getBytecodeNode(); MaterializedFrame generatorFrame = self.getGeneratorFrame(); PFrame.Reference ref = new PFrame.Reference(rootNode, PFrame.Reference.EMPTY); PFrame pFrame = MaterializeFrameNode.materializeGeneratorFrame(PythonLanguage.get(inliningTarget), location, generatorFrame, self.getGeneratorFunction(), self.getGlobals(), ref); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java index 807750f148..bb311fb455 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java @@ -52,7 +52,6 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.TpIterNextBuiltin; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; import com.oracle.graal.python.nodes.frame.ReadFrameNode; @@ -60,7 +59,6 @@ import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode; import com.oracle.graal.python.runtime.CallerFlags; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.bytecode.BytecodeLocation; import com.oracle.truffle.api.dsl.Bind; @@ -201,35 +199,19 @@ static Object getFrame(VirtualFrame frame, PGenerator self, // If it's escaped, we synced at every exit return pyFrame; } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) generatorFrame.getFrameDescriptor().getInfo(); - if (pyFrame == null) { - pyFrame = MaterializeFrameNode.materializeGeneratorFrame(PythonLanguage.get(readFrameNode), self.getBytecodeNode(), generatorFrame, self.getGeneratorFunction(), - self.getGlobals(), currentRef); - } - BytecodeLocation location = self.getCurrentLocation(); - if (location != null) { - pyFrame.setBci(location.getBytecodeIndex()); - pyFrame.setLocation(location.getBytecodeNode()); - pyFrame.resetLine(); - } else { - pyFrame.setBci(0); - pyFrame.setLine(info.getRootNode().getFirstLineno()); - } + BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) generatorFrame.getFrameDescriptor().getInfo(); + if (pyFrame == null) { + pyFrame = MaterializeFrameNode.materializeGeneratorFrame(PythonLanguage.get(readFrameNode), self.getBytecodeNode(), generatorFrame, self.getGeneratorFunction(), + self.getGlobals(), currentRef); + } + BytecodeLocation location = self.getCurrentLocation(); + if (location != null) { + pyFrame.setBci(location.getBytecodeIndex()); + pyFrame.setLocation(location.getBytecodeNode()); + pyFrame.resetLine(); } else { - BytecodeFrameInfo info = (BytecodeFrameInfo) generatorFrame.getFrameDescriptor().getInfo(); - if (pyFrame == null) { - pyFrame = MaterializeFrameNode.materializeGeneratorFrame(PythonLanguage.get(readFrameNode), info.getRootNode(), generatorFrame, self.getGeneratorFunction(), self.getGlobals(), - currentRef); - } - int bci = self.getBci(); - if (bci >= 0) { - pyFrame.setBci(bci); - pyFrame.resetLine(); - } else { - pyFrame.setBci(0); - pyFrame.setLine(info.getRootNode().getFirstLineno()); - } + pyFrame.setBci(0); + pyFrame.setLine(info.getRootNode().getFirstLineno()); } pyFrame.setLastCallerFlags(CallerFlags.ALL_FRAME_FLAGS); assert currentRef.getPyFrame() == pyFrame; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java index c1366dd488..7e60088b0d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java @@ -34,16 +34,9 @@ import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo; import com.oracle.graal.python.nodes.bytecode.FrameInfo; -import com.oracle.graal.python.nodes.bytecode.GeneratorYieldResult; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; -import com.oracle.graal.python.runtime.PythonOptions; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.RootCallTarget; import com.oracle.truffle.api.TruffleStackTraceElement; import com.oracle.truffle.api.bytecode.BytecodeLocation; @@ -71,50 +64,6 @@ public class PGenerator extends PythonBuiltinObject { private final PythonObject globals; private final PFunction generatorFunction; - // TODO (GR-38700): remove BytecodeState after migrated to the Bytecode DSL interpreter. - protected static class BytecodeState { - private final PBytecodeRootNode rootNode; - - /** - * Call targets with copies of the generator's AST. Each call target corresponds to one - * possible entry point into the generator: the first call, and continuation for each yield. - * Each AST can then specialize towards which nodes are executed when starting from that - * particular entry point. When yielding, the next index to the next call target to continue - * from is updated via {@link #handleResult}. - *

- * The owner of this array is really the - * {@link com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorFunctionRootNode}. Every - * {@link PGenerator} instance representing the same generator on AST level gets reference - * to the same array with call targets. - */ - @CompilationFinal(dimensions = 1) private final RootCallTarget[] callTargets; - private int currentCallTarget; - - public BytecodeState(PBytecodeRootNode rootNode, RootCallTarget[] callTargets) { - this.rootNode = rootNode; - this.callTargets = callTargets; - this.currentCallTarget = 0; - } - - public RootCallTarget getCurrentCallTarget() { - return callTargets[currentCallTarget]; - } - - public PBytecodeGeneratorRootNode getCurrentRootNode() { - return (PBytecodeGeneratorRootNode) getCurrentCallTarget().getRootNode(); - } - - public Object handleResult(PythonLanguage language, GeneratorYieldResult result) { - currentCallTarget = result.resumeBci; - if (callTargets[currentCallTarget] == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - PBytecodeGeneratorRootNode generatorRootNode = new PBytecodeGeneratorRootNode(language, rootNode, result.resumeBci, result.resumeStackTop); - callTargets[currentCallTarget] = generatorRootNode.getCallTarget(); - } - return result.yieldValue; - } - } - public static class BytecodeDSLState { private final PBytecodeDSLRootNode rootNode; private final Object[] arguments; @@ -139,22 +88,10 @@ public Object handleResult(PGenerator generator, ContinuationResult result) { } } - // This is either BytecodeState or BytecodeDSLState. - private final Object state; - - private BytecodeState getBytecodeState() { - return (BytecodeState) state; - } + private final BytecodeDSLState state; private BytecodeDSLState getBytecodeDSLState() { - return (BytecodeDSLState) state; - } - - public static PGenerator create(PythonLanguage lang, PFunction function, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments, - PythonBuiltinClassType cls) { - // note: also done in PAsyncGen.create - MaterializedFrame generatorFrame = rootNode.createGeneratorFrame(arguments); - return new PGenerator(lang, function, generatorFrame, cls, new BytecodeState(rootNode, callTargets)); + return state; } public static PGenerator create(PythonLanguage lang, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, @@ -162,7 +99,7 @@ public static PGenerator create(PythonLanguage lang, PFunction function, PByteco return new PGenerator(lang, function, continuationFrame, cls, new BytecodeDSLState(rootNode, arguments, continuationRootNode)); } - protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame frame, PythonBuiltinClassType cls, Object state) { + protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame frame, PythonBuiltinClassType cls, BytecodeDSLState state) { super(cls, cls.getInstanceShape(lang)); this.name = function.getName(); this.qualname = function.getQualname(); @@ -170,33 +107,16 @@ protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame this.generatorFunction = function; this.frame = frame; this.finished = false; - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeDSLState bytecodeDSLState = (BytecodeDSLState) state; - this.state = state; - this.frameInfo = (BytecodeDSLFrameInfo) bytecodeDSLState.rootNode.getFrameDescriptor().getInfo(); - } else { - BytecodeState bytecodeState = (BytecodeState) state; - this.state = state; - this.frameInfo = (BytecodeFrameInfo) bytecodeState.rootNode.getFrameDescriptor().getInfo(); - } + this.state = state; + this.frameInfo = (BytecodeDSLFrameInfo) state.rootNode.getFrameDescriptor().getInfo(); } public Object[] getCallArguments(Object sendValue) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - prepareResume(); - return getBytecodeDSLState().arguments; - } else { - Object[] arguments = PArguments.create(2); - PArguments.setGlobals(arguments, globals); - PArguments.setFunctionObject(arguments, generatorFunction); - PArguments.setArgument(arguments, 0, frame); - PArguments.setArgument(arguments, 1, sendValue); - return arguments; - } + prepareResume(); + return getBytecodeDSLState().arguments; } public Object[] prepareResume() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; // not needed for manual interpreter Object[] arguments = getGeneratorFrame().getArguments(); PArguments.setException(arguments, null); PArguments.setCallerFrameInfo(arguments, null); @@ -204,7 +124,6 @@ public Object[] prepareResume() { } public ContinuationRootNode getBytecodeDSLContinuationRootNode() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; return getBytecodeDSLState().continuationRootNode; } @@ -215,27 +134,23 @@ public ContinuationRootNode getBytecodeDSLContinuationRootNode() { public static boolean isDSLGeneratorTracebackElement(TruffleStackTraceElement element) { // We need to check the source root node type, because this could be another Truffle // language that uses Bytecode DSL - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && isDSLGeneratorTarget(element.getTarget()); + return isDSLGeneratorTarget(element.getTarget()); } public static boolean isDSLGeneratorTarget(RootCallTarget callTarget) { - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && - callTarget.getRootNode() instanceof ContinuationRootNode cr && + return callTarget.getRootNode() instanceof ContinuationRootNode cr && cr.getSourceRootNode() instanceof PBytecodeDSLRootNode; } public static Frame unwrapDSLGeneratorFrame(TruffleStackTraceElement element) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (isDSLGeneratorTracebackElement(element)) { - return (Frame) element.getFrame().getArguments()[0]; - } + if (isDSLGeneratorTracebackElement(element)) { + return (Frame) element.getFrame().getArguments()[0]; } return element.getFrame(); } public static RootNode unwrapContinuationRoot(RootNode rootNode) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && - rootNode instanceof ContinuationRootNode continuationRoot) { + if (rootNode instanceof ContinuationRootNode continuationRoot) { return unwrapContinuationRoot(continuationRoot); } return rootNode; @@ -248,11 +163,7 @@ public static PBytecodeDSLRootNode unwrapContinuationRoot(ContinuationRootNode c public static boolean isGeneratorFrame(Frame frame) { Object frameInfo = frame.getFrameDescriptor().getInfo(); // just to avoid interface dispatch we must cast the info object - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return frameInfo instanceof BytecodeDSLFrameInfo info && info.getCodeUnit().isGeneratorOrCoroutine() && frame.getArguments()[0] instanceof MaterializedFrame; - } else { - return frameInfo instanceof BytecodeFrameInfo info && info.getCodeUnit().isGeneratorOrCoroutine(); - } + return frameInfo instanceof BytecodeDSLFrameInfo info && info.getCodeUnit().isGeneratorOrCoroutine() && frame.getArguments()[0] instanceof MaterializedFrame; } public static MaterializedFrame getGeneratorFrame(Object[] arguments) { @@ -260,13 +171,8 @@ public static MaterializedFrame getGeneratorFrame(Object[] arguments) { } public static MaterializedFrame getGeneratorFrame(Frame frame) { - // For DSL generator frames: we need to unwrap them already before this is used - // This method should go away with the manual interpreter assert isGeneratorFrame(frame); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return (MaterializedFrame) frame; - } - return getGeneratorFrame(frame.getArguments()); + return (MaterializedFrame) frame; } public MaterializedFrame getGeneratorFrame() { @@ -286,26 +192,17 @@ public static Object getSendValue(Object[] arguments) { } public RootNode getRootNode() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return getBytecodeDSLState().rootNode; - } else { - return getBytecodeState().rootNode; - } + return getBytecodeDSLState().rootNode; } /** * Returns the call target that should be used the next time the generator is called. */ public RootCallTarget getCurrentCallTarget() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return getBytecodeDSLState().continuationRootNode.getCallTarget(); - } else { - return getBytecodeState().getCurrentCallTarget(); - } + return getBytecodeDSLState().continuationRootNode.getCallTarget(); } public BytecodeNode getBytecodeNode() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; assert !running; // When it is running, we must use stack walking to get the location BytecodeDSLState state = getBytecodeDSLState(); if (state.isStarted) { @@ -320,7 +217,6 @@ public BytecodeNode getBytecodeNode() { * node. */ public BytecodeNode getContinuationBytecodeNode() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; BytecodeDSLState state = getBytecodeDSLState(); assert state.isStarted; return state.continuationRootNode.getLocation().getBytecodeNode(); @@ -331,14 +227,12 @@ public BytecodeNode getContinuationBytecodeNode() { * used if we know that the generator function is currently not on stack. */ public BytecodeNode getGeneratorFunctionBytecodeNode() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; BytecodeDSLState state = getBytecodeDSLState(); assert !state.isStarted; return state.rootNode.getBytecodeNode(); } public BytecodeLocation getCurrentLocation() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; return getBytecodeDSLState().continuationRootNode.getLocation(); } @@ -347,32 +241,19 @@ public Object getYieldFrom() { return null; } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - PBytecodeDSLRootNode rootNode = getBytecodeDSLState().rootNode; - if (!rootNode.hasYieldFromGenerator() || !getBytecodeDSLState().isStarted) { - return null; - } - return rootNode.readYieldFromGenerator(getContinuationBytecodeNode(), getGeneratorFrame()); - } else { - return ((BytecodeFrameInfo) frameInfo).getYieldFrom(frame, getBci(), getBytecodeState().getCurrentRootNode().getResumeStackTop()); + PBytecodeDSLRootNode rootNode = getBytecodeDSLState().rootNode; + if (!rootNode.hasYieldFromGenerator() || !getBytecodeDSLState().isStarted) { + return null; } - + return rootNode.readYieldFromGenerator(getContinuationBytecodeNode(), getGeneratorFrame()); } public boolean isStarted() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return getBytecodeDSLState().isStarted && !isRunning(); - } else { - return getBytecodeState().currentCallTarget != 0 && !isRunning(); - } + return getBytecodeDSLState().isStarted && !isRunning(); } public Object handleResult(PythonLanguage language, Object result) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return getBytecodeDSLState().handleResult(this, (ContinuationResult) result); - } else { - return getBytecodeState().handleResult(language, (GeneratorYieldResult) result); - } + return getBytecodeDSLState().handleResult(this, (ContinuationResult) result); } public final boolean isFinished() { @@ -414,11 +295,7 @@ public final void setQualname(TruffleString qualname) { } private CodeUnit getCodeUnit() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return getBytecodeDSLState().rootNode.getCodeUnit(); - } else { - return getBytecodeState().rootNode.getCodeUnit(); - } + return getBytecodeDSLState().rootNode.getCodeUnit(); } public final boolean isCoroutine() { @@ -430,14 +307,4 @@ public final boolean isAsyncGen() { return getCodeUnit().isAsyncGenerator(); } - public int getBci() { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; - if (!isStarted()) { - return -1; - } else if (isFinished()) { - return getBytecodeState().rootNode.getCodeUnit().code.length; - } else { - return getBytecodeState().getCurrentRootNode().getResumeBci(); - } - } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java index 3e0417df4f..8f4353f427 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -50,7 +50,6 @@ import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.strings.TruffleString; public final class PythonFrozenModule { @@ -75,11 +74,7 @@ private void initCode() { } private static String getSuffix() { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return "bin_dsl"; - } else { - return "bin"; - } + return "bin_dsl"; } public PythonFrozenModule(String symbol, String originalName, boolean isPackage) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java index 9e8fd679a5..4a2e8d5faa 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java @@ -88,7 +88,6 @@ import com.oracle.graal.python.nodes.SpecialAttributeNames; import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode; import com.oracle.graal.python.nodes.bytecode.FrameInfo; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.classes.IsSubtypeNode; @@ -103,7 +102,6 @@ import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; import com.oracle.graal.python.nodes.object.IsForeignObjectNode; import com.oracle.graal.python.runtime.CallerFlags; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.graal.python.runtime.exception.PythonErrorType; import com.oracle.graal.python.runtime.object.PFactory; @@ -123,8 +121,6 @@ import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.NodeFactory; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.BranchProfile; @@ -283,14 +279,9 @@ PNone initInPlace(VirtualFrame frame, SuperObject self, @SuppressWarnings("unuse @Bind Node inliningTarget, @Shared @Cached PRaiseNode raiseNode, @Shared @Cached CellBuiltins.GetRefNode getRefNode) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode = BytecodeNode.get(this); - assert bytecodeNode != null : this; - return initFromLocalFrame(frame, inliningTarget, self, bytecodeNode, getRefNode, raiseNode); - } else { - PBytecodeRootNode rootNode = (PBytecodeRootNode) getRootNode(); - return initFromLocalFrame(frame, inliningTarget, self, rootNode, rootNode.getLocalFrame(frame), getRefNode, raiseNode); - } + BytecodeNode bytecodeNode = BytecodeNode.get(this); + assert bytecodeNode != null : this; + return initFromLocalFrame(frame, inliningTarget, self, bytecodeNode, getRefNode, raiseNode); } /** @@ -307,39 +298,12 @@ PNone init(VirtualFrame frame, SuperObject self, @SuppressWarnings("unused") PNo throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.NO_CURRENT_FRAME, "super()"); } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeFrame bytecodeFrame = target.getBytecodeFrame(); - if (bytecodeFrame == null) { - throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS); - } - FrameInfo frameInfo = (FrameInfo) bytecodeFrame.getFrameDescriptorInfo(); - return initFromNonLocalFrame(frame, inliningTarget, self, (PBytecodeDSLRootNode) frameInfo.getRootNode(), bytecodeFrame, getRefNode, raiseNode); - } else { - MaterializedFrame locals = target.getLocals(); - if (locals == null) { - throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS); - } - FrameInfo frameInfo = (FrameInfo) locals.getFrameDescriptor().getInfo(); - return initFromLocalFrame(frame, inliningTarget, self, (PBytecodeRootNode) frameInfo.getRootNode(), locals, getRefNode, raiseNode); - } - } - - private PNone initFromLocalFrame(VirtualFrame frame, Node inliningTarget, SuperObject self, PBytecodeRootNode rootNode, Frame localFrame, CellBuiltins.GetRefNode getRefNode, - PRaiseNode raiseNode) { - PCell classCell = rootNode.readClassCell(localFrame); - if (!rootNode.hasSelf() || classCell == null) { + BytecodeFrame bytecodeFrame = target.getBytecodeFrame(); + if (bytecodeFrame == null) { throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS); } - Object cls = getRefNode.execute(inliningTarget, classCell); - if (cls == null) { - // the cell is empty - throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_EMPTY_CLASS); - } - Object obj = rootNode.readSelf(localFrame); - if (obj == null) { - throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_ARG0_DELETED); - } - return init(frame, self, cls, obj, inliningTarget, raiseNode); + FrameInfo frameInfo = (FrameInfo) bytecodeFrame.getFrameDescriptorInfo(); + return initFromNonLocalFrame(frame, inliningTarget, self, (PBytecodeDSLRootNode) frameInfo.getRootNode(), bytecodeFrame, getRefNode, raiseNode); } private PNone initFromLocalFrame(VirtualFrame frame, Node inliningTarget, SuperObject self, BytecodeNode bytecodeNode, CellBuiltins.GetRefNode getRefNode, diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/PTraceback.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/PTraceback.java index 11ff28f361..26bfddc890 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/PTraceback.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/PTraceback.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -46,7 +46,6 @@ import com.oracle.graal.python.builtins.PythonBuiltinClassType; import com.oracle.graal.python.builtins.objects.frame.PFrame; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.bytecode.BytecodeNode; import com.oracle.truffle.api.nodes.Node; @@ -117,11 +116,7 @@ public int getLineno() { public int getLasti(PFrame pFrame) { if (lasti == -1 && bci >= 0) { Node location; - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - location = bytecodeNode; - } else { - location = pFrame.getLocation(); - } + location = bytecodeNode; lasti = PFrame.bciToLasti(bci, location); } return lasti; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java index 3ce8a2a87d..4780af4030 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/TracebackBuiltins.java @@ -54,8 +54,6 @@ import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; import com.oracle.graal.python.nodes.frame.ReadFrameNode; @@ -64,7 +62,6 @@ import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode; import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.exception.ExceptionUtils; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.graal.python.runtime.exception.PythonErrorType; @@ -218,13 +215,10 @@ static void doMaterialize(Node inliningTarget, PTraceback tb, private static PFrame materializeFrame(TruffleStackTraceElement element, MaterializeFrameNode materializeFrameNode, PException pException, List stackTrace) { Node location = element.getLocation(); RootNode rootNode = element.getTarget().getRootNode(); - if (rootNode instanceof PBytecodeRootNode || rootNode instanceof PBytecodeGeneratorRootNode) { - location = rootNode; - } // We must have a callNode for Bytecode DSL root nodes. If this assertion fires, // it can be because of missing BoundaryCallContext.enter/exit around // @TruffleBoundary calls that may call back into Python code. - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || !(unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || + assert !(unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || location != null : String.format("root: %s, frame count: %d, start frame index: %d, stack trace:\n\n%s", rootNode, pException.getTracebackFrameCount(), pException.getTracebackStartIndex(), Arrays.toString(stackTrace.toArray())); // create the PFrame and refresh frame values diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Block.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Block.java deleted file mode 100644 index 3b2c609734..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Block.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021, 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import java.util.ArrayList; -import java.util.EnumSet; - -/** - * Block of instructions. Not always exactly like basic block, we allow having jumps in the middle. - */ -final class Block { - ArrayList instr = new ArrayList<>(); - Block next; - BlockInfo info; - /* - * For exception handlers: allows to unwind more stack items than usual. Useful to rollback to a - * mid-instruction stack state. Used by `with` statements. - */ - int unwindOffset; - - // The following fields are filled when assembling - int stackLevel = -1; - int startBci = -1; - int endBci = -1; - - public Block() { - } - - private static final EnumSet RETURN_OPCODES = EnumSet.of(OpCodes.RETURN_VALUE, OpCodes.RAISE_VARARGS); - - boolean isReturn() { - return !instr.isEmpty() && RETURN_OPCODES.contains(instr.get(instr.size() - 1).opcode); - } - - BlockInfo.AbstractExceptionHandler findExceptionHandler() { - if (info != null) { - return info.findExceptionHandler(); - } - return null; - } - - int computeLoopDepth() { - int loopDepth = 0; - BlockInfo b = info; - while (b != null) { - if (b instanceof BlockInfo.Loop) { - loopDepth++; - } - b = b.outer; - } - return loopDepth; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BlockInfo.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BlockInfo.java deleted file mode 100644 index 94e8192b0a..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BlockInfo.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2021, 2023, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import com.oracle.graal.python.pegparser.sst.StmtTy; - -/** - * Linked stack of block-related information needed to unwind execution before {@code break}, - * {@code continue} or {@code return}. - */ -class BlockInfo { - BlockInfo outer; - - AbstractExceptionHandler findExceptionHandler() { - if (outer != null) { - return outer.findExceptionHandler(); - } - return null; - } - - abstract static class Loop extends BlockInfo { - final Block start; - final Block after; - - public Loop(Block start, Block after) { - this.start = start; - this.after = after; - } - } - - static class While extends Loop { - public While(Block start, Block after) { - super(start, after); - } - } - - static class For extends Loop { - public For(Block start, Block after) { - super(start, after); - } - } - - static class PopValue extends BlockInfo { - } - - static class AbstractExceptionHandler extends BlockInfo { - final Block tryBlock; - final Block exceptionHandler; - - public AbstractExceptionHandler(Block tryBlock, Block exceptionHandler) { - this.tryBlock = tryBlock; - this.exceptionHandler = exceptionHandler; - } - - @Override - AbstractExceptionHandler findExceptionHandler() { - return this; - } - } - - static class ExceptHandler extends AbstractExceptionHandler { - public ExceptHandler(Block tryBlock, Block exceptionHandler) { - super(tryBlock, exceptionHandler); - } - } - - static class TryExcept extends AbstractExceptionHandler { - public TryExcept(Block tryBlock, Block exceptionHandler) { - super(tryBlock, exceptionHandler); - } - } - - static class FinallyHandler extends AbstractExceptionHandler { - public FinallyHandler(Block tryBlock, Block exceptionHandler) { - super(tryBlock, exceptionHandler); - } - } - - static class HandlerBindingCleanup extends AbstractExceptionHandler { - final String bindingName; - - public HandlerBindingCleanup(Block tryBlock, Block exceptionHandler, String bindingName) { - super(tryBlock, exceptionHandler); - this.bindingName = bindingName; - } - } - - static class With extends AbstractExceptionHandler { - final StmtTy.With node; - - public With(Block tryBlock, Block exceptionHandler, StmtTy.With node) { - super(tryBlock, exceptionHandler); - this.node = node; - } - } - - static class AsyncWith extends AbstractExceptionHandler { - final StmtTy.AsyncWith node; - - public AsyncWith(Block tryBlock, Block exceptionHandler, StmtTy.AsyncWith node) { - super(tryBlock, exceptionHandler); - this.node = node; - } - } - - static class TryFinally extends AbstractExceptionHandler { - final StmtTy[] body; - - public TryFinally(Block tryBlock, Block exceptionHandler, StmtTy[] body) { - super(tryBlock, exceptionHandler); - this.body = body; - } - } - - static class AsyncForLoop extends Loop { - public AsyncForLoop(Block start, Block after) { - super(start, after); - } - } - - static class AsyncForLoopExit extends AbstractExceptionHandler { - public AsyncForLoopExit(Block tryBlock, Block exceptionHandler) { - super(tryBlock, exceptionHandler); - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BytecodeCodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BytecodeCodeUnit.java deleted file mode 100644 index 4e31cc7b43..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BytecodeCodeUnit.java +++ /dev/null @@ -1,687 +0,0 @@ -/* - * Copyright (c) 2021, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; - -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.objects.bytes.BytesUtils; -import com.oracle.graal.python.builtins.objects.code.PCode; -import com.oracle.graal.python.builtins.objects.str.StringNodes; -import com.oracle.graal.python.compiler.OpCodes.CollectionBits; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.util.PythonUtils; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.RootNode; -import com.oracle.truffle.api.strings.TruffleString; - -public final class BytecodeCodeUnit extends CodeUnit { - private static final int DISASSEMBLY_NUM_COLUMNS = 8; - - // Note this is being mutated when quickening - @CompilationFinal(dimensions = 1) public final byte[] code; - @CompilationFinal(dimensions = 1) public final byte[] srcOffsetTable; - @CompilationFinal(dimensions = 1) public final long[] primitiveConstants; - @CompilationFinal(dimensions = 1) public final int[] exceptionHandlerRanges; - public final int stacksize; - public final int conditionProfileCount; - - /* Quickening data. See docs in PBytecodeRootNode */ - @CompilationFinal(dimensions = 1) public final byte[] variableShouldUnbox; - @CompilationFinal(dimensions = 1) public final int[] generalizeVarsIndices; - @CompilationFinal(dimensions = 1) public final int[] generalizeVarsValues; - // Which BCIs can trigger generalization. Used to binary search BCI index to the next array - @CompilationFinal(dimensions = 1) public final int[] generalizeInputsKeys; - // Start indices of generalizations in the next array. Has a sentinel value at the end - @CompilationFinal(dimensions = 1) public final int[] generalizeInputsIndices; - @CompilationFinal(dimensions = 1) public final int[] generalizeInputsValues; - - /* Lazily initialized source map */ - @CompilationFinal SourceMap sourceMap; - - public BytecodeCodeUnit(TruffleString name, TruffleString qualname, - int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int flags, - TruffleString[] names, TruffleString[] varnames, TruffleString[] cellvars, - TruffleString[] freevars, int[] cell2arg, Object[] constants, int startLine, int startColumn, - int endLine, int endColumn, - byte[] code, byte[] linetable, - long[] primitiveConstants, int[] exceptionHandlerRanges, int stacksize, int conditionProfileCount, - byte[] variableShouldUnbox, int[] generalizeInputsKeys, int[] generalizeInputsIndices, int[] generalizeInputsValues, - int[] generalizeVarsIndices, int[] generalizeVarsValues) { - super(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, cell2arg, constants, startLine, startColumn, endLine, endColumn); - this.code = code; - this.srcOffsetTable = linetable; - this.primitiveConstants = primitiveConstants; - this.exceptionHandlerRanges = exceptionHandlerRanges; - this.stacksize = stacksize; - this.conditionProfileCount = conditionProfileCount; - this.variableShouldUnbox = variableShouldUnbox; - this.generalizeInputsKeys = generalizeInputsKeys; - this.generalizeInputsIndices = generalizeInputsIndices; - this.generalizeInputsValues = generalizeInputsValues; - this.generalizeVarsIndices = generalizeVarsIndices; - this.generalizeVarsValues = generalizeVarsValues; - } - - public SourceMap getSourceMap() { - if (sourceMap == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - sourceMap = new SourceMap(code, srcOffsetTable, startLine, startColumn); - } - return sourceMap; - } - - public int bciToLine(int bci) { - if (bci < 0 || bci >= code.length) { - return -1; - } - return getSourceMap().startLineMap[bci]; - } - - public int bciToColumn(int bci) { - if (bci < 0 || bci >= code.length) { - return -1; - } - return getSourceMap().startColumnMap[bci]; - } - - public void generalizeInputs(int bci) { - if (generalizeInputsKeys != null) { - int key = Arrays.binarySearch(generalizeInputsKeys, bci); - if (key >= 0) { - int genStart = generalizeInputsIndices[key]; - int genEnd = generalizeInputsIndices[key + 1]; - for (int i = genStart; i < genEnd; i++) { - int generalizeBci = generalizeInputsValues[i]; - OpCodes generalizeInstr = OpCodes.fromOpCode(code[generalizeBci]); - if (generalizeInstr.generalizesTo != null) { - code[generalizeBci] = (byte) generalizeInstr.generalizesTo.ordinal(); - } - } - } - } - } - - @Override - protected void dumpBytecode(StringBuilder sb, boolean quickened, RootNode rootNode) { - int bci = 0; - int oparg = 0; - SourceMap map = getSourceMap(); - HashMap lines = new HashMap<>(); - while (bci < code.length) { - int bcBCI = bci; - OpCodes opcode = OpCodes.fromOpCode(code[bci++]); - - if (!quickened) { - opcode = opcode.quickens != null ? opcode.quickens : opcode; - } - - String[] line = lines.computeIfAbsent(bcBCI, k -> new String[DISASSEMBLY_NUM_COLUMNS]); - line[0] = String.format("%3d:%-3d - %3d:%-3d", map.startLineMap[bcBCI], map.startColumnMap[bcBCI], map.endLineMap[bcBCI], map.endColumnMap[bcBCI]); - if (line[1] == null) { - line[1] = ""; - } - line[2] = String.valueOf(bcBCI); - line[3] = opcode.toString(); - byte[] followingArgs = PythonUtils.EMPTY_BYTE_ARRAY; - if (!opcode.hasArg()) { - line[4] = ""; - } else { - oparg |= Byte.toUnsignedInt(code[bci++]); - if (opcode.argLength > 1) { - followingArgs = new byte[opcode.argLength - 1]; - for (int i = 0; i < opcode.argLength - 1; i++) { - followingArgs[i] = code[bci++]; - } - } - line[4] = String.format("% 2d", oparg); - } - - while (true) { - switch (opcode) { - case EXTENDED_ARG: - line[4] = ""; - break; - case LOAD_BYTE: - line[4] = String.format("% 2d", (byte) oparg); - break; - case LOAD_CONST: - case LOAD_BIGINT: - case LOAD_STRING: - case LOAD_BYTES: - case LOAD_CONST_COLLECTION: - case MAKE_KEYWORD: { - Object constant = constants[oparg]; - if (constant instanceof CodeUnit) { - line[5] = ((CodeUnit) constant).qualname.toJavaStringUncached(); - } else { - if (constant instanceof TruffleString) { - line[5] = StringNodes.StringReprNode.getUncached().execute((TruffleString) constant).toJavaStringUncached(); - } else if (constant instanceof byte[]) { - byte[] bytes = (byte[]) constant; - line[5] = BytesUtils.bytesRepr(bytes, bytes.length); - } else if (constant instanceof int[]) { - line[5] = Arrays.toString((int[]) constant); - } else if (constant instanceof long[]) { - line[5] = Arrays.toString((long[]) constant); - } else if (constant instanceof boolean[]) { - line[5] = Arrays.toString((boolean[]) constant); - } else if (constant instanceof double[]) { - line[5] = Arrays.toString((double[]) constant); - } else if (constant instanceof Object[]) { - line[5] = Arrays.toString((Object[]) constant); - } else { - line[5] = Objects.toString(constant); - } - } - if (opcode == OpCodes.LOAD_CONST_COLLECTION) { - line[5] += " type " + collectionTypeToString(followingArgs[0]) + " into " + collectionKindToString(followingArgs[0]); - } - break; - } - case MAKE_FUNCTION: { - line[4] = String.format("% 2d", followingArgs[0]); - CodeUnit codeUnit = (CodeUnit) constants[oparg]; - line[5] = codeUnit.qualname.toJavaStringUncached(); - break; - } - case MAKE_TYPE_PARAM: - line[4] = String.format("% 2d", oparg); - break; - case LOAD_INT: - case LOAD_LONG: - line[5] = Objects.toString(primitiveConstants[oparg]); - break; - case LOAD_DOUBLE: - line[5] = Objects.toString(Double.longBitsToDouble(primitiveConstants[oparg])); - break; - case LOAD_COMPLEX: { - double[] num = (double[]) constants[oparg]; - if (num[0] == 0.0) { - line[5] = String.format("%gj", num[1]); - } else { - line[5] = String.format("%g%+gj", num[0], num[1]); - } - break; - } - case LOAD_CLOSURE: - case LOAD_DEREF: - case STORE_DEREF: - case DELETE_DEREF: - case LOAD_FROM_DICT_OR_DEREF: - if (oparg >= cellvars.length) { - line[5] = freevars[oparg - cellvars.length].toJavaStringUncached(); - } else { - line[5] = cellvars[oparg].toJavaStringUncached(); - } - break; - case LOAD_FAST: - case STORE_FAST: - case DELETE_FAST: - line[5] = varnames[oparg].toJavaStringUncached(); - break; - case LOAD_NAME: - case LOAD_METHOD: - case STORE_NAME: - case DELETE_NAME: - case IMPORT_NAME: - case IMPORT_FROM: - case LOAD_GLOBAL: - case STORE_GLOBAL: - case DELETE_GLOBAL: - case LOAD_ATTR: - case STORE_ATTR: - case DELETE_ATTR: - case LOAD_FROM_DICT_OR_GLOBALS: - line[5] = names[oparg].toJavaStringUncached(); - break; - case FORMAT_VALUE: { - int type = oparg & FormatOptions.FVC_MASK; - switch (type) { - case FormatOptions.FVC_STR: - line[5] = "STR"; - break; - case FormatOptions.FVC_REPR: - line[5] = "REPR"; - break; - case FormatOptions.FVC_ASCII: - line[5] = "ASCII"; - break; - case FormatOptions.FVC_NONE: - line[5] = "NONE"; - break; - } - if ((oparg & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC) { - line[5] += " + SPEC"; - } - break; - } - case CALL_METHOD: { - line[4] = String.format("% 2d", oparg); - break; - } - case UNARY_OP: - line[5] = UnaryOps.values()[oparg].toString(); - break; - case BINARY_OP: - line[5] = BinaryOps.values()[oparg].toString(); - break; - case COLLECTION_FROM_STACK: - case COLLECTION_ADD_STACK: - case COLLECTION_FROM_COLLECTION: - case COLLECTION_ADD_COLLECTION: - case ADD_TO_COLLECTION: - line[4] = String.format("% 2d", CollectionBits.elementCount(oparg)); - line[5] = collectionKindToString(oparg); - break; - case UNPACK_EX: - line[5] = String.format("%d, %d", oparg, Byte.toUnsignedInt(followingArgs[0])); - break; - case JUMP_BACKWARD: - lines.computeIfAbsent(bcBCI - oparg, k -> new String[DISASSEMBLY_NUM_COLUMNS])[1] = ">>"; - line[5] = String.format("to %d", bcBCI - oparg); - break; - case FOR_ITER: - case JUMP_FORWARD: - case POP_AND_JUMP_IF_FALSE: - case POP_AND_JUMP_IF_TRUE: - case JUMP_IF_FALSE_OR_POP: - case JUMP_IF_TRUE_OR_POP: - case MATCH_EXC_OR_JUMP: - case SEND: - case THROW: - lines.computeIfAbsent(bcBCI + oparg, k -> new String[DISASSEMBLY_NUM_COLUMNS])[1] = ">>"; - line[5] = String.format("to %d", bcBCI + oparg); - break; - default: - if (opcode.quickens != null) { - opcode = opcode.quickens; - continue; - } - } - if (opcode == OpCodes.EXTENDED_ARG) { - oparg <<= 8; - } else { - oparg = 0; - } - break; - } - } - - for (int i = 0; i < exceptionHandlerRanges.length; i += 4) { - int start = exceptionHandlerRanges[i]; - int stop = exceptionHandlerRanges[i + 1]; - int handler = exceptionHandlerRanges[i + 2]; - int stackAtHandler = exceptionHandlerRanges[i + 3]; - String[] line = lines.get(handler); - assert line != null; - String handlerStr = String.format("exc handler %d - %d; stack: %d", start, stop, stackAtHandler); - if (line[6] == null) { - line[6] = handlerStr; - } else { - line[6] += " | " + handlerStr; - } - } - - int generalizationIndex1 = 0; - for (bci = 0; bci < code.length; bci++) { - String[] line = lines.get(bci); - if (line != null) { - line[5] = line[5] == null ? "" : String.format("(%s)", line[5]); - line[6] = line[6] == null ? "" : String.format("(%s)", line[6]); - line[7] = ""; - if (generalizeInputsKeys != null && generalizationIndex1 < generalizeInputsKeys.length && generalizeInputsKeys[generalizationIndex1] == bci) { - int generalizationIndex2 = generalizeInputsIndices[generalizationIndex1++]; - StringBuilder quickenSb = new StringBuilder(); - quickenSb.append("generalizes: "); - for (int i = generalizationIndex2; i < generalizeInputsIndices[generalizationIndex1]; i++) { - if (i > generalizationIndex2) { - quickenSb.append(", "); - } - quickenSb.append(generalizeInputsValues[i]); - } - line[7] = quickenSb.toString(); - } - String formatted = String.format("%-8s %2s %4s %-32s %-3s %-32s %s %s", (Object[]) line); - sb.append(formatted.stripTrailing()); - sb.append('\n'); - } - } - } - - private static String collectionKindToString(int oparg) { - switch (CollectionBits.collectionKind(oparg)) { - case CollectionBits.KIND_LIST: - return "list"; - case CollectionBits.KIND_TUPLE: - return "tuple"; - case CollectionBits.KIND_SET: - return "set"; - case CollectionBits.KIND_DICT: - return "dict"; - case CollectionBits.KIND_KWORDS: - return "PKeyword[]"; - case CollectionBits.KIND_OBJECT: - return "Object[]"; - } - throw new IllegalStateException("Unknown kind"); - } - - private static String collectionTypeToString(int oparg) { - switch (CollectionBits.elementType(oparg)) { - case CollectionBits.ELEMENT_BOOLEAN: - return "boolean"; - case CollectionBits.ELEMENT_INT: - return "int"; - case CollectionBits.ELEMENT_LONG: - return "long"; - case CollectionBits.ELEMENT_DOUBLE: - return "double"; - case CollectionBits.ELEMENT_OBJECT: - return "Object"; - } - throw new IllegalStateException("Unknown type"); - } - - public static final int LINE_TO_BCI_LINE_AFTER_CODEBLOCK = -1; - public static final int LINE_TO_BCI_LINE_BEFORE_CODEBLOCK = -2; - - // -1 for line after the code block, -2 for line before the code block, line number otherwise - public int lineToBci(int line) { - if (startLine == line) { - return 0; - } - if ((flags & PCode.CO_GRAALPYHON_MODULE) != 0 && line < startLine) { - // allow jump to the first line of a file, even if it is a comment - return 0; - } - int[] map = getSourceMap().startLineMap; - int bestBci = LINE_TO_BCI_LINE_AFTER_CODEBLOCK; - int lineDiff = Integer.MAX_VALUE; - boolean afterFirst = false; - for (int bci = 0; bci < map.length; ++bci) { - if (map[bci] >= line) { - int lineDiff2 = map[bci] - line; - // the first bci found is the start of the line - if (lineDiff2 < lineDiff) { - bestBci = bci; - lineDiff = lineDiff2; - } - } - if (map[bci] > 0 && map[bci] <= line) { - // the line is actually within the codeblock. - afterFirst = true; - } - } - // bestBci being -1 means the line is outside the code block - return afterFirst ? bestBci : LINE_TO_BCI_LINE_BEFORE_CODEBLOCK; - } - - public enum StackItem { - With("the body of a with statement"), - Iterable("the body of a for loop"), - Except("an 'except' block as there's no exception"), - Object("Incompatible stack"); - - public final String error; - - StackItem(String error) { - this.error = error; - } - - ArrayList push(ArrayList v) { - ArrayList ret = v == null ? new ArrayList<>() : new ArrayList<>(v); - ret.add(this); - return ret; - } - } - - private void setNextStack(ArrayDeque todo, List> stacks, int target, ArrayList value) { - ArrayList blocksAtTarget = stacks.get(target); - if (blocksAtTarget == null) { - stacks.set(target, value); - todo.addLast(target); - } else { - assert value.equals(blocksAtTarget) : "found conflicting stacks depending on code path: " + this.name + "\t at " + target; - } - } - - private static ArrayList popStack(ArrayList blocks) { - assert blocks != null : "Pop from null stack"; - assert blocks.size() >= 1 : "Pop from empty stack"; - return new ArrayList<>(blocks.subList(0, blocks.size() - 1)); - } - - // returns null if the jump is fine - public String checkJump(Node node, List> stackElems, int from, int to) { - ArrayList blkFrom = stackElems.get(from); - if (blkFrom == null) { - // this should not happen - throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, bciToLine(from)); - } - ArrayList blkTo = stackElems.get(to); - if (blkTo == null) { - throw PRaiseNode.raiseStatic(node, PythonBuiltinClassType.ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, bciToLine(from)); - } - if (blkTo.size() > blkFrom.size()) { - return blkTo.get(blkTo.size() - 1).error; - } - for (int i = blkTo.size() - 1; i >= 0; --i) { - if (blkTo.get(i) != blkFrom.get(i)) { - return blkTo.get(i).error; - } - } - return null; - } - - public List> computeStackElems() { - List> blocks = new ArrayList<>(Collections.nCopies(code.length + 1, null)); - blocks.set(0, new ArrayList<>()); - ArrayDeque todo = new ArrayDeque<>(); - todo.addFirst(0); - while (!todo.isEmpty()) { - int firstBci = todo.removeLast(); - assert blocks.get(firstBci) != null : "Reached block without determining its stack state"; - opCodeAt(code, firstBci, (bci, op, oparg, followingArgs) -> { - // firstBci can be different from bci if EXTEND_ARG is used - // the stack is kept both at firstBci and bci - ArrayList next = blocks.get(firstBci); - if (firstBci != bci) { - blocks.set(bci, next); - } - for (int j = 0; j < exceptionHandlerRanges.length; j += 4) { - int start = exceptionHandlerRanges[j]; - int handler = exceptionHandlerRanges[j + 2]; - int stack = exceptionHandlerRanges[j + 3]; - if (start == bci) { - ArrayList handlerStack = StackItem.Except.push(new ArrayList<>(blocks.get(bci).subList(0, stack))); - // an exception handler is like a jump - // the except block is added in the lines below - setNextStack(todo, blocks, handler, handlerStack); - } - } - switch (op) { - case GET_ITER: - case GET_AITER: - next = StackItem.Iterable.push(popStack(blocks.get(bci))); - setNextStack(todo, blocks, bci + 1, next); - break; - case FOR_ITER: - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), StackItem.Object.push(next)); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, true), popStack(next)); - break; - case PUSH_EXC_INFO: - next = StackItem.Except.push(StackItem.Object.push(popStack(blocks.get(bci)))); - setNextStack(todo, blocks, bci + 1, next); - break; - case MATCH_EXC_OR_JUMP: - next = popStack(next); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, true), next); - break; - case SETUP_WITH: - case SETUP_AWITH: - next = StackItem.Object.push(StackItem.With.push(blocks.get(bci))); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - break; - case GET_AEXIT_CORO: - next = StackItem.Object.push(StackItem.Except.push(popStack(popStack(popStack(blocks.get(bci)))))); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - break; - case DUP_TOP: - next = next.get(next.size() - 1).push(next); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - break; - case ROT_TWO: { - StackItem top = next.get(next.size() - 1); - StackItem belowTop = next.get(next.size() - 2); - next = belowTop.push(top.push(popStack(popStack(next)))); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - break; - } - case ROT_THREE: { - StackItem top = next.get(next.size() - 1); - StackItem second = next.get(next.size() - 2); - StackItem third = next.get(next.size() - 3); - next = second.push(third.push(top.push(top.push(popStack(popStack(popStack(next))))))); - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), next); - break; - } - case LOAD_NONE: - opCodeAt(code, op.getNextBci(bci, oparg, false), (ignored, nextOp, ignored2, ignored3) -> { - // Usually, when compiling bytecode around exception handlers, the code - // is generated twice, once for the path with no exception, and - // once for the path with the exception. However, when generating code - // for a with statement exit, the code is generated as follows (and in a - // similar manner for async with). - // ... - // LOAD_NONE - // EXIT_WITH (exception handler starts here) - // ... - // This means that setting the stack at EXIT_WITH to have Object on top, - // as LOAD_NONE usually would, would cause a conflict with the exception - // handler starting at that position, which has the stack top be an - // Exception. - if (nextOp != OpCodes.GET_AEXIT_CORO && nextOp != OpCodes.EXIT_WITH) { - setNextStack(todo, blocks, op.getNextBci(bci, oparg, false), StackItem.Object.push(blocks.get(bci))); - } - }); - break; - - default: { - int nextWJump = op.getNextBci(bci, oparg, true); - int nextWOJump = op.getNextBci(bci, oparg, false); - int stackLostWJump = op.getNumberOfConsumedStackItems(oparg, followingArgs, true); - int stackLostWOJump = op.getNumberOfConsumedStackItems(oparg, followingArgs, false); - int stackGainWJump = op.getNumberOfProducedStackItems(oparg, followingArgs, true); - int stackGainWOJump = op.getNumberOfProducedStackItems(oparg, followingArgs, false); - handleGeneralOp(blocks, todo, bci, nextWJump, stackLostWJump, stackGainWJump); - if (nextWJump != nextWOJump) { - handleGeneralOp(blocks, todo, bci, nextWOJump, stackLostWOJump, stackGainWOJump); - } - break; - } - } - }); - } - return blocks; - } - - private void handleGeneralOp(List> blocks, ArrayDeque todo, int bci, int next, int stackLost, int stackGain) { - if (next >= 0) { - ArrayList blocksHere = new ArrayList<>(blocks.get(bci)); - for (int k = 0; k < stackLost; ++k) { - blocksHere.remove(blocksHere.size() - 1); - } - for (int k = 0; k < stackGain; ++k) { - blocksHere.add(StackItem.Object); - } - setNextStack(todo, blocks, next, blocksHere); - } - } - - @FunctionalInterface - public interface BytecodeAction { - void run(int bci, OpCodes op, int oparg, byte[] followingArgs); - } - - // returns the following bci - private static int opCodeAt(byte[] bytecode, int bci, BytecodeAction action) { - int oparg = 0; - OpCodes op = OpCodes.fromOpCode(bytecode[bci]); - while (op == OpCodes.EXTENDED_ARG) { - oparg |= Byte.toUnsignedInt(bytecode[bci + 1]); - oparg <<= 8; - bci += 2; - op = OpCodes.fromOpCode(bytecode[bci]); - } - op = op.quickens != null ? op.quickens : op; - byte[] followingArgs = null; - if (op.argLength > 0) { - oparg |= Byte.toUnsignedInt(bytecode[bci + 1]); - if (op.argLength > 1) { - followingArgs = new byte[op.argLength - 1]; - System.arraycopy(bytecode, bci + 2, followingArgs, 0, followingArgs.length); - } - } - action.run(bci, op, oparg, followingArgs); - return bci + op.length(); - } - - public static void iterateBytecode(byte[] bytecode, BytecodeAction action) { - for (int bci = 0; bci < bytecode.length;) { - bci = opCodeAt(bytecode, bci, action); - } - } - - public void iterateBytecode(BytecodeAction action) { - iterateBytecode(code, action); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java index 25f488c6e2..71e4c4fc0b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -125,7 +125,21 @@ public CodeUnit(TruffleString name, TruffleString qualname, } public SourceSection getSourceSection(Source source) { - return SourceMap.getSourceSection(source, startLine, startColumn, endLine, endColumn); + if (!source.hasCharacters()) { + return source.createUnavailableSection(); + } + try { + int truffleStartColumn = Math.max(startColumn + 1, 1); + int truffleEndColumn = Math.max(endColumn + 1, 1); + if (truffleEndColumn == source.getLineLength(endLine) + 1) { + truffleEndColumn--; + } + return source.createSection(startLine, truffleStartColumn, endLine, truffleEndColumn); + } catch (IllegalArgumentException e) { + // TODO GR-40896 we don't track source ranges of f-strings correctly + // Also consider sources created from ast module + return source.createUnavailableSection(); + } } public boolean takesVarKeywordArgs() { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java deleted file mode 100644 index 0066e5ecc0..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CompilationUnit.java +++ /dev/null @@ -1,548 +0,0 @@ -/* - * Copyright (c) 2021, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import static com.oracle.graal.python.compiler.CompilationScope.Class; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_INT_ARRAY; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_LONG_ARRAY; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_TRUFFLESTRING_ARRAY; -import static com.oracle.graal.python.util.PythonUtils.toInternedTruffleStringUncached; - -import java.io.ByteArrayOutputStream; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.Deque; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -import com.oracle.graal.python.builtins.objects.code.PCode; -import com.oracle.graal.python.pegparser.FutureFeature; -import com.oracle.graal.python.pegparser.scope.Scope; -import com.oracle.graal.python.pegparser.tokenizer.SourceRange; -import com.oracle.graal.python.util.PythonUtils; - -public final class CompilationUnit { - final String name; - final String qualName; - final HashMap constants = new HashMap<>(); - final HashMap primitiveConstants = new HashMap<>(); - final HashMap names = new HashMap<>(); - final HashMap varnames = new HashMap<>(); - final HashMap cellvars; - final HashMap freevars; - final int[] cell2arg; - final int argCount; - final int positionalOnlyArgCount; - final int kwOnlyArgCount; - final boolean takesVarArgs; - final boolean takesVarKeywordArgs; - - final Block startBlock = new Block(); - final Scope scope; - final CompilationScope scopeType; - String privateName; - BlockInfo blockInfo; - int conditionProfileCount; - - Block currentBlock = startBlock; - int maxStackSize = 0; - - SourceRange startLocation; - SourceRange currentLocation; - - final EnumSet futureFeatures; - - CompilationUnit(CompilationScope scopeType, Scope scope, String name, String qualName, CompilationUnit parent, int argCount, int positionalOnlyArgCount, int kwOnlyArgCount, boolean takesVarArgs, - boolean takesVarKeywordArgs, SourceRange startLocation, EnumSet futureFeatures) { - this.scopeType = scopeType; - this.scope = scope; - this.name = name; - this.argCount = argCount; - this.positionalOnlyArgCount = positionalOnlyArgCount; - this.kwOnlyArgCount = kwOnlyArgCount; - this.takesVarArgs = takesVarArgs; - this.takesVarKeywordArgs = takesVarKeywordArgs; - this.startLocation = startLocation; - this.futureFeatures = futureFeatures; - currentLocation = startLocation; - - if (scopeType == Class) { - privateName = name; - } else if (parent != null) { - privateName = parent.privateName; - } else { - privateName = null; - } - this.qualName = qualName; - - // derive variable names - for (int i = 0; i < scope.getVarnames().size(); i++) { - varnames.put(scope.getVarnames().get(i), i); - } - cellvars = scope.getSymbolsByType(EnumSet.of(Scope.DefUse.Cell), 0); - if (scope.needsClassClosure()) { - assert scopeType == Class; - assert cellvars.isEmpty(); - cellvars.put("__class__", 0); - } - if (scope.needsClassDict()) { - assert scopeType == Class; - cellvars.put("__classdict__", cellvars.size()); - } - - int[] cell2argValue = new int[cellvars.size()]; - boolean hasArgCell = false; - Arrays.fill(cell2argValue, -1); - for (String cellvar : cellvars.keySet()) { - if (varnames.containsKey(cellvar)) { - cell2argValue[cellvars.get(cellvar)] = varnames.get(cellvar); - hasArgCell = true; - } - } - this.cell2arg = hasArgCell ? cell2argValue : null; - freevars = scope.getSymbolsByType(EnumSet.of(Scope.DefUse.Free, Scope.DefUse.DefFreeClass), cellvars.size()); - } - - void useNextBlock(Block b) { - if (b == currentBlock) { - return; - } - assert currentBlock.next == null; - currentBlock.next = b; - useBlock(b); - } - - void useBlock(Block b) { - b.info = blockInfo; - currentBlock = b; - } - - private void addImplicitReturn() { - Block b = startBlock; - while (b.next != null) { - b = b.next; - } - if (!b.isReturn()) { - b.instr.add(new Instruction(OpCodes.LOAD_NONE, 0, null, null, currentLocation)); - b.instr.add(new Instruction(OpCodes.RETURN_VALUE, 0, null, null, currentLocation)); - } - } - - public BytecodeCodeUnit assemble() { - addImplicitReturn(); - calculateJumpInstructionArguments(); - - SourceMap.Builder sourceMapBuilder = new SourceMap.Builder(startLocation.startLine, startLocation.startColumn); - - // The actual bytecodes - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - - computeStackLevels(); - - int varCount = varnames.size(); - List quickenedInstructions = new ArrayList<>(); - List> variableStores = new ArrayList<>(varCount); - for (int i = 0; i < varCount; i++) { - variableStores.add(new ArrayList<>()); - } - int[] boxingMetric = new int[varCount]; - byte[] shouldUnboxVariable = new byte[varCount]; - Arrays.fill(shouldUnboxVariable, (byte) 0xff); - - SortedSet finishedExceptionHandlerRanges = new TreeSet<>(Comparator.comparingInt(a -> a[0])); - - Block b = startBlock; - HashMap> handlerBlocks = new HashMap<>(); - while (b != null) { - b.startBci = buf.size(); - int quickenMetricWeight = b.computeLoopDepth() * 3 + 1; - BlockInfo.AbstractExceptionHandler handler = b.findExceptionHandler(); - if (handler != null) { - handlerBlocks.computeIfAbsent(handler.exceptionHandler, (x) -> new ArrayList<>()).add(b); - } - if (handlerBlocks.containsKey(b)) { - List blocks = handlerBlocks.get(b); - Block firstBlock = blocks.get(0); - int stackLevel = firstBlock.findExceptionHandler().tryBlock.stackLevel + b.unwindOffset; - int start = firstBlock.startBci; - int end = firstBlock.endBci; - int handlerBci = buf.size(); - for (int i = 1; i < blocks.size(); i++) { - assert start >= 0 && end >= 0; - Block block = blocks.get(i); - if (block.startBci != end) { - addExceptionRange(finishedExceptionHandlerRanges, start, end, handlerBci, stackLevel); - start = block.startBci; - } - end = block.endBci; - } - addExceptionRange(finishedExceptionHandlerRanges, start, end, handlerBci, stackLevel); - } - for (Instruction i : b.instr) { - if (i.quickenOutput || i.quickeningGeneralizeList != null) { - quickenedInstructions.add(i); - } - if (i.opcode == OpCodes.STORE_FAST) { - variableStores.get(i.arg).add(i); - } else if (i.opcode == OpCodes.LOAD_FAST) { - boxingMetric[i.arg] += i.quickenOutput ? quickenMetricWeight : -quickenMetricWeight; - } - i.bci = buf.size(); - emitBytecode(i, buf, sourceMapBuilder); - } - b.endBci = buf.size(); - b = b.next; - } - - int flags = PCode.CO_OPTIMIZED | PCode.CO_NEWLOCALS; - flags |= takesVarArgs ? PCode.CO_VARARGS : 0; - flags |= takesVarKeywordArgs ? PCode.CO_VARKEYWORDS : 0; - if (scope.isNested()) { - flags |= PCode.CO_NESTED; - } - if (scope.isModule()) { - flags |= PCode.CO_GRAALPYHON_MODULE; - } - if (scope.isGenerator() && scope.isCoroutine()) { - flags |= PCode.CO_ASYNC_GENERATOR; - } else if (scope.isGenerator()) { - flags |= PCode.CO_GENERATOR; - } else if (scope.isCoroutine()) { - flags |= PCode.CO_COROUTINE; - } - - for (FutureFeature flag : futureFeatures) { - flags |= flag.flagValue; - } - - final int rangeElements = 4; - int[] exceptionHandlerRanges; - if (finishedExceptionHandlerRanges.isEmpty()) { - exceptionHandlerRanges = EMPTY_INT_ARRAY; - } else { - exceptionHandlerRanges = new int[finishedExceptionHandlerRanges.size() * rangeElements]; - int rangeIndex = 0; - for (int[] range : finishedExceptionHandlerRanges) { - assert range.length == rangeElements; - System.arraycopy(range, 0, exceptionHandlerRanges, rangeIndex, rangeElements); - rangeIndex += rangeElements; - } - } - - int generizationListSize = 0; - int totalGeneralizations = 0; - for (Instruction insn : quickenedInstructions) { - if (insn.quickeningGeneralizeList != null && !insn.quickeningGeneralizeList.isEmpty()) { - generizationListSize++; - totalGeneralizations += insn.quickeningGeneralizeList.size(); - } - } - int[] generalizeInputsKeys = generizationListSize > 0 ? new int[generizationListSize] : EMPTY_INT_ARRAY; - int[] generalizeInputsIndices = generizationListSize > 0 ? new int[generizationListSize + 1] : EMPTY_INT_ARRAY; - int[] generalizeInputsValues = generizationListSize > 0 ? new int[totalGeneralizations] : EMPTY_INT_ARRAY; - int generalizationIndex1 = 0; - int generalizationIndex2 = 0; - for (Instruction insn : quickenedInstructions) { - int insnBodyBci = insn.bodyBci(); - if (insn.quickeningGeneralizeList != null && !insn.quickeningGeneralizeList.isEmpty()) { - generalizeInputsKeys[generalizationIndex1] = insnBodyBci; - generalizeInputsIndices[generalizationIndex1] = generalizationIndex2; - for (int j = 0; j < insn.quickeningGeneralizeList.size(); j++) { - int bci = insn.quickeningGeneralizeList.get(j).bodyBci(); - assert bci >= 0; - generalizeInputsValues[generalizationIndex2++] = bci; - } - generalizationIndex1++; - } - generalizeInputsIndices[generizationListSize] = generalizationIndex2; - } - if (cell2arg != null) { - for (int i = 0; i < cell2arg.length; i++) { - if (cell2arg[i] != -1 && cell2arg[i] < varCount) { - shouldUnboxVariable[cell2arg[i]] = 0; - } - } - } - int[] generalizeVarsIndices = EMPTY_INT_ARRAY; - int[] generalizeVarsValues = EMPTY_INT_ARRAY; - if (!scope.isGenerator() && varCount > 0) { - /* - * We do an optimization in the interpreter that we don't unbox variables that would - * mostly get boxed again. This helps for interpreter performance, but for compiled code - * we have to unbox all variables otherwise the compiler is not always able to prove the - * variable was initialized. In generators, transferring the variables between the two - * modes of usage (boxed vs unboxed) would be too complex, so we skip the optimization - * there and unbox all variables. - */ - int totalVarsGeneralizations = 0; - for (int i = 0; i < varCount; i++) { - List stores = variableStores.get(i); - totalVarsGeneralizations += stores.size(); - } - if (totalVarsGeneralizations > 0) { - generalizeVarsIndices = new int[varCount + 1]; - generalizeVarsValues = new int[totalVarsGeneralizations]; - int generalizeVarsIndex = 0; - for (int i = 0; i < varCount; i++) { - List stores = variableStores.get(i); - generalizeVarsIndices[i] = generalizeVarsIndex; - for (int j = 0; j < stores.size(); j++) { - generalizeVarsValues[generalizeVarsIndex++] = stores.get(j).bodyBci(); - } - if (boxingMetric[i] < 0) { - shouldUnboxVariable[i] = 0; - } - } - generalizeVarsIndices[varCount] = generalizeVarsIndex; - } - } - return new BytecodeCodeUnit(toInternedTruffleStringUncached(name), toInternedTruffleStringUncached(qualName), - argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, - orderedKeys(names, EMPTY_TRUFFLESTRING_ARRAY, PythonUtils::toInternedTruffleStringUncached), - orderedKeys(varnames, EMPTY_TRUFFLESTRING_ARRAY, PythonUtils::toInternedTruffleStringUncached), - orderedKeys(cellvars, EMPTY_TRUFFLESTRING_ARRAY, PythonUtils::toInternedTruffleStringUncached), - orderedKeys(freevars, EMPTY_TRUFFLESTRING_ARRAY, cellvars.size(), PythonUtils::toInternedTruffleStringUncached), - cell2arg, - orderedKeys(constants, EMPTY_OBJECT_ARRAY), - startLocation.startLine, - startLocation.startColumn, - startLocation.endLine, - startLocation.endColumn, - buf.toByteArray(), - sourceMapBuilder.build(), - orderedLong(primitiveConstants), exceptionHandlerRanges, maxStackSize, conditionProfileCount, - shouldUnboxVariable, generalizeInputsKeys, generalizeInputsIndices, generalizeInputsValues, generalizeVarsIndices, generalizeVarsValues); - } - - private static void addExceptionRange(Collection finishedExceptionHandlerRanges, int start, int end, int handler, int stackLevel) { - if (start == end) { - // Don't emit empty ranges. TODO don't emit the block at all if not necessary - return; - } - int[] range = {start, end, handler, stackLevel}; - finishedExceptionHandlerRanges.add(range); - } - - private static final EnumSet UNCONDITIONAL_JUMP_OPCODES = EnumSet.of(OpCodes.JUMP_BACKWARD, OpCodes.JUMP_FORWARD, OpCodes.RETURN_VALUE, OpCodes.RAISE_VARARGS, OpCodes.END_EXC_HANDLER); - - private void computeStackLevels() { - Deque todo = new ArrayDeque<>(); - todo.add(startBlock); - startBlock.stackLevel = 0; - while (!todo.isEmpty()) { - Block block = todo.pop(); - int level = block.stackLevel; - assert level >= 0; - maxStackSize = Math.max(maxStackSize, level); - BlockInfo.AbstractExceptionHandler handler = block.findExceptionHandler(); - if (handler != null) { - assert handler.tryBlock.stackLevel != -1; - int handlerLevel = handler.tryBlock.stackLevel + handler.exceptionHandler.unwindOffset + 1; - computeStackLevels(handler.exceptionHandler, handlerLevel, todo); - } - boolean fallthrough = true; - for (Instruction i : block.instr) { - Block target = i.target; - if (target != null) { - int jumpLevel = level + i.opcode.getStackEffect(i.arg, i.followingArgs, true); - computeStackLevels(target, jumpLevel, todo); - } - if (UNCONDITIONAL_JUMP_OPCODES.contains(i.opcode)) { - assert i.opcode != OpCodes.RETURN_VALUE || level == 1; - fallthrough = false; - break; - } - level += i.opcode.getStackEffect(i.arg, i.followingArgs, false); - assert level >= 0; - maxStackSize = Math.max(maxStackSize, level); - } - if (fallthrough && block.next != null) { - computeStackLevels(block.next, level, todo); - } - } - } - - private static void computeStackLevels(Block block, int level, Deque todo) { - if (block.stackLevel == -1) { - block.stackLevel = level; - todo.push(block); - } else { - assert block.stackLevel == level; - } - } - - private void calculateJumpInstructionArguments() { - HashMap blockLocationMap = new HashMap<>(); - boolean repeat; - do { - repeat = false; - int bci = 0; - Block block = startBlock; - while (block != null) { - blockLocationMap.put(block, bci); - for (Instruction i : block.instr) { - bci += i.extendedLength(); - } - block = block.next; - } - - bci = 0; - block = startBlock; - while (block != null) { - for (int i = 0; i < block.instr.size(); i++) { - Instruction instr = block.instr.get(i); - Block target = instr.target; - if (target != null) { - int targetPos = blockLocationMap.get(target); - int distance = Math.abs(bci + instr.extensions() * 2 - targetPos); - int prevLength = instr.extendedLength(); - instr.arg = distance; - if (instr.extendedLength() != prevLength) { - repeat = true; - } - } - bci += instr.extendedLength(); - } - block = block.next; - } - } while (repeat); - } - - private static void emitBytecode(Instruction instr, ByteArrayOutputStream buf, SourceMap.Builder sourceMapBuilder) throws IllegalStateException { - OpCodes opcode = instr.opcode; - // Pre-quicken constant loads - if (opcode == OpCodes.LOAD_BYTE) { - opcode = instr.quickenOutput ? OpCodes.LOAD_BYTE_I : OpCodes.LOAD_BYTE_O; - } else if (opcode == OpCodes.LOAD_INT) { - opcode = instr.quickenOutput ? OpCodes.LOAD_INT_I : OpCodes.LOAD_INT_O; - } else if (opcode == OpCodes.LOAD_LONG) { - opcode = instr.quickenOutput ? OpCodes.LOAD_LONG_L : OpCodes.LOAD_LONG_O; - } else if (opcode == OpCodes.LOAD_DOUBLE) { - opcode = instr.quickenOutput ? OpCodes.LOAD_DOUBLE_D : OpCodes.LOAD_DOUBLE_O; - } else if (opcode == OpCodes.LOAD_TRUE) { - opcode = instr.quickenOutput ? OpCodes.LOAD_TRUE_B : OpCodes.LOAD_TRUE_O; - } else if (opcode == OpCodes.LOAD_FALSE) { - opcode = instr.quickenOutput ? OpCodes.LOAD_FALSE_B : OpCodes.LOAD_FALSE_O; - } else if (opcode == OpCodes.LOAD_FAST) { - opcode = instr.quickenOutput ? OpCodes.LOAD_FAST : OpCodes.LOAD_FAST_ADAPTIVE_O; - } else if (opcode == OpCodes.FOR_ITER) { - opcode = instr.quickenOutput ? OpCodes.FOR_ITER_I : OpCodes.FOR_ITER_O; - } else if (!instr.quickenOutput) { - if (opcode == OpCodes.UNARY_OP) { - opcode = OpCodes.UNARY_OP_ADAPTIVE_O; - } else if (opcode == OpCodes.BINARY_OP) { - opcode = OpCodes.BINARY_OP_ADAPTIVE_O; - } else if (opcode == OpCodes.BINARY_SUBSCR) { - opcode = OpCodes.BINARY_SUBSCR_ADAPTIVE_O; - } else if (opcode.generalizesTo != null) { - opcode = instr.opcode.generalizesTo; - } - } - assert opcode.ordinal() < 256; - SourceRange location = instr.location; - sourceMapBuilder.appendLocation(location.startLine, location.startColumn, location.endLine, location.endColumn); - if (!opcode.hasArg()) { - buf.write(opcode.ordinal()); - } else { - int oparg = instr.arg; - for (int i = instr.extensions(); i >= 1; i--) { - buf.write(OpCodes.EXTENDED_ARG.ordinal()); - buf.write((oparg >> (i * 8)) & 0xFF); - sourceMapBuilder.appendLocation(location.startLine, location.startColumn, location.endLine, location.endColumn); - } - buf.write(opcode.ordinal()); - buf.write(oparg & 0xFF); - if (opcode.argLength > 1) { - assert instr.followingArgs.length == opcode.argLength - 1; - for (int i = 0; i < instr.followingArgs.length; i++) { - buf.write(instr.followingArgs[i]); - } - } - } - } - - private static U[] orderedKeys(HashMap map, U[] empty, int offset, com.oracle.graal.python.util.Function convertor) { - if (map.isEmpty()) { - return empty; - } - U[] ary = Arrays.copyOf(empty, map.size()); - for (Map.Entry e : map.entrySet()) { - ary[e.getValue() - offset] = convertor.apply(e.getKey()); - } - return ary; - } - - private static T[] orderedKeys(HashMap map, T[] empty) { - return orderedKeys(map, empty, 0, i -> i); - } - - private static U[] orderedKeys(HashMap map, U[] empty, com.oracle.graal.python.util.Function convertor) { - return orderedKeys(map, empty, 0, convertor); - } - - private static long[] orderedLong(HashMap map) { - if (map.isEmpty()) { - return EMPTY_LONG_ARRAY; - } - long[] ary = new long[map.size()]; - for (Map.Entry e : map.entrySet()) { - ary[e.getValue()] = e.getKey(); - } - return ary; - } - - void pushBlock(BlockInfo info) { - info.outer = blockInfo; - blockInfo = info; - } - - void popBlock() { - blockInfo = blockInfo.outer; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java index 7fa2a62012..444e803669 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -40,238 +40,31 @@ */ package com.oracle.graal.python.compiler; -import static com.oracle.graal.python.compiler.CompilationScope.AsyncFunction; -import static com.oracle.graal.python.compiler.CompilationScope.Class; -import static com.oracle.graal.python.compiler.CompilationScope.Function; -import static com.oracle.graal.python.compiler.CompilationScope.Lambda; -import static com.oracle.graal.python.compiler.CompilationScope.TypeParams; -import static com.oracle.graal.python.compiler.OpCodes.ADD_TO_COLLECTION; -import static com.oracle.graal.python.compiler.OpCodes.ASYNCGEN_WRAP; -import static com.oracle.graal.python.compiler.OpCodes.BINARY_OP; -import static com.oracle.graal.python.compiler.OpCodes.BINARY_SUBSCR; -import static com.oracle.graal.python.compiler.OpCodes.BUILD_SLICE; -import static com.oracle.graal.python.compiler.OpCodes.CALL_COMPREHENSION; -import static com.oracle.graal.python.compiler.OpCodes.CALL_FUNCTION; -import static com.oracle.graal.python.compiler.OpCodes.CALL_FUNCTION_KW; -import static com.oracle.graal.python.compiler.OpCodes.CALL_FUNCTION_VARARGS; -import static com.oracle.graal.python.compiler.OpCodes.CALL_METHOD; -import static com.oracle.graal.python.compiler.OpCodes.CALL_METHOD_VARARGS; -import static com.oracle.graal.python.compiler.OpCodes.CLOSURE_FROM_STACK; -import static com.oracle.graal.python.compiler.OpCodes.COLLECTION_ADD_COLLECTION; -import static com.oracle.graal.python.compiler.OpCodes.COLLECTION_ADD_STACK; -import static com.oracle.graal.python.compiler.OpCodes.COLLECTION_FROM_COLLECTION; -import static com.oracle.graal.python.compiler.OpCodes.COLLECTION_FROM_STACK; -import static com.oracle.graal.python.compiler.OpCodes.COPY_DICT_WITHOUT_KEYS; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_ATTR; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_DEREF; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_FAST; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_GLOBAL; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_NAME; -import static com.oracle.graal.python.compiler.OpCodes.DELETE_SUBSCR; -import static com.oracle.graal.python.compiler.OpCodes.DUP_TOP; -import static com.oracle.graal.python.compiler.OpCodes.END_ASYNC_FOR; -import static com.oracle.graal.python.compiler.OpCodes.END_EXC_HANDLER; -import static com.oracle.graal.python.compiler.OpCodes.EXIT_AWITH; -import static com.oracle.graal.python.compiler.OpCodes.EXIT_WITH; -import static com.oracle.graal.python.compiler.OpCodes.FORMAT_VALUE; -import static com.oracle.graal.python.compiler.OpCodes.FOR_ITER; -import static com.oracle.graal.python.compiler.OpCodes.FROZENSET_FROM_LIST; -import static com.oracle.graal.python.compiler.OpCodes.GET_AEXIT_CORO; -import static com.oracle.graal.python.compiler.OpCodes.GET_AITER; -import static com.oracle.graal.python.compiler.OpCodes.GET_ANEXT; -import static com.oracle.graal.python.compiler.OpCodes.GET_AWAITABLE; -import static com.oracle.graal.python.compiler.OpCodes.GET_ITER; -import static com.oracle.graal.python.compiler.OpCodes.GET_LEN; -import static com.oracle.graal.python.compiler.OpCodes.GET_YIELD_FROM_ITER; -import static com.oracle.graal.python.compiler.OpCodes.IMPORT_FROM; -import static com.oracle.graal.python.compiler.OpCodes.IMPORT_NAME; -import static com.oracle.graal.python.compiler.OpCodes.IMPORT_STAR; -import static com.oracle.graal.python.compiler.OpCodes.JUMP_BACKWARD; -import static com.oracle.graal.python.compiler.OpCodes.JUMP_FORWARD; -import static com.oracle.graal.python.compiler.OpCodes.JUMP_IF_FALSE_OR_POP; -import static com.oracle.graal.python.compiler.OpCodes.JUMP_IF_TRUE_OR_POP; -import static com.oracle.graal.python.compiler.OpCodes.KWARGS_DICT_MERGE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_ASSERTION_ERROR; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_ATTR; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_BIGINT; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_BUILD_CLASS; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_BYTE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_BYTES; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_CLOSURE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_COMPLEX; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_CONST; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_CONST_COLLECTION; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_DEREF; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_DOUBLE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_ELLIPSIS; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_FALSE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_FAST; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_FROM_DICT_OR_DEREF; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_FROM_DICT_OR_GLOBALS; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_GLOBAL; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_INT; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_LOCALS; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_LONG; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_METHOD; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_NAME; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_NONE; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_STRING; -import static com.oracle.graal.python.compiler.OpCodes.LOAD_TRUE; -import static com.oracle.graal.python.compiler.OpCodes.MAKE_FUNCTION; -import static com.oracle.graal.python.compiler.OpCodes.MAKE_GENERIC; -import static com.oracle.graal.python.compiler.OpCodes.MAKE_KEYWORD; -import static com.oracle.graal.python.compiler.OpCodes.MAKE_TYPE_ALIAS; -import static com.oracle.graal.python.compiler.OpCodes.MAKE_TYPE_PARAM; -import static com.oracle.graal.python.compiler.OpCodes.MATCH_CLASS; -import static com.oracle.graal.python.compiler.OpCodes.MATCH_EXC_OR_JUMP; -import static com.oracle.graal.python.compiler.OpCodes.MATCH_KEYS; -import static com.oracle.graal.python.compiler.OpCodes.MATCH_MAPPING; -import static com.oracle.graal.python.compiler.OpCodes.MATCH_SEQUENCE; -import static com.oracle.graal.python.compiler.OpCodes.NOP; -import static com.oracle.graal.python.compiler.OpCodes.POP_AND_JUMP_IF_FALSE; -import static com.oracle.graal.python.compiler.OpCodes.POP_AND_JUMP_IF_TRUE; -import static com.oracle.graal.python.compiler.OpCodes.POP_EXCEPT; -import static com.oracle.graal.python.compiler.OpCodes.POP_TOP; -import static com.oracle.graal.python.compiler.OpCodes.PRINT_EXPR; -import static com.oracle.graal.python.compiler.OpCodes.PUSH_EXC_INFO; -import static com.oracle.graal.python.compiler.OpCodes.RAISE_VARARGS; -import static com.oracle.graal.python.compiler.OpCodes.RESUME_YIELD; -import static com.oracle.graal.python.compiler.OpCodes.RETURN_VALUE; -import static com.oracle.graal.python.compiler.OpCodes.ROT_N; -import static com.oracle.graal.python.compiler.OpCodes.ROT_THREE; -import static com.oracle.graal.python.compiler.OpCodes.ROT_TWO; -import static com.oracle.graal.python.compiler.OpCodes.SEND; -import static com.oracle.graal.python.compiler.OpCodes.SETUP_ANNOTATIONS; -import static com.oracle.graal.python.compiler.OpCodes.SETUP_AWITH; -import static com.oracle.graal.python.compiler.OpCodes.SETUP_WITH; -import static com.oracle.graal.python.compiler.OpCodes.STORE_ATTR; -import static com.oracle.graal.python.compiler.OpCodes.STORE_DEREF; -import static com.oracle.graal.python.compiler.OpCodes.STORE_FAST; -import static com.oracle.graal.python.compiler.OpCodes.STORE_GLOBAL; -import static com.oracle.graal.python.compiler.OpCodes.STORE_NAME; -import static com.oracle.graal.python.compiler.OpCodes.STORE_SUBSCR; -import static com.oracle.graal.python.compiler.OpCodes.THROW; -import static com.oracle.graal.python.compiler.OpCodes.TUPLE_FROM_LIST; -import static com.oracle.graal.python.compiler.OpCodes.UNARY_OP; -import static com.oracle.graal.python.compiler.OpCodes.UNPACK_EX; -import static com.oracle.graal.python.compiler.OpCodes.UNPACK_SEQUENCE; -import static com.oracle.graal.python.compiler.OpCodes.UNWRAP_EXC; -import static com.oracle.graal.python.compiler.OpCodes.YIELD_VALUE; -import static com.oracle.graal.python.compiler.SSTUtils.checkCaller; -import static com.oracle.graal.python.compiler.SSTUtils.checkCompare; -import static com.oracle.graal.python.compiler.SSTUtils.checkForbiddenArgs; -import static com.oracle.graal.python.compiler.SSTUtils.checkIndex; -import static com.oracle.graal.python.compiler.SSTUtils.checkSubscripter; -import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___TYPE_PARAMS__; -import static com.oracle.graal.python.nodes.StringLiterals.T_EMPTY_STRING; -import static com.oracle.graal.python.util.PythonUtils.arrayCopyOf; import static com.oracle.graal.python.util.PythonUtils.codePointsToInternedTruffleString; import static com.oracle.graal.python.util.PythonUtils.codePointsToTruffleString; -import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached; import java.util.ArrayList; -import java.util.Collections; import java.util.EnumSet; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.objects.PNone; import com.oracle.graal.python.compiler.OpCodes.CollectionBits; -import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; -import com.oracle.graal.python.lib.PyObjectRichCompareBool; import com.oracle.graal.python.pegparser.AbstractParser; import com.oracle.graal.python.pegparser.FutureFeature; import com.oracle.graal.python.pegparser.InputType; import com.oracle.graal.python.pegparser.Parser; import com.oracle.graal.python.pegparser.ParserCallbacks; import com.oracle.graal.python.pegparser.ParserCallbacks.ErrorType; -import com.oracle.graal.python.pegparser.ParserCallbacks.WarningType; -import com.oracle.graal.python.pegparser.scope.Scope; -import com.oracle.graal.python.pegparser.scope.ScopeEnvironment; import com.oracle.graal.python.pegparser.sst.AliasTy; -import com.oracle.graal.python.pegparser.sst.ArgTy; -import com.oracle.graal.python.pegparser.sst.ArgumentsTy; -import com.oracle.graal.python.pegparser.sst.BoolOpTy; -import com.oracle.graal.python.pegparser.sst.CmpOpTy; -import com.oracle.graal.python.pegparser.sst.ComprehensionTy; import com.oracle.graal.python.pegparser.sst.ConstantValue; -import com.oracle.graal.python.pegparser.sst.ConstantValue.Kind; -import com.oracle.graal.python.pegparser.sst.ExceptHandlerTy; -import com.oracle.graal.python.pegparser.sst.ExprContextTy; import com.oracle.graal.python.pegparser.sst.ExprTy; -import com.oracle.graal.python.pegparser.sst.ExprTy.Tuple; -import com.oracle.graal.python.pegparser.sst.KeywordTy; -import com.oracle.graal.python.pegparser.sst.MatchCaseTy; -import com.oracle.graal.python.pegparser.sst.ModTy; -import com.oracle.graal.python.pegparser.sst.OperatorTy; -import com.oracle.graal.python.pegparser.sst.PatternTy; -import com.oracle.graal.python.pegparser.sst.SSTNode; -import com.oracle.graal.python.pegparser.sst.SSTreeVisitor; import com.oracle.graal.python.pegparser.sst.StmtTy; -import com.oracle.graal.python.pegparser.sst.StmtTy.TypeAlias; -import com.oracle.graal.python.pegparser.sst.TypeIgnoreTy; -import com.oracle.graal.python.pegparser.sst.TypeParamTy; -import com.oracle.graal.python.pegparser.sst.TypeParamTy.ParamSpec; -import com.oracle.graal.python.pegparser.sst.TypeParamTy.TypeVar; -import com.oracle.graal.python.pegparser.sst.TypeParamTy.TypeVarTuple; -import com.oracle.graal.python.pegparser.sst.UnaryOpTy; -import com.oracle.graal.python.pegparser.sst.WithItemTy; -import com.oracle.graal.python.pegparser.tokenizer.SourceRange; -import com.oracle.graal.python.util.PythonUtils; -import com.oracle.graal.python.util.SuppressFBWarnings; -import com.oracle.truffle.api.memory.ByteArraySupport; -import com.oracle.truffle.api.strings.TruffleString; -/** - * Compiler for bytecode interpreter. - */ -public class Compiler implements SSTreeVisitor { +public final class Compiler { public static final int BYTECODE_VERSION = 32; - private final ParserCallbacks parserCallbacks; - - ScopeEnvironment env; - EnumSet flags = EnumSet.noneOf(Flags.class); - EnumSet futureFeatures = EnumSet.noneOf(FutureFeature.class); - int futureLineno = -1; - int optimizationLevel = 0; - int nestingLevel = 0; - CompilationUnit unit; - List stack = new ArrayList<>(); - private boolean interactive; - - private static class PatternContext { - ArrayList stores; - boolean allowIrrefutable; - ArrayList failPop; - int onTop; - } - - public enum Flags { - } - - public Compiler(ParserCallbacks parserCallbacks) { - this.parserCallbacks = parserCallbacks; - } - - @SuppressWarnings("hiding") - public CompilationUnit compile(ModTy mod, EnumSet flags, int optimizationLevel, EnumSet futureFeatures) { - this.flags = flags; - if (mod instanceof ModTy.Module) { - futureLineno = parseFuture(((ModTy.Module) mod).body, futureFeatures, parserCallbacks); - } else if (mod instanceof ModTy.Interactive) { - futureLineno = parseFuture(((ModTy.Interactive) mod).body, futureFeatures, parserCallbacks); - } - this.futureFeatures.addAll(futureFeatures); - this.env = ScopeEnvironment.analyze(mod, parserCallbacks, this.futureFeatures); - this.optimizationLevel = optimizationLevel; - enterScope("", CompilationScope.Module, mod); - mod.accept(this); - CompilationUnit topUnit = unit; - exitScope(); - return topUnit; + private Compiler() { } public static int parseFuture(StmtTy[] modBody, EnumSet futureFeatures, ParserCallbacks parserCallbacks) { @@ -293,8 +86,7 @@ public static int parseFuture(StmtTy[] modBody, EnumSet futureFea return lastFutureLine; } prevLine = line; - if (s instanceof StmtTy.ImportFrom) { - StmtTy.ImportFrom importFrom = (StmtTy.ImportFrom) s; + if (s instanceof StmtTy.ImportFrom importFrom) { if ("__future__".equals(importFrom.module)) { if (done) { throw parserCallbacks.onError(ErrorType.Syntax, s.getSourceRange(), "from __future__ imports must occur at the beginning of the file"); @@ -339,3830 +131,112 @@ private static void parseFutureFeatures(StmtTy.ImportFrom node, EnumSet quickeningStack = new ArrayList<>(); - - void pushOp(Instruction insn) { - if (insn.opcode == FOR_ITER) { - quickeningStack.add(insn); - return; - } - if (insn.target != null && insn.opcode.getNumberOfProducedStackItems(insn.arg, insn.followingArgs, true) > 0) { - // TODO support control flow - quickeningStack.clear(); - return; - } - int consumed = insn.opcode.getNumberOfConsumedStackItems(insn.arg, insn.followingArgs, false); - int produced = insn.opcode.getNumberOfProducedStackItems(insn.arg, insn.followingArgs, false); - byte canQuickenInputTypes = insn.opcode.canQuickenInputTypes(); - List inputs = null; - if (insn.opcode == BINARY_SUBSCR) { - // Asymmetric, needs to be handled separately - Instruction index = popQuickeningStack(); - popQuickeningStack(); // Ignore the collection, it's always object - if (index != null && (index.opcode.canQuickenOutputTypes() & QuickeningTypes.INT) != 0) { - index.quickenOutput = true; - insn.quickeningGeneralizeList = List.of(index); - } - quickeningStack.add(insn); - return; - } else if (insn.opcode == STORE_SUBSCR) { - // Asymmetric, needs to be handled separately - Instruction index = popQuickeningStack(); - popQuickeningStack(); // Ignore the collection, it's always object - Instruction value = popQuickeningStack(); - if (index != null && (index.opcode.canQuickenOutputTypes() & QuickeningTypes.INT) != 0) { - index.quickenOutput = true; - if (value != null && (value.opcode.canQuickenOutputTypes() & canQuickenInputTypes) != 0) { - value.quickenOutput = true; - insn.quickeningGeneralizeList = List.of(value, index); - } else { - insn.quickeningGeneralizeList = List.of(index); - } + private static Object findDocstring(StmtTy[] body) { + if (body != null && body.length > 0 && body[0] instanceof StmtTy.Expr stmt && stmt.value instanceof ExprTy.Constant expr) { + ConstantValue value = expr.value; + if (value.kind == ConstantValue.Kind.CODEPOINTS) { + return codePointsToTruffleString(value.getCodePoints()); } - return; - } - if (consumed > 0) { - if (canQuickenInputTypes != 0) { - inputs = new ArrayList<>(consumed); - for (int i = 0; i < consumed; i++) { - Instruction input = popQuickeningStack(); - if (input == null) { - /* - * This happens when we cleared the stack after a jump or other - * not-yet-supported scenario - */ - canQuickenInputTypes = 0; - break; - } - canQuickenInputTypes &= input.opcode.canQuickenOutputTypes(); - inputs.add(input); - } - } else { - for (int i = 0; i < consumed; i++) { - popQuickeningStack(); - } - } - } - if (produced > 0) { - if (produced > 1) { - // TODO instructions that produce multiple values? - quickeningStack.clear(); - return; - } - quickeningStack.add(insn); - } - if (canQuickenInputTypes != 0) { - insn.quickeningGeneralizeList = inputs; - } - if (canQuickenInputTypes != 0 && inputs != null) { - for (int i = 0; i < inputs.size(); i++) { - inputs.get(i).quickenOutput = true; - } - } - } - - Instruction popQuickeningStack() { - if (quickeningStack.size() == 0) { - return null; } - return quickeningStack.remove(quickeningStack.size() - 1); - } - - // helpers - - private void enterScope(String name, CompilationScope scopeType, SSTNode node) { - enterScope(name, scopeType, node, 0, 0, 0, false, false, node.getSourceRange()); - } - - private void enterScope(String name, CompilationScope scope, Object key, ArgumentsTy args, SourceRange startLocation) { - int argc, pargc, kwargc; - boolean splat, kwSplat; - if (args == null) { - argc = pargc = kwargc = 0; - splat = kwSplat = false; - } else { - argc = args.args == null ? 0 : args.args.length; - pargc = args.posOnlyArgs == null ? 0 : args.posOnlyArgs.length; - kwargc = args.kwOnlyArgs == null ? 0 : args.kwOnlyArgs.length; - splat = args.varArg != null; - kwSplat = args.kwArg != null; - } - enterScope(name, scope, key, argc, pargc, kwargc, splat, kwSplat, startLocation); + return null; } - private void enterScope(String name, CompilationScope scopeType, Object key, int argc, int pargc, int kwargc, - boolean hasSplat, boolean hasKwSplat, SourceRange startLocation) { - if (unit != null) { - stack.add(unit); - } - - unit = new CompilationUnit(scopeType, env.lookupScope(key), name, getNewScopeQualName(name, scopeType), unit, argc, pargc, kwargc, - hasSplat, hasKwSplat, startLocation, futureFeatures); - nestingLevel++; - } + public static final class ConstantCollection { + public final Object collection; + public final int elementType; - private String getNewScopeQualName(String name, CompilationScope scopeType) { - CompilationUnit parent = unit; - int scopeDepth = stack.size(); - if (scopeDepth > 1 && parent != null) { - if (parent.scopeType == TypeParams) { - parent = stack.get(scopeDepth - 2); - if (scopeDepth == 2) { - return name; - } - } - if (!(EnumSet.of(Function, AsyncFunction, Class).contains(scopeType) && - parent.scope.getUseOfName(ScopeEnvironment.mangle(parent.privateName, name)).contains(Scope.DefUse.GlobalExplicit))) { - String base; - if (EnumSet.of(Function, AsyncFunction, Lambda).contains(parent.scopeType)) { - base = parent.qualName + "."; - } else { - base = parent.qualName; - } - return base + "." + name; - } + ConstantCollection(Object collection, int elementType) { + this.collection = collection; + this.elementType = elementType; } - return name; } - private void exitScope() { - nestingLevel--; - if (!stack.isEmpty()) { - unit = stack.remove(stack.size() - 1); - } else { - unit = null; + public static ConstantCollection tryCollectConstantCollection(ExprTy[] elements) { + if (elements == null || elements.length == 0) { + return null; } - } - - protected final void checkForbiddenName(String id, ExprContextTy context) { - SSTUtils.checkForbiddenName(parserCallbacks, unit.currentLocation, id, context); - } - private boolean containsAnnotations(StmtTy[] stmts) { - if (stmts == null) { - return false; - } - for (StmtTy stmt : stmts) { - if (containsAnnotations(stmt)) { - return true; - } - } - return false; - } + int constantType = -1; + List constants = new ArrayList<>(); - private boolean containsAnnotations(StmtTy stmt) { - if (stmt instanceof StmtTy.AnnAssign) { - return true; - } else if (stmt instanceof StmtTy.For forStmt) { - return containsAnnotations(forStmt.body) || containsAnnotations(forStmt.orElse); - } else if (stmt instanceof StmtTy.While whileStmt) { - return containsAnnotations(whileStmt.body) || containsAnnotations(whileStmt.orElse); - } else if (stmt instanceof StmtTy.If ifStmt) { - return containsAnnotations(ifStmt.body) || containsAnnotations(ifStmt.orElse); - } else if (stmt instanceof StmtTy.With withStmt) { - return containsAnnotations(withStmt.body); - } else if (stmt instanceof StmtTy.Try tryStmt) { - if (tryStmt.handlers != null) { - for (ExceptHandlerTy h : tryStmt.handlers) { - if (containsAnnotations(((ExceptHandlerTy.ExceptHandler) h).body)) { - return true; - } - } - } - return containsAnnotations(tryStmt.body) || containsAnnotations(tryStmt.finalBody) || containsAnnotations(tryStmt.orElse); - } else if (stmt instanceof StmtTy.TryStar tryStmt) { - if (tryStmt.handlers != null) { - for (ExceptHandlerTy h : tryStmt.handlers) { - if (containsAnnotations(((ExceptHandlerTy.ExceptHandler) h).body)) { - return true; + for (ExprTy e : elements) { + if (e instanceof ExprTy.Constant c) { + if (c.value.kind == ConstantValue.Kind.BOOLEAN) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_BOOLEAN); + constants.add(c.value.getBoolean()); + } else if (c.value.kind == ConstantValue.Kind.LONG) { + long val = c.value.getLong(); + if (val == (int) val) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_INT); + } else { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_LONG); } - } - } - return containsAnnotations(tryStmt.body) || containsAnnotations(tryStmt.finalBody) || containsAnnotations(tryStmt.orElse); - } - return false; - } - - private Void addOp(OpCodes code) { - addOp(code, 0, null, unit.currentLocation); - return null; - } - - private void addOp(OpCodes code, Block target) { - addOp(code, target, null); - } - - private void addConditionalJump(OpCodes code, Block target) { - int profileIndex = unit.conditionProfileCount; - unit.conditionProfileCount += 2; - /* - * Intentionally ignoring overflow in the conversion of the index. If the unit has more than - * 2^16 conditionals it most likely wouldn't compile anyway, so there's not much harm if - * there's some false sharing of profiles. - */ - byte[] followingArgs = new byte[2]; - ByteArraySupport.littleEndian().putShort(followingArgs, 0, (short) profileIndex); - addOp(code, target, followingArgs); - } - - private void addOp(OpCodes code, Block target, byte[] followingArgs) { - Block b = unit.currentBlock; - Instruction insn = new Instruction(code, 0, followingArgs, target, unit.currentLocation); - b.instr.add(insn); - pushOp(insn); - } - - private Void addOp(OpCodes code, int arg) { - addOp(code, arg, null, unit.currentLocation); - return null; - } - - private Void addOp(OpCodes code, int arg, byte[] followingArgs) { - addOp(code, arg, followingArgs, unit.currentLocation); - return null; - } - - private void addOp(OpCodes code, int arg, byte[] followingArgs, SourceRange location) { - assert code != YIELD_VALUE || unit.scope.isGenerator() || unit.scope.isCoroutine(); - Block b = unit.currentBlock; - Instruction insn = new Instruction(code, arg, followingArgs, null, location); - b.instr.add(insn); - pushOp(insn); - } - - private Void addOpName(OpCodes code, HashMap dict, String name) { - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, name); - addOpObject(code, dict, mangled); - return null; - } - - private void addOpObject(OpCodes code, HashMap dict, T obj) { - int arg = addObject(dict, obj); - addOp(code, arg); - } - - private void addDerefVariableOpcode(ExprContextTy ctx, int idx) { - switch (ctx) { - case Load: - if (unit.scope.isClass()) { - addOp(LOAD_LOCALS); - addOp(LOAD_FROM_DICT_OR_DEREF, idx); - } else if (unit.scope.canSeeClassScope()) { - addOp(LOAD_DEREF, addObject(unit.freevars, "__classdict__")); - addOp(LOAD_FROM_DICT_OR_DEREF, idx); + constants.add(val); + } else if (c.value.kind == ConstantValue.Kind.DOUBLE) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_DOUBLE); + constants.add(c.value.getDouble()); + } else if (c.value.kind == ConstantValue.Kind.CODEPOINTS) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constants.add(codePointsToInternedTruffleString(c.value.getCodePoints())); + } else if (c.value.kind == ConstantValue.Kind.NONE) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constants.add(PNone.NONE); } else { - addOp(LOAD_DEREF, idx); + return null; } - break; - case Store: - addOp(STORE_DEREF, idx); - break; - case Del: - addOp(DELETE_DEREF, idx); - break; + } else { + return null; + } } - } - - private void addFastVariableOpcode(ExprContextTy ctx, int idx) { - switch (ctx) { - case Load: - addOp(LOAD_FAST, idx); - break; - case Store: - addOp(STORE_FAST, idx); - break; - case Del: - addOp(DELETE_FAST, idx); + Object newConstant = null; + switch (constantType) { + case CollectionBits.ELEMENT_OBJECT: + newConstant = constants.toArray(new Object[0]); break; - } - } - - private void addGlobalVariableOpcode(ExprContextTy ctx, int idx, boolean isImplicitScope) { - switch (ctx) { - case Load: - if (unit.scope.canSeeClassScope() && isImplicitScope) { - addOp(LOAD_DEREF, addObject(unit.freevars, "__classdict__")); - addOp(LOAD_FROM_DICT_OR_GLOBALS, idx); - } else { - addOp(LOAD_GLOBAL, idx); + case CollectionBits.ELEMENT_INT: { + int[] a = new int[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (int) (long) constants.get(i); } + newConstant = a; break; - case Store: - addOp(STORE_GLOBAL, idx); - break; - case Del: - addOp(DELETE_GLOBAL, idx); - break; - } - } - - private void addNameVariableOpcode(ExprContextTy ctx, int idx) { - switch (ctx) { - case Load: - if (unit.scope.isClass()) { - // TODO GR-61661 inlined comprehensions - addOp(LOAD_NAME, idx); - } else { - addOp(LOAD_NAME, idx); + } + case CollectionBits.ELEMENT_LONG: { + long[] a = new long[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (long) constants.get(i); } + newConstant = a; break; - case Store: - addOp(STORE_NAME, idx); - break; - case Del: - addOp(DELETE_NAME, idx); - break; - } - } - - private void addNameOp(String name, ExprContextTy ctx) { - checkForbiddenName(name, ctx); - - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, name); - EnumSet uses = unit.scope.getUseOfName(mangled); - - if (uses != null) { - if (uses.contains(Scope.DefUse.Free)) { - addDerefVariableOpcode(ctx, addObject(unit.freevars, mangled)); - return; - } else if (uses.contains(Scope.DefUse.Cell)) { - addDerefVariableOpcode(ctx, addObject(unit.cellvars, mangled)); - return; - } else if (uses.contains(Scope.DefUse.Local)) { - if (unit.scope.isFunction()) { - addFastVariableOpcode(ctx, addObject(unit.varnames, mangled)); - return; - } - } else if (uses.contains(Scope.DefUse.GlobalImplicit)) { - if (unit.scope.isFunction()) { - addGlobalVariableOpcode(ctx, addObject(unit.names, mangled), true); - return; - } - } else if (uses.contains(Scope.DefUse.GlobalExplicit)) { - addGlobalVariableOpcode(ctx, addObject(unit.names, mangled), false); - return; } - } - addNameVariableOpcode(ctx, addObject(unit.names, mangled)); - } - - private static int addObject(HashMap dict, T o) { - Integer v = dict.get(o); - if (v == null) { - v = dict.size(); - dict.put(o, v); - } - return v; - } - - private static TruffleString findDocstring(StmtTy[] body) { - if (body != null && body.length > 0) { - StmtTy stmt = body[0]; - if (stmt instanceof StmtTy.Expr) { - ExprTy expr = ((StmtTy.Expr) stmt).value; - if (expr instanceof ExprTy.Constant) { - ConstantValue value = ((ExprTy.Constant) expr).value; - if (value.kind == ConstantValue.Kind.CODEPOINTS) { - return codePointsToTruffleString(value.getCodePoints()); - } + case CollectionBits.ELEMENT_BOOLEAN: { + boolean[] a = new boolean[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (boolean) constants.get(i); } + newConstant = a; + break; } - } - return null; - } - - private TruffleString getDocstring(StmtTy[] body) { - if (optimizationLevel >= 2) { - return null; - } - return findDocstring(body); - } - - private SourceRange setLocation(SourceRange location) { - SourceRange savedLocation = unit.currentLocation; - unit.currentLocation = location; - return savedLocation; - } - - private SourceRange setLocation(SSTNode node) { - return setLocation(node.getSourceRange()); - } - - private class Collector { - protected final int typeBits; - protected final int stackItemsPerItem; - protected int stackItems = 0; - protected boolean collectionOnStack = false; - - public Collector(int typeBits) { - this.typeBits = typeBits; - stackItemsPerItem = typeBits == CollectionBits.KIND_DICT ? 2 : 1; - } - - public Collector(int typeBits, int stackItems) { - this(typeBits); - this.stackItems = stackItems; - } - - public void appendItem() { - stackItems += stackItemsPerItem; - if (stackItems + stackItemsPerItem > CollectionBits.KIND_MASK) { - doFlushStack(); - } - } - - public void flushStackIfNecessary() { - if (stackItems > 0) { - doFlushStack(); - } - } - - private void doFlushStack() { - assert stackItems <= CollectionBits.KIND_MASK; - if (collectionOnStack) { - addOp(COLLECTION_ADD_STACK, typeBits | stackItems); - } else { - addOp(COLLECTION_FROM_STACK, typeBits | stackItems); - } - collectionOnStack = true; - stackItems = 0; - } - - public void appendCollection() { - assert stackItems == 0; - if (collectionOnStack) { - addOp(COLLECTION_ADD_COLLECTION, typeBits); - } else { - addOp(COLLECTION_FROM_COLLECTION, typeBits); - } - collectionOnStack = true; - } - - public void finishCollection() { - if (stackItems > 0 || !collectionOnStack) { - doFlushStack(); - } - } - - public boolean isEmpty() { - return stackItems == 0 && !collectionOnStack; - } - } - - private class KwargsMergingDictCollector extends Collector { - /* - * Keyword arguments get evaluated in "groups", where a group is a contiguous sequence of - * named keyword arguments or a keyword-splat. For example, in - * - * f(a=2, b=3, **kws, c=4, d=5, **more_kws) - * - * there are 4 groups. Each group is evaluated and only then merged with the existing - * keyword arguments. The merge step is where duplicate keyword arguments are checked. - * - * A call can have an arbitrarily long sequence of named keyword arguments, so we flush them - * from the stack and collect them into an intermediate dict. We cannot eagerly merge them - * with the existing keyword arguments since that could trigger a duplication check before - * all of the arguments in the group have been evaluated. For example, in - * - * f(**{'a': 2}, a=3, b=4, ..., z=function_with_side_effects()) - * - * we cannot merge "a=3" with the existing keywords dict (and consequently raise a - * TypeError) until we compute "z". - */ - private boolean namedKeywordDictOnStack = false; - - public KwargsMergingDictCollector(OpCodes callOp) { - super(CollectionBits.KIND_DICT); - /* - * We're making assumptions about the stack layout below this instruction to obtain the - * callable for error reporting. If we ever add more keywords call instructions, we need - * to adjust the implementation to be able to get the callable. - */ - assert callOp == CALL_FUNCTION_KW; - } - - @Override - public void appendItem() { - stackItems += stackItemsPerItem; - if (stackItems + stackItemsPerItem > CollectionBits.KIND_MASK) { - collectIntoNamedKeywordDict(); - } - } - - @Override - public void flushStackIfNecessary() { - if (stackItems == 0 && !namedKeywordDictOnStack) { - // Nothing pending to be merged. - return; - } - - if (stackItems > 0) { - collectIntoNamedKeywordDict(); - } - if (collectionOnStack) { - // If there's already a collection on the stack, merge it with the dict we just - // finished creating. - addOp(KWARGS_DICT_MERGE); - } - collectionOnStack = true; - namedKeywordDictOnStack = false; - } - - protected void collectIntoNamedKeywordDict() { - if (namedKeywordDictOnStack) { - // Just add the keywords to the existing dict. Since we statically check for - // duplicate named keywords, we don't need to worry about duplicates in this dict. - addOp(COLLECTION_ADD_STACK, typeBits | stackItems); - } else { - // Create a new dict. - addOp(COLLECTION_FROM_STACK, typeBits | stackItems); - namedKeywordDictOnStack = true; - } - stackItems = 0; - } - - @Override - public void appendCollection() { - assert stackItems == 0; - assert !namedKeywordDictOnStack; - if (collectionOnStack) { - addOp(KWARGS_DICT_MERGE); - } else { - addOp(COLLECTION_FROM_COLLECTION, typeBits); - } - collectionOnStack = true; - } - - @Override - public void finishCollection() { - flushStackIfNecessary(); - } - - @Override - public boolean isEmpty() { - return stackItems == 0 || !namedKeywordDictOnStack || !collectionOnStack; - } - } - - /** - * After these bytecodes are executed, there will a Python collection on the stack containing - * all the arguments. - *

- * We push individual arguments to the stack and when we reach certain size threshold, we emit - * instruction to collect N stack items (N is immediate operand) to the collection, which will - * now be on TOS. Next time this happens we emit instruction that adds the stack items to the - * collection. This way we accumulate the arguments into the collection and also never overflow - * certain stack size. - *

- * When we encounter starred argument: we accumulate what we have on stack to the collection and - * then add the values in the starred arg to it. - */ - private void collectIntoArray(ExprTy[] nodes, int bits, int alreadyOnStack) { - Collector collector = new Collector(bits, alreadyOnStack); - if (nodes != null) { - for (ExprTy e : nodes) { - if (e instanceof ExprTy.Starred) { - // splat - collector.flushStackIfNecessary(); - ((ExprTy.Starred) e).value.accept(this); - collector.appendCollection(); - } else { - e.accept(this); - collector.appendItem(); + case CollectionBits.ELEMENT_DOUBLE: { + double[] a = new double[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (double) constants.get(i); } + newConstant = a; + break; } } - collector.finishCollection(); - } - - private void collectIntoArray(ExprTy[] nodes, int bits) { - collectIntoArray(nodes, bits, 0); + return new ConstantCollection(newConstant, constantType); } - private void collectIntoDict(ExprTy[] keys, ExprTy[] values) { - Collector collector = new Collector(CollectionBits.KIND_DICT); - if (keys != null) { - assert keys.length == values.length; - for (int i = 0; i < keys.length; i++) { - ExprTy key = keys[i]; - ExprTy value = values[i]; - if (key == null) { - // splat - collector.flushStackIfNecessary(); - value.accept(this); - collector.appendCollection(); - } else { - key.accept(this); - value.accept(this); - collector.appendItem(); - } - } + private static int determineConstantType(int existing, int type) { + if (existing == -1 || existing == type) { + return type; } - collector.finishCollection(); - } - - protected final void validateKeywords(KeywordTy[] keywords) { - for (int i = 0; i < keywords.length; i++) { - if (keywords[i].arg != null) { - checkForbiddenName(keywords[i].arg, ExprContextTy.Store); - for (int j = i + 1; j < keywords.length; j++) { - if (keywords[i].arg.equals(keywords[j].arg)) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "keyword argument repeated: " + keywords[i].arg); - } - } - } - } - } - - private void collectKeywords(KeywordTy[] keywords, OpCodes callOp) { - validateKeywords(keywords); - boolean hasSplat = false; - for (KeywordTy k : keywords) { - if (k.arg == null) { - hasSplat = true; - break; - } - } - if (!hasSplat) { - Collector collector = new Collector(CollectionBits.KIND_KWORDS); - for (KeywordTy k : keywords) { - k.accept(this); - collector.appendItem(); - } - collector.finishCollection(); - } else if (keywords.length == 1) { - // Just one splat, no need for merging - keywords[0].value.accept(this); - addOp(COLLECTION_FROM_COLLECTION, CollectionBits.KIND_KWORDS); - } else { - /* - * We need to emit bytecodes for proper keywords merging with checking for duplicate - * keys. We accumulate them in an intermediate dict. - */ - Collector collector = new KwargsMergingDictCollector(callOp); - for (KeywordTy k : keywords) { - if (k.arg == null) { - // splat - collector.flushStackIfNecessary(); - k.value.accept(this); - collector.appendCollection(); - } else { - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(k.arg))); - k.value.accept(this); - collector.appendItem(); - } - } - collector.finishCollection(); - addOp(COLLECTION_FROM_COLLECTION, CollectionBits.KIND_KWORDS); - } - } - - private void makeClosure(CodeUnit code, int makeFunctionFlags) { - int newFlags = makeFunctionFlags; - if (code.freevars.length > 0) { - // add the closure - for (TruffleString tfv : code.freevars) { - String fv = tfv.toJavaStringUncached(); - // special case for class scopes - int arg; - if (unit.scopeType == CompilationScope.Class && ("__class__".equals(fv) || "__classdict__".equals(fv)) || unit.scope.getUseOfName(fv).contains(Scope.DefUse.Cell)) { - arg = unit.cellvars.get(fv); - } else { - arg = unit.freevars.get(fv); - } - addOp(LOAD_CLOSURE, arg); - } - addOp(CLOSURE_FROM_STACK, code.freevars.length); - newFlags |= OpCodes.MakeFunctionFlags.HAS_CLOSURE; - } - addOp(MAKE_FUNCTION, addObject(unit.constants, code), new byte[]{(byte) newFlags}); - } - - // visiting - - private void visitBody(StmtTy[] stmts, boolean returnValue) { - if (stmts != null) { - if (unit.scope.isModule() && stmts.length > 0) { - /* - * Set current line number to the line number of first statement. This way line - * number for SETUP_ANNOTATIONS will always coincide with the line number of first - * "real" statement in module. If body is empty, then lineno will be set later in - * assemble. - */ - setLocation(stmts[0]); - } - if (containsAnnotations(stmts)) { - addOp(SETUP_ANNOTATIONS); - } - if (stmts.length > 0) { - int i = 0; - TruffleString docstring = getDocstring(stmts); - if (docstring != null) { - i++; - StmtTy.Expr stmt = (StmtTy.Expr) stmts[0]; - stmt.value.accept(this); - addNameOp("__doc__", ExprContextTy.Store); - } - for (; i < stmts.length - 1; i++) { - stmts[i].accept(this); - } - /* - * To support interop eval we need to return the value of the last statement even if - * we're in file mode. Also used when parsing with arguments. - */ - StmtTy lastStatement = stmts[stmts.length - 1]; - if (returnValue && lastStatement instanceof StmtTy.Expr) { - ExprTy value = ((StmtTy.Expr) lastStatement).value; - value.accept(this); - setLocation(value); - addOp(RETURN_VALUE); - return; - } else { - lastStatement.accept(this); - } - } - } - if (returnValue) { - addOp(LOAD_NONE); - addOp(RETURN_VALUE); - } - } - - @Override - public Void visit(AliasTy node) { - addOp(LOAD_BYTE, 0); - addOp(LOAD_CONST, addObject(unit.constants, PythonUtils.EMPTY_TRUFFLESTRING_ARRAY)); - addOpName(IMPORT_NAME, unit.names, node.name); - if (node.asName != null) { - int dotIdx = node.name.indexOf('.'); - if (dotIdx >= 0) { - while (true) { - int pos = dotIdx + 1; - dotIdx = node.name.indexOf('.', pos); - int end = dotIdx >= 0 ? dotIdx : node.name.length(); - String attr = node.name.substring(pos, end); - addOpObject(IMPORT_FROM, unit.names, attr); - if (dotIdx < 0) { - break; - } - addOp(ROT_TWO); - addOp(POP_TOP); - } - addNameOp(node.asName, ExprContextTy.Store); - addOp(POP_TOP); - } else { - addNameOp(node.asName, ExprContextTy.Store); - } - } else { - int dotIdx = node.name.indexOf('.'); - if (dotIdx >= 0) { - addNameOp(node.name.substring(0, dotIdx), ExprContextTy.Store); - } else { - addNameOp(node.name, ExprContextTy.Store); - } - } - return null; - } - - @Override - public Void visit(ArgTy node) { - throw new IllegalStateException("Should not be visited"); - } - - @Override - public Void visit(ArgumentsTy node) { - throw new IllegalStateException("Should not be visited"); - } - - @Override - public Void visit(ComprehensionTy node) { - throw new IllegalStateException("Should not be visited"); - } - - @Override - public Void visit(ExprTy.Attribute node) { - SourceRange savedLocation = setLocation(node); - try { - node.value.accept(this); - switch (node.context) { - case Store: - checkForbiddenName(node.attr, node.context); - return addOpName(STORE_ATTR, unit.names, node.attr); - case Del: - return addOpName(DELETE_ATTR, unit.names, node.attr); - case Load: - default: - return addOpName(LOAD_ATTR, unit.names, node.attr); - } - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Await node) { - // TODO if !IS_TOP_LEVEL_AWAIT - // TODO handle await in comprehension correctly (currently, it is always allowed) - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'await' outside function"); - } - if (unit.scopeType != CompilationScope.AsyncFunction && unit.scopeType != CompilationScope.Comprehension) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'await' outside async function"); - } - SourceRange savedLocation = setLocation(node); - try { - node.value.accept(this); - addOp(GET_AWAITABLE); - addOp(LOAD_NONE); - addYieldFrom(); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.BinOp node) { - SourceRange savedLocation = setLocation(node); - try { - node.left.accept(this); - node.right.accept(this); - switch (node.op) { - case Add: - addOp(BINARY_OP, BinaryOps.ADD.ordinal()); - break; - case Sub: - addOp(BINARY_OP, BinaryOps.SUB.ordinal()); - break; - case Mult: - addOp(BINARY_OP, BinaryOps.MUL.ordinal()); - break; - case MatMult: - addOp(BINARY_OP, BinaryOps.MATMUL.ordinal()); - break; - case Div: - addOp(BINARY_OP, BinaryOps.TRUEDIV.ordinal()); - break; - case Mod: - addOp(BINARY_OP, BinaryOps.MOD.ordinal()); - break; - case Pow: - addOp(BINARY_OP, BinaryOps.POW.ordinal()); - break; - case LShift: - addOp(BINARY_OP, BinaryOps.LSHIFT.ordinal()); - break; - case RShift: - addOp(BINARY_OP, BinaryOps.RSHIFT.ordinal()); - break; - case BitOr: - addOp(BINARY_OP, BinaryOps.OR.ordinal()); - break; - case BitXor: - addOp(BINARY_OP, BinaryOps.XOR.ordinal()); - break; - case BitAnd: - addOp(BINARY_OP, BinaryOps.AND.ordinal()); - break; - case FloorDiv: - addOp(BINARY_OP, BinaryOps.FLOORDIV.ordinal()); - break; - default: - throw new IllegalStateException("Unknown binary operation " + node.op); - } - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.BoolOp node) { - SourceRange savedLocation = setLocation(node); - try { - Block end = new Block(); - ExprTy[] values = node.values; - OpCodes op; - if (node.op == BoolOpTy.And) { - op = JUMP_IF_FALSE_OR_POP; - } else { - op = JUMP_IF_TRUE_OR_POP; - } - for (int i = 0; i < values.length - 1; i++) { - ExprTy v = values[i]; - v.accept(this); - addConditionalJump(op, end); - } - values[values.length - 1].accept(this); - unit.useNextBlock(end); - return null; - } finally { - setLocation(savedLocation); - } - } - - private static boolean isAttributeLoad(ExprTy node) { - return node instanceof ExprTy.Attribute && ((ExprTy.Attribute) node).context == ExprContextTy.Load; - } - - private static boolean hasOnlyPlainArgs(ExprTy[] args, KeywordTy[] keywords) { - if (keywords.length > 0) { - return false; - } - for (ExprTy arg : args) { - if (arg instanceof ExprTy.Starred) { - return false; - } - } - return true; - } - - @Override - public Void visit(ExprTy.Call node) { - SourceRange savedLocation = setLocation(node); - checkCaller(parserCallbacks, node.func); - try { - // n.b.: we do things completely different from python for calls - OpCodes op = CALL_FUNCTION_VARARGS; - int opArg = 0; - boolean shortCall; - final ExprTy func = node.func; - final ExprTy[] args = node.args; - final KeywordTy[] keywords = node.keywords; - - if (isAttributeLoad(func) && keywords.length == 0) { - ((ExprTy.Attribute) func).value.accept(this); - op = CALL_METHOD_VARARGS; - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, ((ExprTy.Attribute) func).attr); - opArg = addObject(unit.names, mangled); - addOp(LOAD_METHOD, opArg); - shortCall = args.length <= 3; - } else { - func.accept(this); - shortCall = args.length <= 4; - } - - if (hasOnlyPlainArgs(args, keywords) && shortCall) { - if (op == CALL_METHOD_VARARGS) { - op = CALL_METHOD; - } else { - op = CALL_FUNCTION; - } - opArg = args.length; - // fast calls without extra arguments array - visitSequence(args); - return addOp(op, opArg); - } else { - if (op == CALL_METHOD_VARARGS) { - // the receiver is below the method on the stack. swap them so it can be - // collected into the argument array - addOp(OpCodes.ROT_TWO); - } - return callHelper(op, opArg, 0, args, keywords); - } - } finally { - setLocation(savedLocation); - } - } - - private Void callHelper(OpCodes op, int opArg, int alreadyOnStack, ExprTy[] args, KeywordTy[] keywords) { - collectIntoArray(args, CollectionBits.KIND_OBJECT, op == CALL_METHOD_VARARGS ? 1 + alreadyOnStack : alreadyOnStack); - if (keywords.length > 0) { - assert op == CALL_FUNCTION_VARARGS; - collectKeywords(keywords, CALL_FUNCTION_KW); - return addOp(CALL_FUNCTION_KW); - } else if (op == CALL_METHOD_VARARGS) { - return addOp(op); - } else { - return addOp(op, opArg); - } - } - - private void addCompareOp(CmpOpTy op) { - switch (op) { - case Eq: - addOp(BINARY_OP, BinaryOps.EQ.ordinal()); - break; - case NotEq: - addOp(BINARY_OP, BinaryOps.NE.ordinal()); - break; - case Lt: - addOp(BINARY_OP, BinaryOps.LT.ordinal()); - break; - case LtE: - addOp(BINARY_OP, BinaryOps.LE.ordinal()); - break; - case Gt: - addOp(BINARY_OP, BinaryOps.GT.ordinal()); - break; - case GtE: - addOp(BINARY_OP, BinaryOps.GE.ordinal()); - break; - case Is: - addOp(BINARY_OP, BinaryOps.IS.ordinal()); - break; - case IsNot: - addOp(BINARY_OP, BinaryOps.IS.ordinal()); - addOp(UNARY_OP, UnaryOps.NOT.ordinal()); - break; - case In: - addOp(BINARY_OP, BinaryOps.IN.ordinal()); - break; - case NotIn: - addOp(BINARY_OP, BinaryOps.IN.ordinal()); - addOp(UNARY_OP, UnaryOps.NOT.ordinal()); - break; - default: - throw new IllegalStateException("Unknown comparison operation " + op); - } - } - - @Override - public Void visit(ExprTy.Compare node) { - SourceRange savedLocation = setLocation(node); - checkCompare(parserCallbacks, node); - try { - node.left.accept(this); - if (node.comparators.length == 1) { - visitSequence(node.comparators); - addCompareOp(node.ops[0]); - } else { - Block cleanup = new Block(); - int i; - for (i = 0; i < node.comparators.length - 1; i++) { - node.comparators[i].accept(this); - addOp(DUP_TOP); - addOp(ROT_THREE); - addCompareOp(node.ops[i]); - addConditionalJump(JUMP_IF_FALSE_OR_POP, cleanup); - } - node.comparators[i].accept(this); - addCompareOp(node.ops[i]); - Block end = new Block(); - addOp(JUMP_FORWARD, end); - unit.useNextBlock(cleanup); - addOp(ROT_TWO); - addOp(POP_TOP); - unit.useNextBlock(end); - } - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Constant node) { - SourceRange savedLocation = setLocation(node); - try { - return addConstant(node.value); - } finally { - setLocation(savedLocation); - } - } - - private Void addConstant(ConstantValue value) { - switch (value.kind) { - case NONE: - return addOp(LOAD_NONE); - case ELLIPSIS: - return addOp(LOAD_ELLIPSIS); - case BOOLEAN: - return addOp(value.getBoolean() ? LOAD_TRUE : LOAD_FALSE); - case LONG: - return addLoadNumber(value.getLong()); - case DOUBLE: - return addOp(LOAD_DOUBLE, addObject(unit.primitiveConstants, Double.doubleToRawLongBits(value.getDouble()))); - case COMPLEX: - return addOp(LOAD_COMPLEX, addObject(unit.constants, value.getComplex())); - case BIGINTEGER: - return addOp(LOAD_BIGINT, addObject(unit.constants, value.getBigInteger())); - case CODEPOINTS: - return addOp(LOAD_STRING, addObject(unit.constants, codePointsToInternedTruffleString(value.getCodePoints()))); - case BYTES: - return addOp(LOAD_BYTES, addObject(unit.constants, value.getBytes())); - case TUPLE: - addConstantList(value.getTupleElements()); - return addOp(TUPLE_FROM_LIST); - case FROZENSET: - addConstantList(value.getFrozensetElements()); - return addOp(FROZENSET_FROM_LIST); - default: - throw new IllegalStateException("Unknown constant kind " + value.kind); - } - } - - private void addConstantList(ConstantValue[] values) { - Collector collector = new Collector(CollectionBits.KIND_LIST, 0); - for (ConstantValue v : values) { - addConstant(v); - collector.appendItem(); - } - collector.finishCollection(); - } - - private Void addLoadNumber(long value) { - if (value == (byte) value) { - return addOp(LOAD_BYTE, (byte) value); - } else if (value == (int) value) { - return addOp(LOAD_INT, addObject(unit.primitiveConstants, value)); - } else { - return addOp(LOAD_LONG, addObject(unit.primitiveConstants, value)); - } - } - - @Override - public Void visit(ExprTy.Dict node) { - SourceRange savedLocation = setLocation(node); - try { - collectIntoDict(node.keys, node.values); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.DictComp node) { - return visitComprehension(node, "", node.generators, node.key, node.value, ComprehensionType.DICT); - } - - @Override - public Void visit(ExprTy.FormattedValue node) { - SourceRange savedLocation = setLocation(node); - try { - node.value.accept(this); - int oparg; - switch (node.conversion) { - case 's': - oparg = FormatOptions.FVC_STR; - break; - case 'r': - oparg = FormatOptions.FVC_REPR; - break; - case 'a': - oparg = FormatOptions.FVC_ASCII; - break; - case -1: - oparg = FormatOptions.FVC_NONE; - break; - default: - throw parserCallbacks.onError(ErrorType.System, node.getSourceRange(), "Unrecognized conversion character %d", node.conversion); - } - if (node.formatSpec != null) { - node.formatSpec.accept(this); - oparg |= FormatOptions.FVS_HAVE_SPEC; - } - addOp(FORMAT_VALUE, oparg); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.GeneratorExp node) { - return visitComprehension(node, "", node.generators, node.element, null, ComprehensionType.GENEXPR); - } - - @Override - public Void visit(ExprTy.IfExp node) { - SourceRange savedLocation = setLocation(node); - try { - Block end = new Block(); - Block next = new Block(); - jumpIf(node.test, next, false); - node.body.accept(this); - addOp(JUMP_FORWARD, end); - unit.useNextBlock(next); - node.orElse.accept(this); - unit.useNextBlock(end); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.JoinedStr node) { - SourceRange savedLocation = setLocation(node); - try { - // TODO add optimized op for small chains - addOp(LOAD_STRING, addObject(unit.constants, T_EMPTY_STRING)); - addOpName(LOAD_METHOD, unit.names, "join"); - collectIntoArray(node.values, CollectionBits.KIND_LIST); - addOp(CALL_METHOD, 1); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Lambda node) { - SourceRange savedLocation = setLocation(node); - try { - checkForbiddenArgs(parserCallbacks, unit.currentLocation, node.args); - int makeFunctionFlags = collectDefaults(node.args); - enterScope("", CompilationScope.Lambda, node, node.args, node.getSourceRange()); - /* Make None the first constant, so the lambda can't have a docstring. */ - addObject(unit.constants, PNone.NONE); - CodeUnit code; - try { - node.body.accept(this); - addOp(RETURN_VALUE); - code = unit.assemble(); - } finally { - exitScope(); - } - makeClosure(code, makeFunctionFlags); - return null; - } finally { - setLocation(savedLocation); - } - } - - private Void unpackInto(ExprTy[] elements) { - boolean unpack = false; - for (int i = 0; i < elements.length; i++) { - ExprTy e = elements[i]; - if (e instanceof ExprTy.Starred) { - if (unpack) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "multiple starred expressions in assignment"); - } - unpack = true; - int n = elements.length; - int countAfter = n - i - 1; - if (countAfter != (byte) countAfter) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "too many expressions in star-unpacking assignment"); - } - addOp(UNPACK_EX, i, new byte[]{(byte) countAfter}); - } - } - if (!unpack) { - addOp(UNPACK_SEQUENCE, elements.length); - } - for (ExprTy e : elements) { - if (e instanceof ExprTy.Starred) { - ((ExprTy.Starred) e).value.accept(this); - } else if (e != null) { - e.accept(this); - } - } - return null; - } - - @Override - public Void visit(ExprTy.List node) { - SourceRange savedLocation = setLocation(node); - try { - switch (node.context) { - case Store: - return unpackInto(node.elements); - case Load: - boolean emittedConstant = tryLoadConstantCollection(node.elements, CollectionBits.KIND_LIST); - if (emittedConstant) { - return null; - } - collectIntoArray(node.elements, CollectionBits.KIND_LIST); - return null; - case Del: - default: - return visitSequence(node.elements); - } - } finally { - setLocation(savedLocation); - } - } - - private enum ComprehensionType { - LIST(CollectionBits.KIND_LIST), - SET(CollectionBits.KIND_SET), - DICT(CollectionBits.KIND_DICT), - GENEXPR(-1); - - public final int typeBits; - - ComprehensionType(int typeBits) { - this.typeBits = typeBits; - } - } - - @Override - public Void visit(ExprTy.ListComp node) { - return visitComprehension(node, "", node.generators, node.element, null, ComprehensionType.LIST); - } - - private Void visitComprehension(ExprTy node, String name, ComprehensionTy[] generators, ExprTy element, ExprTy value, ComprehensionType type) { - /* - * Create an inner anonymous function to run the comprehension. It takes the outermost - * iterator as an argument and returns the accumulated sequence - */ - SourceRange savedLocation = setLocation(node); - try { - enterScope(name, CompilationScope.Comprehension, node, 1, 0, 0, false, false, node.getSourceRange()); - boolean isAsyncGenerator = unit.scope.isCoroutine(); - if (type != ComprehensionType.GENEXPR) { - // The result accumulator, empty at the beginning - addOp(COLLECTION_FROM_STACK, type.typeBits); - } - // TODO allow top-level await - if (isAsyncGenerator && type != ComprehensionType.GENEXPR && unit.scopeType != CompilationScope.AsyncFunction && unit.scopeType != CompilationScope.Comprehension) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "asynchronous comprehension outside of an asynchronous function"); - } - visitComprehensionGenerator(generators, 0, element, value, type); - if (type != ComprehensionType.GENEXPR) { - addOp(RETURN_VALUE); - } - CodeUnit code = unit.assemble(); - exitScope(); - makeClosure(code, 0); - generators[0].iter.accept(this); - if (generators[0].isAsync) { - addOp(GET_AITER); - } else { - addOp(GET_ITER); - } - addOp(CALL_COMPREHENSION); - // a genexpr will create an asyncgen, which we cannot await - if (type != ComprehensionType.GENEXPR) { - // if we have a non-genexpr async comprehension, the call will produce a - // coroutine which we need to await - if (isAsyncGenerator) { - addOp(GET_AWAITABLE); - addOp(LOAD_NONE); - addYieldFrom(); - } - } - return null; - } finally { - setLocation(savedLocation); - } - } - - private void visitComprehensionGenerator(ComprehensionTy[] generators, int i, ExprTy element, ExprTy value, ComprehensionType type) { - ComprehensionTy gen = generators[i]; - if (i == 0) { - /* The iterator is the function argument for the outermost generator */ - addOp(LOAD_FAST, 0); - } else { - /* Create the iterator for nested iteration */ - gen.iter.accept(this); - if (gen.isAsync) { - addOp(GET_AITER); - } else { - addOp(GET_ITER); - } - } - Block start = new Block(); - Block ifCleanup = new Block(); - Block anchor = new Block(); - Block asyncForTry = gen.isAsync ? new Block() : null; - Block asyncForExcept = gen.isAsync ? new Block() : null; - Block asyncForBody = gen.isAsync ? new Block() : null; - unit.useNextBlock(start); - if (gen.isAsync) { - addOp(DUP_TOP); - unit.useNextBlock(asyncForTry); - unit.pushBlock(new BlockInfo.AsyncForLoopExit(asyncForTry, asyncForExcept)); - addOp(GET_ANEXT); - addOp(LOAD_NONE); - addYieldFrom(); - unit.popBlock(); - unit.useNextBlock(asyncForBody); - gen.target.accept(this); - } else { - addOp(FOR_ITER, anchor); - gen.target.accept(this); - } - for (ExprTy ifExpr : gen.ifs) { - jumpIf(ifExpr, ifCleanup, false); - } - if (i + 1 < generators.length) { - visitComprehensionGenerator(generators, i + 1, element, value, type); - } - if (i == generators.length - 1) { - /* The last generator produces the resulting element to be appended/yielded */ - element.accept(this); - int collectionStackDepth = generators.length + 1; - if (value != null) { - value.accept(this); - collectionStackDepth++; - } - if (type == ComprehensionType.GENEXPR) { - if (generators[i].isAsync) { - addOp(ASYNCGEN_WRAP); - } - addOp(YIELD_VALUE); - addOp(RESUME_YIELD); - addOp(POP_TOP); - } else { - /* - * There is an iterator for every generator on the stack. We need to append to the - * collection that's below them - */ - if (collectionStackDepth > CollectionBits.KIND_MASK) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "too many levels of nested comprehensions"); - } - addOp(ADD_TO_COLLECTION, collectionStackDepth | type.typeBits); - } - } - unit.useNextBlock(ifCleanup); - addOp(JUMP_BACKWARD, start); - if (gen.isAsync) { - unit.useNextBlock(asyncForExcept); - addOp(END_ASYNC_FOR); - } - unit.useNextBlock(anchor); - } - - @Override - public Void visit(ExprTy.Name node) { - SourceRange savedLocation = setLocation(node); - try { - addNameOp(node.id, node.context); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.NamedExpr node) { - SourceRange savedLocation = setLocation(node); - try { - node.value.accept(this); - addOp(DUP_TOP); - node.target.accept(this); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Set node) { - SourceRange savedLocation = setLocation(node); - try { - collectIntoArray(node.elements, CollectionBits.KIND_SET); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.SetComp node) { - return visitComprehension(node, "", node.generators, node.element, null, ComprehensionType.SET); - } - - @Override - public Void visit(ExprTy.Slice node) { - SourceRange savedLocation = setLocation(node); - try { - int n = 2; - if (node.lower != null) { - node.lower.accept(this); - } else { - addOp(LOAD_NONE); - } - if (node.upper != null) { - node.upper.accept(this); - } else { - addOp(LOAD_NONE); - } - if (node.step != null) { - node.step.accept(this); - n++; - } - addOp(BUILD_SLICE, n); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Starred node) { - // Valid occurrences are handled by other visitors - if (node.context == ExprContextTy.Store) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "starred assignment target must be in a list or tuple"); - } else { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "can't use starred expression here"); - } - } - - @Override - public Void visit(ExprTy.Subscript node) { - SourceRange savedLocation = setLocation(node); - if (node.context == ExprContextTy.Load) { - checkSubscripter(parserCallbacks, node.value); - checkIndex(parserCallbacks, node.value, node.slice); - } - try { - node.value.accept(this); - node.slice.accept(this); - switch (node.context) { - case Load: - return addOp(BINARY_SUBSCR); - case Store: - return addOp(STORE_SUBSCR); - case Del: - default: - return addOp(DELETE_SUBSCR); - } - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Tuple node) { - SourceRange savedLocation = setLocation(node); - try { - switch (node.context) { - case Store: - return unpackInto(node.elements); - case Load: - /* - * We don't have mutation operations for tuples, so if we cannot construct the - * tuple within a single instruction, we construct a list and convert it to a - * tuple. - */ - boolean useList = false; - if (node.elements != null) { - if (node.elements.length > CollectionBits.KIND_MASK) { - useList = true; - } else { - for (ExprTy e : node.elements) { - if (e instanceof ExprTy.Starred) { - useList = true; - break; - } - } - } - } - boolean emittedConstant = tryLoadConstantCollection(node.elements, CollectionBits.KIND_TUPLE); - if (emittedConstant) { - return null; - } - if (!useList) { - collectIntoArray(node.elements, CollectionBits.KIND_TUPLE); - } else { - collectIntoArray(node.elements, CollectionBits.KIND_LIST); - addOp(TUPLE_FROM_LIST); - } - return null; - case Del: - default: - return visitSequence(node.elements); - } - } finally { - setLocation(savedLocation); - } - } - - private boolean tryLoadConstantCollection(ExprTy[] elements, int collectionKind) { - ConstantCollection constantCollection = tryCollectConstantCollection(elements); - if (constantCollection == null) { - return false; - } - - addOp(LOAD_CONST_COLLECTION, addObject(unit.constants, constantCollection.collection), new byte[]{(byte) (constantCollection.elementType | collectionKind)}); - return true; - } - - public static final class ConstantCollection { - public final Object collection; - public final int elementType; - - ConstantCollection(Object collection, int elementType) { - this.collection = collection; - this.elementType = elementType; - } - } - - public static ConstantCollection tryCollectConstantCollection(ExprTy[] elements) { - /* - * We try to store the whole tuple as a Java array constant when all the elements are - * constant and context-independent. - */ - if (elements == null || elements.length == 0) { - return null; - } - - int constantType = -1; - List constants = new ArrayList<>(); - - for (ExprTy e : elements) { - if (e instanceof ExprTy.Constant) { - ExprTy.Constant c = (ExprTy.Constant) e; - if (c.value.kind == ConstantValue.Kind.BOOLEAN) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_BOOLEAN); - constants.add(c.value.getBoolean()); - } else if (c.value.kind == ConstantValue.Kind.LONG) { - long val = c.value.getLong(); - if (val == (int) val) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_INT); - } else { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_LONG); - } - constants.add(val); - } else if (c.value.kind == ConstantValue.Kind.DOUBLE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_DOUBLE); - constants.add(c.value.getDouble()); - } else if (c.value.kind == ConstantValue.Kind.CODEPOINTS) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); - constants.add(codePointsToInternedTruffleString(c.value.getCodePoints())); - } else if (c.value.kind == ConstantValue.Kind.NONE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); - constants.add(PNone.NONE); - } else { - return null; - } - } else { - return null; - } - } - Object newConstant = null; - switch (constantType) { - case CollectionBits.ELEMENT_OBJECT: - newConstant = constants.toArray(new Object[0]); - break; - case CollectionBits.ELEMENT_INT: { - int[] a = new int[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (int) (long) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_LONG: { - long[] a = new long[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (long) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_BOOLEAN: { - boolean[] a = new boolean[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (boolean) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_DOUBLE: { - double[] a = new double[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (double) constants.get(i); - } - newConstant = a; - break; - } - } - return new ConstantCollection(newConstant, constantType); - } - - private static int determineConstantType(int existing, int type) { - if (existing == -1 || existing == type) { - return type; - } - if (existing == CollectionBits.ELEMENT_LONG && type == CollectionBits.ELEMENT_INT || existing == CollectionBits.ELEMENT_INT && type == CollectionBits.ELEMENT_LONG) { - return CollectionBits.ELEMENT_LONG; - } - return CollectionBits.ELEMENT_OBJECT; - } - - @Override - public Void visit(ExprTy.UnaryOp node) { - SourceRange savedLocation = setLocation(node); - try { - // Basic constant folding for unary negation - if (node.op == UnaryOpTy.USub && node.operand instanceof ExprTy.Constant) { - ExprTy.Constant c = (ExprTy.Constant) node.operand; - if (c.value.kind == ConstantValue.Kind.BIGINTEGER || c.value.kind == ConstantValue.Kind.DOUBLE || c.value.kind == ConstantValue.Kind.LONG || - c.value.kind == ConstantValue.Kind.COMPLEX) { - ConstantValue cv = c.value.negate(); - return visit(new ExprTy.Constant(cv, null, c.getSourceRange())); - } - } - node.operand.accept(this); - switch (node.op) { - case UAdd: - return addOp(UNARY_OP, UnaryOps.POSITIVE.ordinal()); - case Invert: - return addOp(UNARY_OP, UnaryOps.INVERT.ordinal()); - case Not: - return addOp(UNARY_OP, UnaryOps.NOT.ordinal()); - case USub: - return addOp(UNARY_OP, UnaryOps.NEGATIVE.ordinal()); - default: - throw new IllegalStateException("Unknown unary operation " + node.op); - } - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.Yield node) { - SourceRange savedLocation = setLocation(node); - try { - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'yield' outside function"); - } - if (node.value != null) { - node.value.accept(this); - } else { - addOp(LOAD_NONE); - } - if (unit.scopeType == CompilationScope.AsyncFunction) { - // Async generator - addOp(ASYNCGEN_WRAP); - } - addOp(YIELD_VALUE); - addOp(RESUME_YIELD); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ExprTy.YieldFrom node) { - SourceRange savedLocation = setLocation(node); - try { - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'yield from' outside function"); - } - if (unit.scopeType == CompilationScope.AsyncFunction) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'yield from' inside async function"); - } - node.value.accept(this); - // TODO GET_YIELD_FROM_ITER - addOp(GET_YIELD_FROM_ITER); - addOp(LOAD_NONE); - addYieldFrom(); - return null; - } finally { - setLocation(savedLocation); - } - } - - private void addYieldFrom() { - Block start = new Block(); - Block yield = new Block(); - Block resume = new Block(); - Block exit = new Block(); - Block exceptionHandler = new Block(); - unit.useNextBlock(start); - addOp(SEND, exit); - unit.useNextBlock(yield); - addOp(YIELD_VALUE); - unit.pushBlock(new BlockInfo.TryExcept(resume, exceptionHandler)); - unit.useNextBlock(resume); - addOp(RESUME_YIELD); - addOp(JUMP_BACKWARD, start); - unit.popBlock(); - unit.useNextBlock(exceptionHandler); - addOp(THROW, exit); - addOp(JUMP_BACKWARD, yield); - unit.useNextBlock(exit); - } - - @Override - public Void visit(KeywordTy node) { - node.value.accept(this); - SourceRange savedLocation = setLocation(node); - try { - return addOp(MAKE_KEYWORD, addObject(unit.constants, toTruffleStringUncached(node.arg))); - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(ModTy.Expression node) { - node.body.accept(this); - addOp(RETURN_VALUE); - return null; - } - - @Override - public Void visit(ModTy.FunctionType node) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public Void visit(ModTy.Interactive node) { - if (containsAnnotations(node.body)) { - addOp(SETUP_ANNOTATIONS); - } - interactive = true; - visitSequence(node.body); - addOp(LOAD_NONE); - addOp(RETURN_VALUE); - return null; - } - - @Override - public Void visit(ModTy.Module node) { - visitBody(node.body, true); - return null; - } - - @Override - public Void visit(TypeIgnoreTy.TypeIgnore node) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public Void visit(StmtTy.AnnAssign node) { - setLocation(node); - if (node.value != null) { - node.value.accept(this); - node.target.accept(this); - } - if (node.target instanceof ExprTy.Name) { - String name = ((ExprTy.Name) node.target).id; - checkForbiddenName(name, ExprContextTy.Store); - /* If we have a simple name in a module or class, store annotation. */ - if (node.isSimple && - (unit.scopeType == CompilationScope.Module || unit.scopeType == CompilationScope.Class)) { - boolean futureAnnotations = futureFeatures.contains(FutureFeature.ANNOTATIONS); - if (futureAnnotations) { - visitAnnexpr(node.annotation); - } else { - node.annotation.accept(this); - } - addNameOp("__annotations__", ExprContextTy.Load); - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, name); - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(mangled))); - addOp(STORE_SUBSCR); - } - } else if (node.target instanceof ExprTy.Attribute) { - if (node.value == null) { - ExprTy.Attribute attr = (ExprTy.Attribute) node.target; - checkForbiddenName(attr.attr, ExprContextTy.Store); - if (attr.value != null) { - checkAnnExpr(attr.value); - } - } - } else if (node.target instanceof ExprTy.Subscript) { - if (node.value == null) { - ExprTy.Subscript subscript = (ExprTy.Subscript) node.target; - if (subscript.value != null) { - checkAnnExpr(subscript.value); - } - checkAnnSubscr(subscript.slice); - } - } else { - throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "invalid node type for annotated assignment"); - } - if (!node.isSimple) { - boolean futureAnnotations = futureFeatures.contains(FutureFeature.ANNOTATIONS); - /* - * Annotations of complex targets does not produce anything under annotations future. - * Annotations are only evaluated in a module or class. - */ - if (!futureAnnotations && (unit.scopeType == CompilationScope.Module || unit.scopeType == CompilationScope.Class)) { - checkAnnExpr(node.annotation); - } - } - return null; - } - - private void checkAnnExpr(ExprTy expr) { - expr.accept(this); - addOp(POP_TOP); - } - - private void checkAnnSubscr(ExprTy expr) { - if (expr instanceof ExprTy.Slice) { - ExprTy.Slice slice = (ExprTy.Slice) expr; - if (slice.lower != null) { - checkAnnExpr(slice.lower); - } - if (slice.upper != null) { - checkAnnExpr(slice.upper); - } - if (slice.step != null) { - checkAnnExpr(slice.step); - } - } else if (expr instanceof ExprTy.Tuple) { - ExprTy.Tuple tuple = (ExprTy.Tuple) expr; - for (int i = 0; i < tuple.elements.length; i++) { - checkAnnSubscr(tuple.elements[i]); - } - } else { - checkAnnExpr(expr); - } - } - - private static boolean isNonEmptyTuple(ExprTy expr) { - if (expr instanceof ExprTy.Tuple) { - ExprTy.Tuple tuple = (ExprTy.Tuple) expr; - return tuple.elements != null && tuple.elements.length > 0; - } - if (expr instanceof ExprTy.Constant) { - ConstantValue cv = ((ExprTy.Constant) expr).value; - return cv.kind == Kind.TUPLE && cv.getTupleElements().length > 0; - } - return false; - } - - @Override - public Void visit(StmtTy.Assert node) { - if (isNonEmptyTuple(node.test)) { - warn(node, "assertion is always true, perhaps remove parentheses?"); - } - if (optimizationLevel > 0) { - return null; - } - setLocation(node); - Block end = new Block(); - jumpIf(node.test, end, true); - addOp(LOAD_ASSERTION_ERROR); - if (node.msg != null) { - node.msg.accept(this); - addOp(CALL_FUNCTION, 1); - } - addOp(RAISE_VARARGS, 1); - unit.useNextBlock(end); - return null; - } - - @Override - public Void visit(StmtTy.Assign node) { - setLocation(node); - node.value.accept(this); - for (int i = 0; i < node.targets.length; i++) { - if (i != node.targets.length - 1) { - addOp(DUP_TOP); - } - node.targets[i].accept(this); - } - return null; - } - - @Override - public Void visit(StmtTy.AsyncFor node) { - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'async for' outside function"); - } - if (unit.scopeType != CompilationScope.AsyncFunction) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'async for' outside async function"); - } - visitAsyncFor(node); - return null; - } - - private void visitAsyncFor(StmtTy.AsyncFor node) { - setLocation(node); - Block head = new Block(); - Block body = new Block(); - Block end = new Block(); - Block except = new Block(); - Block loopTry = new Block(); - Block orelse = node.orElse != null ? new Block() : null; - node.iter.accept(this); - addOp(GET_AITER); - unit.useNextBlock(head); - unit.pushBlock(new BlockInfo.AsyncForLoop(head, end)); - addOp(DUP_TOP); - addOp(GET_ANEXT); - unit.useNextBlock(loopTry); - unit.pushBlock(new BlockInfo.AsyncForLoopExit(loopTry, except)); - addOp(LOAD_NONE); - addYieldFrom(); - unit.popBlock(); - unit.useNextBlock(body); - try { - node.target.accept(this); - visitSequence(node.body); - addOp(JUMP_BACKWARD, head); - } finally { - unit.popBlock(); - } - addOp(JUMP_FORWARD, node.orElse != null ? orelse : end); - unit.useNextBlock(except); - addOp(END_ASYNC_FOR); - if (node.orElse != null) { - unit.useNextBlock(orelse); - visitSequence(node.orElse); - } - unit.useNextBlock(end); - } - - // TODO temporary helper so that stuff that's not implemented can compile into stubs - private Void emitNotImplemented(String what) { - addGlobalVariableOpcode(ExprContextTy.Load, addObject(unit.names, "NotImplementedError"), false); - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(what))); - addOp(CALL_FUNCTION, 1); - addOp(RAISE_VARARGS, 1); - return null; - } - - @Override - public Void visit(StmtTy.AsyncFunctionDef node) { - return visitFunctionDef(node, node.name, node.args, node.body, node.decoratorList, node.returns, node.typeParams, true); - } - - @Override - public Void visit(StmtTy.AsyncWith node) { - setLocation(node); - // TODO if !IS_TOP_LEVEL_AWAIT - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'async with' outside function"); - } - if (unit.scopeType != CompilationScope.AsyncFunction && unit.scopeType != CompilationScope.Comprehension) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'async with' outside async function"); - } - visitAsyncWith(node, 0); - unit.useNextBlock(new Block()); - return null; - } - - private void visitAsyncWith(StmtTy.AsyncWith node, int itemIndex) { - Block body = new Block(); - Block handler = new Block(); - - WithItemTy item = node.items[itemIndex]; - item.contextExpr.accept(this); - addOp(SETUP_AWITH); - unit.pushBlock(new BlockInfo.AsyncWith(body, handler, node)); - - unit.useNextBlock(body); - // SETUP_AWITH leaves 2 awaitables rather than a function and a result - addOp(GET_AWAITABLE); - addOp(LOAD_NONE); - addYieldFrom(); - /* - * Unwind one more stack item than it normally would to get rid of the context manager that - * is not needed in the finally block - */ - handler.unwindOffset = -1; - if (item.optionalVars != null) { - item.optionalVars.accept(this); - } else { - addOp(POP_TOP); - } - if (itemIndex < node.items.length - 1) { - visitAsyncWith(node, itemIndex + 1); - } else { - visitSequence(node.body); - } - addOp(LOAD_NONE); - unit.popBlock(); - - unit.useNextBlock(handler); - setLocation(node); - addOp(GET_AEXIT_CORO); - addOp(GET_AWAITABLE); - addOp(LOAD_NONE); - addYieldFrom(); - addOp(EXIT_AWITH); - } - - @Override - public Void visit(StmtTy.AugAssign node) { - ExprTy target = node.target; - setLocation(target); - if (target instanceof ExprTy.Attribute) { - ExprTy.Attribute attr = (ExprTy.Attribute) target; - attr.value.accept(this); - addOp(DUP_TOP); - addOpName(LOAD_ATTR, unit.names, attr.attr); - } else if (target instanceof ExprTy.Subscript) { - ExprTy.Subscript subscript = (ExprTy.Subscript) target; - subscript.value.accept(this); - addOp(DUP_TOP); - subscript.slice.accept(this); - addOp(DUP_TOP); - addOp(ROT_THREE); - addOp(BINARY_SUBSCR); - } else if (target instanceof ExprTy.Name) { - ExprTy.Name name = (ExprTy.Name) target; - addNameOp(name.id, ExprContextTy.Load); - } else { - // TODO this raises SystemError under CPython - throw new IllegalArgumentException("invalid node type for augmented assignment"); - } - setLocation(node); - node.value.accept(this); - switch (node.op) { - case Add: - addOp(BINARY_OP, BinaryOps.INPLACE_ADD.ordinal()); - break; - case Sub: - addOp(BINARY_OP, BinaryOps.INPLACE_SUB.ordinal()); - break; - case Mult: - addOp(BINARY_OP, BinaryOps.INPLACE_MUL.ordinal()); - break; - case MatMult: - addOp(BINARY_OP, BinaryOps.INPLACE_MATMUL.ordinal()); - break; - case Div: - addOp(BINARY_OP, BinaryOps.INPLACE_TRUEDIV.ordinal()); - break; - case Mod: - addOp(BINARY_OP, BinaryOps.INPLACE_MOD.ordinal()); - break; - case Pow: - addOp(BINARY_OP, BinaryOps.INPLACE_POW.ordinal()); - break; - case LShift: - addOp(BINARY_OP, BinaryOps.INPLACE_LSHIFT.ordinal()); - break; - case RShift: - addOp(BINARY_OP, BinaryOps.INPLACE_RSHIFT.ordinal()); - break; - case BitOr: - addOp(BINARY_OP, BinaryOps.INPLACE_OR.ordinal()); - break; - case BitXor: - addOp(BINARY_OP, BinaryOps.INPLACE_XOR.ordinal()); - break; - case BitAnd: - addOp(BINARY_OP, BinaryOps.INPLACE_AND.ordinal()); - break; - case FloorDiv: - addOp(BINARY_OP, BinaryOps.INPLACE_FLOORDIV.ordinal()); - break; - default: - throw new IllegalStateException("Unknown binary inplace operation " + node.op); - } - setLocation(target); - if (target instanceof ExprTy.Attribute) { - ExprTy.Attribute attr = (ExprTy.Attribute) target; - addOp(ROT_TWO); - addOpName(STORE_ATTR, unit.names, attr.attr); - } else if (target instanceof ExprTy.Subscript) { - addOp(ROT_THREE); - addOp(STORE_SUBSCR); - } else { - ExprTy.Name name = (ExprTy.Name) target; - addNameOp(name.id, ExprContextTy.Store); - } - return null; - } - - @Override - public Void visit(StmtTy.ClassDef node) { - setLocation(node); - visitSequence(node.decoratorList); - - SourceRange startLocation = node.getSourceRange(); - if (node.decoratorList != null && node.decoratorList.length > 0) { - startLocation = node.decoratorList[0].getSourceRange(); - } - boolean isGeneric = node.typeParams != null && node.typeParams.length > 0; - if (isGeneric) { - String typeParamsName = ""; - enterScope(typeParamsName, CompilationScope.TypeParams, node.typeParams, null, startLocation); - unit.privateName = node.name; - visitTypeParams(node.typeParams); - addNameOp(".type_params", ExprContextTy.Store); - } - enterScope(node.name, CompilationScope.Class, node, 0, 0, 0, false, false, startLocation); - addNameOp("__name__", ExprContextTy.Load); - addNameOp("__module__", ExprContextTy.Store); - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(unit.qualName))); - addNameOp("__qualname__", ExprContextTy.Store); - - if (isGeneric) { - addNameOp(".type_params", ExprContextTy.Load); - addNameOp(J___TYPE_PARAMS__, ExprContextTy.Store); - } - if (unit.scope.needsClassDict()) { - addOp(LOAD_LOCALS); - // We can't use addNameOp here because we need to generate a STORE_DEREF in a class - // namespace, addNameOp() won't do that by default. - addOp(STORE_DEREF, addObject(unit.cellvars, "__classdict__")); - } - - visitBody(node.body, false); - - if (unit.scope.needsClassDict()) { - addOp(LOAD_CLOSURE, unit.cellvars.get("__classdict__")); - addNameOp("__classdictcell__", ExprContextTy.Store); - } - if (unit.scope.needsClassClosure()) { - int idx = unit.cellvars.get("__class__"); - addOp(LOAD_CLOSURE, idx); - addOp(DUP_TOP); - addNameOp("__classcell__", ExprContextTy.Store); - } else { - addOp(LOAD_NONE); - } - addOp(RETURN_VALUE); - CodeUnit co = unit.assemble(); - exitScope(); - - addOp(LOAD_BUILD_CLASS); - makeClosure(co, 0); - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(node.name))); - - if (isGeneric) { - addNameOp(".type_params", ExprContextTy.Load); - addOp(MAKE_GENERIC); - addNameOp(".generic_base", ExprContextTy.Store); - ExprTy.Name nameNode = new ExprTy.Name(".generic_base", ExprContextTy.Load, node.getSourceRange()); - ExprTy[] bases; - if (node.bases == null) { - bases = new ExprTy[]{nameNode}; - } else { - bases = arrayCopyOf(node.bases, node.bases.length + 1); - bases[bases.length - 1] = nameNode; - } - callHelper(CALL_FUNCTION_VARARGS, 0, 2, bases, node.keywords); - addOp(RETURN_VALUE); - CodeUnit code = unit.assemble(); - exitScope(); - makeClosure(code, 0); - addOp(CALL_FUNCTION, 0); - } else { - callHelper(CALL_FUNCTION_VARARGS, 0, 2, node.bases, node.keywords); - } - applyDecorators(node.decoratorList); - - addNameOp(node.name, ExprContextTy.Store); - - return null; - } - - @Override - public Void visit(StmtTy.Delete node) { - setLocation(node); - visitSequence(node.targets); - return null; - } - - @Override - public Void visit(StmtTy.Expr node) { - setLocation(node); - if (interactive && nestingLevel <= 1) { - node.value.accept(this); - addOp(PRINT_EXPR); - } else if (!(node.value instanceof ExprTy.Constant)) { - node.value.accept(this); - addOp(POP_TOP); - } - return null; - } - - @Override - public Void visit(StmtTy.For node) { - setLocation(node); - Block head = new Block(); - Block body = new Block(); - Block end = new Block(); - Block orelse = node.orElse != null ? new Block() : end; - - node.iter.accept(this); - addOp(GET_ITER); - - unit.useNextBlock(head); - addOp(FOR_ITER, orelse); - - unit.useNextBlock(body); - unit.pushBlock(new BlockInfo.For(head, end)); - try { - node.target.accept(this); - visitSequence(node.body); - addOp(JUMP_BACKWARD, head); - } finally { - unit.popBlock(); - } - - if (node.orElse != null) { - unit.useNextBlock(orelse); - visitSequence(node.orElse); - } - - unit.useNextBlock(end); - return null; - } - - @Override - public Void visit(StmtTy.FunctionDef node) { - return visitFunctionDef(node, node.name, node.args, node.body, node.decoratorList, node.returns, node.typeParams, false); - } - - private Void visitFunctionDef(StmtTy node, String name, ArgumentsTy args, StmtTy[] body, ExprTy[] decoratorList, ExprTy returns, TypeParamTy[] typeParams, boolean isAsync) { - setLocation(node); - checkForbiddenArgs(parserCallbacks, unit.currentLocation, args); - - // visit decorators - visitSequence(decoratorList); - - SourceRange startLocation = node.getSourceRange(); - if (decoratorList != null && decoratorList.length > 0) { - startLocation = decoratorList[0].getSourceRange(); - } - - boolean isGeneric = typeParams != null && typeParams.length > 0; - - // visit defaults outside the function scope - int makeFunctionFlags = collectDefaults(args); - - int numTypeParamArgs = 0; - if (isGeneric) { - if ((makeFunctionFlags & OpCodes.MakeFunctionFlags.HAS_DEFAULTS) != 0) { - numTypeParamArgs++; - } - if ((makeFunctionFlags & OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS) != 0) { - numTypeParamArgs++; - } - String typeParamsName = ""; - enterScope(typeParamsName, CompilationScope.TypeParams, typeParams, numTypeParamArgs, 0, 0, false, false, startLocation); - visitTypeParams(typeParams); - if ((makeFunctionFlags & (OpCodes.MakeFunctionFlags.HAS_DEFAULTS | OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS)) != 0) { - addOp(LOAD_FAST, 0); - } - if ((makeFunctionFlags & (OpCodes.MakeFunctionFlags.HAS_DEFAULTS | OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS)) == (OpCodes.MakeFunctionFlags.HAS_DEFAULTS | - OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS)) { - addOp(LOAD_FAST, 1); - } - } - boolean hasAnnotations = visitAnnotations(args, returns); - if (hasAnnotations) { - makeFunctionFlags |= OpCodes.MakeFunctionFlags.HAS_ANNOTATIONS; - } - - CompilationScope scopeType = isAsync ? CompilationScope.AsyncFunction : CompilationScope.Function; - enterScope(name, scopeType, node, args, startLocation); - - TruffleString docString = getDocstring(body); - addObject(unit.constants, docString == null ? PNone.NONE : docString); - visitSequence(body); - CodeUnit code = unit.assemble(); - exitScope(); - makeClosure(code, makeFunctionFlags); - - if (isGeneric) { - addOp(DUP_TOP); - addOp(ROT_THREE); - addOpName(STORE_ATTR, unit.names, J___TYPE_PARAMS__); - addOp(RETURN_VALUE); - CodeUnit typeParamsCode = unit.assemble(); - exitScope(); - makeClosure(typeParamsCode, 0); - if (numTypeParamArgs == 2) { - addOp(ROT_THREE); - } else if (numTypeParamArgs == 1) { - addOp(ROT_TWO); - } - addOp(CALL_FUNCTION, numTypeParamArgs); - } - - applyDecorators(decoratorList); - - addNameOp(name, ExprContextTy.Store); - return null; - } - - private void applyDecorators(ExprTy[] decoratorList) { - if (decoratorList != null) { - for (int i = decoratorList.length - 1; i >= 0; i--) { - SourceRange savedLocation = setLocation(decoratorList[i]); - addOp(CALL_FUNCTION, 1); - setLocation(savedLocation); - } - } - } - - private void visitTypeParams(TypeParamTy[] typeParams) { - boolean useList = typeParams.length > CollectionBits.KIND_MASK; - Collector typeParamCollector = new Collector(useList ? CollectionBits.KIND_LIST : CollectionBits.KIND_TUPLE); - for (TypeParamTy typeParam : typeParams) { - typeParam.accept(this); - typeParamCollector.appendItem(); - } - typeParamCollector.finishCollection(); - if (useList) { - addOp(TUPLE_FROM_LIST); - } - } - - private boolean visitAnnotations(ArgumentsTy args, ExprTy returns) { - Collector collector = new Collector(CollectionBits.KIND_DICT); - if (args != null) { - visitArgAnnotations(collector, args.args); - visitArgAnnotations(collector, args.posOnlyArgs); - if (args.varArg != null) { - visitArgAnnotation(collector, args.varArg.arg, args.varArg.annotation); - } - visitArgAnnotations(collector, args.kwOnlyArgs); - if (args.kwArg != null) { - visitArgAnnotation(collector, args.kwArg.arg, args.kwArg.annotation); - } - } - visitArgAnnotation(collector, "return", returns); - if (collector.isEmpty()) { - return false; - } - collector.finishCollection(); - return true; - } - - private void visitArgAnnotations(Collector collector, ArgTy[] args) { - for (int i = 0; i < args.length; i++) { - visitArgAnnotation(collector, args[i].arg, args[i].annotation); - } - } - - private void visitArgAnnotation(Collector collector, String name, ExprTy annotation) { - if (annotation != null) { - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, name); - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(mangled))); - if (futureFeatures.contains(FutureFeature.ANNOTATIONS)) { - visitAnnexpr(annotation); - } else { - if (annotation instanceof ExprTy.Starred) { - // *args: *Ts (where Ts is a TypeVarTuple). - // Do [annotation_value] = [*Ts]. - ((ExprTy.Starred) annotation).value.accept(this); - addOp(UNPACK_SEQUENCE, 1); - } else { - annotation.accept(this); - } - } - collector.appendItem(); - } - } - - private void visitAnnexpr(ExprTy annotation) { - addOp(LOAD_STRING, addObject(unit.constants, Unparser.unparse(annotation))); - } - - private int collectDefaults(ArgumentsTy args) { - int makeFunctionFlags = 0; - if (args != null) { - if (args.defaults != null && args.defaults.length > 0) { - collectIntoArray(args.defaults, CollectionBits.KIND_OBJECT); - makeFunctionFlags |= OpCodes.MakeFunctionFlags.HAS_DEFAULTS; - } - if (args.kwDefaults != null && args.kwDefaults.length > 0) { - ArrayList defs = new ArrayList<>(); - for (int i = 0; i < args.kwOnlyArgs.length; i++) { - ArgTy arg = args.kwOnlyArgs[i]; - ExprTy def = args.kwDefaults[i]; - if (def != null) { - String mangled = ScopeEnvironment.maybeMangle(unit.privateName, unit.scope, arg.arg); - defs.add(new KeywordTy(mangled, def, arg.getSourceRange())); - } - } - if (!defs.isEmpty()) { - collectKeywords(defs.toArray(KeywordTy[]::new), null); - makeFunctionFlags |= OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS; - } - } - } - return makeFunctionFlags; - } - - @Override - public Void visit(StmtTy.Global node) { - setLocation(node); - return null; - } - - @Override - public Void visit(StmtTy.If node) { - setLocation(node); - Block then = new Block(); - Block end = new Block(); - Block alt = node.orElse != null && node.orElse.length > 0 ? new Block() : end; - jumpIf(node.test, alt, false); - unit.useNextBlock(then); - visitSequence(node.body); - if (alt != end) { - addOp(JUMP_FORWARD, end); - unit.useNextBlock(alt); - visitSequence(node.orElse); - } - unit.useNextBlock(end); - return null; - } - - private void jumpIf(ExprTy test, Block next, boolean jumpIfTrue) { - // TODO Optimize for various test types, such as short-circuit operators - // See compiler_jump_if in CPython - if (test instanceof ExprTy.Compare) { - checkCompare(parserCallbacks, (ExprTy.Compare) test); - } - test.accept(this); - if (jumpIfTrue) { - addConditionalJump(POP_AND_JUMP_IF_TRUE, next); - } else { - addConditionalJump(POP_AND_JUMP_IF_FALSE, next); - } - } - - @Override - public Void visit(StmtTy.Import node) { - setLocation(node); - return visitSequence(node.names); - } - - @Override - public Void visit(StmtTy.ImportFrom node) { - setLocation(node); - addLoadNumber(node.level); - TruffleString[] names = new TruffleString[node.names.length]; - for (int i = 0; i < node.names.length; i++) { - names[i] = toTruffleStringUncached(node.names[i].name); - } - if (node.getSourceRange().startLine > futureLineno && "__future__".equals(node.module)) { - throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "from __future__ imports must occur at the beginning of the file"); - } - String moduleName = node.module != null ? node.module : ""; - if ("*".equals(node.names[0].name)) { - addOpName(IMPORT_STAR, unit.names, moduleName); - } else { - addOp(LOAD_CONST, addObject(unit.constants, names)); - addOpName(IMPORT_NAME, unit.names, moduleName); - for (AliasTy alias : node.names) { - addOpName(IMPORT_FROM, unit.names, alias.name); - String storeName = alias.asName != null ? alias.asName : alias.name; - addNameOp(storeName, ExprContextTy.Store); - - } - addOp(POP_TOP); - } - return null; - } - - @Override - public Void visit(StmtTy.Match node) { - setLocation(node); - PatternContext pc = new PatternContext(); - node.subject.accept(this); - Block end = new Block(); - assert node.cases.length > 0; - boolean hasDefault = node.cases.length > 1 && wildcardCheck(node.cases[node.cases.length - 1].pattern); - int lastIdx = hasDefault ? node.cases.length - 2 : node.cases.length - 1; - for (int i = 0; i <= lastIdx; i++) { - MatchCaseTy c = node.cases[i]; - setLocation(c); - - // Only copy the subject if we're *not* on the last case: - if (i < lastIdx) { - addOp(DUP_TOP); - } - pc.stores = new ArrayList<>(); - // Irrefutable cases must be either guarded, last, or both: - pc.allowIrrefutable = c.guard != null || i == node.cases.length - 1; - pc.failPop = null; - pc.onTop = 0; - - visit(c.pattern, pc); - - // Store all of the captured names (they're on the stack). - for (String name : pc.stores) { - addNameOp(name, ExprContextTy.Store); - } - if (c.guard != null) { - ensureFailPop(i, pc); - jumpIf(c.guard, pc.failPop.get(0), false); - } - - // Pop the subject off, we're done with it: - if (i < lastIdx) { - addOp(POP_TOP); - } - visitBody(c.body, false); - addOp(JUMP_FORWARD, end); - // If the pattern fails to match, we want the line number of the - // cleanup to be associated with the failed pattern, not the last line - // of the body - setLocation(c); - emitAndResetFailPop(pc); - } - if (hasDefault) { - MatchCaseTy c = node.cases[node.cases.length - 1]; - setLocation(c); - if (node.cases.length == 1) { - // No matches. Done with the subject: - addOp(POP_TOP); - } else { - // Show line coverage for default case (it doesn't create bytecode) - addOp(NOP); - } - if (c.guard != null) { - jumpIf(c.guard, end, false); - } - visitBody(c.body, false); - } - unit.useNextBlock(end); - return null; - } - - private static boolean wildcardCheck(PatternTy pattern) { - return pattern instanceof PatternTy.MatchAs && ((PatternTy.MatchAs) pattern).name == null; - } - - private static boolean wildcardStarCheck(PatternTy pattern) { - return pattern instanceof PatternTy.MatchStar && ((PatternTy.MatchStar) pattern).name == null; - } - - public Void visit(PatternTy pattern, PatternContext pc) { - if (pattern instanceof PatternTy.MatchAs) { - return visit((PatternTy.MatchAs) pattern, pc); - } else if (pattern instanceof PatternTy.MatchMapping) { - return visit((PatternTy.MatchMapping) pattern, pc); - } else if (pattern instanceof PatternTy.MatchSingleton) { - return visit((PatternTy.MatchSingleton) pattern, pc); - } else if (pattern instanceof PatternTy.MatchClass) { - return visit((PatternTy.MatchClass) pattern, pc); - } else if (pattern instanceof PatternTy.MatchOr) { - return visit((PatternTy.MatchOr) pattern, pc); - } else if (pattern instanceof PatternTy.MatchSequence) { - return visit((PatternTy.MatchSequence) pattern, pc); - } else if (pattern instanceof PatternTy.MatchStar) { - return visit((PatternTy.MatchStar) pattern, pc); - } else if (pattern instanceof PatternTy.MatchValue) { - return visit((PatternTy.MatchValue) pattern, pc); - } else { - throw new IllegalStateException("unknown PatternTy type " + pattern.getClass()); - } - } - - public Void visit(PatternTy.MatchStar node, PatternContext pc) { - patternHelperStoreName(node.name, pc); - return null; - } - - public Void visit(PatternTy.MatchSequence node, PatternContext pc) { - int size = lengthOrZero(node.patterns); - int star = -1; - boolean onlyWildcard = true; - boolean starWildcard = false; - - // Find a starred name, if it exists. There may be at most one: - for (int i = 0; i < size; i++) { - PatternTy pattern = node.patterns[i]; - if (pattern instanceof PatternTy.MatchStar) { - if (star >= 0) { - throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "multiple starred names in sequence pattern"); - } - starWildcard = wildcardStarCheck(pattern); - onlyWildcard &= starWildcard; - star = i; - continue; - } - onlyWildcard &= wildcardCheck(pattern); - } - - // We need to keep the subject on top during the sequence and length checks: - pc.onTop++; - addOp(MATCH_SEQUENCE); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - if (star < 0) { - // No star: len(subject) == size - addOp(GET_LEN); - addLoadNumber(size); - addCompareOp(CmpOpTy.Eq); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - } else if (size > 1) { - // Star: len(subject) >= size - 1 - addOp(GET_LEN); - addLoadNumber(size - 1); - addCompareOp(CmpOpTy.GtE); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - } - // Whatever comes next should consume the subject: - pc.onTop--; - if (onlyWildcard) { - // Patterns like: [] / [_] / [_, _] / [*_] / [_, *_] / [_, _, *_] / etc. - addOp(POP_TOP); - } else if (starWildcard) { - patternHelperSequenceSubscr(node.patterns, star, pc); - } else { - patternHelperSequenceUnpack(node.patterns, pc); - } - return null; - } - - // Like pattern_helper_sequence_unpack, but uses BINARY_SUBSCR instead of - // UNPACK_SEQUENCE / UNPACK_EX. This is more efficient for patterns with a - // starred wildcard like [first, *_] / [first, *_, last] / [*_, last] / etc. - private void patternHelperSequenceSubscr(PatternTy[] patterns, int star, PatternContext pc) { - // We need to keep the subject around for extracting elements: - pc.onTop++; - int size = lengthOrZero(patterns); - for (int i = 0; i < size; i++) { - PatternTy pattern = patterns[i]; - if (wildcardCheck(pattern)) { - continue; - } - if (i == star) { - assert wildcardStarCheck(pattern); - continue; - } - addOp(DUP_TOP); - if (i < star) { - addLoadNumber(i); - } else { - // The subject may not support negative indexing! Compute a - // nonnegative index: - addOp(GET_LEN); - addLoadNumber(size - i); - addOp(BINARY_OP, BinaryOps.SUB.ordinal()); - } - addOp(BINARY_SUBSCR); - patternSubpattern(pattern, pc); - } - // Pop the subject, we're done with it: - pc.onTop--; - addOp(POP_TOP); - } - - // Like compiler_pattern, but turn off checks for irrefutability. - private void patternSubpattern(PatternTy pattern, PatternContext pc) { - boolean allowIrrefutable = pc.allowIrrefutable; - pc.allowIrrefutable = true; - visit(pattern, pc); - pc.allowIrrefutable = allowIrrefutable; - } - - private void patternHelperSequenceUnpack(PatternTy[] patterns, PatternContext pc) { - patternUnpackHelper(patterns); - int size = lengthOrZero(patterns); - // We've now got a bunch of new subjects on the stack. They need to remain - // there after each subpattern match: - pc.onTop += size; - for (int i = 0; i < size; i++) { - // One less item to keep track of each time we loop through: - pc.onTop--; - patternSubpattern(patterns[i], pc); - } - } - - private void patternUnpackHelper(PatternTy[] patterns) { - int n = lengthOrZero(patterns); - boolean seenStar = false; - for (int i = 0; i < n; i++) { - PatternTy pattern = patterns[i]; - if (pattern instanceof PatternTy.MatchStar) { - if (seenStar) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "multiple starred expressions in sequence pattern"); - } - seenStar = true; - int countAfter = n - i - 1; - if (countAfter != (byte) countAfter) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "too many expressions in star-unpacking sequence pattern"); - } - addOp(UNPACK_EX, i, new byte[]{(byte) countAfter}); - } - } - if (!seenStar) { - addOp(UNPACK_SEQUENCE, n); - } - } - - private static int lengthOrZero(Object[] p) { - return p == null ? 0 : p.length; - } - - public Void visit(PatternTy.MatchAs node, PatternContext pc) { - if (node.pattern == null) { - if (!pc.allowIrrefutable) { - if (node.name != null) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "name capture '%s' makes remaining patterns unreachable", node.name); - } - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "wildcard makes remaining patterns unreachable"); - } - patternHelperStoreName(node.name, pc); - return null; - } - // Need to make a copy for (possibly) storing later: - pc.onTop++; - addOp(DUP_TOP); - visit(node.pattern, pc); - pc.onTop--; - patternHelperStoreName(node.name, pc); - return null; - } - - private void patternHelperStoreName(String n, PatternContext pc) { - if (n == null) { - addOp(POP_TOP); - return; - } - checkForbiddenName(n, ExprContextTy.Store); - // Can't assign to the same name twice: - if (pc.stores.contains(n)) { - throw duplicateStoreError(n); - } - // Rotate this object underneath any items we need to preserve: - pc.stores.add(n); - addOp(ROT_N, pc.onTop + pc.stores.size()); - } - - public Void visit(PatternTy.MatchClass node, PatternContext pc) { - PatternTy[] patterns = node.patterns; - String[] kwdAttrs = node.kwdAttrs; - PatternTy[] kwdPatterns = node.kwdPatterns; - int nargs = lengthOrZero(patterns); - int nattrs = lengthOrZero(kwdAttrs); - int nKwdPatterns = lengthOrZero(kwdPatterns); - if (nattrs != nKwdPatterns) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "kwd_attrs (%d) / kwd_patterns (%d) length mismatch in class pattern", nattrs, nKwdPatterns); - } - if (Integer.MAX_VALUE < nargs + nattrs - 1) { - String id = node.cls instanceof ExprTy.Name ? ((ExprTy.Name) node.cls).id : node.cls.toString(); - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "too many sub-patterns in class pattern %s", id); - - } - if (nattrs > 0) { - validateKwdAttrs(kwdAttrs, kwdPatterns); - setLocation(node); - } - - node.cls.accept(this); - TruffleString[] attrNames = new TruffleString[nattrs]; - for (int i = 0; i < nattrs; i++) { - attrNames[i] = toTruffleStringUncached(kwdAttrs[i]); - } - addOp(LOAD_CONST, addObject(unit.constants, attrNames)); - addOp(MATCH_CLASS, nargs); - - // TOS is now a tuple of (nargs + nattrs) attributes. Preserve it: - pc.onTop++; - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - for (int i = 0; i < nargs + nattrs; i++) { - PatternTy pattern; - if (i < nargs) { - // Positional: - pattern = patterns[i]; - } else { - // Keyword: - pattern = kwdPatterns[i - nargs]; - } - if (wildcardCheck(pattern)) { - continue; - } - // Get the i-th attribute, and match it against the i-th pattern: - addOp(DUP_TOP); - addLoadNumber(i); - addOp(BINARY_SUBSCR); - patternSubpattern(pattern, pc); - } - // Pop the tuple of attributes: - pc.onTop--; - addOp(POP_TOP); - return null; - } - - private void validateKwdAttrs(String[] attrs, PatternTy[] patterns) { - // Any errors will point to the pattern rather than the arg name as the - // parser is only supplying identifiers rather than Name or keyword nodes - int nattrs = lengthOrZero(attrs); - for (int i = 0; i < nattrs; i++) { - String attr = attrs[i]; - setLocation(patterns[i]); - checkForbiddenName(attr, ExprContextTy.Store); - for (int j = i + 1; j < nattrs; j++) { - String other = attrs[j]; - if (attr.equals(other)) { - setLocation(patterns[i]); - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "attribute name repeated in class pattern: `%s`", attr); - } - } - } - } - - @SuppressWarnings("unused") - public Void visit(PatternTy.MatchMapping node, PatternContext pc) { - ExprTy[] keys = node.keys; - PatternTy[] patterns = node.patterns; - int size = lengthOrZero(keys); - int npatterns = lengthOrZero(patterns); - if (size != npatterns) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "keys (%d) / patterns (%d) length mismatch in mapping pattern", size, npatterns); - } - // We have a double-star target if "rest" is set - String starTarget = node.rest; - // We need to keep the subject on top during the mapping and length checks: - pc.onTop++; - addOp(MATCH_MAPPING); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - - if (size == 0 && starTarget == null) { - pc.onTop--; - addOp(POP_TOP); - return null; - } - if (Integer.MAX_VALUE < size - 1) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "too many sub-patterns in mapping pattern"); - } - if (size > 0) { - // If the pattern has any keys in it, perform a length check: - addOp(GET_LEN); - addLoadNumber(size); - addCompareOp(CmpOpTy.GtE); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - } - // Collect all of the keys into a tuple for MATCH_KEYS and - // COPY_DICT_WITHOUT_KEYS. They can either be dotted names or literals: - Collector collector = new Collector(CollectionBits.KIND_OBJECT, 0); - List seen = new ArrayList<>(); - for (int i = 0; i < size; i++) { - ExprTy key = keys[i]; - if (key == null) { - setLocation(patterns[i]); - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "can't use NULL keys in MatchMapping (set 'rest' parameter instead)"); - } - - if (key instanceof ExprTy.Attribute) { - key.accept(this); - } else { - ConstantValue constantValue = null; - if (key instanceof ExprTy.UnaryOp || key instanceof ExprTy.BinOp) { - constantValue = foldConstantOp(key); - } else if (key instanceof ExprTy.Constant) { - constantValue = ((ExprTy.Constant) key).value; - } else { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "mapping pattern keys may only match literals and attribute lookups"); - } - assert constantValue != null; - Object pythonValue = PythonUtils.pythonObjectFromConstantValue(constantValue); - for (Object o : seen) { - // need python like equal - e.g. 1 equals True - if (PyObjectRichCompareBool.executeEqUncached(o, pythonValue)) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "mapping pattern checks duplicate key (%s)", pythonValue); - } - } - seen.add(pythonValue); - addConstant(constantValue); - } - collector.appendItem(); - } - collector.finishCollection(); - - addOp(MATCH_KEYS); - // There's now an Object[] array of keys and a tuple of values on top of the subject: - pc.onTop += 2; - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - // So far so good. Use that tuple of values on the stack to match - // sub-patterns against: - for (int i = 0; i < size; i++) { - PatternTy pattern = node.patterns[i]; - if (wildcardCheck(pattern)) { - continue; - } - addOp(DUP_TOP); - addLoadNumber(i); - addOp(BINARY_SUBSCR); - patternSubpattern(pattern, pc); - } - - // If we get this far, it's a match! We're done with the tuple of values, - // and whatever happens next should consume the arrays of keys underneath it: - pc.onTop -= 2; - addOp(POP_TOP); - if (starTarget != null) { - // If we have a starred name, bind a dict of remaining items to it: - addOp(COPY_DICT_WITHOUT_KEYS); - patternHelperStoreName(starTarget, pc); - } else { - // Otherwise, we don't care about this tuple of keys anymore: - addOp(POP_TOP); - } - // Pop the subject: - pc.onTop--; - addOp(POP_TOP); - - return null; - } - - @SuppressWarnings("unused") - public Void visit(PatternTy.MatchOr node, PatternContext pc) { - Block end = new Block(); - int size = node.patterns.length; - assert size > 1; - PatternContext oldPc = pc; - // control is the list of names bound by the first alternative. It is used - // for checking different name bindings in alternatives, and for correcting - // the order in which extracted elements are placed on the stack. - ArrayList control = null; - - for (int i = 0; i < size; i++) { - PatternTy pattern = node.patterns[i]; - setLocation(pattern); - pc = new PatternContext(); - pc.stores = new ArrayList<>(); - // An irrefutable sub-pattern must be last, if it is allowed at all: - pc.allowIrrefutable = (i == size - 1) && oldPc.allowIrrefutable; - pc.failPop = null; - pc.onTop = 0; - - addOp(DUP_TOP); - visit(pattern, pc); - int nstores = pc.stores.size(); - if (i == 0) { - // This is the first alternative, so save its stores as a "control" - // for the others (they can't bind a different set of names, and - // might need to be reordered): - assert control == null; - control = pc.stores; - } - if (nstores != control.size()) { - throw altPatternsDiffNamesError(); - } else if (nstores != 0) { - // There were captures. Check to see if we differ from control: - int icontrol = nstores; - while (icontrol-- > 0) { - String name = control.get(icontrol); - int istores = pc.stores.indexOf(name); - if (istores < 0) { - throw altPatternsDiffNamesError(); - } - if (icontrol != istores) { - // Reorder the names on the stack to match the order of the - // names in control. There's probably a better way of doing - // this; the current solution is potentially very - // inefficient when each alternative subpattern binds lots - // of names in different orders. It's fine for reasonable - // cases, though. - assert istores < icontrol; - int rotations = istores + 1; - // Perform the same rotation on pc.stores: - ArrayList rotated = new ArrayList<>(); - Iterator it = pc.stores.iterator(); - int r = 0; - while (it.hasNext() && r++ < rotations) { - rotated.add(it.next()); - it.remove(); - } - for (int j = 0; j < rotated.size(); j++) { - pc.stores.add(icontrol - istores + j, rotated.get(j)); - } - - // That just did: - // rotated = pc_stores[:rotations] - // del pc_stores[:rotations] - // pc_stores[icontrol-istores:icontrol-istores] = rotated - // Do the same thing to the stack, using several ROT_Ns: - while (rotations-- > 0) { - addOp(ROT_N, icontrol + 1); - } - } - } - } - assert control != null; - addOp(JUMP_FORWARD, end); - unit.useNextBlock(new Block()); - emitAndResetFailPop(pc); - } - pc = oldPc; - addOp(POP_TOP); - jumpToFailPop(JUMP_FORWARD, pc); - unit.useNextBlock(end); - - int nstores = control.size(); - // There's a bunch of stuff on the stack between any where the new stores - // are and where they need to be: - // - The other stores. - // - A copy of the subject. - // - Anything else that may be on top of the stack. - // - Any previous stores we've already stashed away on the stack. - int nrots = nstores + 1 + pc.onTop + pc.stores.size(); - for (int i = 0; i < nstores; i++) { - // Rotate this capture to its proper place on the stack: - addOp(ROT_N, nrots); - // Update the list of previous stores with this new name, checking for duplicates: - String name = control.get(i); - if (pc.stores.contains(name)) { - throw duplicateStoreError(name); - } - pc.stores.add(name); - } - - // Pop the copy of the subject: - addOp(POP_TOP); - - return null; - } - - private RuntimeException altPatternsDiffNamesError() { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "alternative patterns bind different names"); - } - - private RuntimeException duplicateStoreError(String name) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "multiple assignments to name '%s' in pattern", name); - } - - public Void visit(PatternTy.MatchSingleton node, PatternContext pc) { - setLocation(node); - switch (node.value.kind) { - case BOOLEAN: - if (node.value.getBoolean()) { - addOp(LOAD_TRUE); - } else { - addOp(LOAD_FALSE); - } - break; - case NONE: - addOp(LOAD_NONE); - break; - default: - throw new IllegalStateException("wrong MatchSingleton value kind " + node.value.kind); - } - addCompareOp(CmpOpTy.Is); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - return null; - } - - public Void visit(PatternTy.MatchValue node, PatternContext pc) { - setLocation(node); - if (node.value instanceof ExprTy.UnaryOp || node.value instanceof ExprTy.BinOp) { - addConstant(foldConstantOp(node.value)); - } else if (node.value instanceof ExprTy.Constant || node.value instanceof ExprTy.Attribute) { - node.value.accept(this); - } else { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "patterns may only match literals and attribute lookups"); - } - addCompareOp(CmpOpTy.Eq); - jumpToFailPop(POP_AND_JUMP_IF_FALSE, pc); - return null; - } - - /** - * handles only particular cases when a constant comes either as a unary or binary op - */ - private ConstantValue foldConstantOp(ExprTy value) { - if (value instanceof ExprTy.UnaryOp) { - return foldUnaryOpConstant((ExprTy.UnaryOp) value); - } else if (value instanceof ExprTy.BinOp) { - return foldBinOpComplexConstant((ExprTy.BinOp) value); - } - throw new IllegalStateException("should not reach here"); - } - - /** - * handles only unary sub and a numeric constant - */ - private ConstantValue foldUnaryOpConstant(ExprTy.UnaryOp unaryOp) { - assert unaryOp.op == UnaryOpTy.USub; - assert unaryOp.operand instanceof ExprTy.Constant : unaryOp.operand; - SourceRange savedLocation = setLocation(unaryOp); - try { - ExprTy.Constant c = (ExprTy.Constant) unaryOp.operand; - ConstantValue ret = c.value.negate(); - assert ret != null; - return ret; - } finally { - setLocation(savedLocation); - } - } - - /** - * handles only complex which comes as a BinOp - */ - private ConstantValue foldBinOpComplexConstant(ExprTy.BinOp binOp) { - assert (binOp.left instanceof ExprTy.UnaryOp || binOp.left instanceof ExprTy.Constant) && binOp.right instanceof ExprTy.Constant : binOp.left + " " + binOp.right; - assert binOp.op == OperatorTy.Sub || binOp.op == OperatorTy.Add; - SourceRange savedLocation = setLocation(binOp); - try { - ConstantValue left; - if (binOp.left instanceof ExprTy.UnaryOp) { - left = foldUnaryOpConstant((ExprTy.UnaryOp) binOp.left); - } else { - left = ((ExprTy.Constant) binOp.left).value; - } - ExprTy.Constant right = (ExprTy.Constant) binOp.right; - switch (binOp.op) { - case Add: - return left.addComplex(right.value); - case Sub: - return left.subComplex(right.value); - default: - throw new IllegalStateException("wrong constant BinOp operator " + binOp.op); - } - } finally { - setLocation(savedLocation); - } - } - - private void jumpToFailPop(OpCodes op, PatternContext pc) { - // Pop any items on the top of the stack, plus any objects we were going to capture on - // success: - int pops = pc.onTop + (pc.stores == null ? 0 : pc.stores.size()); - ensureFailPop(pops, pc); - addConditionalJump(op, pc.failPop.get(pops)); - unit.useNextBlock(new Block()); - } - - private static void ensureFailPop(int n, PatternContext pc) { - int size = n + 1; - if (pc.failPop != null && size <= pc.failPop.size()) { - return; - } - if (pc.failPop == null) { - pc.failPop = new ArrayList<>(); - } - while (pc.failPop.size() < size) { - Block b = new Block(); - pc.failPop.add(b); - } - } - - private void emitAndResetFailPop(PatternContext pc) { - if (pc.failPop == null) { - unit.useNextBlock(new Block()); - return; - } - Collections.reverse(pc.failPop); - Iterator it = pc.failPop.iterator(); - while (it.hasNext()) { - Block b = it.next(); - unit.useNextBlock(b); - it.remove(); - if (it.hasNext()) { - addOp(POP_TOP); - } - } - } - - @Override - public Void visit(MatchCaseTy node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchValue node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchSingleton node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchAs node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchClass node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchMapping node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchOr node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchSequence node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(PatternTy.MatchStar node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(StmtTy.Nonlocal node) { - setLocation(node); - return null; - } - - @Override - public Void visit(StmtTy.Raise node) { - setLocation(node); - int argc = 0; - if (node.exc != null) { - argc++; - node.exc.accept(this); - if (node.cause != null) { - argc++; - node.cause.accept(this); - } - } - addOp(RAISE_VARARGS, argc); - unit.useNextBlock(new Block()); - return null; - } - - @Override - public Void visit(StmtTy.Return node) { - setLocation(node); - if (!unit.scope.isFunction()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'return' outside function"); - } - if (node.value != null && unit.scope.isGenerator() && unit.scope.isCoroutine()) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "'return' with value in async generator"); - } - if (node.value == null) { - unwindBlockStack(UnwindType.RETURN_CONST); - addOp(LOAD_NONE); - } else if (node.value instanceof ExprTy.Constant) { - unwindBlockStack(UnwindType.RETURN_CONST); - node.value.accept(this); - } else { - node.value.accept(this); - unwindBlockStack(UnwindType.RETURN_VALUE); - } - return addOp(RETURN_VALUE); - } - - private void jumpToFinally(Block finalBlock, Block end) { - if (finalBlock != null) { - addOp(JUMP_FORWARD, finalBlock); - } else { - addOp(JUMP_FORWARD, end); - } - } - - @Override - public Void visit(StmtTy.Try node) { - setLocation(node); - if (node.body[0].getSourceRange().startLine != node.getSourceRange().startLine) { - // Add NOP for tracing the line with 'try:' - addOp(NOP); - } - Block tryBody = new Block(); - Block end = new Block(); - boolean hasFinally = node.finalBody != null; - boolean hasHandlers = node.handlers != null && node.handlers.length > 0; - assert hasFinally || hasHandlers; - Block exceptionHandlerBlock = null; - Block finallyBlockNormal = null; - Block finallyBlockExcept = null; - Block finallyBlockExceptWithSavedExc = null; - Block elseBlock = node.orElse != null ? new Block() : null; - if (hasFinally) { - finallyBlockNormal = new Block(); - finallyBlockExcept = new Block(); - finallyBlockExceptWithSavedExc = new Block(); - unit.pushBlock(new BlockInfo.TryFinally(tryBody, finallyBlockExcept, node.finalBody)); - } - if (hasHandlers) { - exceptionHandlerBlock = new Block(); - unit.pushBlock(new BlockInfo.TryExcept(tryBody, exceptionHandlerBlock)); - } - // try block - unit.useNextBlock(tryBody); - visitSequence(node.body); - if (hasHandlers) { - unit.popBlock(); - } - if (elseBlock != null) { - addOp(JUMP_FORWARD, elseBlock); - } else { - jumpToFinally(finallyBlockNormal, end); - } - - // except clauses - if (hasHandlers) { - unit.useNextBlock(exceptionHandlerBlock); - /* This puts saved exception under the current exception */ - addOp(PUSH_EXC_INFO); - /* The stack is now [*, savedException, currentException] */ - boolean hasBareExcept = false; - Block nextHandler = new Block(); - /* - * We need to save and restore the outer exception state. In order to restore it even in - * case of an exception, we need an internal finally handler for this. - */ - Block commonCleanupHandler = new Block(); - unit.pushBlock(new BlockInfo.ExceptHandler(nextHandler, commonCleanupHandler)); - /* - * We use this offset to unwind the exception from the except block, we don't need it on - * the stack - */ - commonCleanupHandler.unwindOffset = -1; - for (int i = 0; i < node.handlers.length; i++) { - ExceptHandlerTy.ExceptHandler handler = ((ExceptHandlerTy.ExceptHandler) node.handlers[i]); - setLocation(handler); - if (hasBareExcept) { - throw parserCallbacks.onError(ErrorType.Syntax, unit.currentLocation, "default 'except:' must be last"); - } - unit.useNextBlock(nextHandler); - - if (i < node.handlers.length - 1) { - nextHandler = new Block(); - } else { - if (hasFinally) { - // Keep the saved state, it's the same - nextHandler = finallyBlockExceptWithSavedExc; - } else { - nextHandler = commonCleanupHandler; - } - } - - Block bindingCleanerExcept = null; - String bindingName = handler.name; - if (handler.type != null) { - handler.type.accept(this); - addConditionalJump(MATCH_EXC_OR_JUMP, nextHandler); - if (bindingName != null) { - addOp(UNWRAP_EXC); - addNameOp(bindingName, ExprContextTy.Store); - Block handlerWithBinding = new Block(); - bindingCleanerExcept = new Block(); - unit.pushBlock(new BlockInfo.HandlerBindingCleanup(handlerWithBinding, bindingCleanerExcept, bindingName)); - unit.useNextBlock(handlerWithBinding); - } else { - addOp(POP_TOP); - } - } else { - hasBareExcept = true; - addOp(POP_TOP); - } - visitSequence(handler.body); - if (bindingName != null) { - unit.popBlock(); - unit.useNextBlock(new Block()); - addOp(LOAD_NONE); - addNameOp(bindingName, ExprContextTy.Store); - addNameOp(bindingName, ExprContextTy.Del); - } - addOp(POP_EXCEPT); - jumpToFinally(finallyBlockNormal, end); - if (bindingName != null) { - unit.useNextBlock(bindingCleanerExcept); - addOp(LOAD_NONE); - addNameOp(bindingName, ExprContextTy.Store); - addNameOp(bindingName, ExprContextTy.Del); - cleanupOnExceptionInHandler(hasFinally, finallyBlockExcept); - } - } - unit.popBlock(); - unit.useNextBlock(commonCleanupHandler); - cleanupOnExceptionInHandler(hasFinally, finallyBlockExcept); - } - - if (elseBlock != null) { - unit.useNextBlock(elseBlock); - visitSequence(node.orElse); - jumpToFinally(finallyBlockNormal, end); - } - - /* - * We emit two copies of the finally block, one that is executed when there is no exception - * and one that is executed when an exception occurs. The latter needs to deal with the - * exception state. We start with the latter. - */ - if (hasFinally) { - unit.popBlock(); - unit.useNextBlock(finallyBlockExcept); - /* This puts saved exception under the current exception */ - addOp(PUSH_EXC_INFO); - Block cleanupHandler = new Block(); - cleanupHandler.unwindOffset = -1; - unit.pushBlock(new BlockInfo.FinallyHandler(finallyBlockExceptWithSavedExc, cleanupHandler)); - /* The stack is [*, savedException, currentException] */ - unit.useNextBlock(finallyBlockExceptWithSavedExc); - visitSequence(node.finalBody); - unit.popBlock(); - unit.useNextBlock(cleanupHandler); - addOp(END_EXC_HANDLER); - - /* Now emit the finally for the no-exception case */ - unit.useNextBlock(finallyBlockNormal); - visitSequence(node.finalBody); - } - - unit.useNextBlock(end); - - return null; - } - - @Override - public Void visit(StmtTy.TryStar node) { - emitNotImplemented("try star"); - return null; - } - - private void cleanupOnExceptionInHandler(boolean hasFinally, Block finallyBlockExcept) { - if (hasFinally) { - addOp(ROT_TWO); - /* - * POP the saved exception state, the finally block needs to push a new one. The saved - * state will be the same, but PUSH_EXC_INFO also updates the current exception info - * which is now different. - */ - addOp(POP_EXCEPT); - addOp(JUMP_FORWARD, finallyBlockExcept); - } else { - /* - * We can also reach this code by falling off the except handlers if no types matched - * and there is no finally - */ - addOp(END_EXC_HANDLER); - } - } - - @Override - public Void visit(ExceptHandlerTy.ExceptHandler node) { - throw new IllegalStateException("should not reach here"); - } - - @Override - public Void visit(StmtTy.While node) { - setLocation(node); - Block test = new Block(); - Block body = new Block(); - Block end = new Block(); - Block orelse = node.orElse != null ? new Block() : end; - unit.useNextBlock(test); - jumpIf(node.test, orelse, false); - unit.useNextBlock(body); - unit.pushBlock(new BlockInfo.While(test, end)); - try { - visitSequence(node.body); - addOp(JUMP_BACKWARD, test); - } finally { - unit.popBlock(); - } - if (node.orElse != null) { - unit.useNextBlock(orelse); - visitSequence(node.orElse); - } - unit.useNextBlock(end); - return null; - } - - @Override - public Void visit(StmtTy.With node) { - setLocation(node); - visitWith(node, 0); - unit.useNextBlock(new Block()); - return null; - } - - private void visitWith(StmtTy.With node, int itemIndex) { - Block body = new Block(); - Block handler = new Block(); - - WithItemTy item = node.items[itemIndex]; - item.contextExpr.accept(this); - addOp(SETUP_WITH); - unit.pushBlock(new BlockInfo.With(body, handler, node)); - - unit.useNextBlock(body); - /* - * Unwind one more stack item than it normally would to get rid of the context manager that - * is not needed in the finally block - */ - handler.unwindOffset = -1; - if (item.optionalVars != null) { - item.optionalVars.accept(this); - } else { - addOp(POP_TOP); - } - if (itemIndex < node.items.length - 1) { - visitWith(node, itemIndex + 1); - } else { - visitSequence(node.body); - } - addOp(LOAD_NONE); - unit.popBlock(); - - unit.useNextBlock(handler); - setLocation(node); - addOp(EXIT_WITH); - } - - @Override - public Void visit(WithItemTy node) { - throw new IllegalStateException("should not reach here"); - } - - private enum UnwindType { - BREAK, - CONTINUE, - RETURN_VALUE, - RETURN_CONST, - } - - private BlockInfo.Loop unwindBlockStack(UnwindType type) { - final BlockInfo savedInfo = unit.blockInfo; - try { - BlockInfo info = unit.blockInfo; - while (info != null) { - unit.blockInfo = info.outer; - if (info instanceof BlockInfo.For) { - if (type == UnwindType.CONTINUE) { - return (BlockInfo.Loop) info; - } - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_TWO); - } - addOp(POP_TOP); - if (type == UnwindType.BREAK) { - return (BlockInfo.Loop) info; - } - } else if (info instanceof BlockInfo.While) { - if (type == UnwindType.BREAK || type == UnwindType.CONTINUE) { - return (BlockInfo.Loop) info; - } - } else if (info instanceof BlockInfo.With) { - unit.useNextBlock(new Block()); - BlockInfo.With with = (BlockInfo.With) info; - setLocation(with.node); - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_THREE); - } - addOp(LOAD_NONE); - addOp(EXIT_WITH); - } else if (info instanceof BlockInfo.AsyncWith) { - unit.useNextBlock(new Block()); - BlockInfo.AsyncWith with = (BlockInfo.AsyncWith) info; - setLocation(with.node); - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_THREE); - } - addOp(LOAD_NONE); - addOp(GET_AEXIT_CORO); - addOp(GET_AWAITABLE); - addOp(LOAD_NONE); - addYieldFrom(); - addOp(EXIT_AWITH); - - } else if (info instanceof BlockInfo.TryFinally) { - unit.useNextBlock(new Block()); - if (type == UnwindType.RETURN_VALUE) { - /* - * If we're returning, the finally block may "cancel" the return using - * break/continue. In that case, we need to pop the return value. - */ - unit.pushBlock(new BlockInfo.PopValue()); - } - visitSequence(((BlockInfo.TryFinally) info).body); - } else if (info instanceof BlockInfo.ExceptHandler) { - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_TWO); - } - addOp(POP_EXCEPT); - } else if (info instanceof BlockInfo.HandlerBindingCleanup) { - String bindingName = ((BlockInfo.HandlerBindingCleanup) info).bindingName; - if (bindingName != null) { - addOp(LOAD_NONE); - addNameOp(bindingName, ExprContextTy.Store); - addNameOp(bindingName, ExprContextTy.Del); - } - } else if (info instanceof BlockInfo.FinallyHandler) { - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_THREE); - } - addOp(POP_EXCEPT); - addOp(POP_TOP); - } else if (info instanceof BlockInfo.PopValue) { - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_TWO); - } - addOp(POP_TOP); - } else if (info instanceof BlockInfo.AsyncForLoop) { - // AsyncForLoopExit cannot have a return, break, or continue in it, so no need - // to check it. - if (type == UnwindType.CONTINUE) { - return (BlockInfo.Loop) info; - } - if (type == UnwindType.RETURN_VALUE) { - addOp(ROT_TWO); - } - addOp(POP_TOP); - if (type == UnwindType.BREAK) { - return (BlockInfo.Loop) info; - } - } - info = info.outer; - } - } finally { - unit.blockInfo = savedInfo; - } - return null; - } - - @Override - @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH") // info is not null guaranteed by parser - public Void visit(StmtTy.Break node) { - setLocation(node); - SourceRange originLoc = unit.currentLocation; - BlockInfo.Loop info = unwindBlockStack(UnwindType.BREAK); - if (info == null) { - throw parserCallbacks.onError(ErrorType.Syntax, originLoc, "'break' outside loop"); - } - addOp(JUMP_FORWARD, info.after); - return null; - } - - @Override - @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH") // info is not null guaranteed by parser - public Void visit(StmtTy.Continue node) { - setLocation(node); - SourceRange originLoc = unit.currentLocation; - BlockInfo.Loop info = unwindBlockStack(UnwindType.CONTINUE); - if (info == null) { - throw parserCallbacks.onError(ErrorType.Syntax, originLoc, "'continue' not properly in loop"); - } - addOp(JUMP_BACKWARD, info.start); - return null; - } - - @Override - public Void visit(StmtTy.Pass node) { - setLocation(node); - addOp(NOP); - return null; - } - - @Override - public Void visit(TypeAlias node) { - SourceRange savedLocation = setLocation(node); - try { - boolean isGeneric = node.typeParams != null && node.typeParams.length > 0; - String name = ((ExprTy.Name) node.name).id; - if (isGeneric) { - String typeParamsName = ""; - enterScope(typeParamsName, CompilationScope.TypeParams, node.typeParams, null, node.getSourceRange()); - } - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(name))); - if (isGeneric) { - visitTypeParams(node.typeParams); - } else { - addOp(LOAD_NONE); - } - enterScope(name, CompilationScope.Function, node); - // Make None the first constant, so the evaluate function can't have a docstring. - addObject(unit.constants, PNone.NONE); - node.value.accept(this); - addOp(RETURN_VALUE); - CodeUnit code = unit.assemble(); - exitScope(); - makeClosure(code, 0); - addOp(MAKE_TYPE_ALIAS); - - if (isGeneric) { - addOp(RETURN_VALUE); - CodeUnit typeParamsCode = unit.assemble(); - exitScope(); - makeClosure(typeParamsCode, 0); - addOp(CALL_FUNCTION, 0); - } - addNameOp(name, ExprContextTy.Store); - return null; - } finally { - setLocation(savedLocation); - } - } - - @Override - public Void visit(TypeVar node) { - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(node.name))); - if (node.bound != null) { - enterScope(node.name, CompilationScope.TypeParams, node); - node.bound.accept(this); - addOp(RETURN_VALUE); - CodeUnit code = unit.assemble(); - exitScope(); - makeClosure(code, 0); - addOp(MAKE_TYPE_PARAM, node.bound instanceof Tuple ? MakeTypeParamKind.TYPE_VAR_WITH_CONSTRAINTS : MakeTypeParamKind.TYPE_VAR_WITH_BOUND); - } else { - addOp(MAKE_TYPE_PARAM, MakeTypeParamKind.TYPE_VAR); + if (existing == CollectionBits.ELEMENT_LONG && type == CollectionBits.ELEMENT_INT || existing == CollectionBits.ELEMENT_INT && type == CollectionBits.ELEMENT_LONG) { + return CollectionBits.ELEMENT_LONG; } - addOp(DUP_TOP); - addNameOp(node.name, ExprContextTy.Store); - return null; - } - - @Override - public Void visit(ParamSpec node) { - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(node.name))); - addOp(MAKE_TYPE_PARAM, MakeTypeParamKind.PARAM_SPEC); - addOp(DUP_TOP); - addNameOp(node.name, ExprContextTy.Store); - return null; - } - - @Override - public Void visit(TypeVarTuple node) { - addOp(LOAD_STRING, addObject(unit.constants, toTruffleStringUncached(node.name))); - addOp(MAKE_TYPE_PARAM, MakeTypeParamKind.TYPE_VAR_TUPLE); - addOp(DUP_TOP); - addNameOp(node.name, ExprContextTy.Store); - return null; - } - - // Equivalent of compiler_warn() - private void warn(SSTNode node, String message, Object... arguments) { - parserCallbacks.onWarning(WarningType.Syntax, node.getSourceRange(), message, arguments); + return CollectionBits.ELEMENT_OBJECT; } public static Parser createParser(String src, ParserCallbacks errorCb, InputType inputType, boolean interactiveTerminal, boolean allowIncompleteInput) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Instruction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Instruction.java deleted file mode 100644 index 153f2b5494..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Instruction.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import java.util.List; - -import com.oracle.graal.python.pegparser.tokenizer.SourceRange; - -final class Instruction { - - final OpCodes opcode; - int arg; - final byte[] followingArgs; - final Block target; - final SourceRange location; - - /** - * Bytecode index of the start of the instruction in the instruction stream including possible - * extended args - */ - public int bci = -1; - public boolean quickenOutput; - public List quickeningGeneralizeList; - - Instruction(OpCodes opcode, int arg, byte[] followingArgs, Block target, SourceRange location) { - this.opcode = opcode; - this.arg = arg; - this.followingArgs = followingArgs; - this.target = target; - this.location = location; - assert opcode.argLength < 2 || followingArgs.length == opcode.argLength - 1; - } - - @Override - public String toString() { - if (target != null) { - return String.format("%s %s", opcode, target); - } - if (opcode.hasArg()) { - return String.format("%s %s", opcode, arg); - } - return opcode.toString(); - } - - public int bodyBci() { - assert bci != -1; - // 2 bytes for EXTENDED_ARG opcode and the arg itself - return bci + 2 * extensions(); - } - - public int extensions() { - if (arg <= 0xFF) { - return 0; - } else if (arg <= 0xFFFF) { - return 1; - } else if (arg <= 0xFFFFFF) { - return 2; - } else { - return 3; - } - } - - public int extendedLength() { - return opcode.length() + extensions() * 2; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java deleted file mode 100644 index 2d12bf55f6..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2022, 2024, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.Arrays; - -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.source.Source; -import com.oracle.truffle.api.source.SourceSection; - -/** - * Helper for encapsulating the encoding and decoding of source line and column information for - * bytecode. - */ -public class SourceMap { - @CompilationFinal(dimensions = 1) public final int[] startLineMap; - @CompilationFinal(dimensions = 1) public final int[] endLineMap; - @CompilationFinal(dimensions = 1) public final int[] startColumnMap; - @CompilationFinal(dimensions = 1) public final int[] endColumnMap; - - private static final byte EXTENDED_NUM = -128; - private static final byte NEXT_LINE = -127; - private static final byte NEXT_LINES = -126; - private static final byte MIN_NUM = -125; - private static final byte MULTIPLIER_NEGATIVE = MIN_NUM + 1; - private static final byte MAX_NUM = 127; - private static final byte MULTIPLIER_POSITIVE = MAX_NUM; - - public SourceMap(byte[] code, byte[] srcTable, int startLine, int startColumn) { - CompilerAsserts.neverPartOfCompilation(); - startLineMap = new int[code.length]; - endLineMap = new int[code.length]; - startColumnMap = new int[code.length]; - endColumnMap = new int[code.length]; - ByteArrayInputStream stream = new ByteArrayInputStream(srcTable); - int[] startLineAndColumn = new int[]{startLine, startColumn}; - for (int bci = 0; bci < code.length;) { - OpCodes op = OpCodes.fromOpCode(code[bci]); - readLineAndColumn(stream, startLineAndColumn); - int[] endLineAndColumn = Arrays.copyOf(startLineAndColumn, 2); - readLineAndColumn(stream, endLineAndColumn); - Arrays.fill(startLineMap, bci, bci + op.length(), startLineAndColumn[0]); - Arrays.fill(startColumnMap, bci, bci + op.length(), startLineAndColumn[1]); - Arrays.fill(endLineMap, bci, bci + op.length(), endLineAndColumn[0]); - Arrays.fill(endColumnMap, bci, bci + op.length(), endLineAndColumn[1]); - bci += op.length(); - } - } - - private static void readLineAndColumn(ByteArrayInputStream stream, int[] pair) { - stream.mark(1); - byte value = (byte) stream.read(); - if (value == NEXT_LINE) { - pair[0]++; - pair[1] = 0; - } else if (value == NEXT_LINES) { - pair[0] += readNum(stream); - pair[1] = 0; - } else { - stream.reset(); - } - pair[1] += readNum(stream); - } - - private static int readNum(ByteArrayInputStream offsets) { - int extensions = 0; - while (true) { - int intValue = offsets.read(); - assert intValue != -1; - byte value = (byte) intValue; - if (value == EXTENDED_NUM) { - extensions++; - } else if (value < 0) { - return extensions * MULTIPLIER_NEGATIVE + value; - } else { - return extensions * MULTIPLIER_POSITIVE + value; - } - } - } - - public static SourceSection getSourceSection(Source source, int startLine, int startColumn, int endLine, int endColumn) { - if (!source.hasCharacters()) { - return source.createUnavailableSection(); - } - try { - /* Truffle columns are 1-based */ - startColumn = Math.max(startColumn + 1, 1); - endColumn = Math.max(endColumn + 1, 1); - /* Truffle doesn't consider the newline a part of the line */ - if (endColumn == source.getLineLength(endLine) + 1) { - endColumn--; - } - return source.createSection(startLine, startColumn, endLine, endColumn); - } catch (IllegalArgumentException e) { - // TODO GR-40896 we don't track source ranges of f-strings correctly - // Also consider sources created from ast module - return source.createUnavailableSection(); - } - } - - public SourceSection getSourceSection(Source source, int bci) { - return getSourceSection(source, startLineMap[bci], startColumnMap[bci], endLineMap[bci], endColumnMap[bci]); - } - - /** - * Encoding: startLine=[NEXT_LINE|NEXT_LINES num] startColumn=num endLine=[NEXT_LINE|NEXT_LINES - * num] endColumn=num - */ - public static class Builder { - private final ByteArrayOutputStream stream = new ByteArrayOutputStream(); - private int lastLine; - private int lastColumn; - - public Builder(int startLine, int startColumn) { - this.lastLine = startLine; - this.lastColumn = startColumn; - } - - private void writeNum(int offset) { - while (offset > MAX_NUM) { - stream.write(EXTENDED_NUM); - offset -= MULTIPLIER_POSITIVE; - } - while (offset < MIN_NUM) { - stream.write(EXTENDED_NUM); - offset -= MULTIPLIER_NEGATIVE; - } - stream.write(offset); - } - - private void writeLine(int lineDelta) { - if (lineDelta == 1) { - stream.write(NEXT_LINE); - } else { - stream.write(NEXT_LINES); - writeNum(lineDelta); - } - } - - private void writeDeltas(int baseColumn, int column, int lineDelta) { - if (lineDelta != 0) { - writeLine(lineDelta); - writeNum(column); - } else { - writeNum(column - baseColumn); - } - } - - public void appendLocation(int startLine, int startColumn, int endLine, int endColumn) { - // ENDMARKER tokens produce negative columns - if (startColumn < 0) { - startColumn = 0; - } - if (endColumn < 0) { - endColumn = 0; - } - if (endLine == 0) { - endLine = startLine; - } - if (endColumn == 0) { - endColumn = startColumn; - } - assert startLine >= 0 && endLine >= startLine && (startLine != endLine || endColumn >= startColumn); - int lineDelta = startLine - lastLine; - int lineSpan = endLine - startLine; - writeDeltas(lastColumn, startColumn, lineDelta); - writeDeltas(startColumn, endColumn, lineSpan); - lastLine = startLine; - lastColumn = startColumn; - } - - public byte[] build() { - return stream.toByteArray(); - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java index 2737745745..08dd406578 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectIsTrueNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -151,7 +151,7 @@ public static boolean doSet(PBaseSet object, @StoreBytecodeIndex public static boolean doOthers(VirtualFrame frame, Object object, @Cached PyObjectIsTrueNodeGeneric internalNode) { - // Cached PyObjectItTrue nodes used in PBytecodeRootNode are significant contributors to + // Cached PyObjectItTrue nodes used in bytecode roots are significant contributors to // footprint, so we use indirection to save all the fields for the nodes used in the generic // variant + this is one polymorphic dispatch to the execute method. Inside the cached // execute method, the hosted inlining can then inline cached nodes, unlike if we inlined to diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java index 112ce0cc79..74bd1f80a9 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java @@ -93,7 +93,6 @@ import com.oracle.graal.python.lib.PyTupleCheckNode; import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; import com.oracle.graal.python.nodes.object.IsForeignObjectNode; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.graal.python.runtime.sequence.PSequence; import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage; @@ -532,8 +531,4 @@ public static boolean hasBuiltinDictIter(Node inliningTarget, PDict dict, GetPyt return isBuiltinDict(dict) || getSlots.execute(inliningTarget, getClassNode.execute(inliningTarget, dict)).tp_iter() == DictBuiltins.SLOTS.tp_iter(); } - @Idempotent - public static boolean isBytecodeDSLInterpreter() { - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; - } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BytecodeFrameInfo.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BytecodeFrameInfo.java deleted file mode 100644 index 635a585e80..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BytecodeFrameInfo.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2025, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.compiler.OpCodesConstants; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.frame.Frame; - -public class BytecodeFrameInfo implements FrameInfo { - @CompilationFinal PBytecodeRootNode rootNode; - - void setRootNode(PBytecodeRootNode rootNode) { - this.rootNode = rootNode; - } - - @Override - public PBytecodeRootNode getRootNode() { - return rootNode; - } - - public int getBci(Frame frame) { - if (frame.isInt(rootNode.bcioffset)) { - return frame.getInt(rootNode.bcioffset); - } else { - return -1; - } - } - - public int getLineForBci(int bci) { - return rootNode.bciToLine(bci); - } - - public int getLine(Frame frame) { - return getLineForBci(getBci(frame)); - } - - @Override - public int getFirstLineNumber() { - return rootNode.getFirstLineno(); - } - - public Object getYieldFrom(Frame generatorFrame, int bci, int stackTop) { - /* Match the `yield from` bytecode pattern and get the object from stack */ - if (bci > 3 && bci < rootNode.bytecode.length && rootNode.bytecode[bci - 3] == OpCodesConstants.SEND && rootNode.bytecode[bci - 1] == OpCodesConstants.YIELD_VALUE && - rootNode.bytecode[bci] == OpCodesConstants.RESUME_YIELD) { - return generatorFrame.getObject(stackTop); - } - return null; - } - - @Override - public CodeUnit getCodeUnit() { - return rootNode.getCodeUnit(); - } - - @Override - public boolean includeInTraceback() { - return rootNode.frameIsVisibleToPython(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorReturnException.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorReturnException.java deleted file mode 100644 index 7b30e46090..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorReturnException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022, 2023, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.runtime.exception.PythonControlFlowException; - -public final class GeneratorReturnException extends PythonControlFlowException { - private static final long serialVersionUID = -7509673125893533425L; - - public final transient Object value; - - public GeneratorReturnException(Object value) { - this.value = value; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorYieldResult.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorYieldResult.java deleted file mode 100644 index 5b049b9bc5..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GeneratorYieldResult.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.truffle.api.CompilerDirectives.ValueType; - -@ValueType -public final class GeneratorYieldResult { - public final int resumeBci; - public final int resumeStackTop; - public final Object yieldValue; - - public GeneratorYieldResult(int resumeBci, int resumeStackTop, Object yieldValue) { - this.resumeBci = resumeBci; - this.resumeStackTop = resumeStackTop; - this.yieldValue = yieldValue; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java deleted file mode 100644 index 6c1ed0cb3f..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeFunctionNode.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___ANNOTATIONS__; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.cell.PCell; -import com.oracle.graal.python.builtins.objects.code.PCode; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.builtins.objects.function.PFunction; -import com.oracle.graal.python.builtins.objects.function.PKeyword; -import com.oracle.graal.python.builtins.objects.object.PythonObject; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; -import com.oracle.graal.python.compiler.OpCodes; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.truffle.api.Assumption; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; - -public abstract class MakeFunctionNode extends PNodeWithContext { - private final int codeIndex; - private final BytecodeCodeUnit codeUnit; - @CompilationFinal private PCode cachedCode; - - private final Assumption codeStableAssumption = Truffle.getRuntime().createAssumption("code stable assumption"); - - public abstract int execute(VirtualFrame frame, Object globals, int initialStackTop, int flags); - - public MakeFunctionNode(int codeIndex, BytecodeCodeUnit codeUnit) { - this.codeIndex = codeIndex; - this.codeUnit = codeUnit; - } - - @Specialization - int makeFunction(VirtualFrame frame, Object globals, int initialStackTop, int flags, - @Bind PythonLanguage language, - @Cached WriteAttributeToPythonObjectNode writeAttrNode) { - int stackTop = initialStackTop; - - PCode code = cachedCode; - if (code == null) { - code = PArguments.getCodeObject(frame).getOrCreateChildCode(codeIndex, codeUnit); - if (PythonLanguage.get(this).isSingleContext()) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - /* - * We cannot initialize the cached code in create, because that may be called - * without langauge context when materializing nodes for instrumentation - */ - cachedCode = code; - } else { - // In multi-context mode we have to create the code for every execution - } - } - - PCell[] closure = null; - Object annotations = null; - PKeyword[] kwdefaults = null; - Object[] defaults = null; - - if ((flags & OpCodes.MakeFunctionFlags.HAS_CLOSURE) != 0) { - closure = (PCell[]) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } - if ((flags & OpCodes.MakeFunctionFlags.HAS_ANNOTATIONS) != 0) { - annotations = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } - if ((flags & OpCodes.MakeFunctionFlags.HAS_KWONLY_DEFAULTS) != 0) { - kwdefaults = (PKeyword[]) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } - if ((flags & OpCodes.MakeFunctionFlags.HAS_DEFAULTS) != 0) { - defaults = (Object[]) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } - - PFunction function = PFactory.createFunction(language, codeUnit.name, codeUnit.qualname, code, (PythonObject) globals, defaults, kwdefaults, closure, codeStableAssumption); - - if (annotations != null) { - writeAttrNode.execute(function, T___ANNOTATIONS__, annotations); - } - - frame.setObject(++stackTop, function); - return stackTop; - } - - @NeverDefault - public static MakeFunctionNode create(int codeIndex, BytecodeCodeUnit codeUnit) { - return MakeFunctionNodeGen.create(codeIndex, codeUnit); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRException.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRException.java deleted file mode 100644 index 099d9ffdbb..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.runtime.exception.PythonControlFlowException; -import com.oracle.truffle.api.exception.AbstractTruffleException; - -/* -Container for for propagating exceptions from OSR without handling them twice. - */ -public class OSRException extends PythonControlFlowException { - private static final long serialVersionUID = 425126860491305807L; - public final AbstractTruffleException exception; - - public OSRException(AbstractTruffleException exception) { - this.exception = exception; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRInterpreterState.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRInterpreterState.java deleted file mode 100644 index 3a12769cb0..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/OSRInterpreterState.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -final class OSRInterpreterState { - public final int stackTop; - - public OSRInterpreterState(int stackTop) { - this.stackTop = stackTop; - } - - static final int REPORT_LOOP_STRIDE = 1 << 8; - static final double REPORT_LOOP_PROBABILITY = (double) 1 / (double) REPORT_LOOP_STRIDE; -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java deleted file mode 100644 index 2eb9b045ed..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorFunctionRootNode.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2018, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.builtins.objects.function.PFunction; -import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.RootCallTarget; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.source.SourceSection; -import com.oracle.truffle.api.strings.TruffleString; - -public class PBytecodeGeneratorFunctionRootNode extends PRootNode { - private final PBytecodeRootNode rootNode; - private final TruffleString originalName; - - @CompilationFinal(dimensions = 1) private final RootCallTarget[] callTargets; - - @TruffleBoundary - public PBytecodeGeneratorFunctionRootNode(PythonLanguage language, FrameDescriptor frameDescriptor, PBytecodeRootNode rootNode, TruffleString originalName) { - super(language, frameDescriptor); - this.rootNode = rootNode; - this.originalName = originalName; - // TODO compress somehow - this.callTargets = new RootCallTarget[rootNode.getCodeUnit().code.length]; - this.callTargets[0] = new PBytecodeGeneratorRootNode(language, rootNode, 0, rootNode.getInitialStackTop()).getCallTarget(); - } - - @Override - public Object execute(VirtualFrame frame) { - Object[] arguments = frame.getArguments(); - - PythonLanguage language = PythonLanguage.get(this); - PFunction generatorFunction = PArguments.getFunctionObject(arguments); - assert generatorFunction != null; - if (rootNode.getCodeUnit().isGenerator()) { - return PFactory.createGenerator(language, generatorFunction, rootNode, callTargets, arguments); - } else if (rootNode.getCodeUnit().isCoroutine()) { - return PFactory.createCoroutine(language, generatorFunction, rootNode, callTargets, arguments); - } else if (rootNode.getCodeUnit().isAsyncGenerator()) { - return PFactory.createAsyncGenerator(language, generatorFunction, rootNode, callTargets, arguments); - } - throw CompilerDirectives.shouldNotReachHere("Unknown generator/coroutine type"); - } - - @Override - public String getName() { - return originalName.toJavaStringUncached(); - } - - @Override - public String toString() { - CompilerAsserts.neverPartOfCompilation(); - return ""; - } - - @Override - public Signature getSignature() { - return rootNode.getSignature(); - } - - @Override - public boolean isPythonInternal() { - return rootNode.isPythonInternal(); - } - - @Override - public SourceSection getSourceSection() { - return rootNode.getSourceSection(); - } - - public PBytecodeRootNode getBytecodeRootNode() { - return rootNode; - } - - @Override - protected byte[] extractCode(Node node) { - return rootNode.extractCode(node); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java deleted file mode 100644 index 6a7511cdac..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeGeneratorRootNode.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.compiler.QuickeningTypes; -import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.runtime.ExecutionContext; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.MaterializedFrame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.BytecodeOSRNode; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.source.SourceSection; - -public final class PBytecodeGeneratorRootNode extends PRootNode implements BytecodeOSRNode { - private final PBytecodeRootNode rootNode; - private final int resumeBci; - private final int resumeStackTop; - - @Child private ExecutionContext.CalleeContext calleeContext = ExecutionContext.CalleeContext.create(); - - @CompilationFinal private Object osrMetadata; - @CompilationFinal(dimensions = 1) private byte[] frameSlotTypes; - - @TruffleBoundary - public PBytecodeGeneratorRootNode(PythonLanguage language, PBytecodeRootNode rootNode, int resumeBci, int resumeStackTop) { - super(language, rootNode.getFrameDescriptor()); - this.rootNode = rootNode; - rootNode.adoptChildren(); - this.resumeBci = resumeBci; - this.resumeStackTop = resumeStackTop; - frameSlotTypes = new byte[resumeStackTop - rootNode.stackoffset + 1]; - } - - @ExplodeLoop - private void copyStackSlotsIntoVirtualFrame(MaterializedFrame generatorFrame, VirtualFrame virtualFrame) { - int offset = rootNode.stackoffset; - for (int i = 0; i < frameSlotTypes.length; i++) { - int frameIndex = i + offset; - switch (frameSlotTypes[i]) { - case QuickeningTypes.OBJECT: - if (generatorFrame.isObject(frameIndex)) { - virtualFrame.setObject(frameIndex, generatorFrame.getObject(frameIndex)); - continue; - } - break; - case QuickeningTypes.INT: - if (generatorFrame.isInt(frameIndex)) { - virtualFrame.setInt(frameIndex, generatorFrame.getInt(frameIndex)); - continue; - } - break; - case QuickeningTypes.LONG: - if (generatorFrame.isLong(frameIndex)) { - virtualFrame.setLong(frameIndex, generatorFrame.getLong(frameIndex)); - continue; - } - break; - case QuickeningTypes.DOUBLE: - if (generatorFrame.isDouble(frameIndex)) { - virtualFrame.setDouble(frameIndex, generatorFrame.getDouble(frameIndex)); - continue; - } - break; - case QuickeningTypes.BOOLEAN: - if (generatorFrame.isBoolean(frameIndex)) { - virtualFrame.setBoolean(frameIndex, generatorFrame.getBoolean(frameIndex)); - continue; - } - break; - } - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (generatorFrame.isObject(frameIndex)) { - virtualFrame.setObject(frameIndex, generatorFrame.getObject(frameIndex)); - frameSlotTypes[i] = QuickeningTypes.OBJECT; - } else if (generatorFrame.isInt(frameIndex)) { - virtualFrame.setInt(frameIndex, generatorFrame.getInt(frameIndex)); - frameSlotTypes[i] = QuickeningTypes.INT; - } else if (generatorFrame.isLong(frameIndex)) { - virtualFrame.setLong(frameIndex, generatorFrame.getLong(frameIndex)); - frameSlotTypes[i] = QuickeningTypes.LONG; - } else if (generatorFrame.isDouble(frameIndex)) { - virtualFrame.setDouble(frameIndex, generatorFrame.getDouble(frameIndex)); - frameSlotTypes[i] = QuickeningTypes.DOUBLE; - } else if (generatorFrame.isBoolean(frameIndex)) { - virtualFrame.setBoolean(frameIndex, generatorFrame.getBoolean(frameIndex)); - frameSlotTypes[i] = QuickeningTypes.BOOLEAN; - } else { - throw new IllegalStateException("unexpected frame slot type"); - } - } - } - - @Override - public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterStateObject) { - OSRInterpreterState interpreterState = (OSRInterpreterState) interpreterStateObject; - MaterializedFrame generatorFrame = PGenerator.getGeneratorFrame(osrFrame); - return rootNode.executeFromBci(osrFrame, generatorFrame, this, target, interpreterState.stackTop); - } - - @Override - public Object execute(VirtualFrame frame) { - MaterializedFrame generatorFrame = PGenerator.getGeneratorFrame(frame); - ExecutionContext.CalleeContext.enterGenerator(frame, generatorFrame); - /* - * Using the materialized frame as stack would be bad for compiled performance, so we copy - * the stack slots back to the virtual frame and use that as the stack. The values are - * copied back in yield node. - * - * TODO we could try to re-virtualize the locals too, but we would need to profile the loads - * and stores to only copy what is actually used, otherwise copying everything makes things - * worse. - */ - copyStackSlotsIntoVirtualFrame(generatorFrame, frame); - try { - return rootNode.executeFromBci(frame, generatorFrame, this, resumeBci, resumeStackTop); - } finally { - calleeContext.exit(frame, this); - } - } - - @Override - public Object getOSRMetadata() { - return osrMetadata; - } - - @Override - public void setOSRMetadata(Object osrMetadata) { - this.osrMetadata = osrMetadata; - } - - @Override - public Object[] storeParentFrameInArguments(VirtualFrame parentFrame) { - return rootNode.storeParentFrameInArguments(parentFrame); - } - - @Override - public Frame restoreParentFrameFromArguments(Object[] arguments) { - return rootNode.restoreParentFrameFromArguments(arguments); - } - - @Override - public String getName() { - return rootNode.getName(); - } - - @Override - public String toString() { - CompilerAsserts.neverPartOfCompilation(); - return ""; - } - - @Override - public boolean setsUpCalleeContext() { - return true; - } - - @Override - public Signature getSignature() { - return rootNode.getSignature(); - } - - @Override - public boolean isPythonInternal() { - return rootNode.isPythonInternal(); - } - - @Override - public SourceSection getSourceSection() { - return rootNode.getSourceSection(); - } - - public int getResumeBci() { - return resumeBci; - } - - public int getResumeStackTop() { - return resumeStackTop; - } - - public PBytecodeRootNode getBytecodeRootNode() { - return rootNode; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java deleted file mode 100644 index af53f81826..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java +++ /dev/null @@ -1,6283 +0,0 @@ -/* - * Copyright (c) 2018, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError; -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError; -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ZeroDivisionError; -import static com.oracle.graal.python.builtins.objects.type.TypeFlags.MAPPING; -import static com.oracle.graal.python.builtins.objects.type.TypeFlags.SEQUENCE; -import static com.oracle.graal.python.nodes.BuiltinNames.T___BUILD_CLASS__; -import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___CLASS__; -import static com.oracle.graal.python.runtime.exception.PythonErrorType.NameError; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_ASSUMPTION_ARRAY; -import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING; -import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached; - -import java.math.BigInteger; -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.locks.Lock; - -import org.graalvm.collections.Pair; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.asyncio.GetAwaitableNode; -import com.oracle.graal.python.builtins.objects.asyncio.GetAwaitableNodeGen; -import com.oracle.graal.python.builtins.objects.cell.PCell; -import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; -import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes; -import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes.SetItemNode; -import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory; -import com.oracle.graal.python.builtins.objects.common.HashingStorage; -import com.oracle.graal.python.builtins.objects.common.HashingStorageFactory; -import com.oracle.graal.python.builtins.objects.common.ObjectHashMap; -import com.oracle.graal.python.builtins.objects.dict.DictNodes; -import com.oracle.graal.python.builtins.objects.dict.DictNodesFactory; -import com.oracle.graal.python.builtins.objects.dict.PDict; -import com.oracle.graal.python.builtins.objects.ellipsis.PEllipsis; -import com.oracle.graal.python.builtins.objects.exception.ChainExceptionsNode; -import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes; -import com.oracle.graal.python.builtins.objects.exception.GetEscapedExceptionNode; -import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins; -import com.oracle.graal.python.builtins.objects.floats.FloatBuiltinsFactory; -import com.oracle.graal.python.builtins.objects.frame.PFrame; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction; -import com.oracle.graal.python.builtins.objects.function.PFunction; -import com.oracle.graal.python.builtins.objects.function.PKeyword; -import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.builtins.objects.ints.IntBuiltins; -import com.oracle.graal.python.builtins.objects.ints.IntBuiltinsFactory; -import com.oracle.graal.python.builtins.objects.list.ListBuiltins; -import com.oracle.graal.python.builtins.objects.list.ListBuiltinsFactory; -import com.oracle.graal.python.builtins.objects.list.PList; -import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod; -import com.oracle.graal.python.builtins.objects.set.PSet; -import com.oracle.graal.python.builtins.objects.set.SetBuiltins; -import com.oracle.graal.python.builtins.objects.set.SetBuiltinsFactory; -import com.oracle.graal.python.builtins.objects.set.SetNodes; -import com.oracle.graal.python.builtins.objects.set.SetNodesFactory; -import com.oracle.graal.python.builtins.objects.slice.PSlice; -import com.oracle.graal.python.builtins.objects.slice.SliceNodes.CreateSliceNode; -import com.oracle.graal.python.builtins.objects.slice.SliceNodesFactory.CreateSliceNodeGen; -import com.oracle.graal.python.compiler.BinaryOpsConstants; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; -import com.oracle.graal.python.compiler.FormatOptions; -import com.oracle.graal.python.compiler.OpCodes; -import com.oracle.graal.python.compiler.OpCodes.CollectionBits; -import com.oracle.graal.python.compiler.OpCodesConstants; -import com.oracle.graal.python.compiler.ParserCallbacksImpl; -import com.oracle.graal.python.compiler.QuickeningTypes; -import com.oracle.graal.python.compiler.UnaryOpsConstants; -import com.oracle.graal.python.lib.PyNumberAddNode; -import com.oracle.graal.python.lib.PyNumberAndNode; -import com.oracle.graal.python.lib.PyNumberFloorDivideNode; -import com.oracle.graal.python.lib.PyNumberInPlaceAddNode; -import com.oracle.graal.python.lib.PyNumberInPlaceAndNode; -import com.oracle.graal.python.lib.PyNumberInPlaceFloorDivideNode; -import com.oracle.graal.python.lib.PyNumberInPlaceLshiftNode; -import com.oracle.graal.python.lib.PyNumberInPlaceMatrixMultiplyNode; -import com.oracle.graal.python.lib.PyNumberInPlaceMultiplyNode; -import com.oracle.graal.python.lib.PyNumberInPlaceOrNode; -import com.oracle.graal.python.lib.PyNumberInPlacePowerNode; -import com.oracle.graal.python.lib.PyNumberInPlaceRemainderNode; -import com.oracle.graal.python.lib.PyNumberInPlaceRshiftNode; -import com.oracle.graal.python.lib.PyNumberInPlaceSubtractNode; -import com.oracle.graal.python.lib.PyNumberInPlaceTrueDivideNode; -import com.oracle.graal.python.lib.PyNumberInPlaceXorNode; -import com.oracle.graal.python.lib.PyNumberInvertNode; -import com.oracle.graal.python.lib.PyNumberLshiftNode; -import com.oracle.graal.python.lib.PyNumberMatrixMultiplyNode; -import com.oracle.graal.python.lib.PyNumberMultiplyNode; -import com.oracle.graal.python.lib.PyNumberNegativeNode; -import com.oracle.graal.python.lib.PyNumberOrNode; -import com.oracle.graal.python.lib.PyNumberPositiveNode; -import com.oracle.graal.python.lib.PyNumberPowerNode; -import com.oracle.graal.python.lib.PyNumberRemainderNode; -import com.oracle.graal.python.lib.PyNumberRshiftNode; -import com.oracle.graal.python.lib.PyNumberSubtractNode; -import com.oracle.graal.python.lib.PyNumberTrueDivideNode; -import com.oracle.graal.python.lib.PyNumberXorNode; -import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNode; -import com.oracle.graal.python.lib.PyObjectAsciiAsObjectNodeGen; -import com.oracle.graal.python.lib.PyObjectDelItem; -import com.oracle.graal.python.lib.PyObjectDelItemNodeGen; -import com.oracle.graal.python.lib.PyObjectFormat; -import com.oracle.graal.python.lib.PyObjectFormatNodeGen; -import com.oracle.graal.python.lib.PyObjectGetAttr; -import com.oracle.graal.python.lib.PyObjectGetAttrNodeGen; -import com.oracle.graal.python.lib.PyObjectGetItem; -import com.oracle.graal.python.lib.PyObjectGetItemNodeGen; -import com.oracle.graal.python.lib.PyObjectGetIter; -import com.oracle.graal.python.lib.PyObjectGetIterNodeGen; -import com.oracle.graal.python.lib.PyObjectGetMethod; -import com.oracle.graal.python.lib.PyObjectGetMethodNodeGen; -import com.oracle.graal.python.lib.PyObjectHashNode; -import com.oracle.graal.python.lib.PyObjectIsTrueNode; -import com.oracle.graal.python.lib.PyObjectIsTrueNodeGen; -import com.oracle.graal.python.lib.PyObjectReprAsObjectNode; -import com.oracle.graal.python.lib.PyObjectReprAsObjectNodeGen; -import com.oracle.graal.python.lib.PyObjectRichCompare.RichCompareBinaryOp; -import com.oracle.graal.python.lib.PyObjectSetAttr; -import com.oracle.graal.python.lib.PyObjectSetAttrNodeGen; -import com.oracle.graal.python.lib.PyObjectSetItem; -import com.oracle.graal.python.lib.PyObjectSetItemNodeGen; -import com.oracle.graal.python.lib.PyObjectSizeNode; -import com.oracle.graal.python.lib.PyObjectSizeNodeGen; -import com.oracle.graal.python.lib.PyObjectStrAsObjectNode; -import com.oracle.graal.python.lib.PyObjectStrAsObjectNodeGen; -import com.oracle.graal.python.lib.RichCmpOp; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode; -import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNodeGen; -import com.oracle.graal.python.nodes.builtins.ListNodes; -import com.oracle.graal.python.nodes.builtins.ListNodesFactory; -import com.oracle.graal.python.nodes.builtins.TupleNodes; -import com.oracle.graal.python.nodes.builtins.TupleNodesFactory; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNodeFactory.ObjHashMapPutNodeGen; -import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNode.ListFromStackNode; -import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNode.TupleFromStackNode; -import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNodeFactory.ListFromStackNodeGen; -import com.oracle.graal.python.nodes.bytecode.SequenceFromStackNodeFactory.TupleFromStackNodeGen; -import com.oracle.graal.python.nodes.bytecode.instrumentation.InstrumentationRoot; -import com.oracle.graal.python.nodes.bytecode.instrumentation.InstrumentationSupport; -import com.oracle.graal.python.nodes.call.BoundDescriptor; -import com.oracle.graal.python.nodes.call.CallNode; -import com.oracle.graal.python.nodes.call.CallNodeGen; -import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode; -import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNodeGen; -import com.oracle.graal.python.nodes.call.special.CallQuaternaryMethodNode; -import com.oracle.graal.python.nodes.call.special.CallQuaternaryMethodNodeGen; -import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode; -import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNodeGen; -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNodeGen; -import com.oracle.graal.python.nodes.exception.ExceptMatchNode; -import com.oracle.graal.python.nodes.exception.ExceptMatchNodeGen; -import com.oracle.graal.python.nodes.expression.BinaryOp; -import com.oracle.graal.python.nodes.expression.UnaryOpNode; -import com.oracle.graal.python.nodes.frame.DeleteGlobalNode; -import com.oracle.graal.python.nodes.frame.DeleteGlobalNodeGen; -import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode; -import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; -import com.oracle.graal.python.nodes.frame.ReadBuiltinNode; -import com.oracle.graal.python.nodes.frame.ReadBuiltinNodeGen; -import com.oracle.graal.python.nodes.frame.ReadFromLocalsNode; -import com.oracle.graal.python.nodes.frame.ReadFromLocalsNodeGen; -import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode; -import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNodeGen; -import com.oracle.graal.python.nodes.frame.ReadNameNode; -import com.oracle.graal.python.nodes.frame.ReadNameNodeGen; -import com.oracle.graal.python.nodes.frame.WriteGlobalNode; -import com.oracle.graal.python.nodes.frame.WriteGlobalNodeGen; -import com.oracle.graal.python.nodes.frame.WriteNameNode; -import com.oracle.graal.python.nodes.frame.WriteNameNodeGen; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.graal.python.nodes.object.IsNode; -import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode; -import com.oracle.graal.python.nodes.util.CastToJavaIntExactNodeGen; -import com.oracle.graal.python.nodes.util.ExceptionStateNodes; -import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext; -import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.graal.python.runtime.PythonOptions; -import com.oracle.graal.python.runtime.exception.ExceptionUtils; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.graal.python.runtime.exception.PythonExitException; -import com.oracle.graal.python.runtime.exception.PythonThreadKillException; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.graal.python.runtime.sequence.PSequence; -import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.graal.python.util.PythonUtils; -import com.oracle.truffle.api.Assumption; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.CompilerDirectives.ValueType; -import com.oracle.truffle.api.HostCompilerDirectives.BytecodeInterpreterSwitch; -import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.FrameSlotKind; -import com.oracle.truffle.api.frame.FrameSlotTypeException; -import com.oracle.truffle.api.frame.MaterializedFrame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode; -import com.oracle.truffle.api.instrumentation.ProbeNode; -import com.oracle.truffle.api.instrumentation.StandardTags; -import com.oracle.truffle.api.instrumentation.Tag; -import com.oracle.truffle.api.nodes.BytecodeOSRNode; -import com.oracle.truffle.api.nodes.ControlFlowException; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.RootNode; -import com.oracle.truffle.api.nodes.UnexpectedResultException; -import com.oracle.truffle.api.source.Source; -import com.oracle.truffle.api.source.SourceSection; -import com.oracle.truffle.api.strings.TruffleString; - -/** - * Root node with main bytecode interpreter loop. - */ -@SuppressWarnings("static-method") -public final class PBytecodeRootNode extends PRootNode implements BytecodeOSRNode { - - private static final NodeSupplier NODE_RAISENODE = RaiseNode::create; - private static final NodeSupplier NODE_OBJECT_DEL_ITEM = PyObjectDelItem::create; - private static final PyObjectDelItem UNCACHED_OBJECT_DEL_ITEM = PyObjectDelItem.getUncached(); - - private static final NodeSupplier NODE_SET_ITEM = HashingCollectionNodes.SetItemNode::create; - private static final SetItemNode UNCACHED_SET_ITEM = HashingCollectionNodes.SetItemNode.getUncached(); - private static final NodeSupplier NODE_OBJ_HASHMAP_PUT = ObjHashMapPutNodeGen::create; - private static final ObjHashMapPutNode UNCACHED_OBJ_HASHMAP_PUT = ObjHashMapPutNodeGen.getUncached(); - private static final NodeSupplier NODE_CAST_TO_JAVA_INT_EXACT = CastToJavaIntExactNode::create; - private static final CastToJavaIntExactNode UNCACHED_CAST_TO_JAVA_INT_EXACT = CastToJavaIntExactNode.getUncached(); - private static final ImportNode UNCACHED_IMPORT = ImportNode.getUncached(); - private static final ReadNameNode UNCACHED_READ_NAME = ReadNameNodeGen.getUncached(); - private static final WriteNameNode UNCACHED_WRITE_NAME = WriteNameNodeGen.getUncached(); - private static final NodeSupplier NODE_IMPORT = ImportNode::create; - private static final ImportStarNode UNCACHED_IMPORT_STAR = ImportStarNode.getUncached(); - private static final NodeSupplier NODE_IMPORT_STAR = ImportStarNode::create; - private static final NodeSupplier NODE_OBJECT_GET_ATTR = PyObjectGetAttr::create; - private static final PyObjectGetAttr UNCACHED_OBJECT_GET_ATTR = PyObjectGetAttr.getUncached(); - private static final NodeSupplier NODE_RAISE = PRaiseCachedNode::create; - private static final PRaiseCachedNode UNCACHED_RAISE = PRaiseCachedNode.getUncached(); - private static final NodeSupplier NODE_CALL = CallNode::create; - private static final CallNode UNCACHED_CALL = CallNode.getUncached(); - private static final NodeSupplier NODE_CALL_QUATERNARY_METHOD = CallQuaternaryMethodNode::create; - private static final CallQuaternaryMethodNode UNCACHED_CALL_QUATERNARY_METHOD = CallQuaternaryMethodNode.getUncached(); - private static final NodeSupplier NODE_CALL_TERNARY_METHOD = CallTernaryMethodNode::create; - private static final CallTernaryMethodNode UNCACHED_CALL_TERNARY_METHOD = CallTernaryMethodNode.getUncached(); - private static final NodeSupplier NODE_CALL_BINARY_METHOD = CallBinaryMethodNode::create; - private static final CallBinaryMethodNode UNCACHED_CALL_BINARY_METHOD = CallBinaryMethodNode.getUncached(); - private static final NodeSupplier NODE_CALL_UNARY_METHOD = CallUnaryMethodNode::create; - private static final CallUnaryMethodNode UNCACHED_CALL_UNARY_METHOD = CallUnaryMethodNode.getUncached(); - private static final NodeSupplier NODE_OBJECT_GET_METHOD = PyObjectGetMethodNodeGen::create; - private static final PyObjectGetMethod UNCACHED_OBJECT_GET_METHOD = PyObjectGetMethodNodeGen.getUncached(); - private static final ForIterONode UNCACHED_FOR_ITER_O = ForIterONode.getUncached(); - private static final NodeSupplier NODE_FOR_ITER_O = ForIterONode::create; - private static final ForIterINode UNCACHED_FOR_ITER_I = ForIterINode.getUncached(); - private static final NodeSupplier NODE_FOR_ITER_I = ForIterINode::create; - private static final NodeSupplier NODE_OBJECT_GET_ITER = PyObjectGetIter::create; - private static final PyObjectGetIter UNCACHED_OBJECT_GET_ITER = PyObjectGetIter.getUncached(); - private static final NodeSupplier NODE_OBJECT_GET_YIELD_FROM_ITER = GetYieldFromIterNode::create; - private static final GetYieldFromIterNode UNCACHED_OBJECT_GET_YIELD_FROM_ITER = GetYieldFromIterNode.getUncached(); - private static final MakeTypeParamNode UNCACHED_MAKE_TYPE_PARAM = MakeTypeParamNode.getUncached(); - private static final NodeSupplier NODE_MAKE_TYPE_PARAM = MakeTypeParamNode::create; - private static final MakeTypeAliasNode UNCACHED_MAKE_TYPE_ALIAS = MakeTypeAliasNode.getUncached(); - private static final NodeSupplier NODE_MAKE_TYPE_ALIAS = MakeTypeAliasNode::create; - private static final MakeGenericNode UNCACHED_MAKE_GENERIC = MakeGenericNode.getUncached(); - private static final NodeSupplier NODE_MAKE_GENERIC = MakeGenericNode::create; - - private static final NodeSupplier NODE_OBJECT_GET_AWAITABLE = GetAwaitableNode::create; - private static final GetAwaitableNode UNCACHED_OBJECT_GET_AWAITABLE = GetAwaitableNode.getUncached(); - private static final NodeSupplier NODE_OBJECT_SET_ATTR = PyObjectSetAttr::create; - private static final PyObjectSetAttr UNCACHED_OBJECT_SET_ATTR = PyObjectSetAttr.getUncached(); - private static final NodeSupplier NODE_READ_BUILTIN_BUILD_CLASS = () -> ReadBuiltinNode.create(); - private static final NodeSupplier NODE_READ_GLOBAL_OR_BUILTIN = ReadGlobalOrBuiltinNode::create; - private static final NodeSupplier NODE_READ_NAME = ReadNameNode::create; - private static final NodeSupplier NODE_WRITE_NAME = WriteNameNode::create; - private static final ReadBuiltinNode UNCACHED_READ_BUILTIN = ReadBuiltinNode.getUncached(); - private static final ReadGlobalOrBuiltinNode UNCACHED_READ_GLOBAL_OR_BUILTIN = ReadGlobalOrBuiltinNode.getUncached(); - private static final NodeSupplier NODE_OBJECT_SET_ITEM = PyObjectSetItem::create; - private static final PyObjectSetItem UNCACHED_OBJECT_SET_ITEM = PyObjectSetItem.getUncached(); - private static final NodeSupplier NODE_OBJECT_IS_TRUE = PyObjectIsTrueNode::create; - private static final PyObjectIsTrueNode UNCACHED_OBJECT_IS_TRUE = PyObjectIsTrueNode.getUncached(); - private static final NodeSupplier NODE_GET_ITEM = PyObjectGetItem::create; - private static final ExceptMatchNode UNCACHED_EXCEPT_MATCH = ExceptMatchNode.getUncached(); - private static final NodeSupplier NODE_EXCEPT_MATCH = ExceptMatchNode::create; - private static final SetupWithNode UNCACHED_SETUP_WITH_NODE = SetupWithNode.getUncached(); - private static final NodeSupplier NODE_SETUP_WITH = SetupWithNode::create; - private static final ExitWithNode UNCACHED_EXIT_WITH_NODE = ExitWithNode.getUncached(); - private static final NodeSupplier NODE_EXIT_WITH = ExitWithNode::create; - private static final SetupAwithNode UNCACHED_SETUP_AWITH_NODE = SetupAwithNode.getUncached(); - private static final NodeSupplier NODE_SETUP_AWITH = SetupAwithNode::create; - private static final GetAExitCoroNode UNCACHED_GET_AEXIT_CORO_NODE = GetAExitCoroNode.getUncached(); - private static final NodeSupplier NODE_GET_AEXIT_CORO = GetAExitCoroNode::create; - private static final ExitAWithNode UNCACHED_EXIT_AWITH_NODE = ExitAWithNode.getUncached(); - private static final GetAIterNode UNCACHED_GET_AITER = GetAIterNode.getUncached(); - private static final NodeSupplier NODE_GET_AITER = GetAIterNode::create; - private static final GetANextNode UNCACHED_GET_ANEXT = GetANextNode.getUncached(); - private static final NodeSupplier NODE_GET_ANEXT = GetANextNode::create; - private static final EndAsyncForNode UNCACHED_END_ASYNC_FOR = EndAsyncForNode.getUncached(); - private static final NodeSupplier NODE_END_ASYNC_FOR = EndAsyncForNode::create; - private static final NodeSupplier NODE_EXIT_AWITH = ExitAWithNode::create; - private static final ImportFromNode UNCACHED_IMPORT_FROM = ImportFromNode.getUncached(); - private static final NodeSupplier NODE_IMPORT_FROM = ImportFromNode::create; - private static final ExecutePositionalStarargsNode UNCACHED_EXECUTE_STARARGS = ExecutePositionalStarargsNode.getUncached(); - private static final NodeSupplier NODE_EXECUTE_STARARGS = ExecutePositionalStarargsNode::create; - private static final KeywordsNode UNCACHED_KEYWORDS = KeywordsNode.getUncached(); - private static final NodeSupplier NODE_KEYWORDS = KeywordsNode::create; - private static final CreateSliceNode UNCACHED_CREATE_SLICE = CreateSliceNode.getUncached(); - private static final NodeSupplier NODE_CREATE_SLICE = CreateSliceNode::create; - private static final ListNodes.ConstructListNode UNCACHED_CONSTRUCT_LIST = ListNodes.ConstructListNode.getUncached(); - private static final NodeSupplier NODE_CONSTRUCT_LIST = ListNodes.ConstructListNode::create; - private static final TupleNodes.ConstructTupleNode UNCACHED_CONSTRUCT_TUPLE = TupleNodes.ConstructTupleNode.getUncached(); - private static final NodeSupplier NODE_CONSTRUCT_TUPLE = TupleNodes.ConstructTupleNode::create; - private static final SetNodes.ConstructSetNode UNCACHED_CONSTRUCT_SET = SetNodes.ConstructSetNode.getUncached(); - private static final NodeSupplier NODE_CONSTRUCT_SET = SetNodes.ConstructSetNode::create; - private static final NodeSupplier NODE_HASHING_STORAGE_INIT = HashingStorage.InitNode::create; - private static final NodeSupplier NODE_LIST_EXTEND = ListBuiltins.ListExtendNode::create; - private static final SetBuiltins.UpdateSingleNode UNCACHED_SET_UPDATE = SetBuiltins.UpdateSingleNode.getUncached(); - private static final NodeSupplier NODE_DICT_UPDATE = DictNodes.UpdateNode::create; - private static final NodeSupplier NODE_SET_UPDATE = SetBuiltins.UpdateSingleNode::create; - private static final ListNodes.AppendNode UNCACHED_LIST_APPEND = ListNodes.AppendNode.getUncached(); - private static final NodeSupplier NODE_LIST_APPEND = ListNodes.AppendNode::create; - private static final SetNodes.AddNode UNCACHED_SET_ADD = SetNodes.AddNode.getUncached(); - private static final NodeSupplier NODE_SET_ADD = SetNodes.AddNode::create; - private static final PyObjectSizeNode UNCACHED_SIZE = PyObjectSizeNode.getUncached(); - private static final NodeSupplier NODE_SIZE = PyObjectSizeNode::create; - private static final NodeSupplier NODE_TP_FLAGS = GetTPFlagsNode::create; - private static final GetTPFlagsNode UNCACHED_TP_FLAGS = GetTPFlagsNode.getUncached(); - private static final DeleteGlobalNode UNCACHED_DELETE_GLOBAL = DeleteGlobalNodeGen.getUncached(); - private static final NodeSupplier NODE_MATCH_KEYS = MatchKeysNode::create; - private static final NodeSupplier NODE_COPY_DICT_WITHOUT_KEYS = CopyDictWithoutKeysNode::create; - private static final KwargsMergeNode UNCACHED_KWARGS_MERGE = KwargsMergeNode.getUncached(); - private static final NodeSupplier NODE_KWARGS_MERGE = KwargsMergeNode::create; - private static final UnpackSequenceNode UNCACHED_UNPACK_SEQUENCE = UnpackSequenceNode.getUncached(); - private static final NodeSupplier NODE_UNPACK_SEQUENCE = UnpackSequenceNode::create; - private static final UnpackExNode UNCACHED_UNPACK_EX = UnpackExNode.getUncached(); - private static final NodeSupplier NODE_UNPACK_EX = UnpackExNode::create; - private static final PyObjectStrAsObjectNode UNCACHED_STR = PyObjectStrAsObjectNode.getUncached(); - private static final NodeSupplier NODE_STR = PyObjectStrAsObjectNode::create; - private static final PyObjectReprAsObjectNode UNCACHED_REPR = PyObjectReprAsObjectNode.getUncached(); - private static final NodeSupplier NODE_REPR = PyObjectReprAsObjectNode::create; - private static final PyObjectAsciiAsObjectNode UNCACHED_ASCII = PyObjectAsciiAsObjectNode.getUncached(); - private static final NodeSupplier NODE_ASCII = PyObjectAsciiAsObjectNode::create; - private static final PyObjectFormat UNCACHED_FORMAT = PyObjectFormat.getUncached(); - private static final NodeSupplier NODE_FORMAT = PyObjectFormat::create; - private static final NodeSupplier NODE_SEND = SendNode::create; - private static final NodeSupplier NODE_THROW = ThrowNode::create; - private static final WriteGlobalNode UNCACHED_WRITE_GLOBAL = WriteGlobalNode.getUncached(); - private static final NodeSupplier NODE_WRITE_GLOBAL = WriteGlobalNode::create; - private static final NodeSupplier NODE_DELETE_GLOBAL = DeleteGlobalNode::create; - private static final PrintExprNode UNCACHED_PRINT_EXPR = PrintExprNode.getUncached(); - private static final NodeSupplier NODE_PRINT_EXPR = PrintExprNode::create; - private static final ReadFromLocalsNode UNCACHED_READ_FROM_LOCALS = ReadFromLocalsNode.getUncached(); - private static final NodeSupplier NODE_READ_FROM_LOCALS = ReadFromLocalsNode::create; - private static final ReadFromDictOrGlobalsNode UNCACHED_READ_FROM_DICT_OR_GLOBALS = ReadFromDictOrGlobalsNode.getUncached(); - private static final NodeSupplier NODE_READ_FROM_DICT_OR_GLOBALS = ReadFromDictOrGlobalsNode::create; - private static final SetupAnnotationsNode UNCACHED_SETUP_ANNOTATIONS = SetupAnnotationsNode.getUncached(); - private static final NodeSupplier NODE_SETUP_ANNOTATIONS = SetupAnnotationsNode::create; - private static final GetSendValueNode UNCACHED_GET_SEND_VALUE = GetSendValueNode.getUncached(); - private static final NodeSupplier NODE_GET_SEND_VALUE = GetSendValueNode::create; - private static final NodeSupplier NODE_BINARY_SUBSCR_SEQ_O = BinarySubscrSeq.ONode::create; - private static final NodeSupplier NODE_BINARY_SUBSCR_SEQ_I = BinarySubscrSeq.INode::create; - private static final NodeSupplier NODE_BINARY_SUBSCR_SEQ_D = BinarySubscrSeq.DNode::create; - private static final NodeSupplier NODE_STORE_SUBSCR_SEQ_O = StoreSubscrSeq.ONode::create; - private static final NodeSupplier NODE_STORE_SUBSCR_SEQ_I = StoreSubscrSeq.INode::create; - private static final NodeSupplier NODE_STORE_SUBSCR_SEQ_D = StoreSubscrSeq.DNode::create; - private static final NodeSupplier NODE_CALL_COMPREHENSION = CallComprehensionNode::create; - - private static final NodeSupplier NODE_INT_ADD = IntBuiltins.AddNode::create; - private static final NodeSupplier NODE_INT_SUB = IntBuiltins.SubNode::create; - private static final NodeSupplier NODE_INT_MUL = IntBuiltins.MulNode::create; - private static final NodeSupplier NODE_INT_FLOORDIV = IntBuiltins.FloorDivNode::create; - private static final NodeSupplier NODE_INT_TRUEDIV = IntBuiltins.TrueDivNode::create; - private static final NodeSupplier NODE_INT_MOD = IntBuiltins.ModNode::create; - private static final NodeSupplier NODE_INT_LSHIFT = IntBuiltins.LShiftNode::create; - private static final NodeSupplier NODE_INT_RSHIFT = IntBuiltins.RShiftNode::create; - private static final NodeSupplier NODE_INT_NEG = IntBuiltins.NegNode::create; - private static final NodeSupplier NODE_INT_POW = IntBuiltins.PowNode::create; - private static final NodeSupplier NODE_FLOAT_POW = FloatBuiltins.PowNode::create; - private static final NodeSupplier NODE_HASHING_STORAGE_FROM_SEQUENCE = HashingStorageFromListSequenceStorageNode::create; - private static final NodeSupplier NODE_MATCH_CLASS = MatchClassNode::create; - private static final IntNodeFunction LIST_FROM_STACK_NODE = ListFromStackNodeGen::create; - private static final IntNodeFunction TUPLE_FROM_STACK_NODE = TupleFromStackNodeGen::create; - - private static final IntNodeFunction UNARY_OP_FACTORY = (int op) -> { - switch (op) { - case UnaryOpsConstants.NOT: - return NotNode.create(); - case UnaryOpsConstants.POSITIVE: - return PyNumberPositiveNode.create(); - case UnaryOpsConstants.NEGATIVE: - return PyNumberNegativeNode.create(); - case UnaryOpsConstants.INVERT: - return PyNumberInvertNode.create(); - default: - throw CompilerDirectives.shouldNotReachHere(); - } - }; - - private static final IntNodeFunction BINARY_OP_FACTORY = (int op) -> { - switch (op) { - case BinaryOpsConstants.ADD: - return PyNumberAddNode.create(); - case BinaryOpsConstants.SUB: - return PyNumberSubtractNode.create(); - case BinaryOpsConstants.MUL: - return PyNumberMultiplyNode.create(); - case BinaryOpsConstants.TRUEDIV: - return PyNumberTrueDivideNode.create(); - case BinaryOpsConstants.FLOORDIV: - return PyNumberFloorDivideNode.create(); - case BinaryOpsConstants.MOD: - return PyNumberRemainderNode.create(); - case BinaryOpsConstants.LSHIFT: - return PyNumberLshiftNode.create(); - case BinaryOpsConstants.RSHIFT: - return PyNumberRshiftNode.create(); - case BinaryOpsConstants.AND: - return PyNumberAndNode.create(); - case BinaryOpsConstants.OR: - return PyNumberOrNode.create(); - case BinaryOpsConstants.XOR: - return PyNumberXorNode.create(); - case BinaryOpsConstants.POW: - return PyNumberPowerNode.create(); - case BinaryOpsConstants.MATMUL: - return PyNumberMatrixMultiplyNode.create(); - case BinaryOpsConstants.INPLACE_ADD: - return PyNumberInPlaceAddNode.create(); - case BinaryOpsConstants.INPLACE_SUB: - return PyNumberInPlaceSubtractNode.create(); - case BinaryOpsConstants.INPLACE_MUL: - return PyNumberInPlaceMultiplyNode.create(); - case BinaryOpsConstants.INPLACE_TRUEDIV: - return PyNumberInPlaceTrueDivideNode.create(); - case BinaryOpsConstants.INPLACE_FLOORDIV: - return PyNumberInPlaceFloorDivideNode.create(); - case BinaryOpsConstants.INPLACE_MOD: - return PyNumberInPlaceRemainderNode.create(); - case BinaryOpsConstants.INPLACE_LSHIFT: - return PyNumberInPlaceLshiftNode.create(); - case BinaryOpsConstants.INPLACE_RSHIFT: - return PyNumberInPlaceRshiftNode.create(); - case BinaryOpsConstants.INPLACE_AND: - return PyNumberInPlaceAndNode.create(); - case BinaryOpsConstants.INPLACE_OR: - return PyNumberInPlaceOrNode.create(); - case BinaryOpsConstants.INPLACE_XOR: - return PyNumberInPlaceXorNode.create(); - case BinaryOpsConstants.INPLACE_POW: - return PyNumberInPlacePowerNode.create(); - case BinaryOpsConstants.INPLACE_MATMUL: - return PyNumberInPlaceMatrixMultiplyNode.create(); - case BinaryOpsConstants.EQ: - return RichCompareBinaryOp.create(RichCmpOp.Py_EQ); - case BinaryOpsConstants.NE: - return RichCompareBinaryOp.create(RichCmpOp.Py_NE); - case BinaryOpsConstants.LT: - return RichCompareBinaryOp.create(RichCmpOp.Py_LT); - case BinaryOpsConstants.LE: - return RichCompareBinaryOp.create(RichCmpOp.Py_LE); - case BinaryOpsConstants.GT: - return RichCompareBinaryOp.create(RichCmpOp.Py_GT); - case BinaryOpsConstants.GE: - return RichCompareBinaryOp.create(RichCmpOp.Py_GE); - case BinaryOpsConstants.IS: - return IsNode.create(); - case BinaryOpsConstants.IN: - return InNode.create(); - default: - throw CompilerDirectives.shouldNotReachHere(); - } - }; - - private static final byte TRACE_FUN = 0b01; - private static final byte PROFILE_FUN = 0b10; - private static final byte TRACE_AND_PROFILE_FUN = TRACE_FUN | PROFILE_FUN; - - private final Signature signature; - private final boolean internal; - private boolean pythonInternal; - - final int celloffset; - final int freeoffset; - final int stackoffset; - final int bcioffset; - final int selfIndex; - final int classcellIndex; - - private final BytecodeCodeUnit co; - private final Source source; - private SourceSection sourceSection; - // For deferred deprecation warnings - private final ParserCallbacksImpl parserCallbacks; - - @CompilationFinal(dimensions = 1) final byte[] bytecode; - @CompilationFinal(dimensions = 1) private final Object[] consts; - @CompilationFinal(dimensions = 1) private final long[] longConsts; - @CompilationFinal(dimensions = 1) private final TruffleString[] names; - @CompilationFinal(dimensions = 1) private final TruffleString[] varnames; - @CompilationFinal(dimensions = 1) private final TruffleString[] freevars; - @CompilationFinal(dimensions = 1) private final TruffleString[] cellvars; - @CompilationFinal(dimensions = 1) private final int[] cell2arg; - @CompilationFinal(dimensions = 1) private final Assumption[] cellEffectivelyFinalAssumptions; - - @CompilationFinal(dimensions = 1) private final int[] exceptionHandlerRanges; - - /** - * Whether store instructions to this variable should attempt to unbox primitives. The number - * determines the type like above. - */ - private final byte[] variableShouldUnbox; - - @CompilationFinal private boolean unboxAllVariables; - - /* - * Whether this variable should be unboxed in the interpreter. We unbox all variables in - * compiled code, but in the interpreter we do an optimization that we only unbox variables that - * would actually get used without immediately being boxed again. This optimization doesn't - * apply to generators where all variables get unboxed both in the interpreter and compiled - * code. - */ - private static final byte UNBOXED_IN_INTERPRETER = (byte) (1 << 7); - /** - * Current primitive types of variables. The value is one of {@link QuickeningTypes} potentially - * ORed with {@link #UNBOXED_IN_INTERPRETER}. Used by argument copying and store instructions. - */ - @CompilationFinal(dimensions = 1) private byte[] variableTypes; - - /* - * When instrumentation is in use, InstrumentationSupport#bciToHelper node is used instead of - * this array. Use getChildNodes() to get the right array. - */ - @Children private Node[] adoptedNodes; - @Child private CalleeContext calleeContext = CalleeContext.create(); - @Child private ExceptionStateNodes.GetCaughtExceptionNode getCaughtExceptionNode; - @Child private ChainExceptionsNode chainExceptionsNode; - - private static final byte TRACE_PROFILE_LINE = 1; - private static final byte TRACE_PROFILE_NEW_FRAME = 1 << 1; - private static final byte TRACE_PROFILE_EXISTING_FRAME = 1 << 2; - private static final byte TRACE_PROFILE_SYNC_LOCALS_BACK = 1 << 3; - private static final byte TRACE_PROFILE_DID_JUMP = 1 << 4; - - private static final class TracingNodes extends Node { - @Child MaterializeFrameNode traceMaterializeFrameNewNode = MaterializeFrameNode.create(); - @Child MaterializeFrameNode traceMaterializeFrameExistingNode = MaterializeFrameNode.create(); - @Child CallNode tracingCallNode = CallNode.create(); - @Child CallNode profilingCallNode = CallNode.create(); - @CompilationFinal(dimensions = 1) byte[] traceProfileData; - - public TracingNodes(int bytecodeLength) { - traceProfileData = new byte[bytecodeLength]; - } - } - - @Child private TracingNodes tracingNodes; - - @CompilationFinal private Object osrMetadata; - - @CompilationFinal private boolean usingCachedNodes; - @CompilationFinal(dimensions = 1) private int[] conditionProfiles; - - @Child private InstrumentationRoot instrumentationRoot = InstrumentationRoot.create(); - - private static FrameDescriptor makeFrameDescriptor(BytecodeCodeUnit co, FrameInfo info) { - int capacity = co.varnames.length + co.cellvars.length + co.freevars.length + co.stacksize + 1; - FrameDescriptor.Builder newBuilder = FrameDescriptor.newBuilder(capacity); - newBuilder.info(info); - // locals - for (int i = 0; i < co.varnames.length; i++) { - TruffleString varname = co.varnames[i]; - if (co.arg2cell != null && i < co.arg2cell.length && co.arg2cell[i] >= 0) { - /* - * If an argument is a cell, its slot gets superseded by the cell's slot below. We - * need to hide it from introspection. - */ - varname = null; - } - newBuilder.addSlot(FrameSlotKind.Illegal, varname, null); - } - // cells - for (int i = 0; i < co.cellvars.length; i++) { - newBuilder.addSlot(FrameSlotKind.Illegal, co.cellvars[i], null); - } - // freevars - for (int i = 0; i < co.freevars.length; i++) { - newBuilder.addSlot(FrameSlotKind.Illegal, co.freevars[i], null); - } - // stack - newBuilder.addSlots(co.stacksize, FrameSlotKind.Illegal); - // BCI filled when unwinding the stack or when pausing generators - // TODO we should use a static slot when GR-40849 and GR-40742 are fixed - newBuilder.addSlot(FrameSlotKind.Int, null, null); - if (co.isGeneratorOrCoroutine()) { - // stackTop saved when pausing a generator - newBuilder.addSlot(FrameSlotKind.Int, null, null); - // return value of a generator - newBuilder.addSlot(FrameSlotKind.Illegal, null, null); - } - return newBuilder.build(); - } - - @TruffleBoundary - public static PBytecodeRootNode create(PythonLanguage language, BytecodeCodeUnit co, Source source, boolean internal) { - return create(language, co, source, internal, null); - } - - @TruffleBoundary - public static RootNode createMaybeGenerator(PythonLanguage language, BytecodeCodeUnit co, Source source, boolean internal) { - PBytecodeRootNode bytecodeRootNode = PBytecodeRootNode.create(language, co, source, internal); - if (co.isGeneratorOrCoroutine()) { - return new PBytecodeGeneratorFunctionRootNode(language, bytecodeRootNode.getFrameDescriptor(), bytecodeRootNode, co.name); - } else { - return bytecodeRootNode; - } - } - - @TruffleBoundary - public static PBytecodeRootNode create(PythonLanguage language, BytecodeCodeUnit co, Source source, boolean internal, ParserCallbacksImpl parserCallbacks) { - BytecodeFrameInfo frameInfo = new BytecodeFrameInfo(); - FrameDescriptor fd = makeFrameDescriptor(co, frameInfo); - PBytecodeRootNode rootNode = new PBytecodeRootNode(language, fd, co.computeSignature(), co, source, internal, parserCallbacks); - PythonContext context = PythonContext.get(rootNode); - if (context != null && context.getOption(PythonOptions.EagerlyMaterializeInstrumentationNodes)) { - rootNode.adoptChildren(); - rootNode.instrumentationRoot.materializeInstrumentableNodes(Collections.singleton(StandardTags.StatementTag.class)); - } - frameInfo.setRootNode(rootNode); - return rootNode; - } - - @TruffleBoundary - private PBytecodeRootNode(PythonLanguage language, FrameDescriptor fd, Signature sign, BytecodeCodeUnit co, Source source, boolean internal, - ParserCallbacksImpl parserCallbacks) { - super(language, fd); - this.celloffset = co.varnames.length; - this.freeoffset = celloffset + co.cellvars.length; - this.stackoffset = freeoffset + co.freevars.length; - this.bcioffset = stackoffset + co.stacksize; - this.source = source; - this.internal = internal; - this.parserCallbacks = parserCallbacks; - this.signature = sign; - this.bytecode = co.code; - this.variableShouldUnbox = co.variableShouldUnbox; - this.consts = co.constants; - this.longConsts = co.primitiveConstants; - this.names = co.names; - this.varnames = co.varnames; - this.freevars = co.freevars; - this.cellvars = co.cellvars; - this.cell2arg = co.cell2arg; - this.exceptionHandlerRanges = co.exceptionHandlerRanges; - this.co = co; - assert co.stacksize < Math.pow(2, 12) : "stacksize cannot be larger than 12-bit range"; - if (cellvars.length == 0) { - cellEffectivelyFinalAssumptions = EMPTY_ASSUMPTION_ARRAY; - } else { - cellEffectivelyFinalAssumptions = new Assumption[cellvars.length]; - for (int i = 0; i < cellvars.length; i++) { - cellEffectivelyFinalAssumptions[i] = Truffle.getRuntime().createAssumption("cell is effectively final"); - } - } - int classcellIndexValue = -1; - for (int i = 0; i < this.freevars.length; i++) { - if (T___CLASS__.equalsUncached(this.freevars[i], TS_ENCODING)) { - classcellIndexValue = this.freeoffset + i; - break; - } - } - this.classcellIndex = classcellIndexValue; - int selfIndexValue = -1; - if (!signature.takesNoArguments()) { - selfIndexValue = 0; - if (co.cell2arg != null) { - for (int i = 0; i < co.cell2arg.length; i++) { - if (co.cell2arg[i] == 0) { - selfIndexValue = celloffset + i; - break; - } - } - } - } - this.selfIndex = selfIndexValue; - if (language.getEngineOption(PythonOptions.ForceInitializeSourceSections)) { - getSourceSection(); - } - } - - @Override - protected int computeSize() { - return bytecode.length / 2; - } - - @Override - public String getName() { - return co.name.toJavaStringUncached(); - } - - @Override - public String getQualifiedName() { - return co.qualname.toJavaStringUncached(); - } - - @Override - public String toString() { - return ""; - } - - @Override - public Signature getSignature() { - return signature; - } - - @Override - public boolean isPythonInternal() { - return pythonInternal; - } - - public void setPythonInternal(boolean pythonInternal) { - this.pythonInternal = pythonInternal; - } - - public BytecodeCodeUnit getCodeUnit() { - return co; - } - - public Source getSourceWithCharacters() { - return getLanguage().getOrCreateSourceWithContent(source); - } - - public Source getSource() { - return source; - } - - public byte[] getBytecode() { - return bytecode; - } - - private Node[] getChildNodes() { - InstrumentationSupport instrumentation = instrumentationRoot.getInstrumentation(); - if (instrumentation != null) { - return instrumentation.bciToHelperNode; - } - if (adoptedNodes == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - Lock lock = getLock(); - lock.lock(); - try { - if (adoptedNodes == null) { - adoptedNodes = new Node[bytecode.length]; - } - } finally { - lock.unlock(); - } - } - return adoptedNodes; - } - - @FunctionalInterface - private interface NodeSupplier { - - T get(); - } - - @FunctionalInterface - private interface IntNodeFunction { - T apply(int argument); - } - - @SuppressWarnings("unchecked") - private T insertChildNodeInt(Node[] nodes, int nodeIndex, Class expectedClass, IntNodeFunction nodeSupplier, int argument) { - Node node = nodes[nodeIndex]; - if (expectedClass.isInstance(node)) { - return (T) node; - } - return doInsertChildNodeInt(nodes, nodeIndex, expectedClass, nodeSupplier, argument); - } - - @SuppressWarnings("unchecked") - private T doInsertChildNodeInt(Node[] nodes, int nodeIndex, Class expectedClass, IntNodeFunction nodeSupplier, int argument) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - Lock lock = getLock(); - lock.lock(); - try { - Node node = nodes[nodeIndex]; - if (expectedClass.isInstance(node)) { - return (T) node; - } - T newNode = nodeSupplier.apply(argument); - doInsertChildNode(nodes, nodeIndex, newNode); - return newNode; - } finally { - lock.unlock(); - } - } - - @SuppressWarnings("unchecked") - private U insertChildNode(Node[] nodes, int nodeIndex, Class cachedClass, NodeSupplier nodeSupplier) { - Node node = nodes[nodeIndex]; - if (node != null && node.getClass() == cachedClass) { - return CompilerDirectives.castExact(node, cachedClass); - } - return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, cachedClass, nodeSupplier), cachedClass); - } - - @SuppressWarnings("unchecked") - private T doInsertChildNode(Node[] nodes, int nodeIndex, Class cachedClass, NodeSupplier nodeSupplier) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - Lock lock = getLock(); - lock.lock(); - try { - Node node = nodes[nodeIndex]; - if (node != null && node.getClass() == cachedClass) { - return (T) node; - } - T newNode = nodeSupplier.get(); - doInsertChildNode(nodes, nodeIndex, newNode); - return newNode; - } finally { - lock.unlock(); - } - } - - @SuppressWarnings("unchecked") - private T insertChildNode(Node[] nodes, int nodeIndex, T uncached, Class cachedClass, NodeSupplier nodeSupplier, boolean useCachedNodes) { - if (!useCachedNodes) { - return uncached; - } - Node node = nodes[nodeIndex]; - if (node != null && node.getClass() == cachedClass) { - return CompilerDirectives.castExact(node, cachedClass); - } - return CompilerDirectives.castExact(doInsertChildNode(nodes, nodeIndex, cachedClass, nodeSupplier), cachedClass); - } - - private void doInsertChildNode(Node[] nodes, int nodeIndex, Node newNode) { - if (nodes == adoptedNodes) { - nodes[nodeIndex] = insert(newNode); - } else { - assert nodes == instrumentationRoot.getInstrumentation().bciToHelperNode; - instrumentationRoot.getInstrumentation().insertHelperNode(newNode, nodeIndex); - } - } - - public PythonLanguage getLanguage() { - return getLanguage(PythonLanguage.class); - } - - private static final int CONDITION_PROFILE_MAX_VALUE = 0x3fffffff; - - // Inlined from ConditionProfile.Counting#profile - private boolean profileCondition(boolean value, byte[] localBC, int bci, boolean useCachedNodes) { - if (!useCachedNodes) { - return value; - } - if (conditionProfiles == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - conditionProfiles = new int[co.conditionProfileCount]; - } - int index = Byte.toUnsignedInt(localBC[bci + 2]) | Byte.toUnsignedInt(localBC[bci + 3]) << 8; - int t = conditionProfiles[index]; - int f = conditionProfiles[index + 1]; - boolean val = value; - if (val) { - if (t == 0) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - } - if (f == 0) { - // Make this branch fold during PE - val = true; - } - if (CompilerDirectives.inInterpreter()) { - if (t < CONDITION_PROFILE_MAX_VALUE) { - conditionProfiles[index] = t + 1; - } - } - } else { - if (f == 0) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - } - if (t == 0) { - // Make this branch fold during PE - val = false; - } - if (CompilerDirectives.inInterpreter()) { - if (f < CONDITION_PROFILE_MAX_VALUE) { - conditionProfiles[index + 1] = f + 1; - } - } - } - if (CompilerDirectives.inInterpreter()) { - // no branch probability calculation in the interpreter - return val; - } else { - int sum = t + f; - return CompilerDirectives.injectBranchProbability((double) t / (double) sum, val); - } - } - - @Override - public Object getOSRMetadata() { - return osrMetadata; - } - - @Override - public void setOSRMetadata(Object osrMetadata) { - this.osrMetadata = osrMetadata; - } - - @ExplodeLoop - private void copyArgs(Object[] args, Frame localFrame) { - if (variableTypes == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - copyArgsFirstTime(args, localFrame); - return; - } - int argCount = co.getRegularArgCount(); - for (int i = 0; i < argCount; i++) { - Object arg = args[i + PArguments.USER_ARGUMENTS_OFFSET]; - byte type = variableTypes[i]; - if ((type & QuickeningTypes.OBJECT) != 0) { - localFrame.setObject(i, arg); - continue; - } else if ((type & QuickeningTypes.INT) != 0) { - if (arg instanceof Integer) { - if (unboxAllVariables || (type & UNBOXED_IN_INTERPRETER) != 0) { - localFrame.setInt(i, (int) arg); - } else { - localFrame.setObject(i, arg); - } - continue; - } - } else if ((type & QuickeningTypes.LONG) != 0) { - if (arg instanceof Long) { - if (unboxAllVariables || (type & UNBOXED_IN_INTERPRETER) != 0) { - localFrame.setLong(i, (long) arg); - } else { - localFrame.setObject(i, arg); - } - continue; - } - } else if ((type & QuickeningTypes.DOUBLE) != 0) { - if (arg instanceof Double) { - if (unboxAllVariables || (type & UNBOXED_IN_INTERPRETER) != 0) { - localFrame.setDouble(i, (double) arg); - } else { - localFrame.setObject(i, arg); - } - continue; - } - } else if ((type & QuickeningTypes.BOOLEAN) != 0) { - if (arg instanceof Boolean) { - if (unboxAllVariables || (type & UNBOXED_IN_INTERPRETER) != 0) { - localFrame.setBoolean(i, (boolean) arg); - } else { - localFrame.setObject(i, arg); - } - continue; - } - } - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeVariableStores(i); - variableTypes[i] = QuickeningTypes.OBJECT; - localFrame.setObject(i, arg); - } - } - - private void copyArgsFirstTime(Object[] args, Frame localFrame) { - CompilerAsserts.neverPartOfCompilation(); - variableTypes = new byte[varnames.length]; - int argCount = co.getRegularArgCount(); - for (int i = 0; i < argCount; i++) { - Object arg = args[i + PArguments.USER_ARGUMENTS_OFFSET]; - if (arg instanceof Integer) { - variableTypes[i] = QuickeningTypes.INT; - if ((variableShouldUnbox[i] & QuickeningTypes.INT) != 0) { - variableTypes[i] |= UNBOXED_IN_INTERPRETER; - localFrame.setInt(i, (int) arg); - continue; - } - } else if (arg instanceof Long) { - variableTypes[i] = QuickeningTypes.LONG; - if ((variableShouldUnbox[i] & QuickeningTypes.LONG) != 0) { - variableTypes[i] |= UNBOXED_IN_INTERPRETER; - localFrame.setLong(i, (long) arg); - continue; - } - } else if (arg instanceof Double) { - variableTypes[i] = QuickeningTypes.DOUBLE; - if ((variableShouldUnbox[i] & QuickeningTypes.DOUBLE) != 0) { - variableTypes[i] |= UNBOXED_IN_INTERPRETER; - localFrame.setDouble(i, (double) arg); - continue; - } - } else if (arg instanceof Boolean) { - variableTypes[i] = QuickeningTypes.BOOLEAN; - if ((variableShouldUnbox[i] & QuickeningTypes.BOOLEAN) != 0) { - variableTypes[i] |= UNBOXED_IN_INTERPRETER; - localFrame.setBoolean(i, (boolean) arg); - continue; - } - } else { - variableTypes[i] = QuickeningTypes.OBJECT; - } - localFrame.setObject(i, arg); - } - } - - public MaterializedFrame createGeneratorFrame(Object[] arguments) { - MaterializedFrame generatorFrame = Truffle.getRuntime().createMaterializedFrame(PArguments.create(), getFrameDescriptor()); - PArguments.setCurrentFrameInfo(generatorFrame, new PFrame.Reference(this, PFrame.Reference.EMPTY)); - copyArgsAndCells(generatorFrame, arguments); - return generatorFrame; - } - - private void copyArgsAndCells(Frame localFrame, Object[] arguments) { - copyArgs(arguments, localFrame); - int varIdx = co.getRegularArgCount(); - if (co.takesVarArgs()) { - int varargsIndex = varIdx++; - localFrame.setObject(varargsIndex, PFactory.createTuple(getLanguage(), (Object[]) PArguments.getArgument(arguments, varargsIndex))); - } - if (co.takesVarKeywordArgs()) { - localFrame.setObject(varIdx, PFactory.createDict(getLanguage(), (PKeyword[]) PArguments.getArgument(arguments, varIdx))); - } - initCellVars(localFrame); - initFreeVars(localFrame, arguments); - } - - int getInitialStackTop() { - return stackoffset - 1; - } - - @Override - public Object execute(VirtualFrame virtualFrame) { - calleeContext.enter(virtualFrame, this); - try { - copyArgsAndCells(virtualFrame, virtualFrame.getArguments()); - return executeFromBci(virtualFrame, virtualFrame, this, 0, getInitialStackTop()); - } finally { - calleeContext.exit(virtualFrame, this); - } - } - - // Doesn't matter which PArguments slot we use as long as it exists - private static final int OSR_FRAME_INDEX = 0; - - @Override - public Object[] storeParentFrameInArguments(VirtualFrame parentFrame) { - Object[] arguments = parentFrame.getArguments(); - arguments[0] = Pair.create(arguments[OSR_FRAME_INDEX], parentFrame); - return arguments; - } - - @Override - @SuppressWarnings("unchecked") - public Frame restoreParentFrameFromArguments(Object[] arguments) { - Pair pair = (Pair) arguments[OSR_FRAME_INDEX]; - arguments[0] = pair.getLeft(); - return pair.getRight(); - } - - @Override - public Object executeOSR(VirtualFrame osrFrame, int target, Object interpreterStateObject) { - OSRInterpreterState interpreterState = (OSRInterpreterState) interpreterStateObject; - return executeFromBci(osrFrame, osrFrame, this, target, interpreterState.stackTop); - } - - private static final class InterpreterContinuation { - public final int bci; - public final int stackTop; - - private InterpreterContinuation(int bci, int stackTop) { - this.bci = bci; - this.stackTop = stackTop; - } - } - - @ValueType - private static final class MutableLoopData { - public int getPastBci() { - return getTraceData().pastBci; - } - - public int setPastBci(int pastBci) { - return this.getTraceData().pastBci = pastBci; - } - - public int getPastLine() { - return getTraceData().pastLine; - } - - public int setPastLine(int pastLine) { - return this.getTraceData().pastLine = pastLine; - } - - public int getReturnLine() { - return getTraceData().returnLine; - } - - public int setReturnLine(int returnLine) { - return this.getTraceData().returnLine = returnLine; - } - - public boolean isReturnCalled() { - return this.getTraceData().returnCalled; - } - - public int getJumpBci() { - return this.getTraceData().jumpBci; - } - - public void setJumpBci(int target) { - this.getTraceData().jumpBci = target; - } - - public void setReturnCalled(boolean value) { - this.getTraceData().returnCalled = value; - } - - public boolean isExceptionNotified() { - return this.getTraceData().exceptionNotified; - } - - public void setExceptionNotified(boolean value) { - this.getTraceData().exceptionNotified = value; - } - - public PFrame getPyFrame() { - return getTraceData().pyFrame; - } - - public PFrame setPyFrame(PFrame pyFrame) { - return this.getTraceData().pyFrame = pyFrame; - } - - private InstrumentationData getTraceData() { - if (instrumentationData == null) { - instrumentationData = new InstrumentationData(); - } - return instrumentationData; - } - - public PythonContext.PythonThreadState getThreadState(PBytecodeRootNode node) { - if (this.getTraceData().threadState == null) { - PythonContext context = PythonContext.get(node); - return this.getTraceData().threadState = context.getThreadState(node.getLanguage()); - } - return this.getTraceData().threadState; - } - - /* - * Data for tracing, profiling and instrumentation - */ - private static final class InstrumentationData { - InstrumentationData() { - pastBci = 0; - pastLine = returnLine = -1; - } - - private int pastBci; - private int pastLine; - private int returnLine; - private PFrame pyFrame = null; - private boolean exceptionNotified; - private boolean returnCalled; - - private int jumpBci; - - private PythonContext.PythonThreadState threadState = null; - } - - private InstrumentationData instrumentationData = null; - - int loopCount; - /* - * This separate tracking of local exception is necessary to make exception state saving - * work in generators. On one hand we need to retain the exception that was caught in the - * generator, on the other hand we don't want to retain the exception state that was passed - * from the outer frame because that changes with every resume. - */ - boolean fetchedException; - AbstractTruffleException outerException; - AbstractTruffleException localException; - } - - Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) { - /* - * A lot of python code is executed just a single time, such as top level module code. We - * want to save some time and memory by trying to first use uncached nodes. We use two - * separate entry points so that they get each get compiled with monomorphic calls to either - * cached or uncached nodes. - */ - if (usingCachedNodes) { - return executeCached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false); - } else { - CompilerDirectives.transferToInterpreterAndInvalidate(); - usingCachedNodes = true; - Object result = executeUncached(virtualFrame, localFrame, osrNode, initialBci, initialStackTop); - if (result instanceof InterpreterContinuation) { - InterpreterContinuation continuation = (InterpreterContinuation) result; - return executeCached(virtualFrame, localFrame, osrNode, continuation.bci, continuation.stackTop, true); - } - return result; - } - } - - @BytecodeInterpreterSwitch - private Object executeCached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean fromOSR) { - return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, true, fromOSR); - } - - @BytecodeInterpreterSwitch - private Object executeUncached(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop) { - return bytecodeLoop(virtualFrame, localFrame, osrNode, initialBci, initialStackTop, false, false); - } - - @ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.MERGE_EXPLODE) - @SuppressWarnings("fallthrough") - @BytecodeInterpreterSwitch - private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, BytecodeOSRNode osrNode, int initialBci, int initialStackTop, boolean useCachedNodes, boolean fromOSR) { - boolean hasUnboxedLocals = unboxAllVariables; - Object[] arguments = virtualFrame.getArguments(); - Object globals = PArguments.getGlobals(arguments); - Object locals = PArguments.getSpecialArgument(arguments); - - boolean isGeneratorOrCoroutine = co.isGeneratorOrCoroutine(); - if (fromOSR && hasUnboxedLocals && !isGeneratorOrCoroutine) { - unboxVariables(localFrame); - } - - final PythonLanguage language = getLanguage(PythonLanguage.class); - final Assumption noTraceOrProfile = language.noTracingOrProfilingAssumption; - final InstrumentationSupport instrumentation = instrumentationRoot.getInstrumentation(); - if (instrumentation != null && !fromOSR) { - Object result = notifyEnter(virtualFrame, instrumentation, initialBci); - if (result != null) { - return result; - } - } - - /* - * We use an object as a workaround for not being able to specify which local variables are - * loop constants (GR-35338). - */ - MutableLoopData mutableData = new MutableLoopData(); - int stackTop = initialStackTop; - int bci = initialBci; - - byte[] localBC = bytecode; - Object[] localConsts = consts; - long[] localLongConsts = longConsts; - TruffleString[] localNames = names; - Node[] localNodes = getChildNodes(); - final int bciSlot = bcioffset; - final int localCelloffset = celloffset; - - setCurrentBci(virtualFrame, bciSlot, initialBci); - - CompilerAsserts.partialEvaluationConstant(localBC); - CompilerAsserts.partialEvaluationConstant(bci); - CompilerAsserts.partialEvaluationConstant(stackTop); - - byte tracingOrProfilingEnabled = 0; - - // if we are simply continuing to run an OSR loop after the replacement, tracing an - // extra CALL event would be incorrect - if (!fromOSR) { - tracingOrProfilingEnabled = checkTracingAndProfilingEnabled(noTraceOrProfile, mutableData); - traceOrProfileCall(virtualFrame, initialBci, mutableData, tracingOrProfilingEnabled, bci); - } - - int oparg = 0; - while (true) { - final byte bc = localBC[bci]; - final int beginBci = bci; - tracingOrProfilingEnabled = checkTracingAndProfilingEnabled(noTraceOrProfile, mutableData); - if (isTracingEnabled(tracingOrProfilingEnabled)) { - final int stackDiff = traceLine(virtualFrame, mutableData, localBC, bci); - if (stackDiff <= 0) { - // See traceLine, if we get here, we should be in the interpreter already, but - // SVM can't prove it, so transfer again - CompilerDirectives.transferToInterpreterAndInvalidate(); - bci = mutableData.getJumpBci(); - stackTop += stackDiff; - continue; - } - } - - CompilerAsserts.partialEvaluationConstant(bc); - CompilerAsserts.partialEvaluationConstant(bci); - CompilerAsserts.partialEvaluationConstant(stackTop); - - try { - switch (bc) { - case OpCodesConstants.LOAD_NONE: - virtualFrame.setObject(++stackTop, PNone.NONE); - break; - case OpCodesConstants.LOAD_ELLIPSIS: - virtualFrame.setObject(++stackTop, PEllipsis.INSTANCE); - break; - case OpCodesConstants.LOAD_TRUE_B: - virtualFrame.setBoolean(++stackTop, true); - break; - case OpCodesConstants.LOAD_TRUE_O: - virtualFrame.setObject(++stackTop, true); - break; - case OpCodesConstants.LOAD_FALSE_B: - virtualFrame.setBoolean(++stackTop, false); - break; - case OpCodesConstants.LOAD_FALSE_O: - virtualFrame.setObject(++stackTop, false); - break; - case OpCodesConstants.LOAD_BYTE_I: - virtualFrame.setInt(++stackTop, localBC[++bci]); // signed! - break; - case OpCodesConstants.LOAD_BYTE_O: - virtualFrame.setObject(++stackTop, (int) localBC[++bci]); // signed! - break; - case OpCodesConstants.LOAD_INT_I: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setInt(++stackTop, (int) localLongConsts[oparg]); - break; - } - case OpCodesConstants.LOAD_INT_O: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, (int) localLongConsts[oparg]); - break; - } - case OpCodesConstants.LOAD_LONG_L: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setLong(++stackTop, localLongConsts[oparg]); - break; - } - case OpCodesConstants.LOAD_LONG_O: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, localLongConsts[oparg]); - break; - } - case OpCodesConstants.LOAD_DOUBLE_D: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setDouble(++stackTop, Double.longBitsToDouble(localLongConsts[oparg])); - break; - } - case OpCodesConstants.LOAD_DOUBLE_O: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, Double.longBitsToDouble(localLongConsts[oparg])); - break; - } - case OpCodesConstants.LOAD_BIGINT: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, PFactory.createInt(language, (BigInteger) localConsts[oparg])); - break; - } - case OpCodesConstants.LOAD_STRING: - case OpCodesConstants.LOAD_CONST: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, localConsts[oparg]); - break; - } - case OpCodesConstants.LOAD_BYTES: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - virtualFrame.setObject(++stackTop, PFactory.createBytes(language, (byte[]) localConsts[oparg])); - break; - } - case OpCodesConstants.LOAD_CONST_COLLECTION: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - int typeAndKind = Byte.toUnsignedInt(localBC[++bci]); - Object array = localConsts[oparg]; - bytecodeLoadConstCollection(virtualFrame, ++stackTop, array, typeAndKind); - break; - } - case OpCodesConstants.LOAD_COMPLEX: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - double[] num = (double[]) localConsts[oparg]; - virtualFrame.setObject(++stackTop, PFactory.createComplex(language, num[0], num[1])); - break; - } - case OpCodesConstants.MAKE_KEYWORD: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - TruffleString key = (TruffleString) localConsts[oparg]; - Object value = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop, new PKeyword(key, value)); - break; - } - case OpCodesConstants.BUILD_SLICE: { - int count = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeBuildSlice(virtualFrame, stackTop, beginBci, count, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.FORMAT_VALUE: { - setCurrentBci(virtualFrame, bciSlot, bci); - int options = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeFormatValue(virtualFrame, stackTop, beginBci, localNodes, options, useCachedNodes); - break; - } - case OpCodesConstants.COLLECTION_FROM_COLLECTION: { - setCurrentBci(virtualFrame, bciSlot, bci); - int type = Byte.toUnsignedInt(localBC[++bci]); - bytecodeCollectionFromCollection(virtualFrame, type, stackTop, localNodes, beginBci, useCachedNodes); - break; - } - case OpCodesConstants.COLLECTION_ADD_COLLECTION: { - setCurrentBci(virtualFrame, bciSlot, bci); - /* - * The first collection must be in the target format already, the second one - * is a python object. - */ - int type = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeCollectionAddCollection(virtualFrame, type, stackTop, localNodes, beginBci, useCachedNodes); - break; - } - case OpCodesConstants.COLLECTION_FROM_STACK: { - setCurrentBci(virtualFrame, bciSlot, bci); - int countAndType = Byte.toUnsignedInt(localBC[++bci]); - int count = CollectionBits.elementCount(countAndType); - int type = CollectionBits.collectionKind(countAndType); - stackTop = bytecodeCollectionFromStack(virtualFrame, type, count, stackTop, localNodes, beginBci, useCachedNodes); - break; - } - case OpCodesConstants.COLLECTION_ADD_STACK: { - setCurrentBci(virtualFrame, bciSlot, bci); - int countAndType = Byte.toUnsignedInt(localBC[++bci]); - int count = CollectionBits.elementCount(countAndType); - int type = CollectionBits.collectionKind(countAndType); - // Just combine COLLECTION_FROM_STACK and COLLECTION_ADD_COLLECTION for now - stackTop = bytecodeCollectionFromStack(virtualFrame, type, count, stackTop, localNodes, beginBci, useCachedNodes); - stackTop = bytecodeCollectionAddCollection(virtualFrame, type, stackTop, localNodes, beginBci + 1, useCachedNodes); - break; - } - case OpCodesConstants.ADD_TO_COLLECTION: { - setCurrentBci(virtualFrame, bciSlot, bci); - int depthAndType = Byte.toUnsignedInt(localBC[++bci]); - int depth = CollectionBits.elementCount(depthAndType); - int type = CollectionBits.collectionKind(depthAndType); - stackTop = bytecodeAddToCollection(virtualFrame, stackTop, beginBci, localNodes, depth, type, useCachedNodes); - break; - } - case OpCodesConstants.TUPLE_FROM_LIST: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeTupleFromList(virtualFrame, stackTop); - break; - } - case OpCodesConstants.FROZENSET_FROM_LIST: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeFrozensetFromList(virtualFrame, stackTop, beginBci, localNodes); - break; - } - case OpCodesConstants.KWARGS_DICT_MERGE: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeKwargsMerge(virtualFrame, useCachedNodes, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.UNPACK_SEQUENCE: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeUnpackSequence(virtualFrame, stackTop, beginBci, localNodes, oparg, useCachedNodes); - break; - } - case OpCodesConstants.UNPACK_EX: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - int countAfter = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeUnpackEx(virtualFrame, stackTop, beginBci, localNodes, oparg, countAfter, useCachedNodes); - break; - } - case OpCodesConstants.NOP: - break; - case OpCodesConstants.LOAD_FAST: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastAdaptiveInputOutput(virtualFrame, localFrame, ++stackTop, localBC, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_ADAPTIVE_O: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastAdaptiveInputOnly(virtualFrame, localFrame, ++stackTop, localBC, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_O: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastO(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_BOXED_I: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastBoxedI(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_BOXED_B: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastBoxedB(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_BOXED_D: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastBoxedD(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_BOXED_L: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastBoxedL(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes, hasUnboxedLocals); - break; - } - case OpCodesConstants.LOAD_FAST_I: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastI(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_I_BOX: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastIBox(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_L: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastL(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_L_BOX: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastLBox(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_D: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastD(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_D_BOX: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastDBox(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_B: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastB(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_FAST_B_BOX: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeLoadFastBBox(virtualFrame, localFrame, ++stackTop, bci++, oparg, localNodes); - break; - } - case OpCodesConstants.LOAD_CLOSURE: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - PCell cell = (PCell) localFrame.getObject(localCelloffset + oparg); - virtualFrame.setObject(++stackTop, cell); - break; - } - case OpCodesConstants.CLOSURE_FROM_STACK: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeClosureFromStack(virtualFrame, stackTop, oparg); - break; - } - case OpCodesConstants.LOAD_DEREF: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadDeref(virtualFrame, localFrame, stackTop, beginBci, localNodes, oparg, localCelloffset, useCachedNodes); - break; - } - case OpCodesConstants.STORE_DEREF: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeStoreDeref(virtualFrame, localFrame, stackTop, oparg, localCelloffset); - break; - } - case OpCodesConstants.STORE_FAST: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastAdaptive(virtualFrame, localFrame, stackTop--, bci++, localBC, oparg, hasUnboxedLocals); - break; - } - case OpCodesConstants.STORE_FAST_O: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastO(virtualFrame, localFrame, stackTop--, oparg); - bci++; - break; - } - case OpCodesConstants.STORE_FAST_UNBOX_I: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastUnboxI(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_BOXED_I: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastBoxedI(virtualFrame, localFrame, stackTop--, bci++, oparg, hasUnboxedLocals); - break; - } - case OpCodesConstants.STORE_FAST_I: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastI(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_UNBOX_L: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastUnboxL(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_BOXED_L: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastBoxedL(virtualFrame, localFrame, stackTop--, bci++, oparg, hasUnboxedLocals); - break; - } - case OpCodesConstants.STORE_FAST_L: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastL(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_UNBOX_D: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastUnboxD(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_BOXED_D: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastBoxedD(virtualFrame, localFrame, stackTop--, bci++, oparg, hasUnboxedLocals); - break; - } - case OpCodesConstants.STORE_FAST_D: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastD(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_UNBOX_B: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastUnboxB(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.STORE_FAST_BOXED_B: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastBoxedB(virtualFrame, localFrame, stackTop--, bci++, oparg, hasUnboxedLocals); - break; - } - case OpCodesConstants.STORE_FAST_B: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeStoreFastB(virtualFrame, localFrame, stackTop--, bci++, oparg); - break; - } - case OpCodesConstants.POP_TOP: - virtualFrame.clear(stackTop--); - break; - case OpCodesConstants.ROT_TWO: { - Object top = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop, virtualFrame.getObject(stackTop - 1)); - virtualFrame.setObject(stackTop - 1, top); - break; - } - case OpCodesConstants.ROT_THREE: { - Object top = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop, virtualFrame.getObject(stackTop - 1)); - virtualFrame.setObject(stackTop - 1, virtualFrame.getObject(stackTop - 2)); - virtualFrame.setObject(stackTop - 2, top); - break; - } - case OpCodesConstants.ROT_N: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytcodeRotN(virtualFrame, stackTop, oparg); - break; - } - case OpCodesConstants.MATCH_SEQUENCE: { - stackTop = bytecodeCheckTpFlags(virtualFrame, SEQUENCE, useCachedNodes, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.MATCH_MAPPING: { - stackTop = bytecodeCheckTpFlags(virtualFrame, MAPPING, useCachedNodes, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.MATCH_KEYS: { - stackTop = bytecodeMatchKeys(virtualFrame, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.COPY_DICT_WITHOUT_KEYS: { - bytecodeCopyDictWithoutKeys(virtualFrame, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.MATCH_CLASS: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeMatchClass(virtualFrame, stackTop, oparg, bci, localNodes); - break; - } - case OpCodesConstants.GET_LEN: { - stackTop = bytecodeGetLen(virtualFrame, useCachedNodes, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.DUP_TOP: - virtualFrame.setObject(stackTop + 1, virtualFrame.getObject(stackTop)); - stackTop++; - break; - case OpCodesConstants.UNARY_OP: { - bytecodeUnaryOpAdaptiveInputOutput(virtualFrame, stackTop, bci++, localBC, localNodes); - break; - } - case OpCodesConstants.UNARY_OP_ADAPTIVE_O: { - bytecodeUnaryOpAdaptiveInputOnly(virtualFrame, stackTop, bci++, localBC, localNodes); - break; - } - case OpCodesConstants.UNARY_OP_O_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpOO(virtualFrame, stackTop, bci++, localNodes, op, bciSlot); - break; - } - case OpCodesConstants.UNARY_OP_I_I: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpII(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.UNARY_OP_I_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpIO(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.UNARY_OP_D_D: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpDD(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.UNARY_OP_D_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpDO(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.UNARY_OP_B_B: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpBB(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.UNARY_OP_B_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeUnaryOpBO(virtualFrame, stackTop, bci++, localNodes, op); - break; - } - case OpCodesConstants.BINARY_OP: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpAdaptiveInputOutput(virtualFrame, stackTop--, localBC, bci++, localNodes, op, useCachedNodes); - break; - } - case OpCodesConstants.BINARY_OP_ADAPTIVE_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpAdaptiveInputOnly(virtualFrame, stackTop--, localBC, bci++, localNodes, op, useCachedNodes); - break; - } - case OpCodesConstants.BINARY_OP_OO_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpOOO(virtualFrame, stackTop--, bci++, localNodes, op, bciSlot); - break; - } - case OpCodesConstants.BINARY_OP_II_I: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpIII(virtualFrame, stackTop--, bci++, localNodes, op, useCachedNodes); - break; - } - case OpCodesConstants.BINARY_OP_II_B: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpIIB(virtualFrame, stackTop--, bci++, localNodes, op); - break; - } - case OpCodesConstants.BINARY_OP_II_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpIIO(virtualFrame, stackTop--, bci++, localNodes, op); - break; - } - case OpCodesConstants.BINARY_OP_DD_D: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpDDD(virtualFrame, stackTop--, bci++, localNodes, op, useCachedNodes); - break; - } - case OpCodesConstants.BINARY_OP_DD_B: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpDDB(virtualFrame, stackTop--, bci++, localNodes, op); - break; - } - case OpCodesConstants.BINARY_OP_DD_O: { - int op = Byte.toUnsignedInt(localBC[bci + 1]); - bytecodeBinaryOpDDO(virtualFrame, stackTop--, bci++, localNodes, op, useCachedNodes); - break; - } - case OpCodesConstants.BINARY_SUBSCR: { - stackTop = bytecodeBinarySubscrAdaptiveInputOutput(virtualFrame, stackTop, bci, localNodes, bciSlot); - break; - } - case OpCodesConstants.BINARY_SUBSCR_ADAPTIVE_O: { - stackTop = bytecodeBinarySubscrAdaptiveInputOnly(virtualFrame, stackTop, bci, localNodes, bciSlot); - break; - } - case OpCodesConstants.BINARY_SUBSCR_SEQ_I_I: { - stackTop = bytecodeBinarySubscrSeqII(virtualFrame, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.BINARY_SUBSCR_SEQ_I_D: { - stackTop = bytecodeBinarySubscrSeqID(virtualFrame, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.BINARY_SUBSCR_SEQ_I_O: { - stackTop = bytecodeBinarySubscrSeqIO(virtualFrame, stackTop, bci, localNodes); - break; - } - case OpCodesConstants.BINARY_SUBSCR_O_O: { - stackTop = bytecodeBinarySubscrOO(virtualFrame, stackTop, bci, localNodes, bciSlot); - break; - } - case OpCodesConstants.STORE_SUBSCR: { - stackTop = bytecodeStoreSubscrAdaptive(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes, bciSlot); - break; - } - case OpCodesConstants.STORE_SUBSCR_OOO: { - stackTop = bytecodeStoreSubscrOOO(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes, bciSlot); - break; - } - case OpCodesConstants.STORE_SUBSCR_SEQ_IOO: { - stackTop = bytecodeStoreSubscrSeqIOO(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.STORE_SUBSCR_SEQ_IIO: { - stackTop = bytecodeStoreSubscrSeqIIO(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.STORE_SUBSCR_SEQ_IDO: { - stackTop = bytecodeStoreSubscrSeqIDO(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.RAISE_VARARGS: { - int count = Byte.toUnsignedInt(localBC[bci + 1]); - throw bytecodeRaiseVarargs(virtualFrame, stackTop, beginBci, count, localNodes); - } - case OpCodesConstants.RETURN_VALUE: { - setCurrentBci(virtualFrame, bciSlot, bci); - return bytecodeReturnValue(virtualFrame, isGeneratorOrCoroutine, instrumentation, mutableData, stackTop, tracingOrProfilingEnabled, beginBci); - } - case OpCodesConstants.LOAD_BUILD_CLASS: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeLoadBuildClass(virtualFrame, useCachedNodes, ++stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.STORE_NAME: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeStoreName(virtualFrame, stackTop, beginBci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.STORE_ATTR: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeStoreAttr(virtualFrame, stackTop, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.STORE_GLOBAL: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeStoreGlobal(virtualFrame, globals, stackTop, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.LOAD_NAME: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadName(virtualFrame, stackTop, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.LOAD_GLOBAL: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadGlobal(virtualFrame, globals, stackTop, beginBci, localNames[oparg], localNodes, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_FAST: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytecodeDeleteFast(localFrame, beginBci, localNodes, oparg); - break; - } - case OpCodesConstants.LOAD_ATTR: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytecodeLoadAttr(virtualFrame, stackTop, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.IMPORT_NAME: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeImportName(virtualFrame, globals, stackTop, beginBci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.IMPORT_FROM: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeImportFrom(virtualFrame, stackTop, beginBci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.JUMP_FORWARD: - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - case OpCodesConstants.POP_AND_JUMP_IF_FALSE: { - bytecodePopAndJumpIfFalse(virtualFrame, bci, stackTop); - continue; - } - case OpCodesConstants.POP_AND_JUMP_IF_TRUE: { - bytecodePopAndJumpIfTrue(virtualFrame, bci, stackTop); - continue; - } - case OpCodesConstants.POP_AND_JUMP_IF_FALSE_O: { - setCurrentBci(virtualFrame, bciSlot, bci); - if (profileCondition(!bytecodePopCondition(virtualFrame, stackTop--, localNodes, bci, useCachedNodes), localBC, bci, useCachedNodes)) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - bci += 3; - } - break; - } - case OpCodesConstants.POP_AND_JUMP_IF_TRUE_O: { - setCurrentBci(virtualFrame, bciSlot, bci); - if (profileCondition(bytecodePopCondition(virtualFrame, stackTop--, localNodes, bci, useCachedNodes), localBC, bci, useCachedNodes)) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - bci += 3; - } - break; - } - case OpCodesConstants.POP_AND_JUMP_IF_FALSE_B: { - if (!virtualFrame.isBoolean(stackTop)) { - generalizePopAndJumpIfFalseB(bci); - continue; - } - boolean cond = virtualFrame.getBoolean(stackTop); - clearInCompiledCode(virtualFrame, stackTop--); - if (profileCondition(!cond, localBC, bci, useCachedNodes)) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - bci += 3; - } - break; - } - case OpCodesConstants.POP_AND_JUMP_IF_TRUE_B: { - if (!virtualFrame.isBoolean(stackTop)) { - generalizePopAndJumpIfTrueB(bci); - continue; - } - boolean cond = virtualFrame.getBoolean(stackTop); - clearInCompiledCode(virtualFrame, stackTop--); - if (profileCondition(cond, localBC, bci, useCachedNodes)) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - bci += 3; - } - break; - } - case OpCodesConstants.JUMP_IF_FALSE_OR_POP: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean cond = evaluateObjectCondition(virtualFrame, useCachedNodes, stackTop, bci, localBC, localNodes, beginBci); - if (cond) { - virtualFrame.clear(stackTop--); - bci += 3; - } else { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } - break; - } - case OpCodesConstants.JUMP_IF_TRUE_OR_POP: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean cond = evaluateObjectCondition(virtualFrame, useCachedNodes, stackTop, bci, localBC, localNodes, beginBci); - if (cond) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - virtualFrame.clear(stackTop--); - bci += 3; - } - break; - } - case OpCodesConstants.JUMP_BACKWARD: { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci -= oparg; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - if (CompilerDirectives.hasNextTier()) { - int counter = ++mutableData.loopCount; - if (CompilerDirectives.inInterpreter()) { - if (!useCachedNodes) { - return new InterpreterContinuation(bci, stackTop); - } - } - if (CompilerDirectives.injectBranchProbability(OSRInterpreterState.REPORT_LOOP_PROBABILITY, counter >= OSRInterpreterState.REPORT_LOOP_STRIDE)) { - LoopNode.reportLoopCount(this, counter); - if (CompilerDirectives.inInterpreter() && BytecodeOSRNode.pollOSRBackEdge(osrNode, counter)) { - /* - * Beware of race conditions when adding more things to the - * interpreterState argument. It gets stored already at this - * point, but the compilation runs in parallel. The compiled - * code may get entered from a different invocation of this - * root, using the interpreterState that was saved here. Don't - * put any data specific to particular invocation in there (like - * python-level arguments or variables) or it will get mixed up. - * To retain such state, put it into the frame instead. - */ - Object osrResult; - try { - osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, new OSRInterpreterState(stackTop), null, virtualFrame); - } catch (AbstractTruffleException e) { - /* - * If the OSR execution throws a python exception, it means - * it has already been processed by the bytecode exception - * handler therein. We wrap it in order to make sure it - * doesn't get processed again, which would overwrite the - * traceback entry with the location of this jump - * instruction. - */ - throw new OSRException(e); - } - if (osrResult != null) { - return osrResult; - } - } - mutableData.loopCount = 0; - } - } - PythonContext.triggerAsyncActions(this); - oparg = 0; - continue; - } - case OpCodesConstants.GET_ITER: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeGetIter(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.GET_YIELD_FROM_ITER: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeGetYieldFromIter(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.FOR_ITER_O: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean shouldLoop = bytecodeForIterO(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - if (shouldLoop) { - stackTop++; - bci++; - } else { - virtualFrame.clear(stackTop--); - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } - break; - } - case OpCodesConstants.FOR_ITER_I: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean shouldLoop = bytecodeForIterI(virtualFrame, useCachedNodes, stackTop, bci, localNodes, beginBci); - if (shouldLoop) { - stackTop++; - bci++; - } else { - virtualFrame.clear(stackTop--); - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } - break; - } - case OpCodesConstants.LOAD_METHOD: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadMethod(virtualFrame, stackTop, bci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.CALL_METHOD: { - setCurrentBci(virtualFrame, bciSlot, bci); - int argcount = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeCallMethod(virtualFrame, stackTop, beginBci, argcount, localNodes, useCachedNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.CALL_METHOD_VARARGS: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeCallMethodVarargs(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.CALL_FUNCTION: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeCallFunction(virtualFrame, stackTop, beginBci, oparg, localNodes, useCachedNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.CALL_COMPREHENSION: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeCallComprehension(virtualFrame, stackTop, beginBci, localNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.CALL_FUNCTION_VARARGS: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeCallFunctionVarargs(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.CALL_FUNCTION_KW: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeCallFunctionKw(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes, mutableData, tracingOrProfilingEnabled); - break; - } - case OpCodesConstants.MAKE_FUNCTION: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - int flags = Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeMakeFunction(virtualFrame, globals, stackTop, localNodes, beginBci, oparg, flags, localConsts[oparg]); - break; - } - case OpCodesConstants.SETUP_ANNOTATIONS: { - setCurrentBci(virtualFrame, bciSlot, bci); - bytecodeSetupAnnotations(virtualFrame, useCachedNodes, localNodes, beginBci); - break; - } - case OpCodesConstants.MATCH_EXC_OR_JUMP: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean match = bytecodeMatchExc(virtualFrame, useCachedNodes, stackTop--, localNodes, beginBci); - if (profileCondition(!match, localBC, bci, useCachedNodes)) { - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } else { - bci += 3; - } - break; - } - case OpCodesConstants.UNWRAP_EXC: { - bytecodeUnwrapExc(virtualFrame, stackTop); - break; - } - case OpCodesConstants.SETUP_WITH: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeSetupWith(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.EXIT_WITH: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeExitWith(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.SETUP_AWITH: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeSetupAWith(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.GET_AEXIT_CORO: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeGetAExitCoro(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.EXIT_AWITH: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeExitAWith(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.GET_AITER: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeGetAIter(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.GET_ANEXT: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeGetANext(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.END_ASYNC_FOR: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeEndAsyncFor(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.ASYNCGEN_WRAP: { - virtualFrame.setObject(stackTop, PFactory.createAsyncGeneratorWrappedValue(language, virtualFrame.getObject(stackTop))); - break; - } - case OpCodesConstants.PUSH_EXC_INFO: { - bytecodePushExcInfo(virtualFrame, arguments, mutableData, stackTop++); - break; - } - case OpCodesConstants.POP_EXCEPT: { - mutableData.localException = popExceptionState(arguments, virtualFrame.getObject(stackTop), mutableData.outerException); - virtualFrame.clear(stackTop--); - break; - } - case OpCodesConstants.END_EXC_HANDLER: { - mutableData.localException = popExceptionState(arguments, virtualFrame.getObject(stackTop - 1), mutableData.outerException); - throw bytecodeEndExcHandler(virtualFrame, stackTop); - } - case OpCodesConstants.YIELD_VALUE: { - return bytecodeYieldValue(virtualFrame, localFrame, initialStackTop, arguments, instrumentation, mutableData, stackTop, bci, tracingOrProfilingEnabled, bciSlot); - } - case OpCodesConstants.RESUME_YIELD: { - bytecodeResumeYield(virtualFrame, useCachedNodes, arguments, mutableData, ++stackTop, bci, localNodes); - break; - } - case OpCodesConstants.SEND: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean returned = bytecodeSend(virtualFrame, stackTop, localNodes, beginBci); - if (!returned) { - bci++; - break; - } else { - stackTop--; - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } - } - case OpCodesConstants.THROW: { - setCurrentBci(virtualFrame, bciSlot, bci); - boolean returned = bytecodeThrow(virtualFrame, stackTop, localNodes, beginBci); - if (!returned) { - bci++; - break; - } else { - stackTop--; - oparg |= Byte.toUnsignedInt(localBC[bci + 1]); - bci += oparg; - oparg = 0; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - continue; - } - } - case OpCodesConstants.GET_AWAITABLE: { - setCurrentBci(virtualFrame, bciSlot, bci); - GetAwaitableNode getAwait = insertChildNode(localNodes, beginBci, UNCACHED_OBJECT_GET_AWAITABLE, GetAwaitableNodeGen.class, NODE_OBJECT_GET_AWAITABLE, useCachedNodes); - virtualFrame.setObject(stackTop, getAwait.execute(virtualFrame, virtualFrame.getObject(stackTop))); - break; - } - case OpCodesConstants.EXTENDED_ARG: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - oparg <<= 8; - bci++; - continue; - } - case OpCodesConstants.LOAD_FROM_DICT_OR_DEREF: - case OpCodesConstants.LOAD_FROM_DICT_OR_GLOBALS: - case OpCodesConstants.MAKE_TYPE_PARAM: - case OpCodesConstants.IMPORT_STAR: - case OpCodesConstants.DELETE_DEREF: - case OpCodesConstants.DELETE_ATTR: - case OpCodesConstants.DELETE_GLOBAL: - case OpCodesConstants.DELETE_NAME: - stackTop = infrequentBytecodes(virtualFrame, localFrame, bc, bci, stackTop, beginBci, oparg, localBC, globals, locals, localNames, localNodes, bciSlot, localCelloffset, - useCachedNodes); - bci++; - break; - case OpCodesConstants.PRINT_EXPR: - case OpCodesConstants.LOAD_LOCALS: - case OpCodesConstants.MAKE_TYPE_ALIAS: - case OpCodesConstants.MAKE_GENERIC: - case OpCodesConstants.DELETE_SUBSCR: - case OpCodesConstants.LOAD_ASSERTION_ERROR: - stackTop = infrequentBytecodes(virtualFrame, localFrame, bc, bci, stackTop, beginBci, oparg, localBC, globals, locals, localNames, localNodes, bciSlot, localCelloffset, - useCachedNodes); - break; - default: - throw raiseUnknownBytecodeError(bc); - } - // prepare next loop - oparg = 0; - bci++; - notifyStatement(virtualFrame, instrumentation, mutableData, bci, beginBci); - } catch (PythonExitException | PythonThreadKillException | GeneratorReturnException e) { - throw e; - } catch (OSRException e) { - // Exception from OSR was already handled in the OSR code - throw e.exception; - } catch (Throwable e) { - try { - if (instrumentation != null) { - if (!mutableData.isExceptionNotified()) { - notifyException(virtualFrame, instrumentation, beginBci, e); - } - mutableData.setExceptionNotified(false); - } - if (e instanceof ThreadDeath) { - throw e; - } - AbstractTruffleException exception; - if (e instanceof AbstractTruffleException) { - exception = (AbstractTruffleException) e; - } else { - exception = wrapJavaExceptionIfApplicable(language, e); - if (exception == null) { - throw e; - } - } - - tracingOrProfilingEnabled = checkTracingAndProfilingEnabled(noTraceOrProfile, mutableData); - if (isTracingEnabled(tracingOrProfilingEnabled) && exception != null && !mutableData.getThreadState(this).isTracing()) { - traceException(virtualFrame, mutableData, beginBci, exception); - } - - int targetIndex = findHandler(beginBci); - CompilerAsserts.partialEvaluationConstant(targetIndex); - chainPythonExceptions(virtualFrame, mutableData, exception); - if (targetIndex == -1) { - prepareForReraise(virtualFrame, localFrame, initialStackTop, isGeneratorOrCoroutine, mutableData, bciSlot, beginBci, tracingOrProfilingEnabled, bci); - if (exception instanceof PException) { - ((PException) exception).notifyAddedTracebackFrame(frameIsVisibleToPython()); - throw exception; - } else { - throw e; - } - } - if (exception instanceof PException) { - ((PException) exception).setCatchingFrameReference(virtualFrame, this, beginBci); - } - int stackSizeOnEntry = exceptionHandlerRanges[targetIndex + 1]; - int targetStackTop = stackSizeOnEntry + stackoffset; - stackTop = unwindBlock(virtualFrame, stackTop, targetStackTop); - /* - * Handler range encodes the stack size, not the top of stack. so the stackTop - * is to be replaced with the exception - */ - virtualFrame.setObject(stackTop, exception); - bci = exceptionHandlerRanges[targetIndex]; - oparg = 0; - if (instrumentation != null) { - notifyStatementAfterException(virtualFrame, instrumentation, bci); - } - } catch (Throwable t) { - if (instrumentation != null) { - // Need to handle instrumentation frame unwind - Object result = notifyExceptionalReturn(virtualFrame, mutableData, t); - if (result == ProbeNode.UNWIND_ACTION_REENTER) { - CompilerDirectives.transferToInterpreter(); - copyArgs(virtualFrame.getArguments(), virtualFrame); - bci = 0; - stackTop = getInitialStackTop(); - oparg = 0; - result = notifyEnter(virtualFrame, instrumentation, bci); - if (result != null) { - return result; - } - continue; - } else if (result != null) { - return result; - } - } - throw t; - } - } - } - } - - @BytecodeInterpreterSwitch - private int infrequentBytecodes(VirtualFrame virtualFrame, Frame localFrame, byte bc, int bci, int stackTop, int beginBci, int oparg, byte[] localBC, Object globals, Object locals, - TruffleString[] localNames, Node[] localNodes, int bciSlot, int localCelloffset, boolean useCachedNodes) { - switch (bc) { - case OpCodesConstants.LOAD_LOCALS: { - if (locals == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.NO_LOCALS_FOUND); - } - virtualFrame.setObject(++stackTop, locals); - break; - } - case OpCodesConstants.LOAD_ASSERTION_ERROR: { - virtualFrame.setObject(++stackTop, PythonBuiltinClassType.AssertionError); - break; - } - case OpCodesConstants.LOAD_FROM_DICT_OR_DEREF: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadFromDictOrDeref(virtualFrame, localFrame, stackTop, beginBci, localNodes, - oparg, localCelloffset, useCachedNodes); - break; - } - case OpCodesConstants.LOAD_FROM_DICT_OR_GLOBALS: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeLoadFromDictOrGlobals(virtualFrame, globals, stackTop, beginBci, - localNames[oparg], localNodes, useCachedNodes); - break; - } - case OpCodesConstants.MAKE_TYPE_PARAM: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeMakeTypeParam(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci, - oparg); - break; - } - case OpCodesConstants.MAKE_TYPE_ALIAS: { - stackTop = bytecodeMakeTypeAlias(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.MAKE_GENERIC: { - stackTop = bytecodeMakeGeneric(virtualFrame, useCachedNodes, stackTop, localNodes, beginBci); - break; - } - case OpCodesConstants.PRINT_EXPR: { - stackTop = bytecodePrintExpr(virtualFrame, useCachedNodes, stackTop, bci, localNodes, bciSlot, beginBci); - break; - } - case OpCodesConstants.IMPORT_STAR: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeImportStar(virtualFrame, stackTop, beginBci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_DEREF: { - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytecodeDeleteDeref(localFrame, beginBci, localNodes, oparg, localCelloffset, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_ATTR: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - stackTop = bytecodeDeleteAttr(virtualFrame, stackTop, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_GLOBAL: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytecodeDeleteGlobal(virtualFrame, globals, beginBci, oparg, localNodes, localNames, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_NAME: { - setCurrentBci(virtualFrame, bciSlot, bci); - oparg |= Byte.toUnsignedInt(localBC[++bci]); - bytecodeDeleteName(virtualFrame, globals, locals, beginBci, oparg, localNames, localNodes, useCachedNodes); - break; - } - case OpCodesConstants.DELETE_SUBSCR: { - setCurrentBci(virtualFrame, bciSlot, bci); - stackTop = bytecodeDeleteSubscr(virtualFrame, stackTop, beginBci, localNodes, useCachedNodes); - break; - } - default: - throw raiseUnknownBytecodeError(bc); - - } - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeGetAIter(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int bci) { - GetAIterNode node = insertChildNode(localNodes, bci, UNCACHED_GET_AITER, GetAIterNodeGen.class, NODE_GET_AITER, useCachedNodes); - virtualFrame.setObject(stackTop, node.execute(virtualFrame, virtualFrame.getObject(stackTop))); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeGetANext(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int bci) { - GetANextNode node = insertChildNode(localNodes, bci, UNCACHED_GET_ANEXT, GetANextNodeGen.class, NODE_GET_ANEXT, useCachedNodes); - virtualFrame.setObject(stackTop, node.execute(virtualFrame, virtualFrame.getObject(stackTop))); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeEndAsyncFor(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int bci) { - EndAsyncForNode node = insertChildNode(localNodes, bci, UNCACHED_END_ASYNC_FOR, EndAsyncForNodeGen.class, NODE_END_ASYNC_FOR, useCachedNodes); - node.execute(virtualFrame.getObject(stackTop), frameIsVisibleToPython()); - virtualFrame.clear(stackTop); // pop the exception - virtualFrame.clear(stackTop - 1); // the coroutine that raised the exception - virtualFrame.clear(stackTop - 2); // the async iterator - return stackTop - 3; - } - - @BytecodeInterpreterSwitch - @ExplodeLoop - private void bytcodeRotN(VirtualFrame virtualFrame, int stackTop, int oparg) { - CompilerAsserts.partialEvaluationConstant(oparg); - if (oparg > 1) { - Object top = virtualFrame.getObject(stackTop); - int i = 0; - for (; i < oparg - 1; i++) { - virtualFrame.setObject(stackTop - i, virtualFrame.getObject(stackTop - i - 1)); - } - virtualFrame.setObject(stackTop - i, top); - } - } - - @BytecodeInterpreterSwitch - private int bytecodeCheckTpFlags(VirtualFrame virtualFrame, long flags, boolean useCachedNodes, int stackTop, int bci, Node[] localNodes) { - Object obj = virtualFrame.getObject(stackTop); - GetTPFlagsNode flagsNode = insertChildNode(localNodes, bci, UNCACHED_TP_FLAGS, GetTPFlagsNodeGen.class, NODE_TP_FLAGS, useCachedNodes); - boolean res = (flagsNode.execute(obj) & flags) != 0; - virtualFrame.setObject(++stackTop, res); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeMatchKeys(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - Object keys = virtualFrame.getObject(stackTop); - Object subject = virtualFrame.getObject(stackTop - 1); - MatchKeysNode matchKeysNode = insertChildNode(localNodes, bci, MatchKeysNodeGen.class, NODE_MATCH_KEYS); - Object values = matchKeysNode.execute(virtualFrame, subject, (Object[]) keys); - virtualFrame.setObject(++stackTop, values); - virtualFrame.setObject(++stackTop, values != PNone.NONE ? true : false); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCopyDictWithoutKeys(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - Object keys = virtualFrame.getObject(stackTop); - Object subject = virtualFrame.getObject(stackTop - 1); - CopyDictWithoutKeysNode copyDictNode = insertChildNode(localNodes, bci, CopyDictWithoutKeysNodeGen.class, NODE_COPY_DICT_WITHOUT_KEYS); - PDict rest = copyDictNode.execute(virtualFrame, subject, (Object[]) keys); - virtualFrame.setObject(stackTop, rest); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeMatchClass(VirtualFrame virtualFrame, int stackTop, int oparg, int bci, Node[] localNodes) { - TruffleString[] argNames = (TruffleString[]) virtualFrame.getObject(stackTop--); - Object type = virtualFrame.getObject(stackTop); - Object subject = virtualFrame.getObject(stackTop - 1); - - MatchClassNode matchClassNode = insertChildNode(localNodes, bci, MatchClassNodeGen.class, NODE_MATCH_CLASS); - Object attrs = matchClassNode.execute(virtualFrame, subject, type, oparg, argNames); - - if (attrs != null) { - virtualFrame.setObject(stackTop, true); - virtualFrame.setObject(stackTop - 1, attrs); - } else { - virtualFrame.setObject(stackTop, false); - } - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeGetLen(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, int bci, Node[] localNodes) { - Object seq = virtualFrame.getObject(stackTop); - PyObjectSizeNode sizeNode = insertChildNode(localNodes, bci, UNCACHED_SIZE, PyObjectSizeNodeGen.class, NODE_SIZE, useCachedNodes); - Object s = sizeNode.executeCached(virtualFrame, seq); - virtualFrame.setObject(++stackTop, s); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeKwargsMerge(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, int bci, Node[] localNodes) { - KwargsMergeNode mergeNode = insertChildNode(localNodes, bci, UNCACHED_KWARGS_MERGE, KwargsMergeNodeGen.class, NODE_KWARGS_MERGE, useCachedNodes); - return mergeNode.execute(virtualFrame, stackTop); - } - - @BytecodeInterpreterSwitch - private boolean evaluateObjectCondition(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, int bci, byte[] localBC, Node[] localNodes, int beginBci) { - PyObjectIsTrueNode isTrue = insertChildNode(localNodes, beginBci, UNCACHED_OBJECT_IS_TRUE, PyObjectIsTrueNodeGen.class, NODE_OBJECT_IS_TRUE, useCachedNodes); - Object condObj = virtualFrame.getObject(stackTop); - boolean cond = isTrue.execute(virtualFrame, condObj); - return profileCondition(cond, localBC, bci, useCachedNodes); - } - - @BytecodeInterpreterSwitch - private void bytecodeGetIter(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - PyObjectGetIter getIter = insertChildNode(localNodes, beginBci, UNCACHED_OBJECT_GET_ITER, PyObjectGetIterNodeGen.class, NODE_OBJECT_GET_ITER, useCachedNodes); - virtualFrame.setObject(stackTop, getIter.executeCached(virtualFrame, virtualFrame.getObject(stackTop))); - } - - @BytecodeInterpreterSwitch - private void bytecodeGetYieldFromIter(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - GetYieldFromIterNode getIter = insertChildNode(localNodes, beginBci, UNCACHED_OBJECT_GET_YIELD_FROM_ITER, GetYieldFromIterNodeGen.class, NODE_OBJECT_GET_YIELD_FROM_ITER, useCachedNodes); - virtualFrame.setObject(stackTop, getIter.execute(virtualFrame, virtualFrame.getObject(stackTop))); - } - - @BytecodeInterpreterSwitch - private boolean bytecodeForIterO(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - ForIterONode node = insertChildNode(localNodes, beginBci, UNCACHED_FOR_ITER_O, ForIterONodeGen.class, NODE_FOR_ITER_O, useCachedNodes); - return node.execute(virtualFrame, virtualFrame.getObject(stackTop), stackTop + 1); - } - - @BytecodeInterpreterSwitch - private boolean bytecodeForIterI(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, int bci, Node[] localNodes, int beginBci) { - ForIterINode node = insertChildNode(localNodes, beginBci, UNCACHED_FOR_ITER_I, ForIterINodeGen.class, NODE_FOR_ITER_I, useCachedNodes); - boolean cont = true; - try { - cont = node.execute(virtualFrame, virtualFrame.getObject(stackTop), stackTop + 1); - } catch (QuickeningGeneralizeException e) { - generalizeForIterI(bci, e); - } - return cont; - } - - @BytecodeInterpreterSwitch - private boolean bytecodeMatchExc(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - Object exception = virtualFrame.getObject(stackTop - 1); - Object matchType = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop); - ExceptMatchNode matchNode = insertChildNode(localNodes, beginBci, UNCACHED_EXCEPT_MATCH, ExceptMatchNodeGen.class, NODE_EXCEPT_MATCH, useCachedNodes); - return matchNode.executeMatch(exception, matchType); - } - - @BytecodeInterpreterSwitch - private void bytecodeUnwrapExc(VirtualFrame virtualFrame, int stackTop) { - Object exception = virtualFrame.getObject(stackTop); - if (exception instanceof PException) { - virtualFrame.setObject(stackTop, ((PException) exception).getEscapedException()); - } - // Let interop exceptions be - } - - @BytecodeInterpreterSwitch - private int bytecodeSetupWith(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - SetupWithNode setupWithNode = insertChildNode(localNodes, beginBci, UNCACHED_SETUP_WITH_NODE, SetupWithNodeGen.class, NODE_SETUP_WITH, useCachedNodes); - return setupWithNode.execute(virtualFrame, stackTop); - } - - @BytecodeInterpreterSwitch - private int bytecodeExitWith(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - ExitWithNode exitWithNode = insertChildNode(localNodes, beginBci, UNCACHED_EXIT_WITH_NODE, ExitWithNodeGen.class, NODE_EXIT_WITH, useCachedNodes); - return exitWithNode.execute(virtualFrame, stackTop, frameIsVisibleToPython()); - } - - @BytecodeInterpreterSwitch - private int bytecodeSetupAWith(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - SetupAwithNode setupAwithNode = insertChildNode(localNodes, beginBci, UNCACHED_SETUP_AWITH_NODE, SetupAwithNodeGen.class, NODE_SETUP_AWITH, useCachedNodes); - return setupAwithNode.execute(virtualFrame, stackTop); - } - - @BytecodeInterpreterSwitch - private int bytecodeGetAExitCoro(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - GetAExitCoroNode getAExitCoroNode = insertChildNode(localNodes, beginBci, UNCACHED_GET_AEXIT_CORO_NODE, GetAExitCoroNodeGen.class, NODE_GET_AEXIT_CORO, useCachedNodes); - return getAExitCoroNode.execute(virtualFrame, stackTop); - } - - @BytecodeInterpreterSwitch - private int bytecodeExitAWith(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - ExitAWithNode exitAWithNode = insertChildNode(localNodes, beginBci, UNCACHED_EXIT_AWITH_NODE, ExitAWithNodeGen.class, NODE_EXIT_AWITH, useCachedNodes); - return exitAWithNode.execute(virtualFrame, stackTop, frameIsVisibleToPython()); - } - - @BytecodeInterpreterSwitch - private boolean bytecodeSend(VirtualFrame virtualFrame, int stackTop, Node[] localNodes, int beginBci) { - Object value = virtualFrame.getObject(stackTop); - Object obj = virtualFrame.getObject(stackTop - 1); - SendNode sendNode = insertChildNode(localNodes, beginBci, SendNodeGen.class, NODE_SEND); - return sendNode.execute(virtualFrame, stackTop, obj, value); - } - - @BytecodeInterpreterSwitch - private boolean bytecodeThrow(VirtualFrame virtualFrame, int stackTop, Node[] localNodes, int beginBci) { - Object exception = virtualFrame.getObject(stackTop); - Object obj = virtualFrame.getObject(stackTop - 1); - ThrowNode throwNode = insertChildNode(localNodes, beginBci, ThrowNodeGen.class, NODE_THROW); - return throwNode.execute(virtualFrame, stackTop, obj, (AbstractTruffleException) exception); - } - - @BytecodeInterpreterSwitch - private void bytecodeSetupAnnotations(VirtualFrame virtualFrame, boolean useCachedNodes, Node[] localNodes, int beginBci) { - SetupAnnotationsNode setupAnnotationsNode = insertChildNode(localNodes, beginBci, UNCACHED_SETUP_ANNOTATIONS, SetupAnnotationsNodeGen.class, NODE_SETUP_ANNOTATIONS, - useCachedNodes); - setupAnnotationsNode.execute(virtualFrame); - } - - @BytecodeInterpreterSwitch - private int bytecodeMakeFunction(VirtualFrame virtualFrame, Object globals, int stackTop, Node[] localNodes, int beginBci, int codeIndex, int flags, Object localConsts) { - BytecodeCodeUnit codeUnit = (BytecodeCodeUnit) localConsts; - MakeFunctionNode makeFunctionNode = insertMakeFunctionNode(localNodes, beginBci, codeIndex, codeUnit); - return makeFunctionNode.execute(virtualFrame, globals, stackTop, flags); - } - - private int bytecodeMakeTypeParam(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci, int kind) { - MakeTypeParamNode makeTypeParamNode = insertChildNode(localNodes, beginBci, UNCACHED_MAKE_TYPE_PARAM, MakeTypeParamNodeGen.class, NODE_MAKE_TYPE_PARAM, useCachedNodes); - return makeTypeParamNode.execute(virtualFrame, stackTop, kind); - } - - private int bytecodeMakeTypeAlias(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - MakeTypeAliasNode makeTypeAliasNode = insertChildNode(localNodes, beginBci, UNCACHED_MAKE_TYPE_ALIAS, MakeTypeAliasNodeGen.class, NODE_MAKE_TYPE_ALIAS, useCachedNodes); - return makeTypeAliasNode.execute(virtualFrame, stackTop); - } - - private int bytecodeMakeGeneric(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - MakeGenericNode makeGenericNode = insertChildNode(localNodes, beginBci, UNCACHED_MAKE_GENERIC, MakeGenericNodeGen.class, NODE_MAKE_GENERIC, useCachedNodes); - return makeGenericNode.execute(virtualFrame, stackTop); - } - - @BytecodeInterpreterSwitch - private void bytecodeResumeYield(VirtualFrame virtualFrame, boolean useCachedNodes, Object[] arguments, MutableLoopData mutableData, int stackTop, int bci, Node[] localNodes) { - mutableData.localException = PArguments.getException(PGenerator.getGeneratorFrame(arguments)); - if (mutableData.localException != null) { - PArguments.setException(arguments, mutableData.localException); - } - GetSendValueNode node = insertChildNode(localNodes, bci, UNCACHED_GET_SEND_VALUE, GetSendValueNodeGen.class, NODE_GET_SEND_VALUE, useCachedNodes); - virtualFrame.setObject(stackTop, node.execute(PGenerator.getSendValue(arguments))); - } - - @BytecodeInterpreterSwitch - private void bytecodePushExcInfo(VirtualFrame virtualFrame, Object[] arguments, MutableLoopData mutableData, int stackTop) { - Object exception = virtualFrame.getObject(stackTop); - if (!mutableData.fetchedException) { - mutableData.outerException = PArguments.getException(arguments); - mutableData.fetchedException = true; - } - virtualFrame.setObject(stackTop++, mutableData.localException); - mutableData.localException = (AbstractTruffleException) exception; - PArguments.setException(arguments, mutableData.localException); - virtualFrame.setObject(stackTop, exception); - } - - @BytecodeInterpreterSwitch - private GeneratorYieldResult bytecodeYieldValue(VirtualFrame virtualFrame, Frame localFrame, int initialStackTop, Object[] arguments, InstrumentationSupport instrumentation, - MutableLoopData mutableData, int stackTop, int bci, byte tracingOrProfilingEnabled, int bciSlot) { - if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) { - LoopNode.reportLoopCount(this, mutableData.loopCount); - } - setCurrentBci(virtualFrame, bciSlot, bci); - Object value = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - traceOrProfileYield(virtualFrame, mutableData, value, tracingOrProfilingEnabled, bci); - if (instrumentation != null) { - notifyReturn(virtualFrame, mutableData, instrumentation, bci, value); - } - // Suspended generators have no backref - PArguments.getCurrentFrameInfo(virtualFrame.getArguments()).setCallerInfo(PFrame.Reference.EMPTY); - PArguments.setException(PGenerator.getGeneratorFrame(arguments), mutableData.localException); - // See PBytecodeGeneratorRootNode#execute - if (localFrame != virtualFrame) { - copyStackSlotsToGeneratorFrame(virtualFrame, localFrame, stackTop); - // Clear slots that were popped (if any) - clearFrameSlots(localFrame, stackTop + 1, initialStackTop); - } - return new GeneratorYieldResult(bci + 1, stackTop, value); - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadBuildClass(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, Node[] localNodes, int beginBci) { - ReadBuiltinNode read = insertChildNode(localNodes, beginBci, UNCACHED_READ_BUILTIN, ReadBuiltinNodeGen.class, NODE_READ_BUILTIN_BUILD_CLASS, useCachedNodes); - virtualFrame.setObject(stackTop, read.execute(T___BUILD_CLASS__)); - } - - @BytecodeInterpreterSwitch - private Object bytecodeReturnValue(VirtualFrame virtualFrame, boolean isGeneratorOrCoroutine, InstrumentationSupport instrumentation, MutableLoopData mutableData, int stackTop, - byte tracingOrProfilingEnabled, int bci) { - if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) { - LoopNode.reportLoopCount(this, mutableData.loopCount); - } - Object value = virtualFrame.getObject(stackTop); - traceOrProfileReturn(virtualFrame, mutableData, value, tracingOrProfilingEnabled, bci); - - if (instrumentation != null) { - notifyReturn(virtualFrame, mutableData, instrumentation, bci, value); - } - if (isGeneratorOrCoroutine) { - throw new GeneratorReturnException(value); - } else { - return value; - } - } - - @InliningCutoff - private void notifyStatementAfterException(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, int bci) { - instrumentation.notifyStatementEnter(virtualFrame, bciToLine(bci)); - } - - @InliningCutoff - private void notifyException(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, int bci, Throwable e) { - instrumentation.notifyException(virtualFrame, bciToLine(bci), e); - } - - @InliningCutoff - private Object notifyExceptionalReturn(VirtualFrame virtualFrame, MutableLoopData mutableData, Throwable e) { - if (instrumentationRoot instanceof WrapperNode) { - WrapperNode wrapper = (WrapperNode) instrumentationRoot; - Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, e, mutableData.isReturnCalled()); - checkOnReturnExceptionalOrUnwindResult(result); - return result; - } - return null; - } - - private void checkOnReturnExceptionalOrUnwindResult(Object result) { - if (result != null) { - if (co.isGeneratorOrCoroutine()) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw new IllegalStateException(result == ProbeNode.UNWIND_ACTION_REENTER ? "Frame restarting is not possible in generators" : "Cannot replace return value of generators"); - } - } - } - - @InliningCutoff - private void notifyReturn(VirtualFrame virtualFrame, MutableLoopData mutableData, InstrumentationSupport instrumentation, int bci, Object value) { - try { - instrumentation.notifyStatementExit(virtualFrame, bciToLine(bci)); - } catch (Throwable t) { - mutableData.setExceptionNotified(true); - throw t; - } - mutableData.setReturnCalled(true); - if (instrumentationRoot instanceof WrapperNode) { - WrapperNode wrapper = (WrapperNode) instrumentationRoot; - wrapper.getProbeNode().onReturnValue(virtualFrame, value); - } - } - - private void notifyStatement(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, MutableLoopData mutableData, int bci, int beginBci) { - if (instrumentation != null) { - notifyStatementCutoff(virtualFrame, instrumentation, mutableData, beginBci, bci); - } - } - - @InliningCutoff - private void notifyStatementCutoff(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, MutableLoopData mutableData, int prevBci, int nextBci) { - try { - instrumentation.notifyStatement(virtualFrame, bciToLine(prevBci), bciToLine(nextBci)); - } catch (Throwable t) { - mutableData.setExceptionNotified(true); - throw t; - } - } - - @InliningCutoff - private Object notifyEnter(VirtualFrame virtualFrame, InstrumentationSupport instrumentation, int initialBci) { - if (instrumentationRoot instanceof WrapperNode) { - WrapperNode wrapper = (WrapperNode) instrumentationRoot; - try { - wrapper.getProbeNode().onEnter(virtualFrame); - } catch (Throwable t) { - Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(virtualFrame, t, false); - checkOnReturnExceptionalOrUnwindResult(result); - if (result == ProbeNode.UNWIND_ACTION_REENTER) { - // We're at the beginning, reenter means just restore args and continue - copyArgs(virtualFrame.getArguments(), virtualFrame); - return null; - } else if (result != null) { - return result; - } - } - } - int line = bciToLine(initialBci); - try { - instrumentation.notifyStatementEnter(virtualFrame, line); - } catch (Throwable t) { - instrumentation.notifyException(virtualFrame, line, t); - throw t; - } - return null; - } - - private MakeFunctionNode insertMakeFunctionNode(Node[] localNodes, int beginBci, int codeIndex, BytecodeCodeUnit codeUnit) { - return insertChildNode(localNodes, beginBci, MakeFunctionNodeGen.class, () -> MakeFunctionNode.create(codeIndex, codeUnit)); - } - - public void materializeContainedFunctionsForInstrumentation(Set> materializedTags) { - usingCachedNodes = true; - PythonLanguage language = getLanguage(); - for (int i = 0; i < co.constants.length; i++) { - if (co.constants[i] instanceof BytecodeCodeUnit codeUnit) { - RootNode rootNode = language.createCachedRootNode( - l -> PBytecodeRootNode.createMaybeGenerator(language, codeUnit, getSource(), isInternal()), - codeUnit); - rootNode.getCallTarget(); // make sure the calltarget is initialized - if (rootNode instanceof PBytecodeGeneratorFunctionRootNode) { - rootNode = ((PBytecodeGeneratorFunctionRootNode) rootNode).getBytecodeRootNode(); - } - ((PBytecodeRootNode) rootNode).instrumentationRoot.materializeInstrumentableNodes(materializedTags); - } - } - } - - public Node createInstrumentationMaterializationForwarder() { - return new InstrumentationMaterializationForwarder(instrumentationRoot); - } - - @InliningCutoff // Used only to print expressions in interactive mode - private int bytecodePrintExpr(VirtualFrame virtualFrame, boolean useCachedNodes, int stackTop, int bci, Node[] localNodes, int bciSlot, int beginBci) { - setCurrentBci(virtualFrame, bciSlot, bci); - PrintExprNode printExprNode = insertChildNode(localNodes, beginBci, UNCACHED_PRINT_EXPR, PrintExprNodeGen.class, NODE_PRINT_EXPR, useCachedNodes); - printExprNode.execute(virtualFrame, virtualFrame.getObject(stackTop)); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private byte checkTracingAndProfilingEnabled(Assumption noTraceOrProfile, MutableLoopData mutableData) { - if (!noTraceOrProfile.isValid()) { - PythonContext.PythonThreadState ts = mutableData.getThreadState(this); - Object profileFun = ts.getProfileFun(); - if (ts.getTraceFun() != null) { - if (profileFun != null) { - return TRACE_AND_PROFILE_FUN; - } else { - return TRACE_FUN; - } - } else if (profileFun != null) { - return PROFILE_FUN; - } - } - return 0; - } - - private static boolean isTracingOrProfilingEnabled(byte tracingOrProfilingEnabled) { - return tracingOrProfilingEnabled != 0; - } - - private static boolean isTracingEnabled(byte tracingOrProfilingEnabled) { - return (tracingOrProfilingEnabled & TRACE_FUN) != 0; - } - - private static boolean isProfilingEnabled(byte tracingOrProfilingEnabled) { - return (tracingOrProfilingEnabled & PROFILE_FUN) != 0; - } - - private void traceOrProfileYield(VirtualFrame virtualFrame, MutableLoopData mutableData, Object value, byte tracingOrProfilingEnabled, int bci) { - if (isTracingOrProfilingEnabled(tracingOrProfilingEnabled)) { - traceOrProfileYieldCutoff(virtualFrame, mutableData, value, tracingOrProfilingEnabled, bci); - } - } - - @InliningCutoff - private void traceOrProfileYieldCutoff(VirtualFrame virtualFrame, MutableLoopData mutableData, Object value, byte tracingOrProfilingEnabled, int bci) { - if (isTracingEnabled(tracingOrProfilingEnabled)) { - invokeTraceFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.RETURN, mutableData.getReturnLine(), true, bci); - } - if (isProfilingEnabled(tracingOrProfilingEnabled)) { - invokeProfileFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.ProfileEvent.RETURN, bci); - } - } - - private void traceOrProfileReturn(VirtualFrame virtualFrame, MutableLoopData mutableData, Object value, byte tracingOrProfilingEnabled, int bci) { - if (isTracingOrProfilingEnabled(tracingOrProfilingEnabled)) { - traceOrProfileReturnCutoff(virtualFrame, mutableData, value, tracingOrProfilingEnabled, bci); - } - } - - @InliningCutoff - private void traceOrProfileReturnCutoff(VirtualFrame virtualFrame, MutableLoopData mutableData, Object value, byte tracingOrProfilingEnabled, int bci) { - if (isTracingEnabled(tracingOrProfilingEnabled)) { - invokeTraceFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.RETURN, mutableData.getReturnLine(), true, bci); - } - if (isProfilingEnabled(tracingOrProfilingEnabled)) { - invokeProfileFunction(virtualFrame, value, mutableData.getThreadState(this), mutableData, PythonContext.ProfileEvent.RETURN, bci); - } - } - - @InliningCutoff - private void traceException(VirtualFrame virtualFrame, MutableLoopData mutableData, int bci, AbstractTruffleException exception) { - mutableData.setPyFrame(ensurePyFrame(virtualFrame, bci)); - if (mutableData.getPyFrame().getLocalTraceFun() != null) { - if (exception instanceof PException) { - ((PException) exception).setCatchingFrameReference(virtualFrame, this, bci); - } - Object exceptionObject = GetEscapedExceptionNode.executeUncached(exception); - Object peType = GetClassNode.executeUncached(exceptionObject); - Object traceback = ExceptionNodes.GetTracebackNode.executeUncached(exception); - invokeTraceFunction(virtualFrame, - PFactory.createTuple(getLanguage(), new Object[]{peType, exceptionObject, traceback}), mutableData.getThreadState(this), - mutableData, - PythonContext.TraceEvent.EXCEPTION, bciToLine(bci), true, bci); - } - } - - private void traceOrProfileCall(VirtualFrame virtualFrame, int initialBci, MutableLoopData mutableData, byte tracingOrProfilingEnabled, int bci) { - if (isTracingOrProfilingEnabled(tracingOrProfilingEnabled)) { - traceOrProfileCallCutoff(virtualFrame, initialBci, mutableData, tracingOrProfilingEnabled, bci); - } - } - - @InliningCutoff - private void traceOrProfileCallCutoff(VirtualFrame virtualFrame, int initialBci, MutableLoopData mutableData, byte tracingOrProfilingEnabled, int bci) { - if (isTracingEnabled(tracingOrProfilingEnabled)) { - invokeTraceFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.CALL, - initialBci == 0 ? getFirstLineno() : (mutableData.setPastLine(bciToLine(initialBci))), false, bci); - } - if (isProfilingEnabled(tracingOrProfilingEnabled)) { - invokeProfileFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.ProfileEvent.CALL, bci); - } - } - - // returns the change in stackTop after the jump, or 1 if no jump happened - @InliningCutoff - private int traceLine(VirtualFrame virtualFrame, MutableLoopData mutableData, byte[] localBC, int bci) { - int thisLine = bciToLine(bci); - int ret = 1; - boolean onANewLine = thisLine != mutableData.getPastLine(); - mutableData.setPastLine(thisLine); - OpCodes c = OpCodes.fromOpCode(localBC[mutableData.getPastBci()]); - /* - * normally, we trace a line every time the previous bytecode instruction was on a different - * line than the current one. There are a number of exceptions to this, notably around - * jumps: - * - * - When a backward jumps happens, a line is traced, even if it is the same as the previous - * one. - * - * - When a forward jump happens to the first bytecode instruction of a line, a line is - * traced. - * - * - When a forward jump happens to the middle of a line, a line is not traced. - * - * see https://github.com/python/cpython/blob/main/Objects/lnotab_notes.txt#L210-L215 for - * more details - */ - boolean shouldTrace = mutableData.getPastBci() > bci; // is a backward jump - if (!shouldTrace) { - shouldTrace = onANewLine && - // is not a forward jump - (mutableData.getPastBci() + c.length() >= bci || - // is a forward jump to the start of line - bciToLine(bci - 1) != thisLine); - } - if (shouldTrace) { - enterTraceProfile(bci, TRACE_PROFILE_LINE); - // do not emit a line event on the line we just jumped to - mutableData.setReturnLine(mutableData.getPastLine()); - mutableData.setPyFrame(ensurePyFrame(virtualFrame, bci)); - PFrame pyFrame = mutableData.getPyFrame(); - if (pyFrame.didJump()) { - mutableData.setPastBci(bci); - return ret; - } - if (pyFrame.getTraceLine()) { - pyFrame.setJumpDestLine(PFrame.NO_JUMP); // jumps from line event allowed - invokeTraceFunction(virtualFrame, null, mutableData.getThreadState(this), mutableData, PythonContext.TraceEvent.LINE, - mutableData.getPastLine(), true, bci); - if (pyFrame.didJump()) { - enterTraceProfile(bci, TRACE_PROFILE_DID_JUMP); - // The loop must be partially unrollable assuming a certain sequence of bytecode - // instructions. A jump can happen non-deterministically and thus break this - // assumption. This can happen repeatedly, so we don't invalidate - CompilerDirectives.transferToInterpreter(); - int newBci = lineToBci(pyFrame.getJumpDestLine()); - mutableData.setPastBci(bci); - if (newBci == BytecodeCodeUnit.LINE_TO_BCI_LINE_AFTER_CODEBLOCK) { - // line after the code block - throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.LINE_D_COMES_AFTER_THE_CURRENT_CODE_BLOCK, pyFrame.getLine()); - } else if (newBci == BytecodeCodeUnit.LINE_TO_BCI_LINE_BEFORE_CODEBLOCK) { - // line before the code block - throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.LINE_D_COMES_BEFORE_THE_CURRENT_CODE_BLOCK, pyFrame.getJumpDestLine()); - } else { - ret = computeJumpStackDifference(bci, newBci); - mutableData.setJumpBci(newBci); - } - } - } - pyFrame.setJumpDestLine(PFrame.DISALLOW_JUMPS); - } - mutableData.setPastBci(bci); - return ret; - } - - @TruffleBoundary - private int computeJumpStackDifference(int bci, int newBci) { - int ret; - var stacks = co.computeStackElems(); - String error = co.checkJump(this, stacks, bci, newBci); - if (error != null) { - throw PRaiseNode.raiseStatic(this, ValueError, ErrorMessages.CANT_JUMP_INTO_S, error); - } - ret = stacks.get(newBci).size() - stacks.get(bci).size(); - return ret; - } - - private int bytecodeBinarySubscrAdaptiveInputOutput(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int bciSlot) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isInt(stackTop) && virtualFrame.getObject(stackTop - 1) instanceof PSequence) { - /* Always start with object result and then try to rewrite to a more specific one */ - // TODO this would benefit from having an uncached node - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_SEQ_I_O; - stackTop = bytecodeBinarySubscrSeqIO(virtualFrame, stackTop, bci, localNodes); - Object result = virtualFrame.getObject(stackTop); - if (result instanceof Integer) { - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_SEQ_I_I; - virtualFrame.setInt(stackTop, (Integer) result); - } else if (result instanceof Double) { - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_SEQ_I_D; - virtualFrame.setDouble(stackTop, (Double) result); - } - return stackTop; - } - if (!virtualFrame.isObject(stackTop)) { - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - } - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_O_O; - return bytecodeBinarySubscrOO(virtualFrame, stackTop, bci, localNodes, bciSlot); - } - - private int bytecodeBinarySubscrAdaptiveInputOnly(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int bciSlot) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isInt(stackTop) && virtualFrame.getObject(stackTop - 1) instanceof PSequence) { - /* Always start with object result and then try to rewrite to a more specific one */ - // TODO this would benefit from having an uncached node - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_SEQ_I_O; - return bytecodeBinarySubscrSeqIO(virtualFrame, stackTop, bci, localNodes); - } - if (!virtualFrame.isObject(stackTop)) { - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - } - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_O_O; - return bytecodeBinarySubscrOO(virtualFrame, stackTop, bci, localNodes, bciSlot); - } - - @BytecodeInterpreterSwitch - private int bytecodeBinarySubscrOO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int bciSlot) { - setCurrentBci(virtualFrame, bciSlot, bci); - PyObjectGetItem getItemNode = insertChildNode(localNodes, bci, PyObjectGetItemNodeGen.class, NODE_GET_ITEM); - Object index; - try { - index = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // Should only happen in multi-context mode - return generalizeBinarySubscr(virtualFrame, stackTop, bci, localNodes); - } - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, getItemNode.executeCached(virtualFrame, virtualFrame.getObject(stackTop), index)); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeBinarySubscrSeqIO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - if (!virtualFrame.isInt(stackTop)) { - return generalizeBinarySubscr(virtualFrame, stackTop, bci, localNodes); - } - int index = virtualFrame.getInt(stackTop); - Object sequence = virtualFrame.getObject(stackTop - 1); - BinarySubscrSeq.ONode node = insertChildNode(localNodes, bci, BinarySubscrSeqFactory.ONodeGen.class, NODE_BINARY_SUBSCR_SEQ_O); - Object value; - try { - value = node.execute(sequence, index); - } catch (QuickeningGeneralizeException e) { - return generalizeBinarySubscrSeq(virtualFrame, stackTop, bci, localNodes, e); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.setObject(stackTop, value); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeBinarySubscrSeqII(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - if (!virtualFrame.isInt(stackTop)) { - return generalizeBinarySubscr(virtualFrame, stackTop, bci, localNodes); - } - int index = virtualFrame.getInt(stackTop); - Object sequence = virtualFrame.getObject(stackTop - 1); - BinarySubscrSeq.INode node = insertChildNode(localNodes, bci, BinarySubscrSeqFactory.INodeGen.class, NODE_BINARY_SUBSCR_SEQ_I); - int value; - try { - value = node.execute(sequence, index); - } catch (QuickeningGeneralizeException e) { - return generalizeBinarySubscrSeq(virtualFrame, stackTop, bci, localNodes, e); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.setInt(stackTop, value); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeBinarySubscrSeqID(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - if (!virtualFrame.isInt(stackTop)) { - return generalizeBinarySubscr(virtualFrame, stackTop, bci, localNodes); - } - int index = virtualFrame.getInt(stackTop); - Object sequence = virtualFrame.getObject(stackTop - 1); - BinarySubscrSeq.DNode node = insertChildNode(localNodes, bci, BinarySubscrSeqFactory.DNodeGen.class, NODE_BINARY_SUBSCR_SEQ_D); - double value; - try { - value = node.execute(sequence, index); - } catch (QuickeningGeneralizeException e) { - return generalizeBinarySubscrSeq(virtualFrame, stackTop, bci, localNodes, e); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.setDouble(stackTop, value); - return stackTop; - } - - private int generalizeBinarySubscrSeq(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, QuickeningGeneralizeException e) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (e == BinarySubscrSeq.GENERALIZE_RESULT) { - return generalizeBinarySubscrSeqResult(virtualFrame, stackTop, bci, localNodes); - } else { - return generalizeBinarySubscr(virtualFrame, stackTop, bci, localNodes); - } - } - - private int generalizeBinarySubscrSeqResult(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_SEQ_I_O; - return bytecodeBinarySubscrOO(virtualFrame, stackTop, bci, localNodes, bcioffset); - } - - private int generalizeBinarySubscr(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - bytecode[bci] = OpCodesConstants.BINARY_SUBSCR_O_O; - return bytecodeBinarySubscrOO(virtualFrame, stackTop, bci, localNodes, bcioffset); - } - - private TracingNodes getTracingNodes() { - if (tracingNodes == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - tracingNodes = insert(new TracingNodes(bytecode.length)); - } - return tracingNodes; - } - - private void enterTraceProfile(int bci, byte profileBits) { - byte[] profile = getTracingNodes().traceProfileData; - if ((profile[bci] & profileBits) == 0) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - profile[bci] |= profileBits; - } - } - - private PFrame ensurePyFrame(VirtualFrame virtualFrame, int bci) { - PFrame pyFrame = PArguments.getCurrentFrameInfo(virtualFrame).getPyFrame(); - if (pyFrame == null) { - enterTraceProfile(bci, TRACE_PROFILE_NEW_FRAME); - return getTracingNodes().traceMaterializeFrameNewNode.executeOnStack(virtualFrame, this, true, false); - } else { - enterTraceProfile(bci, TRACE_PROFILE_EXISTING_FRAME); - return getTracingNodes().traceMaterializeFrameExistingNode.executeOnStack(virtualFrame, this, true, false); - } - } - - @InliningCutoff - private void invokeTraceFunction(VirtualFrame virtualFrame, Object arg, PythonContext.PythonThreadState threadState, MutableLoopData mutableData, - PythonContext.TraceEvent event, int line, boolean useLocalFn, int bci) { - if (threadState.isTracing()) { - return; - } - assert event != PythonContext.TraceEvent.DISABLED; - threadState.tracingStart(event); - PFrame pyFrame = mutableData.setPyFrame(ensurePyFrame(virtualFrame, bci)); - Object traceFn = useLocalFn ? pyFrame.getLocalTraceFun() : threadState.getTraceFun(); - - if (traceFn == null) { - threadState.tracingStop(); - return; - } - - pyFrame.setLocalsAccessed(false); - Object nonNullArg = arg == null ? PNone.NONE : arg; - try { - if (line != -1) { - pyFrame.setLineLock(line); - } - Object result = getTracingNodes().tracingCallNode.execute(virtualFrame, traceFn, pyFrame, event.pythonName, nonNullArg); - syncLocalsBackToFrame(virtualFrame, pyFrame, bci); - // https://github.com/python/cpython/issues/104232 - if (useLocalFn) { - Object realResult = result == PNone.NONE ? traceFn : result; - pyFrame.setLocalTraceFun(realResult); - } else if (result != PNone.NONE) { - pyFrame.setLocalTraceFun(result); - } else { - pyFrame.setLocalTraceFun(null); - } - } catch (Throwable e) { - threadState.setTraceFun(null, null, getLanguage()); - throw e; - } finally { - if (line != -1) { - pyFrame.lineUnlock(); - } - threadState.tracingStop(); - } - } - - public Frame getLocalFrame(VirtualFrame frame) { - if (co.isGeneratorOrCoroutine()) { - return PGenerator.getGeneratorFrame(frame); - } else { - return frame; - } - } - - private void syncLocalsBackToFrame(VirtualFrame virtualFrame, PFrame pyFrame, int bci) { - Frame localFrame = getLocalFrame(virtualFrame); - if (pyFrame.localsAccessed()) { - enterTraceProfile(bci, TRACE_PROFILE_SYNC_LOCALS_BACK); - GetFrameLocalsNode.syncLocalsBackToFrame(co, pyFrame, localFrame); - } - } - - private void profileCEvent(VirtualFrame virtualFrame, Object callable, PythonContext.ProfileEvent event, MutableLoopData mutableData, byte tracingOrProfilingEnabled, int bci) { - if (isProfilingEnabled(tracingOrProfilingEnabled)) { - profileCEvent(virtualFrame, callable, event, mutableData, bci); - } - } - - @InliningCutoff - private void profileCEvent(VirtualFrame virtualFrame, Object callable, PythonContext.ProfileEvent event, MutableLoopData mutableData, int bci) { - PythonContext.PythonThreadState threadState = mutableData.getThreadState(this); - if (isBuiltin(callable)) { - invokeProfileFunction(virtualFrame, callable, threadState, mutableData, event, bci); - } else if (callable instanceof BoundDescriptor && isBuiltin(((BoundDescriptor) callable).descriptor)) { - invokeProfileFunction(virtualFrame, ((BoundDescriptor) callable).descriptor, threadState, mutableData, event, bci); - } - } - - private static boolean isBuiltin(Object fun) { - return fun instanceof PBuiltinFunction || fun instanceof PBuiltinMethod; - } - - @InliningCutoff - private void invokeProfileFunction(VirtualFrame virtualFrame, Object arg, PythonContext.PythonThreadState threadState, MutableLoopData mutableData, PythonContext.ProfileEvent event, int bci) { - if (threadState.isProfiling()) { - return; - } - - threadState.profilingStart(); - PFrame pyFrame = mutableData.setPyFrame(ensurePyFrame(virtualFrame, bci)); - Object profileFun = threadState.getProfileFun(); - - if (profileFun == null) { - threadState.profilingStop(); - return; - } - - pyFrame.setLocalsAccessed(false); - try { - Object result = getTracingNodes().profilingCallNode.execute(virtualFrame, profileFun, pyFrame, event.name, arg == null ? PNone.NONE : arg); - syncLocalsBackToFrame(virtualFrame, pyFrame, bci); - Object realResult = result == PNone.NONE ? null : result; - pyFrame.setLocalTraceFun(realResult); - } catch (Throwable e) { - threadState.setProfileFun(null, null, getLanguage()); - throw e; - } finally { - threadState.profilingStop(); - } - } - - @ExplodeLoop - private void unboxVariables(Frame localFrame) { - /* - * We keep some variables boxed in the interpreter, but unbox in the compiled code. When OSR - * is entered, we need to unbox existing variables for the compiled code. Should have no - * effect otherwise. - */ - for (int i = 0; i < variableTypes.length; i++) { - if (variableTypes[i] != 0 && variableTypes[i] != QuickeningTypes.OBJECT && localFrame.isObject(i)) { - Object value = localFrame.getObject(i); - if (value != null) { - if (variableTypes[i] == QuickeningTypes.INT) { - localFrame.setInt(i, (int) value); - } else if (variableTypes[i] == QuickeningTypes.BOOLEAN) { - localFrame.setBoolean(i, (boolean) value); - } - } - } - } - } - - @InliningCutoff - private void prepareForReraise(VirtualFrame virtualFrame, Frame localFrame, int initialStackTop, boolean isGeneratorOrCoroutine, MutableLoopData mutableData, int bciSlot, - int beginBci, byte tracingOrProfilingEnabled, int bci) { - // For tracebacks - setCurrentBci(virtualFrame, bciSlot, beginBci); - if (isGeneratorOrCoroutine) { - if (localFrame != virtualFrame) { - // Unwind the generator frame stack - clearFrameSlots(localFrame, stackoffset, initialStackTop); - } - } - if (CompilerDirectives.hasNextTier() && mutableData.loopCount > 0) { - LoopNode.reportLoopCount(this, mutableData.loopCount); - } - traceOrProfileReturn(virtualFrame, mutableData, PNone.NONE, tracingOrProfilingEnabled, bci); - } - - @InliningCutoff - private void chainPythonExceptions(VirtualFrame virtualFrame, MutableLoopData mutableData, AbstractTruffleException exception) { - if (exception instanceof PException pe) { - if (mutableData.localException instanceof PException pe2) { - chainPythonExceptions(pe, pe2); - } else { - if (getCaughtExceptionNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - getCaughtExceptionNode = insert(ExceptionStateNodes.GetCaughtExceptionNode.create()); - } - AbstractTruffleException exceptionState = getCaughtExceptionNode.execute(virtualFrame); - if (exceptionState instanceof PException pe2) { - chainPythonExceptions(pe, pe2); - } - } - } - } - - private void chainPythonExceptions(PException current, PException context) { - if (current.isReraised()) { - return; - } - if (chainExceptionsNode == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - chainExceptionsNode = insert(ChainExceptionsNode.create()); - } - chainExceptionsNode.execute(current, context); - } - - private PException raiseUnknownBytecodeError(byte bc) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - TruffleString format = toTruffleStringUncached("not implemented bytecode %s"); - throw PRaiseNode.raiseStatic(this, SystemError, format, OpCodes.fromOpCode(bc)); - } - - private static void clearInCompiledCode(VirtualFrame virtualFrame, int stackTop) { - if (CompilerDirectives.inCompiledCode()) { - virtualFrame.clear(stackTop); - } - } - - private void generalizeForIterI(int bci, QuickeningGeneralizeException e) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (e.type == QuickeningTypes.OBJECT) { - bytecode[bci] = OpCodesConstants.FOR_ITER_O; - } else { - throw CompilerDirectives.shouldNotReachHere("invalid type"); - } - } - - private void generalizePopAndJumpIfTrueB(int bci) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeInputs(bci); - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_TRUE_O; - } - - private void generalizePopAndJumpIfFalseB(int bci) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeInputs(bci); - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_FALSE_O; - } - - private static void setCurrentBci(VirtualFrame virtualFrame, int bciSlot, int bci) { - virtualFrame.setInt(bciSlot, bci); - } - - @BytecodeInterpreterSwitch - private boolean bytecodePopCondition(VirtualFrame virtualFrame, int stackTop, Node[] localNodes, int bci, boolean useCachedNodes) { - PyObjectIsTrueNode isTrue = insertChildNode(localNodes, bci, UNCACHED_OBJECT_IS_TRUE, PyObjectIsTrueNodeGen.class, NODE_OBJECT_IS_TRUE, useCachedNodes); - Object cond; - if (virtualFrame.isObject(stackTop)) { - cond = virtualFrame.getObject(stackTop); - } else { - // Can happen when multiple code paths produce different types - cond = generalizePopCondition(virtualFrame, stackTop, bci); - } - virtualFrame.clear(stackTop); - return isTrue.execute(virtualFrame, cond); - } - - private Object generalizePopCondition(VirtualFrame virtualFrame, int stackTop, int bci) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeInputs(bci); - return virtualFrame.getValue(stackTop); - } - - private void bytecodeBinaryOpAdaptiveInputOutput(VirtualFrame virtualFrame, int stackTop, byte[] localBC, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isObject(stackTop) && virtualFrame.isObject(stackTop - 1)) { - localBC[bci] = OpCodesConstants.BINARY_OP_OO_O; - bytecodeBinaryOpOOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - return; - } else if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - case BinaryOpsConstants.FLOORDIV: - case BinaryOpsConstants.INPLACE_FLOORDIV: - case BinaryOpsConstants.MOD: - case BinaryOpsConstants.INPLACE_MOD: - case BinaryOpsConstants.LSHIFT: - case BinaryOpsConstants.INPLACE_LSHIFT: - case BinaryOpsConstants.RSHIFT: - case BinaryOpsConstants.INPLACE_RSHIFT: - case BinaryOpsConstants.AND: - case BinaryOpsConstants.INPLACE_AND: - case BinaryOpsConstants.OR: - case BinaryOpsConstants.INPLACE_OR: - case BinaryOpsConstants.XOR: - case BinaryOpsConstants.INPLACE_XOR: - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - localBC[bci] = OpCodesConstants.BINARY_OP_II_I; - bytecodeBinaryOpIII(virtualFrame, stackTop, bci, localNodes, op, useCachedNodes); - return; - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - // TODO truediv should quicken to BINARY_OP_II_D - localBC[bci] = OpCodesConstants.BINARY_OP_II_O; - bytecodeBinaryOpIIO(virtualFrame, stackTop, bci, localNodes, op); - return; - case BinaryOpsConstants.EQ: - case BinaryOpsConstants.NE: - case BinaryOpsConstants.GT: - case BinaryOpsConstants.GE: - case BinaryOpsConstants.LE: - case BinaryOpsConstants.LT: - case BinaryOpsConstants.IS: - localBC[bci] = OpCodesConstants.BINARY_OP_II_B; - bytecodeBinaryOpIIB(virtualFrame, stackTop, bci, localNodes, op); - return; - } - } else if (virtualFrame.isDouble(stackTop) && virtualFrame.isDouble(stackTop - 1)) { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - localBC[bci] = OpCodesConstants.BINARY_OP_DD_D; - bytecodeBinaryOpDDD(virtualFrame, stackTop, bci, localNodes, op, useCachedNodes); - return; - case BinaryOpsConstants.EQ: - case BinaryOpsConstants.NE: - case BinaryOpsConstants.GT: - case BinaryOpsConstants.GE: - case BinaryOpsConstants.LE: - case BinaryOpsConstants.LT: - localBC[bci] = OpCodesConstants.BINARY_OP_DD_B; - bytecodeBinaryOpDDB(virtualFrame, stackTop, bci, localNodes, op); - return; - } - } - // TODO other types - generalizeFrameSlot(virtualFrame, stackTop); - generalizeFrameSlot(virtualFrame, stackTop - 1); - generalizeInputs(bci); - localBC[bci] = OpCodesConstants.BINARY_OP_OO_O; - bytecodeBinaryOpOOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - private void bytecodeBinaryOpAdaptiveInputOnly(VirtualFrame virtualFrame, int stackTop, byte[] localBC, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isObject(stackTop) && virtualFrame.isObject(stackTop - 1)) { - localBC[bci] = OpCodesConstants.BINARY_OP_OO_O; - bytecodeBinaryOpOOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - return; - } else if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - case BinaryOpsConstants.FLOORDIV: - case BinaryOpsConstants.INPLACE_FLOORDIV: - case BinaryOpsConstants.MOD: - case BinaryOpsConstants.INPLACE_MOD: - case BinaryOpsConstants.LSHIFT: - case BinaryOpsConstants.INPLACE_LSHIFT: - case BinaryOpsConstants.RSHIFT: - case BinaryOpsConstants.INPLACE_RSHIFT: - case BinaryOpsConstants.AND: - case BinaryOpsConstants.INPLACE_AND: - case BinaryOpsConstants.OR: - case BinaryOpsConstants.INPLACE_OR: - case BinaryOpsConstants.XOR: - case BinaryOpsConstants.INPLACE_XOR: - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - case BinaryOpsConstants.EQ: - case BinaryOpsConstants.NE: - case BinaryOpsConstants.GT: - case BinaryOpsConstants.GE: - case BinaryOpsConstants.LE: - case BinaryOpsConstants.LT: - case BinaryOpsConstants.IS: - localBC[bci] = OpCodesConstants.BINARY_OP_II_O; - bytecodeBinaryOpIIO(virtualFrame, stackTop, bci, localNodes, op); - return; - } - } else if (virtualFrame.isDouble(stackTop) && virtualFrame.isDouble(stackTop - 1)) { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - case BinaryOpsConstants.EQ: - case BinaryOpsConstants.NE: - case BinaryOpsConstants.GT: - case BinaryOpsConstants.GE: - case BinaryOpsConstants.LE: - case BinaryOpsConstants.LT: - localBC[bci] = OpCodesConstants.BINARY_OP_DD_O; - bytecodeBinaryOpDDO(virtualFrame, stackTop, bci, localNodes, op, useCachedNodes); - return; - } - } - // TODO other types - generalizeFrameSlot(virtualFrame, stackTop); - generalizeFrameSlot(virtualFrame, stackTop - 1); - generalizeInputs(bci); - localBC[bci] = OpCodesConstants.BINARY_OP_OO_O; - bytecodeBinaryOpOOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpIIB(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - int right, left; - if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - right = virtualFrame.getInt(stackTop); - left = virtualFrame.getInt(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - boolean result; - switch (op) { - case BinaryOpsConstants.EQ: - case BinaryOpsConstants.IS: - result = left == right; - break; - case BinaryOpsConstants.NE: - result = left != right; - break; - case BinaryOpsConstants.LT: - result = left < right; - break; - case BinaryOpsConstants.LE: - result = left <= right; - break; - case BinaryOpsConstants.GT: - result = left > right; - break; - case BinaryOpsConstants.GE: - result = left >= right; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_II_B"); - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setBoolean(stackTop - 1, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpIIO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - int right, left; - if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - right = virtualFrame.getInt(stackTop); - left = virtualFrame.getInt(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - Object result; - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - IntBuiltins.AddNode addNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.AddNodeFactory.AddNodeGen.class, NODE_INT_ADD); - result = addNode.execute(left, right); - break; - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - IntBuiltins.SubNode subNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.SubNodeFactory.SubNodeGen.class, NODE_INT_SUB); - result = subNode.execute(left, right); - break; - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - IntBuiltins.MulNode mulNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.MulNodeFactory.MulNodeGen.class, NODE_INT_MUL); - result = mulNode.execute(left, right); - break; - case BinaryOpsConstants.FLOORDIV: - case BinaryOpsConstants.INPLACE_FLOORDIV: - IntBuiltins.FloorDivNode floorDivNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.FloorDivNodeFactory.FloorDivNodeGen.class, NODE_INT_FLOORDIV); - result = floorDivNode.execute(left, right); - break; - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - IntBuiltins.TrueDivNode trueDivNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.TrueDivNodeFactory.TrueDivNodeGen.class, NODE_INT_TRUEDIV); - result = trueDivNode.execute(left, right); - break; - case BinaryOpsConstants.MOD: - case BinaryOpsConstants.INPLACE_MOD: - IntBuiltins.ModNode modNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.ModNodeFactory.ModNodeGen.class, NODE_INT_MOD); - result = modNode.execute(left, right); - break; - case BinaryOpsConstants.LSHIFT: - case BinaryOpsConstants.INPLACE_LSHIFT: - IntBuiltins.LShiftNode lShiftNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.LShiftNodeFactory.LShiftNodeGen.class, NODE_INT_LSHIFT); - result = lShiftNode.execute(left, right); - break; - case BinaryOpsConstants.RSHIFT: - case BinaryOpsConstants.INPLACE_RSHIFT: - IntBuiltins.RShiftNode rShiftNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.RShiftNodeFactory.RShiftNodeGen.class, NODE_INT_RSHIFT); - result = rShiftNode.execute(left, right); - break; - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - IntBuiltins.PowNode powNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.PowNodeFactory.PowNodeGen.class, NODE_INT_POW); - result = powNode.execute(left, right); - break; - case BinaryOpsConstants.AND: - case BinaryOpsConstants.INPLACE_AND: - result = left & right; - break; - case BinaryOpsConstants.OR: - case BinaryOpsConstants.INPLACE_OR: - result = left | right; - break; - case BinaryOpsConstants.XOR: - case BinaryOpsConstants.INPLACE_XOR: - result = left ^ right; - break; - case BinaryOpsConstants.IS: - case BinaryOpsConstants.EQ: - result = left == right; - break; - case BinaryOpsConstants.NE: - result = left != right; - break; - case BinaryOpsConstants.LT: - result = left < right; - break; - case BinaryOpsConstants.LE: - result = left <= right; - break; - case BinaryOpsConstants.GT: - result = left > right; - break; - case BinaryOpsConstants.GE: - result = left >= right; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_II_O"); - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setObject(stackTop - 1, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpIII(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - int right, left, result; - if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - right = virtualFrame.getInt(stackTop); - left = virtualFrame.getInt(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - try { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - try { - result = Math.addExact(left, right); - } catch (ArithmeticException e) { - generalizeBinaryOpIIIOverflow(virtualFrame, stackTop, bci, localNodes, op); - return; - } - break; - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - try { - result = Math.subtractExact(left, right); - } catch (ArithmeticException e) { - generalizeBinaryOpIIIOverflow(virtualFrame, stackTop, bci, localNodes, op); - return; - } - break; - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - try { - result = Math.multiplyExact(left, right); - } catch (ArithmeticException e) { - generalizeBinaryOpIIIOverflow(virtualFrame, stackTop, bci, localNodes, op); - return; - } - break; - case BinaryOpsConstants.FLOORDIV: - case BinaryOpsConstants.INPLACE_FLOORDIV: - if (left == Integer.MIN_VALUE && right == -1) { - generalizeBinaryOpIIIOverflow(virtualFrame, stackTop, bci, localNodes, op); - return; - } - if (right == 0) { - raiseDivOrModByZero(bci, localNodes, useCachedNodes); - } - result = Math.floorDiv(left, right); - break; - case BinaryOpsConstants.MOD: - case BinaryOpsConstants.INPLACE_MOD: - IntBuiltins.ModNode modNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.ModNodeFactory.ModNodeGen.class, NODE_INT_MOD); - result = modNode.executeInt(left, right); - break; - case BinaryOpsConstants.LSHIFT: - case BinaryOpsConstants.INPLACE_LSHIFT: - IntBuiltins.LShiftNode lShiftNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.LShiftNodeFactory.LShiftNodeGen.class, NODE_INT_LSHIFT); - result = lShiftNode.executeInt(left, right); - break; - case BinaryOpsConstants.RSHIFT: - case BinaryOpsConstants.INPLACE_RSHIFT: - IntBuiltins.RShiftNode rShiftNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.RShiftNodeFactory.RShiftNodeGen.class, NODE_INT_RSHIFT); - result = rShiftNode.executeInt(left, right); - break; - case BinaryOpsConstants.AND: - case BinaryOpsConstants.INPLACE_AND: - result = left & right; - break; - case BinaryOpsConstants.OR: - case BinaryOpsConstants.INPLACE_OR: - result = left | right; - break; - case BinaryOpsConstants.XOR: - case BinaryOpsConstants.INPLACE_XOR: - result = left ^ right; - break; - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - IntBuiltins.PowNode powNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.PowNodeFactory.PowNodeGen.class, NODE_INT_POW); - result = powNode.executeInt(left, right); - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_II_I"); - } - } catch (UnexpectedResultException e) { - generalizeBinaryOpIIIOverflow(virtualFrame, stackTop, bci, localNodes, op); - return; - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setInt(stackTop - 1, result); - } - - @InliningCutoff - private void raiseDivOrModByZero(int bci, Node[] localNodes, boolean useCachedNodes) { - PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes); - throw raiseNode.raise(ZeroDivisionError, ErrorMessages.S_DIVISION_OR_MODULO_BY_ZERO, "integer"); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpDDD(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - double right, left, result; - if (virtualFrame.isDouble(stackTop) && virtualFrame.isDouble(stackTop - 1)) { - right = virtualFrame.getDouble(stackTop); - left = virtualFrame.getDouble(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - try { - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - result = left + right; - break; - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - result = left - right; - break; - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - result = left * right; - break; - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - if (right == 0.0) { - raiseDivByZero(bci, localNodes, useCachedNodes); - } - result = left / right; - break; - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - FloatBuiltins.PowNode powNode = insertChildNode(localNodes, bci, FloatBuiltinsFactory.PowNodeFactory.PowNodeGen.class, NODE_FLOAT_POW); - result = powNode.executeDouble(left, right); - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_DD_D"); - } - } catch (UnexpectedResultException e) { - generalizeBinaryOpDDDOverflow(virtualFrame, stackTop, bci, localNodes, op, useCachedNodes); - return; - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setDouble(stackTop - 1, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpDDB(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - double right, left; - if (virtualFrame.isDouble(stackTop) && virtualFrame.isDouble(stackTop - 1)) { - right = virtualFrame.getDouble(stackTop); - left = virtualFrame.getDouble(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - boolean result; - switch (op) { - case BinaryOpsConstants.EQ: - result = left == right; - break; - case BinaryOpsConstants.NE: - result = left != right; - break; - case BinaryOpsConstants.LT: - result = left < right; - break; - case BinaryOpsConstants.LE: - result = left <= right; - break; - case BinaryOpsConstants.GT: - result = left > right; - break; - case BinaryOpsConstants.GE: - result = left >= right; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_DD_B"); - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setBoolean(stackTop - 1, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpDDO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - int right, left; - if (virtualFrame.isInt(stackTop) && virtualFrame.isInt(stackTop - 1)) { - right = virtualFrame.getInt(stackTop); - left = virtualFrame.getInt(stackTop - 1); - } else { - generalizeBinaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - Object result; - switch (op) { - case BinaryOpsConstants.ADD: - case BinaryOpsConstants.INPLACE_ADD: - result = left + right; - break; - case BinaryOpsConstants.SUB: - case BinaryOpsConstants.INPLACE_SUB: - result = left - right; - break; - case BinaryOpsConstants.MUL: - case BinaryOpsConstants.INPLACE_MUL: - result = left * right; - break; - case BinaryOpsConstants.TRUEDIV: - case BinaryOpsConstants.INPLACE_TRUEDIV: - if (right == 0.0) { - raiseDivByZero(bci, localNodes, useCachedNodes); - } - result = left / right; - break; - case BinaryOpsConstants.POW: - case BinaryOpsConstants.INPLACE_POW: - FloatBuiltins.PowNode powNode = insertChildNode(localNodes, bci, FloatBuiltinsFactory.PowNodeFactory.PowNodeGen.class, NODE_FLOAT_POW); - result = powNode.execute(left, right); - break; - case BinaryOpsConstants.IS: - case BinaryOpsConstants.EQ: - result = left == right; - break; - case BinaryOpsConstants.NE: - result = left != right; - break; - case BinaryOpsConstants.LT: - result = left < right; - break; - case BinaryOpsConstants.LE: - result = left <= right; - break; - case BinaryOpsConstants.GT: - result = left > right; - break; - case BinaryOpsConstants.GE: - result = left >= right; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for BINARY_OP_DD_O"); - } - clearInCompiledCode(virtualFrame, stackTop); - virtualFrame.setObject(stackTop - 1, result); - } - - @InliningCutoff - private void raiseDivByZero(int bci, Node[] localNodes, boolean useCachedNodes) { - PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes); - throw raiseNode.raise(ZeroDivisionError, ErrorMessages.DIVISION_BY_ZERO); - } - - private void generalizeBinaryOp(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeFrameSlot(virtualFrame, stackTop); - generalizeFrameSlot(virtualFrame, stackTop - 1); - generalizeInputs(bci); - bytecode[bci] = OpCodesConstants.BINARY_OP_OO_O; - bytecodeBinaryOpOOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - private void generalizeBinaryOpIIIOverflow(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - bytecode[bci] = OpCodesConstants.BINARY_OP_II_O; - bytecodeBinaryOpIIO(virtualFrame, stackTop, bci, localNodes, op); - } - - private void generalizeBinaryOpDDDOverflow(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, boolean useCachedNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - bytecode[bci] = OpCodesConstants.BINARY_OP_DD_O; - bytecodeBinaryOpDDO(virtualFrame, stackTop, bci, localNodes, op, useCachedNodes); - } - - @BytecodeInterpreterSwitch - private void bytecodeBinaryOpOOO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, int bciSlot) { - setCurrentBci(virtualFrame, bciSlot, bci); - BinaryOp opNode = (BinaryOp) insertChildNodeInt(localNodes, bci, BinaryOp.class, BINARY_OP_FACTORY, op); - Object right, left; - try { - right = virtualFrame.getObject(stackTop); - left = virtualFrame.getObject(stackTop - 1); - } catch (FrameSlotTypeException e) { - right = generalizePopCondition(virtualFrame, stackTop, bci); - left = virtualFrame.getValue(stackTop - 1); - } - virtualFrame.clear(stackTop); - Object result = opNode.execute(virtualFrame, left, right); - virtualFrame.setObject(stackTop - 1, result); - } - - private void bytecodeUnaryOpAdaptiveInputOutput(VirtualFrame virtualFrame, int stackTop, int bci, byte[] localBC, Node[] localNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - int op = Byte.toUnsignedInt(localBC[bci + 1]); - if (virtualFrame.isObject(stackTop)) { - localBC[bci] = OpCodesConstants.UNARY_OP_O_O; - bytecodeUnaryOpOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - return; - } else if (virtualFrame.isInt(stackTop)) { - if (op == UnaryOpsConstants.NOT) { - // TODO UNARY_OP_I_B - localBC[bci] = OpCodesConstants.UNARY_OP_I_O; - bytecodeUnaryOpIO(virtualFrame, stackTop, bci, localNodes, op); - } else { - localBC[bci] = OpCodesConstants.UNARY_OP_I_I; - bytecodeUnaryOpII(virtualFrame, stackTop, bci, localNodes, op); - } - return; - } else if (virtualFrame.isDouble(stackTop)) { - if (op == UnaryOpsConstants.NOT || op == UnaryOpsConstants.INVERT) { - // TODO UNARY_OP_D_B - localBC[bci] = OpCodesConstants.UNARY_OP_D_O; - bytecodeUnaryOpDO(virtualFrame, stackTop, bci, localNodes, op); - } else { - localBC[bci] = OpCodesConstants.UNARY_OP_D_D; - bytecodeUnaryOpDD(virtualFrame, stackTop, bci, localNodes, op); - } - return; - } else if (virtualFrame.isBoolean(stackTop)) { - if (op == UnaryOpsConstants.NOT) { - localBC[bci] = OpCodesConstants.UNARY_OP_B_B; - bytecodeUnaryOpBB(virtualFrame, stackTop, bci, localNodes, op); - return; - } - } - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - localBC[bci] = OpCodesConstants.UNARY_OP_O_O; - bytecodeUnaryOpOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - private void bytecodeUnaryOpAdaptiveInputOnly(VirtualFrame virtualFrame, int stackTop, int bci, byte[] localBC, Node[] localNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - int op = Byte.toUnsignedInt(localBC[bci + 1]); - if (virtualFrame.isObject(stackTop)) { - localBC[bci] = OpCodesConstants.UNARY_OP_O_O; - bytecodeUnaryOpOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - return; - } else if (virtualFrame.isInt(stackTop)) { - localBC[bci] = OpCodesConstants.UNARY_OP_I_O; - bytecodeUnaryOpIO(virtualFrame, stackTop, bci, localNodes, op); - return; - } else if (virtualFrame.isDouble(stackTop)) { - localBC[bci] = OpCodesConstants.UNARY_OP_D_O; - bytecodeUnaryOpIO(virtualFrame, stackTop, bci, localNodes, op); - return; - } else if (virtualFrame.isBoolean(stackTop)) { - if (op == UnaryOpsConstants.NOT) { - localBC[bci] = OpCodesConstants.UNARY_OP_B_O; - bytecodeUnaryOpBO(virtualFrame, stackTop, bci, localNodes, op); - return; - } - } - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - localBC[bci] = OpCodesConstants.UNARY_OP_O_O; - bytecodeUnaryOpOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpII(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - int value; - if (virtualFrame.isInt(stackTop)) { - value = virtualFrame.getInt(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - switch (op) { - case UnaryOpsConstants.POSITIVE: - break; - case UnaryOpsConstants.NEGATIVE: - try { - virtualFrame.setInt(stackTop, Math.negateExact(value)); - } catch (ArithmeticException e) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - bytecode[bci] = OpCodesConstants.UNARY_OP_I_O; - bytecodeUnaryOpIO(virtualFrame, stackTop, bci, localNodes, op); - return; - } - break; - case UnaryOpsConstants.INVERT: - virtualFrame.setInt(stackTop, ~value); - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_I_I"); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpIO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - int value; - if (virtualFrame.isInt(stackTop)) { - value = virtualFrame.getInt(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - Object result; - switch (op) { - case UnaryOpsConstants.NOT: - result = value == 0; - break; - case UnaryOpsConstants.POSITIVE: - result = value; - break; - case UnaryOpsConstants.NEGATIVE: - IntBuiltins.NegNode negNode = insertChildNode(localNodes, bci, IntBuiltinsFactory.NegNodeFactory.NegNodeGen.class, NODE_INT_NEG); - result = negNode.execute(value); - break; - case UnaryOpsConstants.INVERT: - result = ~value; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_I_O"); - } - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpDD(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - double value; - if (virtualFrame.isDouble(stackTop)) { - value = virtualFrame.getDouble(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - switch (op) { - case UnaryOpsConstants.POSITIVE: - break; - case UnaryOpsConstants.NEGATIVE: - virtualFrame.setDouble(stackTop, -value); - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_D_D"); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpDO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - double value; - if (virtualFrame.isDouble(stackTop)) { - value = virtualFrame.getDouble(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - Object result; - switch (op) { - case UnaryOpsConstants.NOT: - result = value == 0; - break; - case UnaryOpsConstants.POSITIVE: - result = value; - break; - case UnaryOpsConstants.NEGATIVE: - result = -value; - break; - default: - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_D_O"); - } - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpBB(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - boolean value; - if (virtualFrame.isBoolean(stackTop)) { - value = virtualFrame.getBoolean(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - if (op == UnaryOpsConstants.NOT) { - virtualFrame.setBoolean(stackTop, !value); - } else { - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_B_B"); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpBO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - boolean value; - if (virtualFrame.isBoolean(stackTop)) { - value = virtualFrame.getBoolean(stackTop); - } else { - generalizeUnaryOp(virtualFrame, stackTop, bci, localNodes, op); - return; - } - if (op == UnaryOpsConstants.NOT) { - virtualFrame.setObject(stackTop, !value); - } else { - throw CompilerDirectives.shouldNotReachHere("Invalid operation for UNARY_OP_B_B"); - } - } - - private void generalizeUnaryOp(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeFrameSlot(virtualFrame, stackTop); - generalizeInputs(bci); - bytecode[bci] = OpCodesConstants.UNARY_OP_O_O; - bytecodeUnaryOpOO(virtualFrame, stackTop, bci, localNodes, op, bcioffset); - } - - @BytecodeInterpreterSwitch - private void bytecodeUnaryOpOO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int op, int bciSlot) { - setCurrentBci(virtualFrame, bciSlot, bci); - UnaryOpNode opNode = insertChildNodeInt(localNodes, bci, UnaryOpNode.class, UNARY_OP_FACTORY, op); - Object value; - try { - value = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeInputs(bci); - value = virtualFrame.getValue(stackTop); - } - Object result = opNode.execute(virtualFrame, value); - virtualFrame.setObject(stackTop, result); - } - - private void bytecodeStoreFastAdaptive(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, byte[] localBC, int index, boolean hasUnboxedLocals) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - byte stackType = stackSlotTypeToTypeId(virtualFrame, stackTop); - byte itemType = stackType; - boolean unboxInIntepreter = (variableShouldUnbox[index] & itemType) != 0; - if (itemType == QuickeningTypes.OBJECT) { - itemType = QuickeningTypes.fromObjectType(virtualFrame.getObject(stackTop)); - } - byte variableType = variableTypes[index]; - if (variableType == 0) { - variableType = itemType; - } else if ((variableType & ~UNBOXED_IN_INTERPRETER) != itemType) { - if (variableType != QuickeningTypes.OBJECT) { - variableTypes[index] = QuickeningTypes.OBJECT; - generalizeVariableStores(index); - } - if (itemType != QuickeningTypes.OBJECT) { - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - } - localBC[bci] = OpCodesConstants.STORE_FAST_O; - bytecodeStoreFastO(virtualFrame, localFrame, stackTop, index); - return; - } - if (itemType == QuickeningTypes.INT) { - if (unboxInIntepreter && stackType == QuickeningTypes.INT) { - localBC[bci] = OpCodesConstants.STORE_FAST_I; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastI(virtualFrame, localFrame, stackTop, bci, index); - } else if (unboxInIntepreter) { - localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_I; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastUnboxI(virtualFrame, localFrame, stackTop, bci, index); - } else { - variableTypes[index] = variableType; - if (stackType == QuickeningTypes.INT) { - virtualFrame.setObject(stackTop, virtualFrame.getInt(stackTop)); - generalizeInputs(bci); - } - localBC[bci] = OpCodesConstants.STORE_FAST_BOXED_I; - bytecodeStoreFastBoxedI(virtualFrame, localFrame, stackTop, bci, index, hasUnboxedLocals); - } - return; - } else if (itemType == QuickeningTypes.LONG) { - if (unboxInIntepreter && stackType == QuickeningTypes.LONG) { - localBC[bci] = OpCodesConstants.STORE_FAST_L; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastL(virtualFrame, localFrame, stackTop, bci, index); - } else if (unboxInIntepreter) { - localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_L; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastUnboxL(virtualFrame, localFrame, stackTop, bci, index); - } else { - variableTypes[index] = variableType; - if (stackType == QuickeningTypes.LONG) { - virtualFrame.setObject(stackTop, virtualFrame.getLong(stackTop)); - generalizeInputs(bci); - } - localBC[bci] = OpCodesConstants.STORE_FAST_BOXED_L; - bytecodeStoreFastBoxedL(virtualFrame, localFrame, stackTop, bci, index, hasUnboxedLocals); - } - return; - } else if (itemType == QuickeningTypes.DOUBLE) { - if (unboxInIntepreter && stackType == QuickeningTypes.DOUBLE) { - localBC[bci] = OpCodesConstants.STORE_FAST_D; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastD(virtualFrame, localFrame, stackTop, bci, index); - } else if (unboxInIntepreter) { - localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_D; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastUnboxD(virtualFrame, localFrame, stackTop, bci, index); - } else { - variableTypes[index] = variableType; - if (stackType == QuickeningTypes.DOUBLE) { - virtualFrame.setObject(stackTop, virtualFrame.getDouble(stackTop)); - generalizeInputs(bci); - } - localBC[bci] = OpCodesConstants.STORE_FAST_BOXED_D; - bytecodeStoreFastBoxedD(virtualFrame, localFrame, stackTop, bci, index, hasUnboxedLocals); - } - return; - } else if (itemType == QuickeningTypes.BOOLEAN) { - if (unboxInIntepreter && stackType == QuickeningTypes.BOOLEAN) { - localBC[bci] = OpCodesConstants.STORE_FAST_B; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastB(virtualFrame, localFrame, stackTop, bci, index); - } else if (unboxInIntepreter) { - localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_B; - variableType |= UNBOXED_IN_INTERPRETER; - variableTypes[index] = variableType; - bytecodeStoreFastUnboxB(virtualFrame, localFrame, stackTop, bci, index); - } else { - variableTypes[index] = variableType; - if (stackType == QuickeningTypes.BOOLEAN) { - virtualFrame.setObject(stackTop, virtualFrame.getBoolean(stackTop)); - generalizeInputs(bci); - } - localBC[bci] = OpCodesConstants.STORE_FAST_BOXED_B; - bytecodeStoreFastBoxedB(virtualFrame, localFrame, stackTop, bci, index, hasUnboxedLocals); - } - return; - } else if (itemType == QuickeningTypes.OBJECT) { - variableTypes[index] = variableType; - localBC[bci] = OpCodesConstants.STORE_FAST_O; - bytecodeStoreFastO(virtualFrame, localFrame, stackTop, index); - return; - } - throw CompilerDirectives.shouldNotReachHere("Unexpected variable type: " + itemType); - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastI(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - if (virtualFrame.isInt(stackTop)) { - localFrame.setInt(index, virtualFrame.getInt(stackTop)); - clearInCompiledCode(virtualFrame, stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastUnboxI(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (object instanceof Integer) { - localFrame.setInt(index, (int) object); - virtualFrame.clear(stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastBoxedI(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, boolean hasUnboxedLocals) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (!(object instanceof Integer)) { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (hasUnboxedLocals) { - localFrame.setInt(index, (int) object); - } else { - localFrame.setObject(index, object); - } - virtualFrame.clear(stackTop); - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastL(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - if (virtualFrame.isLong(stackTop)) { - localFrame.setLong(index, virtualFrame.getLong(stackTop)); - clearInCompiledCode(virtualFrame, stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastUnboxL(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (object instanceof Long) { - localFrame.setLong(index, (long) object); - virtualFrame.clear(stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastBoxedL(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, boolean hasUnboxedLocals) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (!(object instanceof Long)) { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (hasUnboxedLocals) { - localFrame.setLong(index, (long) object); - } else { - localFrame.setObject(index, object); - } - virtualFrame.clear(stackTop); - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastD(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - if (virtualFrame.isDouble(stackTop)) { - localFrame.setDouble(index, virtualFrame.getDouble(stackTop)); - clearInCompiledCode(virtualFrame, stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastUnboxD(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (object instanceof Double) { - localFrame.setDouble(index, (double) object); - virtualFrame.clear(stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastBoxedD(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, boolean hasUnboxedLocals) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (!(object instanceof Double)) { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (hasUnboxedLocals) { - localFrame.setDouble(index, (double) object); - } else { - localFrame.setObject(index, object); - } - virtualFrame.clear(stackTop); - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastB(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - if (virtualFrame.isBoolean(stackTop)) { - localFrame.setBoolean(index, virtualFrame.getBoolean(stackTop)); - clearInCompiledCode(virtualFrame, stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastUnboxB(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (object instanceof Boolean) { - localFrame.setBoolean(index, (boolean) object); - virtualFrame.clear(stackTop); - } else { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastBoxedB(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, boolean hasUnboxedLocals) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (!(object instanceof Boolean)) { - generalizeStoreFast(virtualFrame, localFrame, stackTop, bci, index); - return; - } - if (hasUnboxedLocals) { - localFrame.setBoolean(index, (boolean) object); - } else { - localFrame.setObject(index, object); - } - virtualFrame.clear(stackTop); - } - - private void generalizeStoreFast(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeFrameSlot(localFrame, index); - generalizeInputs(index); - bytecode[bci] = OpCodesConstants.STORE_FAST_O; - generalizeVariableStores(index); - bytecodeStoreFastO(virtualFrame, localFrame, stackTop, index); - } - - @BytecodeInterpreterSwitch - private void bytecodeStoreFastO(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int index) { - Object object; - try { - object = virtualFrame.getObject(stackTop); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context mode - generalizeVariableStores(index); - object = virtualFrame.getValue(stackTop); - } - localFrame.setObject(index, object); - virtualFrame.clear(stackTop); - } - - @InliningCutoff - private void bytecodeLoadFastAdaptiveInputOutput(VirtualFrame virtualFrame, Frame localFrame, int stackTop, byte[] localBC, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (localFrame.isObject(index)) { - loadFastOAdaptive(virtualFrame, localFrame, stackTop, localBC, bci, index, localNodes, hasUnboxedLocals); - } else if (localFrame.isInt(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_I; - bytecodeLoadFastI(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isLong(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_L; - bytecodeLoadFastL(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isDouble(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_D; - bytecodeLoadFastD(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isBoolean(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_B; - bytecodeLoadFastB(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else { - throw CompilerDirectives.shouldNotReachHere("Unimplemented stack item type for LOAD_FAST"); - } - } - - @InliningCutoff - private void bytecodeLoadFastAdaptiveInputOnly(VirtualFrame virtualFrame, Frame localFrame, int stackTop, byte[] localBC, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (localFrame.isObject(index)) { - loadFastOAdaptive(virtualFrame, localFrame, stackTop, localBC, bci, index, localNodes, hasUnboxedLocals); - } else if (localFrame.isInt(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_I_BOX; - bytecodeLoadFastIBox(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isLong(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_L_BOX; - bytecodeLoadFastLBox(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isDouble(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_D_BOX; - bytecodeLoadFastDBox(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else if (localFrame.isBoolean(index)) { - localBC[bci] = OpCodesConstants.LOAD_FAST_B_BOX; - bytecodeLoadFastBBox(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } else { - throw CompilerDirectives.shouldNotReachHere("Unimplemented stack item type for LOAD_FAST"); - } - } - - private void loadFastOAdaptive(VirtualFrame virtualFrame, Frame localFrame, int stackTop, byte[] localBC, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - if (variableTypes[index] == QuickeningTypes.INT) { - localBC[bci] = OpCodesConstants.LOAD_FAST_BOXED_I; - bytecodeLoadFastBoxedI(virtualFrame, localFrame, stackTop, bci, index, localNodes, hasUnboxedLocals); - } else if (variableTypes[index] == QuickeningTypes.BOOLEAN) { - localBC[bci] = OpCodesConstants.LOAD_FAST_BOXED_B; - bytecodeLoadFastBoxedB(virtualFrame, localFrame, stackTop, bci, index, localNodes, hasUnboxedLocals); - } else if (variableTypes[index] == QuickeningTypes.DOUBLE) { - localBC[bci] = OpCodesConstants.LOAD_FAST_BOXED_D; - bytecodeLoadFastBoxedD(virtualFrame, localFrame, stackTop, bci, index, localNodes, hasUnboxedLocals); - } else if (variableTypes[index] == QuickeningTypes.LONG) { - localBC[bci] = OpCodesConstants.LOAD_FAST_BOXED_L; - bytecodeLoadFastBoxedL(virtualFrame, localFrame, stackTop, bci, index, localNodes, hasUnboxedLocals); - } else { - localBC[bci] = OpCodesConstants.LOAD_FAST_O; - bytecodeLoadFastO(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastIBox(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isInt(index)) { - virtualFrame.setObject(stackTop, localFrame.getInt(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastI(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isInt(index)) { - virtualFrame.setInt(stackTop, localFrame.getInt(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - private void bytecodeLoadFastLBox(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isLong(index)) { - virtualFrame.setObject(stackTop, localFrame.getLong(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - private void bytecodeLoadFastL(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isLong(index)) { - virtualFrame.setLong(stackTop, localFrame.getLong(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - private void bytecodeLoadFastDBox(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isDouble(index)) { - virtualFrame.setObject(stackTop, localFrame.getDouble(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - private void bytecodeLoadFastD(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isDouble(index)) { - virtualFrame.setDouble(stackTop, localFrame.getDouble(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastBBox(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isBoolean(index)) { - virtualFrame.setObject(stackTop, localFrame.getBoolean(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastB(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - if (localFrame.isBoolean(index)) { - virtualFrame.setBoolean(stackTop, localFrame.getBoolean(index)); - } else { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - private void generalizeLoadFast(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeVariableStores(index); - generalizeFrameSlot(localFrame, index); - bytecode[bci] = OpCodesConstants.LOAD_FAST_O; - bytecodeLoadFastO(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastO(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes) { - try { - Object value = localFrame.getObject(index); - if (value == null) { - throw raiseVarReferencedBeforeAssignment(localNodes, bci, index); - } - virtualFrame.setObject(stackTop, value); - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastBoxedI(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - try { - if (hasUnboxedLocals) { - virtualFrame.setObject(stackTop, localFrame.getInt(index)); - } else { - Object value = localFrame.getObject(index); - if (!(value instanceof Integer)) { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - return; - } - virtualFrame.setObject(stackTop, value); - } - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastBoxedB(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - try { - if (hasUnboxedLocals) { - virtualFrame.setObject(stackTop, localFrame.getBoolean(index)); - } else { - Object value = localFrame.getObject(index); - if (!(value instanceof Boolean)) { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - return; - } - virtualFrame.setObject(stackTop, value); - } - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastBoxedD(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - try { - if (hasUnboxedLocals) { - virtualFrame.setObject(stackTop, localFrame.getDouble(index)); - } else { - Object value = localFrame.getObject(index); - if (!(value instanceof Double)) { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - return; - } - virtualFrame.setObject(stackTop, value); - } - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadFastBoxedL(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, int index, Node[] localNodes, boolean hasUnboxedLocals) { - try { - if (hasUnboxedLocals) { - virtualFrame.setObject(stackTop, localFrame.getLong(index)); - } else { - Object value = localFrame.getObject(index); - if (!(value instanceof Long)) { - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - return; - } - virtualFrame.setObject(stackTop, value); - } - } catch (FrameSlotTypeException e) { - // This should only happen when quickened concurrently in multi-context - // mode - generalizeLoadFast(virtualFrame, localFrame, stackTop, bci, index, localNodes); - } - } - - @InliningCutoff - private PException raiseVarReferencedBeforeAssignment(Node[] localNodes, int bci, int index) { - PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, PRaiseCachedNodeGen.class, NODE_RAISE); - throw raiseNode.raise(PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, varnames[index]); - } - - private static byte stackSlotTypeToTypeId(VirtualFrame virtualFrame, int stackTop) { - return QuickeningTypes.fromFrameSlotTag(virtualFrame.getTag(stackTop)); - } - - private void generalizeInputs(int beginBci) { - CompilerAsserts.neverPartOfCompilation(); - co.generalizeInputs(beginBci); - } - - /** - * The caller should ensure that the frame slot is assigned the boxed Object value to avoid - * repeated FrameSlotTypeException. This can happen in combination with OSR: if there are - * multiple OSR bytecode loop invocations that have different view on whether the local - * variables are boxed or unboxed in the frame, but they all share the same frame. - */ - private void generalizeVariableStores(int index) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - variableTypes[index] = QuickeningTypes.OBJECT; - if (co.generalizeVarsIndices != null && index + 1 < co.generalizeVarsIndices.length) { - for (int i = co.generalizeVarsIndices[index]; i < co.generalizeVarsIndices[index + 1]; i++) { - int generalizeBci = co.generalizeVarsValues[i]; - /* - * Keep unadapted stores as they are because we don't know how to generalize their - * unadapted inputs. They will adapt to object once executed. - */ - if (bytecode[generalizeBci] != OpCodesConstants.STORE_FAST) { - generalizeInputs(generalizeBci); - bytecode[generalizeBci] = OpCodesConstants.STORE_FAST_O; - } - } - } - } - - @InliningCutoff - private PException wrapJavaExceptionIfApplicable(PythonLanguage language, Throwable e) { - if (e instanceof AbstractTruffleException) { - return null; - } - if (e instanceof ControlFlowException) { - return null; - } - if (language.getEngineOption(PythonOptions.CatchAllExceptions) && (e instanceof Exception || e instanceof AssertionError)) { - return ExceptionUtils.wrapJavaException(e, this, PFactory.createBaseException(language, SystemError, ErrorMessages.M, new Object[]{e})); - } - return ExceptionUtils.wrapJavaExceptionIfApplicable(this, e); - } - - @ExplodeLoop - private void copyStackSlotsToGeneratorFrame(Frame virtualFrame, Frame generatorFrame, int stackTop) { - for (int i = stackoffset; i <= stackTop; i++) { - if (virtualFrame.isObject(i)) { - generatorFrame.setObject(i, virtualFrame.getObject(i)); - } else if (virtualFrame.isInt(i)) { - generatorFrame.setInt(i, virtualFrame.getInt(i)); - } else if (virtualFrame.isLong(i)) { - generatorFrame.setLong(i, virtualFrame.getLong(i)); - } else if (virtualFrame.isDouble(i)) { - generatorFrame.setDouble(i, virtualFrame.getDouble(i)); - } else if (virtualFrame.isBoolean(i)) { - generatorFrame.setBoolean(i, virtualFrame.getBoolean(i)); - } else { - throw CompilerDirectives.shouldNotReachHere("unexpected frame slot type"); - } - } - } - - @ExplodeLoop - private void clearFrameSlots(Frame frame, int start, int end) { - CompilerAsserts.partialEvaluationConstant(start); - CompilerAsserts.partialEvaluationConstant(end); - for (int i = start; i <= end; i++) { - frame.setObject(i, null); - } - } - - @InliningCutoff - private int bytecodeFormatValue(VirtualFrame virtualFrame, int initialStackTop, int bci, Node[] localNodes, int options, boolean useCachedNodes) { - int stackTop = initialStackTop; - int type = options & FormatOptions.FVC_MASK; - Object spec = PNone.NO_VALUE; - if ((options & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC) { - spec = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - } - Object value = virtualFrame.getObject(stackTop); - switch (type) { - case FormatOptions.FVC_STR: - value = insertChildNode(localNodes, bci, UNCACHED_STR, PyObjectStrAsObjectNodeGen.class, NODE_STR, useCachedNodes).executeCached(virtualFrame, value); - break; - case FormatOptions.FVC_REPR: - value = insertChildNode(localNodes, bci, UNCACHED_REPR, PyObjectReprAsObjectNodeGen.class, NODE_REPR, useCachedNodes).executeCached(virtualFrame, value); - break; - case FormatOptions.FVC_ASCII: - value = insertChildNode(localNodes, bci, UNCACHED_ASCII, PyObjectAsciiAsObjectNodeGen.class, NODE_ASCII, useCachedNodes).executeCached(virtualFrame, value); - break; - default: - assert type == FormatOptions.FVC_NONE; - } - PyObjectFormat formatNode = insertChildNode(localNodes, bci + 1, UNCACHED_FORMAT, PyObjectFormatNodeGen.class, NODE_FORMAT, useCachedNodes); - value = formatNode.execute(virtualFrame, value, spec); - virtualFrame.setObject(stackTop, value); - return stackTop; - } - - private void bytecodeDeleteDeref(Frame localFrame, int bci, Node[] localNodes, int oparg, int cachedCelloffset, boolean useCachedNodes) { - PCell cell = (PCell) localFrame.getObject(cachedCelloffset + oparg); - Object value = cell.getRef(); - if (value == null) { - raiseUnboundCell(localNodes, bci, oparg, useCachedNodes); - } - cell.clearRef(); - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreDeref(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int oparg, int cachedCelloffset) { - PCell cell = (PCell) localFrame.getObject(cachedCelloffset + oparg); - Object value = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - cell.setRef(value); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadDeref(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, Node[] localNodes, int oparg, int cachedCelloffset, boolean useCachedNodes) { - PCell cell = (PCell) localFrame.getObject(cachedCelloffset + oparg); - Object value = cell.getRef(); - if (value == null) { - raiseUnboundCell(localNodes, bci, oparg, useCachedNodes); - } - virtualFrame.setObject(++stackTop, value); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadFromDictOrDeref(VirtualFrame virtualFrame, Frame localFrame, int stackTop, int bci, Node[] localNodes, int oparg, int cachedCelloffset, boolean useCachedNodes) { - TruffleString varName; - if (oparg >= cellvars.length) { - varName = freevars[oparg - cellvars.length]; - } else { - varName = cellvars[oparg]; - } - - ReadFromLocalsNode readFromLocals = insertChildNode(localNodes, bci, UNCACHED_READ_FROM_LOCALS, ReadFromLocalsNodeGen.class, NODE_READ_FROM_LOCALS, useCachedNodes); - Object dict = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object value = readFromLocals.executeCached(virtualFrame, dict, varName); - if (value != PNone.NO_VALUE) { - virtualFrame.setObject(++stackTop, value); - return stackTop; - } else { - return bytecodeLoadDeref(virtualFrame, localFrame, stackTop, bci, localNodes, oparg, cachedCelloffset, useCachedNodes); - } - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadFromDictOrGlobals(VirtualFrame virtualFrame, Object globals, int stackTop, int bci, TruffleString localName, Node[] localNodes, boolean useCachedNodes) { - ReadFromDictOrGlobalsNode read = insertChildNode(localNodes, bci, UNCACHED_READ_FROM_DICT_OR_GLOBALS, ReadFromDictOrGlobalsNodeGen.class, NODE_READ_FROM_DICT_OR_GLOBALS, useCachedNodes); - return read.execute(virtualFrame, stackTop, globals, localName); - } - - @BytecodeInterpreterSwitch - private int bytecodeClosureFromStack(VirtualFrame virtualFrame, int stackTop, int oparg) { - PCell[] closure = new PCell[oparg]; - moveFromStack(virtualFrame, stackTop - oparg + 1, stackTop + 1, closure); - stackTop -= oparg - 1; - virtualFrame.setObject(stackTop, closure); - return stackTop; - } - - private AbstractTruffleException popExceptionState(Object[] arguments, Object savedException, AbstractTruffleException outerException) { - AbstractTruffleException localException = null; - if (savedException instanceof AbstractTruffleException) { - localException = (AbstractTruffleException) savedException; - PArguments.setException(arguments, localException); - } else if (savedException == null) { - PArguments.setException(arguments, outerException); - } else { - throw CompilerDirectives.shouldNotReachHere("expected exception on the stack"); - } - return localException; - } - - private AbstractTruffleException bytecodeEndExcHandler(VirtualFrame virtualFrame, int stackTop) { - Object exception = virtualFrame.getObject(stackTop); - if (exception instanceof PException) { - throw ((PException) exception).getExceptionForReraise(frameIsVisibleToPython()); - } else if (exception instanceof AbstractTruffleException) { - throw (AbstractTruffleException) exception; - } else { - throw CompilerDirectives.shouldNotReachHere("Exception not on stack"); - } - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadAttr(VirtualFrame virtualFrame, int stackTop, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - PyObjectGetAttr getAttr = insertChildNode(localNodes, bci, UNCACHED_OBJECT_GET_ATTR, PyObjectGetAttrNodeGen.class, NODE_OBJECT_GET_ATTR, useCachedNodes); - TruffleString varname = localNames[oparg]; - Object owner = virtualFrame.getObject(stackTop); - Object value = getAttr.executeCached(virtualFrame, owner, varname); - virtualFrame.setObject(stackTop, value); - } - - private void bytecodeDeleteFast(Frame localFrame, int bci, Node[] localNodes, int oparg) { - if (localFrame.isObject(oparg)) { - Object value = localFrame.getObject(oparg); - if (value == null) { - throw raiseVarReferencedBeforeAssignment(localNodes, bci, oparg); - } - } else { - generalizeVariableStores(oparg); - } - localFrame.setObject(oparg, null); - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadGlobal(VirtualFrame virtualFrame, Object globals, int stackTop, int bci, TruffleString localName, Node[] localNodes, boolean useCachedNodes) { - ReadGlobalOrBuiltinNode read = insertChildNode(localNodes, bci, UNCACHED_READ_GLOBAL_OR_BUILTIN, ReadGlobalOrBuiltinNodeGen.class, NODE_READ_GLOBAL_OR_BUILTIN, useCachedNodes); - virtualFrame.setObject(++stackTop, read.read(virtualFrame, globals, localName)); - return stackTop; - } - - @InliningCutoff - private void bytecodeDeleteGlobal(VirtualFrame virtualFrame, Object globals, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - TruffleString varname = localNames[oparg]; - DeleteGlobalNode deleteGlobalNode = insertChildNode(localNodes, bci, UNCACHED_DELETE_GLOBAL, DeleteGlobalNodeGen.class, NODE_DELETE_GLOBAL, useCachedNodes); - deleteGlobalNode.executeWithGlobals(virtualFrame, globals, varname); - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreGlobal(VirtualFrame virtualFrame, Object globals, int stackTop, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - TruffleString varname = localNames[oparg]; - WriteGlobalNode writeGlobalNode = insertChildNode(localNodes, bci, UNCACHED_WRITE_GLOBAL, WriteGlobalNodeGen.class, NODE_WRITE_GLOBAL, useCachedNodes); - writeGlobalNode.write(virtualFrame, globals, varname, virtualFrame.getObject(stackTop)); - virtualFrame.clear(stackTop--); - return stackTop; - } - - private int bytecodeDeleteAttr(VirtualFrame virtualFrame, int stackTop, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - PyObjectSetAttr callNode = insertChildNode(localNodes, bci, UNCACHED_OBJECT_SET_ATTR, PyObjectSetAttrNodeGen.class, NODE_OBJECT_SET_ATTR, useCachedNodes); - TruffleString varname = localNames[oparg]; - Object owner = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - callNode.deleteCached(virtualFrame, owner, varname); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreAttr(VirtualFrame virtualFrame, int stackTop, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - PyObjectSetAttr callNode = insertChildNode(localNodes, bci, UNCACHED_OBJECT_SET_ATTR, PyObjectSetAttrNodeGen.class, NODE_OBJECT_SET_ATTR, useCachedNodes); - TruffleString varname = localNames[oparg]; - Object owner = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object value = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - callNode.executeCached(virtualFrame, owner, varname, value); - return stackTop; - } - - private void bytecodeDeleteName(VirtualFrame virtualFrame, Object globals, Object locals, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - // ceval.c: TARGET(DELETE_NAME) - TruffleString varname = localNames[oparg]; - if (locals != null) { - PyObjectDelItem delItemNode = insertChildNode(localNodes, bci, UNCACHED_OBJECT_DEL_ITEM, PyObjectDelItemNodeGen.class, NODE_OBJECT_DEL_ITEM, useCachedNodes); - try { - delItemNode.executeCached(virtualFrame, locals, varname); - } catch (PException e) { - PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes); - throw raiseNode.raise(NameError, ErrorMessages.NAME_NOT_DEFINED, varname); - } - } else { - DeleteGlobalNode deleteGlobalNode = insertChildNode(localNodes, bci + 1, UNCACHED_DELETE_GLOBAL, DeleteGlobalNodeGen.class, NODE_DELETE_GLOBAL, useCachedNodes); - deleteGlobalNode.executeWithGlobals(virtualFrame, globals, varname); - } - } - - private int bytecodeDeleteSubscr(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - PyObjectDelItem delItem = insertChildNode(localNodes, bci, UNCACHED_OBJECT_DEL_ITEM, PyObjectDelItemNodeGen.class, NODE_OBJECT_DEL_ITEM, useCachedNodes); - Object slice = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object container = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - delItem.executeCached(virtualFrame, container, slice); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreSubscrAdaptive(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes, int bciSlot) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isInt(stackTop) && virtualFrame.getObject(stackTop - 1) instanceof PList) { - if (virtualFrame.isInt(stackTop - 2)) { - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_SEQ_IIO; - return bytecodeStoreSubscrSeqIIO(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } else if (virtualFrame.isDouble(stackTop - 2)) { - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_SEQ_IDO; - return bytecodeStoreSubscrSeqIDO(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } else { - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_SEQ_IOO; - return bytecodeStoreSubscrSeqIOO(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - } - if (!virtualFrame.isObject(stackTop) || !virtualFrame.isObject(stackTop - 2)) { - generalizeInputs(bci); - generalizeFrameSlot(virtualFrame, stackTop); - generalizeFrameSlot(virtualFrame, stackTop - 2); - } - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_OOO; - return bytecodeStoreSubscrOOO(virtualFrame, stackTop, bci, localNodes, useCachedNodes, bciSlot); - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreSubscrOOO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes, int bciSlot) { - setCurrentBci(virtualFrame, bciSlot, bci); - PyObjectSetItem setItem = insertChildNode(localNodes, bci, UNCACHED_OBJECT_SET_ITEM, PyObjectSetItemNodeGen.class, NODE_OBJECT_SET_ITEM, useCachedNodes); - try { - Object index = virtualFrame.getObject(stackTop); - Object container = virtualFrame.getObject(stackTop - 1); - Object value = virtualFrame.getObject(stackTop - 2); - setItem.executeCached(virtualFrame, container, index, value); - } catch (FrameSlotTypeException e) { - // Should only happen in multi-context mode - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreSubscrSeqIOO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - if (!virtualFrame.isInt(stackTop)) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - int index = virtualFrame.getInt(stackTop); - Object container, value; - try { - container = virtualFrame.getObject(stackTop - 1); - value = virtualFrame.getObject(stackTop - 2); - } catch (FrameSlotTypeException e) { - // Should only happen in multi-context mode - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - try { - StoreSubscrSeq.ONode setItem = insertChildNode(localNodes, bci, StoreSubscrSeqFactory.ONodeGen.class, NODE_STORE_SUBSCR_SEQ_O); - setItem.execute(container, index, value); - } catch (QuickeningGeneralizeException e) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreSubscrSeqIIO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - if (!virtualFrame.isInt(stackTop - 2)) { - return generalizeStoreSubscrSeq(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - if (!virtualFrame.isInt(stackTop)) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - int index = virtualFrame.getInt(stackTop); - Object container = virtualFrame.getObject(stackTop - 1); - int value = virtualFrame.getInt(stackTop - 2); - try { - StoreSubscrSeq.INode setItem = insertChildNode(localNodes, bci, StoreSubscrSeqFactory.INodeGen.class, NODE_STORE_SUBSCR_SEQ_I); - setItem.execute(container, index, value); - } catch (QuickeningGeneralizeException e) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.clear(stackTop--); - clearInCompiledCode(virtualFrame, stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreSubscrSeqIDO(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - if (!virtualFrame.isInt(stackTop - 2)) { - return generalizeStoreSubscrSeq(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - if (!virtualFrame.isInt(stackTop)) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - int index = virtualFrame.getInt(stackTop); - Object container = virtualFrame.getObject(stackTop - 1); - double value = virtualFrame.getDouble(stackTop - 2); - try { - StoreSubscrSeq.DNode setItem = insertChildNode(localNodes, bci, StoreSubscrSeqFactory.DNodeGen.class, NODE_STORE_SUBSCR_SEQ_D); - setItem.execute(container, index, value); - } catch (QuickeningGeneralizeException e) { - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - clearInCompiledCode(virtualFrame, stackTop--); - virtualFrame.clear(stackTop--); - clearInCompiledCode(virtualFrame, stackTop--); - return stackTop; - } - - private int generalizeStoreSubscrSeq(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isInt(stackTop)) { - generalizeFrameSlot(virtualFrame, stackTop - 2); - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_SEQ_IOO; - return bytecodeStoreSubscrSeqIOO(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - return generalizeStoreSubscr(virtualFrame, stackTop, bci, localNodes, useCachedNodes); - } - - private int generalizeStoreSubscr(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, boolean useCachedNodes) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - generalizeInputs(bci); - bytecode[bci] = OpCodesConstants.STORE_SUBSCR_OOO; - generalizeFrameSlot(virtualFrame, stackTop); - generalizeFrameSlot(virtualFrame, stackTop - 2); - return bytecodeStoreSubscrOOO(virtualFrame, stackTop, bci, localNodes, useCachedNodes, bcioffset); - } - - private void generalizeFrameSlot(Frame frame, int slot) { - if (!frame.isObject(slot)) { - frame.setObject(slot, frame.getValue(slot)); - } - } - - @BytecodeInterpreterSwitch - private int bytecodeBuildSlice(VirtualFrame virtualFrame, int stackTop, int bci, int count, Node[] localNodes, boolean useCachedNodes) { - Object step; - if (count == 3) { - step = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - } else { - assert count == 2; - step = PNone.NONE; - } - Object stop = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object start = virtualFrame.getObject(stackTop); - CreateSliceNode sliceNode = insertChildNode(localNodes, bci, UNCACHED_CREATE_SLICE, CreateSliceNodeGen.class, NODE_CREATE_SLICE, useCachedNodes); - PSlice slice = sliceNode.execute(start, stop, step); - virtualFrame.setObject(stackTop, slice); - return stackTop; - } - - @BytecodeInterpreterSwitch - private void bytecodeLoadConstCollection(VirtualFrame virtualFrame, int stackTop, Object array, int typeAndKind) { - Object result; - SequenceStorage storage; - int kind = CollectionBits.collectionKind(typeAndKind); - assert kind == CollectionBits.KIND_LIST || kind == CollectionBits.KIND_TUPLE; - boolean list = kind == CollectionBits.KIND_LIST; - PythonLanguage language = getLanguage(); - boolean useNativePrimitiveStorage = language.getEngineOption(PythonOptions.UseNativePrimitiveStorageStrategy); - switch (CollectionBits.elementType(typeAndKind)) { - case CollectionBits.ELEMENT_INT: { - var context = PythonContext.get(this); - int[] a = (int[]) array; - if (useNativePrimitiveStorage) { - storage = context.nativeBufferContext.toNativeIntStorage(a); - } else { - if (list) { - a = PythonUtils.arrayCopyOf(a, a.length); - } - storage = new IntSequenceStorage(a); - } - break; - } - case CollectionBits.ELEMENT_LONG: { - long[] a = (long[]) array; - if (list) { - a = PythonUtils.arrayCopyOf(a, a.length); - } - storage = new LongSequenceStorage(a); - break; - } - case CollectionBits.ELEMENT_BOOLEAN: { - boolean[] a = (boolean[]) array; - if (list) { - a = PythonUtils.arrayCopyOf(a, a.length); - } - storage = new BoolSequenceStorage(a); - break; - } - case CollectionBits.ELEMENT_DOUBLE: { - double[] a = (double[]) array; - if (list) { - a = PythonUtils.arrayCopyOf(a, a.length); - } - storage = new DoubleSequenceStorage(a); - break; - } - case CollectionBits.ELEMENT_OBJECT: { - Object[] a = (Object[]) array; - a = PythonUtils.arrayCopyOf(a, a.length); - storage = new ObjectSequenceStorage(a); - break; - } - default: - throw CompilerDirectives.shouldNotReachHere(); - } - if (list) { - result = PFactory.createList(language, storage); - } else { - result = PFactory.createTuple(language, storage); - } - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private int bytecodeCallFunctionKw(VirtualFrame virtualFrame, int initialStackTop, int bci, Node[] localNodes, boolean useCachedNodes, MutableLoopData mutableData, - byte tracingOrProfilingEnabled) { - int stackTop = initialStackTop; - CallNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL, CallNodeGen.class, NODE_CALL, useCachedNodes); - Object callable = virtualFrame.getObject(stackTop - 2); - Object[] args = (Object[]) virtualFrame.getObject(stackTop - 1); - - Object result; - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, callable, args, (PKeyword[]) virtualFrame.getObject(stackTop)); - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop - 2, result); - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCallFunctionVarargs(VirtualFrame virtualFrame, int initialStackTop, int bci, Node[] localNodes, boolean useCachedNodes, MutableLoopData mutableData, - byte tracingOrProfilingEnabled) { - int stackTop = initialStackTop; - CallNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL, CallNodeGen.class, NODE_CALL, useCachedNodes); - Object callable = virtualFrame.getObject(stackTop - 1); - Object[] args = (Object[]) virtualFrame.getObject(stackTop); - - Object result; - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, callable, args, PKeyword.EMPTY_KEYWORDS); - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, callable, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop - 1, result); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCallMethodVarargs(VirtualFrame virtualFrame, int initialStackTop, int bci, Node[] localNodes, boolean useCachedNodes, MutableLoopData mutableData, - byte tracingOrProfilingEnabled) { - int stackTop = initialStackTop; - Object func = virtualFrame.getObject(stackTop - 1); - Object[] args = (Object[]) virtualFrame.getObject(stackTop); - CallNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL, CallNodeGen.class, NODE_CALL, useCachedNodes); - - Object result; - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, args, PKeyword.EMPTY_KEYWORDS); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop - 1, result); - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadName(VirtualFrame virtualFrame, int initialStackTop, int bci, int oparg, Node[] localNodes, TruffleString[] localNames, boolean useCachedNodes) { - int stackTop = initialStackTop; - ReadNameNode readNameNode = insertChildNode(localNodes, bci, UNCACHED_READ_NAME, ReadNameNodeGen.class, NODE_READ_NAME, useCachedNodes); - virtualFrame.setObject(++stackTop, readNameNode.execute(virtualFrame, localNames[oparg])); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCallFunction(VirtualFrame virtualFrame, int stackTop, int bci, int oparg, Node[] localNodes, boolean useCachedNodes, MutableLoopData mutableData, - byte tracingOrProfilingEnabled) { - Object func = virtualFrame.getObject(stackTop - oparg); - Object result; - switch (oparg) { - case 0: { - CallNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL, CallNodeGen.class, NODE_CALL, useCachedNodes); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, PythonUtils.EMPTY_OBJECT_ARRAY, PKeyword.EMPTY_KEYWORDS); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop, result); - break; - } - case 1: { - CallUnaryMethodNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL_UNARY_METHOD, CallUnaryMethodNodeGen.class, NODE_CALL_UNARY_METHOD, useCachedNodes); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.executeObject(virtualFrame, func, virtualFrame.getObject(stackTop)); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, result); - break; - } - case 2: { - CallBinaryMethodNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL_BINARY_METHOD, CallBinaryMethodNodeGen.class, NODE_CALL_BINARY_METHOD, useCachedNodes); - Object arg1 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg0 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.executeObject(virtualFrame, func, arg0, arg1); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop, result); - break; - } - case 3: { - CallTernaryMethodNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL_TERNARY_METHOD, CallTernaryMethodNodeGen.class, NODE_CALL_TERNARY_METHOD, useCachedNodes); - Object arg2 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg1 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg0 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, arg0, arg1, arg2); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop, result); - break; - } - case 4: { - CallQuaternaryMethodNode callNode = insertChildNode(localNodes, bci, UNCACHED_CALL_QUATERNARY_METHOD, CallQuaternaryMethodNodeGen.class, NODE_CALL_QUATERNARY_METHOD, useCachedNodes); - Object arg3 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg2 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg1 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg0 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, arg0, arg1, arg2, arg3); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop, result); - break; - } - } - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCallComprehension(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, MutableLoopData mutableData, byte tracingOrProfilingEnabled) { - PFunction func = (PFunction) virtualFrame.getObject(stackTop - 1); - CallComprehensionNode callNode = insertChildNode(localNodes, bci, CallComprehensionNodeGen.class, NODE_CALL_COMPREHENSION); - - Object result; - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - Object[] arguments = PArguments.create(1); - PArguments.setArgument(arguments, 0, virtualFrame.getObject(stackTop)); - result = callNode.execute(virtualFrame, func, arguments); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, result); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeLoadMethod(VirtualFrame virtualFrame, int stackTop, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - Object rcvr = virtualFrame.getObject(stackTop); - TruffleString methodName = localNames[oparg]; - PyObjectGetMethod getMethodNode = insertChildNode(localNodes, bci, UNCACHED_OBJECT_GET_METHOD, PyObjectGetMethodNodeGen.class, NODE_OBJECT_GET_METHOD, useCachedNodes); - Object func = getMethodNode.executeCached(virtualFrame, rcvr, methodName); - virtualFrame.setObject(++stackTop, func); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeCallMethod(VirtualFrame virtualFrame, int stackTop, int bci, int argcount, Node[] localNodes, boolean useCachedNodes, MutableLoopData mutableData, - byte tracingOrProfilingEnabled) { - Object func = virtualFrame.getObject(stackTop - argcount); - Object rcvr = virtualFrame.getObject(stackTop - argcount - 1); - - Object result; - - switch (argcount) { - case 0: { - CallUnaryMethodNode callNode = insertChildNode(localNodes, bci + 1, UNCACHED_CALL_UNARY_METHOD, CallUnaryMethodNodeGen.class, NODE_CALL_UNARY_METHOD, useCachedNodes); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.executeObject(virtualFrame, func, rcvr); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, result); - break; - } - case 1: { - CallBinaryMethodNode callNode = insertChildNode(localNodes, bci + 1, UNCACHED_CALL_BINARY_METHOD, CallBinaryMethodNodeGen.class, NODE_CALL_BINARY_METHOD, useCachedNodes); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.executeObject(virtualFrame, func, rcvr, virtualFrame.getObject(stackTop)); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, result); - break; - } - case 2: { - CallTernaryMethodNode callNode = insertChildNode(localNodes, bci + 1, UNCACHED_CALL_TERNARY_METHOD, CallTernaryMethodNodeGen.class, NODE_CALL_TERNARY_METHOD, useCachedNodes); - Object arg1 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg0 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, rcvr, arg0, arg1); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - - virtualFrame.setObject(stackTop, result); - - break; - } - case 3: { - CallQuaternaryMethodNode callNode = insertChildNode(localNodes, bci + 1, UNCACHED_CALL_QUATERNARY_METHOD, CallQuaternaryMethodNodeGen.class, NODE_CALL_QUATERNARY_METHOD, - useCachedNodes); - Object arg2 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg1 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - Object arg0 = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - virtualFrame.clear(stackTop--); - - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_CALL, mutableData, tracingOrProfilingEnabled, bci); - try { - result = callNode.execute(virtualFrame, func, rcvr, arg0, arg1, arg2); - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_RETURN, mutableData, tracingOrProfilingEnabled, bci); - } catch (AbstractTruffleException e) { - profileCEvent(virtualFrame, func, PythonContext.ProfileEvent.C_EXCEPTION, mutableData, tracingOrProfilingEnabled, bci); - throw e; - } - virtualFrame.setObject(stackTop, result); - break; - } - } - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeStoreName(VirtualFrame virtualFrame, int initialStackTop, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - int stackTop = initialStackTop; - Object value = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - WriteNameNode writeNameNode = insertChildNode(localNodes, bci, UNCACHED_WRITE_NAME, WriteNameNodeGen.class, NODE_WRITE_NAME, useCachedNodes); - writeNameNode.execute(virtualFrame, localNames[oparg], value); - return stackTop; - } - - @InliningCutoff - private AbstractTruffleException bytecodeRaiseVarargs(VirtualFrame virtualFrame, int stackTop, int bci, int count, Node[] localNodes) { - RaiseNode raiseNode = insertChildNode(localNodes, bci, RaiseNodeGen.class, NODE_RAISENODE); - Object cause; - Object exception; - if (count > 1) { - cause = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - } else { - cause = PNone.NO_VALUE; - } - if (count > 0) { - exception = virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - } else { - exception = PNone.NO_VALUE; - } - raiseNode.execute(virtualFrame, exception, cause, frameIsVisibleToPython()); - throw CompilerDirectives.shouldNotReachHere(); - } - - @InliningCutoff - private void raiseUnboundCell(Node[] localNodes, int bci, int oparg, boolean useCachedNodes) { - PRaiseCachedNode raiseNode = insertChildNode(localNodes, bci, UNCACHED_RAISE, PRaiseCachedNodeGen.class, NODE_RAISE, useCachedNodes); - if (oparg < cellvars.length) { - throw raiseNode.raise(PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, cellvars[oparg]); - } else { - int varIdx = oparg - cellvars.length; - throw raiseNode.raise(PythonBuiltinClassType.NameError, ErrorMessages.UNBOUNDFREEVAR, freevars[varIdx]); - } - } - - @InliningCutoff - private int bytecodeImportName(VirtualFrame virtualFrame, Object globals, int initialStackTop, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - CastToJavaIntExactNode castNode = insertChildNode(localNodes, bci, UNCACHED_CAST_TO_JAVA_INT_EXACT, CastToJavaIntExactNodeGen.class, NODE_CAST_TO_JAVA_INT_EXACT, useCachedNodes); - TruffleString modname = localNames[oparg]; - int stackTop = initialStackTop; - TruffleString[] fromlist = (TruffleString[]) virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - int level = castNode.executeCached(virtualFrame.getObject(stackTop)); - ImportNode importNode = insertChildNode(localNodes, bci + 1, UNCACHED_IMPORT, ImportNodeGen.class, NODE_IMPORT, useCachedNodes); - Object result = importNode.execute(virtualFrame, modname, globals, fromlist, level); - virtualFrame.setObject(stackTop, result); - return stackTop; - } - - @InliningCutoff - private int bytecodeImportFrom(VirtualFrame virtualFrame, int initialStackTop, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - int stackTop = initialStackTop; - TruffleString importName = localNames[oparg]; - Object from = virtualFrame.getObject(stackTop); - ImportFromNode importFromNode = insertChildNode(localNodes, bci, UNCACHED_IMPORT_FROM, ImportFromNodeGen.class, NODE_IMPORT_FROM, useCachedNodes); - Object imported = importFromNode.execute(virtualFrame, from, importName); - virtualFrame.setObject(++stackTop, imported); - return stackTop; - } - - @InliningCutoff - private int bytecodeImportStar(VirtualFrame virtualFrame, int initialStackTop, int bci, int oparg, TruffleString[] localNames, Node[] localNodes, boolean useCachedNodes) { - int stackTop = initialStackTop; - TruffleString importName = localNames[oparg]; - int level = (int) virtualFrame.getObject(stackTop); - virtualFrame.clear(stackTop--); - ImportStarNode importStarNode = insertChildNode(localNodes, bci, UNCACHED_IMPORT_STAR, ImportStarNodeGen.class, NODE_IMPORT_STAR, useCachedNodes); - importStarNode.execute(virtualFrame, importName, level); - return stackTop; - } - - @ExplodeLoop - private void initCellVars(Frame localFrame) { - for (int i = 0; i < cellvars.length; i++) { - initCell(localFrame, i); - } - } - - private void initCell(Frame localFrame, int i) { - PCell cell = new PCell(cellEffectivelyFinalAssumptions[i]); - localFrame.setObject(celloffset + i, cell); - if (cell2arg != null && cell2arg[i] != -1) { - int idx = cell2arg[i]; - if (unboxAllVariables) { - cell.setRef(localFrame.getValue(idx)); - } else { - cell.setRef(localFrame.getObject(idx)); - } - localFrame.setObject(idx, null); - } - } - - @ExplodeLoop - private void initFreeVars(Frame localFrame, Object[] originalArgs) { - if (freevars.length > 0) { - PCell[] closure = PArguments.getFunctionObject(originalArgs).getClosure(); - for (int i = 0; i < freevars.length; i++) { - localFrame.setObject(freeoffset + i, closure[i]); - } - } - } - - @ExplodeLoop - @SuppressWarnings("unchecked") - private static void moveFromStack(VirtualFrame virtualFrame, int start, int stop, T[] target) { - CompilerAsserts.partialEvaluationConstant(start); - CompilerAsserts.partialEvaluationConstant(stop); - for (int j = 0, i = start; i < stop; i++, j++) { - target[j] = (T) virtualFrame.getObject(i); - virtualFrame.clear(i); - } - } - - @GenerateInline(false) - @GenerateUncached - abstract static class ObjHashMapPutNode extends Node { - public abstract void execute(VirtualFrame frame, ObjectHashMap map, Object key, Object value); - - @Specialization - static void doIt(VirtualFrame frame, ObjectHashMap map, Object key, Object value, - @Bind Node inliningTarget, - @Cached PyObjectHashNode hashNode, - @Cached ObjectHashMap.PutNode putNode) { - long hash = hashNode.execute(frame, inliningTarget, key); - putNode.put(frame, inliningTarget, map, key, hash, value); - } - } - - @ExplodeLoop - private static EconomicMapStorage moveFromStackToSetHashMap(VirtualFrame virtualFrame, int start, int stop, ObjHashMapPutNode putNode) { - CompilerAsserts.partialEvaluationConstant(start); - CompilerAsserts.partialEvaluationConstant(stop); - EconomicMapStorage result = EconomicMapStorage.create(stop - start); - for (int i = start; i < stop; i++) { - putNode.execute(virtualFrame, result, virtualFrame.getObject(i), PNone.NONE); - virtualFrame.clear(i); - } - return result; - } - - @ExplodeLoop - private static EconomicMapStorage moveFromStackToDictHashMap(VirtualFrame virtualFrame, int start, int stop, ObjHashMapPutNode putNode) { - CompilerAsserts.partialEvaluationConstant(start); - CompilerAsserts.partialEvaluationConstant(stop); - EconomicMapStorage result = EconomicMapStorage.create((stop - start) / 2); - for (int i = start; i + 1 < stop; i += 2) { - putNode.execute(virtualFrame, result, virtualFrame.getObject(i), virtualFrame.getObject(i + 1)); - virtualFrame.clear(i); - virtualFrame.clear(i + 1); - } - return result; - } - - @BytecodeInterpreterSwitch - private int bytecodeCollectionFromStack(VirtualFrame virtualFrame, int type, int count, int oldStackTop, Node[] localNodes, int nodeIndex, boolean useCachedNodes) { - int stackTop = oldStackTop; - Object res = null; - switch (type) { - case CollectionBits.KIND_LIST: { - ListFromStackNode storageFromStackNode = insertChildNodeInt(localNodes, nodeIndex, ListFromStackNodeGen.class, LIST_FROM_STACK_NODE, count); - SequenceStorage store = storageFromStackNode.execute(virtualFrame, stackTop - count + 1, stackTop + 1); - res = PFactory.createList(getLanguage(), store, storageFromStackNode); - break; - } - case CollectionBits.KIND_TUPLE: { - TupleFromStackNode storageFromStackNode = insertChildNodeInt(localNodes, nodeIndex, TupleFromStackNodeGen.class, TUPLE_FROM_STACK_NODE, count); - SequenceStorage store = storageFromStackNode.execute(virtualFrame, stackTop - count + 1, stackTop + 1); - res = PFactory.createTuple(getLanguage(), store); - break; - } - case CollectionBits.KIND_SET: { - ObjHashMapPutNode putNode = insertChildNode(localNodes, nodeIndex, UNCACHED_OBJ_HASHMAP_PUT, ObjHashMapPutNodeGen.class, NODE_OBJ_HASHMAP_PUT, - useCachedNodes); - EconomicMapStorage storage = moveFromStackToSetHashMap(virtualFrame, stackTop - count + 1, stackTop + 1, putNode); - res = PFactory.createSet(getLanguage(), storage); - break; - } - case CollectionBits.KIND_DICT: { - ObjHashMapPutNode putNode = insertChildNode(localNodes, nodeIndex, UNCACHED_OBJ_HASHMAP_PUT, ObjHashMapPutNodeGen.class, NODE_OBJ_HASHMAP_PUT, - useCachedNodes); - assert count % 2 == 0; - EconomicMapStorage storage = moveFromStackToDictHashMap(virtualFrame, stackTop - count + 1, stackTop + 1, putNode); - res = PFactory.createDict(getLanguage(), storage); - break; - } - case CollectionBits.KIND_KWORDS: { - PKeyword[] kwds = new PKeyword[count]; - moveFromStack(virtualFrame, stackTop - count + 1, stackTop + 1, kwds); - res = kwds; - break; - } - case CollectionBits.KIND_OBJECT: { - Object[] objs = new Object[count]; - moveFromStack(virtualFrame, stackTop - count + 1, stackTop + 1, objs); - res = objs; - break; - } - } - stackTop -= count; - virtualFrame.setObject(++stackTop, res); - return stackTop; - } - - @BytecodeInterpreterSwitch - private void bytecodeCollectionFromCollection(VirtualFrame virtualFrame, int type, int stackTop, Node[] localNodes, int nodeIndex, boolean useCachedNodes) { - Object sourceCollection = virtualFrame.getObject(stackTop); - Object result; - switch (type) { - case CollectionBits.KIND_LIST: { - ListNodes.ConstructListNode constructNode = insertChildNode(localNodes, nodeIndex, UNCACHED_CONSTRUCT_LIST, ListNodesFactory.ConstructListNodeGen.class, NODE_CONSTRUCT_LIST, - useCachedNodes); - result = constructNode.execute(virtualFrame, sourceCollection); - break; - } - case CollectionBits.KIND_TUPLE: { - TupleNodes.ConstructTupleNode constructNode = insertChildNode(localNodes, nodeIndex, UNCACHED_CONSTRUCT_TUPLE, TupleNodesFactory.ConstructTupleNodeGen.class, NODE_CONSTRUCT_TUPLE, - useCachedNodes); - result = constructNode.execute(virtualFrame, sourceCollection); - break; - } - case CollectionBits.KIND_SET: { - SetNodes.ConstructSetNode constructNode = insertChildNode(localNodes, nodeIndex, UNCACHED_CONSTRUCT_SET, SetNodesFactory.ConstructSetNodeGen.class, NODE_CONSTRUCT_SET, useCachedNodes); - result = constructNode.execute(virtualFrame, sourceCollection); - break; - } - case CollectionBits.KIND_DICT: { - // TODO create uncached node - HashingStorage.InitNode initNode = insertChildNode(localNodes, nodeIndex, HashingStorageFactory.InitNodeGen.class, NODE_HASHING_STORAGE_INIT); - HashingStorage storage = initNode.execute(virtualFrame, sourceCollection, PKeyword.EMPTY_KEYWORDS); - result = PFactory.createDict(getLanguage(), storage); - break; - } - case CollectionBits.KIND_OBJECT: { - ExecutePositionalStarargsNode executeStarargsNode = insertChildNode(localNodes, nodeIndex, UNCACHED_EXECUTE_STARARGS, ExecutePositionalStarargsNodeGen.class, NODE_EXECUTE_STARARGS, - useCachedNodes); - result = executeStarargsNode.executeWith(virtualFrame, sourceCollection); - break; - } - case CollectionBits.KIND_KWORDS: { - KeywordsNode keywordsNode = insertChildNode(localNodes, nodeIndex, UNCACHED_KEYWORDS, KeywordsNodeGen.class, NODE_KEYWORDS, useCachedNodes); - result = keywordsNode.execute(virtualFrame, sourceCollection, stackTop); - break; - } - default: - throw CompilerDirectives.shouldNotReachHere("Unexpected collection type"); - } - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private int bytecodeCollectionAddCollection(VirtualFrame virtualFrame, int type, int initialStackTop, Node[] localNodes, int nodeIndex, boolean useCachedNodes) { - int stackTop = initialStackTop; - Object collection1 = virtualFrame.getObject(stackTop - 1); - Object collection2 = virtualFrame.getObject(stackTop); - Object result; - switch (type) { - case CollectionBits.KIND_LIST: { - // TODO uncached node - ListBuiltins.ListExtendNode extendNode = insertChildNode(localNodes, nodeIndex, ListBuiltinsFactory.ListExtendNodeFactory.ListExtendNodeGen.class, NODE_LIST_EXTEND); - extendNode.execute(virtualFrame, (PList) collection1, collection2); - result = collection1; - break; - } - case CollectionBits.KIND_SET: { - SetBuiltins.UpdateSingleNode updateNode = insertChildNode(localNodes, nodeIndex, UNCACHED_SET_UPDATE, SetBuiltinsFactory.UpdateSingleNodeGen.class, NODE_SET_UPDATE, useCachedNodes); - PSet set = (PSet) collection1; - updateNode.execute(virtualFrame, set, collection2); - result = set; - break; - } - case CollectionBits.KIND_DICT: { - // TODO uncached node - DictNodes.UpdateNode updateNode = insertChildNode(localNodes, nodeIndex, DictNodesFactory.UpdateNodeGen.class, NODE_DICT_UPDATE); - updateNode.execute(virtualFrame, (PDict) collection1, collection2); - result = collection1; - break; - } - // Note: we don't allow this operation for tuple - case CollectionBits.KIND_OBJECT: { - Object[] array1 = (Object[]) collection1; - ExecutePositionalStarargsNode executeStarargsNode = insertChildNode(localNodes, nodeIndex, UNCACHED_EXECUTE_STARARGS, ExecutePositionalStarargsNodeGen.class, NODE_EXECUTE_STARARGS, - useCachedNodes); - Object[] array2 = executeStarargsNode.executeWith(virtualFrame, collection2); - Object[] combined = new Object[array1.length + array2.length]; - System.arraycopy(array1, 0, combined, 0, array1.length); - System.arraycopy(array2, 0, combined, array1.length, array2.length); - result = combined; - break; - } - case CollectionBits.KIND_KWORDS: { - PKeyword[] array1 = (PKeyword[]) collection1; - PKeyword[] array2 = (PKeyword[]) collection2; - PKeyword[] combined = new PKeyword[array1.length + array2.length]; - System.arraycopy(array1, 0, combined, 0, array1.length); - System.arraycopy(array2, 0, combined, array1.length, array2.length); - result = combined; - break; - } - default: - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "COLLECTION_ADD_COLLECTION"); - } - virtualFrame.clear(stackTop--); - virtualFrame.setObject(stackTop, result); - return stackTop; - } - - @BytecodeInterpreterSwitch - private int bytecodeAddToCollection(VirtualFrame virtualFrame, int initialStackTop, int nodeIndex, Node[] localNodes, int depth, int type, boolean useCachedNodes) { - int stackTop = initialStackTop; - Object collection = virtualFrame.getObject(stackTop - depth); - Object item = virtualFrame.getObject(stackTop); - switch (type) { - case CollectionBits.KIND_LIST: { - ListNodes.AppendNode appendNode = insertChildNode(localNodes, nodeIndex, UNCACHED_LIST_APPEND, ListNodesFactory.AppendNodeGen.class, NODE_LIST_APPEND, useCachedNodes); - appendNode.execute((PList) collection, item); - break; - } - case CollectionBits.KIND_SET: { - SetNodes.AddNode addNode = insertChildNode(localNodes, nodeIndex, UNCACHED_SET_ADD, SetNodesFactory.AddNodeGen.class, NODE_SET_ADD, useCachedNodes); - addNode.execute(virtualFrame, (PSet) collection, item); - break; - } - case CollectionBits.KIND_DICT: { - Object key = virtualFrame.getObject(stackTop - 1); - HashingCollectionNodes.SetItemNode setItem = insertChildNode(localNodes, nodeIndex, UNCACHED_SET_ITEM, HashingCollectionNodesFactory.SetItemNodeGen.class, NODE_SET_ITEM, - useCachedNodes); - setItem.executeCached(virtualFrame, (PDict) collection, key, item); - virtualFrame.clear(stackTop--); - break; - } - default: - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw PRaiseNode.raiseStatic(this, SystemError, ErrorMessages.INVALID_TYPE_FOR_S, "ADD_TO_COLLECTION"); - } - virtualFrame.clear(stackTop--); - return stackTop; - } - - @BytecodeInterpreterSwitch - private void bytecodeTupleFromList(VirtualFrame virtualFrame, int stackTop) { - PList list = (PList) virtualFrame.getObject(stackTop); - Object result = PFactory.createTuple(getLanguage(), list.getSequenceStorage()); - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private void bytecodeFrozensetFromList(VirtualFrame virtualFrame, int stackTop, int nodeIndex, Node[] localNodes) { - PList list = (PList) virtualFrame.getObject(stackTop); - HashingStorageFromListSequenceStorageNode node = insertChildNode(localNodes, nodeIndex, HashingStorageFromListSequenceStorageNodeGen.class, NODE_HASHING_STORAGE_FROM_SEQUENCE); - Object result = PFactory.createFrozenSet(getLanguage(), node.execute(virtualFrame, list.getSequenceStorage())); - virtualFrame.setObject(stackTop, result); - } - - @BytecodeInterpreterSwitch - private int bytecodeUnpackSequence(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int count, boolean useCachedNodes) { - UnpackSequenceNode unpackNode = insertChildNode(localNodes, bci, UNCACHED_UNPACK_SEQUENCE, UnpackSequenceNodeGen.class, NODE_UNPACK_SEQUENCE, useCachedNodes); - Object collection = virtualFrame.getObject(stackTop); - return unpackNode.execute(virtualFrame, stackTop - 1, collection, count); - } - - @BytecodeInterpreterSwitch - private int bytecodeUnpackEx(VirtualFrame virtualFrame, int stackTop, int bci, Node[] localNodes, int countBefore, int countAfter, boolean useCachedNodes) { - UnpackExNode unpackNode = insertChildNode(localNodes, bci, UNCACHED_UNPACK_EX, UnpackExNodeGen.class, NODE_UNPACK_EX, useCachedNodes); - Object collection = virtualFrame.getObject(stackTop); - return unpackNode.execute(virtualFrame, stackTop - 1, collection, countBefore, countAfter); - } - - @InliningCutoff - @ExplodeLoop - private int findHandler(int bci) { - CompilerAsserts.partialEvaluationConstant(bci); - - for (int i = 0; i < exceptionHandlerRanges.length; i += 4) { - // The ranges are ordered by their start and non-overlapping - if (bci < exceptionHandlerRanges[i]) { - break; - } else if (bci < exceptionHandlerRanges[i + 1]) { - // bci is inside this try-block range. get the target stack size - return i + 2; - } - } - return -1; - } - - @InliningCutoff - @ExplodeLoop - private static int unwindBlock(VirtualFrame virtualFrame, int stackTop, int stackTopBeforeBlock) { - CompilerAsserts.partialEvaluationConstant(stackTop); - CompilerAsserts.partialEvaluationConstant(stackTopBeforeBlock); - for (int i = stackTop; i > stackTopBeforeBlock; i--) { - virtualFrame.clear(i); - } - return stackTopBeforeBlock; - } - - public PCell readClassCell(Frame frame) { - if (classcellIndex < 0) { - return null; - } - return (PCell) frame.getObject(classcellIndex); - } - - public Object readSelf(Frame frame) { - if (selfIndex < 0) { - return null; - } else if (selfIndex == 0) { - return frame.getObject(0); - } else { - PCell selfCell = (PCell) frame.getObject(selfIndex); - return selfCell.getRef(); - } - } - - public int bciToLine(int bci) { - return co.bciToLine(bci); - } - - public int lineToBci(int line) { - return co.lineToBci(line); - } - - public int getFirstLineno() { - return co.startLine; - } - - public boolean frameIsVisibleToPython() { - return !internal; - } - - @Override - public SourceSection getSourceSection() { - if (sourceSection != null) { - return sourceSection; - } else if (!getSourceWithCharacters().hasCharacters()) { - sourceSection = getSourceWithCharacters().createUnavailableSection(); - return sourceSection; - } else { - sourceSection = co.getSourceSection(getSourceWithCharacters()); - return sourceSection; - } - } - - public int bciToLasti(int bci) { - if (bci <= 0) { - return bci; - } - byte[] bytecode = co.code; - int number = 0; - for (int i = 0; i < bytecode.length;) { - if (i >= bci) { - return number; - } - i += OpCodes.fromOpCode(bytecode[i]).length(); - number += 2; - } - return -1; - } - - public int lastiToBci(int lasti) { - int bci = 0; - for (int i = 0; i < lasti && bci < co.code.length; i += 2) { - bci += OpCodes.fromOpCode(co.code[bci]).length(); - } - return bci; - } - - @Override - public boolean isInternal() { - return internal; - } - - @Override - public boolean setsUpCalleeContext() { - return true; - } - - @Override - protected byte[] extractCode(Node node) { - /* - * CPython exposes individual items of code objects, like constants, as different members of - * the code object and the co_code attribute contains just the bytecode. It would be better - * if we did the same, however we currently serialize everything into just co_code and - * ignore the rest. The reasons are: - * - * 1) TruffleLanguage.parsePublic does source level caching but it only accepts bytes or - * Strings. We could cache ourselves instead, but we have to come up with a cache key. It - * would be impractical to compute a cache key from all the deserialized constants, but we - * could just generate a large random number at compile time to serve as a key. - * - * 2) The arguments of code object constructor would be different. Some libraries like - * cloudpickle (used by pyspark) still rely on particular signature, even though CPython has - * changed theirs several times. We would have to match CPython's signature. It's doable, - * but it would certainly be more practical to update to 3.11 first to have an attribute for - * exception ranges. - * - * 3) While the AST interpreter is still in use, we have to share the code in CodeBuiltins, - * so it's much simpler to do it in a way that is close to what the AST interpreter is - * doing. - * - * TODO We should revisit this when the AST interpreter is removed. - */ - return MarshalModuleBuiltins.serializeCodeUnit(null, getLanguage(), co); - } - - @Override - protected boolean isCloneUninitializedSupported() { - return true; - } - - @Override - protected RootNode cloneUninitialized() { - // Note: the bytecode might be quickened already, it's not practical to undo it - PBytecodeRootNode rootNode = new PBytecodeRootNode(getLanguage(), getFrameDescriptor(), getSignature(), co, source, internal, parserCallbacks); - rootNode.variableTypes = variableTypes; - return rootNode; - } - - public void triggerDeferredDeprecationWarnings() { - if (parserCallbacks != null) { - parserCallbacks.triggerDeprecationWarnings(); - } - } - - private void bytecodePopAndJumpIfFalse(VirtualFrame virtualFrame, int bci, int stackTop) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isBoolean(stackTop)) { - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_FALSE_B; - } else { - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_FALSE_O; - } - } - - private void bytecodePopAndJumpIfTrue(VirtualFrame virtualFrame, int bci, int stackTop) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - if (virtualFrame.isBoolean(stackTop)) { - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_TRUE_B; - } else { - bytecode[bci] = OpCodesConstants.POP_AND_JUMP_IF_TRUE_O; - } - } - - public boolean hasSelf() { - return selfIndex >= 0; - } - - @Override - protected boolean prepareForCompilation(boolean rootCompilation, int compilationTier, boolean lastTier) { - unboxAllVariables = true; - return super.prepareForCompilation(rootCompilation, compilationTier, lastTier); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRoot.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRoot.java deleted file mode 100644 index 288dadaa06..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRoot.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import com.oracle.truffle.api.instrumentation.GenerateWrapper; -import com.oracle.truffle.api.instrumentation.ProbeNode; -import com.oracle.truffle.api.instrumentation.StandardTags; -import com.oracle.truffle.api.instrumentation.Tag; - -/** - * Takes care of lazily materializing the instrumentation nodes when requested. Also its wrapper is - * notified of entering and exiting the function. - * - * @see InstrumentationSupport - */ -@GenerateWrapper -public abstract class InstrumentationRoot extends InstrumentedBytecodeNode { - public static InstrumentationRoot create() { - return new InstrumentationRootImpl(); - } - - @Override - public WrapperNode createWrapper(ProbeNode probe) { - return new InstrumentationRootWrapper(this, probe); - } - - @Override - public boolean hasTag(Class tag) { - return tag == StandardTags.RootBodyTag.class || tag == StandardTags.RootTag.class; - } - - public abstract InstrumentationSupport getInstrumentation(); -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRootImpl.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRootImpl.java deleted file mode 100644 index 9f4c734598..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationRootImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import java.util.Set; - -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; -import com.oracle.truffle.api.instrumentation.InstrumentableNode; -import com.oracle.truffle.api.instrumentation.StandardTags; -import com.oracle.truffle.api.instrumentation.Tag; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.source.SourceSection; - -/** - * @see InstrumentationRoot - * @see InstrumentationSupport - */ -class InstrumentationRootImpl extends InstrumentationRoot { - - @Child private volatile InstrumentationSupport instrumentationSupport; - - @Override - public InstrumentableNode materializeInstrumentableNodes(Set> materializedTags) { - if (materializedTags.contains(StandardTags.StatementTag.class)) { - if (instrumentationSupport == null) { - Node node = getParent(); - while (!(node instanceof PBytecodeRootNode)) { - node = node.getParent(); - } - PBytecodeRootNode rootNode = (PBytecodeRootNode) node; - if (rootNode.getSourceWithCharacters().hasCharacters()) { - instrumentationSupport = insert(new InstrumentationSupport(rootNode)); - rootNode.materializeContainedFunctionsForInstrumentation(materializedTags); - notifyInserted(instrumentationSupport); - } - } - } - return this; - } - - @Override - public InstrumentationSupport getInstrumentation() { - return instrumentationSupport; - } - - @Override - public SourceSection getSourceSection() { - return getRootNode().getSourceSection(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java deleted file mode 100644 index aad522f2b4..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentationSupport.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import com.oracle.graal.python.compiler.BytecodeCodeUnit; -import com.oracle.graal.python.compiler.OpCodes; -import com.oracle.graal.python.nodes.BuiltinNames; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrumentation.InstrumentableNode; -import com.oracle.truffle.api.instrumentation.ProbeNode; -import com.oracle.truffle.api.nodes.Node; - -/** - * The bytecode interpreter has no AST nodes therefore Truffle AST instrumentation doesn't directly - * work. We work around that by lazily creating a fake non-executable AST with a list of statement - * nodes. We keep track of line changes in the bytecode loop and notify the probe nodes manually. We - * also insert bytecode helper nodes into the statement nodes so that asking the location of a call - * node obtained from a frame works. - * - * @see InstrumentationRoot - */ -public final class InstrumentationSupport extends Node { - final BytecodeCodeUnit code; - @Children InstrumentedBytecodeStatement[] statements; - /* - * When instrumentation is active, this array is used instead of PBytecodeRootNode#adoptedNodes - * to hold helper nodes. The actual helper nodes are adopted by the statement nodes in - * statements array, so this must not be annotated as @Children. When materializing, we cannot - * reuse existing nodes from adoptedNodes due to possible race conditions. - */ - @CompilationFinal(dimensions = 1) public Node[] bciToHelperNode; - - final int startLine; - - public InstrumentationSupport(PBytecodeRootNode rootNode) { - assert rootNode.getSourceWithCharacters() != null && rootNode.getSourceWithCharacters().hasCharacters(); - code = rootNode.getCodeUnit(); - /* - * TODO GR-40896 this search for min/max line shouldn't be necessary, but the parser doesn't - * provide the correct location for f-strings (may be outside of the range of the function's - * location). - */ - int minLine = code.startLine; - int maxLine = code.endLine; - for (int bci = 0; bci < code.code.length; bci++) { - minLine = Math.min(minLine, code.bciToLine(bci)); - maxLine = Math.max(maxLine, code.bciToLine(bci)); - } - startLine = minLine; - statements = new InstrumentedBytecodeStatement[maxLine - minLine + 1]; - bciToHelperNode = new Node[code.code.length]; - boolean[] loadedBreakpoint = new boolean[1]; - code.iterateBytecode((bci, op, oparg, followingArgs) -> { - boolean setBreakpoint = false; - if ((op == OpCodes.LOAD_NAME || op == OpCodes.LOAD_GLOBAL) && BuiltinNames.T_BREAKPOINT.equals(code.names[oparg])) { - loadedBreakpoint[0] = true; - } else { - if (op == OpCodes.CALL_FUNCTION && loadedBreakpoint[0]) { - setBreakpoint = true; - } - loadedBreakpoint[0] = false; - } - int line = code.bciToLine(bci); - if (line >= 0) { - InstrumentedBytecodeStatement statement = getStatement(line); - if (statement == null) { - statement = InstrumentedBytecodeStatement.create(); - try { - statement.setSourceSection(rootNode.getSourceWithCharacters().createSection(line)); - } catch (IllegalArgumentException e) { - // happens if source file is not available - statement.setSourceSection(rootNode.getSourceWithCharacters().createUnavailableSection()); - } - setStatement(line, statement); - } - statement.coversBci(bci, op.length()); - if (setBreakpoint) { - statement.setContainsBreakpoint(); - } - } - }); - } - - private InstrumentedBytecodeStatement getStatement(int line) { - return statements[getStatementIndex(line)]; - } - - private void setStatement(int line, InstrumentedBytecodeStatement statement) { - statements[getStatementIndex(line)] = statement; - } - - private int getStatementIndex(int line) { - return line - startLine; - } - - private InstrumentableNode.WrapperNode getWrapperAtLine(int line) { - if (line >= 0) { - InstrumentableNode node = getStatement(line); - if (node instanceof InstrumentableNode.WrapperNode) { - return (InstrumentableNode.WrapperNode) node; - } - } - return null; - } - - public void notifyStatement(VirtualFrame frame, int prevLine, int nextLine) { - if (nextLine != prevLine) { - if (prevLine >= 0) { - notifyStatementExit(frame, prevLine); - } - notifyStatementEnter(frame, nextLine); - } - } - - public void notifyStatementEnter(VirtualFrame frame, int line) { - CompilerAsserts.partialEvaluationConstant(line); - InstrumentableNode.WrapperNode wrapper = getWrapperAtLine(line); - if (wrapper != null) { - try { - wrapper.getProbeNode().onEnter(frame); - } catch (Throwable t) { - handleException(frame, wrapper, t, false); - throw t; - } - } - } - - public void notifyStatementExit(VirtualFrame frame, int line) { - CompilerAsserts.partialEvaluationConstant(line); - InstrumentableNode.WrapperNode wrapper = getWrapperAtLine(line); - if (wrapper != null) { - try { - wrapper.getProbeNode().onReturnValue(frame, null); - } catch (Throwable t) { - handleException(frame, wrapper, t, true); - throw t; - } - } - } - - private static void handleException(VirtualFrame frame, InstrumentableNode.WrapperNode wrapper, Throwable t, boolean isReturnCalled) { - Object result = wrapper.getProbeNode().onReturnExceptionalOrUnwind(frame, t, isReturnCalled); - if (result == ProbeNode.UNWIND_ACTION_REENTER) { - throw CompilerDirectives.shouldNotReachHere("Unwind not supported on statement level"); - } else if (result != null) { - throw CompilerDirectives.shouldNotReachHere("Cannot replace a return of a statement"); - } - } - - public void notifyException(VirtualFrame frame, int line, Throwable exception) { - CompilerAsserts.partialEvaluationConstant(line); - InstrumentableNode.WrapperNode wrapper = getWrapperAtLine(line); - if (wrapper != null) { - handleException(frame, wrapper, exception, false); - } - } - - public void insertHelperNode(Node node, int bci) { - int line = code.bciToLine(bci); - getStatement(line).insertHelperNode(node, bci); - bciToHelperNode[bci] = node; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeNode.java deleted file mode 100644 index c62cbab7aa..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeNode.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import com.oracle.graal.python.runtime.interop.PythonScopes; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.instrumentation.InstrumentableNode; -import com.oracle.truffle.api.interop.NodeLibrary; -import com.oracle.truffle.api.library.ExportLibrary; -import com.oracle.truffle.api.library.ExportMessage; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.source.SourceSection; - -@ExportLibrary(NodeLibrary.class) -public abstract class InstrumentedBytecodeNode extends Node implements InstrumentableNode { - @CompilationFinal private SourceSection sourceSection; - - public void execute(@SuppressWarnings("unused") VirtualFrame frame) { - throw CompilerDirectives.shouldNotReachHere("Instrumentation node not executable"); - } - - @Override - public SourceSection getSourceSection() { - return this.sourceSection; - } - - public void setSourceSection(SourceSection source) { - this.sourceSection = source; - } - - @Override - public boolean isInstrumentable() { - return true; - } - - @ExportMessage - boolean hasScope(@SuppressWarnings("unused") Frame frame) { - return true; - } - - @ExportMessage - Object getScope(Frame frame, @SuppressWarnings("unused") boolean nodeEnter) { - return PythonScopes.create(this, frame != null ? frame.materialize() : null); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatement.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatement.java deleted file mode 100644 index bd2206408d..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatement.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import com.oracle.truffle.api.instrumentation.GenerateWrapper; -import com.oracle.truffle.api.instrumentation.ProbeNode; -import com.oracle.truffle.api.nodes.Node; - -@GenerateWrapper -public abstract class InstrumentedBytecodeStatement extends InstrumentedBytecodeNode { - public static InstrumentedBytecodeStatement create() { - return new InstrumentedBytecodeStatementImpl(); - } - - @Override - public WrapperNode createWrapper(ProbeNode probe) { - return new InstrumentedBytecodeStatementWrapper(this, probe); - } - - public abstract void insertHelperNode(Node node, int bci); - - abstract void setContainsBreakpoint(); - - abstract void coversBci(int bci, int length); -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatementImpl.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatementImpl.java deleted file mode 100644 index c622505e99..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/instrumentation/InstrumentedBytecodeStatementImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode.instrumentation; - -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.debug.DebuggerTags; -import com.oracle.truffle.api.instrumentation.StandardTags; -import com.oracle.truffle.api.instrumentation.Tag; -import com.oracle.truffle.api.nodes.Node; - -class InstrumentedBytecodeStatementImpl extends InstrumentedBytecodeStatement { - @CompilationFinal private boolean containsBreakpoint; - @CompilationFinal private int minBci = Integer.MAX_VALUE; - @CompilationFinal private int maxBci = Integer.MIN_VALUE; - - @Children Node[] children; - - @Override - public boolean hasTag(Class tag) { - return tag == StandardTags.StatementTag.class || tag == DebuggerTags.AlwaysHalt.class && containsBreakpoint; - } - - @Override - public void setContainsBreakpoint() { - containsBreakpoint = true; - } - - @Override - public void insertHelperNode(Node node, int bci) { - CompilerAsserts.neverPartOfCompilation(); - assert minBci != Integer.MAX_VALUE && maxBci != Integer.MIN_VALUE; - if (children == null) { - children = new Node[maxBci - minBci + 1]; - } - children[bci - minBci] = insert(node); - } - - @Override - void coversBci(int bci, int length) { - minBci = Math.min(minBci, bci); - maxBci = Math.max(maxBci, bci + length); - } -} 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 f9fc7cb2de..2198e1cf68 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 @@ -743,7 +743,7 @@ public final PythonThreadState getThreadState() { private TracingNodes getTracingNodes(BytecodeNode location) { /* - * The TracingNodes node must be child of the BytecodeNode and not the PBytecodeRootNode, so + * The TracingNodes node must be child of the BytecodeNode and not the root node, so * in case BytecodeNode changed, we must reinsert it */ if (tracingNodes == null || tracingNodes.getParent() != location) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java index f0f89e879c..9b3df3955b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java @@ -60,7 +60,6 @@ import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; import com.oracle.graal.python.lib.PyObjectStrAsObjectNode; import com.oracle.graal.python.nodes.BuiltinNames; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinClassProfile; import com.oracle.graal.python.nodes.object.GetClassNode; import com.oracle.graal.python.nodes.object.GetClassNode.GetPythonObjectClassNode; @@ -87,7 +86,6 @@ import com.oracle.truffle.api.interop.ExceptionType; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.interop.UnsupportedMessageException; -import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.nodes.RootNode; import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.source.SourceSection; @@ -102,24 +100,12 @@ public final class TopLevelExceptionHandler extends RootNode { @Child private GilNode gilNode = GilNode.create(); - /* - * Necessary to forward materializeInstrumentableNodes calls to the root node. Truffle assumes - * that all source sections of a source are created when the first call target is initialized. - * That may sometimes happen before the bytecode root's call target is initialized, so we need - * to have a node that will trigger the materialization of all nested functions that haven't - * been created yet at this point. - */ - @Child private Node instrumentationForwarder; - public TopLevelExceptionHandler(PythonLanguage language, RootNode child, Source source) { super(language); this.sourceSection = child.getSourceSection(); this.innerCallTarget = PythonUtils.getOrCreateCallTarget(child); this.exception = null; this.source = source; - if (child instanceof PBytecodeRootNode) { - instrumentationForwarder = ((PBytecodeRootNode) child).createInstrumentationMaterializationForwarder(); - } this.newGlobals = source.getOptions(language).get(PythonSourceOptions.NewGlobals); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java index 4bb6dae2a3..92e1c033b3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java @@ -48,15 +48,11 @@ import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageSetItem; import com.oracle.graal.python.builtins.objects.dict.PDict; import com.oracle.graal.python.builtins.objects.frame.PFrame; -import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.lib.PyDictGetItem; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.frame.GetFrameLocalsNodeGen.CopyDSLLocalsToDictNodeGen; -import com.oracle.graal.python.nodes.frame.GetFrameLocalsNodeGen.CopyLocalsToDictNodeGen; import com.oracle.graal.python.runtime.CallerFlags; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -64,16 +60,12 @@ import com.oracle.truffle.api.bytecode.BytecodeNode; import com.oracle.truffle.api.dsl.Bind; import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateCached; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Idempotent; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.ExplodeLoop; import com.oracle.truffle.api.nodes.Node; @@ -136,57 +128,14 @@ abstract static class CopyLocalsToDictBase extends Node { @NeverDefault static CopyLocalsToDictBase create() { - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER ? CopyDSLLocalsToDictNodeGen.create() : CopyLocalsToDictNodeGen.create(); + return CopyDSLLocalsToDictNodeGen.create(); } static CopyLocalsToDictBase getUncached() { - return PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER ? CopyDSLLocalsToDictNodeGen.getUncached() : CopyLocalsToDictNodeGen.getUncached(); + return CopyDSLLocalsToDictNodeGen.getUncached(); } - } - @GenerateUncached - @GenerateInline(false) // footprint reduction 104 -> 86 - abstract static class CopyLocalsToDict extends CopyLocalsToDictBase { - @Override - public final void execute(PFrame frame, PDict dict) { - execute(frame.getLocals(), dict); - } - - abstract void execute(MaterializedFrame locals, PDict dict); - - @Specialization(guards = {"cachedFd == locals.getFrameDescriptor()", "info != null", "count < 32"}, limit = "1") - @ExplodeLoop - static void doCachedFd(MaterializedFrame locals, PDict dict, - @Bind Node inliningTarget, - @SuppressWarnings("unused") @Cached("locals.getFrameDescriptor()") FrameDescriptor cachedFd, - @Bind("getInfo(cachedFd)") FrameInfo info, - @Bind("info.getVariableCount()") int count, - @Shared("setItem") @Cached HashingStorageSetItem setItem, - @Shared("delItem") @Cached HashingStorageDelItem delItem) { - int regularVarCount = info.getRegularVariableCount(); - for (int i = 0; i < count; i++) { - copyItem(inliningTarget, locals.getValue(i), info, dict, setItem, delItem, i, i >= regularVarCount); - } - } - - @Specialization(replaces = "doCachedFd") - void doGeneric(MaterializedFrame locals, PDict dict, - @Bind Node inliningTarget, - @Shared("setItem") @Cached HashingStorageSetItem setItem, - @Shared("delItem") @Cached HashingStorageDelItem delItem) { - FrameInfo info = getInfo(locals.getFrameDescriptor()); - if (info == null) { - // A builtin frame. Ideally we would avoid materializing it in the first place - return; - } - int count = info.getVariableCount(); - int regularVarCount = info.getRegularVariableCount(); - for (int i = 0; i < count; i++) { - copyItem(inliningTarget, locals.getValue(i), info, dict, setItem, delItem, i, i >= regularVarCount); - } - } - - private static void copyItem(Node inliningTarget, Object localValue, FrameInfo info, PDict dict, HashingStorageSetItem setItem, HashingStorageDelItem delItem, int i, boolean deref) { + static void copyItem(Node inliningTarget, Object localValue, BytecodeDSLFrameInfo info, PDict dict, HashingStorageSetItem setItem, HashingStorageDelItem delItem, int i, boolean deref) { TruffleString name = info.getVariableName(i); Object value = localValue; if (deref && value != null) { @@ -199,11 +148,6 @@ private static void copyItem(Node inliningTarget, Object localValue, FrameInfo i dict.setDictStorage(storage); } } - - @Idempotent - protected static FrameInfo getInfo(FrameDescriptor fd) { - return (FrameInfo) fd.getInfo(); - } } @GenerateUncached @@ -227,23 +171,11 @@ void doIt(BytecodeFrame locals, PDict dict, int regularVarCount = regularVarCountProfile.profile(inliningTarget, info.getRegularVariableCount()); int varCount = varCountProfile.profile(inliningTarget, info.getVariableCount()); for (int i = 0; i < varCount; i++) { - CopyLocalsToDict.copyItem(inliningTarget, locals.getLocalValue(i), info, dict, setItem, delItem, i, i >= regularVarCount); + copyItem(inliningTarget, locals.getLocalValue(i), info, dict, setItem, delItem, i, i >= regularVarCount); } } } - /** - * Equivalent of CPython's {@code PyFrame_LocalsToFast} - */ - public static void syncLocalsBackToFrame(CodeUnit co, PFrame pyFrame, Frame localFrame) { - if (!pyFrame.hasCustomLocals()) { - PDict localsDict = (PDict) pyFrame.getLocalsDict(); - copyLocalsArray(localFrame, localsDict, co.varnames, 0, false); - copyLocalsArray(localFrame, localsDict, co.cellvars, co.varnames.length, true); - copyLocalsArray(localFrame, localsDict, co.freevars, co.varnames.length + co.cellvars.length, true); - } - } - /** * Equivalent of CPython's {@code PyFrame_LocalsToFast} */ @@ -277,23 +209,6 @@ private static void copyLocalsArray(Frame localFrame, BytecodeNode bytecodeNode, } } - private static void copyLocalsArray(Frame localFrame, PDict localsDict, TruffleString[] namesArray, int offset, boolean deref) { - for (int i = 0; i < namesArray.length; i++) { - TruffleString varname = namesArray[i]; - Object value = getDictItemUncached(localsDict, varname); - if (deref) { - PCell cell = (PCell) localFrame.getObject(offset + i); - cell.setRef(value); - } else { - if (value == null) { - value = PNone.NONE; - // TODO warn: "assigning None to unbound local %s" - } - localFrame.setObject(offset + i, value); - } - } - } - @TruffleBoundary private static Object getDictItemUncached(PDict localsDict, TruffleString varname) { return PyDictGetItem.executeUncached(localsDict, varname); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java index a48124ca1d..27207e9d02 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java @@ -40,8 +40,6 @@ */ package com.oracle.graal.python.nodes.frame; -import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY; - import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.objects.frame.PFrame; import com.oracle.graal.python.builtins.objects.function.PArguments; @@ -49,14 +47,11 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo; import com.oracle.graal.python.nodes.bytecode.FrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.runtime.CallerFlags; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.Truffle; import com.oracle.truffle.api.bytecode.BytecodeFrame; import com.oracle.truffle.api.bytecode.BytecodeNode; import com.oracle.truffle.api.dsl.Bind; @@ -112,7 +107,7 @@ public static MaterializeFrameNode getUncached() { * is passed as argument to avoid its lookup. Can be used if this node is uncached. */ public final PFrame executeOnStack(Frame frameToMaterialize, BytecodeNode location, boolean markAsEscaped, boolean forceSync) { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; + assert true; return execute(location, markAsEscaped, forceSync, frameToMaterialize); } @@ -121,7 +116,7 @@ public final PFrame executeOnStack(Frame frameToMaterialize, BytecodeNode locati * argument to avoid its lookup. Can be used if this node is uncached. */ public final PFrame executeOnStack(Frame frameToMaterialize, PRootNode location, boolean markAsEscaped, boolean forceSync) { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || !(location instanceof PBytecodeDSLRootNode); + assert !(location instanceof PBytecodeDSLRootNode); return execute(location, markAsEscaped, forceSync, frameToMaterialize); } @@ -133,20 +128,12 @@ public final PFrame executeOnStack(Frame frameToMaterialize, PRootNode location, */ public final PFrame executeOnStack(boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize) { Node location = this; - if (!PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - if (!location.isAdoptable()) { - // This should only happen in uncached manual bytecode interpreter, we are fine with - // root node in such case - location = PArguments.getCurrentFrameInfo(frameToMaterialize).getRootNode(); - } - } else { - if (!this.isAdoptable()) { - // This can happen in the uncached interpreter, but there the UncachedBytecodeNode - // should set itself as encapsulating node before it starts executing its bytecode - location = EncapsulatingNodeReference.getCurrent().get(); - assert location != null; - assert BytecodeNode.get(location) != null; - } + if (!this.isAdoptable()) { + // This can happen in the uncached interpreter, but there the UncachedBytecodeNode + // should set itself as encapsulating node before it starts executing its bytecode + location = EncapsulatingNodeReference.getCurrent().get(); + assert location != null; + assert BytecodeNode.get(location) != null; } return execute(location, markAsEscaped, forceSync, frameToMaterialize); } @@ -162,8 +149,8 @@ public final PFrame executeOnStack(boolean markAsEscaped, boolean forceSync, Fra * this must be some adopted node in the AST that is currently being executed. */ public final PFrame execute(Node location, boolean markAsEscaped, boolean forceSync, Frame frameToMaterialize) { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || frameToMaterialize.getArguments().length != 2 : "caller forgot to unwrap continuation frame"; - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || !(location instanceof PBytecodeDSLRootNode) : String.format("Materialized frame: location must not be PBytecodeDSLRootNode, was: %s", + assert frameToMaterialize.getArguments().length != 2 : "caller forgot to unwrap continuation frame"; + assert !(location instanceof PBytecodeDSLRootNode) : String.format("Materialized frame: location must not be PBytecodeDSLRootNode, was: %s", location); return executeImpl(location, markAsEscaped, forceSync, frameToMaterialize); } @@ -217,13 +204,9 @@ public static PFrame materializeGeneratorFrame(Node location, MaterializedFrame public static PFrame materializeGeneratorFrame(PythonLanguage language, Node location, MaterializedFrame generatorFrame, PFunction generatorFunction, PythonObject globals, PFrame.Reference frameRef) { PFrame escapedFrame = PFactory.createPFrame(language, frameRef, location, generatorFunction, false); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode = BytecodeNode.get(location); - assert bytecodeNode != null : location; - escapedFrame.setBytecodeFrame(bytecodeNode.createMaterializedFrame(0, generatorFrame)); - } else { - escapedFrame.setLocals(generatorFrame); - } + BytecodeNode bytecodeNode = BytecodeNode.get(location); + assert bytecodeNode != null : location; + escapedFrame.setBytecodeFrame(bytecodeNode.createMaterializedFrame(0, generatorFrame)); escapedFrame.setGlobals(globals); frameRef.setPyFrame(escapedFrame); return escapedFrame; @@ -235,27 +218,20 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram pyFrame.setLocation(location); return; } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode; - assert !(location instanceof PBytecodeDSLRootNode); // we need BytecodeNode or its child - CompilerAsserts.partialEvaluationConstant(location); - bytecodeNode = BytecodeNode.get(location); - if (bytecodeNode != null) { - pyFrame.setBci(bytecodeNode.getBytecodeIndex(frameToMaterialize)); - pyFrame.setLocation(bytecodeNode); - pyFrame.resetLine(); - } else { - assert location == PythonLanguage.get(null).unavailableSafepointLocation : String.format("(%s) %s, root: %s", - location != null ? location.getClass().getSimpleName() : "null", - location, location != null ? location.getRootNode() : "null"); - pyFrame.setBci(-1); - pyFrame.setLocation(location); - pyFrame.resetLine(); - } + BytecodeNode bytecodeNode; + assert !(location instanceof PBytecodeDSLRootNode); // we need BytecodeNode or its child + CompilerAsserts.partialEvaluationConstant(location); + bytecodeNode = BytecodeNode.get(location); + if (bytecodeNode != null) { + pyFrame.setBci(bytecodeNode.getBytecodeIndex(frameToMaterialize)); + pyFrame.setLocation(bytecodeNode); + pyFrame.resetLine(); } else { - BytecodeFrameInfo bytecodeFrameInfo = (BytecodeFrameInfo) info; - pyFrame.setBci(bytecodeFrameInfo.getBci(frameToMaterialize)); - pyFrame.setLocation(bytecodeFrameInfo.getRootNode()); + assert location == PythonLanguage.get(null).unavailableSafepointLocation : String.format("(%s) %s, root: %s", + location != null ? location.getClass().getSimpleName() : "null", + location, location != null ? location.getRootNode() : "null"); + pyFrame.setBci(-1); + pyFrame.setLocation(location); pyFrame.resetLine(); } } @@ -309,24 +285,11 @@ static void doSync(PFrame pyFrame, Frame frameToSync, Node location, @Cached(inline = false) ValueProfile frameDescriptorProfile, @Cached InlinedIntValueProfile slotCountProfile, @Exclusive @Cached InlinedBranchProfile createLocalsProfile) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode = BytecodeNode.get(location); - if (bytecodeNode != null) { - // TODO: avoid always making a copy, if a BytecodeFrame is set, just update it - BytecodeFrame copiedFrame = bytecodeNode.createCopiedFrame(0, frameToSync); - pyFrame.setBytecodeFrame(copiedFrame); - } - } else { - FrameDescriptor cachedFd = frameDescriptorProfile.profile(frameToSync.getFrameDescriptor()); - MaterializedFrame target = pyFrame.getLocals(); - if (pyFrame.getLocals() == null) { - createLocalsProfile.enter(inliningTarget); - target = Truffle.getRuntime().createMaterializedFrame(EMPTY_OBJECT_ARRAY, cachedFd); - pyFrame.setLocals(target); - } - assert cachedFd == target.getFrameDescriptor(); - int slotCount = slotCountProfile.profile(inliningTarget, variableSlotCount(cachedFd)); - frameToSync.copyTo(0, target, 0, slotCount); + BytecodeNode bytecodeNode = BytecodeNode.get(location); + if (bytecodeNode != null) { + // TODO: avoid always making a copy, if a BytecodeFrame is set, just update it + BytecodeFrame copiedFrame = bytecodeNode.createCopiedFrame(0, frameToSync); + pyFrame.setBytecodeFrame(copiedFrame); } } @@ -340,15 +303,11 @@ static void doCustomLocals(PFrame pyFrame, Frame frameToSync, Node location) { static void doGenerator(PFrame pyFrame, Frame frameToSync, @SuppressWarnings("unused") Node location, @Bind Node inliningTarget, @Exclusive @Cached InlinedBranchProfile createLocalsProfile) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode = BytecodeNode.get(location); - assert bytecodeNode != null : location; - if (pyFrame.getBytecodeFrame() == null) { - createLocalsProfile.enter(inliningTarget); - pyFrame.setBytecodeFrame(bytecodeNode.createMaterializedFrame(0, frameToSync.materialize())); - } - } else { - pyFrame.setLocals(PGenerator.getGeneratorFrame(frameToSync)); + BytecodeNode bytecodeNode = BytecodeNode.get(location); + assert bytecodeNode != null : location; + if (pyFrame.getBytecodeFrame() == null) { + createLocalsProfile.enter(inliningTarget); + pyFrame.setBytecodeFrame(bytecodeNode.createMaterializedFrame(0, frameToSync.materialize())); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java index 24840959fc..93f83cec88 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/ReadFrameNode.java @@ -57,8 +57,6 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeGeneratorRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.runtime.CallerFlags; import com.oracle.graal.python.runtime.ExecutionContext.CalleeContext; @@ -66,7 +64,6 @@ import com.oracle.graal.python.runtime.IndirectCallData; import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.RootCallTarget; @@ -114,11 +111,7 @@ public static class AllPythonFramesSelector implements FrameSelector { @Override public boolean skip(RootNode rootNode) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return PBytecodeDSLRootNode.cast(rootNode) == null; - } else { - return !(rootNode instanceof PBytecodeRootNode || rootNode instanceof PBytecodeGeneratorRootNode); - } + return PBytecodeDSLRootNode.cast(rootNode) == null; } } @@ -460,7 +453,7 @@ public StackWalkResult visitFrame(FrameInstance frameInstance) { // can be because of missing BoundaryCallContext.enter/exit around @TruffleBoundary // calls that may call back into Python code. Look at the Java stack trace and check // if all @TruffleBoundary methods are preceded by BoundaryCallContext.enter/exit - assert first || !(PGenerator.unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || + assert first || !(PGenerator.unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || callNode != null : String.format("root=%s, i=%d", rootNode, i); first = false; if (!(rootNode instanceof PRootNode pRootNode && pRootNode.setsUpCalleeContext())) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/ExceptionStateNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/ExceptionStateNodes.java index d649e5d5c4..02dee84ffa 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/ExceptionStateNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/ExceptionStateNodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2026, 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 @@ -50,7 +50,6 @@ import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode; import com.oracle.graal.python.runtime.PythonContext.PythonThreadState; import com.oracle.graal.python.runtime.PythonContextFactory.GetThreadStateNodeGen; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -157,7 +156,7 @@ public AbstractTruffleException visitFrame(FrameInstance frameInstance) { // @TruffleBoundary calls that may call back into Python code. Look at the Java // stack trace and check if all @TruffleBoundary methods are preceded by // BoundaryCallContext.enter/exit - assert first || !(PGenerator.unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || callNode != null : rootNode; + assert first || !(PGenerator.unwrapContinuationRoot(rootNode) instanceof PBytecodeDSLRootNode) || callNode != null : rootNode; first = false; IndirectCallData.setCallerFlagsOnIndirectCallData(callNode, CallerFlags.NEEDS_EXCEPTION_STATE); PRootNode pRootNode = null; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java index 58bebd4dd5..d49fbf264a 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java @@ -175,7 +175,7 @@ public final void execute(PythonContext context, Access access) { if (location instanceof RootNode root && PBytecodeDSLRootNode.cast(root) != null) { // PBytecodeDSLRootNode is not usable as a location. To resolve the BCI // stored in the frame, we need the currently executing BytecodeNode, - // using PBytecodeRootNode.getBytecodeNode() is not correct. We use the + // using the root's BytecodeNode is not correct. We use the // dummy node to pass our assertions during stack walking that "call // node" is never PBytecodeDSLRootNode prev = encapsulatingNodeRef.set(language.unavailableSafepointLocation); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java index 4463b8b10b..0ec5ce58a7 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java @@ -400,13 +400,6 @@ public void enter(VirtualFrame frame, PRootNode rootNode) { PArguments.setCurrentFrameInfo(frame, thisFrameRef); } - public static void enterGenerator(VirtualFrame frame, MaterializedFrame generatorFrame) { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; - PFrame.Reference ref = PArguments.getCurrentFrameInfo(generatorFrame); - ref.setCallerInfo(PArguments.getCallerFrameInfo(frame)); - PArguments.setCurrentFrameInfo(frame, ref); - } - public void exit(VirtualFrame frame, PRootNode node) { // For Bytecode DSL root node we need BytecodeNode as location assert !(node instanceof PBytecodeDSLRootNode); @@ -462,7 +455,6 @@ public static void forceEscapeFrame(Frame frame, Node location, Reference info, // go to the other branch and setNeedsCallerFrame. This helps to prevent one-off // initializations (importing a module) from invalidating the assumption - // force the frame so that it can be accessed later materializeNode.execute(location, false, true, frame); // if this frame escaped we must ensure that also f_back does callerInfo.markAsEscaped(); @@ -588,7 +580,7 @@ public static void exit(VirtualFrame frame, PythonThreadState pythonThreadState, } private static void validateBoundaryCallData(BoundaryCallData boundaryCallData) { - assert !PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER || boundaryCallData.isUncached() || + assert boundaryCallData.isUncached() || (!(boundaryCallData.getRootNode() instanceof PBytecodeDSLRootNode) || BytecodeNode.get(boundaryCallData) != null); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java index 783e569de0..a771560e41 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java @@ -424,9 +424,7 @@ public static final class PythonThreadState { Object asyncgenFirstIter; /* - * Instrumentation data (Bytecode DSL interpreter only). For the manual bytecode - * interpreter, this data is stored in a local state variable, but the DSL interpreter must - * use a thread local. + * Instrumentation data for bytecode roots. */ PBytecodeDSLRootNode.InstrumentationData instrumentationData; @@ -1588,7 +1586,7 @@ public void initialize() { } releaseGil(); } - PythonOptions.checkBytecodeDSLEnv(); + } public void resetPerfCounter() { @@ -1610,7 +1608,7 @@ public void patch(Env newEnv) { } finally { releaseGil(); } - PythonOptions.checkBytecodeDSLEnv(); + } private void importSiteIfForced() { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java index 5fffa6fc26..ff99173823 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java @@ -43,7 +43,6 @@ import java.util.Map; import java.util.Optional; -import org.graalvm.nativeimage.ImageInfo; import org.graalvm.options.OptionCategory; import org.graalvm.options.OptionDescriptor; import org.graalvm.options.OptionDescriptors; @@ -84,41 +83,12 @@ public final class PythonOptions { */ public static final boolean AUTOMATIC_ASYNC_ACTIONS = !"false".equalsIgnoreCase(System.getProperty("python.AutomaticAsyncActions")); - /** - * Whether to use the experimental Bytecode DSL interpreter instead of the manually-written - * bytecode interpreter. - */ - public static final boolean ENABLE_BYTECODE_DSL_INTERPRETER; private static final OptionType TS_OPTION_TYPE = new OptionType<>("graal.python.TruffleString", PythonUtils::toTruffleStringUncached); - static { - String prop = System.getProperty("python.EnableBytecodeDSLInterpreter"); - if (prop != null) { - ENABLE_BYTECODE_DSL_INTERPRETER = prop.equalsIgnoreCase("true"); - } else if (!ImageInfo.inImageCode()) { - // In JVM mode we also honor the env variable so that subprocesses spawned from tests in - // JVM mode run the same type of interpreter - String env = System.getenv("BYTECODE_DSL_INTERPRETER"); - if (env != null) { - ENABLE_BYTECODE_DSL_INTERPRETER = env.equalsIgnoreCase("true"); - } else { - ENABLE_BYTECODE_DSL_INTERPRETER = true; - } - } else { - ENABLE_BYTECODE_DSL_INTERPRETER = true; - } - } - private PythonOptions() { // no instances } - public static void checkBytecodeDSLEnv() { - if (ENABLE_BYTECODE_DSL_INTERPRETER && "false".equalsIgnoreCase(System.getenv("BYTECODE_DSL_INTERPRETER"))) { - System.err.println("WARNING: found environment variable BYTECODE_DSL_INTERPRETER=false, but the python.EnableBytecodeDSLInterpreter Java property was not set and defaults to true."); - } - } - @Option(category = OptionCategory.EXPERT, help = "Set the home of Python. Equivalent of GRAAL_PYTHONHOME env variable. " + "Determines default values for the CoreHome, StdLibHome, SysBasePrefix, SysPrefix.", usageSyntax = "", stability = OptionStability.STABLE) // public static final OptionKey PythonHome = new OptionKey<>(""); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java index ba1af768c4..bef449d415 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java @@ -62,14 +62,12 @@ import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode; import com.oracle.graal.python.nodes.BuiltinNames; import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.bytecode.BytecodeFrameInfo; import com.oracle.graal.python.nodes.bytecode.FrameInfo; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler; import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; import com.oracle.graal.python.nodes.object.GetClassNode; import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; @@ -126,27 +124,23 @@ private static ArrayList getStackTraceElements() { private static int getLineno(Frame frame, Node location, FrameInstance frameInstance) { if (frame != null && frame.getFrameDescriptor().getInfo() instanceof FrameInfo frameInfo) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - BytecodeNode bytecodeNode = null; - if (frameInstance != null) { - bytecodeNode = BytecodeNode.get(frameInstance); - } else { - // NB: This fails for the top stack frame, which has no BytecodeNode. - bytecodeNode = BytecodeNode.get(location); - } + BytecodeNode bytecodeNode; + if (frameInstance != null) { + bytecodeNode = BytecodeNode.get(frameInstance); + } else { + // NB: This fails for the top stack frame, which has no BytecodeNode. + bytecodeNode = BytecodeNode.get(location); + } - if (bytecodeNode != null) { - if (PGenerator.isGeneratorFrame(frame)) { - frame = PGenerator.getGeneratorFrame(frame); - } - int bci = bytecodeNode.getBytecodeIndex(frame); - SourceSection sourceLocation = bytecodeNode.getBytecodeLocation(bci).getSourceLocation(); - if (sourceLocation != null) { - return sourceLocation.getStartLine(); - } + if (bytecodeNode != null) { + if (PGenerator.isGeneratorFrame(frame)) { + frame = PGenerator.getGeneratorFrame(frame); + } + int bci = bytecodeNode.getBytecodeIndex(frame); + SourceSection sourceLocation = bytecodeNode.getBytecodeLocation(bci).getSourceLocation(); + if (sourceLocation != null) { + return sourceLocation.getStartLine(); } - } else { - return ((BytecodeFrameInfo) frameInfo).getLine(frame); } } return -1; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java index ee8f15d8e3..ce299c781c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java @@ -54,11 +54,9 @@ import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; import com.oracle.graal.python.runtime.GilNode; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; @@ -104,8 +102,7 @@ public final class PException extends AbstractTruffleException { private transient Thread escapedFrameThread; /** - * Root node that caught this exception object. This node is a manual bytecode or Bytecode DSL - * root node. + * Root node that caught this exception object. */ private transient PRootNode rootNode; /** @@ -231,11 +228,7 @@ public boolean catchingFrameWantedForTraceback() { if (tracebackFrameCount < 0 || rootNode == null) { return false; } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return !((PBytecodeDSLRootNode) rootNode).isInternal(); - } else { - return ((PBytecodeRootNode) rootNode).frameIsVisibleToPython(); - } + return !((PBytecodeDSLRootNode) rootNode).isInternal(); } public int getCatchBci() { @@ -250,11 +243,7 @@ public int getCatchLine() { if (rootNode == null) { return -1; } - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - return ((PBytecodeDSLRootNode) rootNode).bciToLine(catchBci, bytecodeNode); - } else { - return ((PBytecodeRootNode) rootNode).bciToLine(catchBci); - } + return ((PBytecodeDSLRootNode) rootNode).bciToLine(catchBci, bytecodeNode); } /** @@ -310,22 +299,9 @@ public void expect(Node inliningTarget, PythonBuiltinClassType error, IsBuiltinO } } - /** - * Set the catching frame reference for a manual bytecode node. - */ - public void setCatchingFrameReference(Frame frame, PBytecodeRootNode catchLocation, int catchBci) { - this.frameInfo = PArguments.getCurrentFrameInfo(frame); - this.rootNode = catchLocation; - this.catchBci = catchBci; - } - /** * Sets the catching frame information for a Bytecode DSL node. * - * NB: The manual bytecode interpreter sets all of the catching frame info in one step after it - * finds a handler for the bci. This is possible because it has control over the handler - * dispatch logic. - * * The Bytecode DSL interpreter's generated code automatically dispatches to a handler. We can * set the frame info inside the handler code, but the bci of the raising instruction is lost at * that point. @@ -350,7 +326,6 @@ public void setCatchingFrameReference(Frame frame, PBytecodeRootNode catchLocati * found and that the catch location actually refers to a guarded instruction. */ public void setCatchLocation(int catchBci, BytecodeNode bytecodeNode) { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; // Overwrite the catchBci as long as no handler has been found yet. if (!isCaught()) { this.catchBci = catchBci; @@ -359,7 +334,6 @@ public void setCatchLocation(int catchBci, BytecodeNode bytecodeNode) { } public void markAsCaught(Frame frame, PBytecodeDSLRootNode catchLocation) { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; if (!isCaught()) { this.frameInfo = PArguments.getCurrentFrameInfo(frame); this.rootNode = catchLocation; @@ -367,7 +341,6 @@ public void markAsCaught(Frame frame, PBytecodeDSLRootNode catchLocation) { } private boolean isCaught() { - assert PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER; return rootNode != null; } @@ -403,9 +376,8 @@ public Object getEscapedException() { } /** - * If not done already, create the traceback for this exception state using the frame previously - * provided to {@link #setCatchingFrameReference(Frame, PBytecodeRootNode, int)} and sync it to - * the attached python exception. + * If not done already, create the traceback for this exception state and sync it to the + * attached python exception. */ public void ensureReified() { if (!reified) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java index 7a53402940..379043036d 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/interop/PythonLocalScope.java @@ -48,7 +48,6 @@ import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.bytecode.BytecodeFrame; import com.oracle.truffle.api.bytecode.BytecodeNode; @@ -86,7 +85,7 @@ public static PythonLocalScope create(Node node, Frame frame) { RootNode root = node.getRootNode(); PBytecodeDSLRootNode dslRoot = PBytecodeDSLRootNode.cast(root); - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER && dslRoot != null) { + if (dslRoot != null) { BytecodeNode bytecodeNode = BytecodeNode.get(node); BytecodeFrame bytecodeFrame; if (bytecodeNode != null) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java index 7f6ae44422..38f884ccf9 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java @@ -232,9 +232,7 @@ import com.oracle.graal.python.builtins.objects.typing.PTypeAliasType; import com.oracle.graal.python.builtins.objects.typing.PTypeVar; import com.oracle.graal.python.builtins.objects.typing.PTypeVarTuple; -import com.oracle.graal.python.compiler.BytecodeCodeUnit; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.runtime.NativeZlibSupport; @@ -789,19 +787,11 @@ public static PDictView createDictItemsView(PythonLanguage language, Object dict * Special objects: generators, proxies, references, cells */ - public static PGenerator createGenerator(PythonLanguage language, PFunction function, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) { - return PGenerator.create(language, function, rootNode, callTargets, arguments, PythonBuiltinClassType.PGenerator); - } - public static PGenerator createGenerator(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { return PGenerator.create(language, function, rootNode, arguments, PythonBuiltinClassType.PGenerator, continuationRootNode, continuationFrame); } - public static PGenerator createCoroutine(PythonLanguage language, PFunction function, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) { - return PGenerator.create(language, function, rootNode, callTargets, arguments, PythonBuiltinClassType.PCoroutine); - } - public static PGenerator createCoroutine(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { return PGenerator.create(language, function, rootNode, arguments, PythonBuiltinClassType.PCoroutine, continuationRootNode, continuationFrame); @@ -811,10 +801,6 @@ public static PCoroutineWrapper createCoroutineWrapper(PythonLanguage language, return new PCoroutineWrapper(language, generator); } - public static PAsyncGen createAsyncGenerator(PythonLanguage language, PFunction function, PBytecodeRootNode rootNode, RootCallTarget[] callTargets, Object[] arguments) { - return PAsyncGen.create(language, function, rootNode, callTargets, arguments); - } - public static PAsyncGen createAsyncGenerator(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { return new PAsyncGen(language, function, rootNode, continuationRootNode, continuationFrame); @@ -1089,15 +1075,6 @@ public static PCode createCode(PythonLanguage language, RootCallTarget ct, int f -1, -1, flags, null, null, null, null, null, filename, null, null, firstlineno, linetable); } - public static PCode createCode(PythonLanguage language, RootCallTarget callTarget, Signature signature, BytecodeCodeUnit codeUnit, TruffleString filename) { - return createCode(language, callTarget.getRootNode(), signature, codeUnit, filename); - } - - public static PCode createCode(PythonLanguage language, RootNode rootNode, Signature signature, BytecodeCodeUnit codeUnit, TruffleString filename) { - return new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), rootNode, signature, - codeUnit.varnames.length, -1, -1, null, null, null, null, null, filename, codeUnit.name, codeUnit.qualname, -1, codeUnit.srcOffsetTable); - } - public static PCode createCode(PythonLanguage language, RootNode rootNode, Signature signature, BytecodeDSLCodeUnit codeUnit, TruffleString filename) { return new PCode(PythonBuiltinClassType.PCode, PythonBuiltinClassType.PCode.getInstanceShape(language), rootNode, signature, codeUnit.varnames.length, -1, -1, null, null, null, null, null, filename, codeUnit.name, codeUnit.qualname, -1, null); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java index e5a3ae94fe..830912d32c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java @@ -82,7 +82,6 @@ import com.oracle.graal.python.pegparser.scope.ScopeEnvironment; import com.oracle.graal.python.pegparser.sst.ConstantValue; import com.oracle.graal.python.pegparser.tokenizer.CodePoints; -import com.oracle.graal.python.runtime.PythonOptions; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.Assumption; import com.oracle.truffle.api.CallTarget; @@ -806,12 +805,7 @@ public static Source createFakeSource() { @TruffleBoundary public static Source createFakeSource(TruffleString name) { - if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) { - // The DSL interpreter requires character-based sources. - return Source.newBuilder(PythonLanguage.ID, "", name.toJavaStringUncached()).content(Source.CONTENT_NONE).build(); - } else { - return Source.newBuilder(PythonLanguage.ID, EMPTY_BYTE_SEQUENCE, name.toJavaStringUncached()).build(); - } + return Source.newBuilder(PythonLanguage.ID, "", name.toJavaStringUncached()).content(Source.CONTENT_NONE).build(); } public static Object[] prependArgument(Object primary, Object[] arguments) { From 07e59eb67d215e2a330359a0af2154c85f47358e Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:40:27 +0200 Subject: [PATCH 05/20] Remove bytecode DSL interpreter marker --- .../python/harness.py | 1 - .../python/heap/import-a-lot.py | 9 +----- .../integration/runtime/ProfileTests.java | 11 ++----- .../python/test/debug/PythonDebugTest.java | 29 ++++--------------- .../src/tests/test_reparse.py | 2 +- .../src/tests/util.py | 4 +-- .../modules/GraalPythonModuleBuiltins.java | 1 - .../python/builtins/objects/frame/PFrame.java | 2 -- .../nodes/frame/MaterializeFrameNode.java | 1 - .../lib-python/3/test/support/__init__.py | 11 ------- .../lib-python/3/test/test_sys_settrace.py | 4 +-- 11 files changed, 14 insertions(+), 61 deletions(-) diff --git a/graalpython/com.oracle.graal.python.benchmarks/python/harness.py b/graalpython/com.oracle.graal.python.benchmarks/python/harness.py index b951cd548c..964391c6cd 100644 --- a/graalpython/com.oracle.graal.python.benchmarks/python/harness.py +++ b/graalpython/com.oracle.graal.python.benchmarks/python/harness.py @@ -526,7 +526,6 @@ def run_benchmark(args): print("### no extra module search paths specified") if GRAALPYTHON: - print(f"### using bytecode DSL interpreter: {__graalpython__.is_bytecode_dsl_interpreter}") print(f"### using forced uncached interpreter: {getattr(__graalpython__, 'is_forced_uncached_interpreter', False)}") BenchRunner(bench_file, bench_args=bench_args, iterations=iterations, warmup=warmup, warmup_runs=warmup_runs, startup=startup, live_results=live_results, self_measurement=self_measurement).run() diff --git a/graalpython/com.oracle.graal.python.benchmarks/python/heap/import-a-lot.py b/graalpython/com.oracle.graal.python.benchmarks/python/heap/import-a-lot.py index e609712a8c..5866ab2e7a 100644 --- a/graalpython/com.oracle.graal.python.benchmarks/python/heap/import-a-lot.py +++ b/graalpython/com.oracle.graal.python.benchmarks/python/heap/import-a-lot.py @@ -1,4 +1,4 @@ -# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2025, 2026, 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 @@ -59,13 +59,6 @@ import tomllib import argparse import subprocess -import sys - -# We log the bytecode DSL flag only in this benchamark, because we do not want to influence -# the other benchmarks by importing the sys module. Other benchmarks will print a warning -# that bytecode DSL flag could not be verified -if getattr(getattr(sys, "implementation", None), "name", None) == "graalpy": - print(f"### using bytecode DSL interpreter: {__graalpython__.is_bytecode_dsl_interpreter}") # Sleep a bit to shake out weakref callbacks and get more measurement samples for i in range(30): diff --git a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java index 255ad09151..617e091854 100644 --- a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java +++ b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2026, 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 @@ -40,14 +40,11 @@ */ package com.oracle.graal.python.test.integration.runtime; -import static com.oracle.graal.python.test.integration.PythonTests.eval; - import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import org.graalvm.polyglot.Value; import org.junit.Assert; -import org.junit.Assume; +import org.junit.Ignore; import org.junit.Test; import com.oracle.graal.python.test.integration.PythonTests; @@ -70,10 +67,8 @@ public void profileYield() { } @Test + @Ignore("GR-71916: TODO wrong stacktrace") public void profileException() { - Value isBytecodeDLS = eval("__graalpython__.is_bytecode_dsl_interpreter"); - // GR-71916 - Assume.assumeFalse("TODO: wrong stacktrace", isBytecodeDLS.asBoolean()); String source = "import sys\n" + "def f(frame, event, arg): print(frame, event, arg)\n" + "sys.setprofile(f)\n" + diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java index 1d8b5fa3f6..2a3b082338 100644 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java +++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java @@ -40,7 +40,6 @@ */ package com.oracle.graal.python.test.debug; -import static com.oracle.graal.python.test.integration.PythonTests.eval; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -96,7 +95,6 @@ public void dispose() { public void testSteppingAsExpected() throws Throwable { // test that various elements step as expected, including generators, statement level atomic // expressions, and roots - boolean isBytecodeDLS = isBytecodeDSL(); final Source source = Source.newBuilder("python", "" + "import sys\n" + "from sys import version\n" + @@ -167,24 +165,12 @@ public void testSteppingAsExpected() throws Throwable { assertEquals(8, frame.getSourceSection().getStartLine()); event.prepareStepInto(1); }); - // Unlike the manual interpreter, which reports yield as onReturn, the Bytecode DSL - // correctly reports yield as onYield on the probe node, but the step over strategy - // is different for yield vs return - see SteppingStrategy$StepOver#step - if (!isBytecodeDLS) { - // steppping into genfunc() - expectSuspended((SuspendedEvent event) -> { - DebugStackFrame frame = event.getTopStackFrame(); - assertEquals(12, frame.getSourceSection().getStartLine()); - event.prepareStepOver(1); - }); - } else { - // steppping into genfunc() - expectSuspended((SuspendedEvent event) -> { - DebugStackFrame frame = event.getTopStackFrame(); - assertEquals(12, frame.getSourceSection().getStartLine()); - event.prepareStepOut(1); - }); - } + // steppping into genfunc() + expectSuspended((SuspendedEvent event) -> { + DebugStackFrame frame = event.getTopStackFrame(); + assertEquals(12, frame.getSourceSection().getStartLine()); + event.prepareStepOut(1); + }); expectSuspended((SuspendedEvent event) -> { DebugStackFrame frame = event.getTopStackFrame(); assertEquals(8, frame.getSourceSection().getStartLine()); @@ -698,7 +684,4 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx }); } - private static boolean isBytecodeDSL() { - return eval("__graalpython__.is_bytecode_dsl_interpreter").asBoolean(); - } } diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_reparse.py b/graalpython/com.oracle.graal.python.test/src/tests/test_reparse.py index 775e43da5c..575e7f9a30 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_reparse.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_reparse.py @@ -77,7 +77,7 @@ def _terminate_and_collect(proc): @contextlib.contextmanager def pyc_reparse(test_content, expect_success=True, python_options=()): - if sys.implementation.name != "graalpy" or not __graalpython__.is_bytecode_dsl_interpreter: + if sys.implementation.name != "graalpy": raise unittest.SkipTest("Reparsing tests are only meaningful on bytecode DSL interpreter") with tempfile.TemporaryDirectory() as tempdir: tempdir_path = Path(tempdir) 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 d874da1b89..4674fdf710 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/util.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/util.py @@ -41,7 +41,7 @@ import time import unittest -IS_BYTECODE_DSL = sys.implementation.name == 'graalpy' and __graalpython__.is_bytecode_dsl_interpreter +IS_BYTECODE_DSL = sys.implementation.name == 'graalpy' TRANSIENT_GRAALPY_STARTUP_BLOCKING_IO = "ERROR: BlockingIOError: [Errno 11] Resource temporarily unavailable" @@ -91,8 +91,6 @@ def wrapper(test): 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 diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java index 86da1f32da..6f99ff5b69 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java @@ -235,7 +235,6 @@ protected List> getNodeFa public void initialize(Python3Core core) { super.initialize(core); addBuiltinConstant("is_native", TruffleOptions.AOT); - addBuiltinConstant("is_bytecode_dsl_interpreter", true); PythonContext ctx = core.getContext(); PythonLanguage language = ctx.getLanguage(); // Engine options: if they differ from the values baked into the pre-initialized context, diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java index f0ff1569db..f3fb8cc9ac 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java @@ -234,12 +234,10 @@ public PFrame(PythonLanguage lang, @SuppressWarnings("unused") long threadState, * you should use {@link GetFrameLocalsNode} instead of this method. */ public BytecodeFrame getBytecodeFrame() { - assert true; return bytecodeFrame; } public void setBytecodeFrame(BytecodeFrame bytecodeFrame) { - assert true; this.bytecodeFrame = bytecodeFrame; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java index 27207e9d02..97cf0fa312 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java @@ -107,7 +107,6 @@ public static MaterializeFrameNode getUncached() { * is passed as argument to avoid its lookup. Can be used if this node is uncached. */ public final PFrame executeOnStack(Frame frameToMaterialize, BytecodeNode location, boolean markAsEscaped, boolean forceSync) { - assert true; return execute(location, markAsEscaped, forceSync, frameToMaterialize); } diff --git a/graalpython/lib-python/3/test/support/__init__.py b/graalpython/lib-python/3/test/support/__init__.py index 4dc7095adb..2e3d6a93ac 100644 --- a/graalpython/lib-python/3/test/support/__init__.py +++ b/graalpython/lib-python/3/test/support/__init__.py @@ -1156,17 +1156,6 @@ def impl_detail(msg=None, **guards): msg = msg.format(' or '.join(guardnames)) return unittest.skip(msg) -def bytecode_dsl_excluded(test): - """ - Decorator for tests that don't apply to the Bytecode DSL interpreter. - """ - try: - if sys.implementation.name == 'graalpy' and __graalpython__.is_bytecode_dsl_interpreter: - return unittest.skip("Not supported by the Bytecode DSL interpreter") - except NameError: - pass - return test - def _parse_guards(guards): # Returns a tuple ({platform_name: run_me}, default_value) if not guards: diff --git a/graalpython/lib-python/3/test/test_sys_settrace.py b/graalpython/lib-python/3/test/test_sys_settrace.py index 7c35b45700..aa2bd82136 100644 --- a/graalpython/lib-python/3/test/test_sys_settrace.py +++ b/graalpython/lib-python/3/test/test_sys_settrace.py @@ -1983,8 +1983,8 @@ def no_jump_without_trace_function(): raise AssertionError("Trace-function-less jump failed to fail") -# GraalPy Bytecode DSL: for the time being, arbitrary jumps are not supported by Truffle Bytecode DSL -@support.bytecode_dsl_excluded +# GraalPy: for the time being, arbitrary jumps are not supported by Truffle Bytecode DSL +@unittest.skipIf(sys.implementation.name == 'graalpy', "Not supported by Truffle Bytecode DSL") class JumpTestCase(unittest.TestCase): unbound_locals = r"assigning None to [0-9]+ unbound local" From 5eb6fe03a00550dbf018438dddc6be72c6b1ce43 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 12:45:07 +0200 Subject: [PATCH 06/20] Remove compiler utility class --- .../python/test/compiler/UnparserTests.java | 4 +- .../oracle/graal/python/PythonLanguage.java | 5 +- .../builtins/modules/BuiltinFunctions.java | 4 +- .../graal/python/compiler/Compiler.java | 256 ------------------ .../bytecode_dsl/BytecodeDSLCompiler.java | 103 ++++++- .../bytecode_dsl/RootNodeCompiler.java | 104 ++++++- 6 files changed, 207 insertions(+), 269 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java index 49c8f8444a..fc88665f0a 100644 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java +++ b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/compiler/UnparserTests.java @@ -44,8 +44,8 @@ import org.junit.Test; -import com.oracle.graal.python.compiler.Compiler; import com.oracle.graal.python.compiler.Unparser; +import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler; import com.oracle.graal.python.pegparser.InputType; import com.oracle.graal.python.pegparser.Parser; import com.oracle.graal.python.pegparser.ParserCallbacks; @@ -93,7 +93,7 @@ public void testUnparseConstant() { private static void checkRoundTrip(String source) { ParserCallbacks parserCallbacks = new TestParserCallbacksImpl(); - Parser parser = Compiler.createParser(source, parserCallbacks, InputType.EVAL, false, false); + Parser parser = BytecodeDSLCompiler.createParser(source, parserCallbacks, InputType.EVAL, false, false); ModTy.Expression result = (ModTy.Expression) parser.parse(); assertEquals(source, unparse(result.body)); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java index b40309b96b..f5469fbf0f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java @@ -78,7 +78,6 @@ import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.slots.TpSlot; import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.compiler.Compiler; import com.oracle.graal.python.compiler.ParserCallbacksImpl; import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler; import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler.BytecodeDSLCompilerResult; @@ -205,7 +204,7 @@ public final class PythonLanguage extends TruffleLanguage { public static final String GRAALPY_MULTIARCH; /* Magic number used to mark pyc files */ - public static final int MAGIC_NUMBER = 21000 + Compiler.BYTECODE_VERSION * 10; + public static final int MAGIC_NUMBER = 21000 + BytecodeDSLCompiler.BYTECODE_VERSION * 10; public static final byte[] MAGIC_NUMBER_BYTES = new byte[4]; static { @@ -585,7 +584,7 @@ public RootCallTarget parse(PythonContext context, Source source, InputType type if (context.getEnv().getOptions().get(PythonOptions.ParserLogFiles)) { LOGGER.log(Level.FINE, () -> "parse '" + source.getName() + "'"); } - Parser parser = Compiler.createParser(source.getCharacters().toString(), errorCb, type, interactiveTerminal, allowIncompleteInput); + Parser parser = BytecodeDSLCompiler.createParser(source.getCharacters().toString(), errorCb, type, interactiveTerminal, allowIncompleteInput); ModTy mod = (ModTy) parser.parse(); assert mod != null; return compileModule(context, mod, source, topLevel, optimize, argumentNames, errorCb, futureFeatures); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java index ef9024a6fe..5e9249feb9 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java @@ -167,8 +167,8 @@ import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.CallSlotTpIterNextNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotUnaryFunc.CallSlotUnaryNode; -import com.oracle.graal.python.compiler.Compiler; import com.oracle.graal.python.compiler.ParserCallbacksImpl; +import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler; import com.oracle.graal.python.lib.IteratorExhausted; import com.oracle.graal.python.lib.PyAIterCheckNode; import com.oracle.graal.python.lib.PyBytesCheckNode; @@ -1040,7 +1040,7 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m if (context.getEnv().getOptions().get(PythonOptions.ParserLogFiles)) { PythonLanguage.LOGGER.log(Level.FINE, () -> "parse '" + source.getName() + "'"); } - Parser parser = Compiler.createParser(code.toJavaStringUncached(), parserCb, type, compilerFlags, featureVersion); + Parser parser = BytecodeDSLCompiler.createParser(code.toJavaStringUncached(), parserCb, type, compilerFlags, featureVersion); ModTy mod = (ModTy) parser.parse(); parserCb.triggerDeprecationWarnings(); return AstModuleBuiltins.sst2Obj(getContext(), mod); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java deleted file mode 100644 index 444e803669..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/Compiler.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2021, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import static com.oracle.graal.python.util.PythonUtils.codePointsToInternedTruffleString; -import static com.oracle.graal.python.util.PythonUtils.codePointsToTruffleString; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.compiler.OpCodes.CollectionBits; -import com.oracle.graal.python.pegparser.AbstractParser; -import com.oracle.graal.python.pegparser.FutureFeature; -import com.oracle.graal.python.pegparser.InputType; -import com.oracle.graal.python.pegparser.Parser; -import com.oracle.graal.python.pegparser.ParserCallbacks; -import com.oracle.graal.python.pegparser.ParserCallbacks.ErrorType; -import com.oracle.graal.python.pegparser.sst.AliasTy; -import com.oracle.graal.python.pegparser.sst.ConstantValue; -import com.oracle.graal.python.pegparser.sst.ExprTy; -import com.oracle.graal.python.pegparser.sst.StmtTy; - -public final class Compiler { - public static final int BYTECODE_VERSION = 32; - - private Compiler() { - } - - public static int parseFuture(StmtTy[] modBody, EnumSet futureFeatures, ParserCallbacks parserCallbacks) { - int lastFutureLine = -1; - if (modBody == null || modBody.length == 0) { - return lastFutureLine; - } - boolean done = false; - int prevLine = 0; - int i = 0; - if (findDocstring(modBody) != null) { - i++; - } - - for (; i < modBody.length; i++) { - StmtTy s = modBody[i]; - int line = s.getSourceRange().startLine; - if (done && line > prevLine) { - return lastFutureLine; - } - prevLine = line; - if (s instanceof StmtTy.ImportFrom importFrom) { - if ("__future__".equals(importFrom.module)) { - if (done) { - throw parserCallbacks.onError(ErrorType.Syntax, s.getSourceRange(), "from __future__ imports must occur at the beginning of the file"); - } - parseFutureFeatures(importFrom, futureFeatures, parserCallbacks); - lastFutureLine = line; - } else { - done = true; - } - } else { - done = true; - } - } - return lastFutureLine; - } - - private static void parseFutureFeatures(StmtTy.ImportFrom node, EnumSet features, ParserCallbacks parserCallbacks) { - for (AliasTy alias : node.names) { - if (alias.name != null) { - switch (alias.name) { - case "nested_scopes": - case "generators": - case "division": - case "absolute_import": - case "with_statement": - case "print_function": - case "unicode_literals": - case "generator_stop": - break; - case "barry_as_FLUFL": - features.add(FutureFeature.BARRY_AS_BDFL); - break; - case "annotations": - features.add(FutureFeature.ANNOTATIONS); - break; - case "braces": - throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "not a chance"); - default: - throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "future feature %s is not defined", alias.name); - } - } - } - } - - private static Object findDocstring(StmtTy[] body) { - if (body != null && body.length > 0 && body[0] instanceof StmtTy.Expr stmt && stmt.value instanceof ExprTy.Constant expr) { - ConstantValue value = expr.value; - if (value.kind == ConstantValue.Kind.CODEPOINTS) { - return codePointsToTruffleString(value.getCodePoints()); - } - } - return null; - } - - public static final class ConstantCollection { - public final Object collection; - public final int elementType; - - ConstantCollection(Object collection, int elementType) { - this.collection = collection; - this.elementType = elementType; - } - } - - public static ConstantCollection tryCollectConstantCollection(ExprTy[] elements) { - if (elements == null || elements.length == 0) { - return null; - } - - int constantType = -1; - List constants = new ArrayList<>(); - - for (ExprTy e : elements) { - if (e instanceof ExprTy.Constant c) { - if (c.value.kind == ConstantValue.Kind.BOOLEAN) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_BOOLEAN); - constants.add(c.value.getBoolean()); - } else if (c.value.kind == ConstantValue.Kind.LONG) { - long val = c.value.getLong(); - if (val == (int) val) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_INT); - } else { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_LONG); - } - constants.add(val); - } else if (c.value.kind == ConstantValue.Kind.DOUBLE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_DOUBLE); - constants.add(c.value.getDouble()); - } else if (c.value.kind == ConstantValue.Kind.CODEPOINTS) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); - constants.add(codePointsToInternedTruffleString(c.value.getCodePoints())); - } else if (c.value.kind == ConstantValue.Kind.NONE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); - constants.add(PNone.NONE); - } else { - return null; - } - } else { - return null; - } - } - Object newConstant = null; - switch (constantType) { - case CollectionBits.ELEMENT_OBJECT: - newConstant = constants.toArray(new Object[0]); - break; - case CollectionBits.ELEMENT_INT: { - int[] a = new int[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (int) (long) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_LONG: { - long[] a = new long[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (long) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_BOOLEAN: { - boolean[] a = new boolean[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (boolean) constants.get(i); - } - newConstant = a; - break; - } - case CollectionBits.ELEMENT_DOUBLE: { - double[] a = new double[constants.size()]; - for (int i = 0; i < a.length; i++) { - a[i] = (double) constants.get(i); - } - newConstant = a; - break; - } - } - return new ConstantCollection(newConstant, constantType); - } - - private static int determineConstantType(int existing, int type) { - if (existing == -1 || existing == type) { - return type; - } - if (existing == CollectionBits.ELEMENT_LONG && type == CollectionBits.ELEMENT_INT || existing == CollectionBits.ELEMENT_INT && type == CollectionBits.ELEMENT_LONG) { - return CollectionBits.ELEMENT_LONG; - } - return CollectionBits.ELEMENT_OBJECT; - } - - public static Parser createParser(String src, ParserCallbacks errorCb, InputType inputType, boolean interactiveTerminal, boolean allowIncompleteInput) { - EnumSet flags = EnumSet.noneOf(AbstractParser.Flags.class); - if (interactiveTerminal) { - flags.add(AbstractParser.Flags.INTERACTIVE_TERMINAL); - } - if (allowIncompleteInput) { - flags.add(AbstractParser.Flags.ALLOW_INCOMPLETE_INPUT); - } - return createParser(src, errorCb, inputType, flags, PythonLanguage.MINOR); - } - - public static Parser createParser(String src, ParserCallbacks errorCb, InputType inputType, EnumSet flags, int featureVersion) { - return new Parser(src, errorCb, inputType, flags, featureVersion); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java index 91f9d66d92..81a0b9f699 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java @@ -40,23 +40,33 @@ */ package com.oracle.graal.python.compiler.bytecode_dsl; +import static com.oracle.graal.python.util.PythonUtils.codePointsToTruffleString; + import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.compiler.Compiler; import com.oracle.graal.python.compiler.ParserCallbacksImpl; +import com.oracle.graal.python.pegparser.AbstractParser; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.pegparser.FutureFeature; +import com.oracle.graal.python.pegparser.InputType; +import com.oracle.graal.python.pegparser.Parser; import com.oracle.graal.python.pegparser.scope.Scope; import com.oracle.graal.python.pegparser.scope.ScopeEnvironment; +import com.oracle.graal.python.pegparser.ParserCallbacks; +import com.oracle.graal.python.pegparser.ParserCallbacks.ErrorType; +import com.oracle.graal.python.pegparser.sst.AliasTy; +import com.oracle.graal.python.pegparser.sst.ConstantValue; +import com.oracle.graal.python.pegparser.sst.ExprTy; import com.oracle.graal.python.pegparser.sst.ModTy; import com.oracle.graal.python.pegparser.sst.StmtTy; import com.oracle.truffle.api.source.Source; public class BytecodeDSLCompiler { + public static final int BYTECODE_VERSION = 32; public static final record BytecodeDSLCompilerResult(PBytecodeDSLRootNode rootNode, BytecodeDSLCodeUnit codeUnit) { } @@ -83,7 +93,96 @@ private static int parseFuture(ModTy mod, EnumSet futureFeatures, } else { return -1; } - return Compiler.parseFuture(stmts, futureFeatures, parserCallbacks); + return parseFuture(stmts, futureFeatures, parserCallbacks); + } + + private static int parseFuture(StmtTy[] modBody, EnumSet futureFeatures, ParserCallbacks parserCallbacks) { + int lastFutureLine = -1; + if (modBody == null || modBody.length == 0) { + return lastFutureLine; + } + boolean done = false; + int prevLine = 0; + int i = 0; + if (findDocstring(modBody) != null) { + i++; + } + + for (; i < modBody.length; i++) { + StmtTy s = modBody[i]; + int line = s.getSourceRange().startLine; + if (done && line > prevLine) { + return lastFutureLine; + } + prevLine = line; + if (s instanceof StmtTy.ImportFrom importFrom) { + if ("__future__".equals(importFrom.module)) { + if (done) { + throw parserCallbacks.onError(ErrorType.Syntax, s.getSourceRange(), "from __future__ imports must occur at the beginning of the file"); + } + parseFutureFeatures(importFrom, futureFeatures, parserCallbacks); + lastFutureLine = line; + } else { + done = true; + } + } else { + done = true; + } + } + return lastFutureLine; + } + + private static void parseFutureFeatures(StmtTy.ImportFrom node, EnumSet features, ParserCallbacks parserCallbacks) { + for (AliasTy alias : node.names) { + if (alias.name != null) { + switch (alias.name) { + case "nested_scopes": + case "generators": + case "division": + case "absolute_import": + case "with_statement": + case "print_function": + case "unicode_literals": + case "generator_stop": + break; + case "barry_as_FLUFL": + features.add(FutureFeature.BARRY_AS_BDFL); + break; + case "annotations": + features.add(FutureFeature.ANNOTATIONS); + break; + case "braces": + throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "not a chance"); + default: + throw parserCallbacks.onError(ErrorType.Syntax, node.getSourceRange(), "future feature %s is not defined", alias.name); + } + } + } + } + + private static Object findDocstring(StmtTy[] body) { + if (body != null && body.length > 0 && body[0] instanceof StmtTy.Expr stmt && stmt.value instanceof ExprTy.Constant expr) { + ConstantValue value = expr.value; + if (value.kind == ConstantValue.Kind.CODEPOINTS) { + return codePointsToTruffleString(value.getCodePoints()); + } + } + return null; + } + + public static Parser createParser(String src, ParserCallbacks errorCb, InputType inputType, boolean interactiveTerminal, boolean allowIncompleteInput) { + EnumSet flags = EnumSet.noneOf(AbstractParser.Flags.class); + if (interactiveTerminal) { + flags.add(AbstractParser.Flags.INTERACTIVE_TERMINAL); + } + if (allowIncompleteInput) { + flags.add(AbstractParser.Flags.ALLOW_INCOMPLETE_INPUT); + } + return createParser(src, errorCb, inputType, flags, PythonLanguage.MINOR); + } + + public static Parser createParser(String src, ParserCallbacks errorCb, InputType inputType, EnumSet flags, int featureVersion) { + return new Parser(src, errorCb, inputType, flags, featureVersion); } public static class BytecodeDSLCompilerContext { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java index 00eafcda8e..e8d3206fe0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java @@ -91,8 +91,6 @@ import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.type.TypeFlags; import com.oracle.graal.python.compiler.CompilationScope; -import com.oracle.graal.python.compiler.Compiler; -import com.oracle.graal.python.compiler.Compiler.ConstantCollection; import com.oracle.graal.python.compiler.OpCodes.CollectionBits; import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; import com.oracle.graal.python.compiler.SSTUtils; @@ -184,6 +182,16 @@ * {@link StatementCompiler}, which does all the heavy lifting. */ public final class RootNodeCompiler implements BaseBytecodeDSLVisitor { + private static final class ConstantCollection { + final Object collection; + final int elementType; + + ConstantCollection(Object collection, int elementType) { + this.collection = collection; + this.elementType = elementType; + } + } + /** * Because a {@link RootNodeCompiler} instance gets reused on reparse, it should be idempotent. * Consequently, most of its fields are final and immutable/not mutated after construction. For @@ -380,6 +388,94 @@ private Object addConstant(Object c) { return c; } + private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements) { + if (elements == null || elements.length == 0) { + return null; + } + + int constantType = -1; + List constants = new ArrayList<>(); + + for (ExprTy e : elements) { + if (e instanceof ExprTy.Constant c) { + if (c.value.kind == ConstantValue.Kind.BOOLEAN) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_BOOLEAN); + constants.add(c.value.getBoolean()); + } else if (c.value.kind == ConstantValue.Kind.LONG) { + long val = c.value.getLong(); + if (val == (int) val) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_INT); + } else { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_LONG); + } + constants.add(val); + } else if (c.value.kind == ConstantValue.Kind.DOUBLE) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_DOUBLE); + constants.add(c.value.getDouble()); + } else if (c.value.kind == ConstantValue.Kind.CODEPOINTS) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constants.add(codePointsToInternedTruffleString(c.value.getCodePoints())); + } else if (c.value.kind == ConstantValue.Kind.NONE) { + constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constants.add(PNone.NONE); + } else { + return null; + } + } else { + return null; + } + } + Object newConstant = null; + switch (constantType) { + case CollectionBits.ELEMENT_OBJECT: + newConstant = constants.toArray(new Object[0]); + break; + case CollectionBits.ELEMENT_INT: { + int[] a = new int[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (int) (long) constants.get(i); + } + newConstant = a; + break; + } + case CollectionBits.ELEMENT_LONG: { + long[] a = new long[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (long) constants.get(i); + } + newConstant = a; + break; + } + case CollectionBits.ELEMENT_BOOLEAN: { + boolean[] a = new boolean[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (boolean) constants.get(i); + } + newConstant = a; + break; + } + case CollectionBits.ELEMENT_DOUBLE: { + double[] a = new double[constants.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = (double) constants.get(i); + } + newConstant = a; + break; + } + } + return new ConstantCollection(newConstant, constantType); + } + + private static int determineConstantType(int existing, int type) { + if (existing == -1 || existing == type) { + return type; + } + if (existing == CollectionBits.ELEMENT_LONG && type == CollectionBits.ELEMENT_INT || existing == CollectionBits.ELEMENT_INT && type == CollectionBits.ELEMENT_LONG) { + return CollectionBits.ELEMENT_LONG; + } + return CollectionBits.ELEMENT_OBJECT; + } + private static TruffleString[] orderedTruffleStringArray(HashMap map) { return orderedKeys(map, PythonUtils.EMPTY_TRUFFLESTRING_ARRAY, PythonUtils::toInternedTruffleStringUncached); } @@ -2682,7 +2778,7 @@ public Void visit(ExprTy.List node) { boolean newStatement = beginSourceSection(node, b); beginTraceLineChecked(b); - ConstantCollection constantCollection = Compiler.tryCollectConstantCollection(node.elements); + ConstantCollection constantCollection = tryCollectConstantCollection(node.elements); if (constantCollection != null) { emitConstantList(constantCollection); } else { @@ -2985,7 +3081,7 @@ public Void visit(ExprTy.Tuple node) { boolean newStatement = beginSourceSection(node, b); beginTraceLineChecked(b); - ConstantCollection constantCollection = Compiler.tryCollectConstantCollection(node.elements); + ConstantCollection constantCollection = tryCollectConstantCollection(node.elements); if (constantCollection != null) { emitConstantTuple(constantCollection); } else { From e059eec4c9df9910bfebdb0aef6aedb24a8c9b37 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 14:33:21 +0200 Subject: [PATCH 07/20] Inline bytecode DSL code metadata classes --- .../oracle/graal/python/PythonLanguage.java | 9 +- .../builtins/modules/ImpModuleBuiltins.java | 6 +- .../modules/MarshalModuleBuiltins.java | 19 +- .../builtins/objects/code/CodeBuiltins.java | 6 +- .../builtins/objects/code/CodeNodes.java | 4 +- .../python/builtins/objects/code/PCode.java | 24 +- .../builtins/objects/function/PFunction.java | 4 +- .../generator/CommonGeneratorBuiltins.java | 4 +- .../objects/generator/PGenerator.java | 9 +- .../objects/module/PythonFrozenModule.java | 6 +- .../objects/superobject/SuperBuiltins.java | 6 +- .../objects/traceback/LazyTraceback.java | 4 +- .../graal/python/compiler/CodeUnit.java | 243 ------------------ .../oracle/graal/python/compiler/OpCodes.java | 6 +- .../python/nodes/bytecode/FrameInfo.java | 84 ------ .../bytecode_dsl/BytecodeDSLCodeUnit.java | 187 +++++++++++++- .../bytecode_dsl/BytecodeDSLFrameInfo.java | 39 ++- .../bytecode_dsl/PBytecodeDSLRootNode.java | 5 +- .../nodes/frame/MaterializeFrameNode.java | 4 +- .../runtime/exception/ExceptionUtils.java | 4 +- 20 files changed, 270 insertions(+), 403 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/FrameInfo.java diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java index f5469fbf0f..3dafa77699 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java @@ -77,7 +77,6 @@ import com.oracle.graal.python.builtins.objects.type.PythonManagedClass; import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.slots.TpSlot; -import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.compiler.ParserCallbacksImpl; import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler; import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler.BytecodeDSLCompilerResult; @@ -563,12 +562,12 @@ protected CallTarget parse(ParsingRequest request) { return parse(context, source, inputType, topLevel, optimize, interactiveTerminal, argumentNames, futureFeatures); } - public RootCallTarget callTargetFromBytecode(Source source, CodeUnit code) { + public RootCallTarget callTargetFromBytecode(Source source, BytecodeDSLCodeUnit code) { return callTargetFromBytecode(source, code, source.isInternal()); } - public RootCallTarget callTargetFromBytecode(Source source, CodeUnit code, boolean isInternal) { - RootNode rootNode = ((BytecodeDSLCodeUnit) code).createRootNode(this, isInternal); + public RootCallTarget callTargetFromBytecode(Source source, BytecodeDSLCodeUnit code, boolean isInternal) { + RootNode rootNode = code.createRootNode(this, isInternal); return PythonUtils.getOrCreateCallTarget(rootNode); } @@ -1122,7 +1121,7 @@ public T createCachedRootNode(Function r return createCachedRootNodeUnsafe(rootNodeFunction, true, nodeClass1, nodeClass2, type, name); } - public T createCachedRootNode(Function rootNodeFunction, CodeUnit key) { + public T createCachedRootNode(Function rootNodeFunction, BytecodeDSLCodeUnit key) { return createCachedRootNodeUnsafe(rootNodeFunction, true, key); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java index be8ad9dc07..6b302d72eb 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ImpModuleBuiltins.java @@ -90,7 +90,7 @@ import com.oracle.graal.python.builtins.objects.module.PythonModule; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.builtins.objects.str.StringNodes; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.lib.PyMemoryViewFromObject; import com.oracle.graal.python.lib.PyObjectGetAttr; import com.oracle.graal.python.lib.PyObjectLookupAttr; @@ -155,12 +155,12 @@ private static class FrozenResult { private static class FrozenInfo { @SuppressWarnings("unused") final TruffleString name; - final CodeUnit code; + final BytecodeDSLCodeUnit code; final boolean isPackage; final TruffleString origName; @SuppressWarnings("unused") final boolean isAlias; - FrozenInfo(TruffleString name, CodeUnit code, boolean isPackage, TruffleString origName, boolean isAlias) { + FrozenInfo(TruffleString name, BytecodeDSLCodeUnit code, boolean isPackage, TruffleString origName, boolean isAlias) { this.name = name; this.code = code; this.isPackage = isPackage; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java index f477b48de2..dac7c22348 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java @@ -100,7 +100,7 @@ import com.oracle.graal.python.builtins.objects.str.PString; import com.oracle.graal.python.builtins.objects.str.StringNodes.IsInternedStringNode; import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.lib.PyComplexCheckExactNode; import com.oracle.graal.python.lib.PyDictCheckExactNode; import com.oracle.graal.python.lib.PyFloatCheckExactNode; @@ -115,7 +115,6 @@ import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.StringLiterals; -import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNodeGen; import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode; @@ -936,7 +935,7 @@ private void writeComplexObject(Object v, int flag) { lnotab = PythonUtils.EMPTY_BYTE_ARRAY; } writeBytes(lnotab); - } else if (v instanceof CodeUnit) { + } else if (v instanceof BytecodeDSLCodeUnit) { writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT | flag); writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) v); } else if (v instanceof Source s) { @@ -1342,7 +1341,7 @@ private Object[] readObjectArray() { return a; } - private CodeUnit readCodeUnit() { + private BytecodeDSLCodeUnit readCodeUnit() { int codeUnitType = readByte(); return switch (codeUnitType) { case TYPE_GRAALPYTHON_CODE_UNIT -> readRemovedCodeUnitPayload(); @@ -1351,7 +1350,7 @@ private CodeUnit readCodeUnit() { }; } - private CodeUnit readRemovedCodeUnitPayload() { + private BytecodeDSLCodeUnit readRemovedCodeUnitPayload() { throw new MarshalError(ValueError, PythonUtils.tsLiteral( "Attempted to deserialize a code object from the removed legacy bytecode interpreter. Consider clearing or setting a different pycache folder.")); @@ -1394,9 +1393,9 @@ private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() { startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, yieldFromGeneratorIndex, instrumentationDataIndex, maxProfileCEventStackSize, provider); } - private void writeCodeUnit(CodeUnit code) throws IOException { + private void writeCodeUnit(BytecodeDSLCodeUnit code) throws IOException { writeByte(TYPE_GRAALPYTHON_DSL_CODE_UNIT); - writeBytecodeDSLCodeUnit((BytecodeDSLCodeUnit) code); + writeBytecodeDSLCodeUnit(code); } private void writeBytecodeDSLCodeUnit(BytecodeDSLCodeUnit code) throws IOException { @@ -1437,7 +1436,7 @@ private void writeBytecodeDSLCodeUnit(BytecodeDSLCodeUnit code) throws IOExcepti private PCode readCode() { TruffleString fileName = readString(true); int flags = readInt(); - CodeUnit code = readCodeUnit(); + BytecodeDSLCodeUnit code = readCodeUnit(); int firstLineNo = readInt(); byte[] lnoTab = readBytes(); com.oracle.graal.python.util.Supplier supplier = () -> { @@ -1460,7 +1459,7 @@ private PCode readCode() { } @TruffleBoundary - public static byte[] serializeCodeUnit(Node locationForRaise, PythonLanguage language, CodeUnit code) { + public static byte[] serializeCodeUnit(Node locationForRaise, PythonLanguage language, BytecodeDSLCodeUnit code) { try { Marshal marshal = new Marshal(language, CURRENT_VERSION); marshal.writeCodeUnit(code); @@ -1475,7 +1474,7 @@ public static byte[] serializeCodeUnit(Node locationForRaise, PythonLanguage lan } @TruffleBoundary - public static CodeUnit deserializeCodeUnit(Node node, PythonLanguage language, byte[] bytes) { + public static BytecodeDSLCodeUnit deserializeCodeUnit(Node node, PythonLanguage language, byte[] bytes) { try { Marshal marshal = new Marshal(language, bytes, bytes.length, 0); return marshal.readCodeUnit(); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java index 5339860227..45236dca11 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeBuiltins.java @@ -57,7 +57,7 @@ import com.oracle.graal.python.builtins.objects.type.TpSlots; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotHashFun.HashBuiltinNode; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotRichCompare.RichCmpBuiltinNode; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.lib.PyBytesCheckNode; import com.oracle.graal.python.lib.PyObjectGetIter; import com.oracle.graal.python.lib.PyObjectHashNode; @@ -385,7 +385,7 @@ private static final class IteratorData { static Object lines(PCode self) { PythonLanguage language = PythonLanguage.get(null); PTuple tuple; - CodeUnit co = self.getCodeUnit(); + BytecodeDSLCodeUnit co = self.getCodeUnit(); if (co != null) { PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); List lines = computeLinesForBytecodeDSLInterpreter(rootNode); @@ -491,7 +491,7 @@ abstract static class CoPositionsNode extends PythonUnaryBuiltinNode { Object positions(PCode self) { PythonLanguage language = PythonLanguage.get(null); PTuple tuple; - CodeUnit co = self.getCodeUnit(); + BytecodeDSLCodeUnit co = self.getCodeUnit(); if (co != null) { List lines = new ArrayList<>(); PBytecodeDSLRootNode rootNode = (PBytecodeDSLRootNode) self.getRootNodeForExtraction(); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java index c3fc35edc2..86cb1164fc 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java @@ -46,7 +46,6 @@ import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.nodes.PNodeWithContext; import com.oracle.graal.python.nodes.PRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; @@ -169,10 +168,9 @@ private static PCode createCode(PythonLanguage language, int argCount, } private static PRootNode deserializeForBytecodeInterpreter(PythonLanguage language, byte[] data, TruffleString[] cellvars, TruffleString[] freevars, int flags) { - CodeUnit codeUnit = MarshalModuleBuiltins.deserializeCodeUnit(null, language, data); RootNode rootNode; - BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) codeUnit; + BytecodeDSLCodeUnit code = MarshalModuleBuiltins.deserializeCodeUnit(null, language, data); if (code.flags != flags) { code = code.withFlags(flags); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java index e596ca97a7..ef47f14d71 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java @@ -53,7 +53,6 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; import com.oracle.graal.python.builtins.objects.tuple.PTuple; -import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.nodes.PRootNode; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; @@ -157,7 +156,7 @@ public PCode(Object cls, Shape instanceShape, RootNode rootNode, Signature signa } private static TruffleString[] extractFreeVars(RootNode rootNode) { - CodeUnit code = getCodeUnit(rootNode); + BytecodeDSLCodeUnit code = getCodeUnit(rootNode); if (code != null) { return Arrays.copyOf(code.freevars, code.freevars.length); } else { @@ -166,7 +165,7 @@ private static TruffleString[] extractFreeVars(RootNode rootNode) { } private static TruffleString[] extractCellVars(RootNode rootNode) { - CodeUnit code = getCodeUnit(rootNode); + BytecodeDSLCodeUnit code = getCodeUnit(rootNode); if (code != null) { return Arrays.copyOf(code.cellvars, code.cellvars.length); } else { @@ -204,7 +203,7 @@ private static String getSourceSectionFileName(SourceSection src) { @TruffleBoundary private static int extractFirstLineno(RootNode rootNode) { RootNode funcRootNode = rootNodeForExtraction(rootNode); - CodeUnit co = getCodeUnit(funcRootNode); + BytecodeDSLCodeUnit co = getCodeUnit(funcRootNode); if (co != null) { if ((co.flags & CO_GRAALPYHON_MODULE) != 0) { return 1; @@ -221,7 +220,7 @@ private static int extractFirstLineno(RootNode rootNode) { @TruffleBoundary private static TruffleString extractName(RootNode rootNode) { - CodeUnit code = getCodeUnit(rootNode); + BytecodeDSLCodeUnit code = getCodeUnit(rootNode); if (code != null) { return code.name; } @@ -236,7 +235,7 @@ private static int extractStackSize(RootNode rootNode) { @TruffleBoundary private static TruffleString[] extractVarnames(RootNode node) { - CodeUnit code = getCodeUnit(node); + BytecodeDSLCodeUnit code = getCodeUnit(node); if (code != null) { return Arrays.copyOf(code.varnames, code.varnames.length); } @@ -245,7 +244,7 @@ private static TruffleString[] extractVarnames(RootNode node) { private Object[] ensureConstants() { if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, constants == null)) { - CodeUnit codeUnit = getCodeUnit(getRootNode()); + BytecodeDSLCodeUnit codeUnit = getCodeUnit(getRootNode()); constants = codeUnit != null ? new Object[codeUnit.constants.length] : PythonUtils.EMPTY_OBJECT_ARRAY; } return constants; @@ -264,7 +263,7 @@ private Object getOrCreateConstant(int index) { @TruffleBoundary private static TruffleString[] extractNames(RootNode node) { - CodeUnit code = getCodeUnit(node); + BytecodeDSLCodeUnit code = getCodeUnit(node); if (code != null) { return Arrays.copyOf(code.names, code.names.length); } @@ -279,14 +278,14 @@ private static RootNode rootNodeForExtraction(RootNode rootNodeArg) { @TruffleBoundary private static int extractFlags(RootNode node) { int flags = 0; - CodeUnit code = getCodeUnit(node); + BytecodeDSLCodeUnit code = getCodeUnit(node); if (code != null) { flags = code.flags; } return flags; } - private static CodeUnit getCodeUnit(RootNode node) { + private static BytecodeDSLCodeUnit getCodeUnit(RootNode node) { RootNode rootNode = rootNodeForExtraction(node); if (rootNode instanceof PBytecodeDSLRootNode bytecodeDSLRootNode) { return bytecodeDSLRootNode.getCodeUnit(); @@ -422,7 +421,7 @@ public byte[] getCodestring(Node node) { } } - public CodeUnit getCodeUnit() { + public BytecodeDSLCodeUnit getCodeUnit() { return getCodeUnit(getRootNode()); } @@ -456,8 +455,7 @@ private PCode createCode(BytecodeDSLCodeUnit codeUnit) { private Object convertConstantToPythonSpace(int index) { Object o = getCodeUnit().constants[index]; PythonLanguage language = PythonLanguage.get(null); - if (o instanceof CodeUnit) { - BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) o; + if (o instanceof BytecodeDSLCodeUnit code) { return getOrCreateChildCode(index, code); } else if (o instanceof BigInteger) { return PFactory.createInt(language, (BigInteger) o); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java index b95a1bbc37..ce45e5abe3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java @@ -42,7 +42,7 @@ import com.oracle.graal.python.builtins.objects.dict.PDict; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.builtins.objects.str.PString; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.lib.PyUnicodeCheckNode; import com.oracle.graal.python.nodes.PRootNode; import com.oracle.graal.python.runtime.GilNode; @@ -155,7 +155,7 @@ public void setDoc(Object doc) { @TruffleBoundary private void extractDoc() { - CodeUnit co = getCode().getCodeUnit(); + BytecodeDSLCodeUnit co = getCode().getCodeUnit(); if (co != null && co.constants.length > 0 && PyUnicodeCheckNode.executeUncached(co.constants[0])) { doc = co.constants[0]; } else { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java index 043cb9310d..c3ce940632 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java @@ -68,7 +68,7 @@ import com.oracle.graal.python.nodes.ErrorMessages; import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.frame.MaterializeFrameNode; import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; @@ -351,7 +351,7 @@ static Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object MaterializedFrame generatorFrame = self.getGeneratorFrame(); PFrame.Reference ref = new PFrame.Reference(rootNode, PFrame.Reference.EMPTY); PFrame pFrame = MaterializeFrameNode.materializeGeneratorFrame(PythonLanguage.get(inliningTarget), location, generatorFrame, self.getGeneratorFunction(), self.getGlobals(), ref); - FrameInfo info = (FrameInfo) generatorFrame.getFrameDescriptor().getInfo(); + BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) generatorFrame.getFrameDescriptor().getInfo(); pFrame.setLine(info.getFirstLineNumber()); Object existingTracebackObj = getTracebackNode.execute(inliningTarget, instance); PTraceback newTraceback = PFactory.createTraceback(language, pFrame, pFrame.getLine(), diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java index 7e60088b0d..869a43c32f 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java @@ -33,8 +33,7 @@ import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; import com.oracle.graal.python.builtins.objects.object.PythonObject; -import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.truffle.api.RootCallTarget; @@ -52,7 +51,7 @@ public class PGenerator extends PythonBuiltinObject { private TruffleString name; private TruffleString qualname; - private final FrameInfo frameInfo; + private final BytecodeDSLFrameInfo frameInfo; private boolean finished; // running means it is currently on the stack, not just started @@ -294,12 +293,12 @@ public final void setQualname(TruffleString qualname) { this.qualname = qualname; } - private CodeUnit getCodeUnit() { + private BytecodeDSLCodeUnit getCodeUnit() { return getBytecodeDSLState().rootNode.getCodeUnit(); } public final boolean isCoroutine() { - CodeUnit codeUnit = getCodeUnit(); + BytecodeDSLCodeUnit codeUnit = getCodeUnit(); return codeUnit.isCoroutine() || codeUnit.isIterableCoroutine(); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java index 8f4353f427..8e23cf4d8b 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/PythonFrozenModule.java @@ -49,14 +49,14 @@ import org.graalvm.nativeimage.ImageInfo; import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.truffle.api.strings.TruffleString; public final class PythonFrozenModule { private final String symbol; private final TruffleString originalName; private final boolean isPackage; - private CodeUnit code; + private BytecodeDSLCodeUnit code; private void initCode() { try { @@ -106,7 +106,7 @@ public TruffleString getOriginalName() { return originalName; } - public CodeUnit getCode() { + public BytecodeDSLCodeUnit getCode() { if (!ImageInfo.inImageCode() && code == null) { initCode(); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java index 4a2e8d5faa..46ba481e1c 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java @@ -87,7 +87,7 @@ import com.oracle.graal.python.nodes.PRaiseNode; import com.oracle.graal.python.nodes.SpecialAttributeNames; import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.classes.IsSubtypeNode; @@ -302,8 +302,8 @@ PNone init(VirtualFrame frame, SuperObject self, @SuppressWarnings("unused") PNo if (bytecodeFrame == null) { throw raiseNode.raise(inliningTarget, RuntimeError, ErrorMessages.SUPER_NO_CLASS); } - FrameInfo frameInfo = (FrameInfo) bytecodeFrame.getFrameDescriptorInfo(); - return initFromNonLocalFrame(frame, inliningTarget, self, (PBytecodeDSLRootNode) frameInfo.getRootNode(), bytecodeFrame, getRefNode, raiseNode); + BytecodeDSLFrameInfo frameInfo = (BytecodeDSLFrameInfo) bytecodeFrame.getFrameDescriptorInfo(); + return initFromNonLocalFrame(frame, inliningTarget, self, frameInfo.getRootNode(), bytecodeFrame, getRefNode, raiseNode); } private PNone initFromLocalFrame(VirtualFrame frame, Node inliningTarget, SuperObject self, BytecodeNode bytecodeNode, CellBuiltins.GetRefNode getRefNode, diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/LazyTraceback.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/LazyTraceback.java index b4f1b9e9ca..4d80e33710 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/LazyTraceback.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/traceback/LazyTraceback.java @@ -44,7 +44,7 @@ import com.oracle.graal.python.builtins.objects.frame.PFrame; import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.runtime.exception.PException; import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.TruffleStackTraceElement; @@ -155,7 +155,7 @@ public static boolean elementWantedForTraceback(TruffleStackTraceElement element if (frame != null) { // only include frames of non-builtin python functions Object info = frame.getFrameDescriptor().getInfo(); - if (info instanceof FrameInfo frameInfo) { + if (info instanceof BytecodeDSLFrameInfo frameInfo) { return frameInfo.includeInTraceback(); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java deleted file mode 100644 index 71e4c4fc0b..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CodeUnit.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2021, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import static com.oracle.graal.python.util.PythonUtils.isInterned; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.oracle.graal.python.builtins.objects.code.PCode; -import com.oracle.graal.python.builtins.objects.function.Signature; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.RootNode; -import com.oracle.truffle.api.source.Source; -import com.oracle.truffle.api.source.SourceSection; -import com.oracle.truffle.api.strings.TruffleString; - -/** - * A context and language/engine-independent representation of code for bytecode interpreter. - * Contains the actual bytecode and all the related data, like constants or exception handler - * ranges. It doesn't contain the filename to make it easier to keep in native images. - */ -public abstract class CodeUnit { - public final TruffleString name; - public final TruffleString qualname; - - public final int argCount; - public final int kwOnlyArgCount; - public final int positionalOnlyArgCount; - - public final int flags; - - @CompilationFinal(dimensions = 1) public final TruffleString[] names; - @CompilationFinal(dimensions = 1) public final TruffleString[] varnames; - @CompilationFinal(dimensions = 1) public final TruffleString[] cellvars; - @CompilationFinal(dimensions = 1) public final TruffleString[] freevars; - @CompilationFinal(dimensions = 1) public final int[] cell2arg; - @CompilationFinal(dimensions = 1) public final int[] arg2cell; - - @CompilationFinal(dimensions = 1) public final Object[] constants; - - public final int startLine; - public final int startColumn; - public final int endLine; - public final int endColumn; - - public CodeUnit(TruffleString name, TruffleString qualname, - int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int flags, - TruffleString[] names, TruffleString[] varnames, TruffleString[] cellvars, - TruffleString[] freevars, int[] cell2arg, Object[] constants, int startLine, int startColumn, - int endLine, int endColumn) { - assert isInterned(name); - this.name = name; - assert qualname == null || isInterned(qualname); - this.qualname = qualname != null ? qualname : name; - this.argCount = argCount; - this.kwOnlyArgCount = kwOnlyArgCount; - this.positionalOnlyArgCount = positionalOnlyArgCount; - this.flags = flags; - assert isInterned(names); - this.names = names; - assert isInterned(varnames); - this.varnames = varnames; - assert isInterned(cellvars); - this.cellvars = cellvars; - assert isInterned(freevars); - this.freevars = freevars; - this.cell2arg = cell2arg; - int[] arg2cellValue = null; - if (cell2arg != null) { - arg2cellValue = new int[getTotalArgCount()]; - Arrays.fill(arg2cellValue, -1); - for (int i = 0; i < cell2arg.length; i++) { - if (cell2arg[i] >= 0) { - arg2cellValue[cell2arg[i]] = i; - } - } - } - this.arg2cell = arg2cellValue; - this.constants = constants; - - this.startLine = startLine; - this.startColumn = startColumn; - this.endLine = endLine; - this.endColumn = endColumn; - } - - public SourceSection getSourceSection(Source source) { - if (!source.hasCharacters()) { - return source.createUnavailableSection(); - } - try { - int truffleStartColumn = Math.max(startColumn + 1, 1); - int truffleEndColumn = Math.max(endColumn + 1, 1); - if (truffleEndColumn == source.getLineLength(endLine) + 1) { - truffleEndColumn--; - } - return source.createSection(startLine, truffleStartColumn, endLine, truffleEndColumn); - } catch (IllegalArgumentException e) { - // TODO GR-40896 we don't track source ranges of f-strings correctly - // Also consider sources created from ast module - return source.createUnavailableSection(); - } - } - - public boolean takesVarKeywordArgs() { - return (flags & PCode.CO_VARKEYWORDS) != 0; - } - - public boolean takesVarArgs() { - return (flags & PCode.CO_VARARGS) != 0; - } - - public boolean isGenerator() { - return (flags & PCode.CO_GENERATOR) != 0; - } - - public boolean isCoroutine() { - return (flags & PCode.CO_COROUTINE) != 0; - } - - public boolean isAsyncGenerator() { - return (flags & PCode.CO_ASYNC_GENERATOR) != 0; - } - - public boolean isIterableCoroutine() { - return (flags & PCode.CO_ITERABLE_COROUTINE) != 0; - } - - public boolean isGeneratorOrCoroutine() { - return (flags & (PCode.CO_GENERATOR | PCode.CO_COROUTINE | PCode.CO_ASYNC_GENERATOR | PCode.CO_ITERABLE_COROUTINE)) != 0; - } - - public int getRegularArgCount() { - return argCount + positionalOnlyArgCount + kwOnlyArgCount; - } - - public int getTotalArgCount() { - int count = getRegularArgCount(); - if (takesVarArgs()) { - count++; - } - if (takesVarKeywordArgs()) { - count++; - } - return count; - } - - public final Signature computeSignature() { - int posArgCount = argCount + positionalOnlyArgCount; - TruffleString[] parameterNames = Arrays.copyOf(varnames, posArgCount); - TruffleString[] kwOnlyNames = Arrays.copyOfRange(varnames, posArgCount, posArgCount + kwOnlyArgCount); - int varArgsIndex = takesVarArgs() ? posArgCount : -1; - return new Signature(positionalOnlyArgCount, - takesVarKeywordArgs(), - varArgsIndex, - parameterNames, - kwOnlyNames); - } - - @Override - public String toString() { - return toString(false, null); - } - - protected abstract void dumpBytecode(StringBuilder sb, boolean optimized, RootNode rootNode); - - /** - * @param optimized Whether to print the initial state of the bytecode or current state, if - * available, where some instructions may be transformed, e.g., quickened. - * @param rootNode The root node if available (Bytecode DSL code unit may contain just - * serialized code). - */ - public String toString(boolean optimized, RootNode rootNode) { - StringBuilder sb = new StringBuilder(); - - sb.append("Disassembly of ").append(qualname).append(":\n"); - - List flagNames = new ArrayList<>(); - if (isGenerator()) { - flagNames.add("CO_GENERATOR"); - } - if (isCoroutine()) { - flagNames.add("CO_COROUTINE"); - } - if (isAsyncGenerator()) { - flagNames.add("CO_ASYNC_GENERATOR"); - } - if (!flagNames.isEmpty()) { - sb.append("Flags: ").append(String.join(" | ", flagNames)).append("\n"); - } - - dumpBytecode(sb, optimized, rootNode); - - for (Object c : constants) { - if (c instanceof CodeUnit cd) { - sb.append('\n'); - sb.append(cd.toString(optimized, null)); - } - } - - return sb.toString(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java index 6b9baf13a2..a483606073 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, 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 @@ -590,9 +590,9 @@ public enum OpCodes { CLOSURE_FROM_STACK(1, (oparg, followingArgs, withJump) -> oparg, 1), /** * Creates a function object. The first immediate argument is an index to the constants array - * that determines the {@link CodeUnit} object that will provide the function's code. + * that determines the {@link BytecodeDSLCodeUnit} object that will provide the function's code. * - * Pops: The second immediate arguments contains flags (defined in {@link CodeUnit}) that + * Pops: The second immediate arguments contains flags (defined in {@link BytecodeDSLCodeUnit}) that * determine whether it will need to pop (in this order): closure, annotations, keyword only * defaults, defaults. * diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/FrameInfo.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/FrameInfo.java deleted file mode 100644 index 9e8e4c7f3e..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/FrameInfo.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.truffle.api.dsl.Idempotent; -import com.oracle.truffle.api.frame.FrameDescriptor; -import com.oracle.truffle.api.strings.TruffleString; - -/** - * Carries additional metadata for introspection of frames used by the bytecode interpreter. It's - * returned by {@link FrameDescriptor#getInfo()} if and only if the frame is coming from the - * bytecode interpreter. - */ -public interface FrameInfo { - - public PRootNode getRootNode(); - - public int getFirstLineNumber(); - - public boolean includeInTraceback(); - - public CodeUnit getCodeUnit(); - - @Idempotent - public default int getVariableCount() { - CodeUnit code = getCodeUnit(); - return code.varnames.length + code.cellvars.length + code.freevars.length; - } - - public default int getRegularVariableCount() { - return getCodeUnit().varnames.length; - } - - public default TruffleString getVariableName(int slot) { - CodeUnit code = getCodeUnit(); - if (slot < code.varnames.length) { - return code.varnames[slot]; - } else if (slot < code.varnames.length + code.cellvars.length) { - return code.cellvars[slot - code.varnames.length]; - } else { - return code.freevars[slot - code.varnames.length - code.cellvars.length]; - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java index 53d1ec073c..7dffb219c0 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java @@ -40,14 +40,52 @@ */ package com.oracle.graal.python.nodes.bytecode_dsl; +import static com.oracle.graal.python.util.PythonUtils.isInterned; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.compiler.CodeUnit; +import com.oracle.graal.python.builtins.objects.code.PCode; +import com.oracle.graal.python.builtins.objects.function.Signature; import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.nodes.RootNode; +import com.oracle.truffle.api.source.Source; +import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.strings.TruffleString; -public final class BytecodeDSLCodeUnit extends CodeUnit { +/** + * A context and language/engine-independent representation of code for the bytecode DSL + * interpreter. Contains the bytecode supplier and related data, like constants and local variable + * names. It doesn't contain the filename to make it easier to keep in native images. + */ +public final class BytecodeDSLCodeUnit { + public final TruffleString name; + public final TruffleString qualname; + + public final int argCount; + public final int kwOnlyArgCount; + public final int positionalOnlyArgCount; + + public final int flags; + + @CompilationFinal(dimensions = 1) public final TruffleString[] names; + @CompilationFinal(dimensions = 1) public final TruffleString[] varnames; + @CompilationFinal(dimensions = 1) public final TruffleString[] cellvars; + @CompilationFinal(dimensions = 1) public final TruffleString[] freevars; + @CompilationFinal(dimensions = 1) public final int[] cell2arg; + @CompilationFinal(dimensions = 1) public final int[] arg2cell; + + @CompilationFinal(dimensions = 1) public final Object[] constants; + + public final int startLine; + public final int startColumn; + public final int endLine; + public final int endColumn; + public final int classcellIndex; public final int selfIndex; public final int yieldFromGeneratorIndex; @@ -58,7 +96,39 @@ public final class BytecodeDSLCodeUnit extends CodeUnit { public BytecodeDSLCodeUnit(TruffleString name, TruffleString qualname, int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int flags, TruffleString[] names, TruffleString[] varnames, TruffleString[] cellvars, TruffleString[] freevars, int[] cell2arg, Object[] constants, int startLine, int startColumn, int endLine, int endColumn, int classcellIndex, int selfIndex, int yieldFromGeneratorIndex, int instrumentationDataIndex, int maxProfileCEventStackSize, BytecodeSupplier supplier) { - super(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, cell2arg, constants, startLine, startColumn, endLine, endColumn); + assert isInterned(name); + this.name = name; + assert qualname == null || isInterned(qualname); + this.qualname = qualname != null ? qualname : name; + this.argCount = argCount; + this.kwOnlyArgCount = kwOnlyArgCount; + this.positionalOnlyArgCount = positionalOnlyArgCount; + this.flags = flags; + assert isInterned(names); + this.names = names; + assert isInterned(varnames); + this.varnames = varnames; + assert isInterned(cellvars); + this.cellvars = cellvars; + assert isInterned(freevars); + this.freevars = freevars; + this.cell2arg = cell2arg; + int[] arg2cellValue = null; + if (cell2arg != null) { + arg2cellValue = new int[getTotalArgCount()]; + Arrays.fill(arg2cellValue, -1); + for (int i = 0; i < cell2arg.length; i++) { + if (cell2arg[i] >= 0) { + arg2cellValue[cell2arg[i]] = i; + } + } + } + this.arg2cell = arg2cellValue; + this.constants = constants; + this.startLine = startLine; + this.startColumn = startColumn; + this.endLine = endLine; + this.endColumn = endColumn; this.classcellIndex = classcellIndex; this.selfIndex = selfIndex; this.supplier = supplier; @@ -102,13 +172,122 @@ public TruffleString getDocstring() { return null; } + public SourceSection getSourceSection(Source source) { + if (!source.hasCharacters()) { + return source.createUnavailableSection(); + } + try { + int truffleStartColumn = Math.max(startColumn + 1, 1); + int truffleEndColumn = Math.max(endColumn + 1, 1); + if (truffleEndColumn == source.getLineLength(endLine) + 1) { + truffleEndColumn--; + } + return source.createSection(startLine, truffleStartColumn, endLine, truffleEndColumn); + } catch (IllegalArgumentException e) { + // TODO GR-40896 we don't track source ranges of f-strings correctly + // Also consider sources created from ast module + return source.createUnavailableSection(); + } + } + + public boolean takesVarKeywordArgs() { + return (flags & PCode.CO_VARKEYWORDS) != 0; + } + + public boolean takesVarArgs() { + return (flags & PCode.CO_VARARGS) != 0; + } + + public boolean isGenerator() { + return (flags & PCode.CO_GENERATOR) != 0; + } + + public boolean isCoroutine() { + return (flags & PCode.CO_COROUTINE) != 0; + } + + public boolean isAsyncGenerator() { + return (flags & PCode.CO_ASYNC_GENERATOR) != 0; + } + + public boolean isIterableCoroutine() { + return (flags & PCode.CO_ITERABLE_COROUTINE) != 0; + } + + public boolean isGeneratorOrCoroutine() { + return (flags & (PCode.CO_GENERATOR | PCode.CO_COROUTINE | PCode.CO_ASYNC_GENERATOR | PCode.CO_ITERABLE_COROUTINE)) != 0; + } + + public int getRegularArgCount() { + return argCount + positionalOnlyArgCount + kwOnlyArgCount; + } + + public int getTotalArgCount() { + int count = getRegularArgCount(); + if (takesVarArgs()) { + count++; + } + if (takesVarKeywordArgs()) { + count++; + } + return count; + } + + public Signature computeSignature() { + int posArgCount = argCount + positionalOnlyArgCount; + TruffleString[] parameterNames = Arrays.copyOf(varnames, posArgCount); + TruffleString[] kwOnlyNames = Arrays.copyOfRange(varnames, posArgCount, posArgCount + kwOnlyArgCount); + int varArgsIndex = takesVarArgs() ? posArgCount : -1; + return new Signature(positionalOnlyArgCount, + takesVarKeywordArgs(), + varArgsIndex, + parameterNames, + kwOnlyNames); + } + @Override - protected void dumpBytecode(StringBuilder sb, boolean optimized, RootNode rootNode) { + public String toString() { + return toString(false, null); + } + + /** + * @param optimized Whether to print the initial state of the bytecode or current state, if + * available, where some instructions may be transformed, e.g., quickened. + * @param rootNode The root node if available. + */ + public String toString(boolean optimized, RootNode rootNode) { + StringBuilder sb = new StringBuilder(); + + sb.append("Disassembly of ").append(qualname).append(":\n"); + + List flagNames = new ArrayList<>(); + if (isGenerator()) { + flagNames.add("CO_GENERATOR"); + } + if (isCoroutine()) { + flagNames.add("CO_COROUTINE"); + } + if (isAsyncGenerator()) { + flagNames.add("CO_ASYNC_GENERATOR"); + } + if (!flagNames.isEmpty()) { + sb.append("Flags: ").append(String.join(" | ", flagNames)).append("\n"); + } + if (rootNode instanceof PBytecodeDSLRootNode dslRoot) { sb.append(dslRoot.dump()); sb.append('\n'); } else { sb.append("bytecode not available\n"); } + + for (Object c : constants) { + if (c instanceof BytecodeDSLCodeUnit cd) { + sb.append('\n'); + sb.append(cd.toString(optimized, null)); + } + } + + return sb.toString(); } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLFrameInfo.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLFrameInfo.java index c7c37e60b3..c37704dff8 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLFrameInfo.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLFrameInfo.java @@ -40,11 +40,17 @@ */ package com.oracle.graal.python.nodes.bytecode_dsl; -import com.oracle.graal.python.compiler.CodeUnit; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.dsl.Idempotent; +import com.oracle.truffle.api.frame.FrameDescriptor; +import com.oracle.truffle.api.strings.TruffleString; -public class BytecodeDSLFrameInfo implements FrameInfo { +/** + * Carries additional metadata for introspection of frames used by the bytecode DSL interpreter. + * It's returned by {@link FrameDescriptor#getInfo()} if and only if the frame is coming from the + * bytecode DSL interpreter. + */ +public class BytecodeDSLFrameInfo { @CompilationFinal PBytecodeDSLRootNode rootNode; /** @@ -55,23 +61,40 @@ void setRootNode(PBytecodeDSLRootNode rootNode) { this.rootNode = rootNode; } - @Override public PBytecodeDSLRootNode getRootNode() { return rootNode; } - @Override public int getFirstLineNumber() { return rootNode.getFirstLineno(); } - @Override - public CodeUnit getCodeUnit() { + public BytecodeDSLCodeUnit getCodeUnit() { return rootNode.getCodeUnit(); } - @Override public boolean includeInTraceback() { return !rootNode.isInternal(); } + + @Idempotent + public int getVariableCount() { + BytecodeDSLCodeUnit code = getCodeUnit(); + return code.varnames.length + code.cellvars.length + code.freevars.length; + } + + public int getRegularVariableCount() { + return getCodeUnit().varnames.length; + } + + public TruffleString getVariableName(int slot) { + BytecodeDSLCodeUnit code = getCodeUnit(); + if (slot < code.varnames.length) { + return code.varnames[slot]; + } else if (slot < code.varnames.length + code.cellvars.length) { + return code.cellvars[slot - code.varnames.length]; + } else { + return code.freevars[slot - code.varnames.length - code.cellvars.length]; + } + } } 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 2198e1cf68..5022d4348d 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 @@ -120,7 +120,6 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.CallSlotDescrGet; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.CallSlotTpIterNextNode; import com.oracle.graal.python.builtins.objects.typing.PTypeAliasType; -import com.oracle.graal.python.compiler.CodeUnit; import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; import com.oracle.graal.python.compiler.ParserCallbacksImpl; import com.oracle.graal.python.lib.IteratorExhausted; @@ -1301,7 +1300,7 @@ private static Object checkUnboundCell(PCell cell, int index, BytecodeNode bytec Object result = cell.getRef(); if (result == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); - CodeUnit codeUnit = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit(); + BytecodeDSLCodeUnit codeUnit = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit(); if (index < codeUnit.cellvars.length) { TruffleString localName = codeUnit.cellvars[index]; throw PRaiseNode.raiseStatic(bytecodeNode, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName); @@ -3139,7 +3138,7 @@ public static Object doLoadCell(VirtualFrame frame, int index, Object locals, PC @Bind BytecodeNode bytecodeNode, @Bind Node inliningTarget, @Cached ReadFromLocalsNode readLocalsNode) { - CodeUnit co = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit(); + BytecodeDSLCodeUnit co = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit(); TruffleString name; if (index < co.cellvars.length) { name = co.cellvars[index]; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java index 97cf0fa312..a80beb04d6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java @@ -47,7 +47,7 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.runtime.CallerFlags; import com.oracle.graal.python.runtime.object.PFactory; @@ -312,7 +312,7 @@ static void doGenerator(PFrame pyFrame, Frame frameToSync, @SuppressWarnings("un @Idempotent protected static int variableSlotCount(FrameDescriptor fd) { - FrameInfo info = (FrameInfo) fd.getInfo(); + BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) fd.getInfo(); if (info == null) { return 0; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java index bef449d415..1b2ee81929 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/ExceptionUtils.java @@ -62,7 +62,7 @@ import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode; import com.oracle.graal.python.nodes.BuiltinNames; import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.bytecode.FrameInfo; +import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.call.CallNode; import com.oracle.graal.python.nodes.exception.TopLevelExceptionHandler; import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; @@ -123,7 +123,7 @@ private static ArrayList getStackTraceElements() { } private static int getLineno(Frame frame, Node location, FrameInstance frameInstance) { - if (frame != null && frame.getFrameDescriptor().getInfo() instanceof FrameInfo frameInfo) { + if (frame != null && frame.getFrameDescriptor().getInfo() instanceof BytecodeDSLFrameInfo frameInfo) { BytecodeNode bytecodeNode; if (frameInstance != null) { bytecodeNode = BytecodeNode.get(frameInstance); From f3d28ce45f5143b4b9f202231812500eea83b39c Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 14:43:56 +0200 Subject: [PATCH 08/20] Remove bytecode cell argument maps --- .../modules/MarshalModuleBuiltins.java | 11 +---------- .../bytecode_dsl/BytecodeDSLCompiler.java | 2 +- .../bytecode_dsl/RootNodeCompiler.java | 8 -------- .../bytecode_dsl/BytecodeDSLCodeUnit.java | 19 ++----------------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java index dac7c22348..5e3a8c62f3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java @@ -1373,10 +1373,6 @@ private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() { TruffleString[] varnames = readStringArray(true); TruffleString[] cellvars = readStringArray(true); TruffleString[] freevars = readStringArray(true); - int[] cell2arg = readIntArray(); - if (cell2arg.length == 0) { - cell2arg = null; - } Object[] constants = readObjectArray(); int startLine = readInt(); int startColumn = readInt(); @@ -1389,7 +1385,7 @@ private BytecodeDSLCodeUnit readBytecodeDSLCodeUnit() { int maxProfileCEventStackSize = readInt(); BytecodeSupplier provider = new BytecodeSupplier(serialized, bytecodeFile, sourceReference, bytecodeOffset, bytecodeSize, cacheKey); - return new BytecodeDSLCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, cell2arg, constants, + return new BytecodeDSLCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, names, varnames, cellvars, freevars, constants, startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, yieldFromGeneratorIndex, instrumentationDataIndex, maxProfileCEventStackSize, provider); } @@ -1416,11 +1412,6 @@ private void writeBytecodeDSLCodeUnit(BytecodeDSLCodeUnit code) throws IOExcepti writeStringArray(code.varnames); writeStringArray(code.cellvars); writeStringArray(code.freevars); - if (code.cell2arg != null) { - writeIntArray(code.cell2arg); - } else { - writeIntArray(PythonUtils.EMPTY_INT_ARRAY); - } writeObjectArray(code.constants); writeInt(code.startLine); writeInt(code.startColumn); diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java index 81a0b9f699..3f896aafdd 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java @@ -66,7 +66,7 @@ import com.oracle.truffle.api.source.Source; public class BytecodeDSLCompiler { - public static final int BYTECODE_VERSION = 32; + public static final int BYTECODE_VERSION = 33; public static final record BytecodeDSLCompilerResult(PBytecodeDSLRootNode rootNode, BytecodeDSLCodeUnit codeUnit) { } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java index e8d3206fe0..06672de1c3 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java @@ -218,7 +218,6 @@ private static final class ConstantCollection { private final HashMap varnames; private final HashMap cellvars; private final HashMap freevars; - private final int[] cell2arg; private final String selfCellName; // Updated idempotently: the keys are filled during first parsing, on subsequent parsings the @@ -326,22 +325,16 @@ public RootNodeCompiler(BytecodeDSLCompilerContext ctx, RootNodeCompiler parent, this.freevars = scope.getSymbolsByType(EnumSet.of(Scope.DefUse.Free, Scope.DefUse.DefFreeClass), 0); - int[] cell2argValue = new int[cellvars.size()]; - boolean hasArgCell = false; - Arrays.fill(cell2argValue, -1); String selfCellNameValue = null; for (String cellvar : cellvars.keySet()) { if (varnames.containsKey(cellvar)) { int argIndex = varnames.get(cellvar); - cell2argValue[cellvars.get(cellvar)] = argIndex; - hasArgCell = true; if (argIndex == 0) { assert selfCellNameValue == null; selfCellNameValue = cellvar; } } } - this.cell2arg = hasArgCell ? cell2argValue : null; this.selfCellName = selfCellNameValue; } @@ -557,7 +550,6 @@ flags, orderedTruffleStringArray(names), orderedTruffleStringArray(varnames), orderedTruffleStringArray(cellvars), orderedTruffleStringArray(freevars), - cell2arg, orderedKeys(constants, new Object[0]), sourceRange.startLine, sourceRange.startColumn, diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java index 7dffb219c0..fc8c32e0ea 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java @@ -76,9 +76,6 @@ public final class BytecodeDSLCodeUnit { @CompilationFinal(dimensions = 1) public final TruffleString[] varnames; @CompilationFinal(dimensions = 1) public final TruffleString[] cellvars; @CompilationFinal(dimensions = 1) public final TruffleString[] freevars; - @CompilationFinal(dimensions = 1) public final int[] cell2arg; - @CompilationFinal(dimensions = 1) public final int[] arg2cell; - @CompilationFinal(dimensions = 1) public final Object[] constants; public final int startLine; @@ -94,7 +91,7 @@ public final class BytecodeDSLCodeUnit { private final BytecodeSupplier supplier; public BytecodeDSLCodeUnit(TruffleString name, TruffleString qualname, int argCount, int kwOnlyArgCount, int positionalOnlyArgCount, int flags, TruffleString[] names, TruffleString[] varnames, - TruffleString[] cellvars, TruffleString[] freevars, int[] cell2arg, Object[] constants, int startLine, int startColumn, int endLine, int endColumn, + TruffleString[] cellvars, TruffleString[] freevars, Object[] constants, int startLine, int startColumn, int endLine, int endColumn, int classcellIndex, int selfIndex, int yieldFromGeneratorIndex, int instrumentationDataIndex, int maxProfileCEventStackSize, BytecodeSupplier supplier) { assert isInterned(name); this.name = name; @@ -112,18 +109,6 @@ public BytecodeDSLCodeUnit(TruffleString name, TruffleString qualname, int argCo this.cellvars = cellvars; assert isInterned(freevars); this.freevars = freevars; - this.cell2arg = cell2arg; - int[] arg2cellValue = null; - if (cell2arg != null) { - arg2cellValue = new int[getTotalArgCount()]; - Arrays.fill(arg2cellValue, -1); - for (int i = 0; i < cell2arg.length; i++) { - if (cell2arg[i] >= 0) { - arg2cellValue[cell2arg[i]] = i; - } - } - } - this.arg2cell = arg2cellValue; this.constants = constants; this.startLine = startLine; this.startColumn = startColumn; @@ -145,7 +130,7 @@ public abstract static class BytecodeSupplier { public BytecodeDSLCodeUnit withFlags(int flags) { return new BytecodeDSLCodeUnit(name, qualname, argCount, kwOnlyArgCount, positionalOnlyArgCount, flags, - names, varnames, cellvars, freevars, cell2arg, constants, + names, varnames, cellvars, freevars, constants, startLine, startColumn, endLine, endColumn, classcellIndex, selfIndex, yieldFromGeneratorIndex, instrumentationDataIndex, maxProfileCEventStackSize, supplier); } From 6d71877d8853e512b47c509c888db97ee57b7066 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 14:59:30 +0200 Subject: [PATCH 09/20] Cleanup PGenerator --- .../builtins/objects/asyncio/PAsyncGen.java | 3 +- .../builtins/objects/function/PArguments.java | 4 +- .../generator/CommonGeneratorBuiltins.java | 8 +- .../objects/generator/PGenerator.java | 106 +++++------------- .../bytecode_dsl/PBytecodeDSLRootNode.java | 4 +- .../graal/python/runtime/object/PFactory.java | 13 +-- 6 files changed, 41 insertions(+), 97 deletions(-) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java index 081ed1d10a..acef3c6615 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/PAsyncGen.java @@ -54,8 +54,7 @@ public final class PAsyncGen extends PGenerator { private boolean runningAsync = false; public PAsyncGen(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { - super(language, function, continuationFrame, PythonBuiltinClassType.PAsyncGenerator, - new BytecodeDSLState(rootNode, continuationFrame.getArguments(), continuationRootNode)); + super(language, function, continuationFrame, PythonBuiltinClassType.PAsyncGenerator, rootNode, continuationRootNode); } public boolean isClosed() { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java index ae37c1a3ab..5bead17104 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java @@ -49,9 +49,7 @@ *
  • Function calls: non-variadic arguments as individual items in order of {@code co_varnames}, * then varargs as {@code Object[]} iff the function takes them, then variadic keywords as * {@code PKeyword[]} iff the function takes them. Implemented by {@link CreateArgumentsNode}
  • - *
  • Generator resumes (non-DSL): generator frame ({@code MaterializedFrame}), then the send value - * or null
  • - *
  • Generator resumes (DSL): doesn't use PArguments to call the continuation root
  • + *
  • Generator resumes: don't use PArguments to call the continuation root
  • * * * diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java index c3ce940632..70bc7942c9 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/CommonGeneratorBuiltins.java @@ -183,7 +183,7 @@ static Object cachedBytecodeDSL(VirtualFrame frame, Node inliningTarget, PGenera self.setRunning(false); } if (generatorResult instanceof ContinuationResult continuation) { - return handleResult(inliningTarget, self, continuation); + return self.handleResult(continuation); } else { returnProfile.enter(inliningTarget); throw handleReturn(inliningTarget, self, generatorResult); @@ -231,7 +231,7 @@ static Object genericBytecodeDSL(VirtualFrame frame, Node inliningTarget, PGener self.setRunning(false); } if (generatorResult instanceof ContinuationResult continuation) { - return handleResult(inliningTarget, self, continuation); + return self.handleResult(continuation); } else { returnProfile.enter(inliningTarget); throw handleReturn(inliningTarget, self, generatorResult); @@ -252,10 +252,6 @@ private static PException handleException(PGenerator self, Node inliningTarget, throw raiseNode.raiseWithCause(inliningTarget, RuntimeError, e, ErrorMessages.GENERATOR_RAISED_STOPITER); } - private static Object handleResult(Node node, PGenerator self, Object result) { - return self.handleResult(PythonLanguage.get(node), result); - } - private static PException handleReturn(Node inliningTarget, PGenerator self, Object returnValue) { self.markAsFinished(); if (self.isAsyncGen()) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java index 869a43c32f..527eb31b09 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/PGenerator.java @@ -28,7 +28,6 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.objects.code.PCode; import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PFunction; import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; @@ -51,54 +50,26 @@ public class PGenerator extends PythonBuiltinObject { private TruffleString name; private TruffleString qualname; - private final BytecodeDSLFrameInfo frameInfo; private boolean finished; // running means it is currently on the stack, not just started private boolean running; - private PCode code; - private final MaterializedFrame frame; private final PythonObject globals; private final PFunction generatorFunction; + private final PBytecodeDSLRootNode rootNode; + private ContinuationRootNode prevContinuationRootNode; + private ContinuationRootNode continuationRootNode; + private boolean isStarted; - public static class BytecodeDSLState { - private final PBytecodeDSLRootNode rootNode; - private final Object[] arguments; - private ContinuationRootNode prevContinuationRootNode; - private ContinuationRootNode continuationRootNode; - private boolean isStarted; - - public BytecodeDSLState(PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode) { - this.rootNode = rootNode; - this.arguments = arguments; - this.continuationRootNode = continuationRootNode; - } - - public Object handleResult(PGenerator generator, ContinuationResult result) { - assert PBytecodeDSLRootNode.cast(result.getContinuationRootNode()).getFrameDescriptor() == generator.frame.getFrameDescriptor(); - isStarted = true; - // We must keep the previous root so that we can load its BytecodeNode to resolve BCI to - // location, the next continuation node may have different BytecodeNode - prevContinuationRootNode = continuationRootNode; - continuationRootNode = result.getContinuationRootNode(); - return result.getResult(); - } - } - - private final BytecodeDSLState state; - - private BytecodeDSLState getBytecodeDSLState() { - return state; - } - - public static PGenerator create(PythonLanguage lang, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, + public static PGenerator create(PythonLanguage lang, PFunction function, PBytecodeDSLRootNode rootNode, PythonBuiltinClassType cls, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { - return new PGenerator(lang, function, continuationFrame, cls, new BytecodeDSLState(rootNode, arguments, continuationRootNode)); + return new PGenerator(lang, function, continuationFrame, cls, rootNode, continuationRootNode); } - protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame frame, PythonBuiltinClassType cls, BytecodeDSLState state) { + protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame frame, PythonBuiltinClassType cls, + PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode) { super(cls, cls.getInstanceShape(lang)); this.name = function.getName(); this.qualname = function.getQualname(); @@ -106,13 +77,8 @@ protected PGenerator(PythonLanguage lang, PFunction function, MaterializedFrame this.generatorFunction = function; this.frame = frame; this.finished = false; - this.state = state; - this.frameInfo = (BytecodeDSLFrameInfo) state.rootNode.getFrameDescriptor().getInfo(); - } - - public Object[] getCallArguments(Object sendValue) { - prepareResume(); - return getBytecodeDSLState().arguments; + this.rootNode = rootNode; + this.continuationRootNode = continuationRootNode; } public Object[] prepareResume() { @@ -123,7 +89,7 @@ public Object[] prepareResume() { } public ContinuationRootNode getBytecodeDSLContinuationRootNode() { - return getBytecodeDSLState().continuationRootNode; + return continuationRootNode; } /** @@ -165,10 +131,6 @@ public static boolean isGeneratorFrame(Frame frame) { return frameInfo instanceof BytecodeDSLFrameInfo info && info.getCodeUnit().isGeneratorOrCoroutine() && frame.getArguments()[0] instanceof MaterializedFrame; } - public static MaterializedFrame getGeneratorFrame(Object[] arguments) { - return (MaterializedFrame) PArguments.getArgument(arguments, 0); - } - public static MaterializedFrame getGeneratorFrame(Frame frame) { assert isGeneratorFrame(frame); return (MaterializedFrame) frame; @@ -191,23 +153,22 @@ public static Object getSendValue(Object[] arguments) { } public RootNode getRootNode() { - return getBytecodeDSLState().rootNode; + return rootNode; } /** * Returns the call target that should be used the next time the generator is called. */ public RootCallTarget getCurrentCallTarget() { - return getBytecodeDSLState().continuationRootNode.getCallTarget(); + return continuationRootNode.getCallTarget(); } public BytecodeNode getBytecodeNode() { assert !running; // When it is running, we must use stack walking to get the location - BytecodeDSLState state = getBytecodeDSLState(); - if (state.isStarted) { - return state.prevContinuationRootNode.getLocation().getBytecodeNode(); + if (isStarted) { + return prevContinuationRootNode.getLocation().getBytecodeNode(); } else { - return state.rootNode.getBytecodeNode(); + return rootNode.getBytecodeNode(); } } @@ -216,23 +177,12 @@ public BytecodeNode getBytecodeNode() { * node. */ public BytecodeNode getContinuationBytecodeNode() { - BytecodeDSLState state = getBytecodeDSLState(); - assert state.isStarted; - return state.continuationRootNode.getLocation().getBytecodeNode(); - } - - /** - * Loads the BytecodeNode from the RootNode field, which is in general not correct, but can be - * used if we know that the generator function is currently not on stack. - */ - public BytecodeNode getGeneratorFunctionBytecodeNode() { - BytecodeDSLState state = getBytecodeDSLState(); - assert !state.isStarted; - return state.rootNode.getBytecodeNode(); + assert isStarted; + return continuationRootNode.getLocation().getBytecodeNode(); } public BytecodeLocation getCurrentLocation() { - return getBytecodeDSLState().continuationRootNode.getLocation(); + return continuationRootNode.getLocation(); } public Object getYieldFrom() { @@ -240,19 +190,25 @@ public Object getYieldFrom() { return null; } - PBytecodeDSLRootNode rootNode = getBytecodeDSLState().rootNode; - if (!rootNode.hasYieldFromGenerator() || !getBytecodeDSLState().isStarted) { + if (!rootNode.hasYieldFromGenerator() || !isStarted) { return null; } return rootNode.readYieldFromGenerator(getContinuationBytecodeNode(), getGeneratorFrame()); } public boolean isStarted() { - return getBytecodeDSLState().isStarted && !isRunning(); + return isStarted && !isRunning(); } - public Object handleResult(PythonLanguage language, Object result) { - return getBytecodeDSLState().handleResult(this, (ContinuationResult) result); + public Object handleResult(Object result) { + ContinuationResult continuationResult = (ContinuationResult) result; + assert PBytecodeDSLRootNode.cast(continuationResult.getContinuationRootNode()).getFrameDescriptor() == frame.getFrameDescriptor(); + isStarted = true; + // We must keep the previous root so that we can load its BytecodeNode to resolve BCI to + // location, the next continuation node may have different BytecodeNode. + prevContinuationRootNode = continuationRootNode; + continuationRootNode = continuationResult.getContinuationRootNode(); + return continuationResult.getResult(); } public final boolean isFinished() { @@ -294,7 +250,7 @@ public final void setQualname(TruffleString qualname) { } private BytecodeDSLCodeUnit getCodeUnit() { - return getBytecodeDSLState().rootNode.getCodeUnit(); + return rootNode.getCodeUnit(); } public final boolean isCoroutine() { 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 5022d4348d..4ed9050581 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 @@ -1429,9 +1429,9 @@ private static PythonAbstractObject createGenerator(MaterializedFrame continuati PythonLanguage language = PythonLanguage.get(inliningTarget); PArguments.setCurrentFrameInfo(continuationFrame, new PFrame.Reference(innerRoot, PFrame.Reference.EMPTY)); if (innerRoot.getCodeUnit().isGenerator()) { - return PFactory.createGenerator(language, generatorFunction, innerRoot, arguments, continuationRootNode, continuationFrame); + return PFactory.createGenerator(language, generatorFunction, innerRoot, continuationRootNode, continuationFrame); } else if (innerRoot.getCodeUnit().isCoroutine()) { - return PFactory.createCoroutine(language, generatorFunction, innerRoot, arguments, continuationRootNode, continuationFrame); + return PFactory.createCoroutine(language, generatorFunction, innerRoot, continuationRootNode, continuationFrame); } else if (innerRoot.getCodeUnit().isAsyncGenerator()) { return PFactory.createAsyncGenerator(language, generatorFunction, innerRoot, continuationRootNode, continuationFrame); } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java index 38f884ccf9..62ce9d3a9e 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PFactory.java @@ -88,7 +88,6 @@ import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGen; import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenASend; import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenAThrow; -import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenWrappedValue; import com.oracle.graal.python.builtins.objects.asyncio.PCoroutineWrapper; import com.oracle.graal.python.builtins.objects.bytes.PByteArray; import com.oracle.graal.python.builtins.objects.bytes.PBytes; @@ -787,14 +786,14 @@ public static PDictView createDictItemsView(PythonLanguage language, Object dict * Special objects: generators, proxies, references, cells */ - public static PGenerator createGenerator(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode, + public static PGenerator createGenerator(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { - return PGenerator.create(language, function, rootNode, arguments, PythonBuiltinClassType.PGenerator, continuationRootNode, continuationFrame); + return PGenerator.create(language, function, rootNode, PythonBuiltinClassType.PGenerator, continuationRootNode, continuationFrame); } - public static PGenerator createCoroutine(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, Object[] arguments, ContinuationRootNode continuationRootNode, + public static PGenerator createCoroutine(PythonLanguage language, PFunction function, PBytecodeDSLRootNode rootNode, ContinuationRootNode continuationRootNode, MaterializedFrame continuationFrame) { - return PGenerator.create(language, function, rootNode, arguments, PythonBuiltinClassType.PCoroutine, continuationRootNode, continuationFrame); + return PGenerator.create(language, function, rootNode, PythonBuiltinClassType.PCoroutine, continuationRootNode, continuationFrame); } public static PCoroutineWrapper createCoroutineWrapper(PythonLanguage language, PGenerator generator) { @@ -1556,10 +1555,6 @@ public static PAsyncGenAThrow createAsyncGeneratorAThrow(PythonLanguage language return new PAsyncGenAThrow(language, receiver, arg1, arg2, arg3); } - public static PAsyncGenWrappedValue createAsyncGeneratorWrappedValue(PythonLanguage language, Object wrapped) { - return new PAsyncGenWrappedValue(language, wrapped); - } - // pickle public static PPickleBuffer createPickleBuffer(PythonLanguage language, Object view) { From de8758bf6b1365f418db3d56faa902ac73dc8c9c Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 15:56:36 +0200 Subject: [PATCH 10/20] Unskip passing test --- .../graal/python/test/integration/runtime/ProfileTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java index 617e091854..90214c9468 100644 --- a/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java +++ b/graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/runtime/ProfileTests.java @@ -44,7 +44,6 @@ import java.io.PrintStream; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import com.oracle.graal.python.test.integration.PythonTests; @@ -67,7 +66,6 @@ public void profileYield() { } @Test - @Ignore("GR-71916: TODO wrong stacktrace") public void profileException() { String source = "import sys\n" + "def f(frame, event, arg): print(frame, event, arg)\n" + From e852ed5dd8d32a25ee21d19bf257a0b552f22fcd Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 15:57:05 +0200 Subject: [PATCH 11/20] Remove skipUnlessBytecodeDSL --- .../src/tests/test_except_star.py | 2 -- .../src/tests/test_generators.py | 2 -- .../src/tests/test_scope.py | 3 --- .../src/tests/test_string.py | 2 -- .../src/tests/test_sys_settrace.py | 18 ------------------ .../src/tests/util.py | 6 ------ 6 files changed, 33 deletions(-) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_except_star.py b/graalpython/com.oracle.graal.python.test/src/tests/test_except_star.py index 66457d4795..cf88264bbc 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_except_star.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_except_star.py @@ -42,8 +42,6 @@ import sys import textwrap -from tests.util import skipIfBytecodeDSL - class ExceptStarPrintTest(unittest.TestCase): def test_01_eg_simple(self): 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 4c98b3e44a..213c66db4a 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 @@ -697,7 +697,6 @@ def test_normal_generator(): assert e.value == "Stop from send method, value='SENT_VALUE2'", e.value assert e != original_ex -@util.skipUnlessBytecodeDSL() def test_raise_stop_iter_in_throw_generator(): global original_ex original_ex = None @@ -718,7 +717,6 @@ def throw(self, value): raise original_ex -@util.skipUnlessBytecodeDSL() def test_raise_ex_in_throw_generator(): global original_ex original_ex = None diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_scope.py b/graalpython/com.oracle.graal.python.test/src/tests/test_scope.py index 6af28e4aab..e88ccd1207 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_scope.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_scope.py @@ -37,8 +37,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from tests import util - def assert_raises(err, fn, *args, **kwargs): raised = False try: @@ -948,7 +946,6 @@ def toInternal(obj): assert c.co_cellvars == tuple() -@util.skipUnlessBytecodeDSL("name atttribute not populated in manual interpreter") def test_name_errors(): def assert_raises_name_error(name, fn, *args, **kwargs): try: diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_string.py b/graalpython/com.oracle.graal.python.test/src/tests/test_string.py index e8f02c9ada..4b31a2f9a1 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_string.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_string.py @@ -5,7 +5,6 @@ import unittest import string import sys -from tests import util class MyIndexable(object): @@ -1234,7 +1233,6 @@ def __str__(self): return self -@util.skipUnlessBytecodeDSL("bug in manual interpreter") def test_fstring_preserves_type_of_single_str(): assert type(f"{FunkyStr('abc')}") == FunkyStr diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py index 3c9ab0d7ef..2fd3acf9fb 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py @@ -285,7 +285,6 @@ def trace_function_with_offset(self, func, offset_func): return offset_func.__code__.co_firstlineno - self.first_line class TraceTestsStmtWith(TracingEventsUnitTest): - @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") def test_01_break_in_with(self): class C: def __enter__(self): @@ -367,7 +366,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") def test_03_break_in_with_nested(self): class C: def __enter__(self): @@ -417,7 +415,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") def test_04_except_in_with(self): class C: def __enter__(self): @@ -454,7 +451,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") def test_05_except_in_with_nested(self): class C: def __enter__(self): @@ -969,7 +965,6 @@ def func(): self.assert_events(self.events, events) class TraceTestsStmtTry(TracingEventsUnitTest): - @util.skipUnlessBytecodeDSL("Incorrect break in with statement tracing.") def test_01_reraise(self): def func(): try: @@ -998,7 +993,6 @@ def func(): self.assert_events(self.events, events) class ExceptStarTraceTest(TracingEventsUnitTest): - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_01_except_star_with_name(self): def func(): try: @@ -1028,7 +1022,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_02_except_star_multi_with_name(self): def func(): try: @@ -1065,7 +1058,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_03_except_star_with_finally(self): def func(): try: @@ -1098,7 +1090,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") @util.skipIfBytecodeDSL("TODO: Fix return in finally.") def test_04_test_try_except_star_with_wrong_type(self): def func(): @@ -1127,7 +1118,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_05_if_false_in_try_except_star(self): def func(): try: @@ -1147,7 +1137,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") @unittest.skipIf(sys.implementation.name == "cpython", "TODO: seems broken on CPython") def test_06_try_in_try_with_exception(self): def func(): @@ -1216,7 +1205,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_08_try_except_star_no_exception(self): def func(): try: @@ -1250,7 +1238,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_09_try_except_star_named_no_exception(self): def func(): try: @@ -1275,7 +1262,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_10_try_except_star_exception_caught(self): def func(): try: @@ -1302,7 +1288,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_11_try_except_star_named_exception_caught(self): def func(): try: @@ -1329,7 +1314,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_12_try_except_star_exception_not_caught(self): def func(): try: @@ -1356,7 +1340,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_13_try_except_star_named_exception_not_caught(self): def func(): try: @@ -1383,7 +1366,6 @@ def func(): self.assert_events(self.events, events) - @util.skipUnlessBytecodeDSL("try-except* not implemented") def test_14_try_except_star_nested(self): def func(): try: 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 4674fdf710..006d84abb1 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/util.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/util.py @@ -89,12 +89,6 @@ def wrapper(test): return wrapper -def skipUnlessBytecodeDSL(reason=''): - def wrapper(test): - return test - return wrapper - - def storage_to_native(s): if sys.implementation.name == 'graalpy': assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins" From 8e610f733a3cba88e5575a4ba8b0e134aab85f36 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 16:17:02 +0200 Subject: [PATCH 12/20] Fix REPL exception printing --- .../com.oracle.graal.python.test/src/tests/test_repl.py | 2 -- .../python/nodes/exception/TopLevelExceptionHandler.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) 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 b5e1b66704..882d267dba 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,7 +45,6 @@ import sys import tempfile import unittest -from tests import util from dataclasses import dataclass from functools import wraps from textwrap import dedent @@ -207,7 +206,6 @@ def test_continuation(): ''')) - @util.skipIfBytecodeDSL("TODO: vs in traceback") def test_exceptions(): validate_repl(dedent("""\ >>> 1 / 0 diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java index 9b3df3955b..4171d870ba 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/exception/TopLevelExceptionHandler.java @@ -208,10 +208,10 @@ private AbstractTruffleException handlePythonException(AbstractTruffleException } private void exit(int exitCode) { - if (getSourceSection() == null) { + if (source == null) { throw new PythonExitException(this, exitCode); } - if (!getSourceSection().getSource().isInteractive()) { + if (!source.isInteractive()) { if (getContext().isChildContext()) { getContext().getChildContextData().setExitCode(1); } From 1ab98b74d3b6a6792fa694533868af7d06ae2e9d Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 16:17:25 +0200 Subject: [PATCH 13/20] Simplify locals sync --- .../nodes/frame/GetFrameLocalsNode.java | 51 ++++++------------- .../nodes/frame/MaterializeFrameNode.java | 20 +------- 2 files changed, 16 insertions(+), 55 deletions(-) diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java index 92e1c033b3..c56c6577d2 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/GetFrameLocalsNode.java @@ -51,7 +51,6 @@ import com.oracle.graal.python.lib.PyDictGetItem; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLCodeUnit; import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; -import com.oracle.graal.python.nodes.frame.GetFrameLocalsNodeGen.CopyDSLLocalsToDictNodeGen; import com.oracle.graal.python.runtime.CallerFlags; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.CompilerAsserts; @@ -99,7 +98,7 @@ public static Object executeUncached(PFrame pyFrame, boolean freshFrame) { @Specialization(guards = "!pyFrame.hasCustomLocals()") static Object doLoop(VirtualFrame frame, Node inliningTarget, PFrame pyFrame, boolean freshFrame, @Cached InlinedBranchProfile create, - @Cached(inline = false) CopyLocalsToDictBase copyLocalsToDict, + @Cached CopyDSLLocalsToDict copyLocalsToDict, @Cached ReadFrameNode readFrameNode) { if (!freshFrame && pyFrame.needsRefresh(frame, CallerFlags.NEEDS_LOCALS)) { pyFrame = readFrameNode.refreshFrame(frame, pyFrame.getRef(), CallerFlags.NEEDS_LOCALS); @@ -112,7 +111,7 @@ static Object doLoop(VirtualFrame frame, Node inliningTarget, PFrame pyFrame, bo localsDict = PFactory.createDict(PythonLanguage.get(inliningTarget)); pyFrame.setLocalsDict(localsDict); } - copyLocalsToDict.execute(pyFrame, localsDict); + copyLocalsToDict.execute(pyFrame.getBytecodeFrame(), localsDict); return localsDict; } @@ -123,40 +122,9 @@ static Object doCustomLocals(PFrame pyFrame, @SuppressWarnings("unused") boolean return localsDict; } - abstract static class CopyLocalsToDictBase extends Node { - public abstract void execute(PFrame frame, PDict dict); - - @NeverDefault - static CopyLocalsToDictBase create() { - return CopyDSLLocalsToDictNodeGen.create(); - } - - static CopyLocalsToDictBase getUncached() { - return CopyDSLLocalsToDictNodeGen.getUncached(); - } - - static void copyItem(Node inliningTarget, Object localValue, BytecodeDSLFrameInfo info, PDict dict, HashingStorageSetItem setItem, HashingStorageDelItem delItem, int i, boolean deref) { - TruffleString name = info.getVariableName(i); - Object value = localValue; - if (deref && value != null) { - value = ((PCell) value).getRef(); - } - if (value == null) { - delItem.execute(inliningTarget, dict.getDictStorage(), name, dict); - } else { - HashingStorage storage = setItem.execute(inliningTarget, dict.getDictStorage(), name, value); - dict.setDictStorage(storage); - } - } - } - @GenerateUncached @GenerateInline(false) // footprint reduction 104 -> 86 - abstract static class CopyDSLLocalsToDict extends CopyLocalsToDictBase { - @Override - public final void execute(PFrame frame, PDict dict) { - execute(frame.getBytecodeFrame(), dict); - } + abstract static class CopyDSLLocalsToDict extends Node { abstract void execute(BytecodeFrame locals, PDict dict); @@ -171,7 +139,18 @@ void doIt(BytecodeFrame locals, PDict dict, int regularVarCount = regularVarCountProfile.profile(inliningTarget, info.getRegularVariableCount()); int varCount = varCountProfile.profile(inliningTarget, info.getVariableCount()); for (int i = 0; i < varCount; i++) { - copyItem(inliningTarget, locals.getLocalValue(i), info, dict, setItem, delItem, i, i >= regularVarCount); + Object localValue = locals.getLocalValue(i); + TruffleString name = info.getVariableName(i); + Object value = localValue; + if (i >= regularVarCount && value != null) { + value = ((PCell) value).getRef(); + } + if (value == null) { + delItem.execute(inliningTarget, dict.getDictStorage(), name, dict); + } else { + HashingStorage storage = setItem.execute(inliningTarget, dict.getDictStorage(), name, value); + dict.setDictStorage(storage); + } } } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java index a80beb04d6..70e3806137 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java @@ -47,7 +47,6 @@ import com.oracle.graal.python.builtins.objects.generator.PGenerator; import com.oracle.graal.python.builtins.objects.object.PythonObject; import com.oracle.graal.python.nodes.PRootNode; -import com.oracle.graal.python.nodes.bytecode_dsl.BytecodeDSLFrameInfo; import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; import com.oracle.graal.python.runtime.CallerFlags; import com.oracle.graal.python.runtime.object.PFactory; @@ -60,19 +59,15 @@ import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateInline; import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Idempotent; import com.oracle.truffle.api.dsl.ImportStatic; import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.ReportPolymorphism; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.nodes.EncapsulatingNodeReference; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.InlinedBranchProfile; -import com.oracle.truffle.api.profiles.InlinedIntValueProfile; -import com.oracle.truffle.api.profiles.ValueProfile; /** * This node makes sure that the current frame has a filled-in PFrame object with a backref @@ -279,11 +274,7 @@ public abstract static class SyncFrameValuesNode extends Node { public abstract void execute(PFrame pyFrame, Frame frameToSync, Node location); @Specialization(guards = {"!pyFrame.hasCustomLocals()", "!isGeneratorFrame(frameToSync)"}) - static void doSync(PFrame pyFrame, Frame frameToSync, Node location, - @Bind Node inliningTarget, - @Cached(inline = false) ValueProfile frameDescriptorProfile, - @Cached InlinedIntValueProfile slotCountProfile, - @Exclusive @Cached InlinedBranchProfile createLocalsProfile) { + static void doSync(PFrame pyFrame, Frame frameToSync, Node location) { BytecodeNode bytecodeNode = BytecodeNode.get(location); if (bytecodeNode != null) { // TODO: avoid always making a copy, if a BytecodeFrame is set, just update it @@ -309,14 +300,5 @@ static void doGenerator(PFrame pyFrame, Frame frameToSync, @SuppressWarnings("un pyFrame.setBytecodeFrame(bytecodeNode.createMaterializedFrame(0, frameToSync.materialize())); } } - - @Idempotent - protected static int variableSlotCount(FrameDescriptor fd) { - BytecodeDSLFrameInfo info = (BytecodeDSLFrameInfo) fd.getInfo(); - if (info == null) { - return 0; - } - return info.getVariableCount(); - } } } From e0c188dbd2e00005d7a7e75cd4dab62e08eac110 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 16:31:55 +0200 Subject: [PATCH 14/20] Remove OpCodes --- .../annotations/GenerateEnumConstants.java | 54 - .../javax.annotation.processing.Processor | 1 - .../GenerateEnumConstantsProcessor.java | 145 --- .../{BinaryOps.java => CollectionBits.java} | 65 +- .../graal/python/compiler/FormatOptions.java | 72 -- .../{UnaryOps.java => MakeTypeParamKind.java} | 17 +- .../oracle/graal/python/compiler/OpCodes.java | 1077 ----------------- .../bytecode_dsl/RootNodeCompiler.java | 4 +- .../nodes/bytecode/MakeTypeParamNode.java | 4 +- .../bytecode_dsl/PBytecodeDSLRootNode.java | 2 +- 10 files changed, 38 insertions(+), 1403 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/GenerateEnumConstants.java delete mode 100644 graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/GenerateEnumConstantsProcessor.java rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/{BinaryOps.java => CollectionBits.java} (67%) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/FormatOptions.java rename graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/{UnaryOps.java => MakeTypeParamKind.java} (85%) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java diff --git a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/GenerateEnumConstants.java b/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/GenerateEnumConstants.java deleted file mode 100644 index f49da55e12..0000000000 --- a/graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/GenerateEnumConstants.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2020, 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -@Target(ElementType.TYPE) -public @interface GenerateEnumConstants { - enum Type { - INT, - BYTE - } - - Type type() default Type.INT; -} diff --git a/graalpython/com.oracle.graal.python.processor/src/META-INF/services/javax.annotation.processing.Processor b/graalpython/com.oracle.graal.python.processor/src/META-INF/services/javax.annotation.processing.Processor index c56a7e9bd4..a47cddc764 100644 --- a/graalpython/com.oracle.graal.python.processor/src/META-INF/services/javax.annotation.processing.Processor +++ b/graalpython/com.oracle.graal.python.processor/src/META-INF/services/javax.annotation.processing.Processor @@ -1,5 +1,4 @@ com.oracle.graal.python.processor.ArgumentClinicProcessor -com.oracle.graal.python.processor.GenerateEnumConstantsProcessor com.oracle.graal.python.processor.GenerateNativeDowncallsProcessor com.oracle.graal.python.processor.CApiBuiltinsProcessor com.oracle.graal.python.processor.SlotsProcessor diff --git a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/GenerateEnumConstantsProcessor.java b/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/GenerateEnumConstantsProcessor.java deleted file mode 100644 index 660f341688..0000000000 --- a/graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/GenerateEnumConstantsProcessor.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2020, 2024, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.processor; - -import java.io.IOException; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.Set; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; -import javax.tools.Diagnostic.Kind; -import javax.tools.JavaFileObject; - -import com.oracle.graal.python.annotations.GenerateEnumConstants; -import com.oracle.graal.python.processor.CodeWriter.Block; - -public class GenerateEnumConstantsProcessor extends AbstractProcessor { - - @Override - public Set getSupportedAnnotationTypes() { - return Collections.singleton(GenerateEnumConstants.class.getName()); - } - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latestSupported(); - } - - @Override - @SuppressWarnings({"try", "unused"}) - public boolean process(Set annotations, RoundEnvironment re) { - if (re.processingOver()) { - return true; - } - Set annotatedElements = re.getElementsAnnotatedWith(GenerateEnumConstants.class); - for (Element el : annotatedElements) { - GenerateEnumConstants annotation = el.getAnnotation(GenerateEnumConstants.class); - boolean useByte = annotation.type() == GenerateEnumConstants.Type.BYTE; - String elementType = useByte ? "byte" : "int"; - if (el.getKind() == ElementKind.ENUM) { - try { - Element enc = el.getEnclosingElement(); - int enclosingTypes = 0; - OUTER: while (enc != null) { - switch (enc.getKind()) { - case CLASS: - case ENUM: - case INTERFACE: - enclosingTypes++; - break; - default: - break OUTER; - } - enc.getEnclosingElement(); - } - String qualName = ((TypeElement) el).getQualifiedName() + "Constants"; - String pkgName = qualName.substring(0, qualName.lastIndexOf('.')); - String className = qualName.substring(qualName.lastIndexOf('.') + 1); - - while (enclosingTypes-- > 0) { - className = pkgName.substring(qualName.lastIndexOf('.') + 1) + className; - pkgName = pkgName.substring(0, pkgName.lastIndexOf('.')); - qualName = pkgName + "." + className; - } - - JavaFileObject file = processingEnv.getFiler().createSourceFile(qualName); - try (CodeWriter w = new CodeWriter(file.openWriter())) { - w.writeLn("// CheckStyle: start generated"); - w.writeLn("// Auto generated by GenerateEnumConstantsProcessor at %s", LocalDateTime.now()); - w.writeLn("package %s;", pkgName); - w.writeLn(); - w.writeLn("public final class %s {", className); - int i = 0; - for (Element enumBit : el.getEnclosedElements()) { - if (enumBit.getKind() == ElementKind.ENUM_CONSTANT) { - String enumName = ((VariableElement) enumBit).getSimpleName().toString(); - try (Block b = w.newIndent()) { - int value = i++; - if (useByte) { - if (value <= 0xFF) { - value = (byte) value; - } else { - throw new IllegalArgumentException("Enum constant doesn't fit into byte"); - } - } - w.writeLn("public static final %s %s = %d;", elementType, enumName, value); - } - } - } - w.writeLn("}"); - } - } catch (IOException e) { - processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), el); - } - } else { - processingEnv.getMessager().printMessage(Kind.ERROR, "Can only annotate enums with @GenerateEnumConstants", el); - } - } - return true; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BinaryOps.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java similarity index 67% rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BinaryOps.java rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java index bf77570e33..e78b42b3bc 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/BinaryOps.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, 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 @@ -40,43 +40,30 @@ */ package com.oracle.graal.python.compiler; -import com.oracle.graal.python.annotations.GenerateEnumConstants; +public final class CollectionBits { + public static final int KIND_MASK = 0b00011111; + public static final int KIND_LIST = 0b00100000; + public static final int KIND_TUPLE = 0b01000000; + public static final int KIND_SET = 0b01100000; + public static final int KIND_DICT = 0b10000000; + public static final int KIND_KWORDS = 0b10100000; + public static final int KIND_OBJECT = 0b11000000; -/** Operation identifiers for {@link OpCodes#BINARY_OP}. */ -@GenerateEnumConstants -public enum BinaryOps { - ADD, - INPLACE_ADD, - SUB, - INPLACE_SUB, - MUL, - INPLACE_MUL, - FLOORDIV, - INPLACE_FLOORDIV, - TRUEDIV, - INPLACE_TRUEDIV, - MOD, - INPLACE_MOD, - EQ, - NE, - LT, - LE, - GT, - GE, - LSHIFT, - INPLACE_LSHIFT, - RSHIFT, - INPLACE_RSHIFT, - AND, - INPLACE_AND, - OR, - INPLACE_OR, - XOR, - INPLACE_XOR, - POW, - INPLACE_POW, - IN, - IS, - MATMUL, - INPLACE_MATMUL, + public static final byte ELEMENT_INT = 1; + public static final byte ELEMENT_LONG = 2; + public static final byte ELEMENT_BOOLEAN = 3; + public static final byte ELEMENT_DOUBLE = 4; + public static final byte ELEMENT_OBJECT = 5; + + public static int elementCount(int oparg) { + return oparg & KIND_MASK; + } + + public static int elementType(int oparg) { + return oparg & KIND_MASK; + } + + public static int collectionKind(int oparg) { + return oparg & ~KIND_MASK; + } } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/FormatOptions.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/FormatOptions.java deleted file mode 100644 index 487adff00c..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/FormatOptions.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -public abstract class FormatOptions { - /** - * Mask to extract just the conversion type flags. - */ - public static final int FVC_MASK = 0x3; - /** - * No conversion (identity function). - */ - public static final int FVC_NONE = 0x0; - /** - * Conversion equivalent to builtin {@code str} - */ - public static final int FVC_STR = 0x1; - /** - * Conversion equivalent to builtin {@code repr} - */ - public static final int FVC_REPR = 0x2; - /** - * Conversion equivalent to builtin {@code ascii} - */ - public static final int FVC_ASCII = 0x3; - /** - * Mask to extract just the spec flag. - */ - public static final int FVS_MASK = 0x4; - /** - * Whether a format spec is present. - */ - public static final int FVS_HAVE_SPEC = 0x4; -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/UnaryOps.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/MakeTypeParamKind.java similarity index 85% rename from graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/UnaryOps.java rename to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/MakeTypeParamKind.java index deca361880..bbbe166433 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/UnaryOps.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/MakeTypeParamKind.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026, 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 @@ -40,13 +40,10 @@ */ package com.oracle.graal.python.compiler; -import com.oracle.graal.python.annotations.GenerateEnumConstants; - -/** Operation identifiers for {@link OpCodes#UNARY_OP}. */ -@GenerateEnumConstants -public enum UnaryOps { - NOT, - POSITIVE, - NEGATIVE, - INVERT, +public final class MakeTypeParamKind { + public static final int TYPE_VAR = 0; + public static final int TYPE_VAR_TUPLE = 1; + public static final int PARAM_SPEC = 2; + public static final int TYPE_VAR_WITH_BOUND = 3; + public static final int TYPE_VAR_WITH_CONSTRAINTS = 4; } diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java deleted file mode 100644 index a483606073..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/OpCodes.java +++ /dev/null @@ -1,1077 +0,0 @@ -/* - * Copyright (c) 2021, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import java.math.BigInteger; - -import com.oracle.graal.python.annotations.GenerateEnumConstants; -import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenWrappedValue; -import com.oracle.graal.python.builtins.objects.function.PKeyword; -import com.oracle.graal.python.builtins.objects.ints.PInt; -import com.oracle.graal.python.runtime.exception.PException; - -/** - * Operation codes of our bytecode interpreter. They are similar to CPython's, but not the same. Our - * opcodes can have multiple bytes of immediate operands. The first operand can be variably extended - * using {@link #EXTENDED_ARG} instruction. - */ -@GenerateEnumConstants(type = GenerateEnumConstants.Type.BYTE) -public enum OpCodes { - /** Pop a single item from the stack */ - POP_TOP(0, 1, 0), - /** Exchange two top stack items */ - ROT_TWO(0, 2, 2), - /** Exchange three top stack items. [a, b, c] (a is top) becomes [b, c, a] */ - ROT_THREE(0, 3, 3), - /** Exchange N top stack items. [a, b, c, ..., N] (a is top) becomes [b, c, ..., N, a] */ - ROT_N(1, (oparg, followingArgs, withJump) -> oparg, (oparg, followingArgs, withJump) -> oparg), - /** Duplicates the top stack item */ - DUP_TOP(0, 1, 2), - /** Does nothing. Might still be useful to maintain a line number */ - NOP(0, 0, 0), - /** - * Performs a unary operation specified by the immediate operand. It has to be the ordinal of - * one of {@link UnaryOps} constants. - * - * Pops: operand - * - * Pushes: result - */ - UNARY_OP(1, 1, 1), - /** - * Performs a binary operation specified by the immediate operand. It has to be the ordinal of - * one of {@link BinaryOps} constants. - * - * Pops: right operand, then left operand - * - * Pushes: result - */ - BINARY_OP(1, 2, 1), - /** - * Performs subscript get operation - {@code a[b]}. - * - * Pops: {@code b}, then {@code a} - * - * Pushes: result - */ - BINARY_SUBSCR(0, 2, 1), - /** - * Performs subscript set operation - {@code a[b] = c}. - * - * Pops: {@code b}, then {@code a}, then {@code c} - */ - STORE_SUBSCR(0, 3, 0), - /** - * Performs subscript delete operation - {@code del a[b]}. - * - * Pops: {@code b}, then {@code a} - */ - DELETE_SUBSCR(0, 2, 0), - /** - * Gets an iterator of an object - * - * Pops: object - * - * Pushes: iterator - */ - GET_ITER(0, 1, 1), - /** - * Gets an iterator of an object, does nothing for a generator iterator or a coroutine - * - * Pops: object - * - * Pushes: iterator - */ - GET_YIELD_FROM_ITER(0, 1, 1), - /** - * Gets an awaitable of an object - * - * Pops: object - * - * Pushes: awaitable - */ - GET_AWAITABLE(0, 1, 1), - /** - * Gets the async iterator of an object - error if a coroutine is returned - * - * Pops: object - * - * Pushes: async iterator - */ - GET_AITER(0, 1, 1), - /** - * Get the awaitable that will return the next element of an async iterator - * - * Pops: object - * - * Pushes: awaitable - */ - GET_ANEXT(0, 1, 1), - /** - * Pushes: {@code __build_class__} builtin - */ - LOAD_BUILD_CLASS(0, 0, 1), - /** - * Pushes: {@code AssertionError} builtin exception type - */ - LOAD_ASSERTION_ERROR(0, 0, 1), - /** - * Returns the value to the caller. In generators, performs generator return. - * - * Pops: return value - */ - RETURN_VALUE(0, 1, 0), - /** - * Reads a name from locals dict, globals or builtins determined by the immediate operand which - * indexes the names array ({@code co_names}). - * - * Pushes: read object - */ - LOAD_NAME(1, 0, 1), - /** - * Writes the stack top into a name in locals dict or globals determined by the immediate - * operand which indexes the names array ({@code co_names}). - * - * Pops: object to be written - */ - STORE_NAME(1, 1, 0), - /** - * Deletes the name in locals dict or globals determined by the immediate operand which indexes - * the names array ({@code co_names}). - */ - DELETE_NAME(1, 0, 0), - /** - * Reads an attribute - {@code a.b}. {@code b} is determined by the immediate operand which - * indexes the names array ({@code co_names}). - * - * Pops: {@code a} - * - * Pushes: read attribute - */ - LOAD_ATTR(1, 1, 1), - /** - * Reads method on an object. The method name is determined by the first immediate operand which - * indexes the names array ({@code co_names}). - * - * Pushes: read method - */ - LOAD_METHOD(1, 1, 2), - /** - * Writes an attribute - {@code a.b = c}. {@code b} is determined by the immediate operand which - * indexes the names array ({@code co_names}). - * - * Pops: {@code a}, then {@code c} - */ - STORE_ATTR(1, 2, 0), - /** - * Deletes an attribute - {@code del a.b}. {@code b} is determined by the immediate operand - * which indexes the names array ({@code co_names}). - * - * Pops: {@code a} - */ - DELETE_ATTR(1, 1, 0), - /** - * Reads a global variable. The name is determined by the immediate operand which indexes the - * names array ({@code co_names}). - * - * Pushes: read object - */ - LOAD_GLOBAL(1, 0, 1), - /** - * Writes a global variable. The name is determined by the immediate operand which indexes the - * names array ({@code co_names}). - * - * Pops: value to be written - */ - STORE_GLOBAL(1, 1, 0), - /** - * Deletes a global variable. The name is determined by the immediate operand which indexes the - * names array ({@code co_names}). - */ - DELETE_GLOBAL(1, 0, 0), - /** - * Reads a constant object from constants array ({@code co_consts}). Performs no conversion. - * - * Pushes: read constant - */ - LOAD_CONST(1, 0, 1), - /** - * Reads a local variable determined by the immediate operand which indexes a stack slot and a - * variable name in varnames array ({@code co_varnames}). - * - * Pushes: read value - */ - LOAD_FAST(1, 0, 1), - /** - * Writes a local variable determined by the immediate operand which indexes a stack slot and a - * variable name in varnames array ({@code co_varnames}). - * - * Pops: value to be writen - */ - STORE_FAST(1, 1, 0), - /** - * Deletes a local variable determined by the immediate operand which indexes a stack slot and a - * variable name in varnames array ({@code co_varnames}). - */ - DELETE_FAST(1, 0, 0), - /** - * Reads a local cell variable determined by the immediate operand which indexes a stack slot - * after celloffset and a variable name in cellvars or freevars array ({@code co_cellvars}, - * {@code co_freevars}). - * - * Pushes: cell contents - */ - LOAD_DEREF(1, 0, 1), - /** - * Writes a local cell variable determined by the immediate operand which indexes a stack slot - * after celloffset and a variable name in cellvars or freevars array ({@code co_cellvars}, - * {@code co_freevars}). - * - * Pops: value to be written into the cell contents - */ - STORE_DEREF(1, 1, 0), - /** - * Deletes a local cell variable determined by the immediate operand which indexes a stack slot - * after celloffset and a variable name in cellvars or freevars array ({@code co_cellvars}, - * {@code co_freevars}). Note that it doesn't delete the cell, just its contents. - */ - DELETE_DEREF(1, 0, 0), - /** - * Pushes locals (i.e. "special argument") to the stack. - */ - LOAD_LOCALS(0, 0, 1), - /** - * Attempts to read a value from a dict and if not present, reads a local cell variable. The - * immediate operand indexes a stack slot after celloffset and a variable name in cellvars or - * freevars array ({@code co_cellvars}, {@code co_freevars}). - * - * Pops: a dict - * - * Pushes: the value - */ - LOAD_FROM_DICT_OR_DEREF(1, 1, 1), - /** - * Attempts to read a value from a dict and if not present, reads a global variable. The name is - * determined by the immediate operand which indexes the names array ({@code co_names}). - * - * Pops: a dict - * - * Pushes: the value - */ - LOAD_FROM_DICT_OR_GLOBALS(1, 1, 1), - /** - * Raises an exception. If the immediate operand is 0, it pops nothing and is equivalent to - * {@code raise} without arguments. If the immediate operand is 1, it is equivalent to - * {@code raise e} and it pops {@code e}. If the immediate operand is 2, it is equivalent to - * {@code raise e from c} and it pops {@code c}, then {@code e}. Other immediate operand values - * are illegal. - */ - RAISE_VARARGS(1, (oparg, followingArgs, withJump) -> oparg, 0), - /** - * Creates a slice object. If the immediate argument is 2, it is equivalent to a slice - * {@code a:b}. It pops {@code b}, then {@code a}. If the immediate argument is 3, it is - * equivalent to a slice {@code a:b:c}. It pops {@code c}, then {@code b}, then {@code a}. Other - * immediate operand values are illegal. - * - * Pushes: the created slice object - */ - BUILD_SLICE(1, (oparg, followingArgs, withJump) -> oparg, 1), - /** - * Formats a value. If the immediate argument contains flag {@link FormatOptions#FVS_HAVE_SPEC}, - * it is equivalent to {@code format(conv(v), spec)}. It pops {@code spec}, then {@code v}. - * Otherwise, it is equivalent to {@code format(conv(v), None)}. It pops {@code v}. {@code conv} - * is determined by the immediate operand which contains one of the {@code FVC} options in - * {@link FormatOptions}. - * - * Pushes: the formatted value - */ - FORMAT_VALUE(1, (oparg, followingArgs, withJump) -> (oparg & FormatOptions.FVS_MASK) == FormatOptions.FVS_HAVE_SPEC ? 2 : 1, 1), - - /** - * Extends the immediate operand of the following instruction by its own operand shifted left by - * a byte. - */ - EXTENDED_ARG(1, 0, 0), - - /** - * Imports a module by name determined by the immediate operand which indexes the names array - * ({@code co_names}). - * - * Pops: fromlist (must be a constant {@code TruffleString[]}), then level (must be {@code int}) - * - * Pushes: imported module - */ - IMPORT_NAME(1, 2, 1), - /** - * Imports a name from a module. The name determined by the immediate operand which indexes the - * names array ({@code co_names}). - * - * Pops: module object - * - * Pushes: module object, imported object - */ - IMPORT_FROM(1, 1, 2), - /** - * Imports all names from a module of name determined by the immediate operand which indexes the - * names array ({@code co_names}). The imported names are written to locals dict (can only be - * invoked on module level). - * - * Pops: level (must be {@code int}) - */ - IMPORT_STAR(1, 1, 0), - /** - * Prints the top of the stack. Used by "single" parsing mode to echo expressions. - * - * Pops: the value to print - */ - PRINT_EXPR(0, 1, 0), - /** - * Creates annotations dict in locals - */ - SETUP_ANNOTATIONS(0, 0, 0), - - /** - * Determines if a python object is a sequence. - */ - MATCH_SEQUENCE(0, 0, 1), - - /** - * Determines if a python object is a mapping. - */ - MATCH_MAPPING(0, 0, 1), - - /** - * Determines if a python object is of a particular type. - */ - MATCH_CLASS(1, 3, 2), - - /** - * Matches the keys (stack top) in a dict (stack second). On successful match pushes the values - * and True, otherwise None and False. - */ - MATCH_KEYS(0, 2, 4), - - /** - * Creates a copy of a dict (stack second) without elements matching a tuple of keys (stack - * top). - */ - COPY_DICT_WITHOUT_KEYS(0, 1, 1), - - /** - * Retrieves the length of a python object and stores it on top. - */ - GET_LEN(0, 0, 1), - - // load bytecodes for special constants - LOAD_NONE(0, 0, 1), - LOAD_ELLIPSIS(0, 0, 1), - LOAD_TRUE(0, 0, 1), - LOAD_FALSE(0, 0, 1), - /** - * Loads signed byte from immediate operand. - */ - LOAD_BYTE(1, 0, 1), - /** - * Loads {@code int} from primitiveConstants array indexed by the immediate operand. - */ - LOAD_INT(1, 0, 1), - /** - * Loads {@code long} from primitiveConstants array indexed by the immediate operand. - */ - LOAD_LONG(1, 0, 1), - /** - * Loads {@code double} from primitiveConstants array indexed by the immediate operand - * (converted from long). - */ - LOAD_DOUBLE(1, 0, 1), - /** - * Creates a {@link PInt} from a {@link BigInteger} in constants array indexed by the immediate - * operand. - */ - LOAD_BIGINT(1, 0, 1), - /** - * Currently the same as {@link #LOAD_CONST}. - */ - LOAD_STRING(1, 0, 1), - /** - * Creates python {@code bytes} from a {@code byte[]} array in constants array indexed by the - * immediate operand. - */ - LOAD_BYTES(1, 0, 1), - /** - * Creates python {@code complex} from a {@code double[]} array of size 2 in constants array - * indexed by the immediate operand. - */ - LOAD_COMPLEX(1, 0, 1), - /* - * Creates a collection out of a Java array in constants array indexed by the immediate operand. - * The second immediate operand determines the array type and kind, using values from {@link - * CollectionBits}. The only allowed kinds are list and tuple. - */ - LOAD_CONST_COLLECTION(2, 0, 1), - - // calling - /** - * Calls method on an object using an array as args. The receiver is taken from the first - * element of the array. The method name is determined by the immediate operand which indexes - * the names array ({@code co_names}). - * - * Pops: args ({@code Object[]} of size >= 1) and the method - * - * Pushes: call result - */ - CALL_METHOD_VARARGS(0, 2, 1), - /** - * Calls method on an object using a number of stack args determined by the first immediate - * operand. - * - * Pops: multiple arguments depending on the first immediate operand, then the method and the - * receiver - * - * Pushes: call result - */ - CALL_METHOD(1, (oparg, followingArgs, withJump) -> oparg + 2, 1), - /** - * Calls a callable using a number of stack args determined by the immediate operand. - * - * Pops: multiple arguments depending on the immediate operand (0 - 4), then the callable - * - * Pushes: call result - */ - CALL_FUNCTION(1, (oparg, followingArgs, withJump) -> oparg + 1, 1), - /** - * Calls a comprehension function with a single iterator argument. Comprehension functions have - * to always have the same call target at given calls site. The instruction makes use of this - * fact and bypasses function object inline caching which would otherwise slow down warmup since - * comprehensions functions are always created anew and thus the cache would always miss. - * - * Pops: iterator, then the function - * - * Pushes: call result - */ - CALL_COMPREHENSION(0, 2, 1), - /** - * Calls a callable using an arguments array and keywords array. - * - * Pops: keyword args ({@code PKeyword[]}), then args ({@code Object[]}), then callable - * - * Pushes: call result - */ - CALL_FUNCTION_KW(0, 3, 1), - /** - * Calls a callable using an arguments array. No keywords are passed. - * - * Pops: args ({@code Object[]}), then callable - * - * Pushes: call result - */ - CALL_FUNCTION_VARARGS(0, 2, 1), - - // destructuring bytecodes - /** - * Unpacks an iterable into multiple stack items. - * - * Pops: iterable - * - * Pushed: unpacked items, the count is determined by the immediate operand - */ - UNPACK_SEQUENCE(1, 1, (oparg, followingArgs, withJump) -> oparg), - /** - * Unpacks an iterable into multiple stack items with a star item that gets the rest. The first - * immediate operand determines the count before the star item, the second determines the count - * after. - * - * Pops: iterable - * - * Pushed: unpacked items (count = first operand), star item, unpacked items (count = second - * operand) - */ - UNPACK_EX(2, 1, (oparg, followingArgs, withJump) -> oparg + 1 + Byte.toUnsignedInt(followingArgs[0])), - - // jumps - /** - * Get next value from an iterator. If the iterable is exhausted, jump forward by the offset in - * the immediate argument. - * - * Pops: iterator - * - * Pushes (only if not jumping): the iterator, then the next value - */ - FOR_ITER(1, 1, (oparg, followingArgs, withJump) -> withJump ? 0 : 2), - /** - * Jump forward by the offset in the immediate operand. - */ - JUMP_FORWARD(1, 0, 0), - /** - * Jump backward by the offset in the immediate operand. May trigger OSR compilation. - */ - JUMP_BACKWARD(1, 0, 0), - /** - * Jump forward by the offset in the immediate operand if the top of the stack is false (in - * Python sense). - * - * Pops (if not jumping): top of the stack - */ - JUMP_IF_FALSE_OR_POP(3, (oparg, followingArgs, withJump) -> withJump ? 0 : 1, 0), - /** - * Jump forward by the offset in the immediate operand if the top of the stack is true (in - * Python sense). - * - * Pops (if not jumping): top of the stack - */ - JUMP_IF_TRUE_OR_POP(3, (oparg, followingArgs, withJump) -> withJump ? 0 : 1, 0), - /** - * Jump forward by the offset in the immediate operand if the top of the stack is false (in - * Python sense). - * - * Pops: top of the stack - */ - POP_AND_JUMP_IF_FALSE(3, 1, 0), - /** - * Jump forward by the offset in the immediate operand if the top of the stack is true (in - * Python sense). - * - * Pops: top of the stack - */ - POP_AND_JUMP_IF_TRUE(3, 1, 0), - - // making callables - /** - * Like {@link #LOAD_DEREF}, but loads the cell itself, not the contents. - * - * Pushes: the cell object - */ - LOAD_CLOSURE(1, 0, 1), - /** - * Reduces multiple stack items into an array of cell objects. - * - * Pops: multiple cells (count = immediate argument) - * - * Pushes: cell object array ({@code PCell[]}) - */ - CLOSURE_FROM_STACK(1, (oparg, followingArgs, withJump) -> oparg, 1), - /** - * Creates a function object. The first immediate argument is an index to the constants array - * that determines the {@link BytecodeDSLCodeUnit} object that will provide the function's code. - * - * Pops: The second immediate arguments contains flags (defined in {@link BytecodeDSLCodeUnit}) that - * determine whether it will need to pop (in this order): closure, annotations, keyword only - * defaults, defaults. - * - * Pushes: created function - */ - MAKE_FUNCTION(2, (oparg, followingArgs, withJump) -> Integer.bitCount(followingArgs[0]), 1), - - /** - * Creates a TypeVar, TypeVarTuple or ParamSpec object. The immediate argument determines - * (defined in {@link MakeTypeParamKind}) which and whether it will need to pop bound or - * constraints for a TypeVar. - * - * Pops: bound or constraints (if indicated by the immediate argument), then the name - * - * Pushes: created type parameter - */ - MAKE_TYPE_PARAM(1, (oparg, followingArgs, withJump) -> oparg < MakeTypeParamKind.TYPE_VAR_WITH_BOUND ? 1 : 2, 1), - - /** - * Creates a TypeAliasType object. - * - * Pops: function for computing the value, type params tuple and name - * - * Pushes: created type alias - */ - MAKE_TYPE_ALIAS(0, 3, 1), - - /** - * Creates a base for generic classes by calling typing._GenericAlias. - * - * Pops: a tuple of type parameters - * - * Pushes: created base for a generic class - */ - MAKE_GENERIC(0, 1, 1), - - // collection literals - /** - * Creates a collection from multiple elements from the stack. Collection type is determined by - * {@link CollectionBits} in immediate operand. - * - * Pops: items for the collection (count = immediate argument) - * - * Pushes: new collection - */ - COLLECTION_FROM_STACK(1, (oparg, followingArgs, withJump) -> CollectionBits.elementCount(oparg), 1), - /** - * Add multiple elements from the stack to the collection below them. Collection type is - * determined by {@link CollectionBits} in immediate operand. Tuple is not supported. - * - * Pops: items to be added (count = immediate argument) - */ - COLLECTION_ADD_STACK(1, (oparg, followingArgs, withJump) -> CollectionBits.elementCount(oparg) + 1, 1), - /** - * Concatenates two collection of the same type. Collection type is determined by - * {@link CollectionBits} in immediate operand. Tuple is not supported. - * - * Pops: second collection, first collection - * - * Pushes: concatenated collection - */ - COLLECTION_ADD_COLLECTION(1, 2, 1), - /** - * Converts collection to another type determined by {@link CollectionBits} in immediate - * operand. The converted collection is expected to be an independent copy (they don't share - * storage). - * - * Pops: original collection - * - * Pushes: converted collection - */ - COLLECTION_FROM_COLLECTION(1, 1, 1), - /** - * Converts list to tuple by reusing the underlying storage. - * - * Pops: list - * - * Pushes: tuple - */ - TUPLE_FROM_LIST(0, 1, 1), - /** - * Converts list to frozenset. - * - * Pops: list - * - * Pushes: frozenset - */ - FROZENSET_FROM_LIST(0, 1, 1), - /** - * Adds an item to a collection that is multiple items deep under the top of the stack, - * determined by the immediate argument. - * - * Pops: item to be added - */ - ADD_TO_COLLECTION(1, (oparg, followingArgs, withJump) -> CollectionBits.collectionKind(oparg) == CollectionBits.KIND_DICT ? 2 : 1, 0), - /** - * Like {@link #COLLECTION_ADD_COLLECTION} for dicts, but with checks for duplicate keys - * necessary for keyword arguments merge. Note it works with dicts. Keyword arrays need to be - * converted to dicts first. - */ - KWARGS_DICT_MERGE(0, 2, 1), - /** - * Create a single {@link PKeyword} object. The name is determined by the immediate operand - * which indexes the names array ({@code co_names}) - * - * Pops: keyword value - * - * Pushes: keyword object - */ - MAKE_KEYWORD(1, 1, 1), - - // exceptions - /** - * Jump forward by the offset in the immediate argument if the exception doesn't match the - * expected type. The exception object is {@link PException}, not a python exception. - * - * Pops: expected type, then exception - * - * Pushes (if jumping): the exception - */ - MATCH_EXC_OR_JUMP(3, 2, 1), - /** - * Save the current exception state on the stack and set it to the exception on the stack. The - * exception object is {@link PException}, not a python exception. The exception is pushed back - * to the top. - * - * Pops: the exception - * - * Pushes: the saved exception state, the exception - */ - PUSH_EXC_INFO(0, 1, 2), - /** - * Sets the current exception state to the saved state (by {@link #PUSH_EXC_INFO}) on the stack - * and pop it. - * - * Pops: save exception state - */ - POP_EXCEPT(0, 1, 0), - /** - * Restore exception state and reraise exception. - * - * Pops: exception to reraise, then saved exception state - */ - END_EXC_HANDLER(0, 2, 0), - /** - * Gets the python-level exception object from a {@link PException}. - * - * Pops: a {@link PException} Pushes: python exception - */ - UNWRAP_EXC(0, 1, 1), - - // generators - /** - * Yield value from the stack to the caller. Saves execution state. The generator will resume at - * the next instruction. - * - * Pops: yielded value - */ - YIELD_VALUE(0, 1, 0), - /** - * Wrap value from the stack in a {@link PAsyncGenWrappedValue}. CPython 3.11 opcode, used here - * to avoid a runtime check - * - * Pops: an object Pushes: async_generator_wrapped_value - */ - ASYNCGEN_WRAP(0, 1, 1), - /** - * Resume after yield. Will raise exception passed by {@code throw} if any. - * - * Pushes: value received from {@code send} or {@code None}. - */ - RESUME_YIELD(0, 0, 1), - /** - * Send value into a generator. Jumps forward by the offset in the immediate argument if the - * generator is exhausted. Used to implement {@code yield from}. - * - * Pops: value to be sent, then generator - * - * Pushes (if not jumping): the generator, then the yielded value - * - * Pushes (if jumping): the generator return value - */ - SEND(1, 2, (oparg, followingArgs, withJump) -> withJump ? 1 : 2), - /** - * Exception handler for forwarding {@code throw} calls into {@code yield from}. - * - * Pops: exception, then the generator - * - * Pushes (if not jumping): the generator, then the yielded value - * - * Pushes (if jumping): the generator return value - */ - THROW(1, 2, (oparg, followingArgs, withJump) -> withJump ? 1 : 2), - /** - * Exception handler for async for loops. If the current exception is StopAsyncIteration, handle - * it, otherwise, reraise. - * - * Pops: exception, then the anext coroutine, then the async iterator - */ - END_ASYNC_FOR(0, 3, 0), - - // with statements - /** - * Enter a context manager and save data for its exit. - * - * Pops: the context manager - * - * Pushes: the context manager, then maybe-bound {@code __exit__}, then the result of - * {@code __enter__} - */ - SETUP_WITH(0, 1, 3), - /** - * Run the exit handler of a context manager and reraise if necessary. - * - * Pops: exception or {@code None}, then maybe-bound {@code __exit__}, then the context manager - */ - EXIT_WITH(0, 3, 0), - /** - * Enter a context manager and save data for its exit - * - * Pops: the context manager - * - * Pushes: the context manager, then the maybe-bound async function {@code __aexit__}, then the - * awaitable returned by {@code __aenter__} - */ - SETUP_AWITH(0, 1, 3), - /** - * Run the exit handler of a context manager - * - * Pops: exception or {@code None}, then maybe-bound {@code __aexit__}, then the context manager - * - * Pushes: the exception or {@code None}, then the awaitable returned by {@code __aexit__} - */ - GET_AEXIT_CORO(0, 3, 2), - /** - * Reraise the exception passed to {@code __aexit__} if appropriate - * - * Pops: The result of awaiting {@code __aexit__}, then the exception - */ - EXIT_AWITH(0, 2, 0), - - /* - * Quickened bytecodes - */ - LOAD_TRUE_O(LOAD_TRUE, 0, QuickeningTypes.OBJECT), - LOAD_TRUE_B(LOAD_TRUE, 0, QuickeningTypes.BOOLEAN, LOAD_TRUE_O), - LOAD_FALSE_O(LOAD_FALSE, 0, QuickeningTypes.OBJECT), - LOAD_FALSE_B(LOAD_FALSE, 0, QuickeningTypes.BOOLEAN, LOAD_FALSE_O), - LOAD_BYTE_O(LOAD_BYTE, 0, QuickeningTypes.OBJECT), - LOAD_BYTE_I(LOAD_BYTE, 0, QuickeningTypes.INT, LOAD_BYTE_O), - LOAD_INT_O(LOAD_INT, 0, QuickeningTypes.OBJECT), - LOAD_INT_I(LOAD_INT, 0, QuickeningTypes.INT, LOAD_INT_O), - LOAD_LONG_O(LOAD_LONG, 0, QuickeningTypes.OBJECT), - LOAD_LONG_L(LOAD_LONG, 0, QuickeningTypes.LONG, LOAD_LONG_O), - LOAD_DOUBLE_O(LOAD_DOUBLE, 0, QuickeningTypes.OBJECT), - LOAD_DOUBLE_D(LOAD_DOUBLE, 0, QuickeningTypes.DOUBLE, LOAD_DOUBLE_O), - LOAD_FAST_O(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_ADAPTIVE_O(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_I_BOX(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_BOXED_I(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_I(LOAD_FAST, 0, QuickeningTypes.INT, LOAD_FAST_I_BOX), - LOAD_FAST_L_BOX(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_BOXED_L(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_L(LOAD_FAST, 0, QuickeningTypes.LONG, LOAD_FAST_L_BOX), - LOAD_FAST_D_BOX(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_BOXED_D(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_D(LOAD_FAST, 0, QuickeningTypes.DOUBLE, LOAD_FAST_D_BOX), - LOAD_FAST_B_BOX(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_BOXED_B(LOAD_FAST, 0, QuickeningTypes.OBJECT), - LOAD_FAST_B(LOAD_FAST, 0, QuickeningTypes.BOOLEAN, LOAD_FAST_B_BOX), - STORE_FAST_O(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_UNBOX_I(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_BOXED_I(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_I(STORE_FAST, QuickeningTypes.INT, 0), - STORE_FAST_UNBOX_L(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_BOXED_L(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_L(STORE_FAST, QuickeningTypes.LONG, 0), - STORE_FAST_UNBOX_D(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_BOXED_D(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_D(STORE_FAST, QuickeningTypes.DOUBLE, 0), - STORE_FAST_UNBOX_B(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_BOXED_B(STORE_FAST, QuickeningTypes.OBJECT, 0), - STORE_FAST_B(STORE_FAST, QuickeningTypes.BOOLEAN, 0), - UNARY_OP_ADAPTIVE_O(UNARY_OP, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - UNARY_OP_O_O(UNARY_OP, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - UNARY_OP_I_O(UNARY_OP, QuickeningTypes.INT, QuickeningTypes.OBJECT), - UNARY_OP_I_I(UNARY_OP, QuickeningTypes.INT, QuickeningTypes.INT, UNARY_OP_I_O), - UNARY_OP_D_O(UNARY_OP, QuickeningTypes.DOUBLE, QuickeningTypes.OBJECT), - UNARY_OP_D_D(UNARY_OP, QuickeningTypes.DOUBLE, QuickeningTypes.DOUBLE, UNARY_OP_D_O), - UNARY_OP_B_O(UNARY_OP, QuickeningTypes.BOOLEAN, QuickeningTypes.OBJECT), - UNARY_OP_B_B(UNARY_OP, QuickeningTypes.BOOLEAN, QuickeningTypes.BOOLEAN, UNARY_OP_I_O), - BINARY_OP_ADAPTIVE_O(BINARY_OP, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - BINARY_OP_OO_O(BINARY_OP, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - BINARY_OP_II_O(BINARY_OP, QuickeningTypes.INT, QuickeningTypes.OBJECT), - BINARY_OP_II_I(BINARY_OP, QuickeningTypes.INT, QuickeningTypes.INT, BINARY_OP_II_O), - BINARY_OP_II_B(BINARY_OP, QuickeningTypes.INT, QuickeningTypes.BOOLEAN, BINARY_OP_II_O), - BINARY_OP_DD_O(BINARY_OP, QuickeningTypes.DOUBLE, QuickeningTypes.OBJECT), - BINARY_OP_DD_D(BINARY_OP, QuickeningTypes.DOUBLE, QuickeningTypes.DOUBLE, BINARY_OP_DD_O), - BINARY_OP_DD_B(BINARY_OP, QuickeningTypes.DOUBLE, QuickeningTypes.BOOLEAN, BINARY_OP_DD_O), - FOR_ITER_O(FOR_ITER, 0, QuickeningTypes.OBJECT), - FOR_ITER_I(FOR_ITER, 0, QuickeningTypes.INT, FOR_ITER_O), - BINARY_SUBSCR_ADAPTIVE_O(BINARY_SUBSCR, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - BINARY_SUBSCR_O_O(BINARY_SUBSCR, QuickeningTypes.OBJECT, QuickeningTypes.OBJECT), - BINARY_SUBSCR_SEQ_I_O(BINARY_SUBSCR, QuickeningTypes.INT, QuickeningTypes.OBJECT), - BINARY_SUBSCR_SEQ_I_I(BINARY_SUBSCR, QuickeningTypes.INT, QuickeningTypes.INT, BINARY_SUBSCR_SEQ_I_O), - BINARY_SUBSCR_SEQ_I_D(BINARY_SUBSCR, QuickeningTypes.INT, QuickeningTypes.DOUBLE, BINARY_SUBSCR_SEQ_I_O), - STORE_SUBSCR_OOO(STORE_SUBSCR, QuickeningTypes.OBJECT, 0), - /* - * The index and collection inputs are handled manually in the compiler, the input type - * parameter is used just for the value type. - */ - STORE_SUBSCR_SEQ_IOO(STORE_SUBSCR, QuickeningTypes.OBJECT, 0), - STORE_SUBSCR_SEQ_IIO(STORE_SUBSCR, QuickeningTypes.INT, 0), - STORE_SUBSCR_SEQ_IDO(STORE_SUBSCR, QuickeningTypes.DOUBLE, 0), - POP_AND_JUMP_IF_FALSE_O(POP_AND_JUMP_IF_FALSE, QuickeningTypes.OBJECT, 0), - POP_AND_JUMP_IF_FALSE_B(POP_AND_JUMP_IF_FALSE, QuickeningTypes.BOOLEAN, 0, POP_AND_JUMP_IF_FALSE_O), - POP_AND_JUMP_IF_TRUE_O(POP_AND_JUMP_IF_TRUE, QuickeningTypes.OBJECT, 0), - POP_AND_JUMP_IF_TRUE_B(POP_AND_JUMP_IF_TRUE, QuickeningTypes.BOOLEAN, 0, POP_AND_JUMP_IF_TRUE_O); - - public static final class CollectionBits { - public static final int KIND_MASK = 0b00011111; - public static final int KIND_LIST = 0b00100000; - public static final int KIND_TUPLE = 0b01000000; - public static final int KIND_SET = 0b01100000; - public static final int KIND_DICT = 0b10000000; - public static final int KIND_KWORDS = 0b10100000; - public static final int KIND_OBJECT = 0b11000000; - - public static final byte ELEMENT_INT = 1; - public static final byte ELEMENT_LONG = 2; - public static final byte ELEMENT_BOOLEAN = 3; - public static final byte ELEMENT_DOUBLE = 4; - public static final byte ELEMENT_OBJECT = 5; - - public static int elementCount(int oparg) { - return oparg & KIND_MASK; - } - - public static int elementType(int oparg) { - return oparg & KIND_MASK; - } - - public static int collectionKind(int oparg) { - return oparg & ~KIND_MASK; - } - } - - public static final class MakeFunctionFlags { - public static final int HAS_DEFAULTS = 0x1; - public static final int HAS_KWONLY_DEFAULTS = 0x2; - public static final int HAS_ANNOTATIONS = 0x04; - public static final int HAS_CLOSURE = 0x08; - } - - public static final class MakeTypeParamKind { - public static final int TYPE_VAR = 0; - public static final int TYPE_VAR_TUPLE = 1; - public static final int PARAM_SPEC = 2; - public static final int TYPE_VAR_WITH_BOUND = 3; - public static final int TYPE_VAR_WITH_CONSTRAINTS = 4; - } - - private static final OpCodes[] VALUES = new OpCodes[values().length]; - - public static OpCodes fromOpCode(byte opcode) { - return VALUES[Byte.toUnsignedInt(opcode)]; - } - - static { - assert values().length < 256; - System.arraycopy(values(), 0, VALUES, 0, VALUES.length); - } - - public final StackEffect consumesStackItems; - public final StackEffect producesStackItems; - - /** - * Instruction argument length in bytes - */ - public final int argLength; - public final OpCodes quickens; - public final OpCodes generalizesTo; - private byte quickenInputTypes; - private byte quickenOutputTypes; - - OpCodes(int argLength, int consumesStackItems, int producesStackItems) { - this(argLength, (oparg, followingArgs, withJump) -> consumesStackItems, (oparg, followingArgs, withJump) -> producesStackItems); - } - - OpCodes(int argLength, StackEffect consumesStackItems, int producesStackItems) { - this(argLength, consumesStackItems, (oparg, followingArgs, withJump) -> producesStackItems); - } - - OpCodes(int argLength, int consumesStackItems, StackEffect producesStackItems) { - this(argLength, (oparg, followingArgs, withJump) -> consumesStackItems, producesStackItems); - } - - OpCodes(int argLength, StackEffect consumesStackItems, StackEffect producesStackItems) { - this.argLength = argLength; - this.consumesStackItems = consumesStackItems; - this.producesStackItems = producesStackItems; - this.quickens = null; - this.generalizesTo = null; - } - - OpCodes(OpCodes quickens, int inputType, int outputType) { - this(quickens, inputType, outputType, null); - } - - OpCodes(OpCodes quickens, int inputType, int outputType, OpCodes generalizesTo) { - this.argLength = quickens.argLength; - this.consumesStackItems = quickens.consumesStackItems; - this.producesStackItems = quickens.producesStackItems; - this.generalizesTo = generalizesTo; - this.quickens = quickens; - quickens.quickenInputTypes |= (byte) inputType; - quickens.quickenOutputTypes |= (byte) outputType; - } - - public byte canQuickenInputTypes() { - return quickenInputTypes; - } - - public byte canQuickenOutputTypes() { - return quickenOutputTypes; - } - - @FunctionalInterface - private interface StackEffect { - int stackEffect(int oparg, byte[] followingArgs, boolean withJump); - } - - public boolean hasArg() { - return argLength > 0; - } - - public int length() { - return argLength + 1; - } - - public int getNumberOfConsumedStackItems(int oparg, byte[] followingArgs, boolean withJump) { - return consumesStackItems.stackEffect(oparg, followingArgs, withJump); - } - - public int getNumberOfProducedStackItems(int oparg, byte[] followingArgs, boolean withJump) { - return producesStackItems.stackEffect(oparg, followingArgs, withJump); - } - - public int getStackEffect(int oparg, byte[] followingArgs, boolean withJump) { - return getNumberOfProducedStackItems(oparg, followingArgs, withJump) - getNumberOfConsumedStackItems(oparg, followingArgs, withJump); - } - - public int getNextBci(int bci, int oparg, boolean withJump) { - if (this.quickens != null) { - return this.quickens.getNextBci(bci, oparg, withJump); - } - switch (this) { - case JUMP_FORWARD: - return bci + oparg; - case JUMP_BACKWARD: - return bci - oparg; - case POP_AND_JUMP_IF_FALSE: - case POP_AND_JUMP_IF_TRUE: - case JUMP_IF_FALSE_OR_POP: - case JUMP_IF_TRUE_OR_POP: - case FOR_ITER: - case MATCH_EXC_OR_JUMP: - case SEND: - case THROW: - return withJump ? bci + oparg : bci + length(); - case RETURN_VALUE: - case RAISE_VARARGS: - case END_EXC_HANDLER: - return -1; - case EXTENDED_ARG: - assert false : "EXTENDED_ARG passed to getNextBci."; - return -1; - default: - return bci + length(); - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java index 06672de1c3..d557bb0158 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java @@ -90,9 +90,9 @@ import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.type.TypeFlags; +import com.oracle.graal.python.compiler.CollectionBits; import com.oracle.graal.python.compiler.CompilationScope; -import com.oracle.graal.python.compiler.OpCodes.CollectionBits; -import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; +import com.oracle.graal.python.compiler.MakeTypeParamKind; import com.oracle.graal.python.compiler.SSTUtils; import com.oracle.graal.python.compiler.Unparser; import com.oracle.graal.python.compiler.bytecode_dsl.BytecodeDSLCompiler.BytecodeDSLCompilerContext; diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java index 2669fe24b9..ee29e5c6f6 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, 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 @@ -44,7 +44,7 @@ import com.oracle.graal.python.PythonLanguage; import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; +import com.oracle.graal.python.compiler.MakeTypeParamKind; import com.oracle.graal.python.nodes.PNodeWithContext; import com.oracle.graal.python.runtime.object.PFactory; import com.oracle.truffle.api.dsl.Bind; 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 4ed9050581..a9d31dc43c 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 @@ -120,7 +120,7 @@ import com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.CallSlotDescrGet; import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.CallSlotTpIterNextNode; import com.oracle.graal.python.builtins.objects.typing.PTypeAliasType; -import com.oracle.graal.python.compiler.OpCodes.MakeTypeParamKind; +import com.oracle.graal.python.compiler.MakeTypeParamKind; import com.oracle.graal.python.compiler.ParserCallbacksImpl; import com.oracle.graal.python.lib.IteratorExhausted; import com.oracle.graal.python.lib.PyGenFetchStopIterationValue; From c22c4283dc4fd898b43ef317c38b0fe9f26e2ea0 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 16:44:19 +0200 Subject: [PATCH 15/20] Remove unused bytecode nodes --- .../python/compiler/QuickeningTypes.java | 82 ----- .../nodes/bytecode/AbstractKwargsNode.java | 74 ----- .../nodes/bytecode/BinarySubscrSeq.java | 164 ---------- .../nodes/bytecode/CallComprehensionNode.java | 73 ----- .../nodes/bytecode/EndAsyncForNode.java | 89 ------ .../python/nodes/bytecode/ExitAWithNode.java | 94 ------ .../python/nodes/bytecode/ExitWithNode.java | 121 -------- .../python/nodes/bytecode/ForIterINode.java | 110 ------- .../python/nodes/bytecode/ForIterONode.java | 102 ------- .../nodes/bytecode/GetAExitCoroNode.java | 103 ------- ...ingStorageFromListSequenceStorageNode.java | 87 ------ .../graal/python/nodes/bytecode/InNode.java | 67 ---- ...strumentationMaterializationForwarder.java | 92 ------ .../python/nodes/bytecode/KeywordsNode.java | 90 ------ .../nodes/bytecode/KwargsMergeNode.java | 98 ------ .../nodes/bytecode/MakeGenericNode.java | 87 ------ .../nodes/bytecode/MakeTypeAliasNode.java | 87 ------ .../nodes/bytecode/MakeTypeParamNode.java | 102 ------- .../nodes/bytecode/PRaiseCachedNode.java | 75 ----- .../QuickeningGeneralizeException.java | 53 ---- .../bytecode/ReadFromDictOrGlobalsNode.java | 99 ------ .../graal/python/nodes/bytecode/SendNode.java | 145 --------- .../nodes/bytecode/SequenceFromStackNode.java | 288 ------------------ .../python/nodes/bytecode/SetupAwithNode.java | 100 ------ .../python/nodes/bytecode/SetupWithNode.java | 100 ------ .../python/nodes/bytecode/StoreSubscrSeq.java | 136 --------- .../python/nodes/bytecode/ThrowNode.java | 161 ---------- .../python/nodes/bytecode/UnpackExNode.java | 179 ----------- .../nodes/bytecode/UnpackSequenceNode.java | 143 --------- 29 files changed, 3201 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/QuickeningTypes.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BinarySubscrSeq.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CallComprehensionNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/EndAsyncForNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitAWithNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitWithNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAExitCoroNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/HashingStorageFromListSequenceStorageNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InstrumentationMaterializationForwarder.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeGenericNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeAliasNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/QuickeningGeneralizeException.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ReadFromDictOrGlobalsNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SendNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SequenceFromStackNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/StoreSubscrSeq.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ThrowNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/QuickeningTypes.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/QuickeningTypes.java deleted file mode 100644 index 328f78694c..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/QuickeningTypes.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.frame.FrameSlotKind; - -public abstract class QuickeningTypes { - public static final byte OBJECT = 1; - public static final byte INT = 2; - public static final byte LONG = 4; - public static final byte DOUBLE = 8; - public static final byte BOOLEAN = 16; - - public static byte fromFrameSlotTag(byte tag) { - if (tag == FrameSlotKind.Object.tag) { - return OBJECT; - } else if (tag == FrameSlotKind.Int.tag) { - return INT; - } else if (tag == FrameSlotKind.Long.tag) { - return LONG; - } else if (tag == FrameSlotKind.Double.tag) { - return DOUBLE; - } else if (tag == FrameSlotKind.Boolean.tag) { - return BOOLEAN; - } else { - throw CompilerDirectives.shouldNotReachHere("Unknown stack item type"); - } - } - - public static byte fromObjectType(Object object) { - if (object instanceof Integer) { - return INT; - } else if (object instanceof Long) { - return LONG; - } else if (object instanceof Double) { - return DOUBLE; - } else if (object instanceof Boolean) { - return BOOLEAN; - } else { - return OBJECT; - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java deleted file mode 100644 index b1c38f6235..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/AbstractKwargsNode.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.lib.PyObjectFunctionStr; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.argument.keywords.NonMappingException; -import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException; -import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -public class AbstractKwargsNode extends PNodeWithContext { - protected static PException handleNonMapping(VirtualFrame frame, Node inliningTarget, BoundaryCallData boundaryCallData, PRaiseNode raise, int stackTop, NonMappingException e) { - Object functionName = AbstractKwargsNode.getFunctionName(frame, boundaryCallData, stackTop); - throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.ARG_AFTER_MUST_BE_MAPPING, functionName, e.getObject()); - } - - protected static PException handleSameKey(VirtualFrame frame, Node inliningTarget, BoundaryCallData boundaryCallData, PRaiseNode raise, int stackTop, SameDictKeyException e) { - Object functionName = AbstractKwargsNode.getFunctionName(frame, boundaryCallData, stackTop); - throw raise.raise(inliningTarget, PythonBuiltinClassType.TypeError, ErrorMessages.S_GOT_MULTIPLE_VALUES_FOR_KEYWORD_ARG, functionName, e.getKey()); - } - - private static Object getFunctionName(VirtualFrame frame, BoundaryCallData boundaryCallData, int stackTop) { - /* - * The instruction is only emitted when generating CALL_FUNCTION_KW. The stack layout at - * this point is [kwargs dict, varargs, callable]. - */ - Object callable = frame.getObject(stackTop - 2); - return PyObjectFunctionStr.execute(frame, boundaryCallData, callable); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BinarySubscrSeq.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BinarySubscrSeq.java deleted file mode 100644 index a42a0239d1..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/BinarySubscrSeq.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2022, 2024, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; -import com.oracle.graal.python.builtins.objects.list.PList; -import com.oracle.graal.python.builtins.objects.tuple.PTuple; -import com.oracle.graal.python.nodes.PGuards; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.nodes.UnexpectedResultException; - -@ImportStatic(PGuards.class) -public abstract class BinarySubscrSeq extends Node { - public static final QuickeningGeneralizeException GENERALIZE_RESULT = new QuickeningGeneralizeException(0); - public static final QuickeningGeneralizeException GENERALIZE_COLLECTION = new QuickeningGeneralizeException(0); - - @GenerateInline(false) // used in BCI root node - public abstract static class ONode extends BinarySubscrSeq { - public abstract Object execute(Object sequence, int index); - - @Specialization(guards = "isBuiltinList(sequence)") - Object doList(PList sequence, int index, - @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) { - return getItemNode.execute(sequence.getSequenceStorage(), index); - } - - @Specialization(guards = "isBuiltinTuple(sequence)") - Object doList(PTuple sequence, int index, - @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) { - return getItemNode.execute(sequence.getSequenceStorage(), index); - } - - @Fallback - @SuppressWarnings("unused") - Object doGeneralize(Object sequence, int index) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw GENERALIZE_COLLECTION; - } - - public static ONode create() { - return BinarySubscrSeqFactory.ONodeGen.create(); - } - } - - @GenerateInline(false) // used in BCI root node - public abstract static class INode extends BinarySubscrSeq { - public abstract int execute(Object sequence, int index) throws QuickeningGeneralizeException; - - @Specialization(guards = "isBuiltinList(sequence)") - int doList(PList sequence, int index, - @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) { - try { - return getItemNode.executeInt(sequence.getSequenceStorage(), index); - } catch (UnexpectedResultException e) { - // Truffle doesn't let us throw UnexpectedResultException without rewriteOn - throw GENERALIZE_RESULT; - } - } - - @Specialization(guards = "isBuiltinTuple(sequence)") - int doList(PTuple sequence, int index, - @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) { - try { - return getItemNode.executeInt(sequence.getSequenceStorage(), index); - } catch (UnexpectedResultException e) { - // Truffle doesn't let us throw UnexpectedResultException without rewriteOn - throw GENERALIZE_RESULT; - } - } - - @Fallback - @SuppressWarnings("unused") - int doGeneralize(Object sequence, int index) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw GENERALIZE_COLLECTION; - } - - public static INode create() { - return BinarySubscrSeqFactory.INodeGen.create(); - } - } - - @GenerateInline(false) // used in BCI root node - public abstract static class DNode extends BinarySubscrSeq { - public abstract double execute(Object sequence, int index); - - @Specialization(guards = "isBuiltinList(sequence)") - double doList(PList sequence, int index, - @Cached("createForList()") SequenceStorageNodes.GetItemNode getItemNode) { - try { - return getItemNode.executeDouble(sequence.getSequenceStorage(), index); - } catch (UnexpectedResultException e) { - // Truffle doesn't let us throw UnexpectedResultException without rewriteOn - throw GENERALIZE_RESULT; - } - } - - @Specialization(guards = "isBuiltinTuple(sequence)") - double doList(PTuple sequence, int index, - @Cached("createForTuple()") SequenceStorageNodes.GetItemNode getItemNode) { - try { - return getItemNode.executeDouble(sequence.getSequenceStorage(), index); - } catch (UnexpectedResultException e) { - // Truffle doesn't let us throw UnexpectedResultException without rewriteOn - throw GENERALIZE_RESULT; - } - } - - @Fallback - @SuppressWarnings("unused") - double doGeneralize(Object sequence, int index) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw GENERALIZE_COLLECTION; - } - - public static DNode create() { - return BinarySubscrSeqFactory.DNodeGen.create(); - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CallComprehensionNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CallComprehensionNode.java deleted file mode 100644 index f6d4a0087c..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/CallComprehensionNode.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.function.PFunction; -import com.oracle.graal.python.nodes.call.CallDispatchers; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.DirectCallNode; -import com.oracle.truffle.api.nodes.Node; - -@GenerateInline(false) -@ImportStatic(CallDispatchers.class) -public abstract class CallComprehensionNode extends Node { - public abstract Object execute(VirtualFrame frame, PFunction callee, Object[] arguments); - - // No guard, comprehension functions don't change - @Specialization - static Object call(VirtualFrame frame, PFunction callee, Object[] arguments, - @Bind Node inliningTarget, - @Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode, - @Cached CallDispatchers.FunctionDirectInvokeNode invoke) { - return invoke.execute(frame, inliningTarget, callNode, callee, arguments); - } - - @NeverDefault - public static CallComprehensionNode create() { - return CallComprehensionNodeGen.create(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/EndAsyncForNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/EndAsyncForNode.java deleted file mode 100644 index 9d49843ffd..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/EndAsyncForNode.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@ImportStatic(PythonBuiltinClassType.class) -@GenerateInline(false) // used in bytecode root node -public abstract class EndAsyncForNode extends PNodeWithContext { - public abstract void execute(Object exception, boolean rootNodeVisible); - - public static EndAsyncForNode getUncached() { - return EndAsyncForNodeGen.getUncached(); - } - - public static EndAsyncForNode create() { - return EndAsyncForNodeGen.create(); - } - - @Specialization - @SuppressWarnings("unused") - void doNone(PNone none, boolean rootNodeVisible) { - } - - @Specialization - static void doPException(PException exception, boolean rootNodeVisible, - @Bind Node inliningTarget, - @Cached IsBuiltinObjectProfile isStopAsyncIteration) { - if (!isStopAsyncIteration.profileException(inliningTarget, exception, PythonBuiltinClassType.StopAsyncIteration)) { - throw exception.getExceptionForReraise(rootNodeVisible); - } - } - - @Specialization(guards = "!isPException(exception)") - void doInteropException(AbstractTruffleException exception, @SuppressWarnings("unused") boolean rootNodeVisible) { - throw exception; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitAWithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitAWithNode.java deleted file mode 100644 index 3ee0d871b3..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitAWithNode.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.lib.PyObjectIsTrueNode; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; - -@GenerateUncached -@GenerateInline(false) // Used in BCI -public abstract class ExitAWithNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop, boolean rootNodeVisible); - - @Specialization - int exit(VirtualFrame virtualFrame, int stackTopIn, boolean rootNodeVisible, - @Cached PyObjectIsTrueNode isTrueNode) { - int stackTop = stackTopIn; - Object result = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object exception = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - AbstractTruffleException savedExcState = PArguments.getException(virtualFrame); - try { - if (!isTrueNode.execute(virtualFrame, result) && exception != PNone.NONE) { - if (exception instanceof PException) { - throw ((PException) exception).getExceptionForReraise(rootNodeVisible); - } else if (exception instanceof AbstractTruffleException) { - throw (AbstractTruffleException) exception; - } else { - throw CompilerDirectives.shouldNotReachHere("Exception not on stack"); - } - } - } finally { - PArguments.setException(virtualFrame, savedExcState); - } - return stackTop; - } - - public static ExitAWithNode create() { - return ExitAWithNodeGen.create(); - } - - public static ExitAWithNode getUncached() { - return ExitAWithNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitWithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitWithNode.java deleted file mode 100644 index 7238eec0c4..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ExitWithNode.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.lib.PyObjectIsTrueNode; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.call.special.CallQuaternaryMethodNode; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // Used in BCI -public abstract class ExitWithNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop, boolean rootNodeVisible); - - @Specialization - int exit(VirtualFrame virtualFrame, int stackTopIn, boolean rootNodeVisible, - @Bind Node inliningTarget, - @Cached CallQuaternaryMethodNode callExit, - @Cached GetClassNode getClassNode, - @Cached ExceptionNodes.GetTracebackNode getTracebackNode, - @Cached PyObjectIsTrueNode isTrueNode) { - int stackTop = stackTopIn; - Object exception = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object exit = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object contextManager = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - if (exception == PNone.NONE) { - callExit.execute(virtualFrame, exit, contextManager, PNone.NONE, PNone.NONE, PNone.NONE); - } else { - AbstractTruffleException savedExcState = PArguments.getException(virtualFrame); - try { - Object pythonException = exception; - if (exception instanceof PException) { - PArguments.setException(virtualFrame, (PException) exception); - pythonException = ((PException) exception).getEscapedException(); - } else if (exception instanceof AbstractTruffleException) { - PArguments.setException(virtualFrame, (AbstractTruffleException) exception); - } - Object excType = getClassNode.execute(inliningTarget, pythonException); - Object excTraceback = getTracebackNode.execute(inliningTarget, pythonException); - Object result = callExit.execute(virtualFrame, exit, contextManager, excType, pythonException, excTraceback); - if (!isTrueNode.execute(virtualFrame, result)) { - if (exception instanceof PException) { - throw ((PException) exception).getExceptionForReraise(rootNodeVisible); - } else if (exception instanceof AbstractTruffleException) { - throw (AbstractTruffleException) exception; - } else { - throw CompilerDirectives.shouldNotReachHere("Exception not on stack"); - } - } - } finally { - PArguments.setException(virtualFrame, savedExcState); - } - } - return stackTop; - } - - @NeverDefault - public static ExitWithNode create() { - return ExitWithNodeGen.create(); - } - - public static ExitWithNode getUncached() { - return ExitWithNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java deleted file mode 100644 index 9ee702f8de..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterINode.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2018, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator; -import com.oracle.graal.python.compiler.QuickeningTypes; -import com.oracle.graal.python.lib.IteratorExhausted; -import com.oracle.graal.python.lib.PyIterNextNode; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedCountingConditionProfile; - -@GenerateUncached -@GenerateInline(false) // Used in BCI -public abstract class ForIterINode extends PNodeWithContext { - public abstract boolean execute(Frame frame, Object iterator, int stackTop) throws QuickeningGeneralizeException; - - @Specialization - boolean doIntRange(VirtualFrame frame, PIntRangeIterator iterator, int stackTop, - @Bind Node inliningTarget, - /* - * Not using LoopConditionProfile because when OSR-compiled, we might never - * register the condition being false - */ - @Cached InlinedCountingConditionProfile conditionProfile) { - if (conditionProfile.profile(inliningTarget, iterator.hasNextInt())) { - frame.setInt(stackTop, iterator.nextInt()); - return true; - } - iterator.setExhausted(); - return false; - } - - // TODO list, tuple, enumerate, dict keys, dict values, dict items, string, bytes - - @Specialization - @InliningCutoff - static boolean doGeneric(VirtualFrame frame, Object iterator, int stackTop, - @Bind Node inliningTarget, - @Cached PyIterNextNode nextNode) throws QuickeningGeneralizeException { - try { - Object res = nextNode.execute(frame, inliningTarget, iterator); - if (res instanceof Integer) { - frame.setInt(stackTop, (int) res); - return true; - } else { - CompilerDirectives.transferToInterpreterAndInvalidate(); - frame.setObject(stackTop, res); - throw new QuickeningGeneralizeException(QuickeningTypes.OBJECT); - } - } catch (IteratorExhausted e) { - return false; - } - } - - public static ForIterINode create() { - return ForIterINodeGen.create(); - } - - public static ForIterINode getUncached() { - return ForIterINodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java deleted file mode 100644 index a0337e6334..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ForIterONode.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2018, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.iterator.PIntRangeIterator; -import com.oracle.graal.python.lib.IteratorExhausted; -import com.oracle.graal.python.lib.PyIterNextNode; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedCountingConditionProfile; - -@GenerateUncached -@GenerateInline(false) // Used in BCI -public abstract class ForIterONode extends PNodeWithContext { - public abstract boolean execute(Frame frame, Object iterator, int stackTop); - - @Specialization - boolean doIntRange(VirtualFrame frame, PIntRangeIterator iterator, int stackTop, - @Bind Node inliningTarget, - /* - * Not using LoopConditionProfile because when OSR-compiled, we might never - * register the condition being false - */ - @Cached InlinedCountingConditionProfile conditionProfile) { - if (conditionProfile.profile(inliningTarget, iterator.hasNextInt())) { - frame.setObject(stackTop, iterator.nextInt()); - return true; - } - iterator.setExhausted(); - return false; - } - - // TODO list, tuple, enumerate, dict keys, dict values, dict items, string, bytes - - @Specialization - @InliningCutoff - static boolean doGeneric(VirtualFrame frame, Object iterator, int stackTop, - @Bind Node inliningTarget, - @Cached PyIterNextNode nextNode) { - try { - Object res = nextNode.execute(frame, inliningTarget, iterator); - frame.setObject(stackTop, res); - return true; - } catch (IteratorExhausted e) { - return false; - } - } - - public static ForIterONode create() { - return ForIterONodeGen.create(); - } - - public static ForIterONode getUncached() { - return ForIterONodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAExitCoroNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAExitCoroNode.java deleted file mode 100644 index 18de84dbc3..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetAExitCoroNode.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes; -import com.oracle.graal.python.builtins.objects.function.PArguments; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.call.special.CallQuaternaryMethodNode; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class GetAExitCoroNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop); - - @Specialization - int exit(VirtualFrame virtualFrame, int stackTopIn, - @Bind Node inliningTarget, - @Cached CallQuaternaryMethodNode callExit, - @Cached GetClassNode getClassNode, - @Cached ExceptionNodes.GetTracebackNode getTracebackNode) { - int stackTop = stackTopIn; - Object exception = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object exit = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - Object contextManager = virtualFrame.getObject(stackTop); - virtualFrame.setObject(stackTop--, null); - if (exception == PNone.NONE) { - Object result = callExit.execute(virtualFrame, exit, contextManager, PNone.NONE, PNone.NONE, PNone.NONE); - virtualFrame.setObject(++stackTop, PNone.NONE); - virtualFrame.setObject(++stackTop, result); - } else { - Object pythonException = exception; - if (exception instanceof PException) { - PArguments.setException(virtualFrame, (PException) exception); - pythonException = ((PException) exception).getEscapedException(); - } - Object excType = getClassNode.execute(inliningTarget, pythonException); - Object excTraceback = getTracebackNode.execute(inliningTarget, pythonException); - Object result = callExit.execute(virtualFrame, exit, contextManager, excType, pythonException, excTraceback); - virtualFrame.setObject(++stackTop, exception); - virtualFrame.setObject(++stackTop, result); - } - return stackTop; - } - - public static GetAExitCoroNode create() { - return GetAExitCoroNodeGen.create(); - } - - public static GetAExitCoroNode getUncached() { - return GetAExitCoroNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/HashingStorageFromListSequenceStorageNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/HashingStorageFromListSequenceStorageNode.java deleted file mode 100644 index 13bfe1b478..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/HashingStorageFromListSequenceStorageNode.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.common.EmptyStorage; -import com.oracle.graal.python.builtins.objects.common.HashingStorage; -import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageSetItem; -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.LoopNode; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedLoopConditionProfile; - -@GenerateInline(false) // used in BCI root node -abstract class HashingStorageFromListSequenceStorageNode extends PNodeWithContext { - - public abstract HashingStorage execute(Frame virtualFrame, SequenceStorage sequenceStorage); - - @Specialization - HashingStorage doIt(VirtualFrame frame, SequenceStorage sequenceStorage, - @Bind Node inliningTarget, - @Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode, - @Cached HashingStorageSetItem setItem, - @Cached InlinedLoopConditionProfile loopConditionProfile) { - HashingStorage setStorage = EmptyStorage.INSTANCE; - int length = sequenceStorage.length(); - loopConditionProfile.profileCounted(inliningTarget, length); - LoopNode.reportLoopCount(inliningTarget, length); - for (int i = 0; loopConditionProfile.inject(inliningTarget, i < length); ++i) { - Object o = getItemNode.execute(sequenceStorage, i); - setStorage = setItem.execute(frame, inliningTarget, setStorage, o, PNone.NONE); - } - return setStorage; - } - - @NeverDefault - static HashingStorageFromListSequenceStorageNode create() { - return HashingStorageFromListSequenceStorageNodeGen.create(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InNode.java deleted file mode 100644 index 2d928803f2..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InNode.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.lib.PySequenceContainsNode; -import com.oracle.graal.python.nodes.expression.BinaryOpNode; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateInline(false) -abstract class InNode extends BinaryOpNode { - - @Specialization - Object contains(VirtualFrame frame, Object item, Object container, - @Bind Node inliningTarget, - @Cached PySequenceContainsNode containsNode) { - return containsNode.execute(frame, inliningTarget, container, item); - } - - @NeverDefault - public static InNode create() { - return InNodeGen.create(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InstrumentationMaterializationForwarder.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InstrumentationMaterializationForwarder.java deleted file mode 100644 index 5eaa2736ac..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/InstrumentationMaterializationForwarder.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import java.util.Set; - -import com.oracle.truffle.api.instrumentation.InstrumentableNode; -import com.oracle.truffle.api.instrumentation.ProbeNode; -import com.oracle.truffle.api.instrumentation.Tag; -import com.oracle.truffle.api.nodes.Node; - -class InstrumentationMaterializationForwarder extends Node implements InstrumentableNode { - private final InstrumentableNode delegate; - - InstrumentationMaterializationForwarder(InstrumentableNode delegate) { - this.delegate = delegate; - } - - @Override - public boolean isInstrumentable() { - return true; - } - - @Override - public WrapperNode createWrapper(ProbeNode probe) { - return new Wrapper(this, probe); - } - - @Override - public InstrumentableNode materializeInstrumentableNodes(Set> materializedTags) { - delegate.materializeInstrumentableNodes(materializedTags); - return this; - } - - private static class Wrapper extends Node implements WrapperNode { - @Child private Node delegateNode; - @Child private ProbeNode probeNode; - - Wrapper(Node delegateNode, ProbeNode probeNode) { - this.delegateNode = delegateNode; - this.probeNode = probeNode; - } - - @Override - public Node getDelegateNode() { - return delegateNode; - } - - @Override - public ProbeNode getProbeNode() { - return probeNode; - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java deleted file mode 100644 index 4d89287cab..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KeywordsNode.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.function.PKeyword; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.argument.keywords.MappingToKeywordsNode; -import com.oracle.graal.python.nodes.argument.keywords.NonMappingException; -import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException; -import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedBranchProfile; - -@GenerateUncached -@GenerateInline(false) // Used in BCI -public abstract class KeywordsNode extends AbstractKwargsNode { - public abstract PKeyword[] execute(Frame frame, Object sourceCollection, int stackTop); - - @Specialization - static PKeyword[] kwords(VirtualFrame frame, Object sourceCollection, int stackTop, - @Bind Node inliningTarget, - @Cached MappingToKeywordsNode expandKeywordStarargsNode, - @Cached InlinedBranchProfile keywordsError1, - @Cached InlinedBranchProfile keywordsError2, - @Cached("createFor($node)") BoundaryCallData boundaryCallData, - @Cached PRaiseNode raise) { - try { - return expandKeywordStarargsNode.execute(frame, inliningTarget, sourceCollection); - } catch (SameDictKeyException e) { - keywordsError1.enter(inliningTarget); - throw handleSameKey(frame, inliningTarget, boundaryCallData, raise, stackTop, e); - } catch (NonMappingException e) { - keywordsError2.enter(inliningTarget); - throw handleNonMapping(frame, inliningTarget, boundaryCallData, raise, stackTop, e); - } - } - - public static KeywordsNode create() { - return KeywordsNodeGen.create(); - } - - public static KeywordsNode getUncached() { - return KeywordsNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java deleted file mode 100644 index 1bf3a65c69..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/KwargsMergeNode.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.common.HashingStorage; -import com.oracle.graal.python.builtins.objects.dict.PDict; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.argument.keywords.ConcatDictToStorageNode; -import com.oracle.graal.python.nodes.argument.keywords.NonMappingException; -import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException; -import com.oracle.graal.python.runtime.IndirectCallData.BoundaryCallData; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedBranchProfile; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class KwargsMergeNode extends AbstractKwargsNode { - public abstract int execute(Frame frame, int stackTop); - - @Specialization - static int merge(VirtualFrame frame, int initialStackTop, - @Bind Node inliningTarget, - @Cached ConcatDictToStorageNode concatNode, - @Cached PRaiseNode raise, - @Cached InlinedBranchProfile keywordsError1, - @Cached("createFor($node)") BoundaryCallData boundaryCallData, - @Cached InlinedBranchProfile keywordsError2) { - int stackTop = initialStackTop; - Object mapping = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - PDict dict = (PDict) frame.getObject(stackTop); - try { - HashingStorage resultStorage = concatNode.execute(frame, dict.getDictStorage(), mapping); - dict.setDictStorage(resultStorage); - } catch (SameDictKeyException e) { - keywordsError1.enter(inliningTarget); - throw handleSameKey(frame, inliningTarget, boundaryCallData, raise, stackTop, e); - } catch (NonMappingException e) { - keywordsError2.enter(inliningTarget); - throw handleNonMapping(frame, inliningTarget, boundaryCallData, raise, stackTop, e); - } - return stackTop; - } - - public static KwargsMergeNode create() { - return KwargsMergeNodeGen.create(); - } - - public static KwargsMergeNode getUncached() { - return KwargsMergeNodeGen.getUncached(); - } - -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeGenericNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeGenericNode.java deleted file mode 100644 index ecef23467c..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeGenericNode.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.builtins.modules.TypingModuleBuiltins; -import com.oracle.graal.python.builtins.modules.TypingModuleBuiltins.CallTypingFuncObjectNode; -import com.oracle.graal.python.builtins.modules.TypingModuleBuiltins.UnpackTypeVarTuplesNode; -import com.oracle.graal.python.builtins.objects.tuple.PTuple; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateInline(false) // 68 -> 52 -@GenerateUncached -public abstract class MakeGenericNode extends PNodeWithContext { - - public abstract int execute(VirtualFrame frame, int initialStackTop); - - @Specialization - static int makeGeneric(VirtualFrame frame, int initialStackTop, - @Bind Node inliningTarget, - @Cached UnpackTypeVarTuplesNode unpackTypeVarTuplesNode, - @Cached CallTypingFuncObjectNode callTypingFuncObjectNode) { - int stackTop = initialStackTop; - - PTuple params = (PTuple) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - - params = unpackTypeVarTuplesNode.execute(frame, inliningTarget, params); - Object result = callTypingFuncObjectNode.execute(frame, inliningTarget, TypingModuleBuiltins.T_GENERIC_ALIAS, PythonBuiltinClassType.PGeneric, params); - - frame.setObject(++stackTop, result); - return stackTop; - } - - public static MakeGenericNode create() { - return MakeGenericNodeGen.create(); - } - - public static MakeGenericNode getUncached() { - return MakeGenericNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeAliasNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeAliasNode.java deleted file mode 100644 index a3b157931a..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeAliasNode.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.tuple.PTuple; -import com.oracle.graal.python.builtins.objects.typing.PTypeAliasType; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.strings.TruffleString; - -@GenerateInline(false) // 16 -> 0 -@GenerateUncached -public abstract class MakeTypeAliasNode extends PNodeWithContext { - - public abstract int execute(VirtualFrame frame, int initialStackTop); - - @Specialization - int makeTypeAlias(VirtualFrame frame, int initialStackTop, - @Bind PythonLanguage language) { - int stackTop = initialStackTop; - - Object computeValue = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - Object typeParams = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - TruffleString name = (TruffleString) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - - PTypeAliasType result = PFactory.createTypeAliasType(language, name, typeParams == PNone.NONE ? null : (PTuple) typeParams, computeValue, null, null); - - frame.setObject(++stackTop, result); - return stackTop; - } - - public static MakeTypeAliasNode create() { - return MakeTypeAliasNodeGen.create(); - } - - public static MakeTypeAliasNode getUncached() { - return MakeTypeAliasNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java deleted file mode 100644 index ee29e5c6f6..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/MakeTypeParamNode.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2025, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.compiler.MakeTypeParamKind; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.strings.TruffleString; - -@GenerateInline(false) // 16 -> 0 -@GenerateUncached -public abstract class MakeTypeParamNode extends PNodeWithContext { - - public abstract int execute(VirtualFrame frame, int initialStackTop, int kind); - - @Specialization - int makeTypeParam(VirtualFrame frame, int initialStackTop, int kind, - @Bind PythonLanguage language) { - int stackTop = initialStackTop; - - Object evaluateBound = null; - Object evaluateConstraints = null; - - if (kind == MakeTypeParamKind.TYPE_VAR_WITH_BOUND) { - evaluateBound = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } else if (kind == MakeTypeParamKind.TYPE_VAR_WITH_CONSTRAINTS) { - evaluateConstraints = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - } - TruffleString name = (TruffleString) frame.getObject(stackTop); - frame.setObject(stackTop--, null); - - Object result = switch (kind) { - case MakeTypeParamKind.TYPE_VAR, MakeTypeParamKind.TYPE_VAR_WITH_BOUND, MakeTypeParamKind.TYPE_VAR_WITH_CONSTRAINTS -> PFactory.createTypeVar(language, name, - evaluateBound == null ? PNone.NONE : null, evaluateBound, - evaluateConstraints == null ? PFactory.createEmptyTuple(language) : null, evaluateConstraints, - false, false, true); - case MakeTypeParamKind.PARAM_SPEC -> PFactory.createParamSpec(language, name, PNone.NONE, false, false, true); - case MakeTypeParamKind.TYPE_VAR_TUPLE -> PFactory.createTypeVarTuple(language, name); - default -> throw shouldNotReachHere(); - }; - - frame.setObject(++stackTop, result); - return stackTop; - } - - public static MakeTypeParamNode create() { - return MakeTypeParamNodeGen.create(); - } - - public static MakeTypeParamNode getUncached() { - return MakeTypeParamNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java deleted file mode 100644 index eb372bbea2..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PRaiseCachedNode.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.PythonBuiltinClassType; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.strings.TruffleString; - -@GenerateInline(false) // 16 -> 0 -@GenerateUncached -abstract class PRaiseCachedNode extends Node { - public final PException raise(PythonBuiltinClassType type, TruffleString format, Object... formatArgs) { - throw execute(type, format, formatArgs); - } - - protected abstract PException execute(PythonBuiltinClassType type, TruffleString format, Object[] formatArgs); - - @Specialization - PException doRaise(PythonBuiltinClassType type, TruffleString format, Object[] formatArgs) { - throw PRaiseNode.raiseStatic(this, type, format, formatArgs); - } - - @NeverDefault - public static PRaiseCachedNode create() { - return PRaiseCachedNodeGen.create(); - } - - public static PRaiseCachedNode getUncached() { - return PRaiseCachedNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/QuickeningGeneralizeException.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/QuickeningGeneralizeException.java deleted file mode 100644 index 72c700dea2..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/QuickeningGeneralizeException.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.truffle.api.nodes.ControlFlowException; - -public class QuickeningGeneralizeException extends ControlFlowException { - private static final long serialVersionUID = -5530902591292387434L; - - public final int type; - - public QuickeningGeneralizeException(int type) { - this.type = type; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ReadFromDictOrGlobalsNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ReadFromDictOrGlobalsNode.java deleted file mode 100644 index fc84d2a38c..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ReadFromDictOrGlobalsNode.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.runtime.exception.PythonErrorType.KeyError; - -import com.oracle.graal.python.lib.PyObjectGetItem; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateCached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.NeverDefault; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.strings.TruffleString; - -@GenerateUncached -@GenerateCached -@GenerateInline(false) // 52 -> 36 -public abstract class ReadFromDictOrGlobalsNode extends PNodeWithContext { - - public abstract int execute(VirtualFrame frame, int initialStackTop, Object globals, TruffleString name); - - @Specialization - static int read(VirtualFrame frame, int initialStackTop, Object globals, TruffleString name, - @Bind Node inliningTarget, - @Cached PyObjectGetItem getItemNode, - @Cached ReadGlobalOrBuiltinNode readGlobal, - @Cached IsBuiltinObjectProfile errorProfile) { - int stackTop = initialStackTop; - - Object dict = frame.getObject(stackTop); - frame.setObject(stackTop--, null); - Object value; - try { - value = getItemNode.executeCached(frame, dict, name); - } catch (PException e) { - e.expect(inliningTarget, KeyError, errorProfile); - value = readGlobal.read(frame, globals, name); - } - - frame.setObject(++stackTop, value); - return stackTop; - } - - @NeverDefault - public static ReadFromDictOrGlobalsNode create() { - return ReadFromDictOrGlobalsNodeGen.create(); - } - - @NeverDefault - public static ReadFromDictOrGlobalsNode getUncached() { - return ReadFromDictOrGlobalsNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SendNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SendNode.java deleted file mode 100644 index 8fd4a716fa..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SendNode.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.nodes.BuiltinNames.T_SEND; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.exception.PBaseException; -import com.oracle.graal.python.builtins.objects.generator.CommonGeneratorBuiltins; -import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.builtins.objects.type.TpSlots; -import com.oracle.graal.python.builtins.objects.type.TpSlots.GetObjectSlotsNode; -import com.oracle.graal.python.builtins.objects.type.slots.TpSlotIterNext.CallSlotTpIterNextNode; -import com.oracle.graal.python.lib.IteratorExhausted; -import com.oracle.graal.python.lib.PyGenFetchStopIterationValue; -import com.oracle.graal.python.lib.PyIterCheckNode; -import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedBranchProfile; - -@GenerateInline(false) // used in BCI root node -public abstract class SendNode extends PNodeWithContext { - - // Returns true when the generator finished - public abstract boolean execute(VirtualFrame virtualFrame, int stackTop, Object iter, Object arg); - - @Specialization - static boolean doGenerator(VirtualFrame virtualFrame, int stackTop, PGenerator generator, Object arg, - @Bind Node inliningTarget, - @Cached CommonGeneratorBuiltins.SendNode sendNode, - @Exclusive @Cached IsBuiltinObjectProfile stopIterationProfile, - @Exclusive @Cached PyGenFetchStopIterationValue getValue) { - try { - Object value = sendNode.execute(virtualFrame, generator, arg); - virtualFrame.setObject(stackTop, value); - return false; - } catch (PException e) { - handleException(virtualFrame, e, inliningTarget, stopIterationProfile, getValue, stackTop); - return true; - } - } - - @Specialization(guards = "hasIterSlot(slots)", limit = "1") - static boolean doIterator(VirtualFrame virtualFrame, int stackTop, Object iter, @SuppressWarnings("unused") PNone arg, - @Bind Node inliningTarget, - @SuppressWarnings("unused") @Cached GetObjectSlotsNode getSlots, - @Bind("getSlots.execute(inliningTarget, iter)") TpSlots slots, - @Cached CallSlotTpIterNextNode callIterNext, - @Exclusive @Cached InlinedBranchProfile exhaustedNoException, - @Exclusive @Cached IsBuiltinObjectProfile stopIterationProfile, - @Exclusive @Cached PyGenFetchStopIterationValue getValue) { - try { - Object value = callIterNext.execute(virtualFrame, inliningTarget, slots.tp_iternext(), iter); - virtualFrame.setObject(stackTop, value); - return false; - } catch (IteratorExhausted e) { - exhaustedNoException.enter(inliningTarget); - virtualFrame.setObject(stackTop, null); - virtualFrame.setObject(stackTop - 1, PNone.NONE); - return true; - } catch (PException e) { - handleException(virtualFrame, e, inliningTarget, stopIterationProfile, getValue, stackTop); - return true; - } - } - - protected static boolean hasIterSlot(TpSlots slots) { - return PyIterCheckNode.checkSlots(slots); - } - - @Fallback - static boolean doOther(VirtualFrame virtualFrame, int stackTop, Object obj, Object arg, - @Bind Node inliningTarget, - @Cached PyObjectCallMethodObjArgs callMethodNode, - @Exclusive @Cached IsBuiltinObjectProfile stopIterationProfile, - @Exclusive @Cached PyGenFetchStopIterationValue getValue) { - try { - Object value = callMethodNode.execute(virtualFrame, inliningTarget, obj, T_SEND, arg); - virtualFrame.setObject(stackTop, value); - return false; - } catch (PException e) { - handleException(virtualFrame, e, inliningTarget, stopIterationProfile, getValue, stackTop); - return true; - } - } - - private static void handleException(VirtualFrame frame, PException e, Node inliningTarget, IsBuiltinObjectProfile stopIterationProfile, PyGenFetchStopIterationValue getValue, int stackTop) { - e.expectStopIteration(inliningTarget, stopIterationProfile); - Object value = getValue.execute(inliningTarget, (PBaseException) e.getUnreifiedException()); - frame.setObject(stackTop, null); - frame.setObject(stackTop - 1, value); - } - - public static SendNode create() { - return SendNodeGen.create(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SequenceFromStackNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SequenceFromStackNode.java deleted file mode 100644 index bc65d13570..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SequenceFromStackNode.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import java.lang.reflect.Array; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.list.PList.ListOrigin; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.runtime.PythonContext; -import com.oracle.graal.python.runtime.PythonOptions; -import com.oracle.graal.python.runtime.sequence.storage.ArrayBasedSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.BoolSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.DoubleSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.EmptySequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.IntSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorageFactory; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.TruffleLogger; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.nodes.UnexpectedResultException; -import com.oracle.truffle.api.source.SourceSection; - -abstract class SequenceFromStackNode extends PNodeWithContext { - @CompilationFinal protected final int length; - @CompilationFinal protected SequenceStorage.StorageType type = SequenceStorage.StorageType.Uninitialized; - - SequenceFromStackNode(int length) { - this.length = length; - } - - @ExplodeLoop - protected SequenceStorage createSequenceStorageForDirect(VirtualFrame frame, int start, int stop) { - CompilerAsserts.partialEvaluationConstant(start); - CompilerAsserts.partialEvaluationConstant(stop); - - SequenceStorage storage; - if (type == SequenceStorage.StorageType.Uninitialized) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - try { - Object[] elements = new Object[length]; - for (int j = 0, i = start; i < stop; i++, j++) { - elements[j] = frame.getObject(i); - frame.setObject(i, null); - } - storage = SequenceStorageFactory.createStorage(elements); - type = storage.getElementType(); - } catch (Throwable t) { - // we do not want to repeatedly deopt if a value execution - // always raises, for example - type = SequenceStorage.StorageType.Generic; - throw t; - } - } else { - int j = 0; - Object array = null; - try { - switch (type) { - // Ugh. We want to use primitive arrays during unpacking, so - // we cannot dispatch generically here. - case Empty: { - assert length == 0; - storage = EmptySequenceStorage.INSTANCE; - break; - } - case Boolean: { - boolean[] elements = new boolean[getCapacityEstimate()]; - array = elements; - for (int i = start; i < stop; i++, j++) { - elements[j] = castBoolean(frame.getObject(i)); - frame.setObject(i, null); - } - storage = new BoolSequenceStorage(elements, length); - break; - } - case Int: { - int[] elements = new int[getCapacityEstimate()]; - array = elements; - for (int i = start; i < stop; i++, j++) { - elements[j] = castInt(frame.getObject(i)); - frame.setObject(i, null); - } - storage = new IntSequenceStorage(elements, length); - break; - } - case Long: { - long[] elements = new long[getCapacityEstimate()]; - array = elements; - for (int i = start; i < stop; i++, j++) { - elements[j] = castLong(frame.getObject(i)); - frame.setObject(i, null); - } - storage = new LongSequenceStorage(elements, length); - break; - } - case Double: { - double[] elements = new double[getCapacityEstimate()]; - array = elements; - for (int i = start; i < stop; i++, j++) { - elements[j] = castDouble(frame.getObject(i)); - frame.setObject(i, null); - } - storage = new DoubleSequenceStorage(elements, length); - break; - } - case Generic: { - Object[] elements = new Object[getCapacityEstimate()]; - for (int i = start; i < stop; i++, j++) { - elements[j] = frame.getObject(i); - frame.setObject(i, null); - } - storage = new ObjectSequenceStorage(elements, length); - break; - } - default: - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw new RuntimeException("unexpected state"); - } - } catch (UnexpectedResultException e) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - storage = genericFallback(frame, array, start, stop, j, e.getResult()); - } - } - return storage; - } - - private SequenceStorage genericFallback(VirtualFrame frame, Object array, int start, int stop, int count, Object result) { - type = SequenceStorage.StorageType.Generic; - Object[] elements = new Object[getCapacityEstimate()]; - int j = 0; - for (; j < count; j++) { - elements[j] = Array.get(array, j); - } - elements[j++] = result; - for (int i = start + count + 1; i < stop; i++, j++) { - elements[j] = frame.getObject(i); - frame.setObject(i, null); - } - return new ObjectSequenceStorage(elements, length); - } - - private static int castInt(Object o) throws UnexpectedResultException { - if (o instanceof Integer) { - return (int) o; - } - throw new UnexpectedResultException(o); - } - - private static long castLong(Object o) throws UnexpectedResultException { - if (o instanceof Long) { - return (long) o; - } - throw new UnexpectedResultException(o); - } - - private static double castDouble(Object o) throws UnexpectedResultException { - if (o instanceof Double) { - return (double) o; - } - throw new UnexpectedResultException(o); - } - - private static boolean castBoolean(Object o) throws UnexpectedResultException { - if (o instanceof Boolean) { - return (boolean) o; - } - throw new UnexpectedResultException(o); - } - - protected abstract int getCapacityEstimate(); - - public abstract static class ListFromStackNode extends SequenceFromStackNode implements ListOrigin { - - private static final TruffleLogger LOGGER = PythonLanguage.getLogger(ListFromStackNode.class); - - public ListFromStackNode(int length) { - super(length); - this.initialCapacity = new SizeEstimate(length); - } - - public abstract SequenceStorage execute(Frame virtualFrame, int start, int stop); - - @Specialization - SequenceStorage doIt(VirtualFrame virtualFrame, int start, int stop) { - return createSequenceStorageForDirect(virtualFrame, start, stop); - } - - private final SizeEstimate initialCapacity; - - @Override - protected int getCapacityEstimate() { - return initialCapacity.estimate(); - } - - @Override - public void reportUpdatedCapacity(ArrayBasedSequenceStorage newStore) { - if (CompilerDirectives.inInterpreter()) { - if (PythonContext.get(this).getOption(PythonOptions.OverallocateLiteralLists)) { - if (newStore.getCapacity() > initialCapacity.estimate()) { - initialCapacity.updateFrom(newStore.getCapacity()); - LOGGER.finest(() -> { - SourceSection encapsulatingSourceSection = getEncapsulatingSourceSection(); - String sourceSection = encapsulatingSourceSection == null ? "" : encapsulatingSourceSection.toString(); - return String.format("Updating list size estimate at %s. Observed capacity: %d, new estimate: %d", sourceSection, newStore.getCapacity(), - initialCapacity.estimate()); - }); - } - if (newStore.getElementType().generalizesFrom(type)) { - type = newStore.getElementType(); - LOGGER.finest(() -> { - SourceSection encapsulatingSourceSection = getEncapsulatingSourceSection(); - String sourceSection = encapsulatingSourceSection == null ? "" : encapsulatingSourceSection.toString(); - return String.format("Updating list type estimate at %s. New type: %s", sourceSection, type.name()); - }); - } - } - } - // n.b.: it's ok that this races when the code is already being compiled - // or if we're running on multiple threads. if the update isn't seen, we - // are not incorrect, we just don't benefit from the optimization - } - } - - public abstract static class TupleFromStackNode extends SequenceFromStackNode { - - public TupleFromStackNode(int length) { - super(length); - } - - public abstract SequenceStorage execute(Frame virtualFrame, int start, int stop); - - @Specialization - SequenceStorage doIt(VirtualFrame virtualFrame, int start, int stop) { - return createSequenceStorageForDirect(virtualFrame, start, stop); - } - - @Override - protected int getCapacityEstimate() { - return length; - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java deleted file mode 100644 index 892b5802df..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupAwithNode.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AENTER__; -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AEXIT__; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; -import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class SetupAwithNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop); - - @Specialization - static int setup(VirtualFrame frame, int stackTopIn, - @Bind Node inliningTarget, - @Cached GetClassNode getClassNode, - @Cached LookupSpecialMethodNode.Dynamic lookupAEnter, - @Cached LookupSpecialMethodNode.Dynamic lookupAExit, - @Cached CallUnaryMethodNode callEnter, - @Cached PRaiseNode raiseNode) { - int stackTop = stackTopIn; - Object contextManager = frame.getObject(stackTop); - Object type = getClassNode.execute(inliningTarget, contextManager); - Object enter = lookupAEnter.execute(frame, inliningTarget, type, T___AENTER__, contextManager); - if (enter == PNone.NO_VALUE) { - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL, type); - } - Object exit = lookupAExit.execute(frame, inliningTarget, type, T___AEXIT__, contextManager); - if (exit == PNone.NO_VALUE) { - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_THE_ASYNC_CONTEXT_MANAGER_PROTOCOL_AEXIT, type); - } - Object res = callEnter.executeObject(frame, enter, contextManager); - frame.setObject(++stackTop, exit); - frame.setObject(++stackTop, res); - return stackTop; - } - - public static SetupAwithNode create() { - return SetupAwithNodeGen.create(); - } - - public static SetupAwithNode getUncached() { - return SetupAwithNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java deleted file mode 100644 index 057e16499b..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/SetupWithNode.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ENTER__; -import static com.oracle.graal.python.nodes.SpecialMethodNames.T___EXIT__; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode; -import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class SetupWithNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop); - - @Specialization - static int setup(VirtualFrame frame, int stackTopIn, - @Bind Node inliningTarget, - @Cached GetClassNode getClassNode, - @Cached LookupSpecialMethodNode.Dynamic lookupEnter, - @Cached LookupSpecialMethodNode.Dynamic lookupExit, - @Cached CallUnaryMethodNode callEnter, - @Cached PRaiseNode raiseNode) { - int stackTop = stackTopIn; - Object contextManager = frame.getObject(stackTop); - Object type = getClassNode.execute(inliningTarget, contextManager); - Object enter = lookupEnter.execute(frame, inliningTarget, type, T___ENTER__, contextManager); - if (enter == PNone.NO_VALUE) { - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL, type); - } - Object exit = lookupExit.execute(frame, inliningTarget, type, T___EXIT__, contextManager); - if (exit == PNone.NO_VALUE) { - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL_EXIT, type); - } - Object res = callEnter.executeObject(frame, enter, contextManager); - frame.setObject(++stackTop, exit); - frame.setObject(++stackTop, res); - return stackTop; - } - - public static SetupWithNode create() { - return SetupWithNodeGen.create(); - } - - public static SetupWithNode getUncached() { - return SetupWithNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/StoreSubscrSeq.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/StoreSubscrSeq.java deleted file mode 100644 index 2f0cfb4bc7..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/StoreSubscrSeq.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; -import com.oracle.graal.python.builtins.objects.list.PList; -import com.oracle.graal.python.nodes.PGuards; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.ImportStatic; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.profiles.InlinedConditionProfile; - -@ImportStatic(PGuards.class) -public abstract class StoreSubscrSeq extends Node { - @GenerateInline(false) // used in BCI root node - public abstract static class ONode extends StoreSubscrSeq { - public abstract void execute(Object sequence, int index, Object value); - - @Specialization(guards = "isBuiltinList(sequence)") - void doList(PList sequence, int index, Object value, - @Bind Node inliningTarget, - @Cached InlinedConditionProfile updateStorageProfile, - @Cached("createForList()") SequenceStorageNodes.SetItemNode setItemNode) { - updateStorage(inliningTarget, updateStorageProfile, sequence, setItemNode.execute(sequence.getSequenceStorage(), index, value)); - } - - @Fallback - @SuppressWarnings("unused") - void doGeneralize(Object sequence, int index, Object value) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw new QuickeningGeneralizeException(0); - } - - public static ONode create() { - return StoreSubscrSeqFactory.ONodeGen.create(); - } - } - - @GenerateInline(false) // used in BCI root node - public abstract static class INode extends StoreSubscrSeq { - public abstract void execute(Object sequence, int index, int value); - - @Specialization(guards = "isBuiltinList(sequence)") - void doList(PList sequence, int index, int value, - @Bind Node inliningTarget, - @Cached InlinedConditionProfile updateStorageProfile, - @Cached("createForList()") SequenceStorageNodes.SetItemNode setItemNode) { - updateStorage(inliningTarget, updateStorageProfile, sequence, setItemNode.execute(sequence.getSequenceStorage(), index, value)); - } - - @Fallback - @SuppressWarnings("unused") - void doGeneralize(Object sequence, int index, int value) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw new QuickeningGeneralizeException(0); - } - - public static INode create() { - return StoreSubscrSeqFactory.INodeGen.create(); - } - } - - @GenerateInline(false) // used in BCI root node - public abstract static class DNode extends StoreSubscrSeq { - public abstract void execute(Object sequence, int index, double value); - - @Specialization(guards = "isBuiltinList(sequence)") - void doList(PList sequence, int index, double value, - @Bind Node inliningTarget, - @Cached InlinedConditionProfile updateStorageProfile, - @Cached("createForList()") SequenceStorageNodes.SetItemNode setItemNode) { - updateStorage(inliningTarget, updateStorageProfile, sequence, setItemNode.execute(sequence.getSequenceStorage(), index, value)); - } - - @Fallback - @SuppressWarnings("unused") - void doGeneralize(Object sequence, int index, double value) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - throw new QuickeningGeneralizeException(0); - } - - public static DNode create() { - return StoreSubscrSeqFactory.DNodeGen.create(); - } - } - - protected void updateStorage(Node inliningTarget, InlinedConditionProfile updateStorageProfile, PList self, SequenceStorage newStorage) { - if (updateStorageProfile.profile(inliningTarget, self.getSequenceStorage() != newStorage)) { - self.setSequenceStorage(newStorage); - } - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ThrowNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ThrowNode.java deleted file mode 100644 index 46649e41c0..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/ThrowNode.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2022, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.GeneratorExit; -import static com.oracle.graal.python.util.PythonUtils.tsLiteral; - -import com.oracle.graal.python.builtins.objects.PNone; -import com.oracle.graal.python.builtins.objects.exception.ExceptionNodes; -import com.oracle.graal.python.builtins.objects.exception.GetEscapedExceptionNode; -import com.oracle.graal.python.builtins.objects.exception.PBaseException; -import com.oracle.graal.python.builtins.objects.generator.CommonGeneratorBuiltins; -import com.oracle.graal.python.builtins.objects.generator.PGenerator; -import com.oracle.graal.python.lib.PyGenFetchStopIterationValue; -import com.oracle.graal.python.lib.PyObjectLookupAttr; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.WriteUnraisableNode; -import com.oracle.graal.python.nodes.call.CallNode; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.nodes.object.GetClassNode; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.exception.AbstractTruffleException; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.strings.TruffleString; - -@GenerateInline(false) // used in BCI root node -public abstract class ThrowNode extends PNodeWithContext { - - private static final TruffleString T_CLOSE = tsLiteral("close"); - private static final TruffleString T_THROW = tsLiteral("throw"); - - // Returns true when the generator finished - public abstract boolean execute(VirtualFrame frame, int stackTop, Object iter, AbstractTruffleException exception); - - @Specialization - static boolean doGenerator(VirtualFrame frame, int stackTop, PGenerator generator, AbstractTruffleException exception, - @Bind Node inliningTarget, - @Cached CommonGeneratorBuiltins.ThrowNode throwNode, - @Cached CommonGeneratorBuiltins.CloseNode closeNode, - @Exclusive @Cached GetEscapedExceptionNode getEscapedExceptionNode, - @Exclusive @Cached IsBuiltinObjectProfile profileExit, - @Exclusive @Cached IsBuiltinObjectProfile stopIterationProfile, - @Exclusive @Cached PyGenFetchStopIterationValue getValue) { - Object exceptionObject = getEscapedExceptionNode.execute(inliningTarget, exception); - if (profileExit.profileObject(inliningTarget, exceptionObject, GeneratorExit)) { - closeNode.execute(frame, generator); - throw exception; - } else { - try { - Object value = throwNode.execute(frame, generator, exceptionObject, PNone.NO_VALUE, PNone.NO_VALUE); - frame.setObject(stackTop, value); - return false; - } catch (PException e) { - handleException(frame, inliningTarget, e, stopIterationProfile, getValue, stackTop); - return true; - } - } - } - - @Fallback - static boolean doOther(VirtualFrame frame, int stackTop, Object obj, AbstractTruffleException exception, - @Bind Node inliningTarget, - @Cached PyObjectLookupAttr lookupThrow, - @Cached PyObjectLookupAttr lookupClose, - @Cached CallNode callThrow, - @Cached CallNode callClose, - @Cached WriteUnraisableNode writeUnraisableNode, - @Cached GetClassNode getClassNode, - @Cached ExceptionNodes.GetTracebackNode getTracebackNode, - @Exclusive @Cached GetEscapedExceptionNode getEscapedExceptionNode, - @Exclusive @Cached IsBuiltinObjectProfile profileExit, - @Exclusive @Cached IsBuiltinObjectProfile stopIterationProfile, - @Exclusive @Cached PyGenFetchStopIterationValue getValue) { - Object exceptionObject = getEscapedExceptionNode.execute(inliningTarget, exception); - if (profileExit.profileObject(inliningTarget, exceptionObject, GeneratorExit)) { - Object close = PNone.NO_VALUE; - try { - close = lookupClose.execute(frame, inliningTarget, obj, T_CLOSE); - } catch (PException e) { - writeUnraisableNode.execute(frame, e.getEscapedException(), null, obj); - } - if (close != PNone.NO_VALUE) { - callClose.execute(frame, close); - } - throw exception; - } else { - Object throwMethod = lookupThrow.execute(frame, inliningTarget, obj, T_THROW); - if (throwMethod == PNone.NO_VALUE) { - throw exception; - } - try { - Object type = getClassNode.execute(inliningTarget, exceptionObject); - Object tb = getTracebackNode.execute(inliningTarget, exceptionObject); - Object value = callThrow.execute(frame, throwMethod, type, exceptionObject, tb); - frame.setObject(stackTop, value); - return false; - } catch (PException e) { - handleException(frame, inliningTarget, e, stopIterationProfile, getValue, stackTop); - return true; - } - } - } - - private static void handleException(VirtualFrame frame, Node inliningTarget, PException e, - IsBuiltinObjectProfile stopIterationProfile, PyGenFetchStopIterationValue getValue, - int stackTop) { - e.expectStopIteration(inliningTarget, stopIterationProfile); - Object value = getValue.execute(inliningTarget, (PBaseException) e.getUnreifiedException()); - frame.setObject(stackTop, null); - frame.setObject(stackTop - 1, value); - } - - public static ThrowNode create() { - return ThrowNodeGen.create(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java deleted file mode 100644 index b408823f0e..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackExNode.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError; - -import com.oracle.graal.python.PythonLanguage; -import com.oracle.graal.python.builtins.objects.common.SequenceNodes; -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; -import com.oracle.graal.python.builtins.objects.list.PList; -import com.oracle.graal.python.lib.IteratorExhausted; -import com.oracle.graal.python.lib.PyIterNextNode; -import com.oracle.graal.python.lib.PyObjectGetIter; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.builtins.ListNodes; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.graal.python.runtime.object.PFactory; -import com.oracle.graal.python.runtime.sequence.PSequence; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class UnpackExNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop, Object collection, int countBefore, int countAfter); - - @Specialization(guards = "isBuiltinSequence(sequence)") - static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence sequence, int countBefore, int countAfter, - @Bind Node inliningTarget, - @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode, - @Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode, - @Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode, - @Bind PythonLanguage language, - @Exclusive @Cached PRaiseNode raiseNode) { - CompilerAsserts.partialEvaluationConstant(countBefore); - CompilerAsserts.partialEvaluationConstant(countAfter); - int resultStackTop = initialStackTop + countBefore + 1 + countAfter; - int stackTop = resultStackTop; - SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, sequence); - int len = storage.length(); - int starLen = len - countBefore - countAfter; - if (starLen < 0) { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, len); - } - stackTop = moveItemsToStack(frame, inliningTarget, storage, stackTop, 0, countBefore, getItemNode); - PList starList = PFactory.createList(language, getItemSliceNode.execute(storage, countBefore, countBefore + starLen, 1, starLen)); - frame.setObject(stackTop--, starList); - moveItemsToStack(frame, inliningTarget, storage, stackTop, len - countAfter, countAfter, getItemNode); - return resultStackTop; - } - - @Fallback - static int doUnpackIterable(VirtualFrame frame, int initialStackTop, Object collection, int countBefore, int countAfter, - @Bind Node inliningTarget, - @Cached PyObjectGetIter getIter, - @Cached PyIterNextNode nextNode, - @Cached IsBuiltinObjectProfile notIterableProfile, - @Cached ListNodes.ConstructListNode constructListNode, - @Exclusive @Cached SequenceStorageNodes.GetItemScalarNode getItemNode, - @Exclusive @Cached SequenceStorageNodes.GetItemSliceNode getItemSliceNode, - @Bind PythonLanguage language, - @Exclusive @Cached PRaiseNode raiseNode) { - CompilerAsserts.partialEvaluationConstant(countBefore); - CompilerAsserts.partialEvaluationConstant(countAfter); - int resultStackTop = initialStackTop + countBefore + 1 + countAfter; - int stackTop = resultStackTop; - Object iterator; - try { - iterator = getIter.execute(frame, inliningTarget, collection); - } catch (PException e) { - e.expectTypeError(inliningTarget, notIterableProfile); - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection); - } - stackTop = moveItemsToStack(frame, inliningTarget, iterator, stackTop, 0, countBefore, countBefore + countAfter, nextNode, raiseNode); - PList starAndAfter = constructListNode.execute(frame, iterator); - SequenceStorage storage = starAndAfter.getSequenceStorage(); - int lenAfter = storage.length(); - if (lenAfter < countAfter) { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, countBefore + countAfter, countBefore + lenAfter); - } - if (countAfter == 0) { - frame.setObject(stackTop, starAndAfter); - } else { - int starLen = lenAfter - countAfter; - PList starList = PFactory.createList(language, getItemSliceNode.execute(storage, 0, starLen, 1, starLen)); - frame.setObject(stackTop--, starList); - moveItemsToStack(frame, inliningTarget, storage, stackTop, starLen, countAfter, getItemNode); - } - return resultStackTop; - } - - @ExplodeLoop - private static int moveItemsToStack(VirtualFrame frame, Node inliningTarget, Object iterator, int initialStackTop, int offset, int length, int totalLength, PyIterNextNode nextNode, - PRaiseNode raiseNode) { - CompilerAsserts.partialEvaluationConstant(length); - int stackTop = initialStackTop; - for (int i = 0; i < length; i++) { - try { - Object item = nextNode.execute(frame, inliningTarget, iterator); - frame.setObject(stackTop--, item); - } catch (IteratorExhausted e) { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK_EX, totalLength, offset + i); - } - } - return stackTop; - } - - @ExplodeLoop - private static int moveItemsToStack(VirtualFrame frame, Node inliningTarget, SequenceStorage storage, int initialStackTop, int offset, int length, - SequenceStorageNodes.GetItemScalarNode getItemNode) { - CompilerAsserts.partialEvaluationConstant(length); - int stackTop = initialStackTop; - for (int i = 0; i < length; i++) { - frame.setObject(stackTop--, getItemNode.execute(inliningTarget, storage, offset + i)); - } - return stackTop; - } - - public static UnpackExNode create() { - return UnpackExNodeGen.create(); - } - - public static UnpackExNode getUncached() { - return UnpackExNodeGen.getUncached(); - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java deleted file mode 100644 index 946f54f74d..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/UnpackSequenceNode.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2022, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.nodes.bytecode; - -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError; -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError; - -import com.oracle.graal.python.builtins.objects.common.SequenceNodes; -import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; -import com.oracle.graal.python.lib.IteratorExhausted; -import com.oracle.graal.python.lib.PyIterNextNode; -import com.oracle.graal.python.lib.PyObjectGetIter; -import com.oracle.graal.python.nodes.ErrorMessages; -import com.oracle.graal.python.nodes.PNodeWithContext; -import com.oracle.graal.python.nodes.PRaiseNode; -import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; -import com.oracle.graal.python.runtime.exception.PException; -import com.oracle.graal.python.runtime.sequence.PSequence; -import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; -import com.oracle.truffle.api.CompilerAsserts; -import com.oracle.truffle.api.dsl.Bind; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Exclusive; -import com.oracle.truffle.api.dsl.Fallback; -import com.oracle.truffle.api.dsl.GenerateInline; -import com.oracle.truffle.api.dsl.GenerateUncached; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.Frame; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.ExplodeLoop; -import com.oracle.truffle.api.nodes.Node; - -@GenerateUncached -@GenerateInline(false) // used in BCI root node -public abstract class UnpackSequenceNode extends PNodeWithContext { - public abstract int execute(Frame frame, int stackTop, Object collection, int count); - - @Specialization(guards = "isBuiltinSequence(sequence)") - @ExplodeLoop - static int doUnpackSequence(VirtualFrame frame, int initialStackTop, PSequence sequence, int count, - @Bind Node inliningTarget, - @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode, - @Cached SequenceStorageNodes.GetItemScalarNode getItemNode, - @Exclusive @Cached PRaiseNode raiseNode) { - CompilerAsserts.partialEvaluationConstant(count); - int resultStackTop = initialStackTop + count; - int stackTop = resultStackTop; - SequenceStorage storage = getSequenceStorageNode.execute(inliningTarget, sequence); - int len = storage.length(); - if (len == count) { - for (int i = 0; i < count; i++) { - frame.setObject(stackTop--, getItemNode.execute(inliningTarget, storage, i)); - } - } else { - if (len < count) { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, len); - } else { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count); - } - } - return resultStackTop; - } - - @Fallback - @ExplodeLoop - static int doUnpackIterable(Frame frame, int initialStackTop, Object collection, int count, - @Bind Node inliningTarget, - @Cached PyObjectGetIter getIter, - @Cached PyIterNextNode nextNode, - @Cached IsBuiltinObjectProfile notIterableProfile, - @Exclusive @Cached PRaiseNode raiseNode) { - CompilerAsserts.partialEvaluationConstant(count); - int resultStackTop = initialStackTop + count; - int stackTop = resultStackTop; - Object iterator; - try { - iterator = getIter.execute(frame, inliningTarget, collection); - } catch (PException e) { - e.expectTypeError(inliningTarget, notIterableProfile); - throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANNOT_UNPACK_NON_ITERABLE, collection); - } - for (int i = 0; i < count; i++) { - try { - Object item = nextNode.execute(frame, inliningTarget, iterator); - frame.setObject(stackTop--, item); - } catch (IteratorExhausted e) { - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.NOT_ENOUGH_VALUES_TO_UNPACK, count, i); - } - } - try { - nextNode.execute(frame, inliningTarget, iterator); - } catch (IteratorExhausted e) { - return resultStackTop; - } - throw raiseNode.raise(inliningTarget, ValueError, ErrorMessages.TOO_MANY_VALUES_TO_UNPACK, count); - } - - public static UnpackSequenceNode create() { - return UnpackSequenceNodeGen.create(); - } - - public static UnpackSequenceNode getUncached() { - return UnpackSequenceNodeGen.getUncached(); - } -} From 850fa3d075ceadedd793d13b6ab4290453983106 Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 17:02:41 +0200 Subject: [PATCH 16/20] Remove CollectionBits --- .../graal/python/compiler/CollectionBits.java | 69 -------------- .../bytecode_dsl/RootNodeCompiler.java | 95 +++++++++---------- 2 files changed, 47 insertions(+), 117 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java deleted file mode 100644 index e78b42b3bc..0000000000 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/CollectionBits.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.compiler; - -public final class CollectionBits { - public static final int KIND_MASK = 0b00011111; - public static final int KIND_LIST = 0b00100000; - public static final int KIND_TUPLE = 0b01000000; - public static final int KIND_SET = 0b01100000; - public static final int KIND_DICT = 0b10000000; - public static final int KIND_KWORDS = 0b10100000; - public static final int KIND_OBJECT = 0b11000000; - - public static final byte ELEMENT_INT = 1; - public static final byte ELEMENT_LONG = 2; - public static final byte ELEMENT_BOOLEAN = 3; - public static final byte ELEMENT_DOUBLE = 4; - public static final byte ELEMENT_OBJECT = 5; - - public static int elementCount(int oparg) { - return oparg & KIND_MASK; - } - - public static int elementType(int oparg) { - return oparg & KIND_MASK; - } - - public static int collectionKind(int oparg) { - return oparg & ~KIND_MASK; - } -} diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java index d557bb0158..d0b1808997 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java @@ -90,7 +90,6 @@ import com.oracle.graal.python.builtins.objects.function.PArguments; import com.oracle.graal.python.builtins.objects.function.PKeyword; import com.oracle.graal.python.builtins.objects.type.TypeFlags; -import com.oracle.graal.python.compiler.CollectionBits; import com.oracle.graal.python.compiler.CompilationScope; import com.oracle.graal.python.compiler.MakeTypeParamKind; import com.oracle.graal.python.compiler.SSTUtils; @@ -182,15 +181,6 @@ * {@link StatementCompiler}, which does all the heavy lifting. */ public final class RootNodeCompiler implements BaseBytecodeDSLVisitor { - private static final class ConstantCollection { - final Object collection; - final int elementType; - - ConstantCollection(Object collection, int elementType) { - this.collection = collection; - this.elementType = elementType; - } - } /** * Because a {@link RootNodeCompiler} instance gets reused on reparse, it should be idempotent. @@ -381,35 +371,53 @@ private Object addConstant(Object c) { return c; } + private enum CollectionType { + INT, + LONG, + BOOLEAN, + DOUBLE, + OBJECT + } + + private static final class ConstantCollection { + final Object collection; + final CollectionType elementType; + + ConstantCollection(Object collection, CollectionType elementType) { + this.collection = collection; + this.elementType = elementType; + } + } + private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements) { if (elements == null || elements.length == 0) { return null; } - int constantType = -1; + CollectionType constantType = null; List constants = new ArrayList<>(); for (ExprTy e : elements) { if (e instanceof ExprTy.Constant c) { if (c.value.kind == ConstantValue.Kind.BOOLEAN) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_BOOLEAN); + constantType = determineConstantType(constantType, CollectionType.BOOLEAN); constants.add(c.value.getBoolean()); } else if (c.value.kind == ConstantValue.Kind.LONG) { long val = c.value.getLong(); if (val == (int) val) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_INT); + constantType = determineConstantType(constantType, CollectionType.INT); } else { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_LONG); + constantType = determineConstantType(constantType, CollectionType.LONG); } constants.add(val); } else if (c.value.kind == ConstantValue.Kind.DOUBLE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_DOUBLE); + constantType = determineConstantType(constantType, CollectionType.DOUBLE); constants.add(c.value.getDouble()); } else if (c.value.kind == ConstantValue.Kind.CODEPOINTS) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constantType = determineConstantType(constantType, CollectionType.OBJECT); constants.add(codePointsToInternedTruffleString(c.value.getCodePoints())); } else if (c.value.kind == ConstantValue.Kind.NONE) { - constantType = determineConstantType(constantType, CollectionBits.ELEMENT_OBJECT); + constantType = determineConstantType(constantType, CollectionType.OBJECT); constants.add(PNone.NONE); } else { return null; @@ -420,10 +428,10 @@ private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements } Object newConstant = null; switch (constantType) { - case CollectionBits.ELEMENT_OBJECT: + case OBJECT: newConstant = constants.toArray(new Object[0]); break; - case CollectionBits.ELEMENT_INT: { + case INT: { int[] a = new int[constants.size()]; for (int i = 0; i < a.length; i++) { a[i] = (int) (long) constants.get(i); @@ -431,7 +439,7 @@ private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements newConstant = a; break; } - case CollectionBits.ELEMENT_LONG: { + case LONG: { long[] a = new long[constants.size()]; for (int i = 0; i < a.length; i++) { a[i] = (long) constants.get(i); @@ -439,7 +447,7 @@ private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements newConstant = a; break; } - case CollectionBits.ELEMENT_BOOLEAN: { + case BOOLEAN: { boolean[] a = new boolean[constants.size()]; for (int i = 0; i < a.length; i++) { a[i] = (boolean) constants.get(i); @@ -447,7 +455,7 @@ private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements newConstant = a; break; } - case CollectionBits.ELEMENT_DOUBLE: { + case DOUBLE: { double[] a = new double[constants.size()]; for (int i = 0; i < a.length; i++) { a[i] = (double) constants.get(i); @@ -459,14 +467,14 @@ private static ConstantCollection tryCollectConstantCollection(ExprTy[] elements return new ConstantCollection(newConstant, constantType); } - private static int determineConstantType(int existing, int type) { - if (existing == -1 || existing == type) { + private static CollectionType determineConstantType(CollectionType existing, CollectionType type) { + if (existing == null || existing == type) { return type; } - if (existing == CollectionBits.ELEMENT_LONG && type == CollectionBits.ELEMENT_INT || existing == CollectionBits.ELEMENT_INT && type == CollectionBits.ELEMENT_LONG) { - return CollectionBits.ELEMENT_LONG; + if (existing == CollectionType.LONG && type == CollectionType.INT || existing == CollectionType.INT && type == CollectionType.LONG) { + return CollectionType.LONG; } - return CollectionBits.ELEMENT_OBJECT; + return CollectionType.OBJECT; } private static TruffleString[] orderedTruffleStringArray(HashMap map) { @@ -2866,19 +2874,19 @@ public Void visit(ExprTy.NamedExpr node) { private void emitConstantList(ConstantCollection constantCollection) { addConstant(constantCollection.collection); switch (constantCollection.elementType) { - case CollectionBits.ELEMENT_INT: + case INT: b.emitMakeConstantIntList((int[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_LONG: + case LONG: b.emitMakeConstantLongList((long[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_BOOLEAN: + case BOOLEAN: b.emitMakeConstantBooleanList((boolean[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_DOUBLE: + case DOUBLE: b.emitMakeConstantDoubleList((double[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_OBJECT: + case OBJECT: b.emitMakeConstantObjectList((Object[]) constantCollection.collection); break; default: @@ -2889,19 +2897,19 @@ private void emitConstantList(ConstantCollection constantCollection) { private void emitConstantTuple(ConstantCollection constantCollection) { addConstant(constantCollection.collection); switch (constantCollection.elementType) { - case CollectionBits.ELEMENT_INT: + case INT: b.emitMakeConstantIntTuple((int[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_LONG: + case LONG: b.emitMakeConstantLongTuple((long[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_BOOLEAN: + case BOOLEAN: b.emitMakeConstantBooleanTuple((boolean[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_DOUBLE: + case DOUBLE: b.emitMakeConstantDoubleTuple((double[]) constantCollection.collection); break; - case CollectionBits.ELEMENT_OBJECT: + case OBJECT: b.emitMakeConstantObjectTuple((Object[]) constantCollection.collection); break; default: @@ -3449,20 +3457,11 @@ public Void visit(StmtTy.Assert node) { * store to some local variables/cells depending on its semantics. */ public void visitTypeParams(TypeParamTy[] typeParams) { - boolean useList = typeParams.length > CollectionBits.KIND_MASK; - if (useList) { - b.beginMakeList(); - } else { - b.beginMakeTuple(); - } + b.beginMakeTuple(); for (TypeParamTy typeParam : typeParams) { typeParam.accept(this); } - if (useList) { - b.endMakeList(); - } else { - b.endMakeTuple(); - } + b.endMakeTuple(); } // --------------------- assign ------------------------ From 94bbe8155d8eddb9e60c35c49814c1c39c8a65ff Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Tue, 9 Jun 2026 17:09:30 +0200 Subject: [PATCH 17/20] Remove skipIfBytecodeDSL --- .../src/tests/test_sys_settrace.py | 2 +- .../com.oracle.graal.python.test/src/tests/util.py | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py index 2fd3acf9fb..a4dcbb2837 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/test_sys_settrace.py @@ -1090,7 +1090,7 @@ def func(): self.assert_events(self.events, events) - @util.skipIfBytecodeDSL("TODO: Fix return in finally.") + @unittest.skip("TODO: Fix return in finally.") def test_04_test_try_except_star_with_wrong_type(self): def func(): try: 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 006d84abb1..536d6f02f7 100644 --- a/graalpython/com.oracle.graal.python.test/src/tests/util.py +++ b/graalpython/com.oracle.graal.python.test/src/tests/util.py @@ -81,14 +81,6 @@ def needs_capi(test): return test -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 storage_to_native(s): if sys.implementation.name == 'graalpy': assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins" From 98b1b62da1b7b84677bf5bcbcacf0f4d553073fb Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Wed, 10 Jun 2026 09:40:19 +0200 Subject: [PATCH 18/20] Remove node footprint analyzer --- .../test/advanced/NodeFootprintAnalyzer.java | 504 ------------------ mx.graalpython/mx_graalpython.py | 7 - 2 files changed, 511 deletions(-) delete mode 100644 graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java diff --git a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java b/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java deleted file mode 100644 index 6a396599a7..0000000000 --- a/graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/NodeFootprintAnalyzer.java +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Copyright (c) 2023, 2026, 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 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or - * data (collectively the "Software"), free of charge and under any and all - * copyright rights in the Software, and any and all patent rights owned or - * freely licensable by each licensor hereunder covering either (i) the - * unmodified Software as contributed to or provided by such licensor, or (ii) - * the Larger Works (as defined below), to deal in both - * - * (a) the Software, and - * - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * - * The above copyright notice and either this complete permission notice or at a - * minimum a reference to the UPL must be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.oracle.graal.python.test.advanced; - -import static java.lang.Math.abs; -import static java.lang.Math.min; -import static java.lang.Math.round; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Spliterator; -import java.util.Spliterators; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import org.netbeans.lib.profiler.heap.Heap; -import org.netbeans.lib.profiler.heap.HeapFactory; -import org.netbeans.lib.profiler.heap.Instance; -import org.netbeans.lib.profiler.heap.JavaClass; -import org.netbeans.lib.profiler.heap.ObjectArrayInstance; -import org.netbeans.lib.profiler.heap.PrimitiveArrayInstance; - -import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode; -import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode; -import com.oracle.truffle.api.strings.TruffleString; - -/** - * Standalone tool that can be run via {@code mx python-nodes-footprint heap_dump1 heap_dump2}. - * - * It creates a mapping between root nodes instances in two heap dumps according to their source - * sections. The tool provides comparison of retained sizes of root nodes with the same source - * sections. - * - * It is recommended to run GraalPy with the following options when taking the heap dumps. - * - *
    - *     --engine.Splitting=false --engine.OSR=false --python.BuiltinsInliningMaxCallerSize=0 --python.ForceInitializeSourceSections=true
    - * 
    - */ -public class NodeFootprintAnalyzer { - public abstract static class RootInfo implements Comparable { - // Placeholder for duplicate entries - public static RootInfo DUPLICATE = new RootInfo(null, null) { - @Override - public long adoptedNodesRetrainedSize() { - return 0; - } - }; - private final Instance instance; - private final String name; - - public RootInfo(Instance instance, String name) { - this.instance = instance; - this.name = name; - } - - public abstract long adoptedNodesRetrainedSize(); - - @Override - public int compareTo(RootInfo o) { - return Long.compare(adoptedNodesRetrainedSize(), o.adoptedNodesRetrainedSize()); - } - - public Instance instance() { - return instance; - } - - public String name() { - return name; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - - } - if (obj == null || obj.getClass() != this.getClass()) { - return false; - } - var that = (RootInfo) obj; - return Objects.equals(this.instance, that.instance); - } - - @Override - public int hashCode() { - return Objects.hash(instance); - } - } - - public static final class PBytecodeRootInfo extends RootInfo { - private final ObjectArrayInstance adoptedNodes; - - public PBytecodeRootInfo(Instance instance, String name, ObjectArrayInstance adoptedNodes) { - super(instance, name); - this.adoptedNodes = adoptedNodes; - } - - public static RootInfo create(Instance instance) { - Object adoptedNodesField = instance.getValueOfField("adoptedNodes"); - ObjectArrayInstance adoptedNodes = null; - if (adoptedNodesField instanceof ObjectArrayInstance adoptedNodesArr) { - adoptedNodes = adoptedNodesArr; - } - return new PBytecodeRootInfo(instance, getRootName(instance), adoptedNodes); - } - - @Override - public long adoptedNodesRetrainedSize() { - return adoptedNodes == null ? 0 : adoptedNodes.getRetainedSize(); - } - } - - public static final class BuiltinFunctionRootInfo extends RootInfo { - private final Instance body; - - public BuiltinFunctionRootInfo(Instance instance, String name, Instance body) { - super(instance, name); - this.body = body; - } - - public static RootInfo create(Instance instance) { - Object bodyField = instance.getValueOfField("body"); - Instance body = null; - if (bodyField instanceof Instance bodyFieldInstance) { - body = bodyFieldInstance; - } - return new BuiltinFunctionRootInfo(instance, getRootName(instance), body); - } - - @Override - public long adoptedNodesRetrainedSize() { - return body == null ? 0 : body.getRetainedSize(); - } - } - - public static final class AdoptedNodesPair implements Comparable { - private final int index; - private final Instance i1; - private final Instance i2; - - public AdoptedNodesPair(int index, Instance i1, Instance i2) { - this.index = index; - this.i1 = i1; - this.i2 = i2; - } - - long retainedDiff() { - long i1Size = i1 != null ? i1.getRetainedSize() : 0; - long i2Size = i2 != null ? i2.getRetainedSize() : 0; - return i1Size - i2Size; - } - - long getI1InstanceId() { - return i1 == null ? 0 : i1.getInstanceId(); - } - - long getI2InstanceId() { - return i2 == null ? 0 : i2.getInstanceId(); - } - - String getClassName() { - if (i1 != null) { - return i1.getJavaClass().getName(); - } else if (i2 != null) { - return i2.getJavaClass().getName(); - } else { - return ""; - } - } - - @Override - public int compareTo(AdoptedNodesPair o) { - return Long.compare(abs(retainedDiff()), abs(o.retainedDiff())); - } - } - - public static final class RootsPair implements Comparable { - private final RootInfo r1; - private final RootInfo r2; - private ArrayList adoptedNodes; - - public RootsPair(RootInfo r1, RootInfo r2) { - this.r1 = r1; - this.r2 = r2; - } - - long adoptedNodesRetainedSizeDiff() { - return r1.adoptedNodesRetrainedSize() - r2.adoptedNodesRetrainedSize(); - } - - @Override - public int compareTo(RootsPair o) { - return Long.compare(abs(adoptedNodesRetainedSizeDiff()), abs(o.adoptedNodesRetainedSizeDiff())); - } - - @SuppressWarnings("unchecked") - public ArrayList getAdoptedNodes() { - if (adoptedNodes == null) { - if (r1 instanceof PBytecodeRootInfo bci1 && r2 instanceof PBytecodeRootInfo bci2) { - if (bci1.adoptedNodes.getLength() != bci2.adoptedNodes.getLength()) { - System.out.printf("WARNING: '%s': not the same adoptedNodes array size\n", r1.name); - } - int size = min(bci1.adoptedNodes.getLength(), bci2.adoptedNodes.getLength()); - adoptedNodes = new ArrayList<>(size); - List values1 = bci1.adoptedNodes.getValues(); - List values2 = bci2.adoptedNodes.getValues(); - for (int i = 0; i < size; i++) { - adoptedNodes.add(new AdoptedNodesPair(i, values1.get(i), values2.get(i))); - } - adoptedNodes.sort(Comparator.reverseOrder()); - } else if (r1 instanceof BuiltinFunctionRootInfo builtin1 && r2 instanceof BuiltinFunctionRootInfo builtin2) { - adoptedNodes = new ArrayList<>(); - adoptedNodes.add(new AdoptedNodesPair(0, builtin1.body, builtin2.body)); - } - } - return adoptedNodes; - } - - public String adoptedNodesDiffTable() { - if (getAdoptedNodes().size() <= 1) { - return ""; - } - return String.format(" %10s %10s %15s %15s %s\n", "diff", "index", "id1", "id2", "class") + - getAdoptedNodes().stream().// - filter(x -> x.retainedDiff() != 0).// - sorted(Comparator.reverseOrder()).// - map(x -> String.format(" %10d %10d %15d %15d %s", - x.retainedDiff(), // - x.index, // - x.getI1InstanceId(), // - x.getI2InstanceId(), // - x.getClassName())).collect(Collectors.joining("\n")) + - "\n"; - } - } - - public static void main(String[] args) throws Exception { - if (args.length == 0 || args[0].contains("help") || args.length > 2) { - System.out.println("Arguments: heap-dump-file1 heap-dump-file2"); - return; - } - - System.out.println(); - System.out.println("===================="); - System.out.printf("processing %s...\n", args[0]); - Map result0 = processDump(args[0]); - - System.out.println("===================="); - System.out.printf("processing %s...\n", args[1]); - Map result1 = processDump(args[1]); - - HashMap joined = new HashMap<>(); - ArrayList notFound = new ArrayList<>(); - for (Entry e : result0.entrySet()) { - RootInfo r2 = result1.get(e.getKey()); - if (r2 == null) { - notFound.add(e.getKey()); - } else { - joined.put(e.getKey(), new RootsPair(e.getValue(), r2)); - result1.remove(e.getKey()); - } - } - notFound.addAll(result1.keySet()); - - System.out.println("===================="); - System.out.println("Root nodes with the highest difference: "); - System.out.printf(" %10s %10s %10s %15s %15s %10s\n", "diff", "ast_size1", "ast_size2", "id1", "id2", "name"); - List diffs = joined.values().stream().// - filter(x -> x.adoptedNodesRetainedSizeDiff() != 0).// - sorted(Comparator.reverseOrder()).// - map(x -> String.format("root: %10d %10d %10d %15d %15d %s\n%s", - x.adoptedNodesRetainedSizeDiff(), // - x.r1.adoptedNodesRetrainedSize(), // - x.r2.adoptedNodesRetrainedSize(), // - x.r1.instance.getInstanceId(), // - x.r2.instance.getInstanceId(), // - x.r1.name, // - x.adoptedNodesDiffTable())).toList(); - diffs.stream().limit(20).forEach(System.out::println); - final String rootsDiffFile = "/tmp/roots-diff.txt"; - Files.write(Paths.get(rootsDiffFile), diffs); - System.out.println("Full list was written to " + rootsDiffFile); - - if (notFound.size() > 0) { - final String onlyOnceRootsFile = "/tmp/only-once-roots.txt"; - Files.write(Paths.get(onlyOnceRootsFile), notFound); - System.out.println("WARNING: there were some roots nodes that were found in only one of the dumps."); - System.out.println("List of the names of those roots was written to " + onlyOnceRootsFile); - } - - System.out.println(); - System.out.printf("Total retained size: %15s %15s %15s\n", "size1", "size2", "diff"); - long totalDiff = joined.values().stream().mapToLong(RootsPair::adoptedNodesRetainedSizeDiff).sum(); - long size1 = joined.values().stream().mapToLong(x -> x.r1.adoptedNodesRetrainedSize()).sum(); - long size2 = joined.values().stream().mapToLong(x -> x.r2.adoptedNodesRetrainedSize()).sum(); - System.out.printf(" %15d %15d %15d (%d%%)\n", size1, size2, totalDiff, round(totalDiff / ((double) size2 / 100))); - - System.out.println(); - System.out.println("To explore individual objects in VisualVM use OQL query: `[heap.findObjet(ID)]`"); - } - - @SuppressWarnings("unchecked") - private static Map processDump(String dumpFile) throws IOException { - Heap heap = HeapFactory.createHeap(new File(dumpFile)); - Iterator instancesIt = heap.getAllInstancesIterator(); - - JavaClass bytecodeRootNodeClass = heap.getJavaClassByName(PBytecodeDSLRootNode.class.getName()); - JavaClass builtinRootNodeClass = heap.getJavaClassByName(BuiltinFunctionRootNode.class.getName()); - Map roots = Stream.concat( - StreamSupport.stream(Spliterators.spliteratorUnknownSize(instancesIt, Spliterator.ORDERED), - false).// - filter(x -> isSubclass(bytecodeRootNodeClass, x)).// - map(PBytecodeRootInfo::create), - StreamSupport.stream(Spliterators.spliteratorUnknownSize(instancesIt, Spliterator.ORDERED), - false).// - filter(x -> isSubclass(builtinRootNodeClass, x)).// - map(BuiltinFunctionRootInfo::create)).// - collect(Collectors.toMap(RootInfo::name, x -> x, (a, b) -> RootInfo.DUPLICATE)); - List duplicates = roots.entrySet().stream().filter(x -> x.getValue() == RootInfo.DUPLICATE).map(Entry::getKey).toList(); - duplicates.forEach(roots::remove); - if (duplicates.size() > 0) { - final String duplicatedRootsFile = "/tmp/duplicated-roots.text"; - Files.write(Paths.get(duplicatedRootsFile), duplicates); - System.out.println("WARNING: there were some roots nodes with duplicated names."); - System.out.println("List of the names of those roots was written to " + duplicatedRootsFile); - } - - Path dumpFileName = Paths.get(dumpFile).getFileName(); - - generateOQL(roots.values().stream().map(RootInfo::instance), dumpFileName, "ast", "selects all AST objects"); - - String rootsCsv = "id,class,name,nodes_rsize\n" + // - roots.values().stream().sorted().// - map(NodeFootprintAnalyzer::asCSVLine).// - collect(Collectors.joining("\n")) + - "\n"; - final String rootsFile = String.format("/tmp/%s-roots.csv", dumpFileName); - Files.writeString(Paths.get(rootsFile), rootsCsv); - System.out.println("Database with roots was written to " + rootsFile); - - return roots; - } - - private static String asCSVLine(RootInfo info) { - return String.format("%d,%s,%s,%d", info.instance.getInstanceId(), info.instance.getJavaClass().getName(), info.name(), info.adoptedNodesRetrainedSize()); - } - - private static void generateOQL(Stream objects, Path dumpFileName, String id, String description) throws IOException { - String oqlObjects = objects.map(x -> Long.toString(x.getInstanceId())).// - map(x -> String.format("heap.findObject(%s)", x)).// - collect(Collectors.joining(", \n")); - String oql = String.format(""" - [ - %s - ]; - """, oqlObjects); - final String oqlFile = String.format("/tmp/%s-%s.oql", dumpFileName, id); - Files.writeString(Paths.get(oqlFile), oql); - System.out.printf("OQL script that %s was written to %s\n", description, oqlFile); - } - - private static String getRootName(Instance root) { - Object nameFieldValue = root.getValueOfField("name"); - if (nameFieldValue instanceof Instance fieldValueInstance) { - if (fieldValueInstance.getJavaClass().getName().equals(TruffleString.class.getName())) { - Object dataObj = fieldValueInstance.getValueOfField("data"); - if (dataObj instanceof PrimitiveArrayInstance dataArr) { - return getRootSourceInfo(root) + ":" + byteArrayToString(dataArr); - } - } else if (fieldValueInstance.getJavaClass().getName().equals(String.class.getName())) { - String sourceInfo = root.getJavaClass().getName(); - if (root.getJavaClass().getName().equals("com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode")) { - Object bodyFieldValue = root.getValueOfField("factory"); - if (bodyFieldValue instanceof Instance bodyFieldInstance) { - sourceInfo = bodyFieldInstance.getJavaClass().getName(); - } - } - return sourceInfo + ":" + getJavaStringContents(fieldValueInstance); - } - } - return ""; - } - - private static String getRootSourceInfo(Instance root) { - String sourceName = getSourceName(root.getValueOfField("source")); - Object sectionFieldValue = root.getValueOfField("sourceSection"); - if (sectionFieldValue instanceof Instance sectionInstance && - sectionInstance.getJavaClass().getName().equals("com.oracle.truffle.api.source.SourceSectionLoaded")) { - Object indexValue = sectionInstance.getValueOfField("charIndex"); - if (indexValue instanceof Integer indexAsInt && indexAsInt != 0) { - return sourceName + ":" + indexAsInt; - } - } - return sourceName; - } - - private static String getSourceName(Object sourceFieldValue) { - if (sourceFieldValue instanceof Instance sourceInstance) { - Object keyFieldValue = sourceInstance.getValueOfField("key"); - if (keyFieldValue instanceof Instance keyInstance) { - Object pathFieldValue = keyInstance.getValueOfField("path"); - if (pathFieldValue instanceof Instance pathInstance) { - String path = getJavaStringContents(pathInstance); - if (path != null) { - return Paths.get(path).getFileName().toString(); - } - } - - Object nameFieldValue = keyInstance.getValueOfField("name"); - if (nameFieldValue instanceof Instance nameInstance) { - String name = getJavaStringContents(nameInstance); - if (name != null) { - return name; - } - } - } - } - System.out.println("WARNING: could not extract source name"); - return ""; - } - - private static String getJavaStringContents(Instance stringInstance) { - Object valueFieldValue = stringInstance.getValueOfField("value"); - if (valueFieldValue instanceof PrimitiveArrayInstance arr) { - return byteArrayToString(arr); - } - System.out.println("WARNING: could not extract java.lang.String contents"); - return null; - } - - @SuppressWarnings("unchecked") - private static String byteArrayToString(PrimitiveArrayInstance dataArr) { - List values = dataArr.getValues(); - int[] dataInts = values.stream().mapToInt(x -> Byte.parseByte(x.toString())).toArray(); - byte[] dataBytes = new byte[dataInts.length]; - for (int i = 0; i < dataInts.length; i++) { - dataBytes[i] = (byte) dataInts[i]; - } - return new String(dataBytes, StandardCharsets.US_ASCII); - } - - private static boolean isSubclass(JavaClass baseClass, Instance x) { - JavaClass superClass = x.getJavaClass(); - while (superClass != null) { - if (superClass.getJavaClassId() == baseClass.getJavaClassId()) { - return true; - } - superClass = superClass.getSuperClass(); - } - return false; - } -} diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py index e58c7db92f..189b9ca5e6 100644 --- a/mx.graalpython/mx_graalpython.py +++ b/mx.graalpython/mx_graalpython.py @@ -867,12 +867,6 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None return mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, **kwargs) -def node_footprint_analyzer(args, **kwargs): - main_class = 'com.oracle.graal.python.test.advanced.NodeFootprintAnalyzer' - vm_args = mx.get_runtime_jvm_args(['GRAALPYTHON_UNIT_TESTS', 'GRAALPYTHON']) - return mx.run_java(vm_args + [main_class] + args, **kwargs) - - def _dev_pythonhome_context(): home = os.environ.get("GRAAL_PYTHONHOME", _dev_pythonhome()) return set_env(GRAAL_PYTHONHOME=home) @@ -3555,7 +3549,6 @@ def update_github_unittest_tags(args): 'clean': [python_clean, '[--just-pyc]'], 'bisect-benchmark': [mx_graalpython_bisect.bisect_benchmark, ''], 'python-leak-test': [run_leak_launcher, ''], - 'python-nodes-footprint': [node_footprint_analyzer, ''], 'python-checkcopyrights': [python_checkcopyrights, '[--fix]'], 'host-inlining-log-extract': [host_inlining_log_extract_method, ''], 'tox-example': [tox_example, ''], From 9b7f46b23ffbca1e64a888d808f2b43dd1be963e Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Mon, 22 Jun 2026 09:02:52 +0200 Subject: [PATCH 19/20] Fix the overlay revision --- ci.jsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci.jsonnet b/ci.jsonnet index 04056ada0c..ed06e0e4f2 100644 --- a/ci.jsonnet +++ b/ci.jsonnet @@ -5,7 +5,7 @@ (import "ci/python-gate.libsonnet") + (import "ci/python-bench.libsonnet") + { - overlay: "30def35dbfc43256d57ad3b9b981d92718728e2a", + overlay: "26571215e27b3c415afb8119d38a0418c14b29c9", specVersion: "8", // Until buildbot issues around CI tiers are resolved, we cannot use them // tierConfig: self.tierConfig, From 090ea543806e85de645d1ec8cd05623002440b93 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Sat, 20 Jun 2026 14:49:25 +0200 Subject: [PATCH 20/20] Enable GraalOS standalone runtime codegen --- graalpython/graalpy_graalos_standalone_payload/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/graalpython/graalpy_graalos_standalone_payload/config.json b/graalpython/graalpy_graalos_standalone_payload/config.json index 20940f1998..909725a003 100644 --- a/graalpython/graalpy_graalos_standalone_payload/config.json +++ b/graalpython/graalpy_graalos_standalone_payload/config.json @@ -5,6 +5,7 @@ "PYTHONHOME": "/" }, "working_dir": "/", + "allow_runtime_codegen": true, "testing_default_mappings": true, "allowed_ports": [], "graalhost": {