Skip to content

issue-2088 plan: round-9 fail-closed rewrite of condition 4 narrows recall for spread and non-trivial pair-value shapes #2624

Open

Description

@carlos-alm

What

docs/plans/issue-2088.md's escape-analysis design (condition 4 of computeObjectLiteralSiteEscapes, WU-2) had literalHasUnmodeledThisReference inspecting only a closed set of recognised pair-value shapes — an inline method_definition/function_expression/function, an arrow_function, or a same-file-resolved identifier — and silently treating every OTHER shape as safe (non-escaping) by omission, the exact inversion of every other condition's fail-closed default.

Round 9 (PR #2612) fixed the soundness bug: a spread_element (const T = { alpha: fnA, ...mixin } where mixin = { run() { return this.alpha(); } }), a call-expression-valued pair (run: makeRunner()), a parenthesized function expression (run: (function () { ... })), a bare member-expression read, an as/satisfies cast, or a logical/ternary expression now correctly marks the site escaping instead of being silently skipped.

Fixing the soundness bug genuinely narrows recall relative to the (unsound) pre-round-9 draft: an object literal that uses object-spread, or has a property valued by any of the shapes above, alongside a value-ref property the design would otherwise have correlated via T1, now always falls back to T2 for that value-ref property, even in cases where the this-referencing shape reachable through the unrecognised value provably never runs (e.g. a spread source that never actually defines a this-using method) — this plan does not attempt to look inside those shapes to tell a genuinely safe instance apart from an unsafe one.

Why this wasn't folded into the round-9 fix directly

The round-9 fix's whole point is to close the soundness gap now, for every unrecognised shape, rather than special-case a subset the reviewer happens to think of as "probably fine." Extending correlation to look inside a spread source's own shape, or to statically evaluate a call expression's return value, is a materially larger, separate design question (effectively requiring the escape analysis to recurse into an arbitrary second literal, or model call-return shapes generally) that deserves its own focused look rather than expanding round 9's diff — consistent with how #2618/#2620/#2621/#2622/#2623 each filed their own narrower recall limitation instead of being bundled into the round that found them.

Suggested fix shape (not binding — decide at execute/fix time)

For the spread_element case specifically: since computeObjectLiteralSiteEscapes already extracts objectLiteralSites for every object literal in the file, a spread source that is ITSELF a same-file, non-escaping, recognised object literal could in principle be recursively checked for its own this-using methods, rather than treated as unconditionally opaque. For the call_expression/parenthesized_expression/other pair-value cases, no obvious safe extension exists without either evaluating the expression (out of scope for static analysis) or unwrapping one level of parens/pattern (a narrower, plausibly tractable follow-up for the parenthesized_expression case alone, mirroring how TABLE_NAME_PASSTHROUGH_TYPES already unwraps parenthesized_expression for a different purpose in findEnclosingTableName).

Add a regression case to WU-10's correlation-shape list demonstrating a spread source whose own methods are provably this-free still correlates once this is implemented, without weakening the round-9 fail-closed default for spread sources that are NOT provably safe.

Where

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upDeferred work from PR reviews that needs tracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions