Repository navigation
MIR drop-state: chunked, hash-consed block states (#1343, #1315, #1282) - #1353
Merged
Merged
Conversation
This was referenced Sep 22, 2026
…ger needs blocks × keys cells (#1343, #1315, #1282) Root cause. mir_drop_state_blocks_new (src/MirCore.w) allocated one dense out-state row per block, `for _ in 0..bb_count * keys.len(): rows.push(...)`, and every visit copied, joined and compared whole key-width rows (load_block / input / equal / store_block). lldb on the hanging stage1 (`check hello.w --validate-all`, break after mir_drop_state_keys_new with the condition bb_count > 10000) read bb_count = 0xa35a (41,818) and keys.len() = 0xa8ba (43,194): 1.8 G i32 cells, the 7.3 GB RSS of every report, then O(blocks × keys) work per sweep. The body is pcre2's `match_` (`--dump-mir`: "body too large locals=39712 bbs=41818 stmts=45104"). Why only stage1. Not a miscompile: a stage1 embeds no .wo bundles, so the prelude's std.regex resolves std.re.* to lib/std/re source and every program lowers all of pcre2 (stage1 `--dump-mir` of hello.w: 428 bodies; the release binary: 160). The release binary has the same defect on any body that size: `with check lib/std/re/pcre2_match.w --validate-all` on the installed release compiler ran for 300 s before timeout killed it. Why #1319. #1319's code is not involved: before it, `analyze` on a stage1 failed earlier on hello world, so it never reached the driver; `check --validate-all` already hung on stage1 before #1319 (#1282, #1315; reproduced on a stage1 built before #1319 merged). Fix. A state is stored in chunks of up to 128 keys, and stored chunks are hash-consed in the key table's chunk store, so equal content always has one id. A block row is one chunk id per chunk; a map copies a chunk only on the first write that changes it; the join of two stored chunks is memoized on the id pair; the fixpoint loop reuses one scratch map; the entry state is interned once. The join is not associative, so input() still folds predecessors in CSR order, chunk by chunk — the same computation per key, and the driver visits blocks in the same order, so every state matches the dense version exactly. Evidence (fresh :dev stage1): - `analyze examples/hello.w audit:all`: facts=639634 violations=0 ok in 17.7 s (was: never returned). - `check examples/hello.w --validate-all`: ok in 12.8 s, 472 MB peak (was: never returned, 7.3 GB); #1315's repro: validate-all and validate-ownership ok in 11.9 s. - Old stage1 (ae609cd) vs this stage1, both with --link-bundle out/wo/pcre2 so the old one finishes, over 101 files (every 12th test/behavior file plus examples/*.w): --dump-drop-state, --dump-drop-plan and --validate-all output byte-identical, 303/303, including one ownership-verdict failure that both report the same way. - validate-all verdicts match out/release/bin/with on hello.w and five behavior tests. (cherry picked from commit 6a176f8)
Contributor
Author
ehartford
force-pushed
the
fix-1343-drop-state-hang
branch
from
September 23, 2026 00:23
6a176f8 to
ef701be
Compare
ehartford
marked this pull request as ready for review
September 23, 2026 00:23
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.
Fixes #1343, #1315, #1282.
Root cause:
mir_drop_state_blocks_new(src/MirCore.w) set up a dense out-state row for every block:for _ in 0..bb_count * keys.len(): rows.push(MirDropState.Absent). Every visit then copied, joined and compared rows as wide as the full key set. In lldb on the hanging stage1, bb_count was 41,818 and keys.len() was 43,194. That is 1.8 G i32 cells (the 7.3 GB RSS in all three reports), plus O(blocks × keys) work per sweep. The body is pcre2'smatch_.Why only stage1 showed it: this is not a seed miscompile. A stage1 embeds no
.wobundles, so the prelude'sstd.regexresolvesstd.re.*to the pcre2 source files and every program lowers all of pcre2 (hello.w: 428 bodies on stage1, 160 on the release binary). The release binary has the same defect on any body this large:with check lib/std/re/pcre2_match.w --validate-allon the installed compiler was still running whentimeoutkilled it at 300 s.Why it seemed to start with #1319: #1319's code is not involved. Before #1319,
analyzefailed earlier on hello world, so it never got to the drop-state driver.check --validate-allalready hung on a stage1 built before #1319 (#1282, #1315).Fix: states are stored as chunked, hash-consed rows of chunk ids. A map copies a chunk only when a write changes it. Joins of chunk pairs are memoized. The fixpoint loop reuses one scratch map. The algorithm and visit order are unchanged, and predecessors are still folded in CSR order, so every state is identical to the dense version.
Evidence (fresh
:devstage1):analyze examples/hello.w audit:all:violations=0 ok, 17.7 s (before: never returned)check examples/hello.w --validate-all: ok, 12.8 s, 472 MB peak (before: never returned, 7.3 GB). The bootstrap stage1check --validate-alltakes 15+ min at 7 GB RSS on a 20-line file (release binary: 0.07 s) #1315 repro passes validate-all and validate-ownership in 11.9 s.--link-bundle out/wo/pcre2so the old one can finish:--dump-drop-state,--dump-drop-planand--validate-alloutput is byte-identical on 101 files (every 12th test/behavior file plus examples/*.w), 303 of 303 comparisons.--validate-allverdicts matchout/release/bin/withon hello.w and five behavior tests.Not run:
:fixpointand:test. This is a draft until the seed-driven battery has run and passed. The change affects drop elaboration (mir_elaborate_dead_dropsuses the same driver), so it should be in a batch by itself and needs:drop-audit.Fixes #1343
Fixes #1315
Fixes #1282