Skip to content

Release-only invalid free in parallel workspace compile: dropped Vec slot holds the drop-origin tag's address (generation divergence) #729

Closed

Description

@ehartford

Repro

build-w-workspace-parallel-multi selfhost case, or standalone: a build.w with two ctx.create_workspace + add_string workspaces passed to parallel(...); run with build with the release binary. Panics invalid free: pointer is not an allocated payload start. stage1 (seed-compiled, same source) runs it clean — new-compiler codegen is implicated. Survives WITH_ALLOC_NO_REUSE=1 (not reuse corruption). Blocks the :test aggregate at cli-selfhost-build-w-tests, which gates reseed.

Evidence (lldb, release binary)

  • Panic frames: with_panic_core <- rt_free_unlocked_with_drop_origin <- with_vec_free_drop_origin <- [ComptimeEvaluator.compile_workspace_record inlined] <- eval_parallel_workspaces_call.
  • At the panic, the callee-saved reg holding the freed pointer = 0x103f3ead0, which is inside with.__TEXT.__const, and the bytes there read "drop#struct __drop_struct_357" — the free was handed (a slot containing) the drop-origin tag string's address where the Vec payload pointer belongs.
  • The emitter (CodegenDispatch mir_emit_vec_free_ptr) pushes [ptr, origin_ptr, origin_len] correctly at the MIR level; the corruption is downstream — either the glue's receiver marshalling or the origin-threading in the emitted drop glue for __drop_struct_357 under the new compiler.

Fixed-en-route (landed, kept — all real bugs this hunt surfaced)

  • c146669: workspace/capability records cloned at every read (double free, workspace-file case — that case is now green).
  • 6309adf: compile plans cloned into thread jobs/executor.
  • ddb3b16: success-message chain borrows Compilation/AstPool instead of consuming raw-deref copies (seam-sites row).

Next step

Compare the emitted __drop_struct_357 (and its caller's receiver setup) between the stage1 and stage2/release builds — the divergence is in the drop-glue/origin-threading codegen, same investigation shape as the join-truncation (88647fd) which was found by exactly this stage1-vs-release bisection.

Activity

  1. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    Root cause narrowed to the exact gate, with a small-repro matrix (all traced via new WITH_TRACE_RESETS instrumentation + --dump-abi):

    1. Sema still classifies plain read-only T params as SHARE-PLACE (eff=[read] value_ref_abi=1) — the superseded D5 body-inference, live in the sig finalizer. --dump-abi on a trivial fn take2(x: Vec[str], y: Vec[str]) shows SHARE-PLACE for both. Worse: a callee that MOVES fields out of its param (retainer pushing b.a/b.b into a returned vec) still classifies [read] — retention doesn't flip the effect.

    2. Share-place args skip consume_moved_operand in lower_call_arg (arg_is_copy or not callee_share_place). That's correct for borrow semantics ONLY because the callee-side reset machinery blanks moved-out fields through the place alias — verified: retainer's MIR blanks _1.f25/_1.f26 = const zst after each single-field-move call, and the runtime is clean even though the caller keeps the drop.

    3. The loss: a call passing TWO+ moved-field operands to a share-place callee loses ALL its field resets — m.take2(p.a, p.b) lowers as call(copy recv, move _4.f25, move _4.f26) with NO blanks (single-field-arg calls blank correctly; traced: the move operands are created but never reach consume — [new-move-op] id=19/20 with no matching [consume]). comptime_execute_workspace_compile_plan's interior call sym12742(copy _12, move _1.f7561, move _1.f751) is exactly this shape, so the plan's field buffers flow into the Compilation with no blanks anywhere in the alias chain, and eval_parallel's guarded drop of the plan storage (stale non-zero bytes, since the blank never landed) frees them again → the invalid free.

    The one-arg/two-arg divergence means the two shapes take different lowering paths (the single-arg path consumes even for share-place callees; the multi-arg path skips) — the per-path drift D6 warns about, here for arg-consume rather than ABI.

    Open fork for Eric (will brief separately): the D5-superseded read-only→share-place inference in the sig classifier is the foundation of this entire class; retiring it per §3.8 means plain T is owned everywhere and read-only params must be spelled &T — a tree-wide migration. Short of that ruling, the narrow fix is to make the multi-arg share-place path queue field resets exactly like the single-arg path.

  2. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    Session-tail state (intake-clone fix landed as d2efb5a but insufficient — the parallel case still panics; single-workspace case is green):

    • The enriched rt panic now reports: invalid free addr=1611 origin=drop#struct __drop_struct_357. The plan glue is freeing a Vec whose data-pointer slot holds the small integer 1611 — a different field's value (plausibly a str length; the fixture's generated build.w is ~1.2-1.6k chars) sitting where a Vec header should be: an 8-byte-ish writer/reader shift somewhere in the plan value's journey, not heap corruption.
    • ELIMINATED: named-literal field reordering (the constructor's 35-field aggregate is in exact declaration order in MIR); trait-glue duplication (single __drop_struct_357 symbol); allocator races (fully locked); reuse corruption (survives WITH_ALLOC_NO_REUSE=1); the D5 share-place retention chain for source vecs (clones landed, single-workspace case went green).
    • REMAINING SUSPECTS, in order: (1) the thread-job path's raw-pointer arithmetic (jobs.ptr as *mut ComptimeWorkspaceThreadJob) + i — cast-type stride vs the Vec's allocated element stride for the {plan, result} job struct; (2) ce_clone_compile_plan's sret return convention vs one caller's read of it (D6 FnAbi divergence class); note the crash needs TWO workspaces (parallel/threaded path) — the single-plan path (no jobs vec, no threads) is clean, which fits (1).
    • Instrumentation landed for the next session: WITH_TRACE_RESETS (queue/flush/consume/operand/call-arg traces) and the enriched invalid-free panic.

    The D5 share-place classifier brief for Eric is still owed (eff=[read] value_ref_abi=1 on plain params, retention invisible to the effect analysis, multi-arg moved-field calls skip resets where single-arg paths queue them — all documented above).

  3. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    D24 process isolation landed (36fa453) — and it proves the remaining crash is NOT a sharing bug.

    The parallel path now spawns one with __workspace-compile child process per workspace (plan/result cross as serialized files; thread job vector, trampoline, and jobs.ptr + i arithmetic deleted). Verified on stage1: both workspaces compile in separate processes (plan-0/1, result-0/1, stdout/stderr logs present in out/.workspace-parallel/), both artifacts run, --debug-alloc clean on both repros.

    But the release binary still panics — and now with no shared memory anywhere in the path, which localizes it precisely:

    • Same site every time: a guarded drop of a ty357 (compile-plan) local in eval_parallel_workspaces_call — the release disassembly shows rt_value_is_zero → cbnz → __drop_struct_357. The guard is present and passes, i.e. the local's bytes are stale non-zero: the reset-on-move blank never landed, while the value's real owner is the plans vector. Same failure family as const-init lowering misplaces reset-on-move blank: Vec field zeroed before struct build when followed by HashMap move #719 (lost pending resets), not aliasing.
    • stage1 (seed-built) is clean on the identical source; only stage2/release (new-codegen-built) crash. So the defect is in the CURRENT codegen's reset/drop scheduling for this shape, and it is invisible until a binary compiles itself with it.
    • The child processes all succeed (result-0.txt = rc 0 + artifact path); the panic is in the parent after collection.
    • Minimal shapes do NOT reproduce: plans.push(move plan) in a loop over a struct-of-Vecs, then element views at scope exit, is clean under both compilers (push_local_loop.w). The trigger needs more of the real function's control flow (early-return branches, the intercept fallback, the results loop) — narrowing that is the next step, ideally with with reduce against the release binary as predicate.

    Fixes landed en route, all real and all keepers: c146669 (record clones), 6309adf (plan clones), ddb3b16 (borrowed message chain), d2efb5a (Compilation intake clones), 36fa453 (D24 process isolation), 449a248 (invalid-free panic now prints addr+origin).

  4. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    Asm-level localization of the parent-side residue (release binary, post-D24):

    • The blanked, guarded plan slot (sp+0x1810) is handled CORRECTLY: 29 zero-stores cover all 464 bytes right after plans.push, and its exit drop is rt_value_is_zero-guarded. Not the bug.
    • The bug is a second, unguarded inline free cluster emitted per plans-loop iteration, right after the workspace_ids/intercepted pushes: base x20 = sp+0x16e8, five with_vec_free_drop_origin calls at offsets {0x50, 0x70, 0x90, 0xb0, 0x100} with the __drop_struct_357 origin tag. Those offsets match NO contiguous prefix of the plan glue's field offsets ({0x48,0x68,0x98,0xb8,0xd8,0x120,0x140,0x160}) — it looks like a partial/statically-filtered drop of a plan-typed statement temp (most plausibly the sret return temp of workspace_compile_plan) whose cancellation or blanking the CURRENT MirLower loses. Harmless while the slot is blanked (runtime null check), fatal once -O1 slot reuse parks spill data there — which is exactly why the freed "pointer" is a stack address and why only new-codegen-built binaries crash (both binaries' MIR comes from the same current algorithm, but stage1's own body was lowered by the seed's old algorithm).
    • The out-of-line __drop_struct_357 is never called before the panic (breakpoint hit count 0) — the fatal frees are this inline cluster.

    Next session's probe, in order: (1) emit LLVM IR for eval_parallel_workspaces_call from the current compiler and find which MIR statement produces the 5-free cluster (IR is greppable where the asm is not); (2) WITH_TRACE_RESETS on the compiler's own lowering of that statement to see the cancel/queue events for the sret temp; (3) then the fix lands in MirLower's stmt-temp cancellation or partial-drop emission, with a drop-audit cell pinning the shape (sret temp -> move to named local -> loop).

  5. added a commit that references this issue on Aug 17, 2026
  6. ehartford commented on Aug 31, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-08-31: CLOSE (overcome by events). Root cause fixed on main (2920132 branch-created statement temps + fc71ffc validator hole); cli-selfhost-build-w-tests has gated multiple green batteries and reseeds since (last-green at 6684d9c).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions