From 5425734c5693959e66ac52fc97c7ebb3aa766ece Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:31:03 -0400 Subject: [PATCH 1/6] Remove two function calls --- packages/@glimmer/runtime/lib/vm/append.ts | 28 +++++++++++++++++-- packages/@glimmer/runtime/lib/vm/low-level.ts | 22 --------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/packages/@glimmer/runtime/lib/vm/append.ts b/packages/@glimmer/runtime/lib/vm/append.ts index 352341d390..25a80d031d 100644 --- a/packages/@glimmer/runtime/lib/vm/append.ts +++ b/packages/@glimmer/runtime/lib/vm/append.ts @@ -24,7 +24,7 @@ import type { OpaqueIterationItem, OpaqueIterator, Reference } from '@glimmer/re import type { MachineRegister, Register, SyscallRegister } from '@glimmer/vm'; import { associateDestroyableChild } from '@glimmer/destroyable'; import { assertGlobalContextWasSet } from '@glimmer/global-context'; -import { LOCAL_SHOULD_LOG } from '@glimmer/local-debug-flags'; +import { LOCAL_DEBUG, LOCAL_SHOULD_LOG } from '@glimmer/local-debug-flags'; import { createIteratorItemRef, UNDEFINED_REFERENCE } from '@glimmer/reference'; import { assert, expect, LOCAL_LOGGER, reverse, Stack, unwrapHandle } from '@glimmer/util'; import { beginTrackFrame, endTrackFrame, resetTracking } from '@glimmer/validator'; @@ -584,7 +584,31 @@ export class VM implements PublicVM, InternalVM { let opcode = this[INNER_VM].nextStatement(); let result: RichIteratorResult; if (opcode !== null) { - this[INNER_VM].evaluateOuter(opcode, this); + if (LOCAL_DEBUG) { + // These functions are arrows defined in *this* file. + // We don't need to worry about unbound thises + // eslint-disable-next-line @typescript-eslint/unbound-method + let debugBefore = this[INNER_VM].externs.debugBefore; + // eslint-disable-next-line @typescript-eslint/unbound-method + let debugAfter = this[INNER_VM].externs.debugAfter; + + let state = debugBefore(opcode); + + if (opcode.isMachine) { + this[INNER_VM].evaluateMachine(opcode); + } else { + this[INNER_VM].evaluateSyscall(opcode, this); + } + + debugAfter(state); + } else { + if (opcode.isMachine) { + this[INNER_VM].evaluateMachine(opcode); + } else { + this[INNER_VM].evaluateSyscall(opcode, this); + } + } + result = { done: false, value: null }; } else { // Unload the stack diff --git a/packages/@glimmer/runtime/lib/vm/low-level.ts b/packages/@glimmer/runtime/lib/vm/low-level.ts index 219577e30b..5fd5dfcb75 100644 --- a/packages/@glimmer/runtime/lib/vm/low-level.ts +++ b/packages/@glimmer/runtime/lib/vm/low-level.ts @@ -1,6 +1,5 @@ import type { Nullable, RuntimeHeap, RuntimeOp, RuntimeProgram } from '@glimmer/interfaces'; import type { MachineRegister } from '@glimmer/vm'; -import { LOCAL_DEBUG } from '@glimmer/local-debug-flags'; import { assert } from '@glimmer/util'; import { $fp, $pc, $ra, $sp, MachineOp } from '@glimmer/vm'; @@ -134,27 +133,6 @@ export class LowLevelVM { return opcode; } - evaluateOuter(opcode: RuntimeOp, vm: VM) { - if (LOCAL_DEBUG) { - let { - externs: { debugBefore, debugAfter }, - } = this; - let state = debugBefore(opcode); - this.evaluateInner(opcode, vm); - debugAfter(state); - } else { - this.evaluateInner(opcode, vm); - } - } - - evaluateInner(opcode: RuntimeOp, vm: VM) { - if (opcode.isMachine) { - this.evaluateMachine(opcode); - } else { - this.evaluateSyscall(opcode, vm); - } - } - evaluateMachine(opcode: RuntimeOp) { switch (opcode.type) { case MachineOp.PushFrame: From e3986f9ed856693b9624e083cd0985c90facbb69 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:39:16 -0400 Subject: [PATCH 2/6] Remove some checks --- .../runtime/lib/compiled/opcodes/dom.ts | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts index f575240eb5..51827a733f 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts @@ -1,24 +1,19 @@ import type { CapturedPositionalArguments, Environment, + Maybe, ModifierDefinition, ModifierDefinitionState, ModifierInstance, Nullable, Owner, + SimpleElement, + SimpleNode, UpdatingOpcode, UpdatingVM, } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; import type { Revision, Tag } from '@glimmer/validator'; -import { - check, - CheckElement, - CheckMaybe, - CheckNode, - CheckOption, - CheckString, -} from '@glimmer/debug'; import { associateDestroyableChild, destroy, registerDestructor } from '@glimmer/destroyable'; import { getInternalModifierManager } from '@glimmer/manager'; import { createComputeRef, isConstRef, valueForRef } from '@glimmer/reference'; @@ -33,7 +28,6 @@ import { isCurriedType, resolveCurriedValue } from '../../curried-value'; import { APPEND_OPCODES } from '../../opcodes'; import { CONSTANTS } from '../../symbols'; import { createCapturedArgs } from '../../vm/arguments'; -import { CheckArguments, CheckOperations, CheckReference } from './-debug-strip'; import { Assert } from './vm'; APPEND_OPCODES.add(Op.Text, (vm, { op1: text }) => { @@ -49,18 +43,23 @@ APPEND_OPCODES.add(Op.OpenElement, (vm, { op1: tag }) => { }); APPEND_OPCODES.add(Op.OpenDynamicElement, (vm) => { - let tagName = check(valueForRef(check(vm.stack.pop(), CheckReference)), CheckString); + // @ts-expect-error todo + let tagName = valueForRef(vm.stack.pop()); + // @ts-expect-error todo vm.elements().openElement(tagName); }); APPEND_OPCODES.add(Op.PushRemoteElement, (vm) => { - let elementRef = check(vm.stack.pop(), CheckReference); - let insertBeforeRef = check(vm.stack.pop(), CheckReference); - let guidRef = check(vm.stack.pop(), CheckReference); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + let elementRef = vm.stack.pop() as Reference; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + let insertBeforeRef = vm.stack.pop() as Reference; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + let guidRef = vm.stack.pop() as Reference; - let element = check(valueForRef(elementRef), CheckElement); - let insertBefore = check(valueForRef(insertBeforeRef), CheckMaybe(CheckOption(CheckNode))); - let guid = valueForRef(guidRef) as string; + let element = valueForRef(elementRef) as SimpleElement; + let insertBefore = valueForRef(insertBeforeRef) as Maybe; + let guid = valueForRef(guidRef); if (!isConstRef(elementRef)) { vm.updateWith(new Assert(elementRef)); @@ -105,10 +104,11 @@ APPEND_OPCODES.add(Op.PopRemoteElement, (vm) => { }); APPEND_OPCODES.add(Op.FlushElement, (vm) => { - let operations = check(vm.fetchValue($t0), CheckOperations); + let operations = vm.fetchValue($t0); let modifiers: Nullable = null; if (operations) { + // @ts-expect-error todo modifiers = operations.flush(vm); vm.loadValue($t0, null); } @@ -137,13 +137,14 @@ APPEND_OPCODES.add(Op.Modifier, (vm, { op1: handle }) => { } let owner = vm.getOwner(); - let args = check(vm.stack.pop(), CheckArguments); + let args = vm.stack.pop(); let definition = vm[CONSTANTS].getValue(handle); let { manager } = definition; let { constructing } = vm.elements(); + // @ts-expect-error todo let capturedArgs = args.capture(); let state = manager.create( owner, @@ -159,10 +160,11 @@ APPEND_OPCODES.add(Op.Modifier, (vm, { op1: handle }) => { }; let operations = expect( - check(vm.fetchValue($t0), CheckOperations), + vm.fetchValue($t0), 'BUG: ElementModifier could not find operations to append to' ); + // @ts-expect-error todo operations.addModifier(vm, instance, capturedArgs); let tag = manager.getTag(state); @@ -179,14 +181,16 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { } let { stack } = vm; - let ref = check(stack.pop(), CheckReference); - let args = check(stack.pop(), CheckArguments).capture(); + let ref = stack.pop(); + let args = stack.pop(); + // @ts-expect-error todo let { positional: outerPositional, named: outerNamed } = args; let { constructing } = vm.elements(); let initialOwner = vm.getOwner(); let instanceRef = createComputeRef(() => { + // @ts-expect-error todo let value = valueForRef(ref); let owner: Owner; @@ -208,10 +212,12 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { owner = curriedOwner; if (positional !== undefined) { + // @ts-expect-error todo args.positional = positional.concat(outerPositional) as CapturedPositionalArguments; } if (named !== undefined) { + // @ts-expect-error todo args.named = Object.assign({}, ...named, outerNamed); } } else { @@ -225,8 +231,10 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { if (import.meta.env.DEV) { throw new Error( `Expected a dynamic modifier definition, but received an object or function that did not have a modifier manager associated with it. The dynamic invocation was \`{{${ + // @ts-expect-error todo ref.debugLabel }}}\`, and the incorrect definition is the value at the path \`${ + // @ts-expect-error todo ref.debugLabel }\`, which was: ${debugToString!(hostDefinition)}` ); @@ -245,6 +253,7 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { owner, expect(constructing, 'BUG: ElementModifier could not find the element it applies to'), definition.state, + // @ts-expect-error todo args ); @@ -260,10 +269,11 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { if (instance !== undefined) { let operations = expect( - check(vm.fetchValue($t0), CheckOperations), + vm.fetchValue($t0), 'BUG: ElementModifier could not find operations to append to' ); + // @ts-expect-error todo operations.addModifier(vm, instance, args); tag = instance.manager.getTag(instance.state); @@ -273,6 +283,7 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { } } + // @ts-expect-error todo if (!isConstRef(ref) || tag) { return vm.updateWith(new UpdateDynamicModifierOpcode(tag, instance, instanceRef)); } @@ -366,13 +377,17 @@ APPEND_OPCODES.add(Op.StaticAttr, (vm, { op1: _name, op2: _value, op3: _namespac APPEND_OPCODES.add(Op.DynamicAttr, (vm, { op1: _name, op2: _trusting, op3: _namespace }) => { let name = vm[CONSTANTS].getValue(_name); let trusting = vm[CONSTANTS].getValue(_trusting); - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); + + // @ts-expect-error todo let value = valueForRef(reference); let namespace = _namespace ? vm[CONSTANTS].getValue(_namespace) : null; let attribute = vm.elements().setDynamicAttribute(name, value, trusting, namespace); + // @ts-expect-error todo if (!isConstRef(reference)) { + // @ts-expect-error todo vm.updateWith(new UpdateDynamicAttributeOpcode(reference, attribute, vm.env)); } }); From 7b80c48c6043965cb774ef781d706b7cea065333 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:44:10 -0400 Subject: [PATCH 3/6] Remove move checks --- .../runtime/lib/compiled/opcodes/dom.ts | 2 +- .../runtime/lib/compiled/opcodes/vm.ts | 52 +++++++++++-------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts index 51827a733f..ecf6083060 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/dom.ts @@ -182,8 +182,8 @@ APPEND_OPCODES.add(Op.DynamicModifier, (vm) => { let { stack } = vm; let ref = stack.pop(); - let args = stack.pop(); // @ts-expect-error todo + let args = stack.pop().capture(); let { positional: outerPositional, named: outerNamed } = args; let { constructing } = vm.elements(); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/vm.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/vm.ts index 6ac1d0585d..3011736fc3 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/vm.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/vm.ts @@ -1,15 +1,6 @@ import type { CompilableTemplate, Nullable, UpdatingOpcode } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; import type { Revision, Tag } from '@glimmer/validator'; -import { - check, - CheckBlockSymbolTable, - CheckHandle, - CheckInstanceof, - CheckNumber, - CheckOption, - CheckPrimitive, -} from '@glimmer/debug'; import { toBool } from '@glimmer/global-context'; import { createComputeRef, @@ -39,8 +30,6 @@ import type { InternalVM } from '../../vm/append'; import { APPEND_OPCODES } from '../../opcodes'; import { CONSTANTS } from '../../symbols'; -import { VMArgumentsImpl } from '../../vm/arguments'; -import { CheckReference, CheckScope } from './-debug-strip'; import { stackAssert } from './assert'; APPEND_OPCODES.add(Op.ChildScope, (vm) => vm.pushChildScope()); @@ -74,7 +63,7 @@ APPEND_OPCODES.add(Op.Primitive, (vm, { op1: primitive }) => { APPEND_OPCODES.add(Op.PrimitiveReference, (vm) => { let stack = vm.stack; - let value = check(stack.pop(), CheckPrimitive); + let value = stack.pop(); let ref; if (value === undefined) { @@ -86,6 +75,7 @@ APPEND_OPCODES.add(Op.PrimitiveReference, (vm) => { } else if (value === false) { ref = FALSE_REFERENCE; } else { + // @ts-expect-error todo ref = createPrimitiveRef(value); } @@ -93,7 +83,7 @@ APPEND_OPCODES.add(Op.PrimitiveReference, (vm) => { }); APPEND_OPCODES.add(Op.Dup, (vm, { op1: register, op2: offset }) => { - let position = check(vm.fetchValue(register), CheckNumber) - offset; + let position = vm.fetchValue(register) - offset; vm.stack.dup(position); }); @@ -146,20 +136,22 @@ APPEND_OPCODES.add(Op.CompileBlock, (vm: InternalVM) => { APPEND_OPCODES.add(Op.InvokeYield, (vm) => { let { stack } = vm; - let handle = check(stack.pop(), CheckOption(CheckHandle)); - let scope = check(stack.pop(), CheckOption(CheckScope)); - let table = check(stack.pop(), CheckOption(CheckBlockSymbolTable)); + let handle = stack.pop(); + let scope = stack.pop(); + let table = stack.pop(); assert( + // @ts-expect-error todo table === null || (table && typeof table === 'object' && Array.isArray(table.parameters)), stackAssert('Option', table) ); - let args = check(stack.pop(), CheckInstanceof(VMArgumentsImpl)); + let args = stack.pop(); if (table === null) { // To balance the pop{Frame,Scope} vm.pushFrame(); + // @ts-expect-error todo vm.pushScope(scope ?? vm.scope()); return; @@ -169,27 +161,34 @@ APPEND_OPCODES.add(Op.InvokeYield, (vm) => { // If necessary, create a child scope { + // @ts-expect-error todo let locals = table.parameters; let localsCount = locals.length; if (localsCount > 0) { + // @ts-expect-error todo invokingScope = invokingScope.child(); for (let i = 0; i < localsCount; i++) { + // @ts-expect-error todo invokingScope.bindSymbol(unwrap(locals[i]), args.at(i)); } } } vm.pushFrame(); + // @ts-expect-error todo vm.pushScope(invokingScope); - vm.call(handle!); + // @ts-expect-error todo + vm.call(handle); }); APPEND_OPCODES.add(Op.JumpIf, (vm, { op1: target }) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); + // @ts-expect-error todo let value = Boolean(valueForRef(reference)); + // @ts-expect-error todo if (isConstRef(reference)) { if (value === true) { vm.goto(target); @@ -199,14 +198,17 @@ APPEND_OPCODES.add(Op.JumpIf, (vm, { op1: target }) => { vm.goto(target); } + // @ts-expect-error todo vm.updateWith(new Assert(reference)); } }); APPEND_OPCODES.add(Op.JumpUnless, (vm, { op1: target }) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); + // @ts-expect-error todo let value = Boolean(valueForRef(reference)); + // @ts-expect-error todo if (isConstRef(reference)) { if (value === false) { vm.goto(target); @@ -216,12 +218,13 @@ APPEND_OPCODES.add(Op.JumpUnless, (vm, { op1: target }) => { vm.goto(target); } + // @ts-expect-error todo vm.updateWith(new Assert(reference)); } }); APPEND_OPCODES.add(Op.JumpEq, (vm, { op1: target, op2: comparison }) => { - let other = check(vm.stack.peek(), CheckNumber); + let other = vm.stack.peek(); if (other === comparison) { vm.goto(target); @@ -229,17 +232,20 @@ APPEND_OPCODES.add(Op.JumpEq, (vm, { op1: target, op2: comparison }) => { }); APPEND_OPCODES.add(Op.AssertSame, (vm) => { - let reference = check(vm.stack.peek(), CheckReference); + let reference = vm.stack.peek(); + // @ts-expect-error todo if (isConstRef(reference) === false) { + // @ts-expect-error todo vm.updateWith(new Assert(reference)); } }); APPEND_OPCODES.add(Op.ToBoolean, (vm) => { let { stack } = vm; - let valueRef = check(stack.pop(), CheckReference); + let valueRef = stack.pop(); + // @ts-expect-error todo stack.push(createComputeRef(() => toBool(valueForRef(valueRef)))); }); From ea11e3a6f19dd42f1ed500262b34fb4369a7cd32 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:23:36 -0400 Subject: [PATCH 4/6] Remove the rest of the checks --- .../@glimmer/manager/lib/util/capabilities.ts | 3 - .../runtime/lib/compiled/opcodes/component.ts | 143 ++++++++++-------- .../runtime/lib/compiled/opcodes/content.ts | 45 +++--- .../lib/compiled/opcodes/expressions.ts | 86 +++++------ .../runtime/lib/compiled/opcodes/lists.ts | 11 +- packages/@glimmer/runtime/lib/helpers/fn.ts | 3 +- packages/@glimmer/runtime/lib/modifiers/on.ts | 42 +---- packages/@glimmer/runtime/lib/vm/arguments.ts | 15 +- 8 files changed, 164 insertions(+), 184 deletions(-) diff --git a/packages/@glimmer/manager/lib/util/capabilities.ts b/packages/@glimmer/manager/lib/util/capabilities.ts index 7299771b47..afdeefdee2 100644 --- a/packages/@glimmer/manager/lib/util/capabilities.ts +++ b/packages/@glimmer/manager/lib/util/capabilities.ts @@ -23,7 +23,6 @@ import type { WithUpdateHook, WrappedCapability, } from '@glimmer/interfaces'; -import { check, CheckNumber } from '@glimmer/debug'; import { InternalComponentCapabilities } from '@glimmer/vm'; export const FROM_CAPABILITIES = import.meta.env.DEV ? new WeakSet() : undefined; @@ -104,7 +103,6 @@ export function managerHasCapability( capabilities: CapabilityMask, capability: F ): _manager is InternalComponentCapabilityFor { - check(capabilities, CheckNumber); return !!(capabilities & capability); } @@ -112,6 +110,5 @@ export function hasCapability( capabilities: CapabilityMask, capability: InternalComponentCapability ): boolean { - check(capabilities, CheckNumber); return !!(capabilities & capability); } diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts index 655c4e52f6..f6c0baa97f 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts @@ -25,16 +25,6 @@ import type { WithUpdateHook, } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; -import { - check, - CheckFunction, - CheckHandle, - CheckInstanceof, - CheckInterface, - CheckOr, - CheckProgramSymbolTable, - CheckString, -} from '@glimmer/debug'; import { registerDestructor } from '@glimmer/destroyable'; import { managerHasCapability } from '@glimmer/manager'; import { isConstRef, valueForRef } from '@glimmer/reference'; @@ -63,16 +53,7 @@ import { isCurriedType, isCurriedValue, resolveCurriedValue } from '../../currie import { APPEND_OPCODES } from '../../opcodes'; import createClassListRef from '../../references/class-list'; import { ARGS, CONSTANTS } from '../../symbols'; -import { EMPTY_ARGS, VMArgumentsImpl } from '../../vm/arguments'; -import { - CheckArguments, - CheckComponentDefinition, - CheckComponentInstance, - CheckCurriedComponentDefinition, - CheckFinishedComponentInstance, - CheckInvocation, - CheckReference, -} from './-debug-strip'; +import { EMPTY_ARGS } from '../../vm/arguments'; import { UpdateDynamicAttributeOpcode } from './dom'; /** @@ -131,10 +112,9 @@ APPEND_OPCODES.add(Op.PushComponentDefinition, (vm, { op1: handle }) => { APPEND_OPCODES.add(Op.ResolveDynamicComponent, (vm, { op1: _isStrict }) => { let stack = vm.stack; - let component = check( - valueForRef(check(stack.pop(), CheckReference)), - CheckOr(CheckString, CheckCurriedComponentDefinition) - ); + + // @ts-expect-error todo + let component = valueForRef(stack.pop()); let constants = vm[CONSTANTS]; let owner = vm.getOwner(); let isStrict = constants.getValue(_isStrict); @@ -156,6 +136,7 @@ APPEND_OPCODES.add(Op.ResolveDynamicComponent, (vm, { op1: _isStrict }) => { } else if (isCurriedValue(component)) { definition = component; } else { + // @ts-expect-error todo definition = constants.component(component, owner); } @@ -164,7 +145,9 @@ APPEND_OPCODES.add(Op.ResolveDynamicComponent, (vm, { op1: _isStrict }) => { APPEND_OPCODES.add(Op.ResolveCurriedComponent, (vm) => { let stack = vm.stack; - let ref = check(stack.pop(), CheckReference); + + let ref = stack.pop(); + // @ts-expect-error todo let value = valueForRef(ref); let constants = vm[CONSTANTS]; @@ -238,7 +221,8 @@ APPEND_OPCODES.add(Op.PushEmptyArgs, (vm) => { APPEND_OPCODES.add(Op.CaptureArgs, (vm) => { let stack = vm.stack; - let args = check(stack.pop(), CheckInstanceof(VMArgumentsImpl)); + let args = stack.pop(); + // @ts-expect-error todo let capturedArgs = args.capture(); stack.push(capturedArgs); }); @@ -246,7 +230,7 @@ APPEND_OPCODES.add(Op.CaptureArgs, (vm) => { APPEND_OPCODES.add(Op.PrepareArgs, (vm, { op1: _state }) => { let stack = vm.stack; let instance = vm.fetchValue(_state); - let args = check(stack.pop(), CheckInstanceof(VMArgumentsImpl)); + let args = stack.pop(); let { definition } = instance; @@ -339,6 +323,7 @@ APPEND_OPCODES.add(Op.PrepareArgs, (vm, { op1: _state }) => { stack.push(named[unwrap(names[i])]); } + // @ts-expect-error todo args.setup(stack, names, blockNames, positionalCount, false); } @@ -346,7 +331,9 @@ APPEND_OPCODES.add(Op.PrepareArgs, (vm, { op1: _state }) => { }); APPEND_OPCODES.add(Op.CreateComponent, (vm, { op1: flags, op2: _state }) => { - let instance = check(vm.fetchValue(_state), CheckComponentInstance); + let instance = vm.fetchValue(_state); + + // @ts-expect-error todo let { definition, manager, capabilities } = instance; if (!managerHasCapability(manager, capabilities, InternalComponentCapabilities.createInstance)) { @@ -365,7 +352,7 @@ APPEND_OPCODES.add(Op.CreateComponent, (vm, { op1: flags, op2: _state }) => { let args: Nullable = null; if (managerHasCapability(manager, capabilities, InternalComponentCapabilities.createArgs)) { - args = check(vm.stack.peek(), CheckArguments); + args = vm.stack.peek(); } let self: Nullable = null; @@ -385,6 +372,7 @@ APPEND_OPCODES.add(Op.CreateComponent, (vm, { op1: flags, op2: _state }) => { // We want to reuse the `state` POJO here, because we know that the opcodes // only transition at exactly one place. + // @ts-expect-error todo instance.state = state; if (managerHasCapability(manager, capabilities, InternalComponentCapabilities.updateHook)) { @@ -393,7 +381,8 @@ APPEND_OPCODES.add(Op.CreateComponent, (vm, { op1: flags, op2: _state }) => { }); APPEND_OPCODES.add(Op.RegisterComponentDestructor, (vm, { op1: _state }) => { - let { manager, state, capabilities } = check(vm.fetchValue(_state), CheckComponentInstance); + // @ts-expect-error todo + let { manager, state, capabilities } = vm.fetchValue(_state); let d = manager.getDestroyable(state); @@ -415,7 +404,8 @@ APPEND_OPCODES.add(Op.BeginComponentTransaction, (vm, { op1: _state }) => { let name; if (import.meta.env.DEV) { - let { definition, manager } = check(vm.fetchValue(_state), CheckComponentInstance); + // @ts-expect-error todo + let { definition, manager } = vm.fetchValue(_state); name = definition.resolvedName ?? manager.getDebugName(definition.state); } @@ -431,15 +421,11 @@ APPEND_OPCODES.add(Op.PutComponentOperations, (vm) => { APPEND_OPCODES.add(Op.ComponentAttr, (vm, { op1: _name, op2: _trusting, op3: _namespace }) => { let name = vm[CONSTANTS].getValue(_name); let trusting = vm[CONSTANTS].getValue(_trusting); - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); let namespace = _namespace ? vm[CONSTANTS].getValue(_namespace) : null; - check(vm.fetchValue($t0), CheckInstanceof(ComponentElementOperations)).setAttribute( - name, - reference, - trusting, - namespace - ); + // @ts-expect-error todo + vm.fetchValue($t0).setAttribute(name, reference, trusting, namespace); }); APPEND_OPCODES.add(Op.StaticComponentAttr, (vm, { op1: _name, op2: _value, op3: _namespace }) => { @@ -447,11 +433,8 @@ APPEND_OPCODES.add(Op.StaticComponentAttr, (vm, { op1: _name, op2: _value, op3: let value = vm[CONSTANTS].getValue(_value); let namespace = _namespace ? vm[CONSTANTS].getValue(_namespace) : null; - check(vm.fetchValue($t0), CheckInstanceof(ComponentElementOperations)).setStaticAttribute( - name, - value, - namespace - ); + // @ts-expect-error todo + vm.fetchValue($t0).setStaticAttribute(name, value, namespace); }); type DeferredAttribute = { @@ -596,26 +579,30 @@ function setDeferredAttr( } APPEND_OPCODES.add(Op.DidCreateElement, (vm, { op1: _state }) => { - let { definition, state } = check(vm.fetchValue(_state), CheckComponentInstance); + // @ts-expect-error todo + let { definition, state } = vm.fetchValue(_state); let { manager } = definition; - let operations = check(vm.fetchValue($t0), CheckInstanceof(ComponentElementOperations)); + let operations = vm.fetchValue($t0); (manager as WithElementHook).didCreateElement( state, expect(vm.elements().constructing, `Expected a constructing element in DidCreateOpcode`), + // @ts-expect-error todo operations ); }); APPEND_OPCODES.add(Op.GetComponentSelf, (vm, { op1: _state, op2: _names }) => { - let instance = check(vm.fetchValue(_state), CheckComponentInstance); + let instance = vm.fetchValue(_state); + // @ts-expect-error todo let { definition, state } = instance; let { manager } = definition; let selfRef = manager.getSelf(state); if (vm.env.debugRenderTree !== undefined) { - let instance = check(vm.fetchValue(_state), CheckComponentInstance); + let instance = vm.fetchValue(_state); + // @ts-expect-error todo let { definition, manager } = instance; let args: CapturedArguments; @@ -696,7 +683,8 @@ APPEND_OPCODES.add(Op.GetComponentSelf, (vm, { op1: _state, op2: _names }) => { }); APPEND_OPCODES.add(Op.GetComponentTagName, (vm, { op1: _state }) => { - let { definition, state } = check(vm.fetchValue(_state), CheckComponentInstance); + // @ts-expect-error todo + let { definition, state } = vm.fetchValue(_state); let { manager } = definition; let tagName = ( @@ -709,14 +697,16 @@ APPEND_OPCODES.add(Op.GetComponentTagName, (vm, { op1: _state }) => { // Dynamic Invocation Only APPEND_OPCODES.add(Op.GetComponentLayout, (vm, { op1: _state }) => { - let instance = check(vm.fetchValue(_state), CheckComponentInstance); + let instance = vm.fetchValue(_state); + // @ts-expect-error todo let { manager, definition } = instance; let { stack } = vm; let { compilable } = definition; if (compilable === null) { + // @ts-expect-error todo let { capabilities } = instance; assert( @@ -724,6 +714,7 @@ APPEND_OPCODES.add(Op.GetComponentLayout, (vm, { op1: _state }) => { 'BUG: No template was found for this component, and the component did not have the dynamic layout capability' ); + // @ts-expect-error todo compilable = manager.getDynamicLayout(instance.state, vm.runtime.resolver); if (compilable === null) { @@ -742,17 +733,21 @@ APPEND_OPCODES.add(Op.GetComponentLayout, (vm, { op1: _state }) => { }); APPEND_OPCODES.add(Op.Main, (vm, { op1: register }) => { - let definition = check(vm.stack.pop(), CheckComponentDefinition); - let invocation = check(vm.stack.pop(), CheckInvocation); + let definition = vm.stack.pop(); + let invocation = vm.stack.pop(); + // @ts-expect-error todo let { manager, capabilities } = definition; let state: PopulatedComponentInstance = { + // @ts-expect-error todo definition, manager, capabilities, state: null, + // @ts-expect-error todo handle: invocation.handle, + // @ts-expect-error todo table: invocation.symbolTable, lookup: null, }; @@ -764,20 +759,20 @@ APPEND_OPCODES.add(Op.PopulateLayout, (vm, { op1: _state }) => { let { stack } = vm; // In import.meta.env.DEV handles could be ErrHandle objects - let handle = check(stack.pop(), CheckHandle); - let table = check(stack.pop(), CheckProgramSymbolTable); + let handle = stack.pop(); + let table = stack.pop(); - let state = check(vm.fetchValue(_state), CheckComponentInstance); + let state = vm.fetchValue(_state); + // @ts-expect-error todo state.handle = handle; + // @ts-expect-error todo state.table = table; }); APPEND_OPCODES.add(Op.VirtualRootScope, (vm, { op1: _state }) => { - let { table, manager, capabilities, state } = check( - vm.fetchValue(_state), - CheckFinishedComponentInstance - ); + // @ts-expect-error todo + let { table, manager, capabilities, state } = vm.fetchValue(_state); let owner; @@ -804,27 +799,33 @@ APPEND_OPCODES.add(Op.VirtualRootScope, (vm, { op1: _state }) => { }); APPEND_OPCODES.add(Op.SetupForEval, (vm, { op1: _state }) => { - let state = check(vm.fetchValue(_state), CheckFinishedComponentInstance); + let state = vm.fetchValue(_state); + // @ts-expect-error todo if (state.table.hasEval) { + // @ts-expect-error todo 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 state = vm.fetchValue(_state); let scope = vm.scope(); - let args = check(vm.stack.peek(), CheckArguments); + let args = vm.stack.peek(); + // @ts-expect-error todo let callerNames = args.named.atNames; for (let i = callerNames.length - 1; i >= 0; i--) { let atName = unwrap(callerNames[i]); + // @ts-expect-error todo let symbol = state.table.symbols.indexOf(atName); + // @ts-expect-error todo let value = args.named.get(atName, true); if (symbol !== -1) scope.bindSymbol(symbol + 1, value); + // @ts-expect-error todo if (state.lookup) state.lookup[atName] = value; } }); @@ -844,28 +845,33 @@ function bindBlock( } APPEND_OPCODES.add(Op.SetBlocks, (vm, { op1: _state }) => { - let state = check(vm.fetchValue(_state), CheckFinishedComponentInstance); - let { blocks } = check(vm.stack.peek(), CheckArguments); + let state = vm.fetchValue(_state); + // @ts-expect-error todo + let { blocks } = vm.stack.peek(); for (const [i] of enumerate(blocks.names)) { + // @ts-expect-error todo bindBlock(unwrap(blocks.symbolNames[i]), unwrap(blocks.names[i]), state, blocks, vm); } }); // Dynamic Invocation Only APPEND_OPCODES.add(Op.InvokeComponentLayout, (vm, { op1: _state }) => { - let state = check(vm.fetchValue(_state), CheckFinishedComponentInstance); + let state = vm.fetchValue(_state); + // @ts-expect-error todo vm.call(state.handle); }); APPEND_OPCODES.add(Op.DidRenderLayout, (vm, { op1: _state }) => { - let instance = check(vm.fetchValue(_state), CheckComponentInstance); + let instance = vm.fetchValue(_state); + // @ts-expect-error todo let { manager, state, capabilities } = instance; let bounds = vm.elements().popBlock(); if (vm.env.debugRenderTree !== undefined) { if (hasCustomDebugRenderTreeLifecycle(manager)) { + // @ts-expect-error todo let nodes = manager.getDebugCustomRenderTree(instance.definition.state, state, EMPTY_ARGS); nodes.reverse().forEach((node) => { @@ -876,17 +882,20 @@ APPEND_OPCODES.add(Op.DidRenderLayout, (vm, { op1: _state }) => { vm.updateWith(new DebugRenderTreeDidRenderOpcode(bucket, bounds)); }); } else { + // @ts-expect-error todo vm.env.debugRenderTree.didRender(instance, bounds); + // @ts-expect-error todo vm.updateWith(new DebugRenderTreeDidRenderOpcode(instance, bounds)); } } if (managerHasCapability(manager, capabilities, InternalComponentCapabilities.createInstance)) { - let mgr = check(manager, CheckInterface({ didRenderLayout: CheckFunction })); - mgr.didRenderLayout(state, bounds); + manager.didRenderLayout(state, bounds); + // @ts-expect-error todo vm.env.didCreate(instance as ComponentInstanceWithCreate); + // @ts-expect-error todo vm.updateWith(new DidUpdateLayoutOpcode(instance as ComponentInstanceWithCreate, bounds)); } }); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts index 03b1c9c855..acf6e2ecac 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/content.ts @@ -1,10 +1,3 @@ -import { - check, - CheckDocumentFragment, - CheckNode, - CheckSafeString, - CheckString, -} from '@glimmer/debug'; import { hasInternalComponentManager, hasInternalHelperManager } from '@glimmer/manager'; import { isConstRef, valueForRef } from '@glimmer/reference'; import { isObject } from '@glimmer/util'; @@ -14,7 +7,6 @@ import { isCurriedType } from '../../curried-value'; import { isEmpty, isFragment, isNode, isSafeString, shouldCoerce } from '../../dom/normalize'; import { APPEND_OPCODES } from '../../opcodes'; import DynamicTextContent from '../../vm/content/text'; -import { CheckReference } from './-debug-strip'; import { AssertFilter } from './vm'; function toContentType(value: unknown) { @@ -64,28 +56,35 @@ function toDynamicContentType(value: unknown) { } APPEND_OPCODES.add(Op.ContentType, (vm) => { - let reference = check(vm.stack.peek(), CheckReference); + let reference = vm.stack.peek(); + // @ts-expect-error todo vm.stack.push(toContentType(valueForRef(reference))); + // @ts-expect-error todo if (!isConstRef(reference)) { + // @ts-expect-error todo vm.updateWith(new AssertFilter(reference, toContentType)); } }); APPEND_OPCODES.add(Op.DynamicContentType, (vm) => { - let reference = check(vm.stack.peek(), CheckReference); + let reference = vm.stack.peek(); + // @ts-expect-error todo vm.stack.push(toDynamicContentType(valueForRef(reference))); + // @ts-expect-error todo if (!isConstRef(reference)) { + // @ts-expect-error todo vm.updateWith(new AssertFilter(reference, toDynamicContentType)); } }); APPEND_OPCODES.add(Op.AppendHTML, (vm) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); + // @ts-expect-error todo let rawValue = valueForRef(reference); let value = isEmpty(rawValue) ? '' : String(rawValue); @@ -93,39 +92,47 @@ APPEND_OPCODES.add(Op.AppendHTML, (vm) => { }); APPEND_OPCODES.add(Op.AppendSafeHTML, (vm) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); - let rawValue = check(valueForRef(reference), CheckSafeString).toHTML(); - let value = isEmpty(rawValue) ? '' : check(rawValue, CheckString); + // @ts-expect-error todo + let rawValue = valueForRef(reference).toHTML(); + let value = isEmpty(rawValue) ? '' : rawValue; vm.elements().appendDynamicHTML(value); }); APPEND_OPCODES.add(Op.AppendText, (vm) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); + // @ts-expect-error todo let rawValue = valueForRef(reference); let value = isEmpty(rawValue) ? '' : String(rawValue); let node = vm.elements().appendDynamicText(value); + // @ts-expect-error todo if (!isConstRef(reference)) { + // @ts-expect-error todo vm.updateWith(new DynamicTextContent(node, reference, value)); } }); APPEND_OPCODES.add(Op.AppendDocumentFragment, (vm) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); - let value = check(valueForRef(reference), CheckDocumentFragment); + // @ts-expect-error todo + let value = valueForRef(reference); + // @ts-expect-error todo vm.elements().appendDynamicFragment(value); }); APPEND_OPCODES.add(Op.AppendNode, (vm) => { - let reference = check(vm.stack.pop(), CheckReference); + let reference = vm.stack.pop(); - let value = check(valueForRef(reference), CheckNode); + // @ts-expect-error todo + let value = valueForRef(reference); + // @ts-expect-error todo vm.elements().appendDynamicNode(value); }); diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts index 2fa7af7475..da9e3d1586 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/expressions.ts @@ -8,14 +8,6 @@ import type { VM as PublicVM, } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; -import { - check, - CheckBlockSymbolTable, - CheckHandle, - CheckMaybe, - CheckOption, - CheckOr, -} from '@glimmer/debug'; import { _hasDestroyableChildren, associateDestroyableChild, destroy } from '@glimmer/destroyable'; import { toBool } from '@glimmer/global-context'; import { getInternalHelperManager } from '@glimmer/manager'; @@ -36,24 +28,14 @@ import createCurryRef from '../../references/curry-value'; import { CONSTANTS } from '../../symbols'; import { reifyPositional } from '../../vm/arguments'; import { createConcatRef } from '../expressions/concat'; -import { - CheckArguments, - CheckCapturedArguments, - CheckCompilableBlock, - CheckHelper, - CheckReference, - CheckScope, - CheckScopeBlock, - CheckUndefinedReference, -} from './-debug-strip'; export type FunctionExpression = (vm: PublicVM) => Reference; APPEND_OPCODES.add(Op.Curry, (vm, { op1: type, op2: _isStrict }) => { let stack = vm.stack; - let definition = check(stack.pop(), CheckReference); - let capturedArgs = check(stack.pop(), CheckCapturedArguments); + let definition = stack.pop(); + let capturedArgs = stack.pop(); let owner = vm.getOwner(); let resolver = vm.runtime.resolver; @@ -67,14 +49,16 @@ APPEND_OPCODES.add(Op.Curry, (vm, { op1: type, op2: _isStrict }) => { vm.loadValue( $v0, + // @ts-expect-error todo createCurryRef(type as CurriedType, definition, owner, capturedArgs, resolver, isStrict) ); }); APPEND_OPCODES.add(Op.DynamicHelper, (vm) => { let stack = vm.stack; - let ref = check(stack.pop(), CheckReference); - let args = check(stack.pop(), CheckArguments).capture(); + let ref = stack.pop(); + // @ts-expect-error todo + let args = stack.pop().capture(); let helperRef: Reference; let initialOwner: Owner = vm.getOwner(); @@ -84,11 +68,13 @@ APPEND_OPCODES.add(Op.DynamicHelper, (vm) => { destroy(helperRef); } + // @ts-expect-error todo let definition = valueForRef(ref); if (isCurriedType(definition, CurriedTypes.Helper)) { let { definition: resolvedDef, owner, positional, named } = resolveCurriedValue(definition); + // @ts-expect-error todo let helper = resolveHelper(resolvedDef, ref); if (named !== undefined) { @@ -103,6 +89,7 @@ APPEND_OPCODES.add(Op.DynamicHelper, (vm) => { associateDestroyableChild(helperInstanceRef, helperRef); } else if (isObject(definition)) { + // @ts-expect-error todo let helper = resolveHelper(definition, ref); helperRef = helper(args, initialOwner); @@ -151,8 +138,10 @@ function resolveHelper(definition: HelperDefinitionState, ref: Reference): Helpe APPEND_OPCODES.add(Op.Helper, (vm, { op1: handle }) => { let stack = vm.stack; - let helper = check(vm[CONSTANTS].getValue(handle), CheckHelper); - let args = check(stack.pop(), CheckArguments); + let helper = vm[CONSTANTS].getValue(handle); + let args = stack.pop(); + + // @ts-expect-error todo let value = helper(args.capture(), vm.getOwner(), vm.dynamicScope()); if (_hasDestroyableChildren(value)) { @@ -169,15 +158,16 @@ APPEND_OPCODES.add(Op.GetVariable, (vm, { op1: symbol }) => { }); APPEND_OPCODES.add(Op.SetVariable, (vm, { op1: symbol }) => { - let expr = check(vm.stack.pop(), CheckReference); + let expr = vm.stack.pop(); vm.scope().bindSymbol(symbol, expr); }); APPEND_OPCODES.add(Op.SetBlock, (vm, { op1: symbol }) => { - let handle = check(vm.stack.pop(), CheckCompilableBlock); - let scope = check(vm.stack.pop(), CheckScope); - let table = check(vm.stack.pop(), CheckBlockSymbolTable); + let handle = vm.stack.pop(); + let scope = vm.stack.pop(); + let table = vm.stack.pop(); + // @ts-expect-error todo vm.scope().bindBlock(symbol, [handle, scope, table]); }); @@ -199,7 +189,8 @@ APPEND_OPCODES.add(Op.RootScope, (vm, { op1: symbols }) => { APPEND_OPCODES.add(Op.GetProperty, (vm, { op1: _key }) => { let key = vm[CONSTANTS].getValue(_key); - let expr = check(vm.stack.pop(), CheckReference); + let expr = vm.stack.pop(); + // @ts-expect-error todo vm.stack.push(childRefFor(expr, key)); }); @@ -212,9 +203,12 @@ APPEND_OPCODES.add(Op.GetBlock, (vm, { op1: _block }) => { APPEND_OPCODES.add(Op.SpreadBlock, (vm) => { let { stack } = vm; - let block = check(stack.pop(), CheckOption(CheckOr(CheckScopeBlock, CheckUndefinedReference))); + let block = stack.pop(); + + // @ts-expect-error todo if (block && !isUndefinedReference(block)) { + // @ts-expect-error todo let [handleOrCompilable, scope, table] = block; stack.push(table); @@ -237,8 +231,9 @@ function isUndefinedReference(input: ScopeBlock | Reference): input is Reference APPEND_OPCODES.add(Op.HasBlock, (vm) => { let { stack } = vm; - let block = check(stack.pop(), CheckOption(CheckOr(CheckScopeBlock, CheckUndefinedReference))); + let block = stack.pop(); + // @ts-expect-error todo if (block && !isUndefinedReference(block)) { stack.push(TRUE_REFERENCE); } else { @@ -248,13 +243,12 @@ APPEND_OPCODES.add(Op.HasBlock, (vm) => { APPEND_OPCODES.add(Op.HasBlockParams, (vm) => { // FIXME(mmun): should only need to push the symbol table - let block = vm.stack.pop(); - let scope = vm.stack.pop(); + vm.stack.pop(); + vm.stack.pop(); - check(block, CheckMaybe(CheckOr(CheckHandle, CheckCompilableBlock))); - check(scope, CheckMaybe(CheckScope)); - let table = check(vm.stack.pop(), CheckMaybe(CheckBlockSymbolTable)); + let table = vm.stack.pop(); + // @ts-expect-error todo let hasBlockParams = table && table.parameters.length; vm.stack.push(hasBlockParams ? TRUE_REFERENCE : FALSE_REFERENCE); }); @@ -264,22 +258,25 @@ APPEND_OPCODES.add(Op.Concat, (vm, { op1: count }) => { for (let i = count; i > 0; i--) { let offset = i - 1; - out[offset] = check(vm.stack.pop(), CheckReference); + out[offset] = vm.stack.pop(); } vm.stack.push(createConcatRef(out)); }); APPEND_OPCODES.add(Op.IfInline, (vm) => { - let condition = check(vm.stack.pop(), CheckReference); - let truthy = check(vm.stack.pop(), CheckReference); - let falsy = check(vm.stack.pop(), CheckReference); + let condition = vm.stack.pop(); + let truthy = vm.stack.pop(); + let falsy = vm.stack.pop(); vm.stack.push( createComputeRef(() => { + // @ts-expect-error todo if (toBool(valueForRef(condition)) === true) { + // @ts-expect-error todo return valueForRef(truthy); } else { + // @ts-expect-error todo return valueForRef(falsy); } }) @@ -287,10 +284,11 @@ APPEND_OPCODES.add(Op.IfInline, (vm) => { }); APPEND_OPCODES.add(Op.Not, (vm) => { - let ref = check(vm.stack.pop(), CheckReference); + let ref = vm.stack.pop(); vm.stack.push( createComputeRef(() => { + // @ts-expect-error todo return !toBool(valueForRef(ref)); }) ); @@ -299,10 +297,11 @@ APPEND_OPCODES.add(Op.Not, (vm) => { APPEND_OPCODES.add(Op.GetDynamicVar, (vm) => { let scope = vm.dynamicScope(); let stack = vm.stack; - let nameRef = check(stack.pop(), CheckReference); + let nameRef = stack.pop(); stack.push( createComputeRef(() => { + // @ts-expect-error todo let name = String(valueForRef(nameRef)); return valueForRef(scope.get(name)); }) @@ -310,7 +309,8 @@ APPEND_OPCODES.add(Op.GetDynamicVar, (vm) => { }); APPEND_OPCODES.add(Op.Log, (vm) => { - let { positional } = check(vm.stack.pop(), CheckArguments).capture(); + // @ts-expect-error todo + let { positional } = vm.stack.pop().capture(); vm.loadValue( $v0, diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/lists.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/lists.ts index b9318d57a3..38b0e94a88 100644 --- a/packages/@glimmer/runtime/lib/compiled/opcodes/lists.ts +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/lists.ts @@ -1,19 +1,19 @@ -import { check } from '@glimmer/debug'; import { createIteratorRef, valueForRef } from '@glimmer/reference'; import { Op } from '@glimmer/vm'; import { APPEND_OPCODES } from '../../opcodes'; -import { CheckIterator, CheckReference } from './-debug-strip'; import { AssertFilter } from './vm'; APPEND_OPCODES.add(Op.EnterList, (vm, { op1: relativeStart, op2: elseTarget }) => { let stack = vm.stack; - let listRef = check(stack.pop(), CheckReference); - let keyRef = check(stack.pop(), CheckReference); + let listRef = stack.pop(); + let keyRef = stack.pop(); + // @ts-expect-error todo let keyValue = valueForRef(keyRef); let key = keyValue === null ? '@identity' : String(keyValue); + // @ts-expect-error todo let iteratorRef = createIteratorRef(listRef, key); let iterator = valueForRef(iteratorRef); @@ -34,7 +34,8 @@ APPEND_OPCODES.add(Op.ExitList, (vm) => { APPEND_OPCODES.add(Op.Iterate, (vm, { op1: breaks }) => { let stack = vm.stack; - let iterator = check(stack.peek(), CheckIterator); + let iterator = stack.peek(); + // @ts-expect-error todo let item = iterator.next(); if (item !== null) { diff --git a/packages/@glimmer/runtime/lib/helpers/fn.ts b/packages/@glimmer/runtime/lib/helpers/fn.ts index 593e421d87..d35b04a763 100644 --- a/packages/@glimmer/runtime/lib/helpers/fn.ts +++ b/packages/@glimmer/runtime/lib/helpers/fn.ts @@ -1,6 +1,5 @@ import type { CapturedArguments } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; -import { check } from '@glimmer/debug'; import { createComputeRef, isInvokableRef, updateRef, valueForRef } from '@glimmer/reference'; import { buildUntouchableThis } from '@glimmer/util'; @@ -74,7 +73,7 @@ const context = buildUntouchableThis('`fn` helper'); @public */ export const fn = internalHelper(({ positional }: CapturedArguments) => { - let callbackRef = check(positional[0], assertCallbackIsFn); + let callbackRef = positional[0]; return createComputeRef( () => { diff --git a/packages/@glimmer/runtime/lib/modifiers/on.ts b/packages/@glimmer/runtime/lib/modifiers/on.ts index bc79fa7713..d1d27a7d03 100644 --- a/packages/@glimmer/runtime/lib/modifiers/on.ts +++ b/packages/@glimmer/runtime/lib/modifiers/on.ts @@ -5,14 +5,6 @@ import type { SimpleElement, UpdatableTag, } from '@glimmer/interfaces'; -import { - check, - CheckBoolean, - CheckFunction, - CheckOr, - CheckString, - CheckUndefined, -} from '@glimmer/debug'; import { registerDestructor } from '@glimmer/destroyable'; import { setInternalModifierManager } from '@glimmer/manager'; import { valueForRef } from '@glimmer/reference'; @@ -61,22 +53,14 @@ export class OnModifierState { 'You must pass a valid DOM event name as the first argument to the `on` modifier' ); - let eventName = check( - valueForRef(args.positional[0]), - CheckString, - () => 'You must pass a valid DOM event name as the first argument to the `on` modifier' - ); + let eventName = valueForRef(args.positional[0]); assert( args.positional[1], 'You must pass a function as the second argument to the `on` modifier' ); - let userProvidedCallback = check(valueForRef(args.positional[1]), CheckFunction, (actual) => { - return `You must pass a function as the second argument to the \`on\` modifier; you passed ${ - actual === null ? 'null' : typeof actual - }. While rendering:\n\n${args.positional[1]?.debugLabel ?? `{unlabeled value}`}`; - }) as EventListener; + let userProvidedCallback = valueForRef(args.positional[1]); if (import.meta.env.DEV && args.positional.length !== 2) { throw new Error( @@ -91,23 +75,11 @@ export class OnModifierState { if (import.meta.env.DEV) { let { once: _once, passive: _passive, capture: _capture, ...extra } = reifyNamed(args.named); - once = check(_once, CheckOr(CheckBoolean, CheckUndefined), (actual) => { - return `You must pass a boolean or undefined as the \`once\` argument to the \`on\` modifier; you passed ${actual}. While rendering:\n\n${ - args.named['once']!.debugLabel ?? `{unlabeled value}` - }`; - }); - - passive = check(_passive, CheckOr(CheckBoolean, CheckUndefined), (actual) => { - return `You must pass a boolean or undefined as the \`passive\` argument to the \`on\` modifier; you passed ${actual}. While rendering:\n\n${ - args.named['passive']!.debugLabel ?? `{unlabeled value}` - }`; - }); - - capture = check(_capture, CheckOr(CheckBoolean, CheckUndefined), (actual) => { - return `You must pass a boolean or undefined as the \`capture\` argument to the \`on\` modifier; you passed ${actual}. While rendering:\n\n${ - args.named['capture']!.debugLabel ?? `{unlabeled value}` - }`; - }); + once = _once; + + passive = _passive; + + capture = _capture; if (Object.keys(extra).length > 0) { throw new Error( diff --git a/packages/@glimmer/runtime/lib/vm/arguments.ts b/packages/@glimmer/runtime/lib/vm/arguments.ts index ce94d4a494..6e6c193e0e 100644 --- a/packages/@glimmer/runtime/lib/vm/arguments.ts +++ b/packages/@glimmer/runtime/lib/vm/arguments.ts @@ -18,7 +18,6 @@ import type { } from '@glimmer/interfaces'; import type { Reference } from '@glimmer/reference'; import type { Tag } from '@glimmer/validator'; -import { check, CheckBlockSymbolTable, CheckHandle, CheckOption, CheckOr } from '@glimmer/debug'; import { createDebugAliasRef, UNDEFINED_REFERENCE, valueForRef } from '@glimmer/reference'; import { dict, EMPTY_STRING_ARRAY, emptyArray, enumerate, unwrap } from '@glimmer/util'; import { CONSTANT_TAG } from '@glimmer/validator'; @@ -26,7 +25,6 @@ import { $sp } from '@glimmer/vm'; import type { EvaluationStack } from './stack'; -import { CheckCompilableBlock, CheckReference, CheckScope } from '../compiled/opcodes/-debug-strip'; import { REGISTERS } from '../symbols'; /* @@ -167,7 +165,7 @@ export class PositionalArgumentsImpl implements PositionalArguments { return UNDEFINED_REFERENCE; } - return check(stack.get(position, base), CheckReference); + return stack.get(position, base); } capture(): CapturedPositionalArguments { @@ -422,14 +420,11 @@ export class BlockArgumentsImpl implements BlockArguments { let { base, stack } = this; - let table = check(stack.get(idx * 3, base), CheckOption(CheckBlockSymbolTable)); - let scope = check(stack.get(idx * 3 + 1, base), CheckOption(CheckScope)); - let handle = check( - stack.get(idx * 3 + 2, base), - CheckOption(CheckOr(CheckHandle, CheckCompilableBlock)) - ); + let table = stack.get(idx * 3, base); + let scope = stack.get(idx * 3 + 1, base); + let handle = stack.get(idx * 3 + 2, base); - return handle === null ? null : ([handle, scope!, table!] as ScopeBlock); + return handle === null ? null : ([handle, scope, table] as ScopeBlock); } capture(): CapturedBlockArguments { From 0eca4102c30a3d24b9122030a68e53f12ac239a8 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:52:13 -0400 Subject: [PATCH 5/6] Use Prod Assets only --- packages/@glimmer-workspace/build/lib/config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@glimmer-workspace/build/lib/config.js b/packages/@glimmer-workspace/build/lib/config.js index 316790b915..e378fa6492 100644 --- a/packages/@glimmer-workspace/build/lib/config.js +++ b/packages/@glimmer-workspace/build/lib/config.js @@ -262,12 +262,12 @@ export class Package { let builds = []; if (formats.esm ?? true) { - builds.push(...this.rollupESM({ env: 'dev' })); + // builds.push(...this.rollupESM({ env: 'dev' })); builds.push(...this.rollupESM({ env: 'prod' })); } if (formats.cjs ?? true) { - builds.push(...this.rollupCJS({ env: 'dev' })); + builds.push(...this.rollupCJS({ env: 'prod' })); } return builds; @@ -418,7 +418,7 @@ export class Package { return { input: resolve(root, ts), output: { - file: resolve(root, 'dist', env, file), + file: resolve(root, 'dist', 'dev', file), format, sourcemap: true, exports: format === 'cjs' ? 'named' : 'auto', From a3996f472c48f6e5a872e5ebc449b02ba2714a2a Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:12:53 -0400 Subject: [PATCH 6/6] Update benchmark --- benchmark/benchmarks/krausest/vite.config.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/benchmarks/krausest/vite.config.mts b/benchmark/benchmarks/krausest/vite.config.mts index ae34fe4b7b..6a19ae7ce4 100644 --- a/benchmark/benchmarks/krausest/vite.config.mts +++ b/benchmark/benchmarks/krausest/vite.config.mts @@ -11,7 +11,7 @@ const currentPath = path.dirname(fileURLToPath(self)); const packagesPath = path.resolve(currentPath, '..', '..', './../packages'); const packagePath = (name: string) => { - return path.join(packagesPath, name, 'dist/prod/index.js'); + return path.join(packagesPath, name, 'dist/dev/index.js'); }; export default defineConfig({