cleanup unnecessary code from BuildReactiveFunction
Joe Savona committed
Dec 14, 2022 at 08:42 UTC
be9b6356dfd43e55d305e04a7865d5c10bcaeb86
1 file changed
+2
-68
compiler/forget/src/HIR/BuildReactiveFunction.ts
+2
-68
@@ -309,86 +309,20 @@ function getInstructionScope(instr: Instruction): ReactiveScope | null {
309
instr.lvalue.place.identifier.scope !== null &&
310
isScopeActive(instr.lvalue.place.identifier.scope, instr.id)
311
) {
312
- scope = instr.lvalue.place.identifier.scope;
312
+ return instr.lvalue.place.identifier.scope;
313
} else {
314
for (const operand of eachInstructionOperand(instr)) {
315
if (
316
operand.identifier.scope !== null &&
317
isScopeActive(operand.identifier.scope, instr.id)
318
) {
319
- scope = operand.identifier.scope;
320
- break;
319
+ return operand.identifier.scope;
320
}
321
}
322
}
324
- if (
325
- scope !== null &&
326
- (scope.range.end > scope.range.start + 1 || mayAllocate(instr.value))
327
- ) {
328
- return scope;
329
- }
323
return null;
324
}
325
333
-function mayAllocate(value: InstructionValue): boolean {
334
- switch (value.kind) {
335
- case "BinaryExpression":
336
- case "Identifier":
337
- case "JSXText":
338
- case "Primitive": {
339
- return false;
340
- }
341
- case "ArrayExpression":
342
- case "CallExpression":
343
- case "JsxExpression":
344
- case "JsxFragment":
345
- case "NewExpression":
346
- case "ObjectExpression":
347
- case "OtherStatement":
348
- case "UnaryExpression": {
349
- return true;
350
- }
351
- default: {
352
- assertExhaustive(value, `Unexpected value kind '${(value as any).kind}'`);
353
- }
354
- }
355
-}
356
-
326
function isScopeActive(scope: ReactiveScope, id: InstructionId): boolean {
327
return id >= scope.range.start && id < scope.range.end;
328
}
360
-
361
-class ArraySet<T> {
362
- items: Array<T> = [];
363
- set: Set<T> = new Set();
364
-
365
- add(item: T) {
366
- if (!this.set.has(item)) {
367
- this.set.add(item);
368
- this.items.push(item);
369
- }
370
- }
371
-
372
- delete(item: T) {
373
- if (this.set.has(item)) {
374
- this.set.delete(item);
375
- this.items.splice(
376
- this.items.findIndex((x) => x === item),
377
- 1
378
- );
379
- }
380
- }
381
-
382
- has(item: T): boolean {
383
- return this.set.has(item);
384
- }
385
-
386
- last(): T {
387
- invariant(this.items.length > 0, "Called ArraySet::last on empty set");
388
- return this.items[this.items.length - 1];
389
- }
390
-
391
- *[Symbol.iterator]() {
392
- yield* this.items;
393
- }
394
-}