From aa31ebe381d555725cdae2abafa93bac976f1c7e Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sat, 17 Jan 2026 00:12:45 +1300 Subject: Recurse fixed, caching functions consolidated --- src/kompsos-collector.adb | 52 +++++++++++++++++------------------------------ src/kompsos-collector.ads | 1 + 2 files changed, 20 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/kompsos-collector.adb b/src/kompsos-collector.adb index 792c2b2..e8314ff 100644 --- a/src/kompsos-collector.adb +++ b/src/kompsos-collector.adb @@ -381,6 +381,11 @@ package body Kompsos.Collector is when Recurse_Node => if not Book.Contains (Ptr) then Book.Insert (Ptr, (Kind => Recurse_Data, others => <>)); + if Ptr.Rec_Goal.Actual = null then + Book (Ptr).Rec_Gone := True; + elsif not Cache_Memo.Contains (Ptr.Rec_Goal.Actual) then + Cache_Memo.Insert (Ptr.Rec_Goal.Actual, State_Vectors.Empty_Vector); + end if; end if; if Book (Ptr).Rec_Gone then return False; @@ -396,44 +401,18 @@ package body Kompsos.Collector is return False; else Book (Ptr).Rec_Next := 1; + Book (Ptr).Rec_Cache := False; end if; end loop; + if Book (Ptr).Rec_Cache and Ptr.Rec_Goal.Actual.Counter = 1 then + Cache_Memo (Ptr.Rec_Goal.Actual).Append (Result); + end if; Book (Ptr).Rec_Next := Book.Element (Ptr).Rec_Next + 1; return True; end case; end Do_Get_Next; - function Cached - (Ptr : in Goal_Component_Access; - Index : in Long_Positive; - Result : out State) - return Boolean is - begin - if Cache_Memo.Contains (Ptr) and then Index <= Cache_Memo (Ptr).Last_Index then - Result := Cache_Memo (Ptr) (Index); - return True; - else - return False; - end if; - end Cached; - - - procedure Cache_This - (Ptr : in Goal_Component_Access; - Index : in Long_Positive; - Result : in State) is - begin - if Ptr.Counter > 1 and Ptr.Kind /= Static_Node then - if not Cache_Memo.Contains (Ptr) then - Cache_Memo.Insert (Ptr, State_Vectors.Empty_Vector); - end if; - pragma Assert (Index = Cache_Memo (Ptr).Last_Index + 1); - Cache_Memo (Ptr).Append (Result); - end if; - end Cache_This; - - function Get_Next (Ptr : in Constant_Goal_Access; Base : in State; @@ -443,12 +422,19 @@ package body Kompsos.Collector is begin if Ptr = null or else Ptr.Actual = null then return False; - elsif Cached (Ptr.Actual, Index, Result) then + elsif Cache_Memo.Contains (Ptr.Actual) and then + Index <= Cache_Memo (Ptr.Actual).Last_Index + then + Result := Cache_Memo (Ptr.Actual) (Index); return True; else return Found : constant Boolean := Do_Get_Next (Ptr.Actual, Base, Index, Result) do - if Found then - Cache_This (Ptr.Actual, Index, Result); + if Found and Ptr.Actual.Counter > 1 and Ptr.Actual.Kind /= Static_Node then + if not Cache_Memo.Contains (Ptr.Actual) then + Cache_Memo.Insert (Ptr.Actual, State_Vectors.Empty_Vector); + end if; + pragma Assert (Index = Cache_Memo (Ptr.Actual).Last_Index + 1); + Cache_Memo (Ptr.Actual).Append (Result); end if; end return; end if; diff --git a/src/kompsos-collector.ads b/src/kompsos-collector.ads index 2b175a1..cbe8dd7 100644 --- a/src/kompsos-collector.ads +++ b/src/kompsos-collector.ads @@ -69,6 +69,7 @@ private when Recurse_Data => Rec_Next : Long_Positive := 1; Rec_Gone : Boolean := False; + Rec_Cache : Boolean := True; end case; end record; -- cgit