Skip to content

fix(javascript): retain returned-reference mutation uncertainty - #1471

Merged
N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-returned-reference-aliases
Oct 10, 2026
Merged

N0zoM1z0 merged 1 commit into
mainfrom
fix/javascript-returned-reference-aliases

Conversation

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Fixes #1449. Local calls can hand back the same object, but mutation tracking stopped at their results and advertised stale literals after a subsequent write. Resolve candidate return/yield references through the existing escape tracking, sharing the direct-result AST collector with return projection.

The compiled CLI and real stdio MCP regression covers 34 variants: direct and captured calls, property-slot stores, object/class methods, aliases, constructors, recursive wrappers, awaited async results and yielded references. Scalar copies, unrelated containing properties and uninvoked nested callables retain their facts. This is conservative escape analysis: even read-only calls handing back references may become unknown; it does not claim execution or exact post-call values. No schemas, tool inventory or provider behavior change.

Validation: baseline CLI fails with stale 1; fixed public CLI/MCP regression passes, including output-contract validation, Evidence identity, text/structured results, subsequent ping and shutdown. The existing property-store/iteration CLI/MCP journeys also pass; six adjacent source suites pass 353 tests; npm run check:ci and test discovery pass. Controlled fixture execution and public MCP checks pass on Node 22.22.2 and 24.18.0. Real Hopper/Ghidra verification was not performed because this changes pure JavaScript semantics.

Related: #1468 independently addresses simple synchronous thunks. This change also covers the property-slot flow explicitly left open there and method/async/generator forms, using iterative AST traversal and the shared return collector.

@N0zoM1z0 N0zoM1z0 left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final-head review complete for 8414ee4. All CI lanes, including real JavaScript recovery and all native package baselines, are green. The 34-case compiled CLI/stdio MCP regression and Node 22/24 runtime checks preserve scalar copies and unrelated fields while removing stale returned-reference facts. Conservative read-only escape uncertainty is documented. No remaining blocking findings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: #1471 fixes 11 of the 13 call forms that #1468 left wrong, and 24 of 28 new ones. Its tests and check:fast pass on Node 22, 24 and 26. Getters still give the stale literal 1, and one shape got much slower: many methods that return the same object.

Head 8414ee49 against main 4e3d3354. Each case returns shared.x from an exported result(), checked against real JS.

Case set Wrong on main Wrong on #1471 Right answer lost
64 cases from #1449 29 2 6 of 19 controls
90 new forms 28 4 10
197 older cases (#1442 to #1444) 9 2 0

The 2 left in the #1449 set are the cross-module rows. Real JS gives 2 there only when b.js loads first. The 2 left in the older set are one loop shape that this PR does not touch.

Still wrong: getters

const shared = { x: 1 };
const box = { get v() { return shared; } };
box.v.x = 2;
return shared.x; // real 2; main and #1471 say literal 1, coverage complete

A class getter, a static getter and a getter copied into a local first fail the same way. A getter read is not a call, so the new hook never sees it.

Slower: many methods on one object

An object with N methods that all return it, then N calls like box.m1().p1 = 1. Analysis time on Node 24, median of 3:

N main #1471
250 94 ms 201 ms
1,000 341 ms 1,868 ms
2,000 826 ms 7,048 ms
4,000 2,601 ms 30,366 ms

Each doubling costs about 4 times as much at the top. I reran N = 2,000 once and got 0.84 s and 7.9 s. The box was busy for all of these runs. So read them as rough, but the gap is far larger than the noise. Plain get() calls, captured calls and a 200-wrapper chain stay within 16% of main. The Hermes Desktop (MIT) vendor chunk shows no cost.

Precision

Read-only calls now give unknown, as the PR body says they may. For example, get(); return shared.x; was a right literal 1 on main. A write to shared.x also hides an unwritten sibling like shared.y. On the Hermes chunk, 5 values go from a known object to unknown.

Not run

  • MCP for the 90 new forms and the 197 older cases. The 64 cases ran through MCP on Node 24 only.
  • The six suites with 353 tests from the PR body, since they are not named. All 38 files in src/domain/javascript pass.
  • check:ci.
  • Speed on an idle machine. The load average stayed between 5 and 10 the whole time. It counts programs running or waiting for one of the 24 CPU threads.
  • The cause of the slowdown.
  • Windows and macOS.

Thanks, N0zoM1z0, for taking on the method, async and generator forms. The 34-variant test made the cases easy to match.

The 64 cases from #1449

Re-run of the 64 cases from #1449 on #1471

Real JS returns 2 for every row in this table. (The last row needs b.js to load first.) The 19 controls, where 1 is right, come after it.

Call shape main #1468 #1471
get().x = 2, with an arrow, function or function expression literal 1 unknown unknown
const t = get(); t.x = 2 literal 1 unknown unknown
(() => shared)().x = 2 literal 1 unknown unknown
o.a = get(); o.a.x = 2, plain or IIFE literal 1 unknown unknown
get().x += 1, Object.assign(get(), …) literal 1 unknown unknown
() => o.inner, () => o.a.b, () => arr[0] literal 1 unknown unknown
Two returns, let get reassigned, top-level call literal 1 unknown unknown
box.get().x = 2, plain or through o.a literal 1 literal 1 unknown
new B().get().x = 2 literal 1 literal 1 unknown
const get2 = () => get(); get2().x = 2 literal 1 literal 1 unknown
() => (f ? shared : other) literal 1 literal 1 unknown
(() => shared).bind(null) literal 1 literal 1 unknown
(await get()).x = 2, await get().then(…) literal 1 literal 1 unknown
g().next().value.x = 2, spread, for…of literal 1 literal 1 unknown
id(shared).x = 2, pick(o).y = 2, Object(shared), this.x unknown unknown unknown
a.js holds result() and b.js writes: get().x = 2 or shared.x = 2 literal 1 literal 1 literal 1

Result: #1471 fixes 11 of the 13 rows that #1468 left wrong. All 11 return a reference. They are methods, a class method, a call chain, a conditional return, .bind, await and generators. The 2 still wrong are the cross-module rows, where b.js writes and a.js holds result(). They are wrong on main and #1468 too. Real JS gives 2 there only when b.js loads first. With a.js alone it gives 1.

Controls: 19 forms where 1 is right. On main, 17 keep literal 1. On #1468, 16 do. On #1471, 11 do. Six controls move from literal 1 to unknown on #1471 compared with main:

Those six moves are safe, but less precise. The PR body says read-only calls may become unknown. Two more controls use an imported value. They give unknown on main, #1468 and #1471.

Agreement: the CLI gives the same answer on Node 22.23.1, 24.18.0 and 26.11.1 for all 64 cases. The MCP server (analyze_javascript_application, Node 24) matches the Node 24 CLI on all 64. Main 4e3d3354, rebuilt and rerun on Node 24, matches my earlier main run on all 64. Every return shape in the CLI and MCP output reports return_shape_coverage complete.

Full matrix (64 cases, #1471)

Each case is export function result() in app.js, unless files are named. In the cross-module rows, real JS loaded b.js before calling result(). Code drops the const shared = { x: 1 } line and the final return shared.x. Main is 4e3d3354; #1468 is 9c559f3e; #1471 is 8414ee49. CLI on Node 22 shown. For #1471, Node 24, Node 26 and MCP each gave the same answer as Node 22 on every row.

Form Real JS main #1468 #1471 #1471 verdict
const get = () => shared; get().x = 2; 2 literal 1 unknown unknown honest unknown
const get = () => shared; const t = get(); t.x = 2; 2 literal 1 unknown unknown honest unknown
function get() { return shared; } const o = {}; o.a = get(); o.a.x = 2; 2 literal 1 unknown unknown honest unknown
const o = {}; o.a = (() => shared)(); o.a.x = 2; 2 literal 1 unknown unknown honest unknown
const box = { get() { return shared; } }; const o = {}; o.a = box.get(); o.a.x = 2; 2 literal 1 literal 1 unknown honest unknown
const o = {}; o.a = Object(shared); o.a.x = 2; 2 unknown unknown unknown honest unknown
function get() { return shared; } get().x = 2; 2 literal 1 unknown unknown honest unknown
const get = function () { return shared; }; get().x = 2; 2 literal 1 unknown unknown honest unknown
(() => shared)().x = 2; 2 literal 1 unknown unknown honest unknown
const box = { get() { return shared; } }; box.get().x = 2; 2 literal 1 literal 1 unknown honest unknown
class B { get() { return shared; } } new B().get().x = 2; 2 literal 1 literal 1 unknown honest unknown
const id = (v) => v; id(shared).x = 2; 2 unknown unknown unknown honest unknown
const o = { inner: { y: 1 } }; const pick = (p) => p.inner; pick(o).y = 2; return o.inner.y; 2 unknown unknown unknown honest unknown
const get = () => shared; const get2 = () => get(); get2().x = 2; 2 literal 1 literal 1 unknown honest unknown
const other = { x: 1 }; const f = true; const get = () => (f ? shared : other); get().x = 2; 2 literal 1 literal 1 unknown honest unknown
const other = { x: 1 }; const get = (f) => { if (f) return shared; return other; }; get(true).x = 2; 2 literal 1 unknown unknown honest unknown
const other = { x: 1 }; let get = () => other; get = () => shared; get().x = 2; 2 literal 1 unknown unknown honest unknown
const get = () => shared; get().x += 1; 2 literal 1 unknown unknown honest unknown
const get = (() => shared).bind(null); get().x = 2; 2 literal 1 literal 1 unknown honest unknown
const get = () => shared; Object.assign(get(), { x: 2 }); 2 literal 1 unknown unknown honest unknown
const o = { inner: { y: 1 } }; const get = () => o.inner; get().y = 2; return o.inner.y; 2 literal 1 unknown unknown honest unknown
const shared = { y: 1 }; const o = { inner: shared }; const get = () => o.inner; get().y = 2; return shared.y; 2 literal 1 unknown unknown honest unknown
const o = { a: { b: { z: 1 } } }; const get = () => o.a.b; get().z = 2; return o.a.b.z; 2 literal 1 unknown unknown honest unknown
const arr = [{ x: 1 }]; const get = () => arr[0]; get().x = 2; return arr[0].x; 2 literal 1 unknown unknown honest unknown
const o = { x: { y: 1 }, get() { return this.x; } }; o.get().y = 2; return o.x.y; 2 unknown unknown unknown honest unknown
async result: async function get() { return shared; } (await get()).x = 2; 2 literal 1 literal 1 unknown honest unknown
async result: async function get() { return shared; } await get().then((t) => { t.x = 2; }); 2 literal 1 literal 1 unknown honest unknown
function* g() { yield shared; } g().next().value.x = 2; 2 literal 1 literal 1 unknown honest unknown
function* g() { yield shared; } [...g()][0].x = 2; 2 literal 1 literal 1 unknown honest unknown
function* g() { yield shared; } for (const t of g()) t.x = 2; 2 literal 1 literal 1 unknown honest unknown
a.js exports shared, get = () => shared / b.js result: get().x = 2; return shared.x 2 unknown unknown unknown honest unknown
a.js exports shared, get / b.js top level: get().x = 2; result returns shared.x 2 unknown unknown unknown honest unknown
a.js exports shared, get, result returns shared.x / b.js top level: get().x = 2 2 literal 1 literal 1 literal 1 WRONG
a.js exports shared, get / mid.js: export { shared, get } from './a.js' / b.js imports mid.js, result: get().x = 2; return shared.x 2 unknown unknown unknown honest unknown
a.js exports shared, get / mid.js: export * from './a.js' / b.js imports mid.js, result: get().x = 2; return shared.x 2 unknown unknown unknown honest unknown
CJS: a.js module.exports = { shared, get } / b.js result: get().x = 2; return shared.x 2 no shape no shape no shape not reached
CJS: a.js exports shared, get, result / b.js: require('./a.js').get().x = 2 2 no shape no shape no shape not reached
CJS: mid.js: module.exports = require('./a.js') / b.js requires mid.js, result: get().x = 2; return shared.x 2 no shape no shape no shape not reached
module-level shared, get; result returns shared.x; top level: get().x = 2 2 literal 1 unknown unknown honest unknown
shared.x = 2; 2 unknown unknown unknown honest unknown
const o = { inner: { y: 1 } }; o.inner.y = 2; return o.inner.y; 2 unknown unknown unknown honest unknown
a.js exports shared / b.js result: shared.x = 2; return shared.x 2 unknown unknown unknown honest unknown
CJS: a.js exports shared / b.js result: shared.x = 2; return shared.x 2 no shape no shape no shape not reached
a.js exports shared, result returns shared.x / b.js top level: shared.x = 2 2 literal 1 literal 1 literal 1 WRONG
module-level shared; result returns shared.x; top level: shared.x = 2 2 unknown unknown unknown honest unknown
const get = () => ({ x: 1 }); get().x = 2; 1 literal 1 literal 1 literal 1 correct
const get = () => ({ ...shared }); get().x = 2; 1 literal 1 literal 1 literal 1 correct
const get = () => shared.x; let v = get(); v = 2; 1 literal 1 literal 1 literal 1 correct
const get = () => shared; const t = get(); const y = t.x; 1 literal 1 literal 1 unknown lost precision
const get = () => shared; get().y = 2; 1 literal 1 literal 1 unknown lost precision
const other = { x: 1 }; const get = () => other; get().x = 2; 1 literal 1 literal 1 literal 1 correct
const o = { inner: { y: 1 }, other: { y: 1 } }; const get = () => o.other; get().y = 2; return o.inner.y; 1 literal 1 literal 1 literal 1 correct
function* g() { yield { x: 1 }; } g().next().value.x = 2; 1 literal 1 literal 1 literal 1 correct
async result: async function get() { return { x: 1 }; } (await get()).x = 2; 1 literal 1 literal 1 literal 1 correct
async function get() { return shared; } get().then((t) => { t.x = 2; }); 1 literal 1 literal 1 unknown lost precision
a.js exports shared, make = () => ({ x: 1 }) / b.js result: make().x = 2; return shared.x 1 unknown unknown unknown lost precision
a.js exports shared / b.js result: return shared.x (no write anywhere) 1 unknown unknown unknown lost precision
a.js exports shared, get, result returns shared.x / b.js: export const y = get().x 1 literal 1 literal 1 literal 1 correct
const shared = { x: 1, inner: { y: 1 } }; const get = () => shared.inner; get().y = 2; 1 literal 1 literal 1 literal 1 correct
const make = (v) => ({ x: v }); make(1).x = 2; 1 literal 1 literal 1 literal 1 correct
(() => ({ x: 1 }))().x = 2; 1 literal 1 literal 1 literal 1 correct
const get = async () => shared; get().x = 2; 1 literal 1 literal 1 unknown lost precision
function* g() { yield shared; } g().x = 2; 1 literal 1 literal 1 unknown lost precision
const other = { x: 1 }; let get = () => shared; get = () => other; get().x = 2; 1 literal 1 unknown unknown lost precision
Commands
  • Build: git archive of 8414ee49 and 4e3d3354, then npm ci and npm run build on Node 24.
  • CLI: rea analyze-javascript-application <dir> --artifact-format directory --json, once per case and Node.
  • MCP: one stdio server (rea mcp) on Node 24, calling analyze_javascript_application for each case.
Tests and speed detail

Tests

Head is 8414ee49. Base is 4e3d3354.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
New acceptance test on head (1 test, 34 variants, CLI and MCP) pass pass pass
Same test file on base 4e3d3354 fail fail fail
All src/domain/javascript suites on head (38 files, 723 tests) pass pass pass
Same suites on base not run pass (723 tests) not run
npm run check:fast on head (0 errors, 502 lint warnings) pass pass pass
npm run verify:test-discovery (712 test files found once each) pass pass pass

On base, the test fails at the first variant, direct, on all three Nodes. It says direct: expected 1 to be 2. That is the stale 1 the PR describes.

I also ran a copy of the test that keeps going after a failure, on Node 24 only. On base, 27 of the 34 variants fail with the same stale 1. These are the 26 write variants plus the directSibling write. They fail in all three results: CLI JSON, MCP structured content and MCP text. The other 7 variants pass on base: primitive, copy, methodCopy, arrayCopy, unused, nestedCallable and unrelated. These are the cases that must keep their facts. The fix does not change them.

The base lint run has 498 warnings. Head adds 4, all in the new file javascriptSemanticReturnedReferences.ts: complexity 43 and a nesting depth of 5, plus two functions of 142 and 151 lines. These are warnings, not errors.

The PR says six adjacent suites pass 353 tests. It does not name them. I did not reproduce that exact set. All 38 files in src/domain/javascript pass, and that includes the likely ones.

Speed

Node 24.18.0. Each cell is the median of 3 runs of the analysis step, in milliseconds. The base tree is 4e3d3354. Every run started with a high load (see the note below), so all numbers are rough. The analysis result and its output hash matched on both trees for one and reads. Hermes differs, as noted below. Every run exited with code 0.

Case Base, set 1 #1471, set 1 Base, set 2 #1471, set 2
one, 1,000 writes 116 116 125 118
one, 4,000 writes 322 271 310 317
reads, 4,000 writes 577 537 512 521
Hermes Desktop (MIT) vendor-react-C4pS_tun.js 1,812 1,488 1,493 1,433

Set 1 started at load 5.5 to 6.7. Set 2 started at load 9.3 to 10.4. Load average counts the processes that are running or waiting. This CPU has 24 threads. Other tests were running on the box. The gap between trees changes sign from set 1 to set 2: for one at 4,000 it is minus 51 ms, then plus 6 ms. For reads it is minus 39 ms, then plus 9 ms. Hermes on base ranges from 1,394 to 1,850 ms in set 1, wider than the gap to #1471. So I see no cost on these four cases. Use either set.

On the Hermes chunk, the output differs from base in 5 values. Each was an object with known properties on base. On #1471 each is unknown. The stated reason is that the reference may have been changed by a call. That is the conservative effect the PR describes. I read all 25 field differences in the full output.

One extra case is slower. It is an object with N methods, each returning the same object, then N calls like box.m1().p1 = 1. On #1471 the cost grows roughly with the square of N. Median analysis time in milliseconds, with the ratio in brackets:

Methods and calls Base #1471
250 94 201 (2.1x)
500 159 571 (3.6x)
1,000 341 1,868 (5.5x)
2,000 826 7,048 (8.5x)
4,000 2,601 30,366 (11.7x)

The 250, 500, 2,000 and 4,000 rows ran at load 6.0 to 7.5. The 1,000 row ran at load 7.9 to 8.4. Base also grows faster than linear. I did not look for the cause in the source. Three other extra cases cost within 16 percent of base. They were 1,000 calls like get().p1 = 1, 1,000 captured calls like t1 = get(), and a chain of 200 wrappers. In these cases #1471 reports shared.token as unknown where base reports the literal "TOKEN". No write in these sources touches token.

The 90 new forms and the 197 older cases

New probe forms and precision cost

I tested 90 new forms and re-ran the 197 older soundness cases. Both trees are main 4e3d3354 and PR head 8414ee49. Each form has its own case folder, a real-JavaScript answer from Node, and the REA CLI answer for result on each tree. Real JavaScript on Node 22.23.1, 24.18.0 and 26.11.1 agreed on all 89 forms that run. For the new forms, the REA CLI gave the same answer on all three Node versions for both trees.

New probes

Of the 90 forms, 89 run in real JavaScript. The 90th is get?.().x = 2 as typed, which is a SyntaxError in Node, so REA finds no parse result on either tree. Parenthesized as (get?.()).x = 2, it runs.

On main, 28 of the 89 give a stale literal 1. On #1471, 24 of those 28 become unknown. The other 4 stay wrong. All 4 read a getter as a property: box.v.x = 2, a class getter, a getter copied into a local first, and a static getter. Two other getter reads do change to unknown: one stored through a slot (o.a = box.v), and one made with Object.defineProperty.

The prefix const shared = { x: 1 }; is cut from each row. Rows that need a different shared show it in full. The word async: means result is an async function.

Form Real JS main 4e3d3354 #1471 8414ee49
const get = () => shared; get?.().x = 2; return shared.x; SyntaxError no result (parse error) no result (parse error)
const get = () => shared; (get?.()).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get.call(null).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get.apply(null).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; Reflect.apply(get, null, []).x = 2; return shared.x; 2 literal 1, wrong unknown
async: async function* g() { yield shared; } for await (const t of g()) t.x = 2; return shared.x; 2 literal 1, wrong unknown
async: const get = () => shared; (await Promise.all([get()]))[0].x = 2; return shared.x; 2 literal 1, wrong unknown
const shared = { inner: { y: 1 } }; const get = () => shared; const { inner } = get(); inner.y = 2; return shared.inner.y; 2 literal 1, wrong unknown
const box = { get v() { return shared; } }; box.v.x = 2; return shared.x; 2 literal 1, wrong literal 1, wrong
const make = () => () => shared; make()().x = 2; return shared.x; 2 literal 1, wrong unknown
function C() { return shared; } new C().x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; [get()].map((t) => { t.x = 2; }); return shared.x; 2 literal 1, wrong unknown
const get = () => [shared]; get()[0].x = 2; return shared.x; 2 literal 1, wrong unknown
function get(n) { return n ? get(n - 1) : shared; } get(3).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get(); return shared.x; 1 literal 1, right unknown

Controls for each family hand back a fresh object or a shallow copy. 39 of the 40 keep literal 1 on both trees. The 40th is the destructuring copy. A shallow copy shares the inner object, so real JavaScript gives 2. Main says literal 1, which is wrong. #1471 says unknown.

Read-only calls do lose precision, as the PR body says they may. The control get(); return shared.x; has real answer 1. Main says literal 1. #1471 says unknown. In total 10 of the 89 forms go from right to unknown on #1471, and none go the other way:

  • get();, const t = get();, const v = get().x;
  • new C() with a constructor that returns shared, get.call(null);
  • [get()].map((t) => t.x);, a recursive get(3);
  • get().x = 2; return shared.y;, which reads a sibling property of the same object
  • an uninvoked const f = () => get().x;
  • an uninvoked const f = () => { get().x = 2; };

These forms keep their right answer on both trees:

  • a read of a different object
  • a property of a container that holds shared
  • a function that returns a scalar
  • a returning function that only defines an inner callable
  • a getter read with no write (box.v;)

The PR's new hook sits in the branch for calls and new. I read that in javascriptSemanticMemberMutations.ts and did not test it another way. A plain getter read is not a call.

All 90 new forms (main and #1471, Node 24; Node 22 and 26 gave the same cells)
Form Real JS main 4e3d3354 #1471 8414ee49
const get = () => shared; get?.().x = 2; return shared.x; SyntaxError no result (parse error) no result (parse error)
const get = () => shared; (get?.()).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get.call(null).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get.apply(null).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; Reflect.apply(get, null, []).x = 2; return shared.x; 2 literal 1, wrong unknown
async: async function* g() { yield shared; } for await (const t of g()) t.x = 2; return shared.x; 2 literal 1, wrong unknown
async: const get = () => shared; (await Promise.all([get()]))[0].x = 2; return shared.x; 2 literal 1, wrong unknown
const shared = { inner: { y: 1 } }; const get = () => shared; const { inner } = get(); inner.y = 2; return shared.inner.y; 2 literal 1, wrong unknown
const box = { get v() { return shared; } }; box.v.x = 2; return shared.x; 2 literal 1, wrong literal 1, wrong
const make = () => () => shared; make()().x = 2; return shared.x; 2 literal 1, wrong unknown
function C() { return shared; } new C().x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; [get()].map((t) => { t.x = 2; }); return shared.x; 2 literal 1, wrong unknown
const get = () => [shared]; get()[0].x = 2; return shared.x; 2 literal 1, wrong unknown
function get(n) { return n ? get(n - 1) : shared; } get(3).x = 2; return shared.x; 2 literal 1, wrong unknown
const get = () => shared; get(); return shared.x; 1 literal 1, right unknown

| const get = () => ({ x: 1 }); (get?.()).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); (get?.()).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => shared; const t = get?.(); t.x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| const get = () => ({ x: 1 }); const t = get?.(); t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); const t = get?.(); t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ x: 1 }); get.call(null).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); get.call(null).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ x: 1 }); get.apply(null).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); get.apply(null).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ x: 1 }); Reflect.apply(get, null, []).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); Reflect.apply(get, null, []).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: async function* g() { yield ({ x: 1 }); } for await (const t of g()) t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: async function* g() { yield ({ ...shared }); } for await (const t of g()) t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: const get = () => ({ x: 1 }); (await Promise.all([get()]))[0].x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: const get = () => ({ ...shared }); (await Promise.all([get()]))[0].x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: const get = () => shared; (await Promise.resolve(get())).x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| async: const get = () => ({ x: 1 }); (await Promise.resolve(get())).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| async: const get = () => ({ ...shared }); (await Promise.resolve(get())).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const box = { get v() { return ({ x: 1 }); } }; box.v.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const box = { get v() { return ({ ...shared }); } }; box.v.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| class B { get v() { return shared; } } new B().v.x = 2; return shared.x; | 2 | literal 1, wrong | literal 1, wrong |
| class B { get v() { return ({ x: 1 }); } } new B().v.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| class B { get v() { return ({ ...shared }); } } new B().v.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const make = () => () => ({ x: 1 }); make()().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const make = () => () => ({ ...shared }); make()().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function C() { return ({ x: 1 }); } new C().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function C() { return ({ ...shared }); } new C().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ x: 1 }); [get()].map((t) => { t.x = 2; }); return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); [get()].map((t) => { t.x = 2; }); return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => [({ x: 1 })]; get()[0].x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => [({ ...shared })]; get()[0].x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function get(n) { return n ? get(n - 1) : ({ x: 1 }); } get(3).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function get(n) { return n ? get(n - 1) : ({ ...shared }); } get(3).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function* g() { yield* [shared]; } for (const t of g()) t.x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| function* g() { yield* [({ x: 1 })]; } for (const t of g()) t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| function* g() { yield* [({ ...shared })]; } for (const t of g()) t.x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| let cur = shared; const get = () => cur; get().x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| let cur = ({ x: 1 }); const get = () => cur; get().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| let cur = ({ ...shared }); const get = () => cur; get().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => shared; function f() { get().x = 2; } f(); return shared.x; | 2 | literal 1, wrong | unknown |
| const get = () => ({ x: 1 }); function f() { get().x = 2; } f(); return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => ({ ...shared }); function f() { get().x = 2; } f(); return shared.x; | 1 | literal 1, right | literal 1, right |
| const run = (f) => f(); run(() => shared).x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| const run = (f) => f(); run(() => ({ x: 1 })).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const run = (f) => f(); run(() => ({ ...shared })).x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const shared = { inner: { y: 1 } }; const get = () => ({ inner: { y: 1 } }); const { inner } = get(); inner.y = 2; return shared.inner.y; | 1 | literal 1, right | literal 1, right |
| const shared = { inner: { y: 1 } }; const get = () => ({ ...shared }); const { inner } = get(); inner.y = 2; return shared.inner.y; | 2 | literal 1, wrong | unknown |
| const get = () => shared; const v = get().x; return shared.x; | 1 | literal 1, right | unknown |
| const get = () => shared; return get().x; | 1 | unknown | unknown |
| const get = () => shared; const t = get(); return shared.x; | 1 | literal 1, right | unknown |
| const box = { get v() { return shared; } }; box.v; return shared.x; | 1 | literal 1, right | literal 1, right |
| function C() { return shared; } new C(); return shared.x; | 1 | literal 1, right | unknown |
| const get = () => shared; get.call(null); return shared.x; | 1 | literal 1, right | unknown |
| const get = () => shared; [get()].map((t) => t.x); return shared.x; | 1 | literal 1, right | unknown |
| function get(n) { return n ? get(n - 1) : shared; } get(3); return shared.x; | 1 | literal 1, right | unknown |
| const shared = { x: 1, y: 1 }; const get = () => shared; get().x = 2; return shared.y; | 1 | literal 1, right | unknown |
| const shared = { x: 1, y: 1 }; const box = { get v() { return shared; } }; box.v.x = 2; return shared.y; | 1 | literal 1, right | literal 1, right |
| const get = () => shared; shared.x = 2; get(); return shared.x; | 2 | unknown | unknown |
| shared.x = 2; return shared.x; | 2 | unknown | unknown |
| const get = () => shared; get().x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| const get = () => shared; return shared.x; | 1 | literal 1, right | literal 1, right |
| const box = { get v() { return shared; } }; const t = box.v; t.x = 2; return shared.x; | 2 | literal 1, wrong | literal 1, wrong |
| const box = { get v() { return shared; } }; const o = {}; o.a = box.v; o.a.x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| const box = {}; Object.defineProperty(box, 'v', { get() { return shared; } }); box.v.x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| class B { static get v() { return shared; } } B.v.x = 2; return shared.x; | 2 | literal 1, wrong | literal 1, wrong |
| const box = { get() { return shared; } }; box.get().x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| class B { get() { return shared; } } new B().get().x = 2; return shared.x; | 2 | literal 1, wrong | unknown |
| const holder = { a: shared, b: 1 }; const get = () => shared; get().x = 2; return holder.b; | 1 | literal 1, right | literal 1, right |
| const get = () => shared; const f = () => get().x; return shared.x; | 1 | literal 1, right | unknown |
| const get = () => shared.x; get(); return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => shared.x; let n = get(); n = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const get = () => shared; const f = () => { get().x = 2; }; return shared.x; | 1 | literal 1, right | unknown |
| const f = () => { shared.x = 2; }; return shared.x; | 1 | unknown | unknown |
| const get = () => { const inner = () => shared; return { x: 0 }; }; get().x = 2; return shared.x; | 1 | literal 1, right | literal 1, right |
| const other = { x: 9 }; const get = () => shared; get().x = 2; return other.x; | 9 | literal 9, right | literal 9, right |

Precision on the older 197 cases

These are the same 197 cases as the #1444 check. I re-ran their real-JavaScript answers on Node 24, and all 197 equal the stored answers. Main has 9 wrong cases here, the same count as the #1444 check. #1471 fixes 7 of them. It adds no new wrong answer, loses no right answer, and gains none. 190 of the 197 cases give the same answer on both trees.

Case set Cases Right to unknown WRONG fixed New WRONG
#1442 cases 24 0 0 0
#1445 probes 48 0 6 0
for...of cases (#1437) 38 0 1 0
#1390 corpus 59 0 0 0
#1444 added probes 28 0 0 0
Total 197 0 7 0

The 7 fixed cases are the six #1449 cases (q01-call-result and r01 to r05) and c6p_generator, a yielded reference. The 2 still wrong are c3_m0_twice and same_member_twice. Both come from one loop shape that the PR does not touch. I searched the 197 sources for local calls that hand back an object. There are 8: the 7 fixed cases and q11-store-in-arrow-return. Each one writes to that object, and real JavaScript gives 2. So no case is a read-only call, and this table cannot show the loss that the new probes found.

The 7 cases whose answer changed
Case set Case Real JS main 4e3d3354 #1471 8414ee49
probes2 q01-call-result 2 literal 1, wrong unknown
probes3 r01-call-local 2 literal 1, wrong unknown
probes3 r02-call-direct-write 2 literal 1, wrong unknown
probes3 r03-fndecl-slot 2 literal 1, wrong unknown
probes3 r04-iife-slot 2 literal 1, wrong unknown
probes3 r05-method-slot 2 literal 1, wrong unknown
forof c6p_generator 2 literal 1, wrong unknown

The 197-case runs used Node 24 and the CLI only. The MCP server was not run.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (builds and speed on 24.18.0)
  • Head / base: 8414ee49 / 4e3d3354

🤖 Generated with Claude Code (Opus 5.5) 🦊

@N0zoM1z0
N0zoM1z0 marked this pull request as ready for review October 10, 2026 07:46
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@N0zoM1z0
N0zoM1z0 merged commit 782e014 into main Oct 10, 2026
20 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/javascript-returned-reference-aliases branch October 10, 2026 07:46
kaoru0822-kitauji added a commit that referenced this pull request Oct 10, 2026
…1517)

Since #1471, escaping an object also escapes every method's results. Each
call through the object escapes it as the receiver, and each escape
re-expanded all of its methods. N methods returning one shared object,
each called once, did N times N work: 2,000 calls took 3.0 s of semantic
analysis and 4,000 took 12 s.

Expansion below references depends only on syntax, so escapes now reuse
it per expression and path. Identifiers that resolve to the same binding
and path collapse to one, because the escape walk treats them alike.
Every escape site is still recorded. The semantic IR is byte-identical
on 50 sources, and the issue's case takes 253 ms at 2,000 and 638 ms at
4,000.

Closes #1495

Co-authored-by: Claude Opus 5.5 <[email protected]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
) (morluto#1517)

Since morluto#1471, escaping an object also escapes every method's results. Each
call through the object escapes it as the receiver, and each escape
re-expanded all of its methods. N methods returning one shared object,
each called once, did N times N work: 2,000 calls took 3.0 s of semantic
analysis and 4,000 took 12 s.

Expansion below references depends only on syntax, so escapes now reuse
it per expression and path. Identifiers that resolve to the same binding
and path collapse to one, because the escape walk treats them alike.
Every escape site is still recorded. The semantic IR is byte-identical
on 50 sources, and the issue's case takes 253 ms at 2,000 and 638 ms at
4,000.

Closes morluto#1495
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Writing through a function's returned object reports a stale literal

3 participants