Repository navigation
@owned on lib.d.ts / core.d.ts: under rc a library call's result is its caller's - #106
Merged
Merged
Conversation
… its caller's lib.ts defines what these files declare, under the program's own memory model, so each function returns a reference its caller owns. Without a word saying so the compiler could classify none of them, every call kept its +1 for good, and one heap-returning declaration was enough to stop any call through a function value or callback from giving its result back: under rc, 1M calls of a `(n) => any` returning a fresh string grew to 97 MB; with `@owned` they stay at 5.6 MB. core/core.os.d.ts stays unmarked: convertNumber, timestamp_to_string and the time_* functions return a pointer into a char[] buffer, not a reference of their own. Needs the compiler's `@owned` (an older compiler ignores the decorator). 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.
Marks the declarations
lib.tsdefines with@owned(lib.d.ts: every top-leveldeclare function,declare classanddeclare namespace;core/core.d.ts: the Error classes), so under-mm=rcthe compiler counts their results as the caller's.Without it, every library declaration was unclassified in OwnedReturnConsumptionPass. A program that used the library never had a closed world, so every call through a function value, callback or
anyleaked its heap result, and so did every direct library call.core/core.os.d.tsstays unmarked.convertNumber,timestamp_to_stringand thetime_*functions return a pointer into achar[]buffer, not a reference of their own.@owned(ASDAlexander77/TypeScriptCompiler, branchrc-owned-declarations). An older compiler ignores the decorator, so merge order doesn't matter.Measured with the compiler PR (
-mm=rc, peak working set):(n) => any/(n) => P.trim()in a loop, 1MThe mixed probe prints the same output under gc and rc. Its remaining growth is inside the library (
toFixedthroughconvertNumber's buffer), a separate leak.Tests:
tests.ps1release (compile + JIT) passes in gc, rc, none and own against the compiler branch.🤖 Generated with Claude Code