Skip to content

Split #traverseProjection write-back from path reconstruction#1055

Closed
Stevengre wants to merge 23 commits intocodex/fix-interior-mut-drop-gluefrom
codex/traverse-projection-invariant
Closed

Split #traverseProjection write-back from path reconstruction#1055
Stevengre wants to merge 23 commits intocodex/fix-interior-mut-drop-gluefrom
codex/traverse-projection-invariant

Conversation

@Stevengre
Copy link
Copy Markdown
Contributor

@Stevengre Stevengre commented Apr 10, 2026

Closes #1011.

Stacked on top of #999 (codex/fix-interior-mut-drop-glue).

Summary

This refactors #traverseProjection around a single stable invariant instead of accumulating more bridge rules.

After this change:

  • Contexts are used only for inverse write-back reconstruction through #buildUpdate
  • the forward surface place path is accumulated directly during traversal and used for #mkRef / #mkPtr
  • Deref restarts traversal from the pointee, so the old pointer's update frames and accumulated path are discarded together

That removes the need to reconstruct reference/pointer projections back out of traversal contexts, which was the source of the temporary CtxRangeHead / PointerOffset round-trip behavior from #999.

What changed

  • extend #traverseProjection with an explicit forward-path accumulator
  • remove #projectionsFor(...) entirely
  • keep CtxRangeHead(...) as an update-only inverse frame instead of letting it leak into place reconstruction
  • canonicalize range/index/offset projections while traversing, rather than patching them back together afterwards
  • rebuild references and pointers from the directly accumulated path instead of reverse-engineering one from write-back contexts
  • drop the stale niche-enum show snapshot, since it only recorded #EndProgram plus step-count drift and no longer carried diagnostic value

Why this is the right shape

The old design mixed two different concerns in one representation:

  • how to rebuild a modified aggregate/range back into its original container
  • how to describe the final surface place reached by traversal for ref/pointer construction

Those are not the same problem. Once they are represented separately, the temporary bridge rules stop being necessary because CtxRangeHead and CtxPointerOffset no longer need to serve double duty.

Validation

  • uv --project kmir run kdist build mir-semantics.haskell mir-semantics.llvm-library -j4
  • uv --project kmir run pytest kmir/src/tests/integration/test_run_smir_random.py -v -k 'complex-types'
  • uv --project kmir run pytest kmir/src/tests/integration/test_integration.py -v --timeout=600 -k 'iterator-simple or iter-eq-copied-take-dereftruncate or maybe-uninit or Ptr-offset_struct_field_read or Ptr-offset_struct_field_write or Ptr-offset_read or Ptr-offset_write'
  • uv --project kmir run pytest kmir/src/tests/integration/test_integration.py -v --timeout=600 -k 'pointer-cast-zst or enum-discriminants or niche-enum'

@Stevengre Stevengre changed the title Refactor #traverseProjection range normalization Split #traverseProjection write-back from path reconstruction Apr 10, 2026
The old Copy rule only matched `.ProjectionElems` (no projections) and the
Move rule marked the entire base local as Moved without traversing projections.
Both fail for projected places.

Replace the three ad-hoc rules with a single `[owise]` that delegates to the
normal operand evaluation path via `#discardNoOpResult`, so projected
Copy/Move operands traverse projections correctly and only invalidate the
precise subplace.
@Stevengre Stevengre force-pushed the codex/traverse-projection-invariant branch from ac861c9 to 3958dcc Compare April 15, 2026 03:26
…view

Two targeted fixes for issues identified during Codex adversarial review:

1. Generalize Range-head descent into a single #projectsHead rule instead of
   two specialized Range+Field(Aggregate)/Range+Field(Union) rules. The new
   rule separates Range-head descent from scalar projection application,
   making the traversal closed under Field, Downcast, Deref, and WrapStruct
   projections on Range head elements.

2. Fix from-end ConstantIndex to read getValue(ELEMENTS, MINLEN - OFFSET)
   instead of getValue(ELEMENTS, OFFSET), so the read index is consistent
   with the write-back context and path reconstruction.
@Stevengre Stevengre force-pushed the codex/traverse-projection-invariant branch from 3958dcc to 74ce504 Compare April 15, 2026 03:28
@Stevengre Stevengre force-pushed the codex/fix-interior-mut-drop-glue branch 2 times, most recently from 575b6ed to 8c27c7e Compare April 16, 2026 08:48
@Stevengre Stevengre closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant