Repository navigation
Merged
Conversation
This was referenced Sep 28, 2026
Contributor
Author
|
Battery GREEN on the stack top |
ehartford
marked this pull request as ready for review
September 28, 2026 05:11
ehartford
force-pushed
the
fix-fill
branch
2 times, most recently
from
September 28, 2026 05:12
c68e095 to
7fdb39b
Compare
added 2 commits
September 28, 2026 01:12
…not its element count — the tail was stack garbage `mir_emit_stmt`'s large-array `RK_USE` path copies an array with more than 64 elements with `llvm.memcpy`, and passed `wl_get_array_length` (the element COUNT) as the byte length. A `[u32; 100]` copy moved 100 bytes = 25 elements; the rest of the destination kept stack garbage. `u8` was right only because its count equals its byte size. The length is now `wl_abi_size_of(data layout, array type)`. The same line is #1049's root cause: a `[v; N > 64]` fill stores all N elements into its temp (the pre-cleanup IR has every store), and the copy of that temp into the binding went through this memcpy — `[7; 100]` read back `7 37486657`, exactly floor(N / sizeof(T)) elements set. The #1049 review located it here; so did this fix: with only this line changed, every fill row of the #1049 table reads back whole. One root cause, one change, both issues. Evidence: the pre-fix stage1 on the new tests prints `u32 65 bad=48`, `u32 100 bad=75`, `u32 1000 bad=750`, `u16 100 bad=50`, `u64 100 bad=88`, `pair 100 bad=94` (copy) and `u32 100 bad=75`, `u16 80 bad=40`, `u64 72 bad=63`, `i32 100 bad=75`, `pair 100 bad=94` (fill); `u8` and `N = 64` are whole. After: every row `ok`. The C backend copies with `sizeof` and is unaffected. Fixes #1050 Fixes #1049
…nt at every N, as a loop over the element places — never one value copied into N slots §4.3a / §2.3: a fill is its written form `[v, v, …]`; transport is not duplication, and no second live value comes from one unless it is Copy. - MirLower (the NK_ARRAY_LIT fill branch): over 64 elements, or with a const count, a non-Copy fill took `RK_ARRAY_FILL` — one `s.clone()` byte-copied into N slots, N owners of one buffer. `[s.clone(); 65]` segfaulted (rc 139). A non-Copy fill at any N is now `lower_non_copy_array_fill`: the array is zero-initialized storage (every element reset) registered as a statement temp, then a loop `arr[i] = move <v>` evaluates v per element; temps v creates drop per iteration, and an early exit out of v (`[f()?; 70]`) drops the elements already built. MIR size no longer grows with N. - Sema (check_array_literal): a const-count fill held its value once and checked it once, so `[s; N]` moved `s` into N elements (a silent second owner). It is checked twice when N >= 2, as the literal-count desugar's N checks do, and a moved place is "use of moved value". - The tool that stayed silent: `--validate-all` said ok over `_5 = array_fill(move _4, count=65)` of a `str`. The typed MIR validator now rejects an `array_fill` whose element type is not Copy (MirModule.sema_non_copy_fill_types, recorded from Sema beside the moved/dropped drop types); mir_test_non_copy_array_fill builds that MIR by hand. Evidence: pre-fix stage1: `[s.clone(); 65]` → `--validate-all: ok`, run rc 139, MIR `array_fill(move _4, count=65)`; the new test crashed after `64 abc abc`. After: MIR `bb1: _5 = lt(_4, 65) … bb4: _3[_4] = move _7; _4 = add(_4, 1)`; `run --debug-alloc` on the test (str fills at N = 64, 65, 100, 1000, a const 70, Drop-typed `Tok` fills at 65 and 3 with made = dropped) → `debug-alloc: leak count=0`, no double free; `--validate-all` and `--validate-ownership` ok. Early exit, discarded, looped, zero-count, argument and return fills: leak count 0. Fixes #1814
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.
Stack layer 4 of #1813. #1049+#1050 (one root cause: the >64-element array memcpy length was the element count, not the byte size), #1814 (a non-Copy fill evaluated once and byte-copied N times — N owners of one buffer; now a loop over the element places at every N, and the MIR validator refuses RK_ARRAY_FILL of a non-Copy element). Agent evidence: :gate, :drop-audit (213/0), :move-audit (105/0), :deep-debug-tool-tests green. Draft until the stack's battery is green.