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

DYN1198- Heterogeneous list update gives infinite loop #9408

Merged
merged 39 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7156f6e
Add check for invalid cutom node name
reddyashish Dec 3, 2018
5c88c44
Removing trailing spaces
reddyashish Dec 3, 2018
827b090
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 4, 2018
d055de4
Moving the function to utilities class
reddyashish Dec 4, 2018
085fb51
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 10, 2018
12538ab
Revert "Merge branch 'master' of https://github.com/DynamoDS/Dynamo"
reddyashish Dec 10, 2018
101857b
Revert "Revert "Merge branch 'master' of https://github.com/DynamoDS/…
reddyashish Dec 10, 2018
5659d22
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 10, 2018
c3a97df
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 13, 2018
6987cfa
Adding tests - QNTM-3928
reddyashish Dec 13, 2018
68194bd
Comments
reddyashish Dec 13, 2018
77193b5
Moving the test to NodeViewCustomizationTests.cs
reddyashish Dec 13, 2018
3b522b1
Deleting changes to SerializationTests.cs
reddyashish Dec 13, 2018
2b85fc0
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 13, 2018
68eeba9
Create SerializationTests.cs
reddyashish Dec 13, 2018
4a76a7a
Update SerializationTests.cs
reddyashish Dec 13, 2018
bb11dd8
moving the test to UtilityTests.ca
reddyashish Dec 13, 2018
9b37a3d
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Dec 20, 2018
e8d7b8a
Heterogeneous list update gives infinite loop
reddyashish Dec 20, 2018
d91009e
Moving the test dyn file
reddyashish Dec 20, 2018
02b0d99
Revert "Moving the test dyn file"
reddyashish Jan 2, 2019
71f2ca4
Revert "Heterogeneous list update gives infinite loop"
reddyashish Jan 2, 2019
11693cd
Merge branch 'master' of https://github.com/reddyashish/Dynamo
reddyashish Jan 2, 2019
1458b46
making Surface.join node obsolete
reddyashish Jan 9, 2019
a4e0e98
Revert "making Surface.join node obsolete"
reddyashish Jan 9, 2019
ee59554
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
reddyashish Jan 9, 2019
2ed772f
Obsoleting Surface,Join node.
reddyashish Jan 9, 2019
52b95a0
Heterogenous list crash fix
reddyashish Jan 10, 2019
9a0681b
Merge branch 'master' of https://github.com/DynamoDS/Dynamo into DYN1198
reddyashish Jan 10, 2019
10c3c3e
Revert "Obsoleting Surface,Join node."
reddyashish Jan 10, 2019
37678d6
Adding test case for heterogeneous list crash
reddyashish Jan 10, 2019
8f19619
Adding tests
reddyashish Jan 10, 2019
2c1fe9c
Adding new test
reddyashish Jan 11, 2019
9929026
fix remaining edge cases
aparajit-pratap Jan 12, 2019
4f3f6d9
revert assemblysharedinfo file
aparajit-pratap Jan 12, 2019
5d75240
Updating failing tests
reddyashish Jan 12, 2019
b21d0d5
add new method to prevent API break
aparajit-pratap Jan 12, 2019
0fd9e37
Merge branch 'DYN1198' of https://github.com/reddyashish/Dynamo into …
aparajit-pratap Jan 12, 2019
c26dcac
simplify SelectMany
aparajit-pratap Jan 12, 2019
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
52 changes: 28 additions & 24 deletions src/Engine/ProtoCore/Lang/Replication/Replicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,46 +201,50 @@ public static List<List<StackValue>> ComputeAllReducedParams(
RuntimeCore runtimeCore)
{
//Copy the types so unaffected ones get copied back directly
List<StackValue> basicList = new List<StackValue>(formalParams);
var basicList = new List<StackValue>(formalParams);

//Compute the reduced Type args
List<List<StackValue>> reducedParams = new List<List<StackValue>>();
var reducedParams = new List<List<StackValue>>();
reducedParams.Add(basicList);

foreach (ReplicationInstruction ri in replicationInstructions)
foreach (var ri in replicationInstructions)
{
var indices = ri.Zipped ? ri.ZipIndecies : new List<int> { ri.CartesianIndex };
foreach (int index in indices)
{
//This should generally be a collection, so we need to do a one phase unboxing
var targets = reducedParams.Select(r => r[index]).ToList();
foreach (var target in targets)
var target = basicList[index];

if (!target.IsArray)
{
if (!target.IsArray)
{
System.Console.WriteLine("WARNING: Replication unbox requested on Singleton. Trap: 437AD20D-9422-40A3-BFFD-DA4BAD7F3E5F");
continue;
}
System.Console.WriteLine("WARNING: Replication unbox requested on Singleton. Trap: 437AD20D-9422-40A3-BFFD-DA4BAD7F3E5F");
continue;
}

var array = runtimeCore.Heap.ToHeapObject<DSArray>(target);
if (array.Count == 0)
{
continue;
}
var array = runtimeCore.Heap.ToHeapObject<DSArray>(target);
if (array.Count == 0)
{
continue;
}

var arrayStats = ArrayUtils.GetTypeExamplesForLayer(target, runtimeCore).Values;
var arrayStats = new HashSet<StackValue>();
foreach (var targetTemp in targets)
{
var temp = ArrayUtils.GetTypeExamplesForLayer2(targetTemp, runtimeCore).ToList();
arrayStats.UnionWith(temp);
}

List<List<StackValue>> clonedList = new List<List<StackValue>>(reducedParams);
reducedParams.Clear();
var clonedList = new List<List<StackValue>>(reducedParams);
reducedParams.Clear();

foreach (StackValue sv in arrayStats)
foreach (var sv in arrayStats)
{
foreach (var lst in clonedList)
{
foreach (List<StackValue> lst in clonedList)
{
List<StackValue> newArgs = new List<StackValue>(lst);
newArgs[index] = sv;
reducedParams.Add(newArgs);
}
var newArgs = new List<StackValue>(lst);
newArgs[index] = sv;
reducedParams.Add(newArgs);
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/Engine/ProtoCore/Utils/ArrayUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using ProtoCore.DSASM;
using ProtoCore.Exceptions;
using ProtoCore.Runtime;
Expand Down Expand Up @@ -117,6 +118,7 @@ public static ClassNode GetGreatestCommonSubclassForArray(StackValue array, Runt
return runtimeCore.DSExecutable.classTable.ClassNodes[orderedTypes.First()];
}

// TODO gantaa/pratapa: Remove this deprecated method in 3.0 and rename GetTypeExamplesForLayer2
public static Dictionary<int, StackValue> GetTypeExamplesForLayer(StackValue array, RuntimeCore runtimeCore)
{
Dictionary<int, StackValue> usageFreq = new Dictionary<int, StackValue>();
Expand All @@ -138,6 +140,45 @@ public static Dictionary<int, StackValue> GetTypeExamplesForLayer(StackValue arr
return usageFreq;
}

public static IEnumerable<StackValue> GetTypeExamplesForLayer2(StackValue array, RuntimeCore runtimeCore)
{
var usageFreq = new Dictionary<int, List<StackValue>>();

if (!array.IsArray)
{
usageFreq.Add(array.metaData.type, new List<StackValue> {array});

// return flattened list of unique values
return usageFreq.Values.SelectMany(x => x);
}

//This is the element on the heap that manages the data structure
var dsArray = runtimeCore.Heap.ToHeapObject<DSArray>(array);
foreach (var sv in dsArray.Values)
{
// If sv is an array type, continue adding array values to usageFreq dictionary
// as different arrays need not necessarily contain the same types.
if (sv.IsArray)
{
List<StackValue> list;
if (usageFreq.TryGetValue(sv.metaData.type, out list))
{
list.Add(sv);
}
else
{
usageFreq.Add(sv.metaData.type, new List<StackValue> {sv});
}
}
else if (!usageFreq.ContainsKey(sv.metaData.type))
{
usageFreq.Add(sv.metaData.type, new List<StackValue> {sv});
}
}
// return flattened list of unique values
return usageFreq.Values.SelectMany(x => x);
}



/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions test/DynamoCoreTests/DSEvaluationModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,20 @@ public void TestMAGN9507()
OpenModel(dynFilePath);
AssertPreviewValue("3bf992eb-ecc9-4fcc-a90b-9b1ee7e925e9", 3);
}

[Test, Category("UnitTests")]
public void TestHeterogenousList()
{
// open test graph
RunModel(@"core\dsevaluation\test_hetereogenous_list.dyn");

var guidX = "0cb9b9ea3c004c099c31ddfac1ebbb09";
var guidY = "e7711f22858f4ea6bb23112f274b8914";
var guidZ = "a8519f77028643d4af2c0bc415a163fc";
AssertPreviewValue(guidX, new object[] { null, null, null, 5 });
AssertPreviewValue(guidY, new object[] { null, null, null, 10.2 });
AssertPreviewValue(guidZ, new object[] { null, null, null, 15.2 });
}
}

[Category("DSCustomNode")]
Expand Down
45 changes: 45 additions & 0 deletions test/Engine/ProtoTest/Associative/BuiltinMethodsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,51 @@ public void TestTryGetValuesFromDictionary08()
thisTest.Verify("r", null);
}

[Test]
public void TestTryGetValuesFromDictionary09()
{
string code = @"
a = { ""in"" : 42, ""out"" : 24 };
b = { ""in"" : 24, ""out"" : 42 };
c = [[a],[[b]]];
Copy link
Contributor Author

@reddyashish reddyashish Jan 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested Dictionaries work fine but fails when the level of nesting for list "a" i.e 1, is less than the nesting level of list "b" i.e 2.

r1 = Dictionary.ValueAtKey(c, ""in"");
r2 = Dictionary.ValueAtKey(c, ""out"");
";
var mirror = thisTest.RunScriptSource(code);
thisTest.Verify("r1", new object[] { new object[] { 42 } , new object[] { new object[] { 24 } } });
thisTest.Verify("r2", new object[] { new object[] { 24 } , new object[] { new object[] { 42 } } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the results of this test before and after this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, the result is same as before. We were getting this wrong output before too but never caught it.
output

}

[Test]
public void TestTryGetValuesFromDictionary10()
{
string code = @"
a = { ""in"" : 42, ""out"" : 24 };
b = { ""in"" : 24, ""out"" : 42 };
c = [[[a]],b];
r1 = Dictionary.ValueAtKey(c, ""in"");
r2 = Dictionary.ValueAtKey(c, ""out"");
";
var mirror = thisTest.RunScriptSource(code);
thisTest.Verify("r1", new object[] { new object[] { new object[] { 42 } }, 24 });
thisTest.Verify("r2", new object[] { new object[] { new object[] { 24 } }, 42 });
}

[Test]
public void TestTryGetValuesFromDictionary11()
{
string code = @"
a = [ ""in"" , 42, ""out"" , 24 ];
b = { ""in"" : 24, ""out"" : 42 };
c = [a,[b]];
r1 = Dictionary.ValueAtKey(c, ""in"");
r2 = Dictionary.ValueAtKey(c, ""out"");
";
var mirror = thisTest.RunScriptSource(code);
thisTest.Verify("r1", new object[] { new object[] { null, null, null, null }, new object[] { 24 } });
thisTest.Verify("r2", new object[] { new object[] { null, null, null, null }, new object[] { 42 } });
}

[Test]
public void TestGetKeysFromNonArray()
{
Expand Down
Loading