Skip to content

Commit

Permalink
Merge pull request #4464 from ke-yu/magn3979
Browse files Browse the repository at this point in the history
Inline condition replicates on all three branches
  • Loading branch information
lukechurch committed May 19, 2015
2 parents 50bf240 + ec11e59 commit b7dd36f
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/Engine/ProtoAssociative/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6694,7 +6694,7 @@ private void EmitInlineConditionalNode(AssociativeNode node, ref ProtoCore.Type
// As SSA conversion is enabled, we have got the values of
// true and false branch, so it isn't necessary to create
// language blocks.
if (core.Options.IsDeltaExecution && core.Options.GenerateSSA)
if (core.Options.GenerateSSA)
{
inlineCall.FormalArguments.Add(inlineConditionalNode.ConditionExpression);
inlineCall.FormalArguments.Add(inlineConditionalNode.TrueExpression);
Expand Down
5 changes: 0 additions & 5 deletions src/Engine/ProtoCore/DSASM/DSasmDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,26 +408,21 @@ public struct Constants
public const string kTempArg = "%targ";
public const string kTempVar = "%tvar";
public const string kTempPropertyVar = "%tvar_property";
public const string kTempExceptionVar = "%texp";
public const string kTempLangBlock = "%tempLangBlock";
public const string kForLoopExpression = "%forloop_expr_";
public const string kForLoopKey = "%forloop_key_";
public const string kStartOfAutogenForloopIteration = "%autogen_forloop_iteration_";
public const string kStartOfAutogenForloopCount = "%autogen_forloop_count_";
public const string kFunctionPointerCall = "%FunctionPointerCall";
public const string kFunctionRangeExpression = "%generate_range";
public const string kDotMethodName = "%dot";
public const string kDotArgMethodName = "%dotarg";
public const string kInlineConditionalMethodName = "%inlineconditional";
public const string kInlineCondition = "%InlineCondition";
public const string kGetTypeMethodName = "%get_type";
public const string kNodeAstFailed = "%nodeAstFailed";
public const string kWatchResultVar = "watch_result_var";
public const string kSSATempPrefix = "%tSSA_";
public const string kGlobalInstanceNamePrefix = "%globalInstanceFunction_";
public const string kGlobalInstanceFunctionPrefix = "%proc";
public const string kThisPointerArgName = "%thisPtrArg";
public const string kMangledFunctionPlaceholderName = "%Placeholder";
public const string kTempModifierStateNamePrefix = "%tmp_modifierState_";
public const string kTempProcConstant = "temp_proc_var_";
public const string kTempProcLeftVar = "%" + kTempProcConstant;
Expand Down
4 changes: 1 addition & 3 deletions src/Engine/ProtoCore/Lang/BuiltInFunctionEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,8 @@ public override StackValue Execute(ProtoCore.Runtime.Context c, List<StackValue>
// If run in delta execution environment, we don't
// create language blocks for true and false branch,
// so directly return the value.
if (runtimeCore.Options.IsDeltaExecution)
{
if (runtimeCore.Options.GenerateSSA)
return svCondition.RawBooleanValue ? svTrue : svFalse;
}

Validity.Assert(svTrue.IsInteger);
Validity.Assert(svFalse.IsInteger);
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/ProtoCore/Lang/BuiltInMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ public BuiltInMethods(Core core)
Parameters = new List<KeyValuePair<string, ProtoCore.Type>>
{
new KeyValuePair<string, ProtoCore.Type>("condition", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeBool, 0)),
new KeyValuePair<string, ProtoCore.Type>("dyn1", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, Constants.kArbitraryRank)),
new KeyValuePair<string, ProtoCore.Type>("dyn2", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, Constants.kArbitraryRank))
new KeyValuePair<string, ProtoCore.Type>("dyn1", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, 0)),
new KeyValuePair<string, ProtoCore.Type>("dyn2", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, 0))
},
ID = BuiltInMethods.MethodID.kInlineConditional
},
Expand Down
41 changes: 0 additions & 41 deletions src/Engine/ProtoCore/Utils/CoreUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,47 +127,6 @@ private static void InsertUnaryOperationMethod(Core core, ProtoCore.AST.Node roo
(root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
}

private static void InsertInlineConditionOperationMethod(Core core, ProtoCore.AST.Node root, PrimitiveType condition, PrimitiveType r)
{
ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
funcDefNode.access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic;
funcDefNode.Name = ProtoCore.DSASM.Constants.kInlineCondition;
funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r };
ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
{
memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
NameNode = BuildAssocIdentifier(core, "%condition"),
ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)condition), UID = (int)condition }
});
args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
{
memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
NameNode = BuildAssocIdentifier(core, "%trueExp"),
ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r }
});
args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
{
memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
NameNode = BuildAssocIdentifier(core, "%falseExp"),
ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r }
});
funcDefNode.Signature = args;

ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn);
ProtoCore.AST.AssociativeAST.IdentifierNode con = BuildAssocIdentifier(core, "%condition");
ProtoCore.AST.AssociativeAST.IdentifierNode t = BuildAssocIdentifier(core, "%trueExp");
ProtoCore.AST.AssociativeAST.IdentifierNode f = BuildAssocIdentifier(core, "%falseExp");

body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.InlineConditionalNode() { ConditionExpression = con, TrueExpression = t, FalseExpression = f } });
funcDefNode.FunctionBody = body;
(root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
}

private static void InsertPredefinedMethod(Core core, ProtoCore.AST.Node root, bool builtinMethodsLoaded)
{
if (!builtinMethodsLoaded)
Expand Down
10 changes: 8 additions & 2 deletions test/DynamoCoreTests/DSEvaluationModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public void Test_IFnode_3483_1()
public void Test_IFnode_3483_2()
{
RunModel(@"core\dsevaluation\ifnode_3483_2.dyn");
AssertPreviewValue("70b5aeba-80b7-48cc-a48d-6c755c28555c", new object []{ 1, 1, 1, new object []{ -2, -1, 0, 1, 2 },new object[] { -2, -1, 0, 1, 2 } });
AssertPreviewValue("70b5aeba-80b7-48cc-a48d-6c755c28555c", new object[] { 1, 1, 1, 1, 2 });
}
[Test]
[Category("RegressionTests")]
Expand Down Expand Up @@ -710,7 +710,13 @@ public void Test_IfinputFunctionObject_3483()
public void Test_IfAsFunctionobject_3483()
{
RunModel(@"core\dsevaluation\IfAsFunctionobject_3483.dyn");
AssertPreviewValue("80d14b69-4796-48c9-a34d-f447abf7b5ba", new object[] {1,1,new double[]{-2,-1,0,1,2},1,1});
AssertPreviewValue("80d14b69-4796-48c9-a34d-f447abf7b5ba", new object[] {
new object[] { 1, 1, 1, 1, 1},
new object[] { 1, 1, 1, 1, 1},
new double[] {-2,-1, 0, 1, 2},
new object[] { 1, 1, 1, 1, 1},
new object[] { 1, 1, 1, 1, 1},
});
}

[Test]
Expand Down
6 changes: 1 addition & 5 deletions test/DynamoCoreTests/Nodes/IfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public void TestIFBasic()
RunModel(testFilePath);

AssertPreviewValue("7d6e8c70-3abf-4fc4-864e-948f548e7ba2", 5.0);
AssertPreviewValue("d5f5336d-3569-4a88-9a59-5538d6914037",
new object[] { 1, 1, 1, 1,
new object[] {-3, -2, -1, 0, 1, 2, 3},
new object[] {-3, -2, -1, 0, 1, 2, 3},
new object[] {-3, -2, -1, 0, 1, 2, 3}});
AssertPreviewValue("d5f5336d-3569-4a88-9a59-5538d6914037", new object[] { 1.0, 1.0, 1.0, 1.0, 1, 2, 3});
}

[Test]
Expand Down
5 changes: 4 additions & 1 deletion test/Engine/ProtoTest/DebugTests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13101,11 +13101,14 @@ static def foo(y : int)

// It should not be available.
Assert.AreNotEqual(null, objExecVal);
Assert.AreEqual(4, objExecVal.Payload);
Assert.AreEqual(1, objExecVal.Payload);

vms = fsr.Step();
vms = fsr.Step(); // a = x > foo(22) ? foo(1) : A.foo(4);
vms = fsr.Step();
vms = fsr.Step();
vms = fsr.Step();
vms = fsr.Step();
TestFrameWork.Verify(mirror, "a", 8, 0);
}
[Test]
Expand Down
37 changes: 12 additions & 25 deletions test/Engine/ProtoTest/TD/Associative/InlineCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,9 @@ public void T006_Inline_Using_Different_Sized_1_Dim_Collections()
b3 = a1>3?c1:c2; // expected : {1, 2}
";
ExecutionMirror mirror = thisTest.RunScriptSource(src);
Object[] b = new Object[] { 1, 2, 3, 4 };
Object[] c = new Object[] { 1, 2, 3 };
Object[] d = new Object[] { 1, 2 };
Object[] b1 = new Object[] { b, b, b, true };
Object[] b2 = new Object[] { c, c, c, true };
Object[] b3 = new Object[] { d, d, d, c };
thisTest.Verify("b1", b1);
thisTest.Verify("b2", b2);
thisTest.Verify("b3", b3);
thisTest.Verify("b1", new object[] {1, 2, 3,true});
thisTest.Verify("b2", new object[] {1, 2, 3});
thisTest.Verify("b3", new object[] {1, 2});
}


Expand All @@ -163,17 +157,11 @@ public void T007_Inline_Using_Collections_And_Replication()
e1 = (a[-2] == d[9])? 9 : a[1..2]; // { 2, 3 }
";
ExecutionMirror mirror = thisTest.RunScriptSource(src);
// following verification might need to be updated for current implementation, once the defect above is fixed
// b = ((a[i] % 2) > 0)? even(a[i]) : a;
// replication only is supported on condition, not the overall expression.
// List<Object> b = new List<object>() { 1, 6, 3, 10, 5 };
// Assert.IsTrue(mirror.CompareArrays("b", b, typeof(System.Int64)));
List<Object> c = new List<object>() { 4, 6, 8, 10, 12 };
List<Object> d = new List<object>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
List<Object> e1 = new List<object>() { 2, 3 };
Assert.IsTrue(mirror.CompareArrays("c", c, typeof(System.Int64)));
Assert.IsTrue(mirror.CompareArrays("d", d, typeof(System.Int64)));
Assert.IsTrue(mirror.CompareArrays("e1", e1, typeof(System.Int64)));
thisTest.Verify("c", new object[] { 4, 6, 8, 10, 12 });
thisTest.Verify("d", new object[] { 1, 2, 3, 4, 5 });
thisTest.Verify("e1", new object[] { 2, 3});

}


Expand All @@ -189,8 +177,7 @@ public void T008_Inline_Returing_Different_Ranks()
x_1 = x[1];
";
ExecutionMirror mirror = thisTest.RunScriptSource(src);
Object[] b1 = new Object[] { new Object[] { 1, 1 }, new Object[] { 1, 1 }, 0, 0 };
thisTest.Verify("x", b1);
thisTest.Verify("x", new object[] {1, 1});
}


Expand Down Expand Up @@ -241,7 +228,7 @@ def odd(a : int )
";
thisTest.VerifyRunScriptSource(src, errmsg);
Object n1 = null;
thisTest.Verify("b", new object[] { new object[] { 2, 4, 6 }, new object[] { 2, 4, 6 }, new object[] { 2, 4, 6 } });
thisTest.Verify("b", new object[] {2, 4, 6});
thisTest.Verify("a", 10);
thisTest.Verify("c", 13);
thisTest.Verify("d", 53);
Expand Down Expand Up @@ -343,8 +330,8 @@ def foo ( )
";
string err = "MAGN-4026 Execution of both true and false statements in Associative inline condition";
ExecutionMirror mirror = thisTest.RunScriptSource(src, err);
thisTest.Verify("x", 3);
thisTest.Verify("a", 1);
thisTest.Verify("x", 4);
thisTest.Verify("a", 2);
}


Expand Down Expand Up @@ -552,7 +539,7 @@ public void T013_Defect_1467290_2()
test = x;";
string errmsg = "";//1467290 sprint25: rev 3731 : REGRESSION : Update with inline condition across multiple language blocks is not working as expected";
thisTest.VerifyRunScriptSource(code, errmsg);
thisTest.Verify("x", 2);
thisTest.Verify("x", new object[] {2, 2});
}


Expand Down
39 changes: 19 additions & 20 deletions test/Engine/ProtoTest/TD/Associative/Replication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ public void T50_1_of_3_Exprs_is_List()
ExecutionMirror mirror = thisTest.RunScriptSource(code);
//Assert.Fail("1456751 : Sprint16 : Rev 990 : Inline conditions not working with replication over collections");
thisTest.Verify("list2", new object[] { 1, 0, 1, 0, 1 });
thisTest.Verify("list3", 10);
thisTest.Verify("list3", new object[] {10, 10, 10, 10, 10});
thisTest.Verify("list4", new object[] { 1, 0, 1, 0, 1 });
thisTest.Verify("list5", new object[] { 0, 0, 0, 1, 1 });
thisTest.Verify("list6", new object[] { 1, 1, 0, 0 });
Expand All @@ -1539,12 +1539,12 @@ public void T51_2_of_3_Exprs_are_Lists_Different_Length()
list8 = a >= b ? a + c : 10; // { 10, 10, 10 }
list9 = a < b ? 10 : a + c; // { 10, 10, 10 }";
ExecutionMirror mirror = thisTest.RunScriptSource(code);
thisTest.Verify("list3", new object[] { a1, 0, a1, 0 });
thisTest.Verify("list4", new object[] { 0, a1, 0, a1 });
thisTest.Verify("list3", new object[] { 1, 0, 3, 0});
thisTest.Verify("list4", new object[] { 0, 2, 0, 4 });
thisTest.Verify("list6", a1);
thisTest.Verify("list7", new object[] { -1, -2, -3, -4, -5, -6 });
thisTest.Verify("list8", new object[] { 10, 10, a2, a2 });
thisTest.Verify("list9", new object[] { 10, 10, a2, a2 });
thisTest.Verify("list7", new object[] { -1, -2, -3, -4, -5});
thisTest.Verify("list8", new object[] { 10, 10, 10 });
thisTest.Verify("list9", new object[] { 10, 10, 10 });
}

[Test]
Expand All @@ -1558,8 +1558,7 @@ public void T53_3_of_3_Exprs_are_different_dimension_list()
list = a > b ? b + c : a + c; // { { 2, 4, }, { 8, 10 } } ";
ExecutionMirror mirror = thisTest.RunScriptSource(code);
//Assert.Fail("1456751 : Sprint16 : Rev 990 : Inline conditions not working with replication over collections");
Object[] b1 = new Object[] { new Object[] { new Object[] { new Object[] { 2, 4, 6 }, new Object[] { 9, 11, 13 } }, new Object[] { new Object[] { 2, 4, 6 }, new Object[] { 9, 11, 13 } } }, new Object[] { new Object[] { new Object[] { 2, 4 }, new Object[] { 8, 10 }, new Object[] { 14, 16 } }, new Object[] { new Object[] { 2, 4 }, new Object[] { 8, 10 }, new Object[] { 14, 16 } } } };
thisTest.Verify("list", b1);
thisTest.Verify("list", new [] { new [] {2, 4}, new [] {8, 10}});
}

[Test]
Expand All @@ -1568,11 +1567,11 @@ public void T54_3_of_3_Exprs_are_Lists_Different_Length()
{
Object[] list2 = { 1, 2, 3, 4 };
Object[] list3 = { -1, -2, -3, -4, -5, -6 };
Object[] list4 = new Object[] { list2, list3, list2, list2, list3 };
Object[] list5 = new Object[] { list4, list2, list4, list4, list2 };
Object[] list4 = new Object[] { 1, -2, 3, 4 };
Object[] list5 = new Object[] { 1, 2, 3, 4 };
Object[] list6 = { -1, -2, -3, -4, -5 };
Object[] list7 = new Object[] { list2, list6, list2, list2, list6 };
Object[] list8 = new Object[] { new Object[] { 1, 4, 0 }, new Object[] { 0, 5, 1, 5 }, new Object[] { 0, 5, 1, 5 } };
Object[] list7 = new Object[] { 1, -2, 3, 4 };
Object[] list8 = new Object[] { 1, 5, 1};
string code = @"
list1 = { true, false, true, true, false };
list2 = { 1, 2, 3, 4 };
Expand All @@ -1584,7 +1583,7 @@ public void T54_3_of_3_Exprs_are_Lists_Different_Length()
a = { 3, 0, -1 };
b = { 2, 1, 0, 3 };
c = { -2, 4, 1, 2, 0 };
list8 = a < c ? b + c : a + c; // { 1, 4, 1 }";
list8 = a < c ? b + c : a + c; // { 1, 5, 1 }";
ExecutionMirror mirror = thisTest.RunScriptSource(code);
//Assert.Fail("1456751 : Sprint16 : Rev 990 : Inline conditions not working with replication over collections");
thisTest.Verify("list4", list4);
Expand All @@ -1599,9 +1598,9 @@ public void T55_3_of_3_Exprs_are_Lists_Same_Length()
{
Object[] list2 = { 1, 2, 3, 4 };
Object[] list3 = { -1, -2, -3, -4 };
Object[] list6 = new Object[] { new Object[] { -4, -1, 2 }, new Object[] { -4, -1, 2 }, new Object[] { 8, 17, 8 } };
Object[] list5 = new Object[] { list3, list2, list2, list3 };
Object[] list4 = new Object[] { list2, list3, list3, list2 };
Object[] list6 = new Object[] { -4, -1, 8};
Object[] list5 = new Object[] { -1, 2, 3, -4 };
Object[] list4 = new Object[] { 1, -2, -3, 4};
string code = @"
list1 = { true, false, false, true };
list2 = { 1, 2, 3, 4 };
Expand Down Expand Up @@ -3826,7 +3825,7 @@ constructor A ( x )
ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
String errmsg = "";
ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
thisTest.Verify("test", new Object[] { new Object[] { 0, 1 }, new Object[] { 0, 1 } });
thisTest.Verify("test", new [] {0, 1});
}

[Test]
Expand Down Expand Up @@ -6199,7 +6198,7 @@ public void T96_Defect_1467192_Replication_Inline_Condition()
String errmsg = "";
ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
Object[] v1 = new Object[] { false, false };
thisTest.Verify("d2", new Object[] { v1, v1 });
thisTest.Verify("d2", v1);
thisTest.Verify("f2", v1);

}
Expand All @@ -6225,7 +6224,7 @@ public void T96_Defect_1467192_Replication_Inline_Condition_2()
String errmsg = "";
ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
Object[] v1 = new Object[] { false, false };
thisTest.Verify("d2", new Object[] { v1, v1 });
thisTest.Verify("d2", v1);
}

[Test]
Expand Down Expand Up @@ -6253,7 +6252,7 @@ constructor A ( a2:int[], b2:int )
String errmsg = "";
ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
Object[] v1 = new Object[] { false, true };
thisTest.Verify("test1", new Object[] { new Object[] { 0, 0 }, 1 });
thisTest.Verify("test1", new Object[] { 0, 1 });
thisTest.Verify("test2", v1);
}

Expand Down
Loading

0 comments on commit b7dd36f

Please sign in to comment.