@samitouri / QOS-React-2 / commits / 7f7727d7e5

Consolidate logic in MergeOverlappingScopes prior to fix

Small refactor to consolidate visiting operands and their scopes, used in the follow-up PR.

Joe Savona committed Jan 19, 2023 at 10:10 UTC 7f7727d7e5c367273492ec932a10d73792ef9ba5
1 file changed +9 -19
compiler/forget/src/ReactiveScopes/MergeOverlappingReactiveScopes.ts
+9 -19
@@ -10,6 +10,7 @@ import {
10 InstructionId,
11 InstructionValue,
12 makeInstructionId,
13 + Place,
14 ReactiveBlock,
15 ReactiveFunction,
16 ReactiveInstruction,
@@ -161,10 +162,7 @@ function visitValueBlock(context: Context, block: ReactiveValueBlock): void {
162 if (block.last !== null) {
163 context.visitId(block.last.id);
164 if (block.last.value.kind === "Identifier") {
164 - const scope = getPlaceScope(block.last.id, block.last.value);
165 - if (scope !== null) {
166 - context.visitScope(scope);
167 - }
165 + context.visitPlace(block.last.id, block.last.value);
166 }
167 }
168 }
@@ -179,13 +177,7 @@ function visitInstruction(
177 "Expected lvalues to not be null when assigning scopes. " +
178 "Pruning lvalues too early can result in missing scope information."
179 );
182 - if (
183 - instruction.lvalue.place.identifier.scope !== null &&
184 - instruction.id >= instruction.lvalue.place.identifier.scope.range.start &&
185 - instruction.id < instruction.lvalue.place.identifier.scope.range.end
186 - ) {
187 - context.visitScope(instruction.lvalue.place.identifier.scope);
188 - }
180 + context.visitPlace(instruction.id, instruction.lvalue.place);
181 }
182
183 function visitValue(
@@ -195,13 +187,7 @@ function visitValue(
187 ): void {
188 context.visitId(id);
189 for (const operand of eachInstructionValueOperand(value)) {
198 - if (
199 - operand.identifier.scope !== null &&
200 - id >= operand.identifier.scope.range.start &&
201 - id < operand.identifier.scope.range.end
202 - ) {
203 - context.visitScope(operand.identifier.scope);
204 - }
190 + context.visitPlace(id, operand);
191 }
192 }
193
@@ -232,7 +218,11 @@ class Context {
218 });
219 }
220
235 - visitScope(scope: ReactiveScope): void {
221 + visitPlace(id: InstructionId, place: Place): void {
222 + const scope = getPlaceScope(id, place);
223 + if (scope === null) {
224 + return;
225 + }
226 const currentBlock = this.scopes[this.scopes.length - 1]!;
227 // Fast-path for the first time we see a new scope
228 if (!this.seenScopes.has(scope.id)) {