Repository navigation
feat(mir-importer): accept provably no-op drop glue; for-loops over arrays - #167
Merged
Merged
Conversation
…e and the IntoIter machinery `for x in arr` over a by-value `[T; N]` never compiled on the device: the loop's `core::array::IntoIter<T, N>` has an `impl Drop`, and `translate_drop` rejected every MIR `Drop` terminator. Fixing the drop also surfaced three more gaps on the same path, all inside the monomorphized `PolymorphicIter<[MaybeUninit<T>]>::next` that backs the loop. All four are fixed: - Drop terminators: new `drop_glue` analysis walks the monomorphized drop-glue MIR and proves it does nothing observable (only writes to its own locals, calls that resolve to empty shims, branches folded by constant or UbChecks discriminants). Provably no-op drops lower to a plain branch; genuinely effectful destructors keep the loud error, so the no-silent-miscompile guarantee from PR #27 stands (error_drop_glue still fails as required). - Deeply projected assignments: `(*iter).alive.start = v` is a 3-projection destination. statement.rs now walks any 3+ projection chain to a destination address with the same place-address walker that `Rvalue::Ref` uses, then stores through it, instead of enumerating projection combinations by hand. - `assert_inhabited::<T>()` (planted by `MaybeUninit::assume_init_read`): lowers to a unit no-op for inhabited `T` (decided from the layout's `VariantsShape`) and to `unreachable` for uninhabited `T`. - Fat references to slice-tailed structs: `&mut PolymorphicIter<[MaybeUninit<T>]>` is a fat (ptr, len) pair. It is now modelled as `MirSliceType` with the struct as element type, so function-boundary flattening and `PtrMetadata` reuse the existing slice machinery. The place-address walker continues through fat derefs by extracting the data pointer; borrows of the unsized tail produce a real (tail ptr, len) pair with the carried-over metadata; `(*slice)[i]` gets element-size pointer arithmetic; and the unsize cast `&S<[T; N]> -> &S<[T]>` materializes the element count from the struct's trailing array. The new `array_for_loop` example host-verifies both issue shapes: a `for` loop over `[u32; 4]` and over an array of Copy structs. Fixes #138
Reconcile two independent extensions of the place-address walker in mir-importer: - This branch (issue #138) taught the walker to continue through fat-pointer derefs for MirSliceType (tail borrows of slice-tailed unsized structs, deep projection-chain assignments, indexed element addresses), but punted on MirDisjointSliceType. - origin/main (PR #165, issue #58) taught the same walker to compute mutable element addresses through fat derefs for BOTH MirSliceType and MirDisjointSliceType, with a (Deref, Index) assignment arm in statement translation. Unified resolution, one mechanism with the union of capabilities: - Fat-pointee detection uses main's broader fat_elem_ty (slice AND disjoint slice), feeding this branch's continuation machinery (load pair, extract data pointer, tail-borrow slice construction, next-projection dispatch). DisjointSlice no longer punts mid-chain. - Index / ConstantIndex arms keep the emit_indexed_element_addr helper, with main's PointeeKind::Direct naming (array GEP vs plain ptr_offset off a slice data pointer). - statement.rs: main's (Deref, Index | ConstantIndex) arm and this branch's generic 3+ projection fallback now share one store_through_place_address helper (walk the chain mutably, store through the address; punts are loud errors, never value copies). Validated: mir-importer + mir-lower tests, clippy -D warnings, fmt, array_for_loop + slice_get_mut compile with stores through GEPs off the fat data pointer (no spilled copy), error_drop_glue still fails with the destructor diagnostic, compile-only smoketest 84/84.
nihalpasham
added a commit
that referenced
this pull request
Jun 11, 2026
# Conflicts: # crates/rustc-codegen-cuda/STATUS.md
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
for x in arrover[T; N]now compiles for element types whose drop does no work.The decision is NOT
needs_drop(which is true forIntoIter<u32, 4>even though its glue is empty); a small analysis walks the monomorphized drop-glue MIR and accepts only locals-only writes, empty shim calls, and const-folded branches. The reviewer probed this adversarially: an emptyimpl Dropis accepted, a raw-pointer-writing destructor is rejected in two shapes (per-element drop, and anIntoIter-only drop forcing the nested glue chain).Making the loop machinery actually run required three more arms on the same path: deep projection-chain assignments (
(*iter).alive.start = v), theassert_inhabitedintrinsic (fromMaybeUninit::assume_init_read), and fat references to slice-tailed unsized structs (the iterator's&mut PolymorphicIter<[MaybeUninit<T>]>is a(ptr, len)pair). This branch includes a reconciling merge with #165's fat-pointer mutable-place work: one unified walker carries the union of both capabilities (verified by re-running BOTH bite-proofs on the merged code and re-checking #165's store-chain IR guarantee).Evidence
array_for_loop([u32; 4]and[Point; 4]sums, host-verified) passes on sm_120;slice_get_mut(fix(mir-importer): compute element addresses through fat-pointer derefs #165's canary) also passes on the merged code.error_drop_gluestill fails: its destructor writes through a raw pointer, exactly what the analysis must reject. STATUS.md row narrowed to "(effectful)" with an explanation.drop of std::array::IntoIter ... not supportederror.Fixes #138