From 1db261980741de0ba5590332c60f44bc90a2d1b9 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 16 Jun 2023 14:42:16 -0700 Subject: [PATCH] InferReferenceEffects: distinguish conditional mutations in HIR In InferReferenceEffects, locations that are ConditionallyMutate are either recorded as a Mutate or Read, which means we lose the distinction btw conditional/unconditional mutation in later passes. This PR changes to remember that these places were conditionally mutable, used in later analysis. --- .../packages/babel-plugin-react-forget/src/HIR/HIR.ts | 9 ++------- .../src/Inference/InferReferenceEffects.ts | 2 +- .../error.invalid-pass-ref-to-function.expect.md | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts index b02016ebd6..05b80f1bd8 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts @@ -878,16 +878,11 @@ export function isMutableEffect( switch (effect) { case Effect.Capture: case Effect.Store: + case Effect.ConditionallyMutate: case Effect.Mutate: { return true; } - case Effect.ConditionallyMutate: { - // All conditional mutations should be resolved into some other effect after InferReferenceEffects - CompilerError.invariant( - "Unexpected conditional mutation effect", - location - ); - } + case Effect.Unknown: { CompilerError.invariant("Unexpected unknown effect", location); } diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts index 91b4fcd879..4aab1f122b 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts @@ -311,7 +311,7 @@ class InferenceState { valueKind === ValueKind.Mutable || valueKind === ValueKind.Context ) { - effect = Effect.Mutate; + effect = Effect.ConditionallyMutate; } else { effect = Effect.Read; } diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md index 54cb17b425..f9cab45985 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md +++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md @@ -14,7 +14,7 @@ function Component(props) { ## Error ``` -[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate $22[6:8]:TObject (3:3) +[ReactForget] InvalidInput: Ref values may not be passed to functions because they could read the ref value (`current` property) during render. Cannot access ref object at mutate? $22[6:8]:TObject (3:3) ``` \ No newline at end of file