From 52b7b0b47f9035f8332ba32dd34b459ddfd4a20c Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:03:51 -0500 Subject: [PATCH 1/5] Remove support for Partials --- .../interfaces/lib/runtime/scope.d.ts | 6 - packages/@glimmer/runtime/index.ts | 2 +- .../lib/compiled/opcodes/-debug-strip.ts | 4 - packages/@glimmer/runtime/lib/scope.ts | 115 ------------------ packages/@glimmer/runtime/lib/vm/append.ts | 3 - 5 files changed, 1 insertion(+), 129 deletions(-) diff --git a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts index bfbc950fa2..4fbba75236 100644 --- a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts +++ b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts @@ -19,20 +19,14 @@ export interface Scope { getSymbol(symbol: number): Reference; getBlock(symbol: number): Nullable; getEvalScope(): Nullable>; - getPartialMap(): Nullable>; bind(symbol: number, value: ScopeSlot): void; bindSelf(self: Reference): void; bindSymbol(symbol: number, value: Reference): void; bindBlock(symbol: number, value: Nullable): void; bindEvalScope(map: Nullable>): void; - bindPartialMap(map: Dict): void; child(): Scope; } -export interface PartialScope extends Scope { - bindEvalScope(scope: Nullable>): void; -} - export interface DynamicScope { get(key: string): Reference; set(key: string, reference: Reference): Reference; diff --git a/packages/@glimmer/runtime/index.ts b/packages/@glimmer/runtime/index.ts index 0c80f9eceb..131c70cccb 100644 --- a/packages/@glimmer/runtime/index.ts +++ b/packages/@glimmer/runtime/index.ts @@ -39,7 +39,7 @@ export { hash } from './lib/helpers/hash'; export { invokeHelper } from './lib/helpers/invoke'; export { on } from './lib/modifiers/on'; export { renderComponent, renderMain, renderSync } from './lib/render'; -export { DynamicScopeImpl, PartialScopeImpl } from './lib/scope'; +export { DynamicScopeImpl } from './lib/scope'; export type { SafeString } from './lib/upsert'; export { type InternalVM, VM as LowLevelVM, UpdatingVM } from './lib/vm'; export { diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts index 4bad535c78..68e0220bec 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts @@ -11,7 +11,6 @@ import type { InternalComponentManager, Invocation, Nullable, - Scope, ScopeBlock, } from '@glimmer/interfaces'; import type { OpaqueIterator, Reference } from '@glimmer/reference'; @@ -36,7 +35,6 @@ import { import { REFERENCE, UNDEFINED_REFERENCE } from '@glimmer/reference'; import { COMPUTE } from '@glimmer/validator'; -import { PartialScopeImpl } from '../../scope'; import { VMArgumentsImpl } from '../../vm/arguments'; import { ComponentElementOperations } from './component'; @@ -92,8 +90,6 @@ export const CheckCapturedArguments: Checker = CheckInterface named: wrap(() => CheckDict(CheckReference)), }); -export const CheckScope: Checker = wrap(() => CheckInstanceof(PartialScopeImpl)); - export const CheckComponentManager: Checker> = CheckInterface({ getCapabilities: CheckFunction, }); diff --git a/packages/@glimmer/runtime/lib/scope.ts b/packages/@glimmer/runtime/lib/scope.ts index 44226d4e86..9391262108 100644 --- a/packages/@glimmer/runtime/lib/scope.ts +++ b/packages/@glimmer/runtime/lib/scope.ts @@ -1,15 +1,9 @@ import type { Dict, DynamicScope, - Nullable, - Owner, - PartialScope, - Scope, - ScopeBlock, ScopeSlot, } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; -import { UNDEFINED_REFERENCE } from '@glimmer/reference'; import { assign, unwrap } from '@glimmer/util'; export class DynamicScopeImpl implements DynamicScope { @@ -40,112 +34,3 @@ export function isScopeReference(s: ScopeSlot): s is Reference { if (s === null || Array.isArray(s)) return false; return true; } - -export class PartialScopeImpl implements PartialScope { - static root(self: Reference, size = 0, owner: Owner): PartialScope { - let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - - return new PartialScopeImpl(refs, owner, null, null, null).init({ self }); - } - - static sized(size = 0, owner: Owner): Scope { - let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - - return new PartialScopeImpl(refs, owner, null, null, null); - } - - constructor( - // the 0th slot is `self` - readonly slots: Array, - readonly owner: Owner, - private callerScope: Scope | null, - // named arguments and blocks passed to a layout that uses eval - private evalScope: Dict | null, - // locals in scope when the partial was invoked - private partialMap: Dict> | null - ) {} - - init({ self }: { self: Reference }): this { - this.slots[0] = self; - return this; - } - - getSelf(): Reference { - return this.get>(0); - } - - getSymbol(symbol: number): Reference { - return this.get>(symbol); - } - - getBlock(symbol: number): Nullable { - let block = this.get(symbol); - return block === UNDEFINED_REFERENCE ? null : (block as ScopeBlock); - } - - getEvalScope(): Nullable> { - return this.evalScope; - } - - getPartialMap(): Nullable>> { - return this.partialMap; - } - - bind(symbol: number, value: ScopeSlot) { - this.set(symbol, value); - } - - bindSelf(self: Reference) { - this.set>(0, self); - } - - bindSymbol(symbol: number, value: Reference) { - this.set(symbol, value); - } - - bindBlock(symbol: number, value: Nullable) { - this.set>(symbol, value); - } - - bindEvalScope(map: Nullable>) { - this.evalScope = map; - } - - bindPartialMap(map: Dict>) { - this.partialMap = map; - } - - bindCallerScope(scope: Nullable): void { - this.callerScope = scope; - } - - getCallerScope(): Nullable { - return this.callerScope; - } - - child(): Scope { - return new PartialScopeImpl( - this.slots.slice(), - this.owner, - this.callerScope, - this.evalScope, - this.partialMap - ); - } - - private get(index: number): T { - if (index >= this.slots.length) { - throw new RangeError(`BUG: cannot get $${index} from scope; length=${this.slots.length}`); - } - - return this.slots[index] as T; - } - - private set(index: number, value: T): void { - if (index >= this.slots.length) { - throw new RangeError(`BUG: cannot get $${index} from scope; length=${this.slots.length}`); - } - - this.slots[index] = value; - } -} diff --git a/packages/@glimmer/runtime/lib/vm/append.ts b/packages/@glimmer/runtime/lib/vm/append.ts index 352341d390..1f86766b2f 100644 --- a/packages/@glimmer/runtime/lib/vm/append.ts +++ b/packages/@glimmer/runtime/lib/vm/append.ts @@ -7,7 +7,6 @@ import type { Environment, Nullable, Owner, - PartialScope, RenderResult, ResolutionTimeConstants, RichIteratorResult, @@ -41,7 +40,6 @@ import { JumpIfNotModifiedOpcode, } from '../compiled/opcodes/vm'; import { APPEND_OPCODES } from '../opcodes'; -import { PartialScopeImpl } from '../scope'; import { ARGS, CONSTANTS, DESTROYABLE_STACK, HEAP, INNER_VM, REGISTERS, STACKS } from '../symbols'; import { VMArgumentsImpl } from './arguments'; import { LowLevelVM } from './low-level'; @@ -96,7 +94,6 @@ export interface InternalVM { enterItem(item: OpaqueIterationItem): ListItemOpcode; registerItem(item: ListItemOpcode): void; - pushRootScope(size: number, owner: Owner): PartialScope; pushChildScope(): void; popScope(): void; pushScope(scope: Scope): void; From 7d07ae9cd699803df5de2d96fcd84c0d7cbf3c9e Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:51:33 -0500 Subject: [PATCH 2/5] Revert "Remove support for Partials" This reverts commit 3d698b8b8a7e57a1605e7e1c42e1f3a784584627. --- .../interfaces/lib/runtime/scope.d.ts | 6 + packages/@glimmer/runtime/index.ts | 2 +- .../lib/compiled/opcodes/-debug-strip.ts | 4 + packages/@glimmer/runtime/lib/scope.ts | 115 ++++++++++++++++++ packages/@glimmer/runtime/lib/vm/append.ts | 3 + 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts index 4fbba75236..bfbc950fa2 100644 --- a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts +++ b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts @@ -19,14 +19,20 @@ export interface Scope { getSymbol(symbol: number): Reference; getBlock(symbol: number): Nullable; getEvalScope(): Nullable>; + getPartialMap(): Nullable>; bind(symbol: number, value: ScopeSlot): void; bindSelf(self: Reference): void; bindSymbol(symbol: number, value: Reference): void; bindBlock(symbol: number, value: Nullable): void; bindEvalScope(map: Nullable>): void; + bindPartialMap(map: Dict): void; child(): Scope; } +export interface PartialScope extends Scope { + bindEvalScope(scope: Nullable>): void; +} + export interface DynamicScope { get(key: string): Reference; set(key: string, reference: Reference): Reference; diff --git a/packages/@glimmer/runtime/index.ts b/packages/@glimmer/runtime/index.ts index 131c70cccb..0c80f9eceb 100644 --- a/packages/@glimmer/runtime/index.ts +++ b/packages/@glimmer/runtime/index.ts @@ -39,7 +39,7 @@ export { hash } from './lib/helpers/hash'; export { invokeHelper } from './lib/helpers/invoke'; export { on } from './lib/modifiers/on'; export { renderComponent, renderMain, renderSync } from './lib/render'; -export { DynamicScopeImpl } from './lib/scope'; +export { DynamicScopeImpl, PartialScopeImpl } from './lib/scope'; export type { SafeString } from './lib/upsert'; export { type InternalVM, VM as LowLevelVM, UpdatingVM } from './lib/vm'; export { diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts index 68e0220bec..4bad535c78 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts @@ -11,6 +11,7 @@ import type { InternalComponentManager, Invocation, Nullable, + Scope, ScopeBlock, } from '@glimmer/interfaces'; import type { OpaqueIterator, Reference } from '@glimmer/reference'; @@ -35,6 +36,7 @@ import { import { REFERENCE, UNDEFINED_REFERENCE } from '@glimmer/reference'; import { COMPUTE } from '@glimmer/validator'; +import { PartialScopeImpl } from '../../scope'; import { VMArgumentsImpl } from '../../vm/arguments'; import { ComponentElementOperations } from './component'; @@ -90,6 +92,8 @@ export const CheckCapturedArguments: Checker = CheckInterface named: wrap(() => CheckDict(CheckReference)), }); +export const CheckScope: Checker = wrap(() => CheckInstanceof(PartialScopeImpl)); + export const CheckComponentManager: Checker> = CheckInterface({ getCapabilities: CheckFunction, }); diff --git a/packages/@glimmer/runtime/lib/scope.ts b/packages/@glimmer/runtime/lib/scope.ts index 9391262108..44226d4e86 100644 --- a/packages/@glimmer/runtime/lib/scope.ts +++ b/packages/@glimmer/runtime/lib/scope.ts @@ -1,9 +1,15 @@ import type { Dict, DynamicScope, + Nullable, + Owner, + PartialScope, + Scope, + ScopeBlock, ScopeSlot, } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; +import { UNDEFINED_REFERENCE } from '@glimmer/reference'; import { assign, unwrap } from '@glimmer/util'; export class DynamicScopeImpl implements DynamicScope { @@ -34,3 +40,112 @@ export function isScopeReference(s: ScopeSlot): s is Reference { if (s === null || Array.isArray(s)) return false; return true; } + +export class PartialScopeImpl implements PartialScope { + static root(self: Reference, size = 0, owner: Owner): PartialScope { + let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); + + return new PartialScopeImpl(refs, owner, null, null, null).init({ self }); + } + + static sized(size = 0, owner: Owner): Scope { + let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); + + return new PartialScopeImpl(refs, owner, null, null, null); + } + + constructor( + // the 0th slot is `self` + readonly slots: Array, + readonly owner: Owner, + private callerScope: Scope | null, + // named arguments and blocks passed to a layout that uses eval + private evalScope: Dict | null, + // locals in scope when the partial was invoked + private partialMap: Dict> | null + ) {} + + init({ self }: { self: Reference }): this { + this.slots[0] = self; + return this; + } + + getSelf(): Reference { + return this.get>(0); + } + + getSymbol(symbol: number): Reference { + return this.get>(symbol); + } + + getBlock(symbol: number): Nullable { + let block = this.get(symbol); + return block === UNDEFINED_REFERENCE ? null : (block as ScopeBlock); + } + + getEvalScope(): Nullable> { + return this.evalScope; + } + + getPartialMap(): Nullable>> { + return this.partialMap; + } + + bind(symbol: number, value: ScopeSlot) { + this.set(symbol, value); + } + + bindSelf(self: Reference) { + this.set>(0, self); + } + + bindSymbol(symbol: number, value: Reference) { + this.set(symbol, value); + } + + bindBlock(symbol: number, value: Nullable) { + this.set>(symbol, value); + } + + bindEvalScope(map: Nullable>) { + this.evalScope = map; + } + + bindPartialMap(map: Dict>) { + this.partialMap = map; + } + + bindCallerScope(scope: Nullable): void { + this.callerScope = scope; + } + + getCallerScope(): Nullable { + return this.callerScope; + } + + child(): Scope { + return new PartialScopeImpl( + this.slots.slice(), + this.owner, + this.callerScope, + this.evalScope, + this.partialMap + ); + } + + private get(index: number): T { + if (index >= this.slots.length) { + throw new RangeError(`BUG: cannot get $${index} from scope; length=${this.slots.length}`); + } + + return this.slots[index] as T; + } + + private set(index: number, value: T): void { + if (index >= this.slots.length) { + throw new RangeError(`BUG: cannot get $${index} from scope; length=${this.slots.length}`); + } + + this.slots[index] = value; + } +} diff --git a/packages/@glimmer/runtime/lib/vm/append.ts b/packages/@glimmer/runtime/lib/vm/append.ts index 1f86766b2f..352341d390 100644 --- a/packages/@glimmer/runtime/lib/vm/append.ts +++ b/packages/@glimmer/runtime/lib/vm/append.ts @@ -7,6 +7,7 @@ import type { Environment, Nullable, Owner, + PartialScope, RenderResult, ResolutionTimeConstants, RichIteratorResult, @@ -40,6 +41,7 @@ import { JumpIfNotModifiedOpcode, } from '../compiled/opcodes/vm'; import { APPEND_OPCODES } from '../opcodes'; +import { PartialScopeImpl } from '../scope'; import { ARGS, CONSTANTS, DESTROYABLE_STACK, HEAP, INNER_VM, REGISTERS, STACKS } from '../symbols'; import { VMArgumentsImpl } from './arguments'; import { LowLevelVM } from './low-level'; @@ -94,6 +96,7 @@ export interface InternalVM { enterItem(item: OpaqueIterationItem): ListItemOpcode; registerItem(item: ListItemOpcode): void; + pushRootScope(size: number, owner: Owner): PartialScope; pushChildScope(): void; popScope(): void; pushScope(scope: Scope): void; From e1887e9332e8273ff21e8d82b6b7c57d79937b05 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:23:32 -0500 Subject: [PATCH 3/5] Remove bindEval and evalScope --- bin/opcodes.json | 1 - .../@glimmer/debug/lib/opcode-metadata.ts | 30 ------------------- .../interfaces/lib/runtime/scope.d.ts | 4 +-- .../@glimmer/interfaces/lib/vm-opcodes.d.ts | 4 --- .../lib/opcode-builder/helpers/components.ts | 1 - .../runtime/lib/compiled/opcodes/component.ts | 9 ------ .../runtime/lib/compiled/opcodes/debugger.ts | 5 +--- packages/@glimmer/runtime/lib/scope.ts | 15 ++-------- packages/@glimmer/vm/lib/opcodes.toml | 10 ------- packages/@glimmer/vm/lib/opcodes.ts | 4 --- 10 files changed, 4 insertions(+), 79 deletions(-) diff --git a/bin/opcodes.json b/bin/opcodes.json index 66dd0efa4a..afdddbafb8 100644 --- a/bin/opcodes.json +++ b/bin/opcodes.json @@ -91,7 +91,6 @@ "GetComponentSelf", "GetComponentTagName", "GetComponentLayout", - "SetupForEval", "PopulateLayout", "InvokeComponentLayout", "BeginComponentTransaction", diff --git a/packages/@glimmer/debug/lib/opcode-metadata.ts b/packages/@glimmer/debug/lib/opcode-metadata.ts index c559bf57d3..7ceba4aef4 100644 --- a/packages/@glimmer/debug/lib/opcode-metadata.ts +++ b/packages/@glimmer/debug/lib/opcode-metadata.ts @@ -1187,36 +1187,6 @@ METADATA[Op.GetComponentLayout] = { check: true, }; -METADATA[Op.BindEvalScope] = { - name: 'BindEvalScope', - mnemonic: 'eval_scope', - before: null, - stackChange: 0, - ops: [ - { - name: 'state', - type: 'register', - }, - ], - operands: 1, - check: true, -}; - -METADATA[Op.SetupForEval] = { - name: 'SetupForEval', - mnemonic: 'eval_setup', - before: null, - stackChange: 0, - ops: [ - { - name: 'state', - type: 'register', - }, - ], - operands: 1, - check: true, -}; - METADATA[Op.PopulateLayout] = { name: 'PopulateLayout', mnemonic: 'comp_layoutput', diff --git a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts index bfbc950fa2..b310b04640 100644 --- a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts +++ b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts @@ -18,19 +18,17 @@ export interface Scope { getSelf(): Reference; getSymbol(symbol: number): Reference; getBlock(symbol: number): Nullable; - getEvalScope(): Nullable>; getPartialMap(): Nullable>; bind(symbol: number, value: ScopeSlot): void; bindSelf(self: Reference): void; bindSymbol(symbol: number, value: Reference): void; bindBlock(symbol: number, value: Nullable): void; - bindEvalScope(map: Nullable>): void; bindPartialMap(map: Dict): void; child(): Scope; } export interface PartialScope extends Scope { - bindEvalScope(scope: Nullable>): void; + // FIXME remove this } export interface DynamicScope { diff --git a/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts b/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts index c428f832fc..79aa8ea964 100644 --- a/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts +++ b/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts @@ -96,8 +96,6 @@ export type VmPutComponentOperations = 89; export type VmGetComponentSelf = 90; export type VmGetComponentTagName = 91; export type VmGetComponentLayout = 92; -export type VmBindEvalScope = 93; -export type VmSetupForEval = 94; export type VmPopulateLayout = 95; export type VmInvokeComponentLayout = 96; export type VmBeginComponentTransaction = 97; @@ -194,8 +192,6 @@ export type VmOp = | VmGetComponentSelf | VmGetComponentTagName | VmGetComponentLayout - | VmBindEvalScope - | VmSetupForEval | VmPopulateLayout | VmInvokeComponentLayout | VmBeginComponentTransaction diff --git a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts index 2273c88eaf..294b11d70c 100644 --- a/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts +++ b/packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts @@ -414,7 +414,6 @@ export function invokePreparedComponent( op(Op.VirtualRootScope, $s0); op(Op.SetVariable, 0); - op(Op.SetupForEval, $s0); if (bindableAtNames) op(Op.SetNamedVariables, $s0); if (bindableBlocks) op(Op.SetBlocks, $s0); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index 36749bf03c..c6a5508010 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -766,15 +766,6 @@ APPEND_OPCODES.add(Op.VirtualRootScope, (vm, { op1: _state }) => { vm.pushRootScope(table.symbols.length + 1, owner); }); -APPEND_OPCODES.add(Op.SetupForEval, (vm, { op1: _state }) => { - let state = check(vm.fetchValue(_state), CheckFinishedComponentInstance); - - if (state.table.hasEval) { - let lookup = (state.lookup = dict()); - vm.scope().bindEvalScope(lookup); - } -}); - APPEND_OPCODES.add(Op.SetNamedVariables, (vm, { op1: _state }) => { let state = check(vm.fetchValue(_state), CheckFinishedComponentInstance); let scope = vm.scope(); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts index 84e40231ac..b50a13129d 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts @@ -52,16 +52,13 @@ class ScopeInspector { let { scope, locals } = this; let parts = path.split('.'); let [head, ...tail] = path.split('.') as [string, ...string[]]; - - let evalScope = scope.getEvalScope()!; let ref: Reference; if (head === 'this') { ref = scope.getSelf(); } else if (locals[head]) { ref = unwrap(locals[head]); - } else if (head.indexOf('@') === 0 && evalScope[head]) { - ref = evalScope[head] as Reference; + // FIXME restore get("@foo") functionality } else { ref = this.scope.getSelf(); tail = parts; diff --git a/packages/@glimmer/runtime/lib/scope.ts b/packages/@glimmer/runtime/lib/scope.ts index 44226d4e86..721e23c914 100644 --- a/packages/@glimmer/runtime/lib/scope.ts +++ b/packages/@glimmer/runtime/lib/scope.ts @@ -45,13 +45,13 @@ export class PartialScopeImpl implements PartialScope { static root(self: Reference, size = 0, owner: Owner): PartialScope { let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - return new PartialScopeImpl(refs, owner, null, null, null).init({ self }); + return new PartialScopeImpl(refs, owner, null, null).init({ self }); } static sized(size = 0, owner: Owner): Scope { let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - return new PartialScopeImpl(refs, owner, null, null, null); + return new PartialScopeImpl(refs, owner, null, null); } constructor( @@ -59,8 +59,6 @@ export class PartialScopeImpl implements PartialScope { readonly slots: Array, readonly owner: Owner, private callerScope: Scope | null, - // named arguments and blocks passed to a layout that uses eval - private evalScope: Dict | null, // locals in scope when the partial was invoked private partialMap: Dict> | null ) {} @@ -83,10 +81,6 @@ export class PartialScopeImpl implements PartialScope { return block === UNDEFINED_REFERENCE ? null : (block as ScopeBlock); } - getEvalScope(): Nullable> { - return this.evalScope; - } - getPartialMap(): Nullable>> { return this.partialMap; } @@ -107,10 +101,6 @@ export class PartialScopeImpl implements PartialScope { this.set>(symbol, value); } - bindEvalScope(map: Nullable>) { - this.evalScope = map; - } - bindPartialMap(map: Dict>) { this.partialMap = map; } @@ -128,7 +118,6 @@ export class PartialScopeImpl implements PartialScope { this.slots.slice(), this.owner, this.callerScope, - this.evalScope, this.partialMap ); } diff --git a/packages/@glimmer/vm/lib/opcodes.toml b/packages/@glimmer/vm/lib/opcodes.toml index 6648e3ccaa..8fdf4ccb61 100644 --- a/packages/@glimmer/vm/lib/opcodes.toml +++ b/packages/@glimmer/vm/lib/opcodes.toml @@ -834,16 +834,6 @@ operand-stack = [ ["ProgramSymbolTable", "handle"] ] -[syscall.eval_scope] - -format = ["BindEvalScope", "state:register"] -operation = "Populate the eval lookup if necessary." - -[syscall.eval_setup] - -format = ["SetupForEval", "state:register"] -operation = "Setup for eval" - [syscall.comp_layoutput] format = ["PopulateLayout", "state:register"] diff --git a/packages/@glimmer/vm/lib/opcodes.ts b/packages/@glimmer/vm/lib/opcodes.ts index 165c041c4b..4220f45113 100644 --- a/packages/@glimmer/vm/lib/opcodes.ts +++ b/packages/@glimmer/vm/lib/opcodes.ts @@ -7,7 +7,6 @@ import type { VmAssertSame, VmBeginComponentTransaction, VmBindDynamicScope, - VmBindEvalScope, VmCaptureArgs, VmChildScope, VmCloseElement, @@ -96,7 +95,6 @@ import type { VmSetBlock, VmSetBlocks, VmSetNamedVariables, - VmSetupForEval, VmSetVariable, VmSize, VmSpreadBlock, @@ -196,8 +194,6 @@ export const Op = { GetComponentSelf: 90 satisfies VmGetComponentSelf, GetComponentTagName: 91 satisfies VmGetComponentTagName, GetComponentLayout: 92 satisfies VmGetComponentLayout, - BindEvalScope: 93 satisfies VmBindEvalScope, - SetupForEval: 94 satisfies VmSetupForEval, PopulateLayout: 95 satisfies VmPopulateLayout, InvokeComponentLayout: 96 satisfies VmInvokeComponentLayout, BeginComponentTransaction: 97 satisfies VmBeginComponentTransaction, From 95470fc77b5d2be0ba045b6bc947ab03b200923c Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:35:48 -0500 Subject: [PATCH 4/5] Remove more partial, rename PartialScope to Scope --- .../@glimmer/debug/lib/opcode-metadata.ts | 15 ----------- .../interfaces/lib/runtime/scope.d.ts | 8 +----- .../@glimmer/interfaces/lib/vm-opcodes.d.ts | 2 -- packages/@glimmer/runtime/index.ts | 2 +- .../lib/compiled/opcodes/-debug-strip.ts | 4 +-- .../lib/compiled/opcodes/expressions.ts | 12 --------- packages/@glimmer/runtime/lib/scope.ts | 27 +++++++------------ packages/@glimmer/runtime/lib/vm/append.ts | 13 +++++---- packages/@glimmer/vm/lib/opcodes.toml | 12 --------- packages/@glimmer/vm/lib/opcodes.ts | 2 -- 10 files changed, 19 insertions(+), 78 deletions(-) diff --git a/packages/@glimmer/debug/lib/opcode-metadata.ts b/packages/@glimmer/debug/lib/opcode-metadata.ts index 7ceba4aef4..1d25b42946 100644 --- a/packages/@glimmer/debug/lib/opcode-metadata.ts +++ b/packages/@glimmer/debug/lib/opcode-metadata.ts @@ -1267,21 +1267,6 @@ METADATA[Op.DidRenderLayout] = { check: true, }; -METADATA[Op.ResolveMaybeLocal] = { - name: 'ResolveMaybeLocal', - mnemonic: 'eval_varload', - before: null, - stackChange: 1, - ops: [ - { - name: 'local', - type: 'str', - }, - ], - operands: 1, - check: true, -}; - METADATA[Op.Debugger] = { name: 'Debugger', mnemonic: 'debugger', diff --git a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts index b310b04640..1931179fb9 100644 --- a/packages/@glimmer/interfaces/lib/runtime/scope.d.ts +++ b/packages/@glimmer/interfaces/lib/runtime/scope.d.ts @@ -1,4 +1,4 @@ -import type { Dict, Nullable } from '../core.js'; +import type { Nullable } from '../core.js'; import type { Reference } from '../references.js'; import type { CompilableBlock } from '../template.js'; import type { BlockSymbolTable } from '../tier1/symbol-table.js'; @@ -18,19 +18,13 @@ export interface Scope { getSelf(): Reference; getSymbol(symbol: number): Reference; getBlock(symbol: number): Nullable; - getPartialMap(): Nullable>; bind(symbol: number, value: ScopeSlot): void; bindSelf(self: Reference): void; bindSymbol(symbol: number, value: Reference): void; bindBlock(symbol: number, value: Nullable): void; - bindPartialMap(map: Dict): void; child(): Scope; } -export interface PartialScope extends Scope { - // FIXME remove this -} - export interface DynamicScope { get(key: string): Reference; set(key: string, reference: Reference): Reference; diff --git a/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts b/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts index 79aa8ea964..e9fe26a9f6 100644 --- a/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts +++ b/packages/@glimmer/interfaces/lib/vm-opcodes.d.ts @@ -102,7 +102,6 @@ export type VmBeginComponentTransaction = 97; export type VmCommitComponentTransaction = 98; export type VmDidCreateElement = 99; export type VmDidRenderLayout = 100; -export type VmResolveMaybeLocal = 102; export type VmDebugger = 103; export type VmSize = 104; export type VmStaticComponentAttr = 105; @@ -198,7 +197,6 @@ export type VmOp = | VmCommitComponentTransaction | VmDidCreateElement | VmDidRenderLayout - | VmResolveMaybeLocal | VmDebugger | VmSize | VmStaticComponentAttr diff --git a/packages/@glimmer/runtime/index.ts b/packages/@glimmer/runtime/index.ts index 0c80f9eceb..ed20c1e2c2 100644 --- a/packages/@glimmer/runtime/index.ts +++ b/packages/@glimmer/runtime/index.ts @@ -39,7 +39,7 @@ export { hash } from './lib/helpers/hash'; export { invokeHelper } from './lib/helpers/invoke'; export { on } from './lib/modifiers/on'; export { renderComponent, renderMain, renderSync } from './lib/render'; -export { DynamicScopeImpl, PartialScopeImpl } from './lib/scope'; +export { DynamicScopeImpl, ScopeImpl } from './lib/scope'; export type { SafeString } from './lib/upsert'; export { type InternalVM, VM as LowLevelVM, UpdatingVM } from './lib/vm'; export { diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts index 4bad535c78..12f59c0426 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.ts @@ -36,7 +36,7 @@ import { import { REFERENCE, UNDEFINED_REFERENCE } from '@glimmer/reference'; import { COMPUTE } from '@glimmer/validator'; -import { PartialScopeImpl } from '../../scope'; +import { ScopeImpl } from '../../scope'; import { VMArgumentsImpl } from '../../vm/arguments'; import { ComponentElementOperations } from './component'; @@ -92,7 +92,7 @@ export const CheckCapturedArguments: Checker = CheckInterface named: wrap(() => CheckDict(CheckReference)), }); -export const CheckScope: Checker = wrap(() => CheckInstanceof(PartialScopeImpl)); +export const CheckScope: Checker = wrap(() => CheckInstanceof(ScopeImpl)); export const CheckComponentManager: Checker> = CheckInterface({ getCapabilities: CheckFunction, diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts index 2fa7af7475..633276bd13 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts @@ -181,18 +181,6 @@ APPEND_OPCODES.add(Op.SetBlock, (vm, { op1: symbol }) => { vm.scope().bindBlock(symbol, [handle, scope, table]); }); -APPEND_OPCODES.add(Op.ResolveMaybeLocal, (vm, { op1: _name }) => { - let name = vm[CONSTANTS].getValue(_name); - let locals = vm.scope().getPartialMap()!; - - let ref = locals[name]; - if (ref === undefined) { - ref = childRefFor(vm.getSelf(), name); - } - - vm.stack.push(ref); -}); - APPEND_OPCODES.add(Op.RootScope, (vm, { op1: symbols }) => { vm.pushRootScope(symbols, vm.getOwner()); }); diff --git a/packages/@glimmer/runtime/lib/scope.ts b/packages/@glimmer/runtime/lib/scope.ts index 721e23c914..71ef1288fb 100644 --- a/packages/@glimmer/runtime/lib/scope.ts +++ b/packages/@glimmer/runtime/lib/scope.ts @@ -3,7 +3,6 @@ import type { DynamicScope, Nullable, Owner, - PartialScope, Scope, ScopeBlock, ScopeSlot, @@ -41,27 +40,28 @@ export function isScopeReference(s: ScopeSlot): s is Reference { return true; } -export class PartialScopeImpl implements PartialScope { - static root(self: Reference, size = 0, owner: Owner): PartialScope { +export class ScopeImpl implements Scope { + static root(self: Reference, size = 0, owner: Owner): Scope { let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - return new PartialScopeImpl(refs, owner, null, null).init({ self }); + return new ScopeImpl(refs, owner, null).init({ self }); } static sized(size = 0, owner: Owner): Scope { let refs: Reference[] = new Array(size + 1).fill(UNDEFINED_REFERENCE); - return new PartialScopeImpl(refs, owner, null, null); + return new ScopeImpl(refs, owner, null); } constructor( // the 0th slot is `self` readonly slots: Array, readonly owner: Owner, - private callerScope: Scope | null, - // locals in scope when the partial was invoked - private partialMap: Dict> | null + private callerScope: Scope | null ) {} + getPartialMap(): Nullable>> { + throw new Error('Method not implemented.'); + } init({ self }: { self: Reference }): this { this.slots[0] = self; @@ -81,10 +81,6 @@ export class PartialScopeImpl implements PartialScope { return block === UNDEFINED_REFERENCE ? null : (block as ScopeBlock); } - getPartialMap(): Nullable>> { - return this.partialMap; - } - bind(symbol: number, value: ScopeSlot) { this.set(symbol, value); } @@ -101,10 +97,6 @@ export class PartialScopeImpl implements PartialScope { this.set>(symbol, value); } - bindPartialMap(map: Dict>) { - this.partialMap = map; - } - bindCallerScope(scope: Nullable): void { this.callerScope = scope; } @@ -114,11 +106,10 @@ export class PartialScopeImpl implements PartialScope { } child(): Scope { - return new PartialScopeImpl( + return new ScopeImpl( this.slots.slice(), this.owner, this.callerScope, - this.partialMap ); } diff --git a/packages/@glimmer/runtime/lib/vm/append.ts b/packages/@glimmer/runtime/lib/vm/append.ts index 352341d390..76d7b5018d 100644 --- a/packages/@glimmer/runtime/lib/vm/append.ts +++ b/packages/@glimmer/runtime/lib/vm/append.ts @@ -7,7 +7,6 @@ import type { Environment, Nullable, Owner, - PartialScope, RenderResult, ResolutionTimeConstants, RichIteratorResult, @@ -41,7 +40,7 @@ import { JumpIfNotModifiedOpcode, } from '../compiled/opcodes/vm'; import { APPEND_OPCODES } from '../opcodes'; -import { PartialScopeImpl } from '../scope'; +import { ScopeImpl } from '../scope'; import { ARGS, CONSTANTS, DESTROYABLE_STACK, HEAP, INNER_VM, REGISTERS, STACKS } from '../symbols'; import { VMArgumentsImpl } from './arguments'; import { LowLevelVM } from './low-level'; @@ -96,7 +95,7 @@ export interface InternalVM { enterItem(item: OpaqueIterationItem): ListItemOpcode; registerItem(item: ListItemOpcode): void; - pushRootScope(size: number, owner: Owner): PartialScope; + pushRootScope(size: number, owner: Owner): Scope; pushChildScope(): void; popScope(): void; pushScope(scope: Scope): void; @@ -303,7 +302,7 @@ export class VM implements PublicVM, InternalVM { context: CompileTimeCompilationContext, { handle, self, dynamicScope, treeBuilder, numSymbols, owner }: InitOptions ) { - let scope = PartialScopeImpl.root(self, numSymbols, owner); + let scope = ScopeImpl.root(self, numSymbols, owner); let state = vmState(runtime.program.heap.getaddr(handle), scope, dynamicScope); let vm = initVM(context)(runtime, state, treeBuilder); vm.pushUpdating(); @@ -319,7 +318,7 @@ export class VM implements PublicVM, InternalVM { runtime, vmState( runtime.program.heap.getaddr(handle), - PartialScopeImpl.root(UNDEFINED_REFERENCE, 0, owner), + ScopeImpl.root(UNDEFINED_REFERENCE, 0, owner), dynamicScope ), treeBuilder @@ -500,8 +499,8 @@ export class VM implements PublicVM, InternalVM { return child; } - pushRootScope(size: number, owner: Owner): PartialScope { - let scope = PartialScopeImpl.sized(size, owner); + pushRootScope(size: number, owner: Owner): Scope { + let scope = ScopeImpl.sized(size, owner); this[STACKS].scope.push(scope); return scope; } diff --git a/packages/@glimmer/vm/lib/opcodes.toml b/packages/@glimmer/vm/lib/opcodes.toml index 8fdf4ccb61..ade542cace 100644 --- a/packages/@glimmer/vm/lib/opcodes.toml +++ b/packages/@glimmer/vm/lib/opcodes.toml @@ -875,18 +875,6 @@ operation = "Invoke didCreateElement on the current component manager" format = ["DidRenderLayout", "state:register"] operation = "Invoke didRenderLayout on the current component manager" -[syscall.eval_varload] - -format = ["ResolveMaybeLocal", "local:str"] -operation = """ -Resolve {{foo}} inside a partial, which could be either a self-lookup -or a local variable that is in-scope for the caller. -""" -operand-stack = [ - [], - ["Reference"] -] - [syscall.debugger] format = ["Debugger", "symbols:str-array", "debugInfo:array"] diff --git a/packages/@glimmer/vm/lib/opcodes.ts b/packages/@glimmer/vm/lib/opcodes.ts index 4220f45113..320e670abc 100644 --- a/packages/@glimmer/vm/lib/opcodes.ts +++ b/packages/@glimmer/vm/lib/opcodes.ts @@ -90,7 +90,6 @@ import type { VmReifyU32, VmResolveCurriedComponent, VmResolveDynamicComponent, - VmResolveMaybeLocal, VmRootScope, VmSetBlock, VmSetBlocks, @@ -200,7 +199,6 @@ export const Op = { CommitComponentTransaction: 98 satisfies VmCommitComponentTransaction, DidCreateElement: 99 satisfies VmDidCreateElement, DidRenderLayout: 100 satisfies VmDidRenderLayout, - ResolveMaybeLocal: 102 satisfies VmResolveMaybeLocal, Debugger: 103 satisfies VmDebugger, Size: 104 satisfies VmSize, StaticComponentAttr: 105 satisfies VmStaticComponentAttr, From 7f9a6c5ab1e9b8ad17e61bb0a0951c1981d69539 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:42:46 -0500 Subject: [PATCH 5/5] lintfix --- packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts | 2 +- packages/@glimmer/runtime/lib/scope.ts | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts index b50a13129d..1aca4305e6 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts @@ -58,7 +58,7 @@ class ScopeInspector { ref = scope.getSelf(); } else if (locals[head]) { ref = unwrap(locals[head]); - // FIXME restore get("@foo") functionality + // FIXME restore get("@foo") functionality } else { ref = this.scope.getSelf(); tail = parts; diff --git a/packages/@glimmer/runtime/lib/scope.ts b/packages/@glimmer/runtime/lib/scope.ts index 71ef1288fb..60e662376c 100644 --- a/packages/@glimmer/runtime/lib/scope.ts +++ b/packages/@glimmer/runtime/lib/scope.ts @@ -106,11 +106,7 @@ export class ScopeImpl implements Scope { } child(): Scope { - return new ScopeImpl( - this.slots.slice(), - this.owner, - this.callerScope, - ); + return new ScopeImpl(this.slots.slice(), this.owner, this.callerScope); } private get(index: number): T {