Skip to content

Commit

Permalink
Merge pull request #1663 from glimmerjs/internals/streamline-and-mode…
Browse files Browse the repository at this point in the history
…rnize-naming

Streamline and modernize naming
  • Loading branch information
NullVoxPopuli authored Nov 18, 2024
2 parents e7bcee4 + 505b8be commit 33ed91b
Show file tree
Hide file tree
Showing 62 changed files with 840 additions and 803 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
InternalModifierManager,
ModifierDefinitionState,
ResolvedComponentDefinition,
SimpleDocument,
SimpleElement,
} from '@glimmer/interfaces';
import {
Expand All @@ -13,11 +14,13 @@ import {
setInternalHelperManager,
setInternalModifierManager,
} from '@glimmer/manager';
import { programCompilationContext } from '@glimmer/opcode-compiler';
import { EvaluationContextImpl } from '@glimmer/opcode-compiler';
import { artifacts, RuntimeOpImpl } from '@glimmer/program';
import { runtimeContext } from '@glimmer/runtime';

import type { UpdateBenchmark } from '../interfaces';

import createEnvDelegate from './create-env-delegate';
import renderBenchmark from './render-benchmark';

export interface Registry {
Expand Down Expand Up @@ -77,9 +80,15 @@ export default function createRegistry(): Registry {
setInternalModifierManager(manager, modifier);
modifiers.set(name, modifier);
},
render: (entry, args, element, isIteractive) => {
render: (entry, args, element, isInteractive) => {
const sharedArtifacts = artifacts();
const context = programCompilationContext(
const document = element.ownerDocument as SimpleDocument;
const envDelegate = createEnvDelegate(isInteractive ?? true);
const runtime = runtimeContext(
{
document,
},
envDelegate,
sharedArtifacts,
{
lookupHelper: (name) => helpers.get(name) ?? null,
Expand All @@ -88,25 +97,20 @@ export default function createRegistry(): Registry {

lookupBuiltInHelper: () => null,
lookupBuiltInModifier: () => null,
},
(heap) => new RuntimeOpImpl(heap)
}
);

const context = new EvaluationContextImpl(
sharedArtifacts,
(heap) => new RuntimeOpImpl(heap),
runtime
);
const component = components.get(entry);
if (!component) {
throw new Error(`missing ${entry} component`);
}

return renderBenchmark(
sharedArtifacts,
context,
{
lookupComponent: () => null,
},
component,
args,
element as SimpleElement,
isIteractive
);
return renderBenchmark(context, component, args, element as SimpleElement);
},
};
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
import type {
CompileTimeCompilationContext,
Dict,
EvaluationContext,
ResolvedComponentDefinition,
RuntimeArtifacts,
RuntimeResolver,
SimpleElement,
} from '@glimmer/interfaces';
import { NewElementBuilder, renderComponent, renderSync, runtimeContext } from '@glimmer/runtime';
import { NewTreeBuilder, renderComponent, renderSync } from '@glimmer/runtime';

import type { UpdateBenchmark } from '../interfaces';

import createEnvDelegate, { registerResult } from './create-env-delegate';
import { registerResult } from './create-env-delegate';
import { measureRender } from './util';

export default async function renderBenchmark(
artifacts: RuntimeArtifacts,
context: CompileTimeCompilationContext,
runtimeResolver: RuntimeResolver,
context: EvaluationContext,
component: ResolvedComponentDefinition,
args: Dict,
element: SimpleElement,
isInteractive = true
element: SimpleElement
): Promise<UpdateBenchmark> {
let resolveRender: (() => void) | undefined;

await measureRender('render', 'renderStart', 'renderEnd', () => {
const document = element.ownerDocument;
const envDelegate = createEnvDelegate(isInteractive);
const runtime = runtimeContext(
{
document,
},
envDelegate,
artifacts,
runtimeResolver
);
const env = runtime.env;
const env = context.env;
const cursor = { element, nextSibling: null };
const treeBuilder = NewElementBuilder.forInitialRender(env, cursor);
const treeBuilder = NewTreeBuilder.forInitialRender(env, cursor);

const result = renderSync(
env,
renderComponent(runtime, treeBuilder, context, {}, component.state, args)
renderComponent(context, treeBuilder, {}, component.state, args)
);

registerResult(result, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CompileTimeCompilationContext, CompileTimeComponent } from '@glimmer/interfaces';
import type { CompileTimeComponent, EvaluationContext } from '@glimmer/interfaces';
import { unwrapHandle } from '@glimmer/debug-util';

export function compileEntry(entry: CompileTimeComponent, context: CompileTimeCompilationContext) {
export function compileEntry(entry: CompileTimeComponent, context: EvaluationContext) {
return unwrapHandle(entry.compilable!.compile(context));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
CompileTimeResolver,
ClassicResolver,
HelperDefinitionState,
ModifierDefinitionState,
Nullable,
Expand All @@ -8,7 +8,7 @@ import type {

import type { TestJitRuntimeResolver } from './resolver';

export default class JitCompileTimeLookup implements CompileTimeResolver {
export default class JitCompileTimeLookup implements ClassicResolver {
constructor(private resolver: TestJitRuntimeResolver) {}

lookupHelper(name: string): Nullable<HelperDefinitionState> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import type {
CapturedRenderNode,
CompileTimeCompilationContext,
Cursor,
Dict,
DynamicScope,
ElementBuilder,
ElementNamespace,
Environment,
EvaluationContext,
HandleResult,
Helper,
Nullable,
RenderResult,
RuntimeContext,
SimpleDocument,
SimpleDocumentFragment,
SimpleElement,
SimpleText,
TreeBuilder,
} from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import type { CurriedValue, EnvironmentDelegate } from '@glimmer/runtime';
import type { ASTPluginBuilder, PrecompileOptions } from '@glimmer/syntax';
import { castToBrowser, castToSimple, expect, unwrapTemplate } from '@glimmer/debug-util';
import { programCompilationContext } from '@glimmer/opcode-compiler';
import { EvaluationContextImpl } from '@glimmer/opcode-compiler';
import { artifacts, RuntimeOpImpl } from '@glimmer/program';
import { createConstRef } from '@glimmer/reference';
import {
Expand Down Expand Up @@ -58,24 +57,20 @@ import { TestJitRegistry } from './registry';
import { renderTemplate } from './render';
import { TestJitRuntimeResolver } from './resolver';

export interface JitTestDelegateContext {
runtime: RuntimeContext;
program: CompileTimeCompilationContext;
}

export function JitDelegateContext(
doc: SimpleDocument,
resolver: TestJitRuntimeResolver,
env: EnvironmentDelegate
): JitTestDelegateContext {
): EvaluationContext {
let sharedArtifacts = artifacts();
let context = programCompilationContext(
let runtime = runtimeContext(
{ document: doc },
env,
sharedArtifacts,
new JitCompileTimeLookup(resolver),
(heap) => new RuntimeOpImpl(heap)
new JitCompileTimeLookup(resolver)
);
let runtime = runtimeContext({ document: doc }, env, sharedArtifacts, resolver);
return { runtime, program: context };

return new EvaluationContextImpl(sharedArtifacts, (heap) => new RuntimeOpImpl(heap), runtime);
}

export class JitRenderDelegate implements RenderDelegate {
Expand All @@ -86,7 +81,7 @@ export class JitRenderDelegate implements RenderDelegate {
protected resolver: TestJitRuntimeResolver;

private plugins: ASTPluginBuilder[] = [];
private _context: JitTestDelegateContext | null = null;
private _context: Nullable<EvaluationContext> = null;
private self: Nullable<Reference> = null;
private doc: SimpleDocument;
private env: EnvironmentDelegate;
Expand All @@ -108,7 +103,7 @@ export class JitRenderDelegate implements RenderDelegate {
this.registry.register('helper', 'concat', concat);
}

get context(): JitTestDelegateContext {
get context(): EvaluationContext {
if (this._context === null) {
this._context = JitDelegateContext(this.doc, this.resolver, this.env);
}
Expand All @@ -118,7 +113,7 @@ export class JitRenderDelegate implements RenderDelegate {

getCapturedRenderTree(): CapturedRenderNode[] {
return expect(
this.context.runtime.env.debugRenderTree,
this.context.env.debugRenderTree,
'Attempted to capture the DebugRenderTree during tests, but it was not created. Did you enable it in the environment?'
).capture();
}
Expand Down Expand Up @@ -191,7 +186,7 @@ export class JitRenderDelegate implements RenderDelegate {
registerInternalHelper(this.registry, name, helper);
}

getElementBuilder(env: Environment, cursor: Cursor): ElementBuilder {
getElementBuilder(env: Environment, cursor: Cursor): TreeBuilder {
return clientBuilder(env, cursor);
}

Expand All @@ -206,13 +201,13 @@ export class JitRenderDelegate implements RenderDelegate {
compileTemplate(template: string): HandleResult {
let compiled = preprocess(template, this.precompileOptions);

return unwrapTemplate(compiled).asLayout().compile(this.context.program);
return unwrapTemplate(compiled).asLayout().compile(this.context);
}

renderTemplate(template: string, context: Dict<unknown>, element: SimpleElement): RenderResult {
let cursor = { element, nextSibling: null };

let { env } = this.context.runtime;
let { env } = this.context;

return renderTemplate(
template,
Expand All @@ -230,11 +225,11 @@ export class JitRenderDelegate implements RenderDelegate {
dynamicScope?: DynamicScope
): RenderResult {
let cursor = { element, nextSibling: null };
let { program, runtime } = this.context;
let builder = this.getElementBuilder(runtime.env, cursor);
let iterator = renderComponent(runtime, builder, program, {}, component, args, dynamicScope);
let { env } = this.context;
let builder = this.getElementBuilder(env, cursor);
let iterator = renderComponent(this.context, builder, {}, component, args, dynamicScope);

return renderSync(runtime.env, iterator);
return renderSync(env, iterator);
}

private get precompileOptions(): PrecompileOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import type { ElementBuilder, RenderResult } from '@glimmer/interfaces';
import type { EvaluationContext, RenderResult, TreeBuilder } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference';
import type { PrecompileOptions } from '@glimmer/syntax';
import { unwrapTemplate } from '@glimmer/debug-util';
import { renderMain, renderSync } from '@glimmer/runtime';

import type { JitTestDelegateContext } from './delegate';

import { preprocess } from '../../compile';

export function renderTemplate(
src: string,
{ runtime, program }: JitTestDelegateContext,
context: EvaluationContext,
self: Reference,
builder: ElementBuilder,
builder: TreeBuilder,
options?: PrecompileOptions
): RenderResult {
let template = preprocess(src, options);

let iterator = renderMain(
runtime,
program,
{},
self,
builder,
unwrapTemplate(template).asLayout()
);
return renderSync(runtime.env, iterator);
let iterator = renderMain(context, {}, self, builder, unwrapTemplate(template).asLayout());
return renderSync(context.env, iterator);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type {
ClassicResolver,
HelperDefinitionState,
ModifierDefinitionState,
Nullable,
ResolvedComponentDefinition,
RuntimeResolver,
} from '@glimmer/interfaces';

import type { TestJitRegistry } from './registry';

export class TestJitRuntimeResolver implements RuntimeResolver {
export class TestJitRuntimeResolver implements ClassicResolver {
constructor(private registry: TestJitRegistry) {}

lookupHelper(name: string): Nullable<HelperDefinitionState> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Cursor, ElementBuilder, Environment, SimpleNode } from '@glimmer/interfaces';
import type { Cursor, Environment, SimpleNode, TreeBuilder } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { RehydrateBuilder } from '@glimmer/runtime';

Expand All @@ -23,6 +23,6 @@ export class DebugRehydrationBuilder extends RehydrateBuilder {
}
}

export function debugRehydration(env: Environment, cursor: Cursor): ElementBuilder {
export function debugRehydration(env: Environment, cursor: Cursor): TreeBuilder {
return DebugRehydrationBuilder.forInitialRender(env, cursor);
}
Loading

0 comments on commit 33ed91b

Please sign in to comment.