Files
RustPython/tools/opcode_metadata/verify_stack_contract.py
T
dot a974ec938d Align compiler and VM with pinned CPython 3.15 ABI
Couple opcode/cache/stack metadata with iterator pairs, generator preambles, ordinary import packing, common constants, compiler lowering and VM/JIT consumers. Pin official source/tool hashes and retain strict raw code and marshal comparisons.

Use private development magic 0xDA16 and cache tag devabi2 until serialization and Python integration are coherent. Final clean corpus matches recursive code fields in 111/111 requests; full marshal/header exactness remains 0/111. Eight existing disassembly tests remain blocked by unchanged Lib metadata. Monitoring export and frozendict/update_lib integration remain explicit follow-on gates.

Validation: compiler-core 23, codegen 807, CAPI 121 (4 existing ignored), focused certified-controller pytest, release/frozen witnesses, workspace and CAPI all-target Clippy. Independent source/artifact review covers manifest ec1013591ae97b4c519f4a2c78a8200664f3479f0c5452991b5fea4d1be669ea.

Assisted-by: OpenAI Codex:model identifier unavailable
2026-10-12 00:20:11 +09:00

52 lines
1.8 KiB
Python

"""Regenerate independent C stack goldens, or fail if checked-in rows differ."""
import argparse
import subprocess
import tempfile
from pathlib import Path
from target_source import verify_source
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", type=Path, required=True)
parser.add_argument("--build", type=Path, required=True)
parser.add_argument("--write", action="store_true")
args = parser.parse_args()
verify_source(args.source)
here = Path(__file__).resolve().parent
with tempfile.TemporaryDirectory() as temporary:
binary = Path(temporary) / "stack-contract"
subprocess.run(
[
"cc",
"-I" + str(args.build),
"-I" + str(args.source / "Include"),
"-I" + str(args.source / "Include/internal"),
str(here / "stack_contract.c"),
"-o",
str(binary),
],
check=True,
)
output = subprocess.check_output([str(binary)], text=True)
rows = [tuple(map(int, line.split())) for line in output.splitlines()]
assert len(rows) == 3430 and len(set(rows)) == 3430
contents = (
"// Generated by tools/opcode_metadata/verify_stack_contract.py from pinned CPython C metadata.\n"
"const TARGET_STACK_CASES: &[(u16, u32, u32, u32)] = &[\n"
+ "".join(f" ({op}, {arg}, {pop}, {push}),\n" for op, arg, pop, push in rows)
+ "];\n"
)
target = here.parents[1] / "crates/compiler-core/src/bytecode/target_stack_cases.rs"
if args.write:
target.write_text(contents)
elif target.read_text() != contents:
raise SystemExit("pinned C stack rows differ")
print(f"Verified {len(rows)} exact C stack rows")
if __name__ == "__main__":
main()