Summary
RustPython still folds slice objects and tuple-of-slice literals more aggressively than CPython. This creates
large structural bytecode drift in slice-heavy tests.
Evidence
Representative mismatches include:
- CPython
LOAD_CONST None vs RustPython LOAD_CONST slice(None, None, -1)
- CPython scalar constants vs RustPython prebuilt tuple-of-slices constants
- CPython list/loop shape vs RustPython early slice-object materialization
Examples seen in:
Lib/test/test_buffer.py
Lib/dataclasses.py
Lib/test/test_math.py
Specific cases from reports include:
test_buffer.py::transpose
test_buffer.py::test_memoryview_compare_multidim_mixed
test_buffer.py::test_memoryview_compare_multidim_suboffsets
dataclasses.py::_process_class
Expected direction
Slice lowering should follow CPython’s compilation structure. RustPython should avoid turning slice syntax
into constants earlier than CPython does, especially when that changes control-flow shape or constant-table
layout.
Likely implementation areas
crates/codegen/src/compile.rs
- literal/constant-folding paths used during AST or IR lowering
Done when
The slice-heavy functions above stop producing slice(...) and tuple-of-slices constants where CPython still
emits scalar constants or later slice-building bytecode.
Summary
RustPython still folds slice objects and tuple-of-slice literals more aggressively than CPython. This creates
large structural bytecode drift in slice-heavy tests.
Evidence
Representative mismatches include:
LOAD_CONST Nonevs RustPythonLOAD_CONST slice(None, None, -1)Examples seen in:
Lib/test/test_buffer.pyLib/dataclasses.pyLib/test/test_math.pySpecific cases from reports include:
test_buffer.py::transposetest_buffer.py::test_memoryview_compare_multidim_mixedtest_buffer.py::test_memoryview_compare_multidim_suboffsetsdataclasses.py::_process_classExpected direction
Slice lowering should follow CPython’s compilation structure. RustPython should avoid turning slice syntax
into constants earlier than CPython does, especially when that changes control-flow shape or constant-table
layout.
Likely implementation areas
crates/codegen/src/compile.rsDone when
The slice-heavy functions above stop producing
slice(...)and tuple-of-slices constants where CPython stillemits scalar constants or later slice-building bytecode.