Conversation
Add detailed plan for making the React Compiler fault-tolerant by accumulating errors across all passes instead of stopping at the first error. This enables reporting multiple compilation errors at once.
Greptile SummaryThis PR adds a detailed plan document (
Confidence Score: 4/5
Important Files Changed
Last reviewed commit: 056a8e1 |
| - [ ] **4.1 `validateHooksUsage`** (`src/Validation/ValidateHooksUsage.ts`) | ||
| - Change signature from `(fn: HIRFunction): Result<void, CompilerError>` to `(fn: HIRFunction): void` | ||
| - Record errors on `fn.env` instead of returning `errors.asResult()` | ||
| - Update Pipeline.ts call site (line 211): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.2 `validateNoCapitalizedCalls`** (`src/Validation/ValidateNoCapitalizedCalls.ts`) | ||
| - Change signature to return void | ||
| - Fix the hybrid pattern: the direct `CallExpression` path currently throws via `CompilerError.throwInvalidReact()` — change to record on env | ||
| - The `MethodCall` path already accumulates — change to record on env | ||
| - Update Pipeline.ts call site (line 214): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.3 `validateUseMemo`** (`src/Validation/ValidateUseMemo.ts`) | ||
| - Change signature to return void | ||
| - Record hard errors on env instead of returning `errors.asResult()` | ||
| - The soft `voidMemoErrors` path already uses `env.logErrors()` — keep as-is or also record | ||
| - Update Pipeline.ts call site (line 170): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.4 `dropManualMemoization`** (`src/Inference/DropManualMemoization.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env instead of returning `errors.asResult()` | ||
| - Update Pipeline.ts call site (line 178): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.5 `validateNoRefAccessInRender`** (`src/Validation/ValidateNoRefAccessInRender.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env instead of returning Result | ||
| - Update Pipeline.ts call site (line 275): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.6 `validateNoSetStateInRender`** (`src/Validation/ValidateNoSetStateInRender.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env | ||
| - Update Pipeline.ts call site (line 279): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.7 `validateNoImpureFunctionsInRender`** (`src/Validation/ValidateNoImpureFunctionsInRender.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env | ||
| - Update Pipeline.ts call site (line 300): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.8 `validateNoFreezingKnownMutableFunctions`** (`src/Validation/ValidateNoFreezingKnownMutableFunctions.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env | ||
| - Update Pipeline.ts call site (line 303): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.9 `validateExhaustiveDependencies`** (`src/Validation/ValidateExhaustiveDependencies.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env | ||
| - Update Pipeline.ts call site (line 315): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.10 `validateMemoizedEffectDependencies`** (`src/Validation/ValidateMemoizedEffectDependencies.ts`) | ||
| - Change signature to return void (note: operates on `ReactiveFunction`) | ||
| - Record errors on the function's env | ||
| - Update Pipeline.ts call site (line 565): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.11 `validatePreservedManualMemoization`** (`src/Validation/ValidatePreservedManualMemoization.ts`) | ||
| - Change signature to return void (note: operates on `ReactiveFunction`) | ||
| - Record errors on the function's env | ||
| - Update Pipeline.ts call site (line 572): remove `.unwrap()` | ||
|
|
||
| - [ ] **4.12 `validateSourceLocations`** (`src/Validation/ValidateSourceLocations.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env | ||
| - Update Pipeline.ts call site (line 585): remove `.unwrap()` |
There was a problem hiding this comment.
Inaccurate line references for Pipeline.ts
Several line numbers cited for Pipeline.ts do not match the actual codebase. The plan says validateHooksUsage is at line 211 (it's at 199), validateNoCapitalizedCalls at line 214 (it's at 202), inferMutationAliasingEffects at lines 233-239 (it's at 212-218), inferMutationAliasingRanges at lines 258-267 (it's at 231-240), validateNoRefAccessInRender at line 275 (it's at 248), validateNoSetStateInRender at line 279 (it's at 252), validateNoImpureFunctionsInRender at line 300 (it's at 273), validateNoFreezingKnownMutableFunctions at line 303 (it's at 276), validateExhaustiveDependencies at line 315 (it's at 288), validateMemoizedEffectDependencies at line 565 (no such call exists at that line), validatePreservedManualMemoization at line 572 (it's at 514), validateSourceLocations at line 585 (it's at 527), codegenFunction at lines 575-578 (it's at 517-520), and env.logErrors() calls at lines 286-331 (actually around 259-304).
Since these line references are intended to guide implementation, the inaccuracies could cause confusion during development. Consider either correcting them or removing specific line numbers in favor of function/identifier-based references which are more resilient to code changes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/fault-tolerance-overview.md
Line: 130-190
Comment:
**Inaccurate line references for Pipeline.ts**
Several line numbers cited for `Pipeline.ts` do not match the actual codebase. The plan says `validateHooksUsage` is at line 211 (it's at 199), `validateNoCapitalizedCalls` at line 214 (it's at 202), `inferMutationAliasingEffects` at lines 233-239 (it's at 212-218), `inferMutationAliasingRanges` at lines 258-267 (it's at 231-240), `validateNoRefAccessInRender` at line 275 (it's at 248), `validateNoSetStateInRender` at line 279 (it's at 252), `validateNoImpureFunctionsInRender` at line 300 (it's at 273), `validateNoFreezingKnownMutableFunctions` at line 303 (it's at 276), `validateExhaustiveDependencies` at line 315 (it's at 288), `validateMemoizedEffectDependencies` at line 565 (no such call exists at that line), `validatePreservedManualMemoization` at line 572 (it's at 514), `validateSourceLocations` at line 585 (it's at 527), `codegenFunction` at lines 575-578 (it's at 517-520), and `env.logErrors()` calls at lines 286-331 (actually around 259-304).
Since these line references are intended to guide implementation, the inaccuracies could cause confusion during development. Consider either correcting them or removing specific line numbers in favor of function/identifier-based references which are more resilient to code changes.
How can I resolve this? If you propose a fix, please make it concise.| ## Detailed Design | ||
|
|
||
| * The Environment needs a way to record errors as compilation proceeds. This should generally store the error (and log, if a logger is configured), but should immediately throw if the error is an invariant (see above). | ||
| * BuildHIR should always produce an HIR without error. For syntax forms that are unsupported (currently throwing a Todo error), we should instead construct record the todo error on the environment, and construct a partial HIR. The exact form of the partial HIR can be situation specific: |
There was a problem hiding this comment.
Typo: "construct record" should be "construct, record" or "record"
This sentence reads: "we should instead construct record the todo error on the environment, and construct a partial HIR." It appears to have a duplicated/garbled verb. It likely should be "we should instead record the todo error on the environment, and construct a partial HIR."
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/fault-tolerance-overview.md
Line: 20
Comment:
**Typo: "construct record" should be "construct, record" or "record"**
This sentence reads: "we should instead construct record the todo error on the environment, and construct a partial HIR." It appears to have a duplicated/garbled verb. It likely should be "we should instead **record** the todo error on the environment, and construct a partial HIR."
How can I resolve this? If you propose a fix, please make it concise.| - [ ] **4.3 `validateUseMemo`** (`src/Validation/ValidateUseMemo.ts`) | ||
| - Change signature to return void | ||
| - Record hard errors on env instead of returning `errors.asResult()` | ||
| - The soft `voidMemoErrors` path already uses `env.logErrors()` — keep as-is or also record | ||
| - Update Pipeline.ts call site (line 170): remove `.unwrap()` |
There was a problem hiding this comment.
validateUseMemo line reference is wrong (163 vs 170)
Step 4.3 says the validateUseMemo call site is at Pipeline.ts line 170, but it is actually at line 163 (validateUseMemo(hir).unwrap()). Line 170 in Pipeline.ts is inlineImmediatelyInvokedFunctionExpressions(hir), a completely different pass.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/fault-tolerance-overview.md
Line: 141-145
Comment:
**`validateUseMemo` line reference is wrong (163 vs 170)**
Step 4.3 says the `validateUseMemo` call site is at Pipeline.ts line 170, but it is actually at line 163 (`validateUseMemo(hir).unwrap()`). Line 170 in Pipeline.ts is `inlineImmediatelyInvokedFunctionExpressions(hir)`, a completely different pass.
How can I resolve this? If you propose a fix, please make it concise.| - [ ] **4.4 `dropManualMemoization`** (`src/Inference/DropManualMemoization.ts`) | ||
| - Change signature to return void | ||
| - Record errors on env instead of returning `errors.asResult()` | ||
| - Update Pipeline.ts call site (line 178): remove `.unwrap()` |
There was a problem hiding this comment.
dropManualMemoization line reference is wrong (166 vs 178)
Step 4.4 says the dropManualMemoization call site is at Pipeline.ts line 178, but it is actually at line 166 (dropManualMemoization(hir).unwrap()). Line 178 is mergeConsecutiveBlocks.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/fault-tolerance-overview.md
Line: 147-150
Comment:
**`dropManualMemoization` line reference is wrong (166 vs 178)**
Step 4.4 says the `dropManualMemoization` call site is at Pipeline.ts line 178, but it is actually at line 166 (`dropManualMemoization(hir).unwrap()`). Line 178 is `mergeConsecutiveBlocks`.
How can I resolve this? If you propose a fix, please make it concise.| - [ ] **7.1 Wrap `lower()` call** (line 163) | ||
| - Change from `lower(func, env).unwrap()` to `lower(func, env)` (direct return after Phase 3.1) |
There was a problem hiding this comment.
Pipeline.ts lower() call is at line 156, not 163
Step 7.1 says the lower() call is at line 163, but it is actually at line 156 (const hir = lower(func, env).unwrap()). Line 163 is validateUseMemo.
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/fault-tolerance-overview.md
Line: 251-252
Comment:
**Pipeline.ts `lower()` call is at line 156, not 163**
Step 7.1 says the `lower()` call is at line 163, but it is actually at line 156 (`const hir = lower(func, env).unwrap()`). Line 163 is `validateUseMemo`.
How can I resolve this? If you propose a fix, please make it concise.|
Upstream PR was closed or merged. Code is synced via branch mirror. |
Mirror of facebook/react#35840
Original author: josephsavona
Add detailed plan for making the React Compiler fault-tolerant by
accumulating errors across all passes instead of stopping at the first
error. This enables reporting multiple compilation errors at once.
Stack created with Sapling. Best reviewed with ReviewStack.