Skip to content

issue-2088 plan: round-10 recall improvement for unshadowed builtins was unsound and is reverted in round 11 #2627

Open

Description

@carlos-alm

What

docs/plans/issue-2088.md's escape-analysis design (condition 4 of computeObjectLiteralSiteEscapes, WU-2) resolves an identifier-valued pair or shorthand object-literal property whose name happens to match a known JS/DOM/Node global (BUILTIN_GLOBALS).

Round 10 (PR #2612) introduced isUnshadowedBuiltinGlobal(name, definitionNames) — BUILTIN_GLOBALS.has(name) && !definitionNames.has(name) — to skip identifier resolution (treat the property as safe) only when the name is a builtin AND this file defines no same-file symbol by that name at all. This was framed as a strict recall improvement over the pair arm's prior, always-conservative behaviour (which escaped unconditionally on any builtin-named value, shadowed or not).

Round 11 (PR #2612) found that this "improvement" was unsound, not merely imprecise, and reverted it: definitionNames is built from symbols.definitions (src/domain/graph/builder/stages/build-edges.ts:559), which never includes an imported binding. A builtin-named import (import { Response } from './resp.js' where Response is a same-file, this-using function in resp.js) is therefore indistinguishable, under isUnshadowedBuiltinGlobal, from a genuine, un-redeclared global — even though the import shadows the name exactly as much as a same-file declaration does. Both the pair and shorthand_property_identifier arms now escape unconditionally on any BUILTIN_GLOBALS name instead, with no definitionNames lookup and no resolution attempted at all, and isUnshadowedBuiltinGlobal is deleted.

Why this wasn't fixed by threading importedNames through instead

The critic reviewing round 11 offered two remedies: (a) thread importedNames through the guard so it can also recognise an imported shadow, or (b) revert to unconditional escape on any builtin name. Round 11 chose (b) deliberately: threading importedNames through adds a new parameter to a soundness-critical resolution chain (resolveIdentifierValueThisReference / literalHasUnmodeledThisReference) that this plan has already found bugs in across rounds 7, 8, 9, and 10, for an improvement that itself had not yet had its own focused review round — it was folded into round 10's finding-2 fix as a side effect, not designed and reviewed as its own change. Re-attempting it deserves that focused review, rather than being re-patched inline under a "revert a regression" round whose own mandate was the narrowest possible fix.

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

Thread importedNames (the same set points-to.ts already builds and tests separately from definitionNames, e.g. at src/domain/graph/resolver/points-to.ts:306) through to wherever definitionNames is currently passed for this purpose, and extend the guard to something like BUILTIN_GLOBALS.has(name) && !definitionNames.has(name) && !importedNames.has(name) — safe to skip resolution only when the name is a builtin AND has no same-file declaration AND no same-file import. This needs the identical treatment in both engines (isUnshadowedBuiltinGlobal TS-side, is_unshadowed_builtin_global Rust-side, if the helper is reintroduced), applied identically to both the pair and shorthand_property_identifier arms — the exact "both arms, not just one" discipline round 10's own finding 2 was about, and the exact place a re-introduced helper could regress again if only one arm is updated.

Add escape-fallback fixtures proving a genuine, unshadowed builtin (no same-file declaration, no same-file import) is credited as safe once this lands, without weakening the current unconditional-escape default for the imported-shadow case that round 11's escape-fallback cases (ab)/(ac) already gate.

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