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 39ae54167f
28 changed files with 94 additions and 66 deletions

View file

@ -36,6 +36,8 @@ namespace xo {
using ACollector = xo::mm::ACollector;
/** gc-aware object facet **/
using AGCObject = xo::mm::AGCObject;
/** gc-centric object visitor **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** pretty-printer state for APrintable **/
using ppindentinfo = xo::print::ppindentinfo;
@ -148,7 +150,7 @@ namespace xo {
/** move to new address, mandated by @p gc **/
DArray * shallow_move(obj<ACollector> gc) noexcept;
/** forward elements to @p gc to-space; replace originals with forarding pointers **/
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}
private:

View file

@ -7,6 +7,7 @@
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
#include <xo/facet/obj.hpp>
#include <cstdint>
@ -16,6 +17,7 @@ namespace xo {
struct DBoolean {
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using AGCObject = xo::mm::AGCObject;
using ppindentinfo = xo::print::ppindentinfo;
using value_type = long;
@ -38,7 +40,7 @@ namespace xo {
// GCObject facet
DBoolean * shallow_move(obj<ACollector> gc) noexcept;
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
private:
/** boxed boolean value **/

View file

@ -8,6 +8,7 @@
#include "DArray.hpp"
#include "DString.hpp"
#include <xo/alloc2/GCObject.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/obj.hpp>
@ -35,6 +36,8 @@ namespace xo {
using AAllocator = xo::mm::AAllocator;
/** garbage collector facet **/
using ACollector = xo::mm::ACollector;
/** gc-centric object visitor **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** gc-aware object facet **/
using AGCObject = xo::mm::AGCObject;
/** pretty-printer state for APrintable **/
@ -203,7 +206,7 @@ namespace xo {
/** return shallow copy of this array, using memory from @p mm **/
DDictionary * shallow_move(obj<ACollector> gc) noexcept;
/** forward elements to @p gc to-space; replace originals with forwarding pointers **/
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}
private:

View file

@ -7,6 +7,7 @@
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -15,6 +16,7 @@ namespace xo {
struct DFloat {
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using ppindentinfo = xo::print::ppindentinfo;
using value_type = double;
@ -35,7 +37,7 @@ namespace xo {
// GCObject facet
DFloat * shallow_move(obj<ACollector> gc) noexcept;
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
private:

View file

@ -6,6 +6,7 @@
#pragma once
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
#include <xo/facet/obj.hpp>
@ -16,6 +17,7 @@ namespace xo {
struct DInteger {
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using AGCObject = xo::mm::AGCObject;
using ppindentinfo = xo::print::ppindentinfo;
using value_type = long;
@ -40,7 +42,7 @@ namespace xo {
// GCObject facet
DInteger * shallow_move(obj<ACollector> gc) noexcept;
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
private:
/** boxed integer value **/

View file

@ -20,6 +20,7 @@ namespace xo {
using AGCObject = xo::mm::AGCObject;
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using ppindentinfo = xo::print::ppindentinfo;
public:
@ -70,7 +71,7 @@ namespace xo {
/** @defgroup xo-scm-list-gcobject-facet gcobject facet **/
///@{
DList * shallow_move(obj<ACollector> gc) noexcept;
void forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}
/** first member of list **/

View file

@ -18,6 +18,7 @@ namespace xo {
public:
using AGCObject = xo::mm::AGCObject;
using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using AAllocator = xo::mm::AAllocator;
using ppindentinfo = xo::print::ppindentinfo;
@ -49,9 +50,8 @@ namespace xo {
/** @defgroup scm-runtimeerror-gcobject-facet gcobject facet **/
///@{
std::size_t shallow_size() const noexcept;
DRuntimeError * shallow_move(obj<ACollector> gc) noexcept;
std::size_t forward_children(obj<ACollector> gc) noexcept;
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;
///@}

View file

@ -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(DArray & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DArray & 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(DArray & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -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(DBoolean & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DBoolean & 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(DBoolean & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -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(DDictionary & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DDictionary & 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(DDictionary & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -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(DRuntimeError & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DRuntimeError & 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(DRuntimeError & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -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(DList & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DList & 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(DList & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

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

View file

@ -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(DInteger & self, obj<ACollector> gc) noexcept;
/** during GC: forward immdiate children **/
static void forward_children(DInteger & 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(DInteger & self, obj<AGCObjectVisitor> fn) noexcept;
///@}
};

View file

@ -198,16 +198,16 @@ namespace xo {
}
void
DArray::forward_children(obj<ACollector> gc) noexcept
DArray::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
{
scope log(XO_DEBUG(false));
for (size_type i = 0; i < size_; ++i) {
log && log("DArray::forward_children (loop)", xtag("i", i), xtag("z", size_));
log && log("DArray::visit_gco_children (loop)", xtag("i", i), xtag("z", size_));
obj<AGCObject> & elt = elts_[i];
gc.forward_inplace(&elt);
gc.visit_child(&elt);
}
}

View file

@ -36,9 +36,9 @@ namespace xo {
}
void
DBoolean::forward_children(obj<ACollector>) noexcept
DBoolean::visit_gco_children(obj<AGCObjectVisitor>) noexcept
{
// no-op
// no-op. childless
}

View file

@ -274,11 +274,10 @@ namespace xo {
}
void
DDictionary::forward_children(obj<ACollector> gc) noexcept
DDictionary::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
{
gc.forward_inplace(&keys_);
gc.forward_inplace(&values_);
gc.visit_child(&keys_);
gc.visit_child(&values_);
}
} /*namespace scm*/

View file

@ -34,9 +34,9 @@ namespace xo {
}
void
DFloat::forward_children(obj<ACollector>) noexcept
DFloat::visit_gco_children(obj<AGCObjectVisitor>) noexcept
{
// noop
// noop -- childless!
}
} /*namespace scm*/

View file

@ -34,9 +34,9 @@ namespace xo {
}
void
DInteger::forward_children(obj<ACollector>) noexcept
DInteger::visit_gco_children(obj<AGCObjectVisitor>) noexcept
{
// no-op
// no-op. childless
}
} /*namespace scm*/

View file

@ -185,12 +185,12 @@ namespace xo {
}
void
DList::forward_children(obj<ACollector> gc) noexcept
DList::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
{
//scope log(XO_DEBUG(true));
gc.forward_inplace(&head_);
gc.forward_inplace(&rest_);
gc.visit_child(&head_);
gc.visit_child(&rest_);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -52,32 +52,28 @@ namespace xo {
// ----- GCObject facet -----
std::size_t
DRuntimeError::shallow_size() const noexcept
{
return sizeof(DRuntimeError);
}
DRuntimeError *
DRuntimeError::shallow_move(obj<ACollector> gc) noexcept
{
return gc.std_move_for(this);
}
std::size_t
DRuntimeError::forward_children(obj<ACollector> gc) noexcept
void
DRuntimeError::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
{
{
auto iface = xo::facet::impl_for<AGCObject,DString>();
gc.forward_inplace(&iface, (void **)(&src_function_));
gc.visit_child(&src_function_);
//auto iface = xo::facet::impl_for<AGCObject,DString>();
//gc.forward_inplace(&iface, (void **)(&src_function_));
}
{
auto iface = xo::facet::impl_for<AGCObject,DString>();
gc.forward_inplace(&iface, (void **)(&error_descr_));
}
gc.visit_child(&error_descr_);
return this->shallow_size();
//auto iface = xo::facet::impl_for<AGCObject,DString>();
//gc.forward_inplace(&iface, (void **)(&error_descr_));
}
}
// ----- Printable facet -----

View file

@ -21,9 +21,9 @@ namespace xo {
return self.shallow_move(gc);
}
auto
IGCObject_DArray::forward_children(DArray & self, obj<ACollector> gc) noexcept -> void
IGCObject_DArray::visit_gco_children(DArray & 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_DBoolean::forward_children(DBoolean & self, obj<ACollector> gc) noexcept -> void
IGCObject_DBoolean::visit_gco_children(DBoolean & 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_DDictionary::forward_children(DDictionary & self, obj<ACollector> gc) noexcept -> void
IGCObject_DDictionary::visit_gco_children(DDictionary & 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_DFloat::forward_children(DFloat & self, obj<ACollector> gc) noexcept -> void
IGCObject_DFloat::visit_gco_children(DFloat & 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_DInteger::forward_children(DInteger & self, obj<ACollector> gc) noexcept -> void
IGCObject_DInteger::visit_gco_children(DInteger & 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_DList::forward_children(DList & self, obj<ACollector> gc) noexcept -> void
IGCObject_DList::visit_gco_children(DList & 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_DRuntimeError::forward_children(DRuntimeError & self, obj<ACollector> gc) noexcept -> void
IGCObject_DRuntimeError::visit_gco_children(DRuntimeError & self, obj<AGCObjectVisitor> fn) noexcept -> void
{
self.forward_children(gc);
self.visit_gco_children(fn);
}
} /*namespace scm*/