Skip to main content

Module structure

Module structure 

Source
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_objects consumes the input array of Obj<'lean> handles. Each handle’s owned refcount is transferred — via Obj::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. No Obj::clone (which would lean_inc) runs on the input path.
  • take_ctor_objects reads each object slot once, calls lean_inc on the field, and wraps the bumped pointer in a fresh Obj<'lean>. The parent Obj is then dropped; its lean_dec walks back through the original per-field counts, leaving each returned handle with the same effective ownership the parent had given that field.
  • ctor_tag is a borrow-only read; it never touches the refcount.

Functions§

alloc_ctor_with_objects
Allocate a freshly-initialised constructor with N object-pointer fields and no scalar payload.
ctor_tag
Read the tag byte of a constructor object.
take_ctor_objects
Validate that obj is a constructor with expected_tag and exactly N object-pointer fields, then return the N owned field handles.