From 7418c75425c3b2a816282b7f2b93ccfd75367e27 Mon Sep 17 00:00:00 2001 From: "Kim, Jake" Date: Thu, 9 Jan 2025 13:53:37 -0500 Subject: [PATCH 1/3] Move special handling for PackageableElementPtr in ValueSpecificationBuilderForFuncExpr to ValueSpecificationBuilder --- .../compiler/toPureGraph/CompileContext.java | 8 +- .../HelperValueSpecificationBuilder.java | 2 +- .../ValueSpecificationBuilder.java | 88 +++++++++++++----- .../ValueSpecificationBuilderForFuncExpr.java | 90 ------------------- .../toPureGraph/handlers/Handlers.java | 8 +- .../CompositeFunctionExpressionBuilder.java | 11 +-- .../builder/FunctionExpressionBuilder.java | 4 +- ...MultiHandlerFunctionExpressionBuilder.java | 12 +-- ...larSignatureFunctionExpressionBuilder.java | 11 +-- 9 files changed, 97 insertions(+), 137 deletions(-) delete mode 100644 legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilderForFuncExpr.java diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java index 9251d930c07..0b26074f6de 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java @@ -36,6 +36,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section; import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; import org.finos.legend.engine.protocol.pure.v1.model.type.relationType.RelationType; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; @@ -456,13 +457,14 @@ public org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag r // ------------------------------------------ FUNCTION EXPRESSION BUILDER ----------------------------------------- - public Pair> buildFunctionExpression(String functionName, String fControl, List parameters, MutableList openVariables, SourceInformation sourceInformation, ProcessingContext processingContext) + public Pair> buildFunctionExpression(String functionName, String fControl, List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) { Pair> functionExpression; - functionExpression = this.pureModel.handlers.buildFunctionExpression(functionName, parameters, openVariables, sourceInformation, this, processingContext); + ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; + functionExpression = this.pureModel.handlers.buildFunctionExpression(functionName, parameters, sourceInformation, valueSpecificationBuilder); if (fControl != null) { - testFunction(fControl, processingContext, functionExpression.getOne()); + testFunction(fControl, valueSpecificationBuilder.getProcessingContext(), functionExpression.getOne()); } return functionExpression; } diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java index 1108843c944..dc3dcb83ce8 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java @@ -274,7 +274,7 @@ else if (foundFunction instanceof QualifiedProperty) automapLambda.parameters = lambdaParams; List newParams = Lists.mutable.of(parameters.get(0), automapLambda); MilestoningDatePropagationHelper.updateMilestoningPropagationContextWhileReprocessingFunctionExpression(processingContext); - result = context.buildFunctionExpression("map", null, newParams, openVariables, sourceInformation, processingContext).getOne(); + result = context.buildFunctionExpression("map", null, newParams, sourceInformation, new ValueSpecificationBuilder(context, openVariables, processingContext)).getOne(); processingContext.pop(); } else diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java index 74af5658271..1aaf20277fb 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java @@ -94,6 +94,7 @@ import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_SimpleFunctionExpression_Impl; import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl; import org.finos.legend.pure.generated.Root_meta_pure_runtime_ExecutionContext; +import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime; import org.finos.legend.pure.generated.Root_meta_pure_tds_AggregateValue_Impl; import org.finos.legend.pure.generated.Root_meta_pure_tds_BasicColumnSpecification_Impl; import org.finos.legend.pure.generated.Root_meta_pure_tds_SortInformation_Impl; @@ -130,12 +131,27 @@ import java.util.Objects; import java.util.Optional; -public class ValueSpecificationBuilder implements ValueSpecificationVisitor +public final class ValueSpecificationBuilder implements ValueSpecificationVisitor { private final CompileContext context; private final MutableList openVariables; private final ProcessingContext processingContext; + public CompileContext getContext() + { + return context; + } + + public MutableList getOpenVariables() + { + return openVariables; + } + + public ProcessingContext getProcessingContext() + { + return processingContext; + } + public ValueSpecificationBuilder(CompileContext context, MutableList openVariables, ProcessingContext processingContext) { this.context = context; @@ -162,10 +178,38 @@ public ValueSpecification visit(PackageableElementPtr packageableElementPtr) return visit(new UnitType(packageableElementPtr.fullPath, packageableElementPtr.sourceInformation)); } org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement packageableElement = this.context.resolvePackageableElement(packageableElementPtr.fullPath, packageableElementPtr.sourceInformation); - return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) - ._genericType(packageableElement._classifierGenericType()) - ._multiplicity(this.context.pureModel.getMultiplicity("one")) - ._values(Lists.immutable.with(packageableElement)); + + if (packageableElement instanceof Root_meta_pure_runtime_PackageableRuntime) + { + Root_meta_core_runtime_Runtime resolvedRuntime = this.context.resolveRuntime(packageableElementPtr.fullPath); + GenericType runtimeGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass(M3Paths.GenericType)) + ._rawType(this.context.pureModel.getType("meta::core::runtime::Runtime")); + return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) + ._genericType(runtimeGenericType) + ._multiplicity(this.context.pureModel.getMultiplicity("one")) + ._values(Lists.mutable.with(resolvedRuntime)); + } + + MutableList values = this.context.getCompilerExtensions().getExtraValueSpecificationBuilderForFuncExpr().collect(x -> x.value(packageableElement, this.context, this.processingContext), Lists.mutable.empty()); + values.removeIf(Objects::isNull); + switch (values.size()) + { + case 0: + { + return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) + ._genericType(packageableElement._classifierGenericType()) + ._multiplicity(this.context.pureModel.getMultiplicity("one")) + ._values(Lists.mutable.with(packageableElement)); + } + case 1: + { + return values.get(0); + } + default: + { + throw new EngineException("More than one handler found for the Packageable Element '" + packageableElementPtr.fullPath + "'", packageableElementPtr.sourceInformation, EngineErrorType.COMPILATION); + } + } } @Override @@ -224,8 +268,8 @@ public ValueSpecification visit(CStrictTime cStrictTime) public ValueSpecification processClassInstance(AggregateValue aggregateValue) { - LambdaFunction l = (LambdaFunction) ((InstanceValue) aggregateValue.mapFn.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))._values().getFirst(); - LambdaFunction o = (LambdaFunction) ((InstanceValue) aggregateValue.aggregateFn.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))._values().getFirst(); + LambdaFunction l = (LambdaFunction) ((InstanceValue) aggregateValue.mapFn.accept(this))._values().getFirst(); + LambdaFunction o = (LambdaFunction) ((InstanceValue) aggregateValue.aggregateFn.accept(this))._values().getFirst(); return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(aggregateValue.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) ._genericType(this.context.pureModel.getGenericType("meta::pure::functions::collection::AggregateValue")) ._multiplicity(this.context.pureModel.getMultiplicity("one")) @@ -473,7 +517,7 @@ private ValueSpecification proccessColSpec(ColSpec colSpec) } else if (colSpec.function2 == null) { - InstanceValue funcVS = (InstanceValue) colSpec.function1.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)); + InstanceValue funcVS = (InstanceValue) colSpec.function1.accept(this); org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition func = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition) funcVS._values().getFirst(); FunctionType func1Type = (FunctionType) org.finos.legend.pure.m3.navigation.function.Function.computeFunctionType(func, this.context.pureModel.getExecutionSupport().getProcessorSupport()); @@ -507,10 +551,10 @@ else if (colSpec.function2 == null) } else { - InstanceValue funcVS = (InstanceValue) colSpec.function1.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)); + InstanceValue funcVS = (InstanceValue) colSpec.function1.accept(this); org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition func1 = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition) funcVS._values().getFirst(); - InstanceValue func2VS = (InstanceValue) colSpec.function2.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)); + InstanceValue func2VS = (InstanceValue) colSpec.function2.accept(this); org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition func2 = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition) func2VS._values().getFirst(); FunctionType func1Type = (FunctionType) org.finos.legend.pure.m3.navigation.function.Function.computeFunctionType(func1, this.context.pureModel.getExecutionSupport().getProcessorSupport()); @@ -567,7 +611,7 @@ public ValueSpecification processClassInstance(Path path) GenericType genericType = core_pure_corefunctions_metaExtension.Root_meta_pure_functions_meta_functionReturnType_Function_1__GenericType_1_(property, this.context.pureModel.getExecutionSupport()); MutableList result = a.result; org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.path.PropertyPathElement ppe = new Root_meta_pure_metamodel_path_PropertyPathElement_Impl("", SourceInformationHelper.toM3SourceInformation(b.sourceInformation), null); - RichIterable params = ListIterate.collect(((PropertyPathElement) b).parameters, p -> p.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext))); + RichIterable params = ListIterate.collect(((PropertyPathElement) b).parameters, p -> p.accept(this)); result.add(ppe._property(property)._parameters(params)); return new TypeAndList(genericType._rawType(), result); } @@ -678,8 +722,8 @@ public ValueSpecification processClassInstance(ExecutionContextInstance executio public ValueSpecification processClassInstance(Pair pair) { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification f = pair.first.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), processingContext)); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification s = pair.second.accept(new ValueSpecificationBuilder(this.context, Lists.mutable.empty(), processingContext)); + org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification f = pair.first.accept(this); + org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification s = pair.second.accept(this); GenericType gt = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass(M3Paths.GenericType))._rawType(this.context.pureModel.getType(M3Paths.Pair)) ._typeArguments(Lists.immutable.with(f._genericType(), s._genericType())); return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(pair.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) @@ -697,7 +741,7 @@ public ValueSpecification processClassInstance(PureList pureList) return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl(" ", SourceInformationHelper.toM3SourceInformation(pureList.sourceInformation), null) ._genericType(this.context.pureModel.getGenericType(M3Paths.List)) ._multiplicity(this.context.pureModel.getMultiplicity("one")) - ._values(ListIterate.collect(pureList.values, v -> v.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))); + ._values(ListIterate.collect(pureList.values, v -> v.accept(this))); } @Override @@ -756,7 +800,7 @@ public ValueSpecification visit(Collection collection) { MutableList transformed = ListIterate.collect(collection.values, expression -> { - ValueSpecification res = expression.accept(new ValueSpecificationBuilder(context, openVariables, processingContext)); + ValueSpecification res = expression.accept(this); if (res._multiplicity()._lowerBound()._value() != 1 || res._multiplicity()._upperBound()._value() == null || res._multiplicity()._upperBound()._value() != 1) { throw new EngineException("Collection element must have a multiplicity [1] - Context:" + processingContext.getStack() + ", multiplicity:" + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(res._multiplicity()), expression.sourceInformation, EngineErrorType.COMPILATION); @@ -788,7 +832,7 @@ public ValueSpecification visit(AppliedFunction appliedFunction) MilestoningDatePropagationHelper.isValidSource(appliedFunction, processingContext); if (appliedFunction.function.equals("letFunction")) { - MutableList vs = ListIterate.collect(appliedFunction.parameters, expression -> expression.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext))); + MutableList vs = ListIterate.collect(appliedFunction.parameters, expression -> expression.accept(this)); String letName = ((CString) appliedFunction.parameters.get(0)).value; org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification ve = new Root_meta_pure_metamodel_valuespecification_VariableExpression_Impl("", SourceInformationHelper.toM3SourceInformation(appliedFunction.sourceInformation), this.context.pureModel.getClass(M3Paths.VariableExpression))._name(letName); ve._genericType(vs.get(1)._genericType()); @@ -796,7 +840,7 @@ public ValueSpecification visit(AppliedFunction appliedFunction) processingContext.addInferredVariables(letName, ve); } - org.eclipse.collections.api.tuple.Pair> func = this.context.buildFunctionExpression(this.context.pureModel.buildNameForAppliedFunction(appliedFunction.function), appliedFunction.fControl, appliedFunction.parameters, openVariables, appliedFunction.sourceInformation, processingContext); + org.eclipse.collections.api.tuple.Pair> func = this.context.buildFunctionExpression(this.context.pureModel.buildNameForAppliedFunction(appliedFunction.function), appliedFunction.fControl, appliedFunction.parameters, appliedFunction.sourceInformation, this); processingContext.pop(); Assert.assertTrue(func != null, () -> "Can't find a match for function '" + appliedFunction.function + "(?)'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION); Assert.assertTrue(func.getOne() != null, () -> "Can't find a match for function '" + appliedFunction.function + "(" + (func.getTwo() == null ? "?" : LazyIterate.collect(func.getTwo(), v -> (v._genericType() == null ? "?" : org.finos.legend.pure.m3.navigation.generictype.GenericType.print(v._genericType(), context.pureModel.getExecutionSupport().getProcessorSupport())) + org.finos.legend.pure.m3.navigation.multiplicity.Multiplicity.print(v._multiplicity())).makeString(",")) + ")'", appliedFunction.sourceInformation, EngineErrorType.COMPILATION); @@ -852,8 +896,8 @@ public ValueSpecification processClassInstance(TdsOlapAggregation tdsOlapAggrega public ValueSpecification processClassInstance(TDSAggregateValue tdsAggregateValue) { - LambdaFunction l = (LambdaFunction) ((InstanceValue) tdsAggregateValue.mapFn.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))._values().getFirst(); - LambdaFunction o = (LambdaFunction) ((InstanceValue) tdsAggregateValue.aggregateFn.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))._values().getFirst(); + LambdaFunction l = (LambdaFunction) ((InstanceValue) tdsAggregateValue.mapFn.accept(this))._values().getFirst(); + LambdaFunction o = (LambdaFunction) ((InstanceValue) tdsAggregateValue.aggregateFn.accept(this))._values().getFirst(); return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(tdsAggregateValue.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) ._genericType(this.context.pureModel.getGenericType("meta::pure::tds::AggregateValue")) ._multiplicity(this.context.pureModel.getMultiplicity("one")) @@ -871,7 +915,7 @@ public ValueSpecification processClassInstance(TDSSortInformation tdsSortInforma public ValueSpecification processClassInstance(TDSColumnInformation tdsColumnInformation) { - LambdaFunction l = (LambdaFunction) ((InstanceValue) tdsColumnInformation.columnFn.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)))._values().getFirst(); + LambdaFunction l = (LambdaFunction) ((InstanceValue) tdsColumnInformation.columnFn.accept(this))._values().getFirst(); return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(tdsColumnInformation.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) ._genericType(this.context.pureModel.getGenericType("meta::pure::tds::BasicColumnSpecification")) ._multiplicity(this.context.pureModel.getMultiplicity("one")) @@ -918,8 +962,8 @@ public ValueSpecification visit(UnitType unitType) @Override public ValueSpecification visit(KeyExpression keyExpression) { - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification key = keyExpression.key.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)); - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification expression = keyExpression.expression.accept(new ValueSpecificationBuilder(this.context, openVariables, processingContext)); + org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification key = keyExpression.key.accept(this); + org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification expression = keyExpression.expression.accept(this); GenericType keyExpressionGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass(M3Paths.GenericType))._rawType(this.context.pureModel.getType(M3Paths.KeyExpression)); return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(keyExpression.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) ._genericType(keyExpressionGenericType) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilderForFuncExpr.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilderForFuncExpr.java deleted file mode 100644 index 6e158092d98..00000000000 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilderForFuncExpr.java +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2020 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.pure.compiler.toPureGraph; - -import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.UnitType; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.packageableElement.PackageableElementPtr; -import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; -import org.finos.legend.pure.generated.Root_meta_core_runtime_Runtime; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_type_generics_GenericType_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl; -import org.finos.legend.pure.generated.Root_meta_pure_runtime_PackageableRuntime; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue; -import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; -import org.finos.legend.pure.m3.navigation.M3Paths; - -import java.util.Objects; - -public class ValueSpecificationBuilderForFuncExpr extends ValueSpecificationBuilder implements ValueSpecificationVisitor -{ - private final CompileContext context; - private final ProcessingContext processingContext; - - public ValueSpecificationBuilderForFuncExpr(CompileContext context, MutableList openVariables, ProcessingContext processingContext) - { - super(context, openVariables, processingContext); - this.context = context; - this.processingContext = processingContext; - } - - @Override - public ValueSpecification visit(PackageableElementPtr packageableElementPtr) - { - if (packageableElementPtr.fullPath.contains("~")) - { - // for backward compatibility, since some protocol versions use PackageableElementPtr for units - return visit(new UnitType(packageableElementPtr.fullPath, packageableElementPtr.sourceInformation)); - } - - org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement packageableElement = this.context.resolvePackageableElement(packageableElementPtr.fullPath, packageableElementPtr.sourceInformation); - - if (packageableElement instanceof Root_meta_pure_runtime_PackageableRuntime) - { - Root_meta_core_runtime_Runtime resolvedRuntime = this.context.resolveRuntime(packageableElementPtr.fullPath); - GenericType runtimeGenericType = new Root_meta_pure_metamodel_type_generics_GenericType_Impl("", null, this.context.pureModel.getClass(M3Paths.GenericType)) - ._rawType(this.context.pureModel.getType("meta::core::runtime::Runtime")); - return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) - ._genericType(runtimeGenericType) - ._multiplicity(this.context.pureModel.getMultiplicity("one")) - ._values(Lists.mutable.with(resolvedRuntime)); - } - - MutableList values = this.context.getCompilerExtensions().getExtraValueSpecificationBuilderForFuncExpr().collect(x -> x.value(packageableElement, this.context, this.processingContext), Lists.mutable.empty()); - values.removeIf(Objects::isNull); - switch (values.size()) - { - case 0: - { - return new Root_meta_pure_metamodel_valuespecification_InstanceValue_Impl("", SourceInformationHelper.toM3SourceInformation(packageableElementPtr.sourceInformation), this.context.pureModel.getClass(M3Paths.InstanceValue)) - ._genericType(packageableElement._classifierGenericType()) - ._multiplicity(this.context.pureModel.getMultiplicity("one")) - ._values(Lists.mutable.with(packageableElement)); - } - case 1: - { - return values.get(0); - } - default: - { - throw new EngineException("More than one handler found for the Packageable Element '" + packageableElementPtr.fullPath + "'", packageableElementPtr.sourceInformation, EngineErrorType.COMPILATION); - } - } - } -} diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java index dc346d9d6ce..80b4489da0b 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java @@ -34,6 +34,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.ClassInstance; @@ -1913,10 +1914,11 @@ private void registerCalendarFunctions() register("meta::pure::functions::date::calendar::ytd_Date_1__String_1__Date_1__Number_$0_1$__Number_$0_1$_", false, ps -> res("Number", "zeroOne")); } - public Pair> buildFunctionExpression(String functionName, List parameters, MutableList openVariables, SourceInformation sourceInformation, CompileContext compileContext, ProcessingContext processingContext) + public Pair> buildFunctionExpression(String functionName, List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) { - FunctionExpressionBuilder builder = compileContext.resolveFunctionBuilder(functionName, this.registeredMetaPackages, this.map, sourceInformation, processingContext); - return builder.buildFunctionExpression(parameters, openVariables, sourceInformation, compileContext, processingContext); + ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; + FunctionExpressionBuilder builder = valueSpecificationBuilder.getContext().resolveFunctionBuilder(functionName, this.registeredMetaPackages, this.map, sourceInformation, valueSpecificationBuilder.getProcessingContext()); + return builder.buildFunctionExpression(parameters, sourceInformation, valueSpecificationBuilder); } private void registerMetaPackage(FunctionHandler... handlers) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java index 060ec99bbd6..7b86cfff992 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java @@ -19,11 +19,11 @@ import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.tuple.Tuples; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.MilestoningDatePropagationHelper; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.operational.Assert; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; @@ -74,19 +74,20 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, MutableList openVariables, SourceInformation sourceInformation, CompileContext compileContext, ProcessingContext processingContext) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) { List resolvedParams = null; + ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; for (FunctionExpressionBuilder b : builders) { - Pair> res = b.buildFunctionExpression(parameters, openVariables, sourceInformation, compileContext, processingContext); + Pair> res = b.buildFunctionExpression(parameters, sourceInformation, valueSpecificationBuilder); if (res.getOne() != null) { return res; } else { - MilestoningDatePropagationHelper.updateMilestoningPropagationContextWhileReprocessingFunctionExpression(processingContext); + MilestoningDatePropagationHelper.updateMilestoningPropagationContextWhileReprocessingFunctionExpression(valueSpecificationBuilder.getProcessingContext()); } if (res.getTwo() != null) { diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java index 56b89b150b9..0d79d58b27f 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java @@ -18,11 +18,11 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.list.mutable.FastList; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.datatype.CString; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.ClassInstance; @@ -41,7 +41,7 @@ public abstract class FunctionExpressionBuilder { - public abstract Pair> buildFunctionExpression(List parameters, MutableList openVariables, SourceInformation sourceInformation, CompileContext compileContext, ProcessingContext processingContext); + public abstract Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor); public abstract String getFunctionName(); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java index 65a0a51c6b7..d6669b04a11 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java @@ -19,13 +19,12 @@ import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.list.mutable.FastList; import org.eclipse.collections.impl.tuple.Tuples; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilderForFuncExpr; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.operational.Assert; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; @@ -71,11 +70,12 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, MutableList openVariables, SourceInformation sourceInformation, CompileContext compileContext, ProcessingContext processingContext) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) { - if (test(handlers.get(0).getFunc(), parameters, compileContext.pureModel, processingContext)) + ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; + if (test(handlers.get(0).getFunc(), parameters, valueSpecificationBuilder.getContext().pureModel, valueSpecificationBuilder.getProcessingContext())) { - List processed = parameters.stream().map(p -> p.accept(new ValueSpecificationBuilderForFuncExpr(compileContext, openVariables, processingContext))).collect(Collectors.toList()); + List processed = parameters.stream().map(p -> p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); return Tuples.pair(buildFunctionExpressionGraph(processed, sourceInformation), processed); } return Tuples.pair(null, null); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java index 06d0489b782..d31d6286e1e 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java @@ -17,12 +17,12 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; import org.eclipse.collections.impl.tuple.Tuples; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference.ParametersInference; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; +import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; @@ -64,11 +64,12 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, MutableList openVariables, SourceInformation sourceInformation, CompileContext compileContext, ProcessingContext processingContext) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) { - if (test(handlers.handlers.get(0).getFunc(), parameters, compileContext.pureModel, processingContext)) + ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; + if (test(handlers.handlers.get(0).getFunc(), parameters, valueSpecificationBuilder.getContext().pureModel, valueSpecificationBuilder.getProcessingContext())) { - List newParameters = parametersInference.update(parameters, openVariables, compileContext, processingContext); + List newParameters = parametersInference.update(parameters, valueSpecificationBuilder.getOpenVariables(), valueSpecificationBuilder.getContext(), valueSpecificationBuilder.getProcessingContext()); return Tuples.pair(this.handlers.buildFunctionExpressionGraph(newParameters, sourceInformation), newParameters); } else From 7d26e42b47b1b9836984b52c972b265060a819de Mon Sep 17 00:00:00 2001 From: "Kim, Jake" Date: Fri, 10 Jan 2025 08:41:44 -0500 Subject: [PATCH 2/3] Remove creating new ValueSpecificationBuilder instance in Handlers.java --- .../compiler/toPureGraph/CompileContext.java | 4 +- .../ValueSpecificationBuilder.java | 2 +- .../toPureGraph/handlers/Handlers.java | 203 +++++++++--------- .../CompositeFunctionExpressionBuilder.java | 4 +- .../builder/FunctionExpressionBuilder.java | 4 +- ...MultiHandlerFunctionExpressionBuilder.java | 4 +- ...larSignatureFunctionExpressionBuilder.java | 6 +- .../inference/ParametersInference.java | 6 +- 8 files changed, 116 insertions(+), 117 deletions(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java index 0b26074f6de..8ecdd45ac75 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/CompileContext.java @@ -36,7 +36,6 @@ import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section; import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; import org.finos.legend.engine.protocol.pure.v1.model.type.relationType.RelationType; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.deployment.DeploymentMode; import org.finos.legend.engine.shared.core.identity.Identity; import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException; @@ -457,10 +456,9 @@ public org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.extension.Tag r // ------------------------------------------ FUNCTION EXPRESSION BUILDER ----------------------------------------- - public Pair> buildFunctionExpression(String functionName, String fControl, List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) + public Pair> buildFunctionExpression(String functionName, String fControl, List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder) { Pair> functionExpression; - ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; functionExpression = this.pureModel.handlers.buildFunctionExpression(functionName, parameters, sourceInformation, valueSpecificationBuilder); if (fControl != null) { diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java index 1aaf20277fb..8d68563f68e 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/ValueSpecificationBuilder.java @@ -131,7 +131,7 @@ import java.util.Objects; import java.util.Optional; -public final class ValueSpecificationBuilder implements ValueSpecificationVisitor +public class ValueSpecificationBuilder implements ValueSpecificationVisitor { private final CompileContext context; private final MutableList openVariables; diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java index 80b4489da0b..32182170e90 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/Handlers.java @@ -34,7 +34,6 @@ import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType; import org.finos.legend.engine.protocol.pure.v1.model.type.PackageableType; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.application.AppliedFunction; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.ClassInstance; @@ -165,7 +164,7 @@ private static void updateTDSRowLambda(List vars) variable2.multiplicity = new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1); } - public static void aggInference(Object obj, GenericType gt, int mapOffset, int aggOffset, CompileContext cc, MutableList ov, ProcessingContext pc) + public static void aggInference(Object obj, GenericType gt, int mapOffset, int aggOffset, ValueSpecificationBuilder valueSpecificationBuilder) { Lambda aggFirstLambda = null; Lambda aggSecondLambda = null; @@ -187,27 +186,29 @@ else if (obj instanceof TDSAggregateValue) } if (aggFirstLambda != null && aggSecondLambda != null) { + CompileContext cc = valueSpecificationBuilder.getContext(); updateSimpleLambda(aggFirstLambda, gt, org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity.PURE_ONE, cc); - ValueSpecification processLambda = aggFirstLambda.accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification processLambda = aggFirstLambda.accept(valueSpecificationBuilder); updateSimpleLambda(aggSecondLambda, funcReturnType(processLambda, cc.pureModel), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(), cc); } } - private static void aggInferenceAll(List parameters, GenericType gt, int mapOffset, int aggOffset, MutableList ov, CompileContext cc, ProcessingContext pc) + private static void aggInferenceAll(List parameters, GenericType gt, int mapOffset, int aggOffset, ValueSpecificationBuilder valueSpecificationBuilder) { if (parameters.get(2) instanceof Collection) { - ((Collection) parameters.get(2)).values.forEach(a -> aggInference(a, gt, mapOffset, aggOffset, cc, ov, pc)); + ((Collection) parameters.get(2)).values.forEach(a -> aggInference(a, gt, mapOffset, aggOffset, valueSpecificationBuilder)); } else { - aggInference(parameters.get(2), gt, mapOffset, aggOffset, cc, ov, pc); + aggInference(parameters.get(2), gt, mapOffset, aggOffset, valueSpecificationBuilder); } } - public static final ParametersInference ExtendInference = (parameters, ov, cc, pc) -> + public static final ParametersInference ExtendInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + CompileContext cc = valueSpecificationBuilder.getContext(); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); GenericType gt = firstProcessedParameter._genericType(); MutableList processedParameters; if (parameters.size() == 3) @@ -221,7 +222,7 @@ private static void aggInferenceAll(List updateLambdaWithCol(cc.pureModel.getGenericType("meta::pure::tds::TDSRow"), l, cc)); List results = Lists.mutable.with(firstProcessedParameter); - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(results::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(results::add); return results; } }; @@ -392,43 +393,44 @@ public static TypeAndMultiplicity OverReturnInference(List p } - public static final ParametersInference LambdaCollectionInference = (parameters, ov, cc, pc) -> + public static final ParametersInference LambdaCollectionInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); - updateLambdaCollection(parameters, firstProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, cc); - return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); + updateLambdaCollection(parameters, firstProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, valueSpecificationBuilder.getContext()); + return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; - public static final ParametersInference TDSContainsInference = (parameters, ov, cc, pc) -> + public static final ParametersInference TDSContainsInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); - updateLambdaCollection(parameters, firstProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, cc); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); + updateLambdaCollection(parameters, firstProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, valueSpecificationBuilder.getContext()); updateTDSRowLambda(((Lambda) parameters.get(4)).parameters); - return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; - public static final ParametersInference EvalInference = (parameters, ov, cc, pc) -> + public static final ParametersInference EvalInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification secondProcessedParameter = parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc)); - updateLambdaCollection(parameters, secondProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 0, cc); - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); - return Stream.concat(Stream.of(firstProcessedParameter, secondProcessedParameter), parameters.stream().skip(2).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + ValueSpecification secondProcessedParameter = parameters.get(1).accept(valueSpecificationBuilder); + updateLambdaCollection(parameters, secondProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 0, valueSpecificationBuilder.getContext()); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); + return Stream.concat(Stream.of(firstProcessedParameter, secondProcessedParameter), parameters.stream().skip(2).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; - public static final ParametersInference EvalInference2 = (parameters, ov, cc, pc) -> + public static final ParametersInference EvalInference2 = (parameters, valueSpecificationBuilder) -> { - ValueSpecification secondProcessedParameter = parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc)); - ValueSpecification thirdProcessedParameter = parameters.get(2).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification secondProcessedParameter = parameters.get(1).accept(valueSpecificationBuilder); + ValueSpecification thirdProcessedParameter = parameters.get(2).accept(valueSpecificationBuilder); updateTwoParamsLambdaDiffTypes(parameters.get(0), secondProcessedParameter._genericType(), thirdProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1)); - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); - return Stream.concat(Stream.of(firstProcessedParameter, secondProcessedParameter, thirdProcessedParameter), parameters.stream().skip(3).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); + return Stream.concat(Stream.of(firstProcessedParameter, secondProcessedParameter, thirdProcessedParameter), parameters.stream().skip(3).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; - public static final ParametersInference RenameColInference = (parameters, ov, cc, pc) -> + public static final ParametersInference RenameColInference = (parameters, valueSpecificationBuilder) -> { + CompileContext cc = valueSpecificationBuilder.getContext(); ProcessorSupport ps = cc.pureModel.getExecutionSupport().getProcessorSupport(); - ValueSpecification vs = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification vs = parameters.get(0).accept(valueSpecificationBuilder); RelationType type = (RelationType) vs._genericType()._typeArguments().getFirst()._rawType(); ColSpec firstCol = (ColSpec) ((ClassInstance) parameters.get(1)).value; @@ -443,9 +445,9 @@ public static TypeAndMultiplicity OverReturnInference(List p ); }; - public static final ParametersInference SelectColInference = (parameters, ov, cc, pc) -> + public static final ParametersInference SelectColInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification vs = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification vs = parameters.get(0).accept(valueSpecificationBuilder); RelationType type = (RelationType) vs._genericType()._typeArguments().getFirst()._rawType(); Object obj = ((ClassInstance) parameters.get(1)).value; @@ -453,13 +455,13 @@ public static TypeAndMultiplicity OverReturnInference(List p specs.forEach(c -> { - Column found = findColumn(type, c, cc.pureModel.getExecutionSupport().getProcessorSupport()); + Column found = findColumn(type, c, valueSpecificationBuilder.getContext().pureModel.getExecutionSupport().getProcessorSupport()); c.type = _Column.getColumnType(found)._rawType()._name(); }); return Lists.mutable.with( vs, - parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc)) + parameters.get(1).accept(valueSpecificationBuilder) ); }; @@ -501,9 +503,10 @@ public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation return buildColSpec(col._name(), _Column.getColumnType(col), _Column.getColumnMultiplicity(col), pureModel, ps); } - public static final ParametersInference LambdaColCollectionInference = (parameters, ov, cc, pc) -> + public static final ParametersInference LambdaColCollectionInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + CompileContext cc = valueSpecificationBuilder.getContext(); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); GenericType gt = firstProcessedParameter._genericType(); if (parameters.get(1) instanceof ClassInstance) { @@ -514,19 +517,20 @@ public static org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relation final GenericType gt2 = gt._rawType()._name().equals("TabularDataSet") || gt._rawType()._name().equals("TableTDS") ? cc.pureModel.getGenericType("meta::pure::tds::TDSRow") : gt; toCollection(parameters.get(1)).values.forEach(l -> updateLambdaWithCol(gt2, l, cc)); } - return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; - public static final ParametersInference SortColumnInference = (parameters, ov, cc, pc) -> + public static final ParametersInference SortColumnInference = (parameters, valueSpecificationBuilder) -> { + CompileContext cc = valueSpecificationBuilder.getContext(); ProcessorSupport processorSupport = cc.pureModel.getExecutionSupport().getProcessorSupport(); - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); GenericType gt = firstProcessedParameter._genericType(); if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS", "RelationStoreAccessor").contains(gt._rawType().getName())) { processSort(parameters.get(1), gt, cc, processorSupport); } - return Lists.mutable.with(firstProcessedParameter, parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc))); + return Lists.mutable.with(firstProcessedParameter, parameters.get(1).accept(valueSpecificationBuilder)); }; private static void processSort(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification parameter, GenericType gt, CompileContext cc, ProcessorSupport processorSupport) @@ -563,23 +567,23 @@ private static void processAscendingDescending(AppliedFunction af, RelationType< return foundColumn; } - public static final ParametersInference LambdaInference = (parameters, ov, cc, pc) -> + public static final ParametersInference LambdaInference = (parameters, valueSpecificationBuilder) -> { - List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); - updateSimpleLambda(parameters.get(1), firstPassProcessed.get(0)._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), cc); - return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(new ValueSpecificationBuilder(cc, ov, pc))); + List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); + updateSimpleLambda(parameters.get(1), firstPassProcessed.get(0)._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), valueSpecificationBuilder.getContext()); + return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(valueSpecificationBuilder)); }; - public static final ParametersInference TwoParameterLambdaInference = (parameters, ov, cc, pc) -> + public static final ParametersInference TwoParameterLambdaInference = (parameters, valueSpecificationBuilder) -> { - List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); updateTwoParamsLambda(parameters.get(1), firstPassProcessed.get(0)._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1)); - return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(new ValueSpecificationBuilder(cc, ov, pc))); + return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(valueSpecificationBuilder)); }; - public static final ParametersInference TwoParameterLambdaInferenceDiffTypes = (parameters, ov, cc, pc) -> + public static final ParametersInference TwoParameterLambdaInferenceDiffTypes = (parameters, valueSpecificationBuilder) -> { - List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + List firstPassProcessed = parameters.stream().map(p -> p instanceof Lambda ? null : p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); Multiplicity mul = firstPassProcessed.get(2)._multiplicity(); org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity m2 = new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(); @@ -590,83 +594,85 @@ private static void processAscendingDescending(AppliedFunction af, RelationType< } updateTwoParamsLambdaDiffTypes(parameters.get(1), firstPassProcessed.get(0)._genericType(), firstPassProcessed.get(2)._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), m2); - return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(new ValueSpecificationBuilder(cc, ov, pc))); + return ListIterate.zip(firstPassProcessed, parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(valueSpecificationBuilder)); }; - public static final ParametersInference TDSFilterInference = (parameters, ov, cc, pc) -> + public static final ParametersInference TDSFilterInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + CompileContext cc = valueSpecificationBuilder.getContext(); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); List result = Lists.mutable.with(firstProcessedParameter); GenericType gt = firstProcessedParameter._genericType(); if ("TabularDataSet".equals(gt._rawType()._name())) { updateSimpleLambda(parameters.get(1), cc.pureModel.getGenericType("meta::pure::tds::TDSRow"), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), cc); - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } else if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS", "RelationStoreAccessor").contains(gt._rawType().getName())) { updateSimpleLambda(parameters.get(1), gt._typeArguments().getFirst(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), cc); - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } else { - List firstPassProcessed = parameters.stream().skip(1).map(p -> p instanceof Lambda ? null : p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + List firstPassProcessed = parameters.stream().skip(1).map(p -> p instanceof Lambda ? null : p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); updateSimpleLambda(parameters.get(1), parameters.size() != 0 && parameters.get(0) instanceof Lambda ? firstPassProcessed.get(0)._genericType() : firstProcessedParameter._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), cc); - return LazyIterate.zip(LazyIterate.concatenate(Lists.fixedSize.of(firstProcessedParameter), firstPassProcessed), parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(new ValueSpecificationBuilder(cc, ov, pc))).toList(); + return LazyIterate.zip(LazyIterate.concatenate(Lists.fixedSize.of(firstProcessedParameter), firstPassProcessed), parameters).collect(p -> p.getOne() != null ? p.getOne() : p.getTwo().accept(valueSpecificationBuilder)).toList(); } return result; }; - public static final ParametersInference AsOfJoinInference = (parameters, ov, cc, pc) -> + public static final ParametersInference AsOfJoinInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); - ValueSpecification secondProcessedParameter = parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); + ValueSpecification secondProcessedParameter = parameters.get(1).accept(valueSpecificationBuilder); org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity one = new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1); updateTwoParamsLambdaDiffTypes(parameters.get(2), firstProcessedParameter._genericType()._typeArguments().getFirst(), secondProcessedParameter._genericType()._typeArguments().getFirst(), one, one); if (parameters.size() == 4) { updateTwoParamsLambdaDiffTypes(parameters.get(3), firstProcessedParameter._genericType()._typeArguments().getFirst(), secondProcessedParameter._genericType()._typeArguments().getFirst(), one, one); } - MutableList base = Lists.mutable.with(firstProcessedParameter).with(secondProcessedParameter).with(parameters.get(2).accept(new ValueSpecificationBuilder(cc, ov, pc))); - return parameters.size() == 4 ? base.with(parameters.get(3).accept(new ValueSpecificationBuilder(cc, ov, pc))) : base; + MutableList base = Lists.mutable.with(firstProcessedParameter).with(secondProcessedParameter).with(parameters.get(2).accept(valueSpecificationBuilder)); + return parameters.size() == 4 ? base.with(parameters.get(3).accept(valueSpecificationBuilder)) : base; }; - public static final ParametersInference JoinInference = (parameters, ov, cc, pc) -> + public static final ParametersInference JoinInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); MutableList result = Lists.mutable.with(firstProcessedParameter); GenericType gt = firstProcessedParameter._genericType(); if ("TabularDataSet".equals(gt._rawType()._name())) { updateTDSRowLambda(((Lambda) parameters.get(3)).parameters); - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } else if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS", "RelationStoreAccessor").contains(gt._rawType().getName())) { - ValueSpecification secondProcessedParameter = parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification secondProcessedParameter = parameters.get(1).accept(valueSpecificationBuilder); org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity one = new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1); updateTwoParamsLambdaDiffTypes(parameters.get(3), firstProcessedParameter._genericType()._typeArguments().getFirst(), secondProcessedParameter._genericType()._typeArguments().getFirst(), one, one); - result.with(secondProcessedParameter).with(parameters.get(2).accept(new ValueSpecificationBuilder(cc, ov, pc))).with(parameters.get(3).accept(new ValueSpecificationBuilder(cc, ov, pc))); + result.with(secondProcessedParameter).with(parameters.get(2).accept(valueSpecificationBuilder)).with(parameters.get(3).accept(valueSpecificationBuilder)); } else { - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } return result; }; - public static final ParametersInference TDSAggInference = (parameters, ov, cc, pc) -> + public static final ParametersInference TDSAggInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + CompileContext cc = valueSpecificationBuilder.getContext(); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); MutableList result = Lists.mutable.with(firstProcessedParameter); GenericType gt = firstProcessedParameter._genericType(); if ("TabularDataSet".equals(gt._rawType()._name())) { - aggInferenceAll(parameters, cc.pureModel.getGenericType("meta::pure::tds::TDSRow"), 1, 2, ov, cc, pc); - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + aggInferenceAll(parameters, cc.pureModel.getGenericType("meta::pure::tds::TDSRow"), 1, 2, valueSpecificationBuilder); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } else if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS", "RelationStoreAccessor").contains(gt._rawType().getName())) { @@ -675,36 +681,36 @@ else if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS" Object aggCol = ((ClassInstance) parameters.get(2)).value; if (aggCol instanceof ColSpecArray) { - ((ColSpecArray) aggCol).colSpecs.forEach(c -> processSingleAggColSpec(c, firstProcessedParameter, ov, cc, pc)); + ((ColSpecArray) aggCol).colSpecs.forEach(c -> processSingleAggColSpec(c, firstProcessedParameter, valueSpecificationBuilder)); } else if (aggCol instanceof ColSpec) { - processSingleAggColSpec((ColSpec) aggCol, firstProcessedParameter, ov, cc, pc); + processSingleAggColSpec((ColSpec) aggCol, firstProcessedParameter, valueSpecificationBuilder); } else { throw new RuntimeException("Not supported " + aggCol.getClass()); } - result.with(parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc))).with(parameters.get(2).accept(new ValueSpecificationBuilder(cc, ov, pc))); + result.with(parameters.get(1).accept(valueSpecificationBuilder)).with(parameters.get(2).accept(valueSpecificationBuilder)); } else { - parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).forEach(result::add); + parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder)).forEach(result::add); } return result; }; - public static final ParametersInference DistinctInference = (parameters, ov, cc, pc) -> + public static final ParametersInference DistinctInference = (parameters, valueSpecificationBuilder) -> { - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); MutableList result = Lists.mutable.with(firstProcessedParameter); GenericType gt = firstProcessedParameter._genericType(); if (Sets.immutable.with("Nil", "Relation", "RelationElementAccessor", "TDS", "RelationStoreAccessor").contains(gt._rawType().getName())) { - processColumn(parameters.get(1), gt, cc); - result.with(parameters.get(1).accept(new ValueSpecificationBuilder(cc, ov, pc))); + processColumn(parameters.get(1), gt, valueSpecificationBuilder.getContext()); + result.with(parameters.get(1).accept(valueSpecificationBuilder)); } else { @@ -754,15 +760,17 @@ private static void processColumn(Object parameter, GenericType gt, CompileConte } } - private static void processSingleAggColSpec(ColSpec colSpec, ValueSpecification firstProcessedParameter, MutableList ov, CompileContext cc, ProcessingContext pc) + private static void processSingleAggColSpec(ColSpec colSpec, ValueSpecification firstProcessedParameter, ValueSpecificationBuilder valueSpecificationBuilder) { + CompileContext cc = valueSpecificationBuilder.getContext(); updateSimpleLambda(colSpec.function1, firstProcessedParameter._genericType()._typeArguments().getFirst(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), cc); - FunctionDefinition lambda = (FunctionDefinition) ((InstanceValue) colSpec.function1.accept(new ValueSpecificationBuilder(cc, ov, pc)))._values().getFirst(); + FunctionDefinition lambda = (FunctionDefinition) ((InstanceValue) colSpec.function1.accept(valueSpecificationBuilder))._values().getFirst(); updateSimpleLambda(colSpec.function2, lambda._expressionSequence().getLast()._genericType(), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(0, null), cc); } - public static final ParametersInference TDSOLAPInference = (parameters, ov, cc, pc) -> + public static final ParametersInference TDSOLAPInference = (parameters, valueSpecificationBuilder) -> { + CompileContext cc = valueSpecificationBuilder.getContext(); parameters.forEach(parameter -> { Object param = parameter instanceof ClassInstance ? ((ClassInstance) parameter).value : parameter; @@ -780,29 +788,31 @@ else if (param instanceof TdsOlapAggregation) } }); - return parameters.stream().map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + return parameters.stream().map(p -> p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); }; - public static final ParametersInference OLAPFuncTDSInference = (parameters, ov, cc, pc) -> + public static final ParametersInference OLAPFuncTDSInference = (parameters, valueSpecificationBuilder) -> { + CompileContext cc = valueSpecificationBuilder.getContext(); updateSimpleLambda(parameters.get(0), cc.pureModel.getGenericType("meta::pure::tds::TDSRow"), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(), cc); - return parameters.stream().map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + return parameters.stream().map(p -> p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); }; - public static final ParametersInference OLAPFuncNumInference = (parameters, ov, cc, pc) -> + public static final ParametersInference OLAPFuncNumInference = (parameters, valueSpecificationBuilder) -> { + CompileContext cc = valueSpecificationBuilder.getContext(); updateSimpleLambda(parameters.get(1), cc.pureModel.getGenericType("Number"), new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(), cc); - return parameters.stream().map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc))).collect(Collectors.toList()); + return parameters.stream().map(p -> p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); }; - public static final ParametersInference LambdaAndAggInference = (parameters, ov, cc, pc) -> + public static final ParametersInference LambdaAndAggInference = (parameters, valueSpecificationBuilder) -> { // Main Lambda - ValueSpecification firstProcessedParameter = parameters.get(0).accept(new ValueSpecificationBuilder(cc, ov, pc)); + ValueSpecification firstProcessedParameter = parameters.get(0).accept(valueSpecificationBuilder); GenericType gt = firstProcessedParameter._genericType(); - updateLambdaCollection(parameters, gt, new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, cc); - aggInferenceAll(parameters, gt, 0, 1, ov, cc, pc); - return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(new ValueSpecificationBuilder(cc, ov, pc)))).collect(Collectors.toList()); + updateLambdaCollection(parameters, gt, new org.finos.legend.engine.protocol.pure.v1.model.domain.Multiplicity(1, 1), 1, valueSpecificationBuilder.getContext()); + aggInferenceAll(parameters, gt, 0, 1, valueSpecificationBuilder); + return Stream.concat(Stream.of(firstProcessedParameter), parameters.stream().skip(1).map(p -> p.accept(valueSpecificationBuilder))).collect(Collectors.toList()); }; private final Map map = UnifiedMap.newMap(); @@ -1914,9 +1924,8 @@ private void registerCalendarFunctions() register("meta::pure::functions::date::calendar::ytd_Date_1__String_1__Date_1__Number_$0_1$__Number_$0_1$_", false, ps -> res("Number", "zeroOne")); } - public Pair> buildFunctionExpression(String functionName, List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) + public Pair> buildFunctionExpression(String functionName, List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder) { - ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; FunctionExpressionBuilder builder = valueSpecificationBuilder.getContext().resolveFunctionBuilder(functionName, this.registeredMetaPackages, this.map, sourceInformation, valueSpecificationBuilder.getProcessingContext()); return builder.buildFunctionExpression(parameters, sourceInformation, valueSpecificationBuilder); } diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java index 7b86cfff992..125f48921d4 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/CompositeFunctionExpressionBuilder.java @@ -23,7 +23,6 @@ import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.operational.Assert; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; @@ -74,10 +73,9 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder) { List resolvedParams = null; - ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; for (FunctionExpressionBuilder b : builders) { Pair> res = b.buildFunctionExpression(parameters, sourceInformation, valueSpecificationBuilder); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java index 0d79d58b27f..990be90f222 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/FunctionExpressionBuilder.java @@ -20,9 +20,9 @@ import org.eclipse.collections.impl.list.mutable.FastList; import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.Variable; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.datatype.CString; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.ClassInstance; @@ -41,7 +41,7 @@ public abstract class FunctionExpressionBuilder { - public abstract Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor); + public abstract Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder); public abstract String getFunctionName(); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java index d6669b04a11..fabc3af97bc 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/MultiHandlerFunctionExpressionBuilder.java @@ -24,7 +24,6 @@ import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.engine.shared.core.operational.Assert; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; @@ -70,9 +69,8 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder) { - ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; if (test(handlers.get(0).getFunc(), parameters, valueSpecificationBuilder.getContext().pureModel, valueSpecificationBuilder.getProcessingContext())) { List processed = parameters.stream().map(p -> p.accept(valueSpecificationBuilder)).collect(Collectors.toList()); diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java index d31d6286e1e..cfd8497998c 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/builder/RequiredInferenceSimilarSignatureFunctionExpressionBuilder.java @@ -22,7 +22,6 @@ import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.FunctionHandler; import org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference.ParametersInference; import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; -import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecificationVisitor; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; @@ -64,12 +63,11 @@ public Optional getParametersSize() } @Override - public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationVisitor valueSpecificationVisitor) + public Pair> buildFunctionExpression(List parameters, SourceInformation sourceInformation, ValueSpecificationBuilder valueSpecificationBuilder) { - ValueSpecificationBuilder valueSpecificationBuilder = (ValueSpecificationBuilder) valueSpecificationVisitor; if (test(handlers.handlers.get(0).getFunc(), parameters, valueSpecificationBuilder.getContext().pureModel, valueSpecificationBuilder.getProcessingContext())) { - List newParameters = parametersInference.update(parameters, valueSpecificationBuilder.getOpenVariables(), valueSpecificationBuilder.getContext(), valueSpecificationBuilder.getProcessingContext()); + List newParameters = parametersInference.update(parameters, valueSpecificationBuilder); return Tuples.pair(this.handlers.buildFunctionExpressionGraph(newParameters, sourceInformation), newParameters); } else diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/inference/ParametersInference.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/inference/ParametersInference.java index c1adac9a403..c9838cd6430 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/inference/ParametersInference.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/handlers/inference/ParametersInference.java @@ -14,14 +14,12 @@ package org.finos.legend.engine.language.pure.compiler.toPureGraph.handlers.inference; -import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext; -import org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification; import java.util.List; public interface ParametersInference { - List update(List parameters, MutableList openVariables, CompileContext compileContext, ProcessingContext processingContext); + List update(List parameters, ValueSpecificationBuilder valueSpecificationBuilder); } From be90b94ce196074c8af955bca12ce486068da8dc Mon Sep 17 00:00:00 2001 From: "Kim, Jake" Date: Fri, 10 Jan 2025 09:23:29 -0500 Subject: [PATCH 3/3] Allow ability to pass in a special ValueSpecificationBuilder --- .../toPureGraph/HelperValueSpecificationBuilder.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java index dc3dcb83ce8..277c8eaca84 100644 --- a/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java +++ b/legend-engine-core/legend-engine-core-base/legend-engine-core-language-pure/legend-engine-language-pure-compiler/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperValueSpecificationBuilder.java @@ -15,6 +15,7 @@ package org.finos.legend.engine.language.pure.compiler.toPureGraph; import org.eclipse.collections.api.RichIterable; +import org.eclipse.collections.api.block.function.Function3; import org.eclipse.collections.api.list.ListIterable; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.tuple.Pair; @@ -96,10 +97,15 @@ public static LambdaFunction buildLambdaWithContext(List buildLambdaWithContext(String lambdaId, List expressions, List parameters, CompileContext context, ProcessingContext ctx) + { + return buildLambdaWithContext(lambdaId, expressions, parameters, context, ctx, ValueSpecificationBuilder::new); + } + + public static LambdaFunction buildLambdaWithContext(String lambdaId, List expressions, List parameters, CompileContext context, ProcessingContext ctx, Function3, ProcessingContext, ValueSpecificationBuilder> valueSpecificationBuilderFactory) { ctx.push("new lambda"); ctx.addVariableLevel(); - MutableList pureParameters = ListIterate.collect(parameters, p -> (VariableExpression) p.accept(new ValueSpecificationBuilder(context, Lists.mutable.empty(), ctx))); + MutableList pureParameters = ListIterate.collect(parameters, p -> (VariableExpression) p.accept(valueSpecificationBuilderFactory.value(context, Lists.mutable.empty(), ctx))); if (parameters.size() != 0 && !parameters.get(0).name.equals("v_automap")) { if (ctx.milestoningDatePropagationContext.size() == 0) @@ -112,7 +118,7 @@ public static LambdaFunction buildLambdaWithContext(String lambdaId, List openVariables = Lists.mutable.empty(); - MutableList valueSpecifications = ListIterate.collect(expressions, p -> p.accept(new ValueSpecificationBuilder(context, openVariables, ctx))); + MutableList valueSpecifications = ListIterate.collect(expressions, p -> p.accept(valueSpecificationBuilderFactory.value(context, openVariables, ctx))); // Remove Lambda parameters from openVariables MutableList cleanedOpenVariables = openVariables.distinct();