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

DYN-6527: Fix graph update for primitive input nodes that are first initialized to null #14703

Merged
merged 41 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
64b4706
remove coreclr-ncalc references
aparajit-pratap Aug 23, 2023
4a82ae7
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Aug 25, 2023
dbc3e12
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Aug 30, 2023
81ace20
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Aug 31, 2023
a7cafdc
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 6, 2023
55c654d
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 6, 2023
7ede2a4
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 7, 2023
c43a02d
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 8, 2023
1951d1a
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 20, 2023
cd100b1
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 21, 2023
c04c193
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Sep 25, 2023
35edbdb
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 16, 2023
5c6a4a3
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 18, 2023
1641149
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 19, 2023
eff8d9b
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 20, 2023
8415e17
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 23, 2023
8a3368b
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Oct 30, 2023
3350614
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 6, 2023
be0a127
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 10, 2023
a3d62e9
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 15, 2023
a3c806e
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 17, 2023
e93499d
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 20, 2023
a551e0e
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 21, 2023
1889a02
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 27, 2023
f3a7315
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 27, 2023
06e96a0
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 29, 2023
823d317
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Nov 30, 2023
f411221
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 1, 2023
7c590f3
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 1, 2023
02e4acf
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 4, 2023
d9358e0
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 5, 2023
1d41e40
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 5, 2023
12c7dc1
Merge branch 'master' of github.com:DynamoDS/Dynamo
aparajit-pratap Dec 6, 2023
816dccf
add failing test for dropdown node
aparajit-pratap Dec 6, 2023
fa51c82
cleanup
aparajit-pratap Dec 6, 2023
c48f42a
update tests
aparajit-pratap Dec 7, 2023
76b04a4
attempt initial fix
aparajit-pratap Dec 7, 2023
33c071b
cleanup
aparajit-pratap Dec 7, 2023
600fea5
update test
aparajit-pratap Dec 7, 2023
d688294
review comments
aparajit-pratap Dec 7, 2023
ba8f011
add code comments
aparajit-pratap Dec 8, 2023
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
58 changes: 8 additions & 50 deletions src/Engine/ProtoAssociative/CodeGen_SSA.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ProtoCore.AST.AssociativeAST;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.DSASM;
using ProtoCore.Utils;
using System.Collections.Generic;
Expand Down Expand Up @@ -275,7 +275,11 @@ private List<AssociativeNode> BuildSSA(List<AssociativeNode> astList, ProtoCore.
BinaryExpressionNode bnode = (node as BinaryExpressionNode);
int generatedUID = ProtoCore.DSASM.Constants.kInvalidIndex;

if (context.applySSATransform && core.Options.GenerateSSA)
// Skip SSA for input ASTs that are first assigned null such as this:
// a = null; (update "a") => a = <some primitive>;
// SSA would break up the null AST into two assignments, which then breaks update:
// a = null; (SSA) => temp = null; a = temp;
if (context.applySSATransform && core.Options.GenerateSSA && !bnode.IsInputExpression)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Skip SSA for cases such as this:

a = null;
// update a
a = <some primitive>;

which would after SSA turn into this:

temp = null;
a = temp;
...
a = <some primitive>; // breaks!

Copy link
Member

Choose a reason for hiding this comment

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

do you think this is a good constraint to have on SSA, or should we mark this as a temporary workaround and file a task to fix the optimization in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't see any reason why we need to SSA a simple expression like a = null; in the first place, which essentially states that each variable should be assigned exactly once.

int ssaID = ProtoCore.DSASM.Constants.kInvalidIndex;
string name = ProtoCore.Utils.CoreUtils.GenerateIdentListNameString(bnode.LeftNode);
Expand Down Expand Up @@ -382,53 +386,6 @@ private List<AssociativeNode> BuildSSA(List<AssociativeNode> astList, ProtoCore.
return astList;
}

private void DfsSSAIeentList(AssociativeNode node, ref Stack<AssociativeNode> ssaStack, ref List<AssociativeNode> astlist)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused

if (node is IdentifierListNode)
{
IdentifierListNode listNode = node as IdentifierListNode;

bool isSingleDot = !(listNode.LeftNode is IdentifierListNode) && !(listNode.RightNode is IdentifierListNode);
if (isSingleDot)
{
BinaryExpressionNode bnode = BuildSSAIdentListAssignmentNode(listNode);
astlist.Add(bnode);
ssaStack.Push(bnode);
}
else
{
DfsSSAIeentList(listNode.LeftNode, ref ssaStack, ref astlist);

IdentifierListNode newListNode = node as IdentifierListNode;
newListNode.Optr = Operator.dot;

AssociativeNode leftnode = ssaStack.Pop();
Validity.Assert(leftnode is BinaryExpressionNode);

newListNode.LeftNode = (leftnode as BinaryExpressionNode).LeftNode;
newListNode.RightNode = listNode.RightNode;

BinaryExpressionNode bnode = BuildSSAIdentListAssignmentNode(newListNode);
astlist.Add(bnode);
ssaStack.Push(bnode);

}
}
else if (node is FunctionCallNode)
{
FunctionCallNode fcNode = node as FunctionCallNode;
for (int idx = 0; idx < fcNode.FormalArguments.Count; idx++)
{
AssociativeNode arg = fcNode.FormalArguments[idx];

Stack<AssociativeNode> ssaStack1 = new Stack<AssociativeNode>();
DFSEmitSSA_AST(arg, ssaStack1, ref astlist);
AssociativeNode argNode = ssaStack.Pop();
fcNode.FormalArguments[idx] = argNode is BinaryExpressionNode ? (argNode as BinaryExpressionNode).LeftNode : argNode;
}
}
}

private void DFSEmitSSA_AST(AssociativeNode node, Stack<AssociativeNode> ssaStack, ref List<AssociativeNode> astlist)
{
Validity.Assert(null != astlist && null != ssaStack);
Expand Down Expand Up @@ -488,7 +445,8 @@ private void DFSEmitSSA_AST(AssociativeNode node, Stack<AssociativeNode> ssaStac

var bnode = AstFactory.BuildAssignment(leftNode, rightNode);
bnode.isSSAAssignment = isSSAAssignment;
bnode.IsInputExpression = astBNode.IsInputExpression;
// TODO: SSA is not called for ASTs that are input expressions. Revisit this if there are any issues.
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
// bnode.IsInputExpression = astBNode.IsInputExpression;

astlist.Add(bnode);
ssaStack.Push(bnode);
Expand Down
3 changes: 2 additions & 1 deletion src/Engine/ProtoCore/DSASM/InstructionSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using ProtoCore.Exceptions;
Expand All @@ -10,6 +10,7 @@ namespace ProtoCore.DSASM
public enum Registers
{
RX,
// Register used to temporarily store primitive values for graph update cycles.
LX,
}

Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/CoreNodeModels/Enum.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down
53 changes: 53 additions & 0 deletions test/DynamoCoreWpfTests/NodeExecutionUITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,58 @@ public void TestSelectionNodeUpdate2()
AssertPreviewValue(tsn.GUID.ToString(), 0);

}

[Test]
public void TestDropdownNodeUpdate()
{
var model = GetModel();
var tdd = new TestDropdown
{
SelectedIndex = 0
};

var command = new DynamoModel.CreateNodeCommand(tdd, 0, 0, true, false);
model.ExecuteCommand(command);

AssertPreviewValue(tdd.GUID.ToString(), "one");

tdd.SelectedIndex = 1;
tdd.OnNodeModified();

AssertPreviewValue(tdd.GUID.ToString(), "two");

tdd.SelectedIndex = 2;
tdd.OnNodeModified();

AssertPreviewValue(tdd.GUID.ToString(), "three");

}

[Test]
public void TestDropdownNodeUpdate1()
{
var model = GetModel();
var tdd = new TestDropdown();

var command = new DynamoModel.CreateNodeCommand(tdd, 0, 0, true, false);
model.ExecuteCommand(command);

AssertPreviewValue(tdd.GUID.ToString(), null);

tdd.SelectedIndex = 0;
tdd.OnNodeModified();

AssertPreviewValue(tdd.GUID.ToString(), "one");

tdd.SelectedIndex = 1;
tdd.OnNodeModified();

AssertPreviewValue(tdd.GUID.ToString(), "two");

tdd.SelectedIndex = 2;
tdd.OnNodeModified();

AssertPreviewValue(tdd.GUID.ToString(), "three");
}
}
}
52 changes: 51 additions & 1 deletion test/TestUINodes/TestUINodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -140,4 +140,54 @@ protected override int GetModelObjectFromIdentifer(string id)
return id.Length;
}
}

[NodeName("Test Dropdown Node")]
[NodeCategory("TestUINodes")]
[NodeDescription("test dropdown node")]
[OutPortTypes("string")]
[IsDesignScriptCompatible]
[IsVisibleInDynamoLibrary(false)]
public class TestDropdown : DSDropDownBase
{
public TestDropdown() : base("TestDropdown") { }


public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
AssociativeNode node;
if (SelectedIndex < 0 || SelectedIndex >= Items.Count)
{
node = AstFactory.BuildNullNode();
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), node) };
}
else
{
// get the selected items name
var stringNode = AstFactory.BuildStringNode((string)Items[SelectedIndex].Name);

// assign the selected name to an actual enumeration value
var assign = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), stringNode);

// return the enumeration value
return new List<AssociativeNode> { assign };
}
}

protected override SelectionState PopulateItemsCore(string currentSelection)
{
Items.Clear();

var symbols = new[] { "one", "two", "three" };


foreach (var symbol in symbols)
{

Items.Add(new DynamoDropDownItem(symbol, symbol));
}

return SelectionState.Restore;
}

}
}
Loading