18
IdentifierId,
19
InstructionValue,
20
ManualMemoDependency,
21
- Place,
21
PrunedReactiveScopeBlock,
22
ReactiveFunction,
23
ReactiveInstruction,
28
SourceLocation,
29
} from '../HIR';
30
import {printIdentifier, printManualMemoDependency} from '../HIR/PrintHIR';
32
-import {eachInstructionValueOperand} from '../HIR/visitors';
31
+import {
32
+ eachInstructionValueLValue,
33
+ eachInstructionValueOperand,
34
+} from '../HIR/visitors';
35
import {collectMaybeMemoDependencies} from '../Inference/DropManualMemoization';
36
import {
37
ReactiveFunctionVisitor,
339
* @returns a @{ManualMemoDependency} representing the variable +
340
* property reads represented by @value
341
*/
340
- recordDepsInValue(
341
- value: ReactiveValue,
342
- state: VisitorState,
343
- ): ManualMemoDependency | null {
342
+ recordDepsInValue(value: ReactiveValue, state: VisitorState): void {
343
switch (value.kind) {
344
case 'SequenceExpression': {
345
for (const instr of value.instructions) {
346
this.visitInstruction(instr, state);
347
}
349
- const result = this.recordDepsInValue(value.value, state);
350
- return result;
348
+ this.recordDepsInValue(value.value, state);
349
+ break;
350
}
351
case 'OptionalExpression': {
353
- return this.recordDepsInValue(value.value, state);
352
+ this.recordDepsInValue(value.value, state);
353
+ break;
354
}
355
case 'ConditionalExpression': {
356
this.recordDepsInValue(value.test, state);
357
this.recordDepsInValue(value.consequent, state);
358
this.recordDepsInValue(value.alternate, state);
359
- return null;
359
+ break;
360
}
361
case 'LogicalExpression': {
362
this.recordDepsInValue(value.left, state);
363
this.recordDepsInValue(value.right, state);
364
- return null;
364
+ break;
365
}
366
default: {
367
- const dep = collectMaybeMemoDependencies(
368
- value,
369
- this.temporaries,
370
- false,
371
- );
372
- if (value.kind === 'StoreLocal' || value.kind === 'StoreContext') {
373
- const storeTarget = value.lvalue.place;
374
- state.manualMemoState?.decls.add(
375
- storeTarget.identifier.declarationId,
376
- );
377
- if (storeTarget.identifier.name?.kind === 'named' && dep == null) {
378
- const dep: ManualMemoDependency = {
379
- root: {
380
- kind: 'NamedLocal',
381
- value: storeTarget,
382
- },
383
- path: [],
384
- };
385
- this.temporaries.set(storeTarget.identifier.id, dep);
386
- return dep;
367
+ collectMaybeMemoDependencies(value, this.temporaries, false);
368
+ if (
369
+ value.kind === 'StoreLocal' ||
370
+ value.kind === 'StoreContext' ||
371
+ value.kind === 'Destructure'
372
+ ) {
373
+ for (const storeTarget of eachInstructionValueLValue(value)) {
374
+ state.manualMemoState?.decls.add(
375
+ storeTarget.identifier.declarationId,
376
+ );
377
+ if (storeTarget.identifier.name?.kind === 'named') {
378
+ this.temporaries.set(storeTarget.identifier.id, {
379
+ root: {
380
+ kind: 'NamedLocal',
381
+ value: storeTarget,
382
+ },
383
+ path: [],
384
+ });
385
+ }
386
}
387
}
389
- return dep;
388
+ break;
389
}
390
}
391
}
402
state.manualMemoState.decls.add(lvalue.identifier.declarationId);
403
}
404
406
- const maybeDep = this.recordDepsInValue(value, state);
407
- if (lvalId != null) {
408
- if (maybeDep != null) {
409
- temporaries.set(lvalId, maybeDep);
410
- } else if (isNamedLocal) {
411
- temporaries.set(lvalId, {
412
- root: {
413
- kind: 'NamedLocal',
414
- value: {...(instr.lvalue as Place)},
415
- },
416
- path: [],
417
- });
418
- }
405
+ this.recordDepsInValue(value, state);
406
+ if (lvalue != null) {
407
+ temporaries.set(lvalue.identifier.id, {
408
+ root: {
409
+ kind: 'NamedLocal',
410
+ value: {...lvalue},
411
+ },
412
+ path: [],
413
+ });
414
}
415
}
416