Expand description
Constructor-object plumbing for product and sum structures.
The “structure pattern” lives at two primitives, hand-called at each
struct boundary. There is no per-struct trait, no derive, no
procedural macro: callers compose alloc_ctor_with_objects and
take_ctor_objects field by field and let the per-field
super::traits::IntoLean / super::traits::TryFromLean impls
do the actual type marshalling.
The module is the only place in abi that knows how
lean_alloc_ctor, lean_ctor_obj_cptr, and the constructor’s
tag/num_objs invariants line up; container modules
(crate::abi::option, crate::abi::except) and downstream
handlers ship through these primitives instead of repeating the
pointer arithmetic. That keeps a single audited copy of the
ctor-allocation rules and centralises the lean_inc/lean_dec
reasoning.
§Lifetime and refcount invariants
alloc_ctor_with_objectsconsumes the input array ofObj<'lean>handles. Each handle’s owned refcount is transferred — viaObj::into_raw— into the freshly allocated constructor’s object-slot, so the new parent owns exactly one count per field plus its own header count. NoObj::clone(which wouldlean_inc) runs on the input path.take_ctor_objectsreads each object slot once, callslean_incon the field, and wraps the bumped pointer in a freshObj<'lean>. The parentObjis then dropped; itslean_decwalks back through the original per-field counts, leaving each returned handle with the same effective ownership the parent had given that field.ctor_tagis a borrow-only read; it never touches the refcount.
Functions§
- alloc_
ctor_ with_ objects - Allocate a freshly-initialised constructor with
Nobject-pointer fields and no scalar payload. - ctor_
tag - Read the tag byte of a constructor object.
- take_
ctor_ objects - Validate that
objis a constructor withexpected_tagand exactlyNobject-pointer fields, then return theNowned field handles.