Bug: inline times codegen doesn't flush virtual stack before loop #264
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#264
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
The inline
timesloop codegen has a virtual stack synchronization bug that causes incorrect results when the loop body operates on values pushed before the loop.Reproduction
Expected:
8(1→2→4→8)Actual:
2Root Cause
The inline codegen keeps the initial value (
1) in a virtual register (%0), but the loop body re-materializes it every iteration instead of working with the accumulated value:After each iteration, the result is stored to the stack, but then immediately overwritten with the original
%0value at the start of the next iteration.Affected Code
crates/compiler/src/codegen/inline/ops.rs-codegen_inline_times_literalProposed Fix
Flush the virtual stack to the real stack BEFORE entering the loop, so the loop body works purely on real stack values. The virtual stack state should be "empty" (all values materialized) when the loop begins.
Notes
patch_seq_timesfunction works correctly - this only affects the inlined codegen path10-quotations/03-times.seqFix Applied
Fixed by spilling virtual stack before entering loop and using a proper preloop block for phi node predecessors.
Changes:
codegen_inline_times_literal: Addedspill_virtual_stack()call and preloop blockcodegen_inline_while: Same fixcodegen_inline_until: Same fixFiles modified:
crates/compiler/src/codegen/inline/ops.rsAll 293 integration tests pass.
https://github.com/navicore/patch-seq/pull/265