Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Partial infra and rename eval -> debugger #1662

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/opcodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"GetComponentSelf",
"GetComponentTagName",
"GetComponentLayout",
"SetupForEval",
"SetupForDebug",
"PopulateLayout",
"InvokeComponentLayout",
"BeginComponentTransaction",
Expand Down
8 changes: 4 additions & 4 deletions packages/@glimmer/constants/lib/syscall-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
VmAppendText,
VmAssertSame,
VmBeginComponentTransaction,
VmBindDebuggerScope,
VmBindDynamicScope,
VmBindEvalScope,
VmCaptureArgs,
VmChildScope,
VmCloseElement,
Expand Down Expand Up @@ -86,7 +86,7 @@ import type {
VmSetBlock,
VmSetBlocks,
VmSetNamedVariables,
VmSetupForEval,
VmSetupForDebugger,
VmSetVariable,
VmSize,
VmSpreadBlock,
Expand Down Expand Up @@ -174,8 +174,8 @@ export const VM_PUT_COMPONENT_OPERATIONS_OP = 89 satisfies VmPutComponentOperati
export const VM_GET_COMPONENT_SELF_OP = 90 satisfies VmGetComponentSelf;
export const VM_GET_COMPONENT_TAG_NAME_OP = 91 satisfies VmGetComponentTagName;
export const VM_GET_COMPONENT_LAYOUT_OP = 92 satisfies VmGetComponentLayout;
export const VM_BIND_EVAL_SCOPE_OP = 93 satisfies VmBindEvalScope;
export const VM_SETUP_FOR_EVAL_OP = 94 satisfies VmSetupForEval;
export const VM_BIND_DEBUGGER_SCOPE_OP = 93 satisfies VmBindDebuggerScope;
export const VM_SETUP_FOR_DEBUGGER_OP = 94 satisfies VmSetupForDebugger;
export const VM_POPULATE_LAYOUT_OP = 95 satisfies VmPopulateLayout;
export const VM_INVOKE_COMPONENT_LAYOUT_OP = 96 satisfies VmInvokeComponentLayout;
export const VM_BEGIN_COMPONENT_TRANSACTION_OP = 97 satisfies VmBeginComponentTransaction;
Expand Down
16 changes: 8 additions & 8 deletions packages/@glimmer/debug/lib/opcode-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
VM_APPEND_TEXT_OP,
VM_ASSERT_SAME_OP,
VM_BEGIN_COMPONENT_TRANSACTION_OP,
VM_BIND_DEBUGGER_SCOPE_OP,
VM_BIND_DYNAMIC_SCOPE_OP,
VM_BIND_EVAL_SCOPE_OP,
VM_CAPTURE_ARGS_OP,
VM_CHILD_SCOPE_OP,
VM_CLOSE_ELEMENT_OP,
Expand Down Expand Up @@ -93,7 +93,7 @@ import {
VM_SET_BLOCKS_OP,
VM_SET_NAMED_VARIABLES_OP,
VM_SET_VARIABLE_OP,
VM_SETUP_FOR_EVAL_OP,
VM_SETUP_FOR_DEBUGGER_OP,
VM_SPREAD_BLOCK_OP,
VM_STATIC_ATTR_OP,
VM_SYSCALL_SIZE,
Expand Down Expand Up @@ -1293,9 +1293,9 @@ if (LOCAL_DEBUG) {
check: true,
};

METADATA[VM_BIND_EVAL_SCOPE_OP] = {
name: 'BindEvalScope',
mnemonic: 'eval_scope',
METADATA[VM_BIND_DEBUGGER_SCOPE_OP] = {
name: 'BindDebuggerScope',
mnemonic: 'debugger_scope',
before: null,
stackChange: 0,
ops: [
Expand All @@ -1308,9 +1308,9 @@ if (LOCAL_DEBUG) {
check: true,
};

METADATA[VM_SETUP_FOR_EVAL_OP] = {
name: 'SetupForEval',
mnemonic: 'eval_setup',
METADATA[VM_SETUP_FOR_DEBUGGER_OP] = {
name: 'SetupForDebugger',
mnemonic: 'debugger_setup',
before: null,
stackChange: 0,
ops: [
Expand Down
10 changes: 2 additions & 8 deletions packages/@glimmer/interfaces/lib/runtime/scope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ export interface Scope {
getSelf(): Reference;
getSymbol(symbol: number): Reference;
getBlock(symbol: number): Nullable<ScopeBlock>;
getEvalScope(): Nullable<Dict<ScopeSlot>>;
getPartialMap(): Nullable<Dict<Reference>>;
getDebuggerScope(): Nullable<Dict<ScopeSlot>>;
bind(symbol: number, value: ScopeSlot): void;
bindSelf(self: Reference): void;
bindSymbol(symbol: number, value: Reference): void;
bindBlock(symbol: number, value: Nullable<ScopeBlock>): void;
bindEvalScope(map: Nullable<Dict<ScopeSlot>>): void;
bindPartialMap(map: Dict<Reference>): void;
bindDebuggerScope(map: Nullable<Dict<ScopeSlot>>): void;
child(): Scope;
}

export interface PartialScope extends Scope {
bindEvalScope(scope: Nullable<Dict<ScopeSlot>>): void;
}

export interface DynamicScope {
get(key: string): Reference<unknown>;
set(key: string, reference: Reference<unknown>): Reference<unknown>;
Expand Down
8 changes: 4 additions & 4 deletions packages/@glimmer/interfaces/lib/vm-opcodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ 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 VmBindDebuggerScope = 93;
export type VmSetupForDebugger = 94;
export type VmPopulateLayout = 95;
export type VmInvokeComponentLayout = 96;
export type VmBeginComponentTransaction = 97;
Expand Down Expand Up @@ -193,8 +193,8 @@ export type VmOp =
| VmGetComponentSelf
| VmGetComponentTagName
| VmGetComponentLayout
| VmBindEvalScope
| VmSetupForEval
| VmBindDebuggerScope
| VmSetupForDebugger
| VmPopulateLayout
| VmInvokeComponentLayout
| VmBeginComponentTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
VM_SET_BLOCKS_OP,
VM_SET_NAMED_VARIABLES_OP,
VM_SET_VARIABLE_OP,
VM_SETUP_FOR_EVAL_OP,
VM_SETUP_FOR_DEBUGGER_OP,
VM_VIRTUAL_ROOT_SCOPE_OP,
} from '@glimmer/constants';
import { unwrap } from '@glimmer/debug-util';
Expand Down Expand Up @@ -463,7 +463,7 @@ export function invokePreparedComponent(

op(VM_VIRTUAL_ROOT_SCOPE_OP, $s0);
op(VM_SET_VARIABLE_OP, 0);
op(VM_SETUP_FOR_EVAL_OP, $s0);
op(VM_SETUP_FOR_DEBUGGER_OP, $s0);

if (bindableAtNames) op(VM_SET_NAMED_VARIABLES_OP, $s0);
if (bindableBlocks) op(VM_SET_BLOCKS_OP, $s0);
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { UpdatingVM, type VM } from './lib/vm';
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -92,7 +92,7 @@ export const CheckCapturedArguments: Checker<CapturedArguments> = CheckInterface
named: wrap(() => CheckDict(CheckReference)),
});

export const CheckScope: Checker<Scope> = wrap(() => CheckInstanceof(PartialScopeImpl));
export const CheckScope: Checker<Scope> = wrap(() => CheckInstanceof(ScopeImpl));

export const CheckComponentManager: Checker<InternalComponentManager<unknown>> = CheckInterface({
getCapabilities: CheckFunction,
Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
VM_RESOLVE_DYNAMIC_COMPONENT_OP,
VM_SET_BLOCKS_OP,
VM_SET_NAMED_VARIABLES_OP,
VM_SETUP_FOR_EVAL_OP,
VM_SETUP_FOR_DEBUGGER_OP,
VM_STATIC_COMPONENT_ATTR_OP,
VM_VIRTUAL_ROOT_SCOPE_OP,
} from '@glimmer/constants';
Expand Down Expand Up @@ -838,12 +838,12 @@ APPEND_OPCODES.add(VM_VIRTUAL_ROOT_SCOPE_OP, (vm, { op1: register }) => {
vm.pushRootScope(table.symbols.length + 1, owner);
});

APPEND_OPCODES.add(VM_SETUP_FOR_EVAL_OP, (vm, { op1: register }) => {
APPEND_OPCODES.add(VM_SETUP_FOR_DEBUGGER_OP, (vm, { op1: register }) => {
let state = check(vm.fetchValue(check(register, CheckRegister)), CheckFinishedComponentInstance);

if (state.table.hasEval) {
let lookup = (state.lookup = dict<ScopeSlot>());
vm.scope().bindEvalScope(lookup);
vm.scope().bindDebuggerScope(lookup);
}
});

Expand Down
6 changes: 3 additions & 3 deletions packages/@glimmer/runtime/lib/compiled/opcodes/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class ScopeInspector {
let parts = path.split('.');
let [head, ...tail] = path.split('.') as [string, ...string[]];

let evalScope = scope.getEvalScope()!;
let debuggerScope = scope.getDebuggerScope()!;
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;
} else if (head.indexOf('@') === 0 && debuggerScope[head]) {
ref = debuggerScope[head] as Reference;
} else {
ref = this.scope.getSelf();
tail = parts;
Expand Down
39 changes: 11 additions & 28 deletions packages/@glimmer/runtime/lib/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
DynamicScope,
Nullable,
Owner,
PartialScope,
Scope,
ScopeBlock,
ScopeSlot,
Expand Down Expand Up @@ -42,28 +41,26 @@ export function isScopeReference(s: ScopeSlot): s is Reference {
return true;
}

export class PartialScopeImpl implements PartialScope {
static root(self: Reference<unknown>, size = 0, owner: Owner): PartialScope {
export class ScopeImpl implements Scope {
static root(self: Reference<unknown>, size = 0, owner: Owner): Scope {
let refs: Reference<unknown>[] = new Array(size + 1).fill(UNDEFINED_REFERENCE);

return new PartialScopeImpl(refs, owner, null, null, null).init({ self });
return new ScopeImpl(refs, owner, null, null).init({ self });
}

static sized(size = 0, owner: Owner): Scope {
let refs: Reference<unknown>[] = new Array(size + 1).fill(UNDEFINED_REFERENCE);

return new PartialScopeImpl(refs, owner, null, null, null);
return new ScopeImpl(refs, owner, null, null);
}

constructor(
// the 0th slot is `self`
readonly slots: Array<ScopeSlot>,
readonly owner: Owner,
private callerScope: Scope | null,
// named arguments and blocks passed to a layout that uses eval
private evalScope: Dict<ScopeSlot> | null,
// locals in scope when the partial was invoked
private partialMap: Dict<Reference<unknown>> | null
// named arguments and blocks passed to a layout that uses debugger
private debuggerScope: Dict<ScopeSlot> | null
) {}

init({ self }: { self: Reference<unknown> }): this {
Expand All @@ -84,12 +81,8 @@ export class PartialScopeImpl implements PartialScope {
return block === UNDEFINED_REFERENCE ? null : (block as ScopeBlock);
}

getEvalScope(): Nullable<Dict<ScopeSlot>> {
return this.evalScope;
}

getPartialMap(): Nullable<Dict<Reference<unknown>>> {
return this.partialMap;
getDebuggerScope(): Nullable<Dict<ScopeSlot>> {
return this.debuggerScope;
}

bind(symbol: number, value: ScopeSlot) {
Expand All @@ -108,12 +101,8 @@ export class PartialScopeImpl implements PartialScope {
this.set<Nullable<ScopeBlock>>(symbol, value);
}

bindEvalScope(map: Nullable<Dict<ScopeSlot>>) {
this.evalScope = map;
}

bindPartialMap(map: Dict<Reference<unknown>>) {
this.partialMap = map;
bindDebuggerScope(map: Nullable<Dict<ScopeSlot>>) {
this.debuggerScope = map;
}

bindCallerScope(scope: Nullable<Scope>): void {
Expand All @@ -125,13 +114,7 @@ export class PartialScopeImpl implements PartialScope {
}

child(): Scope {
return new PartialScopeImpl(
this.slots.slice(),
this.owner,
this.callerScope,
this.evalScope,
this.partialMap
);
return new ScopeImpl(this.slots.slice(), this.owner, this.callerScope, this.debuggerScope);
}

private get<T extends ScopeSlot>(index: number): T {
Expand Down
11 changes: 5 additions & 6 deletions packages/@glimmer/runtime/lib/vm/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
JitConstants,
Nullable,
Owner,
PartialScope,
RenderResult,
RichIteratorResult,
RuntimeContext,
Expand Down Expand Up @@ -53,7 +52,7 @@ import {
JumpIfNotModifiedOpcode,
} from '../compiled/opcodes/vm';
import { APPEND_OPCODES } from '../opcodes';
import { PartialScopeImpl } from '../scope';
import { ScopeImpl } from '../scope';
import { VMArgumentsImpl } from './arguments';
import { LowLevelVM } from './low-level';
import RenderResultImpl from './render-result';
Expand Down Expand Up @@ -240,7 +239,7 @@ export class VM implements PublicVM {
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();
Expand All @@ -256,7 +255,7 @@ export class VM implements PublicVM {
runtime,
vmState(
runtime.program.heap.getaddr(handle),
PartialScopeImpl.root(UNDEFINED_REFERENCE, 0, owner),
ScopeImpl.root(UNDEFINED_REFERENCE, 0, owner),
dynamicScope
),
treeBuilder
Expand Down Expand Up @@ -437,8 +436,8 @@ export class VM implements PublicVM {
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;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/@glimmer/vm/lib/opcodes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,15 @@ format = ["GetComponentLayout", "state:register"]
operand-stack = [[], ["ProgramSymbolTable", "handle"]]
operation = "Get the component layout from the manager."

[syscall.eval_scope]
[syscall.debugger_scope]

format = ["BindEvalScope", "state:register"]
operation = "Populate the eval lookup if necessary."
format = ["BindDebuggerScope", "state:register"]
operation = "Populate the debugger lookup if necessary."

[syscall.eval_setup]
[syscall.debugger_setup]

format = ["SetupForEval", "state:register"]
operation = "Setup for eval"
format = ["SetupForDebugger", "state:register"]
operation = "Setup for debugger"

[syscall.comp_layoutput]

Expand Down
Loading