fix(javascript): retain proven property presence at reads (#12477)

* fix(javascript): retain proven property presence at reads

The read-time IR and projection boundary builds on the destructuring work in #7716. This change adds an indexed own-slot proof and uses it for ordinary member reads as well.

Co-authored-by: SII-YDD <38822679+SII-YDD@users.noreply.github.com>

* fix(javascript): retain destructuring proof in read order

---------

Co-authored-by: SII-YDD <38822679+SII-YDD@users.noreply.github.com>
This commit is contained in:
morlutoandSII-YDD authored and GitHub committed 2026-11-19 19:17:32 +00:00
1 parent 833916bb4a
commit 1dc22f18cd
8 files changed
+322 -42

No files matched your search

@@ -484,6 +484,14 @@ export const semanticBindingEffectGeneration = (
binding: JavaScriptSemanticBindingState,
): number => binding.memberWrites.length + binding.escapedPaths.length;
/** A read may need to distinguish a captured reference from its merged value. */
export const hasRecordedReferenceEffects = (
binding: JavaScriptSemanticBindingState,
state: JavaScriptSemanticAnalysisState,
): boolean =>
semanticBindingEffectGeneration(binding) > 0 ||
state.opaqueEffects.byScope.size > 0;
/**
* Recorded ambient writes to `global` paths, as intrinsic paths with
* non-literal keys as null. A write recorded without a site is placed at the
@@ -967,6 +975,62 @@ const opaqueCodeMayReachBindingReference = (
): boolean =>
semanticBindingMayHaveOpaqueEffect(binding, state, capturePoint, "reference");
const observesCapturedWrite = (
binding: JavaScriptSemanticBindingState,
capture: t.Node | undefined,
node: t.Node | undefined,
parents: JavaScriptSemanticAnalysisState["parentsByNode"],
): boolean =>
capture === undefined ||
node === undefined ||
!semanticBindingEffectFollowsCapture(binding, capture, node, parents);
const observesCapturedEscape = (
binding: JavaScriptSemanticBindingState,
capture: t.Node | undefined,
node: t.Node | undefined,
parents: JavaScriptSemanticAnalysisState["parentsByNode"],
): boolean =>
capture === undefined ||
!semanticEscapeFollowsCapture(binding, capture, node, parents);
/** Whether a captured own slot or its receiver may have changed before the read. */
export const capturedBindingPathMayHaveChanged = (
binding: JavaScriptSemanticBindingState,
path: readonly string[],
capture: t.Node,
state: JavaScriptSemanticAnalysisState,
): boolean => {
return (
opaqueCodeMayReachBindingReference(binding, state, capture) ||
semanticOpaqueGlobalMayHaveChanged(capture, state) ||
semanticSomeEffectPathCandidate(
binding.memberWrites,
path,
(effect) =>
semanticEffectPathMatches(effect.path, path) &&
observesCapturedWrite(
binding,
capture,
effect.node,
state.parentsByNode,
),
) ||
semanticSomeEffectPathCandidate(
binding.escapedPaths,
path,
(effect) =>
semanticEffectPathMatches(effect.path, path) &&
observesCapturedEscape(
binding,
capture,
effect.node,
state.parentsByNode,
),
)
);
};
/**
* The value of `binding`'s reference as a read captured at `capturePoint`
* observes it, after the recorded effects that may precede the capture:
@@ -983,16 +1047,8 @@ export const applySemanticBindingReferenceEffects = (
let projected = invalidateSemanticMutationPaths(
value,
binding.memberWrites
.filter(
({ node }) =>
capturePoint === undefined ||
node === undefined ||
!semanticBindingEffectFollowsCapture(
binding,
capturePoint,
node,
state.parentsByNode,
),
.filter(({ node }) =>
observesCapturedWrite(binding, capturePoint, node, state.parentsByNode),
)
.map(({ path }) => path),
);
@@ -1000,8 +1056,7 @@ export const applySemanticBindingReferenceEffects = (
// Escapes only invalidate object references; other lattice values survive.
if (projected.status !== "object" && projected.status !== "array") break;
if (
capturePoint !== undefined &&
semanticEscapeFollowsCapture(
!observesCapturedEscape(
binding,
capturePoint,
escape.node,