Repository navigation
fix(javascript): classify member assignment targets as property writes - #2881
0x-saurabh wants to merge 4 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a105aa0e10
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 561b9232e0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open. Changes are present at public head |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0065ca243
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| parent.left === node && | ||
| parent.operator !== "=") || | ||
| (t.isUpdateExpression(parent) && parent.argument === node); | ||
| semanticWriteSiteTarget(parent) === node && |
There was a problem hiding this comment.
Carry write-site ownership into wrapped identifier references
For a TypeScript/Flow-wrapped binding target such as (count as number)++ or count! += 1, collectSemanticReferencesSteps still gives semanticIdentifierRole and this predicate the identifier's immediate wrapper parent, so the occurrence is emitted only as a read and the graph has no writes edge; wrapped updates also miss bindAssignment's identifier-only update branch and can leave the old exact value. The fresh evidence beyond the resolved wrapped-member case is the still-immediate-parent call at javascriptSemanticProjection.ts:180-185; carry the owning write site through identifier collection too.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 7051da0. Identifier references now resolve their write site through inert wrappers with a new shared helper, semanticWrappedWriteSite, so count! += 1 and (count as number)++ produce a read and a write reference (and therefore the writes edge), and count! = 2 a write. bindAssignment unwraps the identifier for the assignment and update fast paths, so the binding's old exact value is no longer retained after a wrapped update. delete x deliberately stays a read, as before. Covered in javascriptSemanticAnalysis.dataflow.test.ts ("wrapped binding targets"); both cases fail on the previous head and pass now.
| export const semanticWriteSiteTarget = (node: t.Node): t.Node | null => { | ||
| if (t.isAssignmentExpression(node)) return node.left; | ||
| if (t.isUpdateExpression(node)) return node.argument; | ||
| if (t.isUnaryExpression(node, { operator: "delete" })) return node.argument; | ||
| if (t.isForOfStatement(node) || t.isForInStatement(node)) return node.left; |
There was a problem hiding this comment.
Invalidate symbolic bundle tables for flattened targets
When a detected bundle table is overwritten through a destructuring target such as [table[1]] = [replacement], JavaScriptSymbolicBindings still uses its own dispatch at javascriptSymbolicBindings.ts:107-112 and passes the whole ArrayPattern to #indexWrite, so no slot is recorded or invalidated and wrapped-call analysis can continue reporting APIs from the replaced factory. Route this affected consumer through the new write-site owner and flatten its targets conservatively as well.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 7051da0. JavaScriptSymbolicBindings now dispatches through semanticWriteSiteTarget. A direct identifier or member target records its value as before; a destructuring pattern or loop head is flattened with semanticWriteTargets and each leaf conservatively invalidates its root binding (the existing dynamic-path behavior), so [table[1]] = [replacement] and for (table[1] of list) no longer leave a stale bootstrap slot. The member walk also unwraps inert wrappers, matching the object collector. Three new cases in javascriptSymbolicBindings.test.ts fail on the previous head and pass now.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa3047ad59
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const writeTarget = semanticWriteSiteTarget(node); | ||
| if (writeTarget !== null) markTarget(writeTarget, node); |
There was a problem hiding this comment.
Normalize reference-store targets before escape analysis
When a member store is wrapped by TypeScript syntax, such as (external.slot as unknown) = source, this branch unwraps it for markTarget, but the preceding semanticIterationSources call uses an independent pattern walker that only recognizes a bare MemberExpression (javascriptSemanticIterationSources.ts:79). It therefore emits no reference-store, so source never receives an escaped path and can remain an exact object even after being exposed through an arbitrary receiver; normalize that producer through the same write-target owner before applying either effect.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
| * {@link semanticWriteTargets} flattens to its written leaves. | ||
| */ | ||
| export const semanticWriteSiteTarget = (node: t.Node): t.Node | null => { | ||
| if (t.isAssignmentExpression(node)) return node.left; |
There was a problem hiding this comment.
Project wrapped CommonJS exports through the write owner
For a wrapped or destructured export target such as (module.exports.run as unknown) = handler or ({ handler: module.exports.run } = impl), this owner and semanticWriteTargets identify the member write, but collectCommonJsExport still passes the raw node.left to commonJsExportName (javascriptSemanticProjection.ts:462-467), which rejects wrappers and patterns. No commonjs-export module link is emitted, so cross-file composition loses the exported run; have that consumer inspect the owner's normalized target leaves and preserve the corresponding RHS projection when available.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| ) { | ||
| this.#indexWrite( | ||
| direct, | ||
| t.isAssignmentExpression(site) ? site.right : site, |
There was a problem hiding this comment.
Wrapped exports get wrong values
#indexWriteSite now reaches wrapped member targets, but it records site.right for every assignment operator. In a module factory, exports.api = 'prefix'; (exports as any).api += require('electron'); makes load(1).api resolve to Electron, although the actual value is a string. #propertyValue treats the recorded right-hand side as the final export value, so later analysis follows the wrong value.
Only record an exact value for =. Compound assignments need to keep the result unknown unless their full result is calculated.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSymbolicBindings.ts
Line: 960
Comment:
**Wrapped exports get wrong values**
`#indexWriteSite` now reaches wrapped member targets, but it records `site.right` for every assignment operator. In a module factory, `exports.api = 'prefix'; (exports as any).api += require('electron');` makes `load(1).api` resolve to Electron, although the actual value is a string. `#propertyValue` treats the recorded right-hand side as the final export value, so later analysis follows the wrong value.
Only record an exact value for `=`. Compound assignments need to keep the result unknown unless their full result is calculated.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.7051da0 to
a916e54
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a916e54f12
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * has a wrapper as its immediate parent, so the parent alone cannot say that | ||
| * the identifier or member is written. | ||
| */ | ||
| export const semanticWrappedWriteSite = ( |
There was a problem hiding this comment.
Normalize wrapped targets for result-binding projection
When a data-effectful call is assigned through a newly supported wrapper, such as child! = spawn(...), assignedSemanticResultBindings still passes the raw owner.left to projectedPatternBindings (javascriptSemanticDataEffectHelpers.ts:41-50), whose walker has no wrapper case. It therefore returns no result binding, so child-process interactions, resource releases, async handles, and request consumers remain unlinked even though the reference and binding IR now records the write; normalize this target through the shared owner before projection.
AGENTS.md reference: AGENTS.md:L23-L23
Useful? React with 👍 / 👎.
| ): void => { | ||
| if (t.isAssignmentExpression(node)) { | ||
| if (t.isIdentifier(node.left)) | ||
| const left = unwrapJavaScriptExpression(node.left).node; |
There was a problem hiding this comment.
Route binding dispatch through the write-site owner
bindAssignment still independently dispatches assignment, update, and for-in/of syntax instead of using the new semanticWriteSiteTarget owner. A future write-form or normalization correction can therefore update object, mutation, Electron, and symbolic projections while leaving binding definitions and values stale; obtain the target from the owner once, then retain only the value-specific handling here and deliberately ignore identifier deletes.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
| ) { | ||
| this.#indexWrite( | ||
| direct, | ||
| t.isAssignmentExpression(site) ? site.right : site, |
There was a problem hiding this comment.
Keep compound symbolic writes inexact
Within a detected bundle module, a wrapped compound target such as (module.exports.count as number) += 2 now reaches this branch, but every assignment expression records site.right as the exact exported value. #propertyValue later evaluates that node directly even though the runtime result depends on the previous count (and a logical assignment may not write at all), producing false exact literals or APIs; only plain = should store its RHS, while read-modify writes should be invalidated or modeled from the shared read-first fact.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Member expressions that are the target of a destructuring assignment, a for...of or for...in head, or a delete expression were recorded as property reads because the object collector only recognized a direct assignment or update parent. The semantic graph then projected a false reads-property relation and no write occurrence for these forms. Classify a member from its owning write site instead: the collector records the written member leaves when it enters a write site, using the existing semanticWriteTargets walker. The set of write-site constructs now lives in one exported helper, semanticWriteSiteTarget, shared with the member-mutation analysis that already treated these forms as writes. Fixes morluto#2567 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Keying each written member to its owning write site lets the object collector decide read-before-write from that site, so TypeScript-wrapped targets such as source.count!++ or (source.count as number) += 1 keep their property read instead of becoming write-only. The predicate lives beside semanticWriteSiteTarget as semanticWriteSiteReadsFirst. The Electron member-write collector now dispatches through semanticWriteSiteTarget too, removing the last inline copy of the write-site cascade. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…te-site owner Identifier references classified a wrapped target such as count! += 1 or (count as number)++ from its immediate wrapper parent, so the occurrence was a read only and binding assignment kept the old exact value. A new shared helper, semanticWrappedWriteSite, finds the write site through inert wrappers; the reference collector and binding assignment use it, so wrapped updates emit the read and the write. The symbolic bindings resolver kept its own write-site cascade and passed whole destructuring patterns to its index walk, so a bootstrap table slot overwritten through [table[1]] = [...] or a loop head stayed resolvable. It now dispatches through semanticWriteSiteTarget, flattens pattern and loop-head targets with semanticWriteTargets, and conservatively invalidates each leaf's root binding. The member walk unwraps inert wrappers, matching the object collector. Co-Authored-By: Claude Fable 5.1 <[email protected]>
a916e54 to
ef85297
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef85297599
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const left = unwrapJavaScriptExpression(node.left).node; | ||
| if (t.isIdentifier(left)) |
There was a problem hiding this comment.
Normalize wrapped targets in interop reassignment proofs
When TypeScript wraps the reassignment in the already-supported Rolldown interop pattern, for example let electron = require("electron"); electron! = __toESM(electron, 1);, this branch now adds the assignment definition, but createSemanticModuleInterop.origin still requires a bare assignment.left at javascriptModuleInterop.ts:570-583. The conversion therefore becomes unprovable, and electronExport at javascriptSemanticAnalysis.ts:588-592 rejects the reassigned binding, dropping subsequent BrowserWindow, IPC, and other Electron findings; normalize that proof through the shared write target as well.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
| const left = unwrapJavaScriptExpression(node.left).node; | ||
| if (t.isIdentifier(left)) |
There was a problem hiding this comment.
Preserve ordering for wrapped assignment initializers
When a wrapped reassignment follows an alias read inside a getter, such as let x = old; const y = x; x! = replacement; return y, the initializer recorded here has no statement position because directInitializerPosition only accepts a bare parent.left at javascriptSemanticMutationInitializers.ts:56-66. semanticReadInitializers therefore retains the future replacement initializer while resolving y, so a later holder.selected.mode = value is projected onto both old and replacement even though runtime returns only old; normalize the LHS in that ordering helper.
AGENTS.md reference: AGENTS.md:L25-L25
Useful? React with 👍 / 👎.
Track module writes and escapes at their owner, preserve capture and reassignment ordering, and share CommonJS/default namespace identity without erasing parent-slot changes. Carry write sites into ambient alias resolution and use parsed write targets across consumers. Deduplicate returned-reference work with cycle context; retain unchanged temporal selection identity so provenance memoization stays effective. Reviewed fixes include #2041, #2465, #2830, #2881, and #2948. Remove superseded mutation representations and the ineffective per-markValue dedup layer. Validation: 380 focused JavaScript tests passed under a 384 MiB heap cap, including the previously aborting 30-level/128-call alias regression. Six public CLI/MCP builtin tests passed. Exact pdf.js completed-workflow performance remains unmeasured.
|
Heads up: main already has this change in 04672f2. The code is in 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Superseded by the delivered change on main: fb4b8a470. Member-assignment targets are property writes, with direct/destructured/loop/delete and read-control coverage in the owning semantic analysis. Closing this earlier proposal. Current main qualification passed: https://github.com/morluto/rea/actions/runs/38690953281. |
|
Thanks @saurabh-sol for the JavaScript member-write classification case. Main preserves that write evidence in the shared parser. |
Summary
Fixes #2567.
JavaScript semantic analysis classified a member expression as a property write only when its immediate parent was an assignment or update expression. A member that is the target of a destructuring assignment (
[o.count] = [2]), afor...of/for...inhead (for (o.count of list)), ordelete o.counttherefore produced areadobject operation and a falsereads-propertyrelation in the semantic graph, although none of these forms reads the property value.Problem and expected behavior
Smallest trigger:
ir.objectOperationsreported["read"]and the graph projected aread:/countoccurrence with areads-propertyrelation. The violated invariant is the one the sibling member-mutation analysis already follows: these constructs assign into their target and are writes, so the object operation must bewrite, the occurrencewrite:/count, and the relationwrites-property. A directsource.count = 2must stay a write; a plainsource.countaccess, and a member used as a destructuring default value ([v = source.count] = []), must stay reads.Change and scope
The object collector now classifies a member from its owning write site rather than from its immediate parent. When the traversal enters a write site it records each written member leaf, keyed to that site, through the existing
semanticWriteTargetswalker;collectMemberconsumes the entry. Read-before-write is decided from the owning site through a new shared predicate,semanticWriteSiteReadsFirst, so TypeScript-wrapped targets such assource.count!++or(source.count as number) += 1keep their property read (previously these were read-only, since the wrapper hid the assignment parent).The notion of "which constructs are write sites" previously lived inline in
javascriptSemanticMemberMutations.tsand again injavascriptElectronMemberWrites.ts. It is now one exported helper,semanticWriteSiteTarget, injavascriptAstValues.tsnext tosemanticWriteTargets, and the object collector, the member-mutation analysis, the Electron provenance collector, the identifier reference collector, binding assignment, and the symbolic bindings resolver all dispatch through it. No consumer reinterprets the syntax.Review follow-ups on the same owner:
semanticReadsBeforeWritedelegates tosemanticWriteSiteTargetandsemanticWriteSiteReadsFirst(maintainer commit5fbeb4313), so identifier references and member operations share one read-before-write rule.count! += 1,(count as number)++) are classified from their write site through a newsemanticWrappedWriteSitehelper, so the reference collector emits the read and the write, and binding assignment sees through the wrapper so the old exact value is not retained.javascriptSymbolicBindings.ts) dispatches throughsemanticWriteSiteTarget. A direct identifier or member target records its value as before; a destructuring pattern or loop head is flattened withsemanticWriteTargetsand each leaf conservatively invalidates its root binding, so[table[1]] = [replacement]orfor (table[1] of list)no longer leaves a stale bootstrap slot. Wrappers inside a member chain ((table as never)[1]) are unwrapped during the walk, matching the object collector.Not included: the value-projection side (
writes-propertyrelations added from the value analysis) is untouched; this change only removes the false read occurrence and adds the missing write occurrence at the object-operation boundary. No CLI, MCP, or catalog contract changes.Follow the contribution scope.
Contract and boundary impact
collectJavaScriptSemanticObjectsinsrc/domain/javascript/javascriptSemanticObjects.ts(domain static analysis). The graph projection inJavaScriptSemanticGraphObjectProjection.tsconsumes the corrected operation kind unchanged.writes-propertyrelation and loses a falsereads-propertyrelation for the same location. No identity or provenance fields change.docs/public/product-catalog.json), package, or installation impact: none.Expected effects:
Evidence and regression coverage
Tests added or updated (listed per file; the last two bullets are the review follow-ups):
src/domain/javascript/javascriptSemanticAnalysis.dataflow.test.ts: sevenit.eachcases (destructuring assignment, with default, nested, rest,for...ofhead,for...inhead,delete) assertobjectOperationsis exactly["write"]; one control asserts a member in a destructuring default value stays["read"]. Four wrapped read-modify-write cases (source.count!++,source.count! += 1,(source.count as number) += 1,(source.count)++) assert["read", "write"], and two wrapped write-only cases ((source.count as number) = 2,delete source.count!) assert["write"]. The existing direct-assignment and read-modify-write cases remain and still pass.src/domain/javascript/javascriptSemanticAnalysis.dataflow.test.ts(wrapped binding targets):count! += 1; (count as number)++; const copy = count!yields reference rolesread, write, read, write, readand the binding value becomes unknown;count! = 2yields a singlewrite.src/domain/javascript/javascriptSymbolicBindings.test.ts: a bootstrap module slot overwritten through a destructuring assignment, afor...ofhead, or a wrapped member chain makes the laterload(1)unknown.src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts:[source.count] = [2]projects a singlewrite:/countoccurrence with a resolvedwrites-propertyrelation to the/countslot and noreads-propertyrelation.Base reproduction or other evidence: executed. With the source files stashed and only the tests applied, the seven new dataflow cases fail (each reports
["read"]); the direct-assignment control and the default-value control pass. The three TypeScript-wrapped read-modify-write cases fail against the first commit of this PR (write-only) and pass after the second. With the fix applied all cases pass.User-visible CLI/MCP output (if applicable): not applicable.
Remaining proof gaps: none known for the listed forms. Member targets inside destructuring declarations (
const [x] = ...) cannot contain member expressions and are unaffected.Observed, derived, and inferred claims remain distinguishable.
Artifact identity, source provenance, and failed attempts remain preserved.
Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.
Validation performed
npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.dataflow.test.ts src/domain/javascript/javascriptSymbolicBindings.test.ts src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts— 4 files, 336 tests passed (at 7051da0).aa3047ad5(tests only) — the five review follow-up cases fail (two wrapped-identifier, three symbolic-bindings); the rest pass.["read"]; both controls pass. Confirms the regression reproduces on the base.npm run check:fast— typecheck and lint, 2 tasks successful (at 7051da0).npm run check:changed— 89 test files, 2000 tests passed (at 7051da0).git diff --check— clean..nvmrc), npm 11.16.0, macOS arm64. No real-provider lane applies.Compatibility, safety, and release
Before merge
type(scope): outcome.🤖 Generated with Claude Code