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

Refactor Wrapper to Injected Service (WrapperFactory) #536

Merged
merged 24 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ea89232
Break up some dependencies in the expression directory
georg-schwarz Apr 2, 2024
e593726
Inject evaluator and type-computer registry as service
georg-schwarz Apr 2, 2024
15a1213
introduce WrapperFactory for creating BlockTypes and TypedObjects
georg-schwarz Apr 2, 2024
25d030c
Move constraintType wrapping to WrapperFactory
georg-schwarz Apr 2, 2024
27fe35f
Refactor structure of WrapperFactory
georg-schwarz Apr 2, 2024
133d40a
Rename ExpressionEvaluatorRegistry to OperatorEvaluatorRegistry
georg-schwarz Apr 2, 2024
3ebed50
Cleanup ValidationRegistry
georg-schwarz Apr 2, 2024
93e824f
Enforce WrapperFactory over BlocktypeWrapper and ConstraintTypeWrapper
georg-schwarz Apr 2, 2024
620432f
Add license header to new files
georg-schwarz Apr 2, 2024
ecf65ad
Fix docs build
georg-schwarz Apr 2, 2024
70a90a8
Simplify creation of WrapperFactory
georg-schwarz Apr 3, 2024
9abe83b
Add PipelineWrapper functionality to WrapperFactory
georg-schwarz Apr 3, 2024
f7b3c4b
Add PipeWrapper functionality to WrapperFactory
georg-schwarz Apr 3, 2024
85a881d
Add CellRangeWrapper functionality to WrapperFactory
georg-schwarz Apr 3, 2024
0e11e70
Reorganize cell-range util functionality
georg-schwarz Apr 3, 2024
05e21bd
Import WrapperFactory as type
georg-schwarz Apr 3, 2024
73ced3b
Add license infos to new files
georg-schwarz Apr 3, 2024
1dac8ca
Minor fixes to introduced changes (see self-code review)
georg-schwarz Apr 4, 2024
8db76f0
Simplify validation methods by introducing JayveeValidationProps as g…
georg-schwarz Apr 4, 2024
e1e9e01
Move method wrapTypedObject into a dedicated namespace in WrapperFactory
georg-schwarz Apr 4, 2024
c6a069c
Merge branch 'main' into dependency-cycles
georg-schwarz Apr 4, 2024
b167c38
Rename WrapperFactory to WrapperFactoryProvider
georg-schwarz Apr 5, 2024
eb35410
Fix typo in wrappers
georg-schwarz Apr 5, 2024
7f93694
Fix some jsdoc comments
georg-schwarz Apr 5, 2024
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: 2 additions & 0 deletions apps/docs/generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function generateBlockTypeDocs(
): void {
const blockTypes = getAllBuiltinBlocktypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
);

const docsPath = join(
Expand Down Expand Up @@ -72,6 +73,7 @@ function generateConstraintTypeDocs(
);
const constraintTypes = getAllBuiltinConstraintTypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
);

for (const constraintType of constraintTypes) {
Expand Down
4 changes: 2 additions & 2 deletions libs/execution/src/lib/blocks/block-execution-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
BlockDefinition,
CompositeBlocktypeDefinition,
PipelineDefinition,
PipelineWrapper,
} from '@jvalue/jayvee-language-server';

import { type ExecutionContext } from '../execution-context';
Expand Down Expand Up @@ -34,7 +33,8 @@ export async function executeBlocks(
pipesContainer: CompositeBlocktypeDefinition | PipelineDefinition,
initialInputValue: IOTypeImplementation | undefined = undefined,
): Promise<R.Result<ExecutionOrderItem[]>> {
const pipelineWrapper = new PipelineWrapper(pipesContainer);
const pipelineWrapper =
executionContext.wrapperFactories.Pipeline.wrap(pipesContainer);
const executionOrder: {
block: BlockDefinition;
value: IOTypeImplementation | null;
Expand Down
5 changes: 5 additions & 0 deletions libs/execution/src/lib/blocks/composite-block-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IOType,
InternalValueRepresentation,
Valuetype,
WrapperFactoryProvider,
createValuetype,
evaluateExpression,
evaluatePropertyValue,
Expand Down Expand Up @@ -133,6 +134,7 @@ export function createCompositeBlockExecutor(
block,
properties,
context.evaluationContext,
context.wrapperFactories,
);

assert(
Expand All @@ -153,6 +155,7 @@ export function createCompositeBlockExecutor(
block: BlockDefinition,
properties: BlocktypeProperty[],
evaluationContext: EvaluationContext,
wrapperFactories: WrapperFactoryProvider,
): InternalValueRepresentation | undefined {
const propertyFromBlock = block.body.properties.find(
(property) => property.name === name,
Expand All @@ -162,6 +165,7 @@ export function createCompositeBlockExecutor(
const value = evaluatePropertyValue(
propertyFromBlock,
evaluationContext,
wrapperFactories,
valueType,
);

Expand All @@ -181,6 +185,7 @@ export function createCompositeBlockExecutor(
return evaluateExpression(
propertyFromBlockType.defaultValue,
evaluationContext,
wrapperFactories,
);
}
};
Expand Down
10 changes: 5 additions & 5 deletions libs/execution/src/lib/blocks/execution-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export type Err = E.Left<ExecutionErrorDetails>;
export type Ok<T> = E.Right<T>;

/**
* Creates an @Ok object from a data object typed T.
* Creates an @see Ok object from a data object typed T.
* @param data the data object
* @returns the created @Ok object
* @returns the created @see Ok object
*/
export function ok<T>(data: T): Result<T> {
return E.right(data);
}
/**
* Creates an @Err object from a @ExecutionErrorDetails object.
* @param details the @ExecutionErrorDetails object
* @returns the created @Err object
* Creates an @see Err object from a @see ExecutionErrorDetails object.
* @param details the @see ExecutionErrorDetails object
* @returns the created @see Err object
*/
export function err<T>(details: ExecutionErrorDetails): Result<T> {
return E.left(details);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('default constraint extension', () => {

getAllBuiltinConstraintTypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
).forEach((constraintType) => {
const matchingConstraintExecutorClass = defaultConstraintExtension
.getConstraintExecutors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export class ExpressionConstraintExecutor

context.evaluationContext.setValueForValueKeyword(value);

const result = evaluateExpression(expression, context.evaluationContext);
const result = evaluateExpression(
expression,
context.evaluationContext,
context.wrapperFactories,
);
assert(PrimitiveValuetypes.Boolean.isInternalValueRepresentation(result));

context.evaluationContext.deleteValueForValueKeyword();
Expand Down
21 changes: 5 additions & 16 deletions libs/execution/src/lib/execution-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { strict as assert } from 'assert';

import {
BlockDefinition,
BlockTypeWrapper,
ConstraintDefinition,
ConstraintTypeWrapper,
EvaluationContext,
InternalValueRepresentation,
PipelineDefinition,
PropertyAssignment,
TransformDefinition,
Valuetype,
type WrapperFactoryProvider,
evaluatePropertyValue,
isBlockDefinition,
isExpressionConstraintDefinition,
Expand Down Expand Up @@ -46,6 +45,7 @@ export class ExecutionContext {
public readonly executionExtension: JayveeExecExtension,
public readonly constraintExtension: JayveeConstraintExtension,
public readonly logger: Logger,
public readonly wrapperFactories: WrapperFactoryProvider,
public readonly runOptions: {
isDebugMode: boolean;
debugGranularity: DebugGranularity;
Expand Down Expand Up @@ -99,6 +99,7 @@ export class ExecutionContext {
const propertyValue = evaluatePropertyValue(
property,
this.evaluationContext,
this.wrapperFactories,
valuetype,
);
assert(propertyValue !== undefined);
Expand Down Expand Up @@ -152,21 +153,9 @@ export class ExecutionContext {

assert(isReference(currentNode.type));
if (isTypedConstraintDefinition(currentNode)) {
assert(
ConstraintTypeWrapper.canBeWrapped(currentNode.type),
`ConstraintType ${
currentNode.type.ref?.name ?? '<unresolved reference>'
} cannot be wrapped`,
);
return new ConstraintTypeWrapper(currentNode.type);
return this.wrapperFactories.ConstraintType.wrap(currentNode.type);
} else if (isBlockDefinition(currentNode)) {
assert(
BlockTypeWrapper.canBeWrapped(currentNode.type),
`Blocktype ${
currentNode.type.ref?.name ?? '<unresolved reference>'
} cannot be wrapped`,
);
return new BlockTypeWrapper(currentNode.type);
return this.wrapperFactories.BlockType.wrap(currentNode.type);
}
assertUnreachable(currentNode);
}
Expand Down
1 change: 1 addition & 0 deletions libs/execution/src/lib/transforms/transform-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class TransformExecutor {
newValue = evaluateExpression(
this.getOutputAssignment().expression,
context.evaluationContext,
context.wrapperFactories,
);
} catch (e) {
if (e instanceof Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ValueRepresentationValidityVisitor extends ValuetypeVisitor<boolean> {

const constraints = valuetype.getConstraints(
this.context.evaluationContext,
this.context.wrapperFactories,
);
for (const constraint of constraints) {
const constraintExecutor =
Expand Down
10 changes: 9 additions & 1 deletion libs/execution/test/utils/test-infrastructure-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// SPDX-License-Identifier: AGPL-3.0-only

import {
DefaultOperatorEvaluatorRegistry,
EvaluationContext,
PipelineDefinition,
RuntimeParameterProvider,
WrapperFactoryProvider,
} from '@jvalue/jayvee-language-server';
import { AstNode, AstNodeLocator, LangiumDocument } from 'langium';

Expand Down Expand Up @@ -55,13 +57,19 @@ export function getTestExecutionContext(
'pipelines@0',
) as PipelineDefinition;

const operatorEvaluatorRegistry = new DefaultOperatorEvaluatorRegistry();

const executionContext = new ExecutionContext(
pipeline,
new TestExecExtension(),
new DefaultConstraintExtension(),
new CachedLogger(runOptions.isDebugMode, undefined, loggerPrintLogs),
new WrapperFactoryProvider(operatorEvaluatorRegistry),
runOptions,
new EvaluationContext(new RuntimeParameterProvider()),
new EvaluationContext(
new RuntimeParameterProvider(),
operatorEvaluatorRegistry,
),
);

initialStack.forEach((node) => executionContext.enterNode(node));
Expand Down
22 changes: 14 additions & 8 deletions libs/interpreter-lib/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
JayveeModel,
JayveeServices,
PipelineDefinition,
PipelineWrapper,
RuntimeParameterProvider,
WrapperFactoryProvider,
createJayveeServices,
initializeWorkspace,
internalValueToString,
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function interpretModel(
model,
new StdExecExtension(),
new DefaultConstraintExtension(),
services.RuntimeParameterProvider,
services,
loggerFactory,
{
debug: options.debug,
Expand Down Expand Up @@ -177,7 +177,7 @@ async function interpretJayveeModel(
model: JayveeModel,
executionExtension: JayveeExecExtension,
constraintExtension: JayveeConstraintExtension,
runtimeParameterProvider: RuntimeParameterProvider,
jayveeServices: JayveeServices,
loggerFactory: LoggerFactory,
runOptions: InterpreterOptions,
): Promise<ExitCode> {
Expand All @@ -186,7 +186,7 @@ async function interpretJayveeModel(
pipeline,
executionExtension,
constraintExtension,
runtimeParameterProvider,
jayveeServices,
loggerFactory,
runOptions,
);
Expand All @@ -203,7 +203,7 @@ async function runPipeline(
pipeline: PipelineDefinition,
executionExtension: JayveeExecExtension,
constraintExtension: JayveeConstraintExtension,
runtimeParameterProvider: RuntimeParameterProvider,
jayveeServices: JayveeServices,
loggerFactory: LoggerFactory,
runOptions: InterpreterOptions,
): Promise<ExitCode> {
Expand All @@ -212,18 +212,23 @@ async function runPipeline(
executionExtension,
constraintExtension,
loggerFactory.createLogger(),
jayveeServices.WrapperFactories,
{
isDebugMode: runOptions.debug,
debugGranularity: runOptions.debugGranularity,
debugTargets: runOptions.debugTargets,
},
new EvaluationContext(runtimeParameterProvider),
new EvaluationContext(
jayveeServices.RuntimeParameterProvider,
jayveeServices.operators.EvaluatorRegistry,
),
);

logPipelineOverview(
pipeline,
runtimeParameterProvider,
jayveeServices.RuntimeParameterProvider,
executionContext.logger,
jayveeServices.WrapperFactories,
);

const startTime = new Date();
Expand All @@ -248,8 +253,9 @@ export function logPipelineOverview(
pipeline: PipelineDefinition,
runtimeParameterProvider: RuntimeParameterProvider,
logger: Logger,
wrapperFactories: WrapperFactoryProvider,
) {
const pipelineWrapper = new PipelineWrapper(pipeline);
const pipelineWrapper = wrapperFactories.Pipeline.wrap(pipeline);

const toString = (block: BlockDefinition, depth = 0): string => {
const blockTypeName = block.type.ref?.name;
Expand Down
5 changes: 4 additions & 1 deletion libs/interpreter-lib/src/std-extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { NodeFileSystem } from 'langium/node';
async function loadAllBuiltinBlocktypes(): Promise<BlockTypeWrapper[]> {
const services = createJayveeServices(NodeFileSystem).Jayvee;
await initializeWorkspace(services);
return getAllBuiltinBlocktypes(services.shared.workspace.LangiumDocuments);
return getAllBuiltinBlocktypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
);
}

describe('std extension', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import * as path from 'path';

import { parseValueToInternalRepresentation } from '@jvalue/jayvee-execution';
import {
DefaultOperatorEvaluatorRegistry,
DefaultOperatorTypeComputerRegistry,
EvaluationContext,
RuntimeParameterLiteral,
RuntimeParameterProvider,
ValidationContext,
WrapperFactoryProvider,
createJayveeServices,
} from '@jvalue/jayvee-language-server';
import {
Expand Down Expand Up @@ -60,11 +63,24 @@ describe('Validation of validateRuntimeParameterLiteral', () => {
}
}

validateRuntimeParameterLiteral(
runtimeParameter,
new ValidationContext(validationAcceptorMock),
new EvaluationContext(runtimeProvider),
const operatorEvaluatorRegistry = new DefaultOperatorEvaluatorRegistry();
const operatorTypeComputerRegistry =
new DefaultOperatorTypeComputerRegistry();
const wrapperFactories = new WrapperFactoryProvider(
operatorEvaluatorRegistry,
);

validateRuntimeParameterLiteral(runtimeParameter, {
validationContext: new ValidationContext(
validationAcceptorMock,
operatorTypeComputerRegistry,
),
evaluationContext: new EvaluationContext(
runtimeProvider,
operatorEvaluatorRegistry,
),
wrapperFactories: wrapperFactories,
});
}

beforeAll(async () => {
Expand Down
Loading
Loading