Skip to content

Commit 3b315b3

Browse files
committed
Fix errors
1 parent 7d7d1bd commit 3b315b3

File tree

20 files changed

+102
-178
lines changed

20 files changed

+102
-178
lines changed

packages/@glimmer-workspace/benchmark-env/lib/benchmark/create-registry.ts

+6-19
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ export default function createRegistry(): Registry {
8989
document,
9090
},
9191
envDelegate,
92-
sharedArtifacts,
93-
{
94-
lookupComponent: () => null,
95-
}
96-
);
97-
98-
const context = new EvaluationContextImpl(
9992
sharedArtifacts,
10093
{
10194
lookupHelper: (name) => helpers.get(name) ?? null,
@@ -104,7 +97,11 @@ export default function createRegistry(): Registry {
10497

10598
lookupBuiltInHelper: () => null,
10699
lookupBuiltInModifier: () => null,
107-
},
100+
}
101+
);
102+
103+
const context = new EvaluationContextImpl(
104+
sharedArtifacts,
108105
(heap) => new RuntimeOpImpl(heap),
109106
runtime
110107
);
@@ -113,17 +110,7 @@ export default function createRegistry(): Registry {
113110
throw new Error(`missing ${entry} component`);
114111
}
115112

116-
return renderBenchmark(
117-
sharedArtifacts,
118-
context,
119-
{
120-
lookupComponent: () => null,
121-
},
122-
component,
123-
args,
124-
element as SimpleElement,
125-
isInteractive
126-
);
113+
return renderBenchmark(context, component, args, element as SimpleElement);
127114
},
128115
};
129116
}

packages/@glimmer-workspace/benchmark-env/lib/benchmark/render-benchmark.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
Dict,
33
EvaluationContext,
44
ResolvedComponentDefinition,
5-
RuntimeArtifacts,
65
SimpleElement,
76
} from '@glimmer/interfaces';
87
import { NewTreeBuilder, renderComponent, renderSync } from '@glimmer/runtime';
@@ -13,7 +12,6 @@ import { registerResult } from './create-env-delegate';
1312
import { measureRender } from './util';
1413

1514
export default async function renderBenchmark(
16-
artifacts: RuntimeArtifacts,
1715
context: EvaluationContext,
1816
component: ResolvedComponentDefinition,
1917
args: Dict,

packages/@glimmer-workspace/integration-tests/lib/modes/rehydration/partial-rehydration-delegate.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export class PartialRehydrationDelegate extends RehydrationDelegate {
1616
element: SimpleElement
1717
): RenderResult {
1818
let cursor = { element, nextSibling: null };
19-
let { program, runtime } = this.clientEnv;
20-
let builder = this.getElementBuilder(runtime.env, cursor) as DebugRehydrationBuilder;
19+
let context = this.clientContext;
20+
let builder = this.getElementBuilder(context.env, cursor) as DebugRehydrationBuilder;
2121
let component = this.clientRegistry.lookupComponent(name)!;
2222

23-
let iterator = renderComponent(runtime, builder, program, {}, component.state, args);
23+
let iterator = renderComponent(context, builder, {}, component.state, args);
2424

25-
const result = renderSync(runtime.env, iterator);
25+
const result = renderSync(context.env, iterator);
2626

2727
this.rehydrationStats = {
2828
clearedNodes: builder.clearedNodes,
@@ -34,14 +34,14 @@ export class PartialRehydrationDelegate extends RehydrationDelegate {
3434
renderComponentServerSide(name: string, args: Dict<unknown>): string {
3535
const element = this.serverDoc.createElement('div');
3636
let cursor = { element, nextSibling: null };
37-
let { program, runtime } = this.serverEnv;
38-
let builder = this.getElementBuilder(runtime.env, cursor);
37+
let context = this.serverContext;
38+
let builder = this.getElementBuilder(context.env, cursor);
3939

4040
let component = this.serverRegistry.lookupComponent(name)!;
4141

42-
let iterator = renderComponent(runtime, builder, program, {}, component.state, args);
42+
let iterator = renderComponent(context, builder, {}, component.state, args);
4343

44-
renderSync(runtime.env, iterator);
44+
renderSync(context.env, iterator);
4545

4646
return this.serialize(element);
4747
}

packages/@glimmer-workspace/integration-tests/test/debug-render-tree-test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,8 @@ class DebugRenderTreeTest extends RenderTest {
254254
args: (actual) => {
255255
const args = { positional: [], named: { arg: 'first', arg2: { error } } };
256256
this.assert.deepEqual(actual, args);
257-
this.assert.ok(
258-
!this.delegate.context.runtime.env.isArgumentCaptureError!(actual.named['arg'])
259-
);
260-
this.assert.ok(
261-
this.delegate.context.runtime.env.isArgumentCaptureError!(actual.named['arg2'])
262-
);
257+
this.assert.ok(!this.delegate.context.env.isArgumentCaptureError!(actual.named['arg']));
258+
this.assert.ok(this.delegate.context.env.isArgumentCaptureError!(actual.named['arg2']));
263259
return true;
264260
},
265261
instance: (instance: EmberishCurlyComponent) => (instance as any).arg === 'first',

packages/@glimmer/debug-util/lib/platform-utils.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ export function unwrap<T>(val: Maybe<T>): T {
1010
return val as T;
1111
}
1212

13-
export const expect = (
14-
LOCAL_DEBUG
15-
? <T>(value: T, _message: string) => value
16-
: <T>(val: T, message: string): Present<T> => {
17-
if (LOCAL_DEBUG) if (val === null || val === undefined) throw new Error(message);
18-
return val as Present<T>;
19-
}
20-
) as <T>(value: T, message: string) => NonNullable<T>;
13+
export const expect = (LOCAL_DEBUG
14+
? <T>(value: T, _message: string) => value
15+
: <T>(val: T, message: string): Present<T> => {
16+
if (LOCAL_DEBUG) if (val === null || val === undefined) throw new Error(message);
17+
return val as Present<T>;
18+
}) as <T>(value: T, message: string) => NonNullable<T> as <T>(
19+
value: T,
20+
message: string
21+
) => Present<T>;
2122

2223
export const unreachable = LOCAL_DEBUG
2324
? () => {}

packages/@glimmer/interfaces/lib/managers/internal/component.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import type { ComponentInstanceState, PreparedArguments } from '../../components
22
import type { Destroyable, Nullable } from '../../core.js';
33
import type { Bounds } from '../../dom/bounds.js';
44
import type { SimpleElement } from '../../dom/simple.js';
5+
import type { ClassicResolver } from '../../program.js';
56
import type { Reference } from '../../references.js';
67
import type { Owner } from '../../runtime.js';
78
import type { CapturedArguments, VMArguments } from '../../runtime/arguments.js';
89
import type { RenderNode } from '../../runtime/debug-render-tree.js';
910
import type { ElementOperations } from '../../runtime/element.js';
1011
import type { Environment } from '../../runtime/environment.js';
1112
import type { DynamicScope } from '../../runtime/scope.js';
12-
import type { RuntimeResolver } from '../../serialize.js';
1313
import type { CompilableProgram } from '../../template.js';
1414
import type { ProgramSymbolTable } from '../../tier1/symbol-table.js';
1515

@@ -237,7 +237,7 @@ export interface WithUpdateHook<ComponentInstanceState = unknown>
237237

238238
export interface WithDynamicLayout<
239239
I = ComponentInstanceState,
240-
R extends RuntimeResolver = RuntimeResolver,
240+
R extends ClassicResolver = ClassicResolver,
241241
> extends InternalComponentManager<I> {
242242
// Return the compiled layout to use for this component. This is called
243243
// *after* the component instance has been created, because you might

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {
2-
ContainingMetadata,
2+
BlockMetadata,
33
LayoutWithContext,
44
NamedBlocks,
55
Nullable,
@@ -105,7 +105,7 @@ export function CompilePositional(
105105
return positional.length;
106106
}
107107

108-
export function meta(layout: LayoutWithContext): ContainingMetadata {
108+
export function meta(layout: LayoutWithContext): BlockMetadata {
109109
let [, symbols, , upvars, debugSymbols] = layout.block;
110110

111111
return {

packages/@glimmer/program/lib/constants.ts

+24-56
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import type {
2-
CompileTimeConstants,
32
ComponentDefinition,
43
ComponentDefinitionState,
54
ConstantPool,
65
HelperDefinitionState,
76
ModifierDefinitionState,
8-
ResolutionTimeConstants,
9-
ResolvedComponentDefinition,
107
ProgramConstants,
8+
ResolvedComponentDefinition,
119
Template,
1210
} from '@glimmer/interfaces';
1311
import { constants } from '@glimmer/constants';
@@ -30,14 +28,33 @@ const WELL_KNOWN_EMPTY_ARRAY: unknown = Object.freeze([]);
3028
const STARTER_CONSTANTS = constants(WELL_KNOWN_EMPTY_ARRAY);
3129
const WELL_KNOWN_EMPTY_ARRAY_POSITION: number = STARTER_CONSTANTS.indexOf(WELL_KNOWN_EMPTY_ARRAY);
3230

33-
export class CompileTimeConstantImpl implements CompileTimeConstants {
34-
// `0` means NULL
31+
export class ConstantsImpl implements ProgramConstants {
32+
protected reifiedArrs: { [key: number]: unknown[] } = {
33+
[WELL_KNOWN_EMPTY_ARRAY_POSITION]: WELL_KNOWN_EMPTY_ARRAY as unknown[],
34+
};
35+
36+
defaultTemplate: Template = templateFactory(DEFAULT_TEMPLATE)();
37+
38+
// Used for tests and debugging purposes, and to be able to analyze large apps
39+
// This is why it's enabled even in production
40+
helperDefinitionCount = 0;
41+
modifierDefinitionCount = 0;
42+
componentDefinitionCount = 0;
3543

36-
protected values: unknown[] = STARTER_CONSTANTS.slice();
37-
protected indexMap: Map<unknown, number> = new Map(
44+
private values: unknown[] = STARTER_CONSTANTS.slice();
45+
private indexMap: Map<unknown, number> = new Map(
3846
this.values.map((value, index) => [value, index])
3947
);
4048

49+
private helperDefinitionCache = new WeakMap<HelperDefinitionState, number | null>();
50+
51+
private modifierDefinitionCache = new WeakMap<ModifierDefinitionState, number | null>();
52+
53+
private componentDefinitionCache = new WeakMap<
54+
ComponentDefinitionState | ResolvedComponentDefinition,
55+
ComponentDefinition | null
56+
>();
57+
4158
value(value: unknown) {
4259
let indexMap = this.indexMap;
4360
let index = indexMap.get(value);
@@ -67,55 +84,6 @@ export class CompileTimeConstantImpl implements CompileTimeConstants {
6784
toPool(): ConstantPool {
6885
return this.values;
6986
}
70-
}
71-
72-
export class RuntimeConstantsImpl implements ProgramConstants {
73-
protected values: unknown[];
74-
75-
constructor(pool: ConstantPool) {
76-
this.values = pool;
77-
}
78-
79-
getValue<T>(handle: number) {
80-
return this.values[handle] as T;
81-
}
82-
83-
getArray<T>(value: number): T[] {
84-
let handles = this.getValue<number[]>(value);
85-
let reified: T[] = new Array(handles.length);
86-
87-
for (const [i, n] of enumerate(handles)) {
88-
reified[i] = this.getValue(n);
89-
}
90-
91-
return reified;
92-
}
93-
}
94-
95-
export class ConstantsImpl
96-
extends CompileTimeConstantImpl
97-
implements ProgramConstants, ResolutionTimeConstants
98-
{
99-
protected reifiedArrs: { [key: number]: unknown[] } = {
100-
[WELL_KNOWN_EMPTY_ARRAY_POSITION]: WELL_KNOWN_EMPTY_ARRAY as unknown[],
101-
};
102-
103-
defaultTemplate: Template = templateFactory(DEFAULT_TEMPLATE)();
104-
105-
// Used for tests and debugging purposes, and to be able to analyze large apps
106-
// This is why it's enabled even in production
107-
helperDefinitionCount = 0;
108-
modifierDefinitionCount = 0;
109-
componentDefinitionCount = 0;
110-
111-
private helperDefinitionCache = new WeakMap<HelperDefinitionState, number | null>();
112-
113-
private modifierDefinitionCache = new WeakMap<ModifierDefinitionState, number | null>();
114-
115-
private componentDefinitionCache = new WeakMap<
116-
ComponentDefinitionState | ResolvedComponentDefinition,
117-
ComponentDefinition | null
118-
>();
11987

12088
helper(
12189
definitionState: HelperDefinitionState,
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { RuntimeArtifacts } from '@glimmer/interfaces';
22

33
import { ConstantsImpl } from './constants';
4-
import { HeapImpl } from './program';
4+
import { ProgramHeapImpl } from './program';
55

66
export function artifacts(): RuntimeArtifacts {
77
return {
88
constants: new ConstantsImpl(),
9-
heap: new HeapImpl(),
9+
heap: new ProgramHeapImpl(),
1010
};
1111
}

packages/@glimmer/program/lib/opcode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { OpcodeHeap, RuntimeOp, SomeVmOp } from '@glimmer/interfaces';
1+
import type { ProgramHeap, RuntimeOp, SomeVmOp } from '@glimmer/interfaces';
22
import { ARG_SHIFT, MACHINE_MASK, OPERAND_LEN_MASK, TYPE_MASK } from '@glimmer/vm';
33

44
export class RuntimeOpImpl implements RuntimeOp {
55
public offset = 0;
6-
constructor(readonly heap: OpcodeHeap) {}
6+
constructor(readonly heap: ProgramHeap) {}
77

88
get size() {
99
let rawType = this.heap.getbyaddr(this.offset);

packages/@glimmer/program/lib/program.ts

+7-38
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type {
2-
JitConstants,
2+
Program,
3+
ProgramConstants,
34
ProgramHeap,
4-
RuntimeHeap,
5-
RuntimeProgram,
65
SerializedHeap,
76
StdLibOperand,
87
} from '@glimmer/interfaces';
9-
import { expect, unwrap } from '@glimmer/debug-util';
8+
import { unwrap } from '@glimmer/debug-util';
109
import { LOCAL_DEBUG } from '@glimmer/local-debug-flags';
1110
import { MACHINE_MASK } from '@glimmer/vm';
1211

@@ -24,36 +23,6 @@ export type StdlibPlaceholder = [number, StdLibOperand];
2423

2524
const PAGE_SIZE = 0x100000;
2625

27-
export class RuntimeHeapImpl implements RuntimeHeap {
28-
private heap: Int32Array;
29-
private table: number[];
30-
31-
constructor(serializedHeap: SerializedHeap) {
32-
let { buffer, table } = serializedHeap;
33-
this.heap = new Int32Array(buffer);
34-
this.table = table;
35-
}
36-
37-
// It is illegal to close over this address, as compaction
38-
// may move it. However, it is legal to use this address
39-
// multiple times between compactions.
40-
getaddr(handle: number): number {
41-
return unwrap(this.table[handle]);
42-
}
43-
44-
getbyaddr(address: number): number {
45-
return expect(this.heap[address], 'Access memory out of bounds of the heap');
46-
}
47-
48-
sizeof(handle: number): number {
49-
return sizeof(this.table, handle);
50-
}
51-
}
52-
53-
export function hydrateHeap(serializedHeap: SerializedHeap): RuntimeHeap {
54-
return new RuntimeHeapImpl(serializedHeap);
55-
}
56-
5726
/**
5827
* The Heap is responsible for dynamically allocating
5928
* memory in which we read/write the VM's instructions
@@ -74,7 +43,7 @@ export function hydrateHeap(serializedHeap: SerializedHeap): RuntimeHeap {
7443
* valid during the execution. This means you cannot close
7544
* over them as you will have a bad memory access exception.
7645
*/
77-
export class HeapImpl implements ProgramHeap, RuntimeHeap {
46+
export class ProgramHeapImpl implements ProgramHeap {
7847
offset = 0;
7948

8049
private heap: Int32Array;
@@ -202,14 +171,14 @@ export class HeapImpl implements ProgramHeap, RuntimeHeap {
202171
}
203172
}
204173

205-
export class RuntimeProgramImpl implements RuntimeProgram {
174+
export class ProgramImpl implements Program {
206175
[key: number]: never;
207176

208177
private _opcode: RuntimeOpImpl;
209178

210179
constructor(
211-
public constants: JitConstants,
212-
public heap: RuntimeHeap
180+
public constants: ProgramConstants,
181+
public heap: ProgramHeap
213182
) {
214183
this._opcode = new RuntimeOpImpl(this.heap);
215184
}

0 commit comments

Comments
 (0)