diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts index 6819c2c6c5bfb..a761152853ff3 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/BuildReactiveScopeTerminalsHIR.ts @@ -179,24 +179,6 @@ export function buildReactiveScopeTerminalsHIR(fn: HIRFunction): void { * Fix scope and identifier ranges to account for renumbered instructions */ for (const [, block] of fn.body.blocks) { - for (const instruction of block.instructions) { - for (const lvalue of eachInstructionLValue(instruction)) { - /* - * Any lvalues whose mutable range was a single instruction must have - * started at the current instruction, so update the range to match - * the instruction's new id - */ - if ( - lvalue.identifier.mutableRange.end === - lvalue.identifier.mutableRange.start + 1 - ) { - lvalue.identifier.mutableRange.start = instruction.id; - lvalue.identifier.mutableRange.end = makeInstructionId( - instruction.id + 1, - ); - } - } - } const terminal = block.terminal; if (terminal.kind === 'scope' || terminal.kind === 'pruned-scope') { /* diff --git a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts index dcd12abf34205..259e03c2d3243 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateMemoizedEffectDependencies.ts @@ -99,6 +99,8 @@ class Visitor extends ReactiveFunctionVisitor { const deps = instruction.value.args[1]!; if ( deps.kind === 'Identifier' && + // TODO: isMutable is not safe to call here as it relies on identifier mutableRange which is no longer valid at this point + // in the pipeline (isMutable(instruction as Instruction, deps) || isUnmemoized(deps.identifier, this.scopes)) ) { diff --git a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts index bbf271c50e5bb..4eb67230c41f3 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts @@ -14,6 +14,7 @@ import { InstructionValue, ManualMemoDependency, Place, + PrunedReactiveScopeBlock, ReactiveFunction, ReactiveInstruction, ReactiveScopeBlock, @@ -277,6 +278,7 @@ function validateInferredDep( class Visitor extends ReactiveFunctionVisitor { scopes: Set = new Set(); + prunedScopes: Set = new Set(); scopeMapping = new Map(); temporaries: Map = new Map(); @@ -414,6 +416,14 @@ class Visitor extends ReactiveFunctionVisitor { } } + override visitPrunedScope( + scopeBlock: PrunedReactiveScopeBlock, + state: VisitorState, + ): void { + this.traversePrunedScope(scopeBlock, state); + this.prunedScopes.add(scopeBlock.scope.id); + } + override visitInstruction( instruction: ReactiveInstruction, state: VisitorState, @@ -464,7 +474,10 @@ class Visitor extends ReactiveFunctionVisitor { instruction.value as InstructionValue, )) { if ( - isMutable(instruction as Instruction, value) || + (isDep && + value.identifier.scope != null && + !this.scopes.has(value.identifier.scope.id) && + !this.prunedScopes.has(value.identifier.scope.id)) || (isDecl && isUnmemoized(value.identifier, this.scopes)) ) { state.errors.push({