-
Notifications
You must be signed in to change notification settings - Fork 635
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
Avoid namespace collisions when collapsing graph to custom node #9330
Avoid namespace collisions when collapsing graph to custom node #9330
Conversation
Not sure how this effects node2code. - may create rewriter directly.
@@ -674,7 +678,8 @@ internal bool TryGetInfoFromPath(string path, bool isTestMode, out CustomNodeInf | |||
nodeGraph.ElementResolver, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the nodeGraph is instantiated from an xml file? Is that why it doesn't get the correct element resolver as we are now using JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is where we use the deserialized element resolver when loading a JSON graph and pass it to the home workspace or customNode workspace that was just deserialized.
ws = new CustomNodeWorkspaceModel(factory, nodes, notes, annotations, |
use it in custmNodeManager collapse method
@aparajit-pratap I've updated this with one potential solution. |
{ | ||
node.InputSymbol += ":" + typedParameter.Type.Name; | ||
this.AsLogger().LogError($"{e.Message}: could not generate a short type name for {typedParameter.Type.Name}"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this set InputSymbol
to the full name even though it is unable to find a short name? If not, it should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, thats what it does.
return node; | ||
|
||
// build an idlistnode from the full type name | ||
var identListNode = CoreUtils.CreateNodeFromString(node.datatype.Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just pass node.TypeAlias
to CreateNodeFromString
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will try that - thanks.
// build an idlistnode from the full type name | ||
var identListNode = CoreUtils.CreateNodeFromString(node.datatype.Name); | ||
if (identListNode == null) | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be safer to return node
here just in case it's still valid.
// visit the idlist | ||
var shortNameNode = identListNode.Accept(this); | ||
if(shortNameNode == null) | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be safer to return node
here just in case it's still valid.
{ | ||
var idNode = (shortNameNode as IdentifierNode); | ||
resultingNode.TypeAlias = idNode.Value; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just do: resultingNode.TypeAlias = shortNameNode.ToString();
|
||
|
||
var resultingNode = new TypedIdentifierNode(); | ||
resultingNode.Name = node.Name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var resultingNode = new TypedIdentifierNode{
Name = node.Name,
Value = node.Name,
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
node.Name = resultingNode.Name; | ||
node.Value = resultingNode.Value; | ||
node.datatype = resultingNode.datatype; | ||
node.TypeAlias = resultingNode.TypeAlias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does node
have to be passed as a ref
parameter in order to directly assign it to resultingNode
? Is that why you have modified its properties individually here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I found that assigning node = resultantNode
did not update the node I passed in, and using a ref parameter requires touching the ASTreplacer base class - so this is not ideal, but it does seem to work.
@@ -1077,10 +1083,17 @@ internal bool TryGetNodeInfo(string name, out CustomNodeInfo info) | |||
var funcDesc = dsFunc.Controller.Definition; | |||
parameters = funcDesc.Parameters.ToList(); | |||
|
|||
// if the node is an instance member the function won't contain a | |||
// parameter for this type so we need to geneate a new typedParameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: generate
@mjkkirschner I think this looks good overall. Couple of other comments you could address here. I will look at the test cases you add before we decide to merge this. Thanks for sticking with this and fixing it :) |
update references add comments to node2code mutation tests
add extra logic to deserialization for symbol node element resolver cache
@aparajit-pratap I've moved the I've added a few tests for shortNameReplacer that test the I have yet to run all the tests on self serve CI. |
test/DynamoCoreTests/CustomNodes.cs
Outdated
var inputs = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<Symbol>().ToList(); | ||
Assert.IsNotNull(inputs); | ||
|
||
var pointParams = inputs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is pointParams
used?
test/DynamoCoreTests/CustomNodes.cs
Outdated
|
||
Assert.IsTrue(inputs.All(t => | ||
{ | ||
Console.WriteLine(t.InputSymbol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the Console.WriteLine
for?
test/DynamoCoreTests/CustomNodes.cs
Outdated
var inputs = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<Symbol>().ToList(); | ||
Assert.IsNotNull(inputs); | ||
|
||
var pointParams = inputs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
@mjkkirschner excellent! Some minor comments and then LGTM! |
# Conflicts: # src/DynamoCore/Core/CustomNodeManager.cs # src/DynamoCore/Engine/NodeToCode/NodeToCode.cs # src/DynamoCore/Graph/Nodes/CustomNodes/Function.cs # src/DynamoCore/Graph/Workspaces/NodesToCodeExtensions.cs
…moDS#9330) * this works - but I am hesitant to modify this replacer. Not sure how this effects node2code. - may create rewriter directly. * add a new visitor method for typedIdentifierNode use it in custmNodeManager collapse method * move shortQualifiedNameReplacer update references add comments to node2code mutation tests * add more tests add extra logic to deserialization for symbol node element resolver cache * revert public API break, keep rewriter in dynamoCore but in new file * remove extra usings added previously. * remove debugging code
… (#9360) * this works - but I am hesitant to modify this replacer. Not sure how this effects node2code. - may create rewriter directly. * add a new visitor method for typedIdentifierNode use it in custmNodeManager collapse method * move shortQualifiedNameReplacer update references add comments to node2code mutation tests * add more tests add extra logic to deserialization for symbol node element resolver cache * revert public API break, keep rewriter in dynamoCore but in new file * remove extra usings added previously. * remove debugging code
Purpose
Collapsing a graph to a custom node can create errors if there is a namespace conflict in types used in the generated input nodes.
Adds a new visitor to the shortQualifiedNameReplacer and uses it to replace names when creating custom node symbols when collapsing.
Will cherry pick this to 2.1 branch if no issues found.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@aparajit-pratap
FYIs
@smangarole