Skip to content

Commit 589945a

Browse files
Merge pull request #1665 from glimmerjs/feature/pass-args-to-debugger
Feature/pass args to debugger
2 parents 361b214 + 99d0232 commit 589945a

File tree

32 files changed

+94
-167
lines changed

32 files changed

+94
-167
lines changed

packages/@glimmer-workspace/integration-tests/lib/suites/debugger.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ export class DebuggerSuite extends RenderTest {
2828
callbackExecuted++;
2929
this.assert.strictEqual(context.foo, expectedContext.foo, 'reading from the context');
3030
this.assert.strictEqual(get('foo'), expectedContext.foo, 'reading from a local');
31-
this.assert.strictEqual(get('@a'), expectedContext.a, 'reading from an unused named args');
32-
this.assert.strictEqual(get('@used'), expectedContext.used, 'reading from a used named args');
31+
this.assert.strictEqual(
32+
get('this.args.a'),
33+
expectedContext.a,
34+
'reading from an unused named arg (available on this.args)'
35+
);
36+
this.assert.strictEqual(get('@used'), expectedContext.used, 'reading from a used named arg');
3337
});
3438

3539
this.registerComponent(

packages/@glimmer-workspace/integration-tests/test/compiler/compile-options-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {
116116
`component name is a free variable lookup`
117117
);
118118

119-
let componentName = block[3][componentNameExpr[1]];
119+
let componentName = block[2][componentNameExpr[1]];
120120
assert.strictEqual(componentName, 'ooFX', 'customized component name was used');
121121
});
122122

@@ -140,7 +140,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {
140140
`component name is a free variable lookup`
141141
);
142142

143-
let componentName = block[3][componentNameExpr[1]];
143+
let componentName = block[2][componentNameExpr[1]];
144144
assert.strictEqual(componentName, 'rental', 'customized component name was used');
145145
});
146146

@@ -163,7 +163,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {
163163
`component name is a free variable lookup`
164164
);
165165

166-
let componentName = block[3][componentNameExpr[1]];
166+
let componentName = block[2][componentNameExpr[1]];
167167
assert.strictEqual(componentName, 'my-component', 'original component name was used');
168168
});
169169

@@ -186,7 +186,7 @@ module('[glimmer-compiler] precompile', ({ test }) => {
186186
`component name is a free variable lookup`
187187
);
188188

189-
let componentName = block[3][componentNameExpr[1]];
189+
let componentName = block[2][componentNameExpr[1]];
190190
assert.strictEqual(componentName, 'MyComponent', 'original component name was used');
191191
});
192192

packages/@glimmer/compiler/lib/passes/1-normalization/keywords/append.ts

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export const APPEND_KEYWORDS = keywords('Append')
9898
node: ASTv2.AppendContent;
9999
state: NormalizationState;
100100
}): Result<mir.Statement> {
101-
scope.setHasDebugger();
102101
return Ok(new mir.Debugger({ loc: node.loc, scope }));
103102
},
104103
})

packages/@glimmer/compiler/lib/passes/2-encoding/content.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ContentEncoder {
5656
private visitContent(stmt: mir.Statement): WireFormat.Statement | WireStatements {
5757
switch (stmt.type) {
5858
case 'Debugger':
59-
return [SexpOpcodes.Debugger, stmt.scope.getDebugInfo()];
59+
return [SexpOpcodes.Debugger, ...stmt.scope.getDebugInfo(), {}];
6060
case 'AppendComment':
6161
return this.AppendComment(stmt);
6262
case 'AppendTextNode':

packages/@glimmer/compiler/lib/passes/2-encoding/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import { CONTENT } from './content';
1010
export function visit(template: mir.Template): WireFormat.SerializedTemplateBlock {
1111
let statements = CONTENT.list(template.body);
1212
let scope = template.scope;
13-
let block: WireFormat.SerializedTemplateBlock = [
14-
statements,
15-
scope.symbols,
16-
scope.hasDebugger,
17-
scope.upvars,
18-
];
13+
let block: WireFormat.SerializedTemplateBlock = [statements, scope.symbols, scope.upvars];
1914

2015
if (LOCAL_TRACE_LOGGING) {
2116
let debug = new WireFormatDebugger(block);

packages/@glimmer/compiler/lib/wire-encoding.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ when otherwise explicitly stated.
130130

131131
## Flags
132132

133-
| 0 | 1 | 2 | 3 | 4 | 5 |
134-
| -------- | -------- | -------- | -------- | ---------- | ----------- |
135-
| reserved | reserved | reserved | reserved | has upvars | hasDebugger |
133+
| 0 | 1 | 2 | 3 | 4 |
134+
| -------- | -------- | -------- | -------- | ---------- |
135+
| reserved | reserved | reserved | reserved | has upvars |
136136

137137
# Expression
138138

packages/@glimmer/compiler/lib/wire-format-debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class WireFormatDebugger {
1616
private upvars: string[];
1717
private symbols: string[];
1818

19-
constructor([_statements, symbols, _hasDebugger, upvars]: SerializedTemplateBlock) {
19+
constructor([_statements, symbols, upvars]: SerializedTemplateBlock) {
2020
this.upvars = upvars;
2121
this.symbols = symbols;
2222
}

packages/@glimmer/compiler/test/compiler-test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ function test(desc: string, template: string, ...expectedStatements: BuilderStat
3636

3737
let statements = buildStatements(expectedStatements, symbols);
3838

39-
let expected: SerializedTemplateBlock = [
40-
statements,
41-
symbols.toSymbols(),
42-
false,
43-
symbols.toUpvars(),
44-
];
39+
let expected: SerializedTemplateBlock = [statements, symbols.toSymbols(), symbols.toUpvars()];
4540

4641
let debugExpected = new WireFormatDebugger(expected).format(expected);
4742
let debugActual = new WireFormatDebugger(actual.block).format(actual.block);

packages/@glimmer/constants/lib/syscall-ops.ts

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
VmAppendText,
77
VmAssertSame,
88
VmBeginComponentTransaction,
9-
VmBindDebuggerScope,
109
VmBindDynamicScope,
1110
VmCaptureArgs,
1211
VmChildScope,
@@ -86,7 +85,6 @@ import type {
8685
VmSetBlock,
8786
VmSetBlocks,
8887
VmSetNamedVariables,
89-
VmSetupForDebugger,
9088
VmSetVariable,
9189
VmSize,
9290
VmSpreadBlock,
@@ -174,8 +172,6 @@ export const VM_PUT_COMPONENT_OPERATIONS_OP = 89 satisfies VmPutComponentOperati
174172
export const VM_GET_COMPONENT_SELF_OP = 90 satisfies VmGetComponentSelf;
175173
export const VM_GET_COMPONENT_TAG_NAME_OP = 91 satisfies VmGetComponentTagName;
176174
export const VM_GET_COMPONENT_LAYOUT_OP = 92 satisfies VmGetComponentLayout;
177-
export const VM_BIND_DEBUGGER_SCOPE_OP = 93 satisfies VmBindDebuggerScope;
178-
export const VM_SETUP_FOR_DEBUGGER_OP = 94 satisfies VmSetupForDebugger;
179175
export const VM_POPULATE_LAYOUT_OP = 95 satisfies VmPopulateLayout;
180176
export const VM_INVOKE_COMPONENT_LAYOUT_OP = 96 satisfies VmInvokeComponentLayout;
181177
export const VM_BEGIN_COMPONENT_TRANSACTION_OP = 97 satisfies VmBeginComponentTransaction;

packages/@glimmer/debug-util/lib/debug-brand.ts

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export interface DebugProgramSymbolTable {
8080
readonly upvars: readonly string[];
8181
readonly named: Dict<number>;
8282
readonly blocks: Dict<number>;
83-
readonly hasDebugger: boolean;
8483
}
8584

8685
export type LocalDebugType = keyof LocalDebugMap;

packages/@glimmer/debug/lib/dism/opcode.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,12 @@ function describeProgramSymbolTable(
272272
) {
273273
const debug = dev(classified.options.debug);
274274

275-
const hasDebugger = debug.hasDebugger
276-
? frag`(${as.kw('has debugger')})`
277-
: frag`(${as.dim('no debugger')})`.subtle();
278275
const keywords = labelledList('keywords', debug.keywords);
279276
const upvars = labelledList('upvars', debug.upvars);
280277
const atNames = labelledList('@-names', Object.keys(debug.named));
281278
const blocks = labelledList('blocks', Object.keys(debug.blocks));
282279

283-
const fields = join([hasDebugger, keywords, atNames, upvars, blocks], ' ');
280+
const fields = join([keywords, atNames, upvars, blocks], ' ');
284281

285282
const full = frag` ${value(debug, { ref: 'debug' })}`.subtle();
286283

packages/@glimmer/debug/lib/opcode-metadata.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
VM_APPEND_TEXT_OP,
1111
VM_ASSERT_SAME_OP,
1212
VM_BEGIN_COMPONENT_TRANSACTION_OP,
13-
VM_BIND_DEBUGGER_SCOPE_OP,
1413
VM_BIND_DYNAMIC_SCOPE_OP,
1514
VM_CAPTURE_ARGS_OP,
1615
VM_CHILD_SCOPE_OP,
@@ -94,7 +93,6 @@ import {
9493
VM_SET_BLOCKS_OP,
9594
VM_SET_NAMED_VARIABLES_OP,
9695
VM_SET_VARIABLE_OP,
97-
VM_SETUP_FOR_DEBUGGER_OP,
9896
VM_SPREAD_BLOCK_OP,
9997
VM_STATIC_ATTR_OP,
10098
VM_SYSCALL_SIZE,
@@ -693,20 +691,6 @@ if (LOCAL_DEBUG) {
693691
ops: ['state:register'],
694692
};
695693

696-
METADATA[VM_BIND_DEBUGGER_SCOPE_OP] = {
697-
name: 'BindDebuggerScope',
698-
mnemonic: 'debugger_scope',
699-
stackChange: 0,
700-
ops: ['state:register'],
701-
};
702-
703-
METADATA[VM_SETUP_FOR_DEBUGGER_OP] = {
704-
name: 'SetupForDebugger',
705-
mnemonic: 'debugger_setup',
706-
stackChange: 0,
707-
ops: ['state:register'],
708-
};
709-
710694
METADATA[VM_POPULATE_LAYOUT_OP] = {
711695
name: 'PopulateLayout',
712696
mnemonic: 'comp_layoutput',
@@ -751,6 +735,6 @@ if (LOCAL_DEBUG) {
751735
name: 'Debugger',
752736
mnemonic: 'debugger',
753737
stackChange: 0,
754-
ops: ['symbols:const/any', 'debugInfo:const/i32[]'],
738+
ops: ['symbols:const/any'],
755739
};
756740
}

packages/@glimmer/debug/lib/stack-check.ts

-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ export const CheckBlockSymbolTable: Checker<BlockSymbolTable> = LOCAL_DEBUG
511511

512512
export const CheckProgramSymbolTable: Checker<ProgramSymbolTable> = LOCAL_DEBUG
513513
? CheckInterface({
514-
hasDebugger: CheckBoolean,
515514
symbols: CheckArray(CheckString),
516515
})
517516
: new NoopChecker();

packages/@glimmer/interfaces/lib/compile/operands.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export interface IsStrictModeOperand {
3333

3434
export interface DebugSymbolsOperand {
3535
type: DebugSymbolsOperandType;
36-
value: undefined;
36+
value: {
37+
locals: Record<string, number>;
38+
upvars: Record<string, number>;
39+
lexical: Record<string, number>;
40+
};
3741
}
3842

3943
export interface BlockOperand {

packages/@glimmer/interfaces/lib/compile/wire-format/api.d.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export type SexpOpcode = keyof SexpOpcodeMap;
7272
export namespace Core {
7373
export type Expression = Expressions.Expression;
7474

75+
export type DebugSymbols = [locals: Record<string, number>, upvars: Record<string, number>];
76+
7577
export type CallArgs = [Params, Hash];
7678
export type Path = [string, ...string[]];
7779
export type ConcatParams = PresentArray<Expression>;
@@ -80,10 +82,9 @@ export namespace Core {
8082
export type Blocks = Nullable<[string[], SerializedInlineBlock[]]>;
8183
export type Args = [Params, Hash];
8284
export type NamedBlock = [string, SerializedInlineBlock];
83-
export type DebugInfo = number[];
8485
export type ElementParameters = Nullable<PresentArray<ElementParameter>>;
8586

86-
export type Syntax = Path | Params | ConcatParams | Hash | Blocks | Args | DebugInfo;
87+
export type Syntax = Path | Params | ConcatParams | Hash | Blocks | Args;
8788
}
8889

8990
export type CoreSyntax = Core.Syntax;
@@ -254,7 +255,12 @@ export namespace Statements {
254255
| TrustingDynamicAttr
255256
| TrustingComponentAttr;
256257

257-
export type Debugger = [DebuggerOpcode, Core.DebugInfo];
258+
export type Debugger = [
259+
op: DebuggerOpcode,
260+
locals: Record<string, number>,
261+
upvars: Record<string, number>,
262+
lexical: Record<string, number>,
263+
];
258264
export type InElement = [
259265
op: InElementOpcode,
260266
block: SerializedInlineBlock,
@@ -366,7 +372,6 @@ export type SerializedInlineBlock = [statements: Statements.Statement[], paramet
366372
export type SerializedTemplateBlock = [
367373
statements: Statements.Statement[],
368374
locals: string[],
369-
hasDebugger: boolean,
370375
upvars: string[],
371376
lexicalSymbols?: string[],
372377
];

packages/@glimmer/interfaces/lib/runtime/scope.d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Dict, Nullable } from '../core.js';
1+
import type { Nullable } from '../core.js';
22
import type { Reference } from '../references.js';
33
import type { CompilableBlock } from '../template.js';
44
import type { BlockSymbolTable } from '../tier1/symbol-table.js';
@@ -25,8 +25,6 @@ export interface Scope {
2525
getSelf(): Reference;
2626
getSymbol(symbol: number): Reference;
2727
getBlock(symbol: number): Nullable<ScopeBlock>;
28-
getDebuggerScope(): Nullable<Dict<ScopeSlot>>;
29-
bindDebuggerScope(map: Nullable<Dict<ScopeSlot>>): void;
3028
bind(symbol: number, value: ScopeSlot): void;
3129
bindSelf(self: Reference): void;
3230
bindSymbol(symbol: number, value: Reference): void;

packages/@glimmer/interfaces/lib/template.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,16 @@ export interface BlockSymbolNames {
110110
upvars: Nullable<string[]>;
111111
}
112112

113+
export interface DebuggerInfo {
114+
locals: Record<string, number>;
115+
lexical: Record<string, number>;
116+
upvars: Record<string, number>;
117+
}
118+
113119
export interface BlockMetadata {
114120
symbols: BlockSymbolNames;
115121
scopeValues: unknown[] | null;
116122
isStrictMode: boolean;
117-
hasDebugger: boolean;
118123
moduleName: string;
119124
owner: Owner | null;
120125
size: number;

packages/@glimmer/interfaces/lib/tier1/symbol-table.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface ProgramSymbolTable {
2-
hasDebugger: boolean;
32
symbols: string[];
43
}
54

packages/@glimmer/interfaces/lib/vm-opcodes.d.ts

-4
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ export type VmPutComponentOperations = 89;
9696
export type VmGetComponentSelf = 90;
9797
export type VmGetComponentTagName = 91;
9898
export type VmGetComponentLayout = 92;
99-
export type VmBindDebuggerScope = 93;
100-
export type VmSetupForDebugger = 94;
10199
export type VmPopulateLayout = 95;
102100
export type VmInvokeComponentLayout = 96;
103101
export type VmBeginComponentTransaction = 97;
@@ -193,8 +191,6 @@ export type VmOp =
193191
| VmGetComponentSelf
194192
| VmGetComponentTagName
195193
| VmGetComponentLayout
196-
| VmBindDebuggerScope
197-
| VmSetupForDebugger
198194
| VmPopulateLayout
199195
| VmInvokeComponentLayout
200196
| VmBeginComponentTransaction

packages/@glimmer/opcode-compiler/lib/compilable-template.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ class CompilableTemplateImpl<S extends SymbolTable> implements CompilableTemplat
5555
}
5656

5757
export function compilable(layout: LayoutWithContext, moduleName: string): CompilableProgram {
58-
let [statements, symbols, hasDebugger] = layout.block;
58+
let [statements, symbols] = layout.block;
5959
return new CompilableTemplateImpl(
6060
statements,
6161
meta(layout),
6262
{
6363
symbols,
64-
hasDebugger,
6564
},
6665
moduleName
6766
);

packages/@glimmer/opcode-compiler/lib/opcode-builder/encoder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class EncoderImpl implements Encoder {
193193
return encodeHandle(constants.value(this.meta.isStrictMode));
194194

195195
case HighLevelOperands.DebugSymbols:
196-
return encodeHandle(constants.value(this.meta.symbols));
196+
return encodeHandle(constants.value(operand.value));
197197

198198
case HighLevelOperands.Block:
199199
return encodeHandle(constants.value(compilableBlock(operand.value, this.meta)));

packages/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import {
5151
VM_SET_BLOCKS_OP,
5252
VM_SET_NAMED_VARIABLES_OP,
5353
VM_SET_VARIABLE_OP,
54-
VM_SETUP_FOR_DEBUGGER_OP,
5554
VM_VIRTUAL_ROOT_SCOPE_OP,
5655
} from '@glimmer/constants';
5756
import { unwrap } from '@glimmer/debug-util';
@@ -195,9 +194,7 @@ function InvokeStaticComponent(
195194
): void {
196195
let { symbolTable } = layout;
197196

198-
let bailOut =
199-
symbolTable.hasDebugger ||
200-
hasCapability(capabilities, InternalComponentCapabilities.prepareArgs);
197+
let bailOut = hasCapability(capabilities, InternalComponentCapabilities.prepareArgs);
201198

202199
if (bailOut) {
203200
InvokeNonStaticComponent(op, {
@@ -464,7 +461,6 @@ export function invokePreparedComponent(
464461

465462
op(VM_VIRTUAL_ROOT_SCOPE_OP, $s0);
466463
op(VM_SET_VARIABLE_OP, 0);
467-
op(VM_SETUP_FOR_DEBUGGER_OP, $s0);
468464

469465
if (bindableAtNames) op(VM_SET_NAMED_VARIABLES_OP, $s0);
470466
if (bindableBlocks) op(VM_SET_BLOCKS_OP, $s0);

0 commit comments

Comments
 (0)