Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uplift and fix canReactivateDynamically native function #646

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,25 @@ public void testEval()
this.execute("test():Boolean[1]");
}

@Test
public void testNonReactivatableFunction()
{
compileTestSource("fromString.pure",
"function test():Boolean[1]\n" +
"{\n" +
" assert(false == canReactivateDynamically_ValueSpecification_1__Boolean_1_->eval({s:String[1]|$s}->evaluateAndDeactivate().expressionSequence->toOne()), |'');\n" +
"}\n");
this.execute("test():Boolean[1]");
}

@Test
public void testSimpleFuncExpressionReactivationInScopeOfParams()
{
compileTestSource("fromString.pure",
"function test():Boolean[1]\n" +
"{\n" +
" assert(true == canReactivateDynamically_ValueSpecification_1__Map_1__Boolean_1_->eval({s:String[1]|$s}->evaluateAndDeactivate().expressionSequence->toOne(), newMap(^Pair<String, List<Any>>(first = 's', second = ^List<Any>(values = 'dummy')))), |'');\n" +
"}\n");
this.execute("test():Boolean[1]");
}
hardikmaheshwari marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ native function meta::pure::functions::meta::deactivate(var:Any[*]):ValueSpecifi

native function meta::pure::functions::meta::reactivate(vs:ValueSpecification[1], vars:Map<String, List<Any>>[1]):Any[*];

native function meta::pure::functions::meta::canReactivateDynamically(vs:ValueSpecification[1]):Boolean[1];
function meta::pure::functions::meta::canReactivateDynamically(vs:ValueSpecification[1]):Boolean[1]
{
canReactivateDynamically($vs, ^Map<String, List<Any>>())
}

native function meta::pure::functions::meta::canReactivateDynamically(vs:ValueSpecification[1], vars:Map<String, List<Any>>[1]):Boolean[1];

native function meta::pure::functions::meta::evaluateAndDeactivate<T|m>(var:T[m]):T[m];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification;
import org.finos.legend.pure.m3.execution.ExecutionSupport;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.natives.AbstractNativeFunctionGeneric;
import org.finos.legend.pure.runtime.java.compiled.generation.processors.support.map.PureMap;

public class CanReactivateDynamically extends AbstractNativeFunctionGeneric
{
public CanReactivateDynamically()
{
super("CoreGen.canReactivateWithoutJavaCompilation",new Class[]{ValueSpecification.class, ExecutionSupport.class},
false, true, false, "canReactivateDynamically_ValueSpecification_1__Boolean_1_");
super("CoreGen.canReactivateWithoutJavaCompilation",new Class[]{ValueSpecification.class, PureMap.class, ExecutionSupport.class},
false, true, false, "canReactivateDynamically_ValueSpecification_1__Map_1__Boolean_1_");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public CoreExtensionCompiled()
" return Pure.canReactivateWithoutJavaCompilation(valueSpecification, es, new PureMap(UnifiedMap.newMap()), bridge);\n" +
" }\n" +
"\n" +
" public static boolean canReactivateWithoutJavaCompilation(ValueSpecification valueSpecification, ExecutionSupport es, PureMap lambdaOpenVariablesMap)\n" +
" public static boolean canReactivateWithoutJavaCompilation(ValueSpecification valueSpecification, PureMap lambdaOpenVariablesMap, ExecutionSupport es)\n" +
" {\n" +
" return Pure.canReactivateWithoutJavaCompilation(valueSpecification, es, lambdaOpenVariablesMap, bridge);\n" +
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void init(PureRuntime runtime, Message message)
this.nativeFunctions.put("subTypeOf_Type_1__Type_1__Boolean_1_", new SubTypeOf(repository));
this.nativeFunctions.put("deactivate_Any_MANY__ValueSpecification_1_", new Deactivate());
this.nativeFunctions.put("reactivate_ValueSpecification_1__Map_1__Any_MANY_", new Reactivate(this));
this.nativeFunctions.put("canReactivateDynamically_ValueSpecification_1__Boolean_1_", new CanReactivateDynamically(repository));
this.nativeFunctions.put("canReactivateDynamically_ValueSpecification_1__Map_1__Boolean_1_", new CanReactivateDynamically(this));
this.nativeFunctions.put("evaluateAndDeactivate_T_m__T_m_", new EvaluateAndDeactivate());
this.nativeFunctions.put("toString_Any_1__String_1_", new ToString(repository, this));
this.nativeFunctions.put("mutateAdd_T_1__String_1__Any_MANY__T_1_", new MutateAdd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.map.MutableMap;
import org.finos.legend.pure.m3.exception.PureExecutionException;
import org.finos.legend.pure.m3.compiler.Context;
import org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap;
import org.finos.legend.pure.m3.exception.PureExecutionException;
import org.finos.legend.pure.m3.navigation.ProcessorSupport;
import org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap;
import org.finos.legend.pure.m4.coreinstance.CoreInstance;
import org.finos.legend.pure.m4.ModelRepository;
import org.finos.legend.pure.runtime.java.interpreted.ExecutionSupport;
import org.finos.legend.pure.runtime.java.interpreted.FunctionExecutionInterpreted;
import org.finos.legend.pure.runtime.java.interpreted.VariableContext;
import org.finos.legend.pure.runtime.java.interpreted.natives.core.InstantiationContext;
import org.finos.legend.pure.runtime.java.interpreted.natives.core.NativeFunction;
Expand All @@ -32,17 +32,24 @@

public class CanReactivateDynamically extends NativeFunction
{
private final ModelRepository repository;
private final FunctionExecutionInterpreted functionExecution;

public CanReactivateDynamically(ModelRepository repository)
public CanReactivateDynamically(FunctionExecutionInterpreted functionExecution)
{
this.repository = repository;
this.functionExecution = functionExecution;
}

@Override
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, CoreInstance functionExpressionToUseInStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException
{
// return repository.newBooleanCoreInstance(true);
return ValueSpecificationBootstrap.newBooleanLiteral(repository, true, processorSupport);
try
{
new Reactivate(this.functionExecution).execute(params, resolvedTypeParameters, resolvedMultiplicityParameters, variableContext, functionExpressionToUseInStack, profiler, instantiationContext, executionSupport, context, processorSupport);
hardikmaheshwari marked this conversation as resolved.
Show resolved Hide resolved
return ValueSpecificationBootstrap.newBooleanLiteral(this.functionExecution.getPureRuntime().getModelRepository(), true, processorSupport);
}
catch (PureExecutionException e)
{
return ValueSpecificationBootstrap.newBooleanLiteral(this.functionExecution.getPureRuntime().getModelRepository(), false, processorSupport);
}
}
}