Skip to content

One InternPool and one AstPool per compilation: phases borrow &InternPool/&AstPool, the pool .clone() sites (#2449's allowance) go away #2523

Done

Description

@ehartford

#2449 (closed) made InternPool and AstPool counted handles: since then a type that keeps a pool stores pool.clone(), the explicit second-holder spelling. build/ceremony-allowances.tsv grants these under clone-call src (bar 537 → ceiling 558) with the note that "the single-owner restructure (one pool per compilation, every phase borrowing it) removes them". Fix shape step 1 of #2449 — one owner per compilation, everyone else borrows &InternPool / &AstPool — has no open issue. This is that issue.

Where the clones are (38 pool/intern-named .clone() sites in src/, rough lexical count):

file sites
src/compiler/Backend.w 8
src/compiler/Compilation.w 6
src/compiler/Zcu.w 5
src/Lsp.w, src/Parser.w 2 each
src/CCodegen.w, Frontend.w, ComptimeTransform.w, MirLower.w, Parse.w, ComptimeEval.w, Codegen.w, AsyncLower.w, Sema.w, Resolve.w 1 each

Representative: Zcu { pool: pool.clone(), frontend_pool: pool, … } (src/compiler/Zcu.w:149), self.pool = sema.pool.clone() (Zcu.w:533), return pool.clone() (Compilation.w:1093,1097), and emit_intern = … last_sema.pool.clone() else: self.zcu.pool.clone() (Compilation.w:1766). Several of these exist because Zcu holds two or three pools (pool, frontend_pool, typed_pool_cache) that are swapped as phases hand the pool along.

Fix

  1. One InternPool and one AstPool per compilation, owned by Compilation/Zcu (and by the LSP document for with lsp).
  2. Parser, Sema, MirLower, Codegen, the backends and the analyze tools take &InternPool / &AstPool and do not store a handle; a phase that needs the pool for its lifetime borrows it from the owner instead of holding a count.
  3. The pool swaps in Zcu (set_pool, set_frontend_pool, sync_from_sema, typed_pool_cache) are replaced by one pool that the phases mutate in turn, or the case for keeping two distinct pools is written down.
  4. The clone-call src allowance line for InternPool and AstPool are Copy handles over raw allocations that nothing frees: every init leaks (the LSP leaks 1 MB per reparse) #2449 is removed and the bar falls by the clones removed.

Done when: no InternPool/AstPool .clone() remains in src/ outside a site that genuinely needs an independent second holder (each named in a comment), the allowance is gone, with lsp's RSS stays flat over repeated reparses (#2449's pin), and the drop audit is unchanged.

Related: #2449, D111/D120 (a counted handle is the explicit second-holder form), #2519 (the census section that lists these as intentional until this lands).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced: not started. build/ceremony-allowances.tsv still grants clone-call src 537 → 558 for the pool clones, with the note that "the single-owner restructure (one pool per compilation, every phase borrowing it) removes them".

    post-release: a compiler-wide ownership refactor.

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
  3. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Step 1 merged (#3605): Zcu holds one intern pool. Its third holder (frontend_pool, read by nothing) and set_pool (no callers) are gone, and the two swaps that took a pool back from Sema now only require it is the same pool. That requirement never fires in the stage chain or the battery, so the swaps were no-ops: every phase already interns into the compilation's pool.

    Left, in the order I would take it:

    1. Zcu.typed_pool_cache and Compilation.active_pool: the same question for the AST pool (it already has require_same_storage).
    2. The backends' if sema has symbols: sema.pool.clone() else: self.pool.clone() choices (Backend.with, 8 sites): with one pool these are one expression.
    3. The fields that keep a handle for a phase's lifetime (Parser, Resolve, Sema, MirLower, Codegen, CCodegen, AsyncLower, ComptimeEval): the borrow half of the issue.
    4. Then the InternPool and AstPool are Copy handles over raw allocations that nothing frees: every init leaks (the LSP leaks 1 MB per reparse) #2449 allowance line and its bar.
  4. ehartford commented on Nov 25, 2026

    @ehartford
    ContributorAuthor

    Steps 2 and 3 merged (#3606, #3607). The backends' eight either-pool choices are two helpers that return the compilation's own pools, and active_pool is a check. Each replaced swap or choice was guarded by a same-storage requirement that never fired in the stage chain or the battery, so there is one intern pool and one tree per compilation in fact; what remains is spelling it that way.

    Clone sites named pool/ast/intern/tree in src/: 39 → 27.

    Left: the fields that keep a handle for a phase's lifetime (Parser, Resolve, Sema, MirLower, Codegen, CCodegen, AsyncLower, ComptimeEval, Lsp), which is the borrow half of the issue, and then the #2449 allowance line and its bar.

  5. added a commit that references this issue on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions