Repository navigation
analyze: audit:pool-views catches intern-pool views held across interning; sweep of the 33 sites (#1323) - #1328
Merged
Merged
Conversation
added 8 commits
September 22, 2026 14:48
…ave grown (#1323) `InternPool.resolve_symbol` returns `&self.state.symbol_texts[sym]`; a binding of that view read after anything interns is a use-after-free inside the compiler (the release binary segfaulted in ct_generate_debug_derive, #1322). The pool sits behind a Copy `*mut InternPoolState` handle, so the ordinary "cannot mutate while a view is live" check never sees the aliasing: the same program over a plain struct is rejected at check time. The audit derives every role from the live MIR and call graph, never from a name: a pool field is the F in `<place>.F[i]` whose element some body returns a ref to; a producer is that body or a wrapper returning its result (InternPool.resolve, Sema.pool_resolve, AstPool.get_string, …); a grower mutates a place ending in a pool field in place (mut-receiver call, mutating container intrinsic) or assigns it, plus everything reaching one over the call graph, per field; a hit is a local holding a producer's result that is read, passed or written through after a call reaching a grower of its field with no reassignment between, on any CFG path (forward dataflow, union at joins). It is part of audit:all. The first cut queued a successor only when its in-state grew, so a block after a clean call was never audited and the fixture's planted defect passed silently; every block is now visited at least once. WITH_ANALYZE_TRACE= pool-views prints the per-block state. The deep-debug lane runs the audit over a fixture with one defect (`dangling`) and two clean shapes (`safe`, `reads_only`) and requires the defect named and the clean cases silent. On src/main.w: 7 fields, 18 producers, 23 direct growers, 33 hits, 99 s and 1.5 GB.
…t return i32, not a view (#1323) Unannotated, D43 tail inference gave these accessors the element place's type `&i32` — a view into impl_type_params / impl_trait_type_args, which add_impl_type_params / add_impl_trait_type_args push to. audit:pool-views flagged the views held across resolve_type_expr and resolve_impl_trait_arg_for_source in Sema.bind_type_params_from_type_expr (SemaCheck.w:17409), Sema.select_blanket_impl_for_generic_inst (17735) and Sema.install_trait_default_type_args (SemaDecl.w:2104, 2106). A start or a count is a value; the signature now says so.
audit:pool-views: eval_str_method_call `method` read at 3431 after eval_expr; function_decl_summary_value and type_decl_summary_value `name` passed at 4221 / 4268 after empty_vec_for_field — all reach InternPool.intern_str.
audit:pool-views: check_index `base_name` read at 12092 after check_expr; check_method_call_parts `mc_method_name_raw` passed at 21467 after check_builtin_method_call_arg; check_typeinfo_module_call `method_name` read at 22476 after resolve_type_level_arg_expr — all reach Sema.pool_intern.
audit:pool-views: collect_fn_decl `fn_name_str` passed at 1654 after resolve_type_expr; collect_impl_decl `trait_name` read at 2481 after warn_large_copy_type — both reach Sema.pool_intern.
audit:pool-views: `name_str` passed at 5388 after compute_fn_abi, which reaches InternPool.intern_str.
…ve_type (#1323) audit:pool-views: mir_emit_atomic_fiber_intrinsic_call `asm_constr` passed at 10186 after resolve_type, which reaches InternPool.intern_str.
audit:pool-views: ensure_monomorphized_trait_vtable `type_name`, `trait_name`, `method_name` read at 1054 after InternPool.intern; ensure_generic_inst_trait_vtable `trait_text` read at 1122 after ensure_concrete_mir_function — all reach InternPool.intern_str.
ehartford
force-pushed
the
fix-1323-intern-views
branch
from
September 22, 2026 19:10
5b7f879 to
fea60e3
Compare
Contributor
Author
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 #1323. Based on #1322 (
fix-derive-x-match-observes), which owns the 17 ComptimeTransform sites; merge that first, then this rebases to main.The tool:
with analyze <file> audit:pool-views(inaudit:all)InternPool.resolve_symbolreturns&self.state.symbol_texts[sym]— a reference to thestrheader slot inside aVec[str]. The bytes live in the never-movingInternStringArena; the header slot is what the nextpushfrees. Anylet name = intern.resolve(sym)still read after something interns is a use-after-free inside the compiler (release binary segfaulted inct_generate_debug_derive, #1322).Why the language did not catch it. The same program over a plain struct (
type Pool { texts: Vec[str] },fn resolve(i) -> &str: self.texts[i], thenp.intern(..), then use) is rejected at check time:cannot mutate p while name is a live view into it.InternPoolis a Copy handle over*mut InternPoolState, so the view-invalidation check never sees the aliasing. That is the root cause; the audit polices the class until the structure is fixed (see the decision below).Criterion, derived from live MIR and the live call graph, never from a name:
F: the field in<place>.F[i]whose element some body returns arefto (throughcopychains to_0);_0is a producer's call result — found:InternPool.resolve_symbol/resolve,Sema.pool_resolve_symbol/pool_resolve,MirBuilder.symbol_text,AstPool.get_string,Ci{Type,Expr,Stmt,Decl}Pool.get_string,Sema.source_text_view_for_file_id/source_text_for_decl_node,Sema.dyn_impl_row_sig/dyn_impl_row_mono_sym, and (before the fix below)AstPool.impl_type_params_start/count,impl_trait_type_args_start/count;Fas the receiver of amut fn/move fncall or a mutating container intrinsic (symbol_texts.push), or assigns the field; plus everything reaching one over the MIR call graph, per field (growingsymbol_textsnever poisons a view intoimpl_type_params);copychains) that is read, passed, or written through after a call reaching a grower of its field with no reassignment between, on any CFG path (forward dataflow, union at joins).Each violation names the function, binding, producer, source line, the poisoning call and the direct grower it reaches.
WITH_ANALYZE_TRACE=pool-viewsprints the per-block state. Not covered, by design and stated indocs/deep-debugging-tools.md: a view stored into an aggregate, a view from a builtin (Vec.get), a view into a container the function owns.A tool that stayed silent is a bug — it happened here: the first cut queued a CFG successor only when its in-state grew, so a block after a clean call was never audited and the fixture's planted defect passed with
violations=0 ok. Every block is now visited at least once; the fixture (deep-debug lane inbuild.w) requires the planteddanglingnamed and the cleansafe/reads_onlysilent, andaudit:allover the same fixture must fail too.Cost on
src/main.w: 99 s, 1.5 GB (facts collection dominates).The sweep
analyze src/main.w audit:pool-viewson the base: 37 hits (33 once growth is tracked per pool field; the 4 dropped wereAstPoolviews "poisoned" by calls that only reachintern_str). After: 0. One commit per module:Ast.w:impl_type_params_start/count,impl_trait_type_args_start/countwere unannotated, so D43 gave them the element place's type&i32— a real view into a Vec theiradd_*siblings push to. Annotated-> i32; fixes 5 sites in SemaCheck/SemaDecl at the producer.ComptimeEval.w(3),SemaCheck.w(3),SemaDecl.w(2),Codegen.w(1),CodegenDispatch.w(1),CodegenTraits.w(4): own the text at the binding (.clone()), each commit lists the site, the poisoning call and the grower.ComptimeTransform.w(14 of the 33): owned by Main reds: derive generators held an intern-pool view across interning (release-only segfault); da_match_place_observes never allocated #1322, not touched here.Alternative I evaluated — decision needed, not taken here
Making
resolvereturn an ownedstris wrong: it allocates on everypool_resolveon every hot path, and most of the ~200 bindings never intern. Astrheader copy (bytes are arena-stable) would be a second owner of the same allocation — §2.3 transport is not duplication — so that is out too.The structural fix is making the header store stable:
symbol_textsas a chunked store (fixed pages ofstrheaders, allocated likeInternStringArena's byte pages, never reallocated) so&symbol_texts[sym]is valid for the pool's lifetime and the class cannot exist forInternPool.resolve's contract (-> &str) stays. The audit still guards the other pools (AstPool.get_string,Ci*Pool.get_string,dyn_impl_row_*). I have not changedInternPool; that is Eric's call.Verification
with check src/main.w: ok.with build :dev: green (stage1 built with the audit and the fixes).analyze src/main.w audit:pool-viewswith that stage1:violations=0 ok; fixture:violations=1 FAILEDnamingdanglingonly.run --debug-alloc test/behavior/derive_enum_debug_clone.w: expected output,leak count=0.:fixpoint,:test, and the deep-debug lane itself (deep-debug-tool-testsneeds the release build) — the fixture and the audit were exercised by hand with the same command the lane runs.