[be] Use switch for exhaustiveness
Joe Savona committed
Feb 14, 2023 at 15:48 UTC
9493e13709867440e4a9192d3a3d6348820b0d38
1 file changed
+27
-9
compiler/forget/src/ReactiveScopes/InferReactiveIdentifiers.ts
+27
-9
@@ -5,6 +5,7 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
+import { CompilerError } from "../CompilerError";
9
import {
10
Effect,
11
IdentifierId,
@@ -12,6 +13,7 @@ import {
13
ReactiveInstruction,
14
} from "../HIR/HIR";
15
import { parseHookCall } from "../Inference/InferReferenceEffects";
16
+import { assertExhaustive } from "../Utils/utils";
17
import {
18
eachReactiveValueOperand,
19
ReactiveFunctionVisitor,
@@ -56,15 +58,31 @@ class Environment extends ReactiveFunctionVisitor<IdentifierReactivity> {
58
if (hasReactiveInput) {
59
// all mutating effects must also be marked as reactive
60
for (const operand of eachReactiveValueOperand(value)) {
59
- if (
60
- operand.effect === Effect.Store ||
61
- operand.effect === Effect.Mutate
62
- ) {
63
- // Explicitly compare to `false` here, since absence from the
64
- // map indicates a free variable
65
- // todo [@mofeiZ] add knowledge about free variables
66
- if (reactivityMap.get(operand.identifier.id) === false) {
67
- reactivityMap.set(operand.identifier.id, true);
61
+ switch (operand.effect) {
62
+ case Effect.Store:
63
+ case Effect.Mutate: {
64
+ // Explicitly compare to `false` here, since absence from the
65
+ // map indicates a free variable
66
+ // todo [@mofeiZ] add knowledge about free variables
67
+ if (reactivityMap.get(operand.identifier.id) === false) {
68
+ reactivityMap.set(operand.identifier.id, true);
69
+ }
70
+ break;
71
+ }
72
+ case Effect.Capture:
73
+ case Effect.Freeze:
74
+ case Effect.Read: {
75
+ // no-op
76
+ break;
77
+ }
78
+ case Effect.Unknown: {
79
+ CompilerError.invariant("Unexpected unknown effect", operand.loc);
80
+ }
81
+ default: {
82
+ assertExhaustive(
83
+ operand.effect,
84
+ `Unexpected effect kind '${operand.effect}'`
85
+ );
86
}
87
}
88
}