@samitouri / QOS-React-2 / commits / 1db2619807

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.

Joe Savona committed Jun 16, 2023 at 14:42 UTC 1db261980741de0ba5590332c60f44bc90a2d1b9
3 files changed +4 -9
compiler/forget/packages/babel-plugin-react-forget/src/HIR/HIR.ts
+2 -7
@@ -878,16 +878,11 @@ export function isMutableEffect(
878 switch (effect) {
879 case Effect.Capture:
880 case Effect.Store:
881 + case Effect.ConditionallyMutate:
882 case Effect.Mutate: {
883 return true;
884 }
884 - case Effect.ConditionallyMutate: {
885 - // All conditional mutations should be resolved into some other effect after InferReferenceEffects
886 - CompilerError.invariant(
887 - "Unexpected conditional mutation effect",
888 - location
889 - );
890 - }
885 +
886 case Effect.Unknown: {
887 CompilerError.invariant("Unexpected unknown effect", location);
888 }
compiler/forget/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts
+1 -1
@@ -311,7 +311,7 @@ class InferenceState {
311 valueKind === ValueKind.Mutable ||
312 valueKind === ValueKind.Context
313 ) {
314 - effect = Effect.Mutate;
314 + effect = Effect.ConditionallyMutate;
315 } else {
316 effect = Effect.Read;
317 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md
+1 -1
@@ -14,7 +14,7 @@ function Component(props) {
14 ## Error
15
16 ```
17 -[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<BuiltInUseRefId> (3:3)
17 +[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<BuiltInUseRefId> (3:3)
18 ```
19
20
\ No newline at end of file