From 649a397ec67cc324f03e3c8404dcdf15630cd7d7 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Wed, 18 Nov 2026 18:44:51 +0000 Subject: [PATCH] @owned on lib.d.ts and core.d.ts: under rc a library call's result is 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 --- src/core/core.d.ts | 5 +++++ src/lib.d.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/core/core.d.ts b/src/core/core.d.ts index 2abcebe..96054a2 100644 --- a/src/core/core.d.ts +++ b/src/core/core.d.ts @@ -1,3 +1,4 @@ +@owned declare class Error { public message?: string; public filename?: string; @@ -5,18 +6,22 @@ declare class Error { constructor(message?: string, filename?: string, line?: int); } +@owned declare class RangeError extends Error { constructor(message?: string, filename?: string, line?: int); } +@owned declare class TypeError extends Error { constructor(message?: string, filename?: string, line?: int); } +@owned declare class SyntaxError extends Error { constructor(message?: string, filename?: string, line?: int); } +@owned declare class ErrorEvent { public message: string; constructor(message: string); diff --git a/src/lib.d.ts b/src/lib.d.ts index 150da74..3fae85d 100644 --- a/src/lib.d.ts +++ b/src/lib.d.ts @@ -3,19 +3,32 @@ /// /// +// @owned: lib.ts defines what this file declares, compiled under the program's own memory model, so +// under -mm=rc each function here returns a reference its caller owns, as an imported function does. +// Without it the compiler can say nothing of these results: every call kept its +1 for good, and one +// declaration with a heap result was enough to stop any call through a function value from giving +// its result back. Never on a C function, nor on one that returns a pointer into a buffer +// (core/core.os.d.ts's convertNumber, timestamp_to_string, ...). + +@owned declare function parseInt(val: string, radix?: int): int; +@owned declare function parseFloat(val: string): number; +@owned declare function isNaN(val: number): boolean; +@owned declare function isFinite(val: number): boolean; +@owned declare namespace __Boolean { function toString(this: boolean): string; } @final +@owned declare class Boolean { private value: boolean; @@ -26,6 +39,7 @@ declare class Boolean { valueOf(): boolean; } +@owned declare namespace __Number { function toExponential(this: number, fractionDigits?: int): string; @@ -38,6 +52,7 @@ declare namespace __Number { } @final +@owned declare class Number { static EPSILON: number; @@ -96,6 +111,7 @@ declare class Number { valueOf(): number; } +@owned declare namespace __BigInt { function toLocaleString(this: bigint, locale?: string): string; @@ -104,6 +120,7 @@ declare namespace __BigInt { } @final +@owned declare class BigInt { private value: bigint; @@ -117,6 +134,7 @@ declare class BigInt { } @final +@owned declare class Date { private timestamp: time_t; @@ -222,6 +240,7 @@ declare class Date { } @final +@owned declare class MatchIndicesResults { private match: Opaque; @@ -238,6 +257,7 @@ declare class MatchIndicesResults } @final +@owned declare class MatchResults { private match: Opaque; @@ -258,6 +278,7 @@ declare class MatchResults } @final +@owned declare class RegExp { dotAll: boolean; @@ -294,6 +315,7 @@ declare class RegExp { [Symbol.dispose](): void; } +@owned declare namespace __String { function at(this: string, index: int): string; @@ -368,6 +390,7 @@ declare namespace __String { } @final +@owned declare class String { private value: string; @@ -453,6 +476,7 @@ declare class String { //[Symbol.iterator](): ClassIterator; } +@owned declare namespace Math { /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ const E = 2.718281828459045; @@ -659,6 +683,7 @@ declare namespace Math { } @final +@owned declare class Headers { private names: string[]; private values: string[]; @@ -681,6 +706,7 @@ declare class Headers { } @final +@owned declare class Response { status: int; headers: Headers; @@ -697,6 +723,7 @@ declare class Response { } @final +@owned declare class JsonValue { private tag: int; private flag: boolean; @@ -739,12 +766,15 @@ declare class JsonValue { toJSON(): string; } +@owned declare namespace JSON { function parse(text: string): JsonValue; } +@owned declare function fetch(url: string, init?: { method?: string, headers?: [string, string][], body?: string }): Response; +@owned declare namespace console { function readLine(): string | null;