From ebbfb5c3b30648ba22774e1f40e11a7ed791b55c Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Thu, 24 Sep 2026 11:29:14 +0200 Subject: [PATCH] Bump the bytecode version on every truffle import --- .../bytecode_dsl/BytecodeDSLCompiler.java | 6 ++++- mx.graalpython/mx_graalpython.py | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) 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 7d873180af..ad9e3804ef 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 @@ -67,7 +67,11 @@ import com.oracle.truffle.api.source.Source; public class BytecodeDSLCompiler { - public static final int BYTECODE_VERSION = 33; + /* + * Bump this with every Truffle import change because serialized GraalPy bytecode effectively + * depends on Truffle bytecode internals. + */ + public static final int BYTECODE_VERSION = 34; public static final record BytecodeDSLCompilerResult(PBytecodeDSLRootNode rootNode, BytecodeDSLCodeUnit codeUnit) { } diff --git a/mx.graalpython/mx_graalpython.py b/mx.graalpython/mx_graalpython.py index f7f45052ee..c7c2e616d4 100644 --- a/mx.graalpython/mx_graalpython.py +++ b/mx.graalpython/mx_graalpython.py @@ -2739,8 +2739,9 @@ def update_import(name, suite_py: Path, args): break if not dep_dir: mx.warn("could not find suite %s to update" % name) - return + return False vc = cast(mx.VC, mx.VC.get_vc(dep_dir)) + old_tip = str(vc.tip(dep_dir)).strip() repo_name = os.path.basename(dep_dir) if repo_name == "graal" and args.graal_rev: rev = args.graal_rev @@ -2762,7 +2763,7 @@ def update_import(name, suite_py: Path, args): end = dep_match.end(1) assert end - start == len(tip) mx.update_file(suite_py.resolve().as_posix(), "".join([contents[:start], tip, contents[end:]]), showDiff=True) - return tip + return tip != old_tip def _import_update_branch_name(): @@ -2891,10 +2892,23 @@ def update_import_cmd(args): for suite in d["suite"].get("imports", {}).get("suites", []): imports_to_update.add(suite["name"]) - revisions = {} + changed = False # now update all imports for name in imports_to_update: - revisions[name] = update_import(name, suite_py, args) + changed = update_import(name, suite_py, args) or changed + + if changed: + # bump the bytecode version, because truffle may have changed + source = repo / "graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/BytecodeDSLCompiler.java" + with open(source) as f: + contents = f.read() + matches = list(re.compile(r"(public static final int BYTECODE_VERSION = )(\d+)(;)").finditer(contents)) + if len(matches) != 1: + mx.abort(f"expected exactly one bytecode version in {source}, found {len(matches)}") + match = matches[0] + version = int(match.group(2)) + updated = contents[:match.start(2)] + str(version + 1) + contents[match.end(2):] + mx.update_file(source.resolve().as_posix(), updated, showDiff=True) shutil.copy(truffle_repo / "common.json", repo / "ci" / "graal" / "common.json") shutil.copytree(truffle_repo / "ci", repo / "ci" / "graal" / "ci", dirs_exist_ok=True)