refactor: + narrower interface for gc pointer forwarding

add AGCObjectVisitor, instead of requiring ACollector.
This commit is contained in:
Roland Conybeare 2026-04-05 23:53:02 -04:00
commit 8fe1871094
11 changed files with 45 additions and 27 deletions

View file

@ -9,6 +9,7 @@
#include <xo/type/Type.hpp>
#include <xo/object2/DArray.hpp>
#include <xo/alloc2/GCObjectConversion.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/reflect/Reflect.hpp>
#include <xo/alloc2/Allocator.hpp>
@ -76,8 +77,9 @@ namespace xo {
using Traits = detail::PmFnTraits<Fn>;
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 DArray = xo::scm::DArray;
using Reflect = xo::reflect::Reflect;
using TypeDescr = xo::reflect::TypeDescr;
@ -134,7 +136,7 @@ namespace xo {
/** @defgroup scm-primitive-gcobject-facet **/
///@{
Primitive * shallow_move(obj<ACollector> gc) noexcept;
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}
private:
@ -197,11 +199,12 @@ namespace xo {
template <typename Fn>
void
Primitive<Fn>::forward_children(obj<ACollector> gc) noexcept {
{
auto e = type_.to_facet<AGCObject>(); // FacetRegistry dep
gc.forward_inplace(e.iface(), (void **)&(type_.data_));
}
Primitive<Fn>::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept {
gc.visit_poly_child(&type_);
//{
// auto e = type_.to_facet<AGCObject>(); // FacetRegistry dep
// gc.forward_inplace(e.iface(), (void **)&(type_.data_));
//}
}
} /*namespace scm*/

View file

@ -44,6 +44,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;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DPrimitive_gco_0 & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DPrimitive_gco_0 & self, obj<ACollector> 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(DPrimitive_gco_0 & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -44,6 +44,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;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DPrimitive_gco_1_gco & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DPrimitive_gco_1_gco & self, obj<ACollector> 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(DPrimitive_gco_1_gco & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -44,6 +44,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;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DPrimitive_gco_2_dict_string & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DPrimitive_gco_2_dict_string & self, obj<ACollector> 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(DPrimitive_gco_2_dict_string & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -44,6 +44,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;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DPrimitive_gco_2_gco_gco & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DPrimitive_gco_2_gco_gco & self, obj<ACollector> 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(DPrimitive_gco_2_gco_gco & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -44,6 +44,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;
///@}
@ -54,8 +55,10 @@ namespace xo {
// non-const methods
/** move instance using allocator **/
static Opaque shallow_move(DPrimitive_gco_3_dict_string_gco & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DPrimitive_gco_3_dict_string_gco & self, obj<ACollector> 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(DPrimitive_gco_3_dict_string_gco & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DPrimitive_gco_0::forward_children(DPrimitive_gco_0 & self, obj<ACollector> gc) noexcept -> void
IGCObject_DPrimitive_gco_0::visit_gco_children(DPrimitive_gco_0 & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DPrimitive_gco_1_gco::forward_children(DPrimitive_gco_1_gco & self, obj<ACollector> gc) noexcept -> void
IGCObject_DPrimitive_gco_1_gco::visit_gco_children(DPrimitive_gco_1_gco & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DPrimitive_gco_2_dict_string::forward_children(DPrimitive_gco_2_dict_string & self, obj<ACollector> gc) noexcept -> void
IGCObject_DPrimitive_gco_2_dict_string::visit_gco_children(DPrimitive_gco_2_dict_string & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DPrimitive_gco_2_gco_gco::forward_children(DPrimitive_gco_2_gco_gco & self, obj<ACollector> gc) noexcept -> void
IGCObject_DPrimitive_gco_2_gco_gco::visit_gco_children(DPrimitive_gco_2_gco_gco & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DPrimitive_gco_3_dict_string_gco::forward_children(DPrimitive_gco_3_dict_string_gco & self, obj<ACollector> gc) noexcept -> void
IGCObject_DPrimitive_gco_3_dict_string_gco::visit_gco_children(DPrimitive_gco_3_dict_string_gco & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/