]> Repositorios git - scryer-prolog.git/commitdiff
restore free list usage on structures in facts without crashing lgtunit loader
authorMark Thom <[email protected]>
Sat, 14 Jan 2023 01:34:29 +0000 (18:34 -0700)
committerMark Thom <[email protected]>
Sat, 14 Jan 2023 01:35:13 +0000 (18:35 -0700)
src/codegen.rs
src/debray_allocator.rs

index 79574005318e829024a6abe35dd03879c2189ff2..31219e1aefbc339a251913c95a5876aef1710bcf 100644 (file)
@@ -243,14 +243,22 @@ fn trim_structure_by_last_arg(instr: &mut Instruction, last_arg: &Term) {
 }
 
 trait AddToFreeList<'a, Target: CompilationTarget<'a>> {
+    fn add_term_to_free_list(&mut self, r: RegType);
     fn add_subterm_to_free_list(&mut self, term: &Term);
 }
 
 impl<'a, 'b> AddToFreeList<'a, FactInstruction> for CodeGenerator<'b> {
+    fn add_term_to_free_list(&mut self, r: RegType) {
+        self.marker.add_to_free_list(r);
+    }
+
     fn add_subterm_to_free_list(&mut self, _term: &Term) {}
 }
 
 impl<'a, 'b> AddToFreeList<'a, QueryInstruction> for CodeGenerator<'b> {
+    #[inline(always)]
+    fn add_term_to_free_list(&mut self, _r: RegType) {}
+
     #[inline(always)]
     fn add_subterm_to_free_list(&mut self, term: &Term) {
         if let Some(cell) = structure_cell(term) {
@@ -374,6 +382,8 @@ impl<'b> CodeGenerator<'b> {
                     self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
                     target.push(Target::to_structure(name, terms.len(), cell.get()));
 
+                    <CodeGenerator<'b> as AddToFreeList<'a, Target>>::add_term_to_free_list(self, cell.get());
+
                     if let Some(instr) = target.last_mut() {
                         if let Some(term) = terms.last() {
                             trim_structure_by_last_arg(instr, term);
@@ -392,6 +402,8 @@ impl<'b> CodeGenerator<'b> {
                     self.marker.mark_non_var::<Target>(lvl, term_loc, cell, &mut target);
                     target.push(Target::to_list(lvl, cell.get()));
 
+                    <CodeGenerator<'b> as AddToFreeList<'a, Target>>::add_term_to_free_list(self, cell.get());
+
                     self.subterm_to_instr::<Target>(head, term_loc, &mut target);
                     self.subterm_to_instr::<Target>(tail, term_loc, &mut target);
 
@@ -965,6 +977,8 @@ impl<'b> CodeGenerator<'b> {
             return Err(CompilationError::ExceededMaxArity);
         }
 
+        self.marker.reset_free_list();
+
         let mut unsafe_var_marker = UnsafeVarMarker::new();
 
         if !fact.is_empty() {
index 51ac8f70a5328714ada6501dfe7444b6c04c5fff..e9cc73c7293a11c2e7d0fccc96fd65a96083602c 100644 (file)
@@ -218,6 +218,10 @@ impl DebrayAllocator {
             self.free_list.push(r);
         }
     }
+
+    pub fn reset_free_list(&mut self) {
+        self.free_list.clear();
+    }
 }
 
 impl Allocator for DebrayAllocator {