-
Notifications
You must be signed in to change notification settings - Fork 0
[compiler] Prevent overriding a derivationEntry on effect mutation - CONTAINS BUG #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Greptile SummaryThis PR introduces a critical ordering bug in the validation pass that checks for derived computations in effects. The key changes include:
Issues Found
Confidence Score: 0/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Main as validateNoDerivedComputationsInEffects_exp
participant Cache as DerivationCache
participant Block as Block Processing Loop
participant RecordPhi as recordPhiDerivations
participant RecordInstr as recordInstructionDerivations
Main->>Cache: Initialize cache with props/params
Main->>Main: Start do-while loop
Main->>Cache: takeSnapshot()
Note over Cache: Store previous cache state
Main->>Block: Iterate over blocks
rect rgb(255, 200, 200)
Note over Block,RecordInstr: BUG: Wrong Order!
Block->>RecordInstr: Process instructions FIRST
Note over RecordInstr: Looks up phi values in cache
Note over RecordInstr: Missing entries! Phi derivations not yet recorded
Block->>RecordPhi: recordPhiDerivations() AFTER
Note over RecordPhi: NOW adds phi metadata to cache (too late!)
end
Block->>Main: Continue to next block
Main->>Cache: checkForChanges()
Note over Cache: Compare current vs snapshot
Main->>Cache: snapshot() returns hasChanges
alt hasChanges is true
Main->>Main: Continue loop
else hasChanges is false
Main->>Main: Exit loop, validate effects
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
| for (const block of fn.body.blocks.values()) { | ||
| recordPhiDerivations(block, context); | ||
| for (const instr of block.instructions) { | ||
| recordInstructionDerivations(instr, context, isFirstPass); | ||
| } | ||
| recordPhiDerivations(block, context); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Critical ordering bug: recordPhiDerivations must be called BEFORE the instruction loop, not after. Phi nodes define values at the beginning of a block in SSA form, so their derivation metadata must be in the cache before processing instructions that may reference them.
| for (const block of fn.body.blocks.values()) { | |
| recordPhiDerivations(block, context); | |
| for (const instr of block.instructions) { | |
| recordInstructionDerivations(instr, context, isFirstPass); | |
| } | |
| recordPhiDerivations(block, context); | |
| } | |
| for (const block of fn.body.blocks.values()) { | |
| recordPhiDerivations(block, context); | |
| for (const instr of block.instructions) { | |
| recordInstructionDerivations(instr, context, isFirstPass); | |
| } | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateNoDerivedComputationsInEffects_exp.ts
Line: 225:230
Comment:
**logic:** Critical ordering bug: `recordPhiDerivations` must be called BEFORE the instruction loop, not after. Phi nodes define values at the beginning of a block in SSA form, so their derivation metadata must be in the cache before processing instructions that may reference them.
```suggestion
for (const block of fn.body.blocks.values()) {
recordPhiDerivations(block, context);
for (const instr of block.instructions) {
recordInstructionDerivations(instr, context, isFirstPass);
}
}
```
How can I resolve this? If you propose a fix, please make it concise.
Summary:
With this we are now comparing a snapshot of the derivationCache with the new changes every time we are done recording the derivations happening in the HIR.
We have to do this after recording everything since we still do some mutations on the cache when recording mutations.
Test Plan:
Test the following in playground:
This no longer causes an infinite loop.
Added a test case in the next PR in the stack