From 9e8bd96f25092b6e0fbbe00934df7c5a332e6096 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Mon, 17 Oct 2016 14:41:02 +0800 Subject: [PATCH 01/17] Add a property DeltaComputation to SyncTree --- src/DynamoCore/Engine/EngineController.cs | 11 +++++- src/Engine/ProtoScript/Runners/LiveRunner.cs | 40 +++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/DynamoCore/Engine/EngineController.cs b/src/DynamoCore/Engine/EngineController.cs index 30b6694b2a1..40e754bb75a 100644 --- a/src/DynamoCore/Engine/EngineController.cs +++ b/src/DynamoCore/Engine/EngineController.cs @@ -364,15 +364,22 @@ private bool VerifyGraphSyncData(IEnumerable nodes) nodes.Where(n => n.NeedsForceExecution) .Select(n => n.GUID)); + var codeBlockNodes = new HashSet( + nodes.Where(n => n is CodeBlockNodeModel).Select(n => n.GUID)); + if (reExecuteNodesIds.Any()) { for (int i = 0; i < graphSyncdata.ModifiedSubtrees.Count; ++i) { var st = graphSyncdata.ModifiedSubtrees[i]; - if (reExecuteNodesIds.Contains(st.GUID)) + var forceExecution = reExecuteNodesIds.Contains(st.GUID); + var isCodeBlockNode = codeBlockNodes.Contains(st.GUID); + + if (forceExecution || isCodeBlockNode) { Subtree newSt = new Subtree(st.AstNodes, st.GUID); - newSt.ForceExecution = true; + newSt.ForceExecution = forceExecution; + newSt.DeltaComputation = !isCodeBlockNode; graphSyncdata.ModifiedSubtrees[i] = newSt; } } diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index f769ab91d75..8fed94c6cdc 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -29,16 +29,40 @@ public enum EventStatus /// public struct Subtree { - public Guid GUID; + /// + /// The GUID of corresponding UI node. + /// + public Guid GUID + { + get; private set; + } + + /// + /// Specify if all ast nodes should be executed. + /// + public bool ForceExecution + { + get; set; + } + + /// + /// Sepcify if the VM should do delta computation for these ASTs + /// By default it is true. + /// + public bool DeltaComputation + { + get; set; + } + public List AstNodes; public List ModifiedAstNodes; - public bool ForceExecution; public Subtree(List astNodes, System.Guid guid) { GUID = guid; AstNodes = astNodes; ForceExecution = false; + DeltaComputation = true; ModifiedAstNodes = new List(); } @@ -789,14 +813,18 @@ private List GetModifiedNodes(Subtree subtree) { // Check if node exists in the prev AST list bool nodeFound = false; - foreach (AssociativeNode prevNode in st.AstNodes) + if (subtree.DeltaComputation) { - if (prevNode.Equals(node)) + foreach (AssociativeNode prevNode in st.AstNodes) { - nodeFound = true; - break; + if (prevNode.Equals(node)) + { + nodeFound = true; + break; + } } } + if (!nodeFound) { // At this point, the ast was determined to have been modified From 5f2d6facfb2498aa1fb382b84613deee006bc509 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Mon, 17 Oct 2016 15:01:05 +0800 Subject: [PATCH 02/17] Check code block node --- src/DynamoCore/Engine/EngineController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DynamoCore/Engine/EngineController.cs b/src/DynamoCore/Engine/EngineController.cs index 40e754bb75a..4521bbe9fcf 100644 --- a/src/DynamoCore/Engine/EngineController.cs +++ b/src/DynamoCore/Engine/EngineController.cs @@ -367,7 +367,7 @@ private bool VerifyGraphSyncData(IEnumerable nodes) var codeBlockNodes = new HashSet( nodes.Where(n => n is CodeBlockNodeModel).Select(n => n.GUID)); - if (reExecuteNodesIds.Any()) + if (reExecuteNodesIds.Any() || codeBlockNodes.Any()) { for (int i = 0; i < graphSyncdata.ModifiedSubtrees.Count; ++i) { From b6d84e6f1ff4d18602f1f20ccabeda6c0e42dd69 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Tue, 18 Oct 2016 14:00:53 +0800 Subject: [PATCH 03/17] Update recorded xml file --- test/core/recorded/CodeBlockNode_DefineDictionary.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/recorded/CodeBlockNode_DefineDictionary.xml b/test/core/recorded/CodeBlockNode_DefineDictionary.xml index f2763364e97..cc43b3293de 100644 --- a/test/core/recorded/CodeBlockNode_DefineDictionary.xml +++ b/test/core/recorded/CodeBlockNode_DefineDictionary.xml @@ -30,7 +30,7 @@ 00000000-0000-0000-0000-000000000000 - + 86107112-5c2d-43ae-9d7c-e2d756a80bf3 From 588b74fdbd0883727172ab132a210ca1f4fa3f2d Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Tue, 18 Oct 2016 15:18:07 +0800 Subject: [PATCH 04/17] Delete dead Enumeration --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 8fed94c6cdc..87f8e7ccca4 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -17,13 +17,6 @@ namespace ProtoScript.Runners { - public enum EventStatus - { - OK, - Error, - Warning - } - /// /// A subtree represents a node in graph. It contains a list of AST node. /// From 7406019dff3358dc9710e3c916b708a8d68c68c5 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 10:20:48 +0800 Subject: [PATCH 05/17] Refactor UpdatedCachedAstList() --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 177 ++++++++++--------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 87f8e7ccca4..9b7a385c105 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -432,63 +432,64 @@ public List EstimateNodesAffectedByASTList(List astList) private IEnumerable GetDeltaAstListDeleted(IEnumerable deletedSubTrees) { var deltaAstList = new List(); - csData.DeletedBinaryExprASTNodes = new List(); csData.DeletedFunctionDefASTNodes = new List(); - if (deletedSubTrees != null) + if (deletedSubTrees == null || !deletedSubTrees.Any()) { - foreach (var st in deletedSubTrees) - { - var deletedBinaryExpressions = new List(); + return deltaAstList; + } - if (st.AstNodes != null && st.AstNodes.Count > 0) - { - deletedBinaryExpressions.AddRange(st.AstNodes); - } - else + foreach (var st in deletedSubTrees) + { + var deletedBinaryExpressions = new List(); + + if (st.AstNodes != null && st.AstNodes.Any()) + { + deletedBinaryExpressions.AddRange(st.AstNodes); + } + else + { + // Handle the case where only the GUID of the deleted subtree was provided + // Get the cached subtree that is now being deleted + Subtree removeSubTree = new Subtree(); + if (currentSubTreeList.TryGetValue(st.GUID, out removeSubTree)) { - // Handle the case where only the GUID of the deleted subtree was provided - // Get the cached subtree that is now being deleted - Subtree removeSubTree = new Subtree(); - if (currentSubTreeList.TryGetValue(st.GUID, out removeSubTree)) + if (removeSubTree.AstNodes != null) { - if (removeSubTree.AstNodes != null) - { - deletedBinaryExpressions.AddRange(removeSubTree.AstNodes); - } + deletedBinaryExpressions.AddRange(removeSubTree.AstNodes); } } + } - // Cache removed function definitions - Subtree oldSubTree; - if (currentSubTreeList.TryGetValue(st.GUID, out oldSubTree)) + // Cache removed function definitions + Subtree oldSubTree; + if (currentSubTreeList.TryGetValue(st.GUID, out oldSubTree)) + { + if (oldSubTree.AstNodes != null) { - if (oldSubTree.AstNodes != null) - { - csData.DeletedFunctionDefASTNodes.AddRange(oldSubTree.AstNodes.Where(n => n is FunctionDefinitionNode)); - } - currentSubTreeList.Remove(st.GUID); + csData.DeletedFunctionDefASTNodes.AddRange(oldSubTree.AstNodes.Where(n => n is FunctionDefinitionNode)); } + currentSubTreeList.Remove(st.GUID); + } - // Build the nullify ASTs - var nullNodes = BuildNullAssignments(deletedBinaryExpressions); - foreach (AssociativeNode node in nullNodes) + // Build the nullify ASTs + var nullNodes = BuildNullAssignments(deletedBinaryExpressions); + foreach (AssociativeNode node in nullNodes) + { + var bnode = node as BinaryExpressionNode; + if (bnode != null) { - var bnode = node as BinaryExpressionNode; - if (bnode != null) - { - bnode.guid = st.GUID; - } + bnode.guid = st.GUID; } - deltaAstList.AddRange(nullNodes); - - core.BuildStatus.ClearWarningsForGraph(st.GUID); - - runtimeCore.RuntimeStatus.ClearWarningsForGraph(st.GUID); - csData.DeletedBinaryExprASTNodes.AddRange(deletedBinaryExpressions); } + deltaAstList.AddRange(nullNodes); + + core.BuildStatus.ClearWarningsForGraph(st.GUID); + runtimeCore.RuntimeStatus.ClearWarningsForGraph(st.GUID); + csData.DeletedBinaryExprASTNodes.AddRange(deletedBinaryExpressions); } + return deltaAstList; } @@ -577,30 +578,15 @@ private void SetNestedLanguageBlockASTGuids(Guid guid, List } } - public void UpdateCachedASTFromSubtrees(List modifiedSubTrees) - { - if (modifiedSubTrees != null) - { - for (int n = 0; n < modifiedSubTrees.Count(); ++n) - { - Subtree subtree = modifiedSubTrees[n]; - if (subtree.AstNodes == null) - { - continue; - } - - UpdateCachedASTList(subtree, subtree.ModifiedAstNodes); - } - } - } - /// /// Update the cached ASTs in the subtree given the modified ASTs /// /// /// - private void UpdateCachedASTList(Subtree st, List modifiedASTList) + private List UpdateCachedASTList(Subtree st, List modifiedASTList) { + List removedModifiedNodes = new List(); + // Disable removed nodes from the cache Subtree oldSubTree; bool cachedTreeExists = currentSubTreeList.TryGetValue(st.GUID, out oldSubTree); @@ -621,6 +607,17 @@ private void UpdateCachedASTList(Subtree st, List modifiedASTLi core.BuildStatus.ClearWarningsForAst(removedAST.ID); runtimeCore.RuntimeStatus.ClearWarningsForAst(removedAST.ID); } + + var nullNodes = BuildNullAssignments(csData.RemovedBinaryNodesFromModification); + foreach (AssociativeNode node in nullNodes) + { + var bnode = node as BinaryExpressionNode; + if (bnode != null) + { + bnode.guid = st.GUID; + } + } + removedModifiedNodes.AddRange(nullNodes); } // Cache the modifed functions @@ -676,6 +673,8 @@ private void UpdateCachedASTList(Subtree st, List modifiedASTLi currentSubTreeList[st.GUID] = st; } } + + return removedModifiedNodes; } @@ -701,9 +700,10 @@ private IEnumerable GetDeltaAstListModified(List modif } // Get modified statements - var modifiedASTList = GetModifiedNodes(modifiedSubTrees[n]); - modifiedSubTrees[n].ModifiedAstNodes.Clear(); - modifiedSubTrees[n].ModifiedAstNodes.AddRange(modifiedASTList); + var modifiedSubTree = modifiedSubTrees[n]; + var modifiedASTList = GetModifiedNodes(modifiedSubTree); + modifiedSubTree.ModifiedAstNodes.Clear(); + modifiedSubTree.ModifiedAstNodes.AddRange(modifiedASTList); deltaAstList.AddRange(modifiedASTList); foreach (AssociativeNode node in modifiedASTList) @@ -713,9 +713,12 @@ private IEnumerable GetDeltaAstListModified(List modif { bnode.guid = modifiedSubTrees[n].GUID; } - SetNestedLanguageBlockASTGuids(modifiedSubTrees[n].GUID, new List() { bnode }); + SetNestedLanguageBlockASTGuids(modifiedSubTree.GUID, new List() { bnode }); } + + deltaAstList.AddRange(UpdateCachedASTList(modifiedSubTree, modifiedSubTree.ModifiedAstNodes)); } + return deltaAstList; } @@ -723,11 +726,18 @@ private IEnumerable GetDeltaAstListModified(List modif public List GetDeltaASTList(GraphSyncData syncData) { csData = new ChangeSetData(); - List finalDeltaAstList = new List(); - finalDeltaAstList.AddRange(GetDeltaAstListDeleted(syncData.DeletedSubtrees)); - finalDeltaAstList.AddRange(GetDeltaAstListAdded(syncData.AddedSubtrees)); - finalDeltaAstList.AddRange(GetDeltaAstListModified(syncData.ModifiedSubtrees)); - csData.ContainsDeltaAST = finalDeltaAstList.Count > 0; + var finalDeltaAstList = new List(); + + var deletedDeltaAsts = GetDeltaAstListDeleted(syncData.DeletedSubtrees); + finalDeltaAstList.AddRange(deletedDeltaAsts); + + var addedDeltaAsts = GetDeltaAstListAdded(syncData.AddedSubtrees); + finalDeltaAstList.AddRange(addedDeltaAsts); + + var modifiedDeltaAsts = GetDeltaAstListModified(syncData.ModifiedSubtrees); + finalDeltaAstList.AddRange(modifiedDeltaAsts); + + csData.ContainsDeltaAST = finalDeltaAstList.Any(); return finalDeltaAstList; } @@ -938,21 +948,23 @@ private bool CompileToSSA(Guid guid, List astList, out List /// /// - private List BuildNullAssignments(List astList) + private List BuildNullAssignments(List astList) { - var astNodeList = new List(); - if (null != astList) + var astNodeList = new List(); + if (astList == null) + { + return astNodeList; + } + + foreach (var node in astList) { - foreach (var node in astList) + BinaryExpressionNode bNode = node as BinaryExpressionNode; + if (bNode != null) { - BinaryExpressionNode bNode = node as BinaryExpressionNode; - if (bNode != null) - { - BinaryExpressionNode newBNode = new BinaryExpressionNode(bNode.LeftNode, new NullNode(), ProtoCore.DSASM.Operator.assign); - astNodeList.Add(newBNode); - } + astNodeList.Add(AstFactory.BuildAssignment(bNode.LeftNode, AstFactory.BuildNullNode())); } } + return astNodeList; } } @@ -1021,16 +1033,6 @@ public IList SearchDirectories } } - /// - /// If the Interpreter mode is true, the LiveRunner takes in code - /// statements as input strings and not SyncData - /// - public bool InterpreterMode - { - get; - set; - } - public Configuration() { passThroughConfiguration = new Dictionary(); @@ -1436,7 +1438,6 @@ private void SynchronizeInternal(GraphSyncData syncData) // Get AST list that need to be executed var finalDeltaAstList = changeSetComputer.GetDeltaASTList(syncData); - changeSetComputer.UpdateCachedASTFromSubtrees(syncData.ModifiedSubtrees); // Prior to execution, apply state modifications to the VM given the delta AST's bool anyForcedExecutedNodes = changeSetComputer.csData.ForceExecuteASTList.Any(); From b5f87a4602a99d83125203ca9d183b0b2ddad0e0 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 13:48:46 +0800 Subject: [PATCH 06/17] Handle code block node non delta computation --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 119 +++++++++++-------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 9b7a385c105..43d514b350d 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -474,15 +474,7 @@ private IEnumerable GetDeltaAstListDeleted(IEnumerable } // Build the nullify ASTs - var nullNodes = BuildNullAssignments(deletedBinaryExpressions); - foreach (AssociativeNode node in nullNodes) - { - var bnode = node as BinaryExpressionNode; - if (bnode != null) - { - bnode.guid = st.GUID; - } - } + var nullNodes = BuildNullAssignments(deletedBinaryExpressions, st.GUID); deltaAstList.AddRange(nullNodes); core.BuildStatus.ClearWarningsForGraph(st.GUID); @@ -583,7 +575,7 @@ private void SetNestedLanguageBlockASTGuids(Guid guid, List /// /// /// - private List UpdateCachedASTList(Subtree st, List modifiedASTList) + private void UpdateCachedASTList(Subtree st, List modifiedASTList) { List removedModifiedNodes = new List(); @@ -607,17 +599,6 @@ private List UpdateCachedASTList(Subtree st, List UpdateCachedASTList(Subtree st, List GetDeltaAstListModified(List modif for (int n = 0; n < modifiedSubTrees.Count(); ++n) { - if (modifiedSubTrees[n].AstNodes == null) + var modifiedSubTree = modifiedSubTrees[n]; + + if (modifiedSubTree.AstNodes == null) { continue; } - // Get modified statements - var modifiedSubTree = modifiedSubTrees[n]; - var modifiedASTList = GetModifiedNodes(modifiedSubTree); - modifiedSubTree.ModifiedAstNodes.Clear(); - modifiedSubTree.ModifiedAstNodes.AddRange(modifiedASTList); - deltaAstList.AddRange(modifiedASTList); - - foreach (AssociativeNode node in modifiedASTList) + if (modifiedSubTree.DeltaComputation) { - var bnode = node as BinaryExpressionNode; - if (bnode != null) + // Get modified statements + var modifiedASTList = GetModifiedNodes(modifiedSubTree); + modifiedSubTree.ModifiedAstNodes.Clear(); + modifiedSubTree.ModifiedAstNodes.AddRange(modifiedASTList); + deltaAstList.AddRange(modifiedASTList); + + foreach (AssociativeNode node in modifiedASTList) { - bnode.guid = modifiedSubTrees[n].GUID; + var bnode = node as BinaryExpressionNode; + if (bnode != null) + { + bnode.guid = modifiedSubTrees[n].GUID; + } + SetNestedLanguageBlockASTGuids(modifiedSubTree.GUID, new List() { bnode }); } - SetNestedLanguageBlockASTGuids(modifiedSubTree.GUID, new List() { bnode }); + + UpdateCachedASTList(modifiedSubTree, modifiedSubTree.ModifiedAstNodes); } + else + { + // No delta computation. + Subtree oldSubTree; + List deletedExpressions = new List(); + if (currentSubTreeList.TryGetValue(modifiedSubTree.GUID, out oldSubTree) && oldSubTree.AstNodes != null) + { + csData.DeletedFunctionDefASTNodes.AddRange(oldSubTree.AstNodes.Where(f => f is FunctionDefinitionNode)); + deletedExpressions.AddRange(oldSubTree.AstNodes); + var nullNodes = BuildNullAssignments(deletedExpressions, modifiedSubTree.GUID); + deltaAstList.AddRange(nullNodes); + } + currentSubTreeList.Remove(modifiedSubTree.GUID); + + core.BuildStatus.ClearWarningsForGraph(modifiedSubTree.GUID); + runtimeCore.RuntimeStatus.ClearWarningsForGraph(modifiedSubTree.GUID); + csData.DeletedBinaryExprASTNodes.AddRange(deletedExpressions); + + currentSubTreeList.Add(modifiedSubTree.GUID, modifiedSubTree); + deltaAstList.AddRange(modifiedSubTree.AstNodes); + + foreach (AssociativeNode node in modifiedSubTree.AstNodes) + { + var bnode = node as BinaryExpressionNode; + if (bnode != null) + { + bnode.guid = modifiedSubTree.GUID; + } + + SetNestedLanguageBlockASTGuids(modifiedSubTree.GUID, new List() { bnode }); + } - deltaAstList.AddRange(UpdateCachedASTList(modifiedSubTree, modifiedSubTree.ModifiedAstNodes)); + var modifiedFunctions = modifiedSubTree.AstNodes.Where(f => f is FunctionDefinitionNode); + csData.ModifiedFunctions.AddRange(modifiedFunctions); + } } return deltaAstList; @@ -816,15 +834,12 @@ private List GetModifiedNodes(Subtree subtree) { // Check if node exists in the prev AST list bool nodeFound = false; - if (subtree.DeltaComputation) + foreach (AssociativeNode prevNode in st.AstNodes) { - foreach (AssociativeNode prevNode in st.AstNodes) + if (prevNode.Equals(node)) { - if (prevNode.Equals(node)) - { - nodeFound = true; - break; - } + nodeFound = true; + break; } } @@ -948,7 +963,7 @@ private bool CompileToSSA(Guid guid, List astList, out List /// /// - private List BuildNullAssignments(List astList) + private List BuildNullAssignments(List astList, Guid guid) { var astNodeList = new List(); if (astList == null) @@ -959,10 +974,20 @@ private List BuildNullAssignments(List as foreach (var node in astList) { BinaryExpressionNode bNode = node as BinaryExpressionNode; - if (bNode != null) + if (bNode == null) { - astNodeList.Add(AstFactory.BuildAssignment(bNode.LeftNode, AstFactory.BuildNullNode())); + continue; + } + + IdentifierNode leftNode = bNode.LeftNode as IdentifierNode; + if (leftNode == null || leftNode.ArrayDimensions != null) + { + continue; } + + var nullAssignment = AstFactory.BuildAssignment(leftNode, AstFactory.BuildNullNode()); + nullAssignment.guid = guid; + astNodeList.Add(nullAssignment); } return astNodeList; From 363dc3bd2d07dfbdb68393f599af08df33be2663 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 14:24:49 +0800 Subject: [PATCH 07/17] Move deleted function to RemovedFunctionDefNodesFromModification list --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 43d514b350d..5c3e488dd5f 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -707,7 +707,7 @@ private IEnumerable GetDeltaAstListModified(List modif List deletedExpressions = new List(); if (currentSubTreeList.TryGetValue(modifiedSubTree.GUID, out oldSubTree) && oldSubTree.AstNodes != null) { - csData.DeletedFunctionDefASTNodes.AddRange(oldSubTree.AstNodes.Where(f => f is FunctionDefinitionNode)); + csData.RemovedFunctionDefNodesFromModification.AddRange(oldSubTree.AstNodes.Where(f => f is FunctionDefinitionNode)); deletedExpressions.AddRange(oldSubTree.AstNodes); var nullNodes = BuildNullAssignments(deletedExpressions, modifiedSubTree.GUID); deltaAstList.AddRange(nullNodes); From da8fe44bff63055ee0aeffab760f60b9cdfa30d0 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 15:05:37 +0800 Subject: [PATCH 08/17] Mark graph node as dirty if references deleted function --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 5c3e488dd5f..381c01986c7 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -226,6 +226,7 @@ private void ApplyChangeSetDeleted(ChangeSetData changeSet) { DeactivateGraphnodes(changeSet.DeletedBinaryExprASTNodes); UndefineFunctions(changeSet.DeletedFunctionDefASTNodes); + ProtoCore.AssociativeEngine.Utils.MarkGraphNodesDirtyFromFunctionRedef(runtimeCore, changeSet.DeletedFunctionDefASTNodes); } private void ApplyChangeSetModified(ChangeSetData changeSet) From c9fdcd2e111cd5717ad016245384e9c6b4d758b1 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 17:05:41 +0800 Subject: [PATCH 09/17] Explicity assign to a variable to get the value of property --- test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs index 9e6683a60e4..78c23012f9b 100644 --- a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs +++ b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs @@ -5505,10 +5505,10 @@ public void RegressMAGN5353() deleted.Add(subtree); var guid3 = Guid.NewGuid(); - var code3 = "__GC();"; + var code3 = "__GC();z = DisposeTracer.DisposeCount;"; syncData = new GraphSyncData(deleted, new List { ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid3, code3)}, null); liveRunner.UpdateGraph(syncData); - AssertValue("y", 1); + AssertValue("z", 1); } [Test] From 20bdc480a1b67a24629adea123c7b0a055bcd72b Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Wed, 19 Oct 2016 17:27:16 +0800 Subject: [PATCH 10/17] Handle multiple assignment expression --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 381c01986c7..1f5b2b63e0f 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -972,9 +972,10 @@ private List BuildNullAssignments(List as return astNodeList; } - foreach (var node in astList) + Stack workingStack = new Stack(astList); + while (workingStack.Any()) { - BinaryExpressionNode bNode = node as BinaryExpressionNode; + var bNode = workingStack.Pop() as BinaryExpressionNode; if (bNode == null) { continue; @@ -989,6 +990,11 @@ private List BuildNullAssignments(List as var nullAssignment = AstFactory.BuildAssignment(leftNode, AstFactory.BuildNullNode()); nullAssignment.guid = guid; astNodeList.Add(nullAssignment); + + if (bNode.RightNode is BinaryExpressionNode) + { + workingStack.Push(bNode.RightNode); + } } return astNodeList; From bcb0d16bf1a7c10428df2c67b02cd13bd67f894c Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 10:02:41 +0800 Subject: [PATCH 11/17] Remove dead property from BinaryExpressionNode --- src/Engine/ProtoCore/Parser/AssociativeAST.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Engine/ProtoCore/Parser/AssociativeAST.cs b/src/Engine/ProtoCore/Parser/AssociativeAST.cs index f4e69f82b44..f579f42f9c1 100644 --- a/src/Engine/ProtoCore/Parser/AssociativeAST.cs +++ b/src/Engine/ProtoCore/Parser/AssociativeAST.cs @@ -2076,11 +2076,6 @@ public class BinaryExpressionNode : AssociativeNode public bool isSSAPointerAssignment { get; set; } public bool IsFirstIdentListNode { get; set; } - // These properties are used only for the GraphUI ProtoAST - public uint Guid { get; set; } - //private uint splitFromUID = 0; - //public uint SplitFromUID { get { return splitFromUID; } set { splitFromUID = value; } } - public BinaryExpressionNode(AssociativeNode left = null, AssociativeNode right = null, Operator optr = Operator.none) { isSSAAssignment = false; From b7b107375f9a47b9230a3c49b3eef2351788d924 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 10:47:48 +0800 Subject: [PATCH 12/17] Remove TEstCodeBlockDeleteLine01 from Failure category --- test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs | 1 - test/Engine/ProtoTestFx/TestFrameWork.cs | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs index 78c23012f9b..31276178802 100644 --- a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs +++ b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs @@ -2982,7 +2982,6 @@ public void TestCodeblockModification16() } [Test] - [Category("Failure")] public void TestCodeBlockDeleteLine01() { // Tracked in: http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-4159 diff --git a/test/Engine/ProtoTestFx/TestFrameWork.cs b/test/Engine/ProtoTestFx/TestFrameWork.cs index 46f9d303395..78d1655b293 100644 --- a/test/Engine/ProtoTestFx/TestFrameWork.cs +++ b/test/Engine/ProtoTestFx/TestFrameWork.cs @@ -892,6 +892,7 @@ public static Subtree CreateSubTreeFromCode(Guid guid, string code) { var cbn = ProtoCore.Utils.ParserUtils.Parse(code); var subtree = null == cbn ? new Subtree(null, guid) : new Subtree(cbn.Body, guid); + subtree.DeltaComputation = false; return subtree; } From 4f65c7c3bc2fdba957929f5ab070a82eb662d3f5 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 13:02:16 +0800 Subject: [PATCH 13/17] Handle multiple assginment --- src/Engine/ProtoAssociative/CodeGen.cs | 1 + src/Engine/ProtoScript/Runners/LiveRunner.cs | 31 +++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Engine/ProtoAssociative/CodeGen.cs b/src/Engine/ProtoAssociative/CodeGen.cs index d98b25744be..c54b679300e 100644 --- a/src/Engine/ProtoAssociative/CodeGen.cs +++ b/src/Engine/ProtoAssociative/CodeGen.cs @@ -1961,6 +1961,7 @@ private AssociativeNode DFSEmitSplitAssign_AST(AssociativeNode node, ref List nodeList) return; } - foreach (var node in nodeList) + var workingStack = new Stack(nodeList); + var astIDs = new HashSet(); + + while (workingStack.Any()) { - BinaryExpressionNode bNode = node as BinaryExpressionNode; - if (bNode != null) + var node = workingStack.Pop() as BinaryExpressionNode; + if (node != null) { - foreach (var gnode in core.DSExecutable.instrStreamList[0].dependencyGraph.GraphList) - { - if (gnode.OriginalAstID == bNode.OriginalAstID) - { - gnode.isActive = false; - } - } + astIDs.Add(node.OriginalAstID); + workingStack.Push(node.RightNode); + } + } + + if (!astIDs.Any()) + { + return; + } + + foreach (var gnode in core.DSExecutable.instrStreamList[0].dependencyGraph.GraphList) + { + if (astIDs.Contains(gnode.OriginalAstID)) + { + gnode.isActive = false; } } } From 68639336248f3697960f29cf4a70acbca9a40045 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 13:02:44 +0800 Subject: [PATCH 14/17] Update test cases --- .../LiveRunnerTests/ChangeSetComputerTests.cs | 4 ++-- .../ProtoTest/LiveRunnerTests/MicroFeatureTests.cs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs b/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs index 4246f0d3340..01ba091c492 100644 --- a/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs +++ b/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs @@ -217,7 +217,7 @@ public void TestModified01() // The list must be in the order that it is expected List expectedCode = new List() { - "b = 1;" + "a = null; b = 1;" }; List expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode); @@ -262,7 +262,7 @@ public void TestModified02() // The list must be in the order that it is expected List expectedCode = new List() { - "c = 1;" + "b = null; c = null; c = 1;" }; List expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode); diff --git a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs index 31276178802..babcb17a541 100644 --- a/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs +++ b/test/Engine/ProtoTest/LiveRunnerTests/MicroFeatureTests.cs @@ -5209,13 +5209,13 @@ public void TestNestedLanguageBlockReExecution11() @" a = [Imperative] { - return = 10; + return = 20; } b = [Imperative] { - return = 20; + return = 30; } @@ -5226,7 +5226,7 @@ public void TestNestedLanguageBlockReExecution11() { e = 40; } - return = 50; + return = 60; } ", @@ -5246,12 +5246,18 @@ public void TestNestedLanguageBlockReExecution11() List modified = new List(); Subtree subtree = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, codes[1]); modified.Add(subtree); + syncData = new GraphSyncData(null, null, modified); + liveRunner.UpdateGraph(syncData); + AssertValue("a", 20); + AssertValue("b", 30); + AssertValue("c", 60); + AssertValue("f", null); // Create a new CBN to add the removed line Guid guid2 = System.Guid.NewGuid(); added = new List(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid2, codes[2])); - syncData = new GraphSyncData(null, added, modified); + syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); AssertValue("f", 60); From ffe85db72f80743527c760b649d354a8b06c883f Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 13:06:22 +0800 Subject: [PATCH 15/17] Update expected result --- test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs b/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs index 01ba091c492..36ef34ef5d8 100644 --- a/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs +++ b/test/Engine/ProtoTest/LiveRunnerTests/ChangeSetComputerTests.cs @@ -262,7 +262,7 @@ public void TestModified02() // The list must be in the order that it is expected List expectedCode = new List() { - "b = null; c = null; c = 1;" + "b = null; a = null; c = 1;" }; List expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode); From 6554972c3396ad5607945259cf8b9235a0e65d7a Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 13:57:50 +0800 Subject: [PATCH 16/17] Cleanup and comment --- src/Engine/ProtoScript/Runners/LiveRunner.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Engine/ProtoScript/Runners/LiveRunner.cs b/src/Engine/ProtoScript/Runners/LiveRunner.cs index 24c6f20a3ab..d001f55fffa 100644 --- a/src/Engine/ProtoScript/Runners/LiveRunner.cs +++ b/src/Engine/ProtoScript/Runners/LiveRunner.cs @@ -714,7 +714,10 @@ private IEnumerable GetDeltaAstListModified(List modif } else { - // No delta computation. + // No delta computation. + // Right now it is only disabled for code block node, but we may + // completely disable it. Details about why doing so: + // https://github.com/DynamoDS/Dynamo/pull/7282 Subtree oldSubTree; List deletedExpressions = new List(); if (currentSubTreeList.TryGetValue(modifiedSubTree.GUID, out oldSubTree) && oldSubTree.AstNodes != null) From 3a17b6bbd6f6ca50a5e34fe82c7055c59bf95da2 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Thu, 20 Oct 2016 14:19:43 +0800 Subject: [PATCH 17/17] Add test cases for self modification in code block node --- test/DynamoCoreTests/DSEvaluationModelTest.cs | 10 +++++++++ test/core/dsevaluation/MAGN-9507.dyn | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/core/dsevaluation/MAGN-9507.dyn diff --git a/test/DynamoCoreTests/DSEvaluationModelTest.cs b/test/DynamoCoreTests/DSEvaluationModelTest.cs index 791a9e8f577..2241dd86c35 100644 --- a/test/DynamoCoreTests/DSEvaluationModelTest.cs +++ b/test/DynamoCoreTests/DSEvaluationModelTest.cs @@ -1107,6 +1107,16 @@ public void TestDictionaryDefinition2() AssertPreviewValue("e7bf0921-cf77-4f37-8336-8aa9c56b22a6", new object[] { "qux" }); AssertPreviewValue("756497b4-4f7a-4ae3-9e5c-de5f69762d16", new object[] { 1024 }); } + + [Test] + public void TestMAGN9507() + { + // x = {1, 2, 3}; + // x = Count(x); + var dynFilePath = Path.Combine(TestDirectory, @"core\dsevaluation\MAGN-9507.dyn"); + OpenModel(dynFilePath); + AssertPreviewValue("3bf992eb-ecc9-4fcc-a90b-9b1ee7e925e9", 3); + } } [Category("DSCustomNode")] diff --git a/test/core/dsevaluation/MAGN-9507.dyn b/test/core/dsevaluation/MAGN-9507.dyn new file mode 100644 index 00000000000..8f23ab598b4 --- /dev/null +++ b/test/core/dsevaluation/MAGN-9507.dyn @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file