From 780f3cc80cadf87ecfdb702ef90fcb606f2783fd Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 16 Jul 2023 18:06:18 +0800 Subject: Fix the bug of forgetting to check cloned nodes. In the process of splitting, cloning, and planting the forest, I forgot to check whether some cloned node of the node inquestion satisfy the condition. This used to cause forests that violate some fundamental assumptions. Now this is supposed to be fixed, but more tests await us. --- chain/src/item/default/mod.rs | 50 +++++++++++++------------------------------ 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'chain/src/item/default/mod.rs') diff --git a/chain/src/item/default/mod.rs b/chain/src/item/default/mod.rs index 7b0a843..0781dd2 100644 --- a/chain/src/item/default/mod.rs +++ b/chain/src/item/default/mod.rs @@ -498,7 +498,7 @@ impl Forest for DefaultForest> { let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); - let f_node_label_packed = builder_query(builder.borrow(), node_label.label()); + let f_node_label_packed = builder_query(&builder, node_label.label()); if let Some((f_node, _f_label, f_packed)) = f_node_label_packed { match (node_label.is_packed(), f_packed) { @@ -512,8 +512,7 @@ impl Forest for DefaultForest> { .ok_or(Error::NodeNoLabel(child))? .label(); - if let Some((f_child, _, _)) = - builder_query(builder.borrow(), child_label) + if let Some((f_child, _, _)) = builder_query(&builder, child_label) { builder.add_edge(f_node, f_child, node_label)?; } else { @@ -524,12 +523,7 @@ impl Forest for DefaultForest> { builder.add_edge(f_node, f_child, node_label)?; } } - } else if !children_match_p( - builder.borrow(), - f_node, - fragment.borrow(), - node, - )? { + } else if !children_match_p(&builder, f_node, fragment.borrow(), node)? { let cloned = self.clone_node(f_node, 0, false)?; let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); @@ -540,8 +534,7 @@ impl Forest for DefaultForest> { .ok_or(Error::NodeNoLabel(child))? .label(); - if let Some((f_child, _, _)) = - builder_query(builder.borrow(), child_label) + if let Some((f_child, _, _)) = builder_query(&builder, child_label) { builder.add_edge(cloned, f_child, node_label)?; } else { @@ -568,8 +561,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = - builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(cloned, f_child, child_label)?; @@ -590,12 +582,8 @@ impl Forest for DefaultForest> { for cloned_child in fragment.children_of(node)? { let builder = PLGBuilderMut::from_graph_mut(&mut self.graph); - if !children_match_p( - builder.borrow(), - f_node, - fragment.borrow(), - cloned_child, - )? { + if !children_match_p(&builder, f_node, fragment.borrow(), cloned_child)? + { let cloned = self.clone_node(f_node, 0, false)?; let mut builder = PLGBuilderMut::from_graph_mut(&mut self.graph); @@ -605,8 +593,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = - builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(cloned, f_child, child_label)?; @@ -636,8 +623,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = - builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(f_node_clone, f_child, child_label)?; @@ -654,12 +640,7 @@ impl Forest for DefaultForest> { continue 'node_loop; } - if children_match_p( - builder.borrow(), - f_node_clone, - fragment.borrow(), - node, - )? { + if children_match_p(&builder, f_node_clone, fragment.borrow(), node)? { continue 'node_loop; } } @@ -679,7 +660,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(cloned, f_child, child_label)?; @@ -710,8 +691,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = - builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(f_node_clone, f_child, child_label)?; @@ -729,7 +709,7 @@ impl Forest for DefaultForest> { } if children_match_p( - builder.borrow(), + &builder, f_node_clone, fragment.borrow(), cloned_child, @@ -753,7 +733,7 @@ impl Forest for DefaultForest> { .vertex_label(child)? .ok_or(Error::NodeNoLabel(child))?; - let f_child = builder_query(builder.borrow(), child_label.label()); + let f_child = builder_query(&builder, child_label.label()); if let Some((f_child, _, _)) = f_child { builder.add_edge(cloned, f_child, child_label)?; @@ -785,7 +765,7 @@ impl Forest for DefaultForest> { .ok_or(Error::NodeNoLabel(child))? .label(); - let f_child_label_packed = builder_query(builder.borrow(), child_label_label); + let f_child_label_packed = builder_query(&builder, child_label_label); if let Some((f_child, _, _)) = f_child_label_packed { builder.add_edge(f_node, f_child, node_label)?; -- cgit v1.2.3-18-g5258