From 26a39302058b77664caba856c35c37cd40fae48a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 5 Apr 2026 23:53:02 -0400 Subject: [PATCH] refactor: + narrower interface for gc pointer forwarding add AGCObjectVisitor, instead of requiring ACollector. --- include/xo/type/DArrayType.hpp | 4 +++- include/xo/type/DAtomicType.hpp | 4 +++- include/xo/type/DFunctionType.hpp | 6 ++++-- include/xo/type/DListType.hpp | 4 +++- include/xo/type/array/IGCObject_DArrayType.hpp | 7 +++++-- .../xo/type/atomic/IGCObject_DAtomicType.hpp | 7 +++++-- .../type/function/IGCObject_DFunctionType.hpp | 7 +++++-- include/xo/type/list/IGCObject_DListType.hpp | 7 +++++-- include/xo/type/typevar/DTypeVarRef.hpp | 3 ++- .../xo/type/typevar/IGCObject_DTypeVarRef.hpp | 7 +++++-- src/type/DArrayType.cpp | 15 +++++++-------- src/type/DAtomicType.cpp | 6 +++--- src/type/DFunctionType.cpp | 17 ++++++++--------- src/type/DListType.cpp | 15 +++++++-------- src/type/DTypeVarRef.cpp | 7 +++---- src/type/IGCObject_DArrayType.cpp | 4 ++-- src/type/IGCObject_DAtomicType.cpp | 4 ++-- src/type/IGCObject_DFunctionType.cpp | 4 ++-- src/type/IGCObject_DListType.cpp | 4 ++-- src/type/IGCObject_DTypeVarRef.cpp | 4 ++-- 20 files changed, 78 insertions(+), 58 deletions(-) diff --git a/include/xo/type/DArrayType.hpp b/include/xo/type/DArrayType.hpp index db827e8..92a9eca 100644 --- a/include/xo/type/DArrayType.hpp +++ b/include/xo/type/DArrayType.hpp @@ -9,6 +9,7 @@ #include "Metatype.hpp" #include #include +#include namespace xo { namespace scm { @@ -19,6 +20,7 @@ namespace xo { class DArrayType { public: using ACollector = xo::mm::ACollector; + using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; @@ -43,7 +45,7 @@ namespace xo { ///@{ std::size_t shallow_size() const noexcept; DArrayType * shallow_move(obj gc) noexcept; - std::size_t forward_children(obj gc) noexcept; + void visit_gco_children(obj gc) noexcept; ///@} private: diff --git a/include/xo/type/DAtomicType.hpp b/include/xo/type/DAtomicType.hpp index b9daf76..3274b88 100644 --- a/include/xo/type/DAtomicType.hpp +++ b/include/xo/type/DAtomicType.hpp @@ -8,6 +8,7 @@ #include "Type.hpp" #include "Metatype.hpp" #include +#include #include namespace xo { @@ -22,6 +23,7 @@ namespace xo { class DAtomicType { public: using ACollector = xo::mm::ACollector; + using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; @@ -44,7 +46,7 @@ namespace xo { ///@{ std::size_t shallow_size() const noexcept; DAtomicType * shallow_move(obj gc) noexcept; - std::size_t forward_children(obj gc) noexcept; + void visit_gco_children(obj gc) noexcept; ///@} private: diff --git a/include/xo/type/DFunctionType.hpp b/include/xo/type/DFunctionType.hpp index 5fbb93a..66b92c1 100644 --- a/include/xo/type/DFunctionType.hpp +++ b/include/xo/type/DFunctionType.hpp @@ -9,6 +9,7 @@ #include "Metatype.hpp" #include #include +#include #include namespace xo { @@ -20,8 +21,9 @@ namespace xo { class DFunctionType { public: using ACollector = xo::mm::ACollector; - using AAllocator = xo::mm::AAllocator; using AGCObject = xo::mm::AGCObject; + using AGCObjectVisitor = xo::mm::AGCObjectVisitor; + using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; public: @@ -65,7 +67,7 @@ namespace xo { ///@{ std::size_t shallow_size() const noexcept; DFunctionType * shallow_move(obj gc) noexcept; - std::size_t forward_children(obj gc) noexcept; + void visit_gco_children(obj gc) noexcept; ///@} private: diff --git a/include/xo/type/DListType.hpp b/include/xo/type/DListType.hpp index b2fd196..c6fa030 100644 --- a/include/xo/type/DListType.hpp +++ b/include/xo/type/DListType.hpp @@ -9,6 +9,7 @@ #include "Metatype.hpp" #include #include +#include #include namespace xo { @@ -24,6 +25,7 @@ namespace xo { public: using TypeDescr = xo::reflect::TypeDescr; using ACollector = xo::mm::ACollector; + using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AAllocator = xo::mm::AAllocator; public: @@ -51,7 +53,7 @@ namespace xo { ///@{ std::size_t shallow_size() const noexcept; DListType * shallow_move(obj gc) noexcept; - std::size_t forward_children(obj gc) noexcept; + void visit_gco_children(obj gc) noexcept; ///@} private: diff --git a/include/xo/type/array/IGCObject_DArrayType.hpp b/include/xo/type/array/IGCObject_DArrayType.hpp index fe1e8b1..8e6b92d 100644 --- a/include/xo/type/array/IGCObject_DArrayType.hpp +++ b/include/xo/type/array/IGCObject_DArrayType.hpp @@ -42,6 +42,7 @@ namespace xo { using size_type = xo::mm::AGCObject::size_type; using AAllocator = xo::mm::AGCObject::AAllocator; using ACollector = xo::mm::AGCObject::ACollector; + using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor; using Copaque = xo::mm::AGCObject::Copaque; using Opaque = xo::mm::AGCObject::Opaque; ///@} @@ -52,8 +53,10 @@ namespace xo { // non-const methods /** move instance using allocator **/ static Opaque shallow_move(DArrayType & self, obj gc) noexcept; - /** during GC: forward immdiate children **/ - static void forward_children(DArrayType & self, obj gc) noexcept; + /** Invoke fn.visit_child(iface,data) for each child GCObject pointer. +Context: provides address of data pointer so it can be updated in place +when @p fn invokes garbage collector reentry point **/ + static void visit_gco_children(DArrayType & self, obj fn) noexcept; ///@} }; diff --git a/include/xo/type/atomic/IGCObject_DAtomicType.hpp b/include/xo/type/atomic/IGCObject_DAtomicType.hpp index 844c21c..88f607d 100644 --- a/include/xo/type/atomic/IGCObject_DAtomicType.hpp +++ b/include/xo/type/atomic/IGCObject_DAtomicType.hpp @@ -42,6 +42,7 @@ namespace xo { using size_type = xo::mm::AGCObject::size_type; using AAllocator = xo::mm::AGCObject::AAllocator; using ACollector = xo::mm::AGCObject::ACollector; + using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor; using Copaque = xo::mm::AGCObject::Copaque; using Opaque = xo::mm::AGCObject::Opaque; ///@} @@ -52,8 +53,10 @@ namespace xo { // non-const methods /** move instance using allocator **/ static Opaque shallow_move(DAtomicType & self, obj gc) noexcept; - /** during GC: forward immdiate children **/ - static void forward_children(DAtomicType & self, obj gc) noexcept; + /** Invoke fn.visit_child(iface,data) for each child GCObject pointer. +Context: provides address of data pointer so it can be updated in place +when @p fn invokes garbage collector reentry point **/ + static void visit_gco_children(DAtomicType & self, obj fn) noexcept; ///@} }; diff --git a/include/xo/type/function/IGCObject_DFunctionType.hpp b/include/xo/type/function/IGCObject_DFunctionType.hpp index 19c9b7d..2e027c3 100644 --- a/include/xo/type/function/IGCObject_DFunctionType.hpp +++ b/include/xo/type/function/IGCObject_DFunctionType.hpp @@ -42,6 +42,7 @@ namespace xo { using size_type = xo::mm::AGCObject::size_type; using AAllocator = xo::mm::AGCObject::AAllocator; using ACollector = xo::mm::AGCObject::ACollector; + using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor; using Copaque = xo::mm::AGCObject::Copaque; using Opaque = xo::mm::AGCObject::Opaque; ///@} @@ -52,8 +53,10 @@ namespace xo { // non-const methods /** move instance using allocator **/ static Opaque shallow_move(DFunctionType & self, obj gc) noexcept; - /** during GC: forward immdiate children **/ - static void forward_children(DFunctionType & self, obj gc) noexcept; + /** Invoke fn.visit_child(iface,data) for each child GCObject pointer. +Context: provides address of data pointer so it can be updated in place +when @p fn invokes garbage collector reentry point **/ + static void visit_gco_children(DFunctionType & self, obj fn) noexcept; ///@} }; diff --git a/include/xo/type/list/IGCObject_DListType.hpp b/include/xo/type/list/IGCObject_DListType.hpp index 1945027..bda54e7 100644 --- a/include/xo/type/list/IGCObject_DListType.hpp +++ b/include/xo/type/list/IGCObject_DListType.hpp @@ -42,6 +42,7 @@ namespace xo { using size_type = xo::mm::AGCObject::size_type; using AAllocator = xo::mm::AGCObject::AAllocator; using ACollector = xo::mm::AGCObject::ACollector; + using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor; using Copaque = xo::mm::AGCObject::Copaque; using Opaque = xo::mm::AGCObject::Opaque; ///@} @@ -52,8 +53,10 @@ namespace xo { // non-const methods /** move instance using allocator **/ static Opaque shallow_move(DListType & self, obj gc) noexcept; - /** during GC: forward immdiate children **/ - static void forward_children(DListType & self, obj gc) noexcept; + /** Invoke fn.visit_child(iface,data) for each child GCObject pointer. +Context: provides address of data pointer so it can be updated in place +when @p fn invokes garbage collector reentry point **/ + static void visit_gco_children(DListType & self, obj fn) noexcept; ///@} }; diff --git a/include/xo/type/typevar/DTypeVarRef.hpp b/include/xo/type/typevar/DTypeVarRef.hpp index f59f3f7..9e1d6b9 100644 --- a/include/xo/type/typevar/DTypeVarRef.hpp +++ b/include/xo/type/typevar/DTypeVarRef.hpp @@ -23,6 +23,7 @@ namespace xo { class DTypeVarRef { public: using ACollector = xo::mm::ACollector; + using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AAllocator = xo::mm::AAllocator; using TypeDescr = xo::reflect::TypeDescr; @@ -55,7 +56,7 @@ namespace xo { ///@{ std::size_t shallow_size() const noexcept; DTypeVarRef * shallow_move(obj gc) noexcept; - std::size_t forward_children(obj gc) noexcept; + void visit_gco_children(obj gc) noexcept; ///@} private: diff --git a/include/xo/type/typevar/IGCObject_DTypeVarRef.hpp b/include/xo/type/typevar/IGCObject_DTypeVarRef.hpp index caf3566..72261cb 100644 --- a/include/xo/type/typevar/IGCObject_DTypeVarRef.hpp +++ b/include/xo/type/typevar/IGCObject_DTypeVarRef.hpp @@ -42,6 +42,7 @@ namespace xo { using size_type = xo::mm::AGCObject::size_type; using AAllocator = xo::mm::AGCObject::AAllocator; using ACollector = xo::mm::AGCObject::ACollector; + using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor; using Copaque = xo::mm::AGCObject::Copaque; using Opaque = xo::mm::AGCObject::Opaque; ///@} @@ -52,8 +53,10 @@ namespace xo { // non-const methods /** move instance using allocator **/ static Opaque shallow_move(DTypeVarRef & self, obj gc) noexcept; - /** during GC: forward immdiate children **/ - static void forward_children(DTypeVarRef & self, obj gc) noexcept; + /** Invoke fn.visit_child(iface,data) for each child GCObject pointer. +Context: provides address of data pointer so it can be updated in place +when @p fn invokes garbage collector reentry point **/ + static void visit_gco_children(DTypeVarRef & self, obj fn) noexcept; ///@} }; diff --git a/src/type/DArrayType.cpp b/src/type/DArrayType.cpp index 46bad06..4a172f9 100644 --- a/src/type/DArrayType.cpp +++ b/src/type/DArrayType.cpp @@ -88,15 +88,14 @@ namespace xo { return gc.std_move_for(this); } - std::size_t - DArrayType::forward_children(obj gc) noexcept + void + DArrayType::visit_gco_children(obj gc) noexcept { - { - auto e = FacetRegistry::instance().variant(elt_type_); - gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); - } - - return this->shallow_size(); + gc.visit_poly_child(&elt_type_); + //{ + // auto e = FacetRegistry::instance().variant(elt_type_); + // gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); + //} } } } diff --git a/src/type/DAtomicType.cpp b/src/type/DAtomicType.cpp index c5d3033..070683b 100644 --- a/src/type/DAtomicType.cpp +++ b/src/type/DAtomicType.cpp @@ -66,10 +66,10 @@ namespace xo { return gc.std_move_for(this); } - std::size_t - DAtomicType::forward_children(obj) noexcept + void + DAtomicType::visit_gco_children(obj) noexcept { - return this->shallow_size(); + // no-op. no children } } /*namespace scm*/ diff --git a/src/type/DFunctionType.cpp b/src/type/DFunctionType.cpp index 83462b8..b27e9ac 100644 --- a/src/type/DFunctionType.cpp +++ b/src/type/DFunctionType.cpp @@ -99,17 +99,16 @@ namespace xo { return gc.std_move_for(this); } - std::size_t - DFunctionType::forward_children(obj gc) noexcept + void + DFunctionType::visit_gco_children(obj gc) noexcept { - { - auto e = FacetRegistry::instance().variant(return_type_); - gc.forward_inplace(e.iface(), (void **)&(return_type_.data_)); - } + gc.visit_poly_child(&return_type_); + //{ + // auto e = FacetRegistry::instance().variant(return_type_); + // gc.forward_inplace(e.iface(), (void **)&(return_type_.data_)); + //} - gc.forward_inplace(&arg_types_); - - return this->shallow_size(); + gc.visit_child(&arg_types_); } } /*namespace scm*/ diff --git a/src/type/DListType.cpp b/src/type/DListType.cpp index 4955777..0ffdf8d 100644 --- a/src/type/DListType.cpp +++ b/src/type/DListType.cpp @@ -93,15 +93,14 @@ namespace xo { return gc.std_move_for(this); } - std::size_t - DListType::forward_children(obj gc) noexcept + void + DListType::visit_gco_children(obj gc) noexcept { - { - auto e = FacetRegistry::instance().variant(elt_type_); - gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); - } - - return this->shallow_size(); + gc.visit_poly_child(&elt_type_); + //{ + // auto e = FacetRegistry::instance().variant(elt_type_); + // gc.forward_inplace(e.iface(), (void **)&(elt_type_.data_)); + //} } } } diff --git a/src/type/DTypeVarRef.cpp b/src/type/DTypeVarRef.cpp index e9119d1..a540c62 100644 --- a/src/type/DTypeVarRef.cpp +++ b/src/type/DTypeVarRef.cpp @@ -87,17 +87,16 @@ namespace xo { return gc.std_move_for(this); } - std::size_t - DTypeVarRef::forward_children(obj gc) noexcept + void + DTypeVarRef::visit_gco_children(obj gc) noexcept { - gc.forward_pivot_inplace(&type_); + gc.visit_poly_child(&type_); //{ // auto e = FacetRegistry::instance().variant(type_); // gc.forward_inplace(e.iface(), (void **)&type_.data_); //} - return this->shallow_size(); } } /*namespace scm*/ diff --git a/src/type/IGCObject_DArrayType.cpp b/src/type/IGCObject_DArrayType.cpp index 5f9e6c2..3483c40 100644 --- a/src/type/IGCObject_DArrayType.cpp +++ b/src/type/IGCObject_DArrayType.cpp @@ -21,9 +21,9 @@ namespace xo { return self.shallow_move(gc); } auto - IGCObject_DArrayType::forward_children(DArrayType & self, obj gc) noexcept -> void + IGCObject_DArrayType::visit_gco_children(DArrayType & self, obj fn) noexcept -> void { - self.forward_children(gc); + self.visit_gco_children(fn); } } /*namespace scm*/ diff --git a/src/type/IGCObject_DAtomicType.cpp b/src/type/IGCObject_DAtomicType.cpp index 287db90..2d891ef 100644 --- a/src/type/IGCObject_DAtomicType.cpp +++ b/src/type/IGCObject_DAtomicType.cpp @@ -21,9 +21,9 @@ namespace xo { return self.shallow_move(gc); } auto - IGCObject_DAtomicType::forward_children(DAtomicType & self, obj gc) noexcept -> void + IGCObject_DAtomicType::visit_gco_children(DAtomicType & self, obj fn) noexcept -> void { - self.forward_children(gc); + self.visit_gco_children(fn); } } /*namespace scm*/ diff --git a/src/type/IGCObject_DFunctionType.cpp b/src/type/IGCObject_DFunctionType.cpp index 3114a00..36d76b4 100644 --- a/src/type/IGCObject_DFunctionType.cpp +++ b/src/type/IGCObject_DFunctionType.cpp @@ -21,9 +21,9 @@ namespace xo { return self.shallow_move(gc); } auto - IGCObject_DFunctionType::forward_children(DFunctionType & self, obj gc) noexcept -> void + IGCObject_DFunctionType::visit_gco_children(DFunctionType & self, obj fn) noexcept -> void { - self.forward_children(gc); + self.visit_gco_children(fn); } } /*namespace scm*/ diff --git a/src/type/IGCObject_DListType.cpp b/src/type/IGCObject_DListType.cpp index bf5860f..68130a8 100644 --- a/src/type/IGCObject_DListType.cpp +++ b/src/type/IGCObject_DListType.cpp @@ -21,9 +21,9 @@ namespace xo { return self.shallow_move(gc); } auto - IGCObject_DListType::forward_children(DListType & self, obj gc) noexcept -> void + IGCObject_DListType::visit_gco_children(DListType & self, obj fn) noexcept -> void { - self.forward_children(gc); + self.visit_gco_children(fn); } } /*namespace scm*/ diff --git a/src/type/IGCObject_DTypeVarRef.cpp b/src/type/IGCObject_DTypeVarRef.cpp index 910b7a9..3ff82f3 100644 --- a/src/type/IGCObject_DTypeVarRef.cpp +++ b/src/type/IGCObject_DTypeVarRef.cpp @@ -21,9 +21,9 @@ namespace xo { return self.shallow_move(gc); } auto - IGCObject_DTypeVarRef::forward_children(DTypeVarRef & self, obj gc) noexcept -> void + IGCObject_DTypeVarRef::visit_gco_children(DTypeVarRef & self, obj fn) noexcept -> void { - self.forward_children(gc); + self.visit_gco_children(fn); } } /*namespace scm*/