mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
* Align compiler and VM with final CPython 3.15 bytecode Reconstruct the compiler-only baseline from validated487ae47 on the current main and frozen mapping prerequisitec78d811. Preserve the full source delta while dropping obsolete prerequisite ancestry; detailed old-to-new provenance is retained in the recovery artifact. Assisted-by: OpenAI Codex: model identifier unavailable * Fix final script validation, exception cleanup and private cache contracts Replay reviewed compiler CI repairs2191a9d,1f1fe04,a2dacafon the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Align canonical compiler fixtures and generator frame state Replay reviewed compiler CI repairs476bb74on the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Preserve code-name owners and final warning and constant-fold contracts Replay reviewed compiler CI repairs6482adfon the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Skip unavailable monitoring C API tests before tool registration Replay reviewed compiler CI repairs246c309on the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Assert exact final constant-list iterable folding Replay reviewed compiler CI repairs7ecedcfon the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Align local monitoring events and exception lifecycle state with final 3.15 Replay reviewed compiler CI repairsec206b1,191fe58on the frozen current prerequisite. Intermediate compile/diagnostic corrections are combined where they address the same failure. Assisted-by: OpenAI Codex: model identifier unavailable * Align 3.15 code objects and codegen with CPython - Store co_consts, co_names, co_localsplusnames, co_localspluskinds, co_linetable, co_exceptiontable and co_name as objects on PyCode; build co_code and the varnames/cellvars/freevars tuples lazily in _co_cached, with co_code deoptimized through deopt_code. - Move the compiler constant cache (_PyCode_ConstantKey, const_cache_insert) to builtins/code/const_cache.rs. - Write every code field with w_object in marshal and pass the read field objects to MarshalBag::make_code through CodeFields. - Emit RETURN_GENERATOR/POP_TOP in enter_scope and place SETUP_CLEANUP after them; drop the generator part of insert_prefix_instructions. - Add PyCode::first_traceable (_co_firsttraceable) for _PyFrame_IsIncomplete and sys.monitoring. - Follow the CPython DISABLE branches in sys.monitoring, the check_matched signature in warnings, the 3.15 % format error messages for str and bytes, code_returns_only_none, and the FOR_ITER stack analysis. - Compute IMPORT_NAME flags with in_exception_handler. - Replace the linetable/exceptiontable byte tests in codegen with dis(show_positions=True) insta snapshots in _opcode. - Remove the opcode metadata verification tooling, byte-exact scripts, private cache tests and redundant snippets. - Restore test_code.py and test_monitoring.py to v3.15.0 plus RUSTPYTHON markers. Assisted-by: Claude Code:claude-opus-5-5 * Remove generator snippet checks covered by Lib/test Drop extra_tests/snippets/generator_iterator_prefix.py. Its loop, delegation, async, f_back and never-awaited checks are covered by test_generators, test_coroutines, test_asyncgen, test_yield_from and test_monitoring. Move the remaining checks into existing files: genexpr prefix tracing and monitoring into stdlib_sys.py, and the caller frame seen from the eager iterator into stdlib_sys_getframe.py. Assisted-by: Claude Code:claude-opus-5-5 * Emit the generator prefix for top-level await modules Module code compiled with PyCF_ALLOW_TOP_LEVEL_AWAIT and marked ste_coroutine now starts with RETURN_GENERATOR; POP_TOP. The prefix and RESUME emission move into emit_scope_prefix, shared by enter_scope and the module entry points, as in codegen_enter_scope. Fixes test_builtin.test_compile_top_level_await. Assisted-by: Claude Code:claude-opus-5-5 * Allow the c_long cast in _opcode.stack_effect c_long is i32 on Windows, where clippy reports the cast to i32 as unnecessary. Assisted-by: Claude Code:claude-opus-5-5 * Update malachite crates to 0.14.0 pymath requires malachite-bigint ^0, so the example projects, which have no lock file, resolve it to 0.14.0 while the workspace pinned 0.13.0, and fail to build. Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: dot <dot@youknowone.org>
136 lines
3.5 KiB
Python
Vendored
136 lines
3.5 KiB
Python
Vendored
|
|
"""
|
|
opcode module - potentially shared between dis and other modules which
|
|
operate on bytecodes (e.g. peephole optimizers).
|
|
"""
|
|
|
|
|
|
__all__ = ["cmp_op", "stack_effect", "hascompare", "opname", "opmap",
|
|
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",
|
|
"hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]
|
|
|
|
import builtins
|
|
import _opcode
|
|
from _opcode import stack_effect
|
|
|
|
from _opcode_metadata import (_specializations, _specialized_opmap, opmap, # noqa: F401
|
|
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE) # noqa: F401
|
|
EXTENDED_ARG = opmap['EXTENDED_ARG']
|
|
|
|
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
|
|
for m in (opmap, _specialized_opmap):
|
|
for op, i in m.items():
|
|
opname[i] = op
|
|
|
|
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
|
|
|
|
# These lists are documented as part of the dis module's API
|
|
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
|
|
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
|
|
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
|
|
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
|
|
hasjrel = hasjump # for backward compatibility
|
|
hasjabs = []
|
|
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
|
|
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
|
|
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
|
|
|
|
|
|
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
|
|
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
|
|
_special_method_names = _opcode.get_special_method_names()
|
|
_common_constants = [builtins.AssertionError, builtins.NotImplementedError,
|
|
builtins.tuple, builtins.all, builtins.any, builtins.list,
|
|
builtins.set,
|
|
# Append-only — must match CONSTANT_* in
|
|
# Include/internal/pycore_opcode_utils.h.
|
|
None, "", True, False, -1]
|
|
_nb_ops = _opcode.get_nb_ops()
|
|
|
|
hascompare = [opmap["COMPARE_OP"]]
|
|
|
|
_cache_format = frozendict(
|
|
LOAD_GLOBAL=frozendict(
|
|
counter=1,
|
|
index=1,
|
|
module_keys_version=1,
|
|
builtin_keys_version=1,
|
|
),
|
|
BINARY_OP=frozendict(
|
|
counter=1,
|
|
descr=4,
|
|
),
|
|
UNPACK_SEQUENCE=frozendict(
|
|
counter=1,
|
|
),
|
|
COMPARE_OP=frozendict(
|
|
counter=1,
|
|
),
|
|
CONTAINS_OP=frozendict(
|
|
counter=1,
|
|
),
|
|
FOR_ITER=frozendict(
|
|
counter=1,
|
|
),
|
|
GET_ITER=frozendict(
|
|
counter=1,
|
|
),
|
|
LOAD_SUPER_ATTR=frozendict(
|
|
counter=1,
|
|
),
|
|
LOAD_ATTR=frozendict(
|
|
counter=1,
|
|
version=2,
|
|
keys_version=2,
|
|
descr=4,
|
|
),
|
|
STORE_ATTR=frozendict(
|
|
counter=1,
|
|
version=2,
|
|
index=1,
|
|
),
|
|
CALL=frozendict(
|
|
counter=1,
|
|
func_version=2,
|
|
),
|
|
CALL_KW=frozendict(
|
|
counter=1,
|
|
func_version=2,
|
|
),
|
|
CALL_FUNCTION_EX=frozendict(
|
|
counter=1,
|
|
),
|
|
STORE_SUBSCR=frozendict(
|
|
counter=1,
|
|
),
|
|
SEND=frozendict(
|
|
counter=1,
|
|
),
|
|
JUMP_BACKWARD=frozendict(
|
|
counter=1,
|
|
),
|
|
TO_BOOL=frozendict(
|
|
counter=1,
|
|
version=2,
|
|
),
|
|
POP_JUMP_IF_TRUE=frozendict(
|
|
counter=1,
|
|
),
|
|
POP_JUMP_IF_FALSE=frozendict(
|
|
counter=1,
|
|
),
|
|
POP_JUMP_IF_NONE=frozendict(
|
|
counter=1,
|
|
),
|
|
POP_JUMP_IF_NOT_NONE=frozendict(
|
|
counter=1,
|
|
),
|
|
RESUME=frozendict(
|
|
counter=1,
|
|
),
|
|
)
|
|
|
|
_inline_cache_entries = frozendict({
|
|
name : sum(value.values()) for (name, value) in _cache_format.items()
|
|
})
|