Repository navigation
rc: a temporary is released right after its last use (rc compile ~27 min -> 10.6 s) - #977
Merged
Merged
Conversation
…of its block Under -mm=rc OwnedReturnConsumptionPass gave a discarded temporary back where its stretch of the block ends, so every temporary was live across every call after it: each call that may throw got a cleanup pad giving back all of them (UnwindReleasePass), quadratic code - binaryArithmeticControlFlowGraphNotTooLarge (1300 lines of `any` arithmetic) took ~27 min to compile under rc, 860 s of it in LLVM's optimizer. - lastUseInBlock: the op of the block holding the last use of the value under any of its names (what users make of it unless it comes with a reference of its own, what a conditional hands on, loads of a local it is stored into); none when a use can't be followed, and the release stays where it was. The release goes right after that op; nested exits after it owe nothing. rc only: own's passes read where releases are. - UnwindReleasePass: a value whose release dominates the call is given back already and owes nothing (the walk on from the call for its release went to the end of the function, and in a loop found the next turn's); a resource's aliases and a release's hand-over test are answered once. rc compile of that file: ~27 min -> 10.5 s; n=200 synthetic: 13.7 s -> 1.6 s, cleanup releases linear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he releases in front of a yield - A `const` holding the value itself (OWNED_RESULT_NAMED) is a local: given back where its scope ends, as an object let go of earlier is seen (Shared.count, a WeakRef's deref) - stack-promotion/shared_handle. - A view (an interface made of an object literal's copy) is the block it shows: the first `use(<I>o)` gave it back and the literal's block, born with no count, was freed before the second (own_interface_literal_views under rc hung at exit). A view's users are followed as the value's (NewInterface is marked owned). - generator-temporaries.cmake counts the releases in front of each yield instead of reading the ops right before it; own-mlirgen-matches-rc compares with the releases left out (their places are each model's). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(gc #976, rc release at last use) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follow-up to #976 (TSLANG 154). Under -mm=rc,
binaryArithmeticControlFlowGraphNotTooLarge(1300 lines ofanyarithmetic in one function) took ~27 min to compile; it now takes 10.6 s.Cause. Under rc,
OwnedReturnConsumptionPassreleased a discarded temporary at the end of its stretch of the block. Every temporary therefore stayed live across every call after it. Each call that may throw got a cleanup pad (UnwindReleasePass) that released all of them, so the code grew quadratically. Doubling the function multiplied the cleanup releases by about 4.UnwindReleasePasstook ~8–11 min and LLVM's optimizer ~14 min.Fix (rc only, because own's passes read where the releases are).
Placement. A temporary is released right after the op of its block that uses it last (
lastUseInBlock). The value's other names count as uses:If a use can't be followed (a store anywhere else, a terminator handing it on), the release stays where it was. Nested exits after the last use no longer release it.
Exceptions. Two cases keep the old placement:
const(__owned_result_named) is a local; releasing it earlier would be visible throughShared.countor aWeakRef(stack-promotion/shared_handle);own_interface_literal_viewsunder rc).Unwind pass.
UnwindReleasePassskips a value whose release dominates the call: it was released before the call, so the call owes nothing for it. A resource's aliases and a release's hand-over test are each computed once.Cleanup releases now grow linearly (528 → 878 → 1578 for 25/50/100 lines, against 7.5k → 26k → 97k before).
Tests updated.
generator-temporaries.cmakecounts the releases in front of each yield instead of reading the ops just before it.own-mlirgen-matches-rc.cmakecompares the two models with release lines left out, since where releases go is now each model's own.Verified locally.
mm_fuzz.py run: 551 programs, 0 failures.mm_fuzz.py leaks: 80 programs, no leaks.🤖 Generated with Claude Code