Repository navigation
InternPool and AstPool are counted handles: a clone is another holder, the last drop frees (#2449) - #2453
Merged
Conversation
…, the last drop frees (#2449) Both pools were `impl Copy` handles over raw with_alloc blocks with no Drop and no owner: every InternPool.init() leaked a 1 MB arena page and the symbol tables by construction, every AstPool.new() its node tables. The LSP made a pool per reparse (peak RSS grew about half a megabyte per edit: 45 MB after 40 edits, 126 MB after 200), the test runner one per discovered file, Codegen three placeholders per unit. Now the state block carries a holder count. `clone()` is another holder, dropping a handle releases, and the release that finds no other holder drops the tables, the maps and the arena's pages and frees the block. Copy is gone, so the language sees the handle: a function that only reads or interns takes `&InternPool` / `&AstPool` (428 signatures), a type that keeps a handle stores a clone (Parser, Sema, MirBuilder, the evaluators, Codegen, Zcu, the LSP document), and a pass that hands the pool on takes it owned. The parser holds the caller's intern pool as a further holder, so the `x = parser.intern` hand-backs are gone; the backend seams give codegen clones instead of lending and restoring; take_pool/take_intern and the foundation duplicate (src/compiler/foundation/InternPool.w, used by two internals tests, now on the real pool) are removed. AstPool's setters drop `mut`: they write through the state pointer, and `mut` only stopped borrowed callers. The arena leaves 16 bytes at the head of every page: a str whose payload started a page read as an owned allocation to rt_payload_start_is_owned, and its copies retained and released the page. Pins: test/debug_alloc/da_2449_pools_free_on_last_drop.w (holders, clones, a page-sized string, leak count=0; main's pool leaks 283 of 286 blocks on the same program) and the LSP self-host check `lsp-memory-flat`: the new `with/memory` request answers the runtime's committed byte count, and 50 edits may grow it by less than a megabyte (measured 65 KB over 40 edits, 262 KB over 200).
Contributor
Author
|
Battery GREEN on 263d45e under the pinned seed: 333 s wall ( |
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 #2449.
The defect.
InternPoolandAstPoolwereimpl Copyhandles over rawwith_allocblocks with no Drop and no owner. EveryInternPool.init()leaked a 1 MB arena page and its tables by construction, everyAstPool.new()its node tables, and the language could not see it. The LSP made a pool per reparse: peak RSS 45 MB after 40 edits, 126 MB after 200 (about half a megabyte per edit). The test runner made one per discovered file, Codegen three placeholders per unit.The fix. The state block carries a holder count.
clone()is another holder, dropping a handle releases, the last release drops the tables, the maps and the arena pages and frees the block. Copy is gone, so the language sees the handle: a function that only reads or interns takes&InternPool/&AstPool(428 signatures, awith runsweep), a type that keeps a handle stores a clone (Parser, Sema, MirBuilder, the evaluators, Codegen, Zcu, the LSP document), a pass that hands the pool on takes it owned. The parser holds the caller's intern pool as a further holder, so thex = parser.internhand-backs are gone; the backend seams give codegen clones instead of lending and restoring;take_pool/take_internand the foundation duplicatesrc/compiler/foundation/InternPool.w(two internals tests, now on the real pool) are removed. AstPool's setters dropmut(they write through the state pointer;mutonly stopped borrowed callers). The arena leaves 16 bytes at the head of every page: a str whose payload started a page read as an owned allocation tort_payload_start_is_owned, so its copies retained and released the page itself.Ceremony report (the census's
clone-call, granted 537 → 558 inbuild/ceremony-allowances.tsv).pool.clone()at a type that keeps a handle is the explicit second-holder spelling, asRc.cloneis: With has no implicit alias, and today every compiler phase holds the pool. It reads as a meaning (this value outlives the caller's handle), not as something the compiler already knows. What would remove the 21: one pool per compilation with every phase borrowing it, which makes Sema and Codegen view-holding types and restructures the phase hand-offs. The clone count is the honest measure of how far that restructure is.Pins.
test/debug_alloc/da_2449_pools_free_on_last_drop.w: holders, clones, interning through a clone, a page-sized string;leak count=0. The same program against main's pool:leak count=283 allocations=286, the 1 MB page among them.lsp-memory-flatincli-selfhost-lsp-tests: the newwith/memoryrequest answers the runtime's committed byte count; after 50 edits it may have grown by less than a megabyte (measured 65 KB over 40 edits, 262 KB over 200; main's server has no such request and fails the check).Verification (pinned seed, on 263d45e):
:gategreen (231 s);:cli-selfhost-lsp-tests,:drop-audit,:debug-alloc-tests,:deep-debug-tool-tests,:internals-testsgreen on the gate's release compiler; self-host A/B against main 809561f's reseeded compiler,check src/main.w, three interleaved rounds: 0.976, 0.962, 0.973 (median 0.973: the branch is faster). Battery: running, posted when green.Found on the way and filed: #2452 (the build graph cache survives a deleted or added source file).