From f17f4dcf0b27056c0474ec06eecf9970311ac823 Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Fri, 3 Mar 2023 13:35:02 +0000 Subject: [PATCH] [hir] Treat values escaping into a contextref as Mutate --- compiler/forget/src/Inference/InferReferenceEffects.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/forget/src/Inference/InferReferenceEffects.ts b/compiler/forget/src/Inference/InferReferenceEffects.ts index f289e31d46..f8bc60fcec 100644 --- a/compiler/forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/forget/src/Inference/InferReferenceEffects.ts @@ -783,8 +783,12 @@ function inferBlock( continue; } case "LoadLocal": { - state.reference(instrValue.place, Effect.Capture); const lvalue = instr.lvalue; + const effect = + state.isDefined(lvalue) && state.kind(lvalue) === ValueKind.Context + ? Effect.Mutate + : Effect.Capture; + state.reference(instrValue.place, effect); lvalue.effect = Effect.Mutate; // direct aliasing: `a = b`; state.alias(lvalue, instrValue.place);