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

Avoid namespace collisions when collapsing graph to custom node #9330

Merged
merged 9 commits into from
Jan 2, 2019

Conversation

mjkkirschner
Copy link
Member

@mjkkirschner mjkkirschner commented Dec 19, 2018

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

  • The code base is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning, and are documented in the API Changes document.

Reviewers

@aparajit-pratap

FYIs

@smangarole

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,
Copy link
Contributor

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?

Copy link
Member Author

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
@mjkkirschner mjkkirschner changed the title [WIP] Avoid namespace collisions when generating custom node [WIP] Avoid namespace collisions when collapsing graph to custom node Dec 20, 2018
@mjkkirschner
Copy link
Member Author

@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}");
}
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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.

Copy link
Member Author

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;
Copy link
Contributor

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;
Copy link
Contributor

@aparajit-pratap aparajit-pratap Dec 20, 2018

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;
}
Copy link
Contributor

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;
Copy link
Contributor

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,
...
}

Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: generate

@aparajit-pratap
Copy link
Contributor

@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 :)

@mjkkirschner
Copy link
Member Author

@aparajit-pratap I've moved the ShortQualifiedNameReplacer to it's own file but kept it in dynamo core because it was used by public methods in dynamoCore (ie ReplaceWithShorestQualifiedName) and I wanted to keep the underlying class internal.

I've added a few tests for shortNameReplacer that test the typedIdentifer visitor and some customNodeCollapse tests that use FFITarget to create conflicts.

I have yet to run all the tests on self serve CI.

@mjkkirschner mjkkirschner changed the title [WIP] Avoid namespace collisions when collapsing graph to custom node Avoid namespace collisions when collapsing graph to custom node Dec 22, 2018
@mjkkirschner mjkkirschner added PTAL Please Take A Look 👀 and removed WIP labels Dec 22, 2018
var inputs = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<Symbol>().ToList();
Assert.IsNotNull(inputs);

var pointParams = inputs;
Copy link
Contributor

Choose a reason for hiding this comment

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

where is pointParams used?


Assert.IsTrue(inputs.All(t =>
{
Console.WriteLine(t.InputSymbol);
Copy link
Contributor

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?

var inputs = CurrentDynamoModel.CurrentWorkspace.Nodes.OfType<Symbol>().ToList();
Assert.IsNotNull(inputs);

var pointParams = inputs;
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

@aparajit-pratap
Copy link
Contributor

@mjkkirschner excellent! Some minor comments and then LGTM!

@aparajit-pratap aparajit-pratap added the LGTM Looks good to me label Dec 22, 2018
@mjkkirschner mjkkirschner removed the PTAL Please Take A Look 👀 label Dec 31, 2018
# 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
@mjkkirschner mjkkirschner merged commit 74c856e into DynamoDS:master Jan 2, 2019
mjkkirschner added a commit to mjkkirschner/Dynamo that referenced this pull request Jan 3, 2019
…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
QilongTang pushed a commit that referenced this pull request Jan 3, 2019
… (#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM Looks good to me
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants