From 8486474f377faf2d800d79166a7abe6b975e3e50 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 2 Jun 2023 15:00:48 +0800 Subject: Fix a bug of duplication from planting after sploing I should have staged and committed these changes separately, but I am too lazy to deal with that. The main changes in this commit are that I added the derive macro that automates the delegation of the Graph trait. This saves a lot of boiler-plate codes. The second main change, perhaps the most important one, is that I found and tried to fix a bug that caused duplication of nodes. The bug arises from splitting or cloning a node multiple times, and immediately planting the same fragment under the new "sploned" node. That is, when we try to splone the node again, we found that we need to splone, because the node that was created by the same sploning process now has a different label because of the planting of the fragment. Then after the sploning, we plant the fragment again. This makes the newly sploned node have the same label (except for the clone index) and the same children as the node that was sploned and planted in the previous rounds. The fix is to check for the existence of a node that has the same set of children as the about-to-be-sploned node, except for the last one, which contains the about-to-be-planted fragment as a prefix. If that is the case, treat it as an already existing node, so that we do not have to splone the node again. This is consistent with the principle to not create what we do not need. --- graph_macro/tests/works.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'graph_macro/tests') diff --git a/graph_macro/tests/works.rs b/graph_macro/tests/works.rs index a57e866..dc0f75a 100644 --- a/graph_macro/tests/works.rs +++ b/graph_macro/tests/works.rs @@ -11,13 +11,17 @@ pub(crate) struct Haha { #[derive(Debug)] /// Testing docs -#[allow(unused)] +#[repr(C)] #[derive(Default, Graph)] +#[allow(unused)] pub struct HahaU(pub(crate) graph::ALGraph); #[derive(Debug, Graph)] pub struct HahaG { - graph: graph::DLGraph, + #[graph(haha)] + #[allow(unused)] + #[inline] + pub(crate) graph: graph::DLGraph, } impl Default for HahaG { -- cgit v1.2.3-18-g5258