Skip to content

Conversation

@fasterthanlime
Copy link
Contributor

@fasterthanlime fasterthanlime commented Dec 6, 2025

Summary

Major architectural refactor of the facet vtable system for better code sharing and reduced binary bloat.

Key Changes

New Pointer Types

  • Remove ThinPtr/WidePtr in favor of PtrConst<'a>/PtrMut<'a>/PtrUninit<'a>
  • Add OxRef<'a>/OxMut<'a> - shaped pointers bundling ptr + shape
  • Add Ox<'a> enum for ownership tracking (like Cow for shaped pointers)

VTable Refactor

  • VTableDirect: for concrete types, uses raw *const ()/*mut (), returns T directly
  • VTableIndirect: for generic containers, uses OxRef/OxMut, returns Option<T>
  • VTableErased enum wraps both styles
  • Shape::call_* helpers dispatch to either style transparently

Builder Patterns Everywhere

  • vtable_direct! macro for sized types with compile-time known traits
  • VTableIndirect::builder() for generic containers with runtime dispatch
  • All container vtables (Array, Option, Result, List, Map, Set) use builders
  • No more positional arguments - named builder methods only

Hash Support via HashProxy

  • Hash trait is generic over H: Hasher, can't store directly in vtable
  • HashProxy type-erases the hasher for vtable storage
  • Enables hash support without wrapper function bloat

Reorganized Impls

  • impls_core/impls_alloc/impls_stdimpls/core/alloc/std/crates
  • New internal/ module for facet's own types (Shape, Def, etc.)
  • Cleaner separation of concerns

MarkerTraits on Shape

  • Copy, Send, Sync, Eq, Unpin stored as bitflags on Shape
  • Set via ShapeBuilder methods: .copy(), .send(), .sync(), .eq()

Status

WIP: Core infrastructure is done. Some impl modules still need migration to the new API.

Migration Guide

See drafts/no-bloat.md for the full migration guide. Key mappings:

Old New
ThinPtr *const () or PtrConst<'a>
vtable_ref!(value_vtable!(...)) vtable_direct!(T => Debug, ...)
Closures in vtables Named fn items
shape.is_type::<T>() shape.is_shape(T::SHAPE)

@github-actions github-actions bot added ⚙️ core facet-core crate, core types and traits 💅 devex Developer experience 💥 breaking Breaking API changes labels Dec 6, 2025
@fasterthanlime fasterthanlime changed the title wip: vtable code sharing - instant vs delayed resolution VTable code sharing: instant vs delayed resolution Dec 7, 2025
@github-actions github-actions bot added ✨ enhancement New feature or request 📜 derive Related to the derive macro labels Dec 7, 2025
@fasterthanlime fasterthanlime force-pushed the vtable-code-sharing branch 2 times, most recently from 219c28c to c1ed049 Compare December 7, 2025 13:21
@github-actions github-actions bot added the 🧹 code quality keep it sparkly label Dec 7, 2025
@github-actions github-actions bot added the 🏷️ macros facet-macros, proc-macro implementation label Dec 7, 2025
@fasterthanlime fasterthanlime force-pushed the vtable-code-sharing branch 4 times, most recently from 1588c6d to a7ab835 Compare December 8, 2025 07:57
@fasterthanlime fasterthanlime changed the title VTable code sharing: instant vs delayed resolution Refactor VTable system: Direct/Indirect styles, OxRef/OxMut, builder patterns Dec 8, 2025
@fasterthanlime fasterthanlime force-pushed the vtable-code-sharing branch 4 times, most recently from d66eafd to 85056de Compare December 8, 2025 11:22
…patterns

Major architectural refactor of the facet vtable system for better code sharing
and reduced binary bloat.

- Remove ThinPtr/WidePtr in favor of PtrConst<'a>/PtrMut<'a>/PtrUninit<'a>
- Add OxRef<'a>/OxMut<'a> - shaped pointers bundling ptr + shape
- Add Ox<'a> enum for ownership tracking (like Cow for shaped pointers)

- VTableDirect: for concrete types, uses raw *const ()/*mut (), returns T directly
- VTableIndirect: for generic containers, uses OxRef/OxMut, returns Option<T>
- VTableErased enum wraps both styles
- Shape::call_* helpers dispatch to either style transparently

- vtable_direct! macro for sized types with compile-time known traits
- VTableIndirect::builder() for generic containers with runtime dispatch
- All container vtables (Array, Option, Result, List, Map, Set) use builders
- No more positional arguments - named builder methods only

- Hash trait is generic over H: Hasher, can't store directly in vtable
- HashProxy type-erases the hasher for vtable storage
- Enables hash support without wrapper function bloat

- impls_core/impls_alloc/impls_std -> impls/core/alloc/std/crates
- New internal/ module for facet's own types (Shape, Def, etc.)
- Cleaner separation of concerns

- Copy, Send, Sync, Eq, Unpin stored as bitflags on Shape
- Set via ShapeBuilder methods: .copy(), .send(), .sync(), .eq()

- ThinPtr -> *const () or PtrConst<'a>
- WidePtr -> OxRef<'a> or OxMut<'a>
- vtable_ref! -> vtable_direct! or VTableIndirect::builder()
- ValueVTable -> VTableDirect or VTableIndirect
- Closures in vtables -> named fn items

WIP: Some impl modules still need migration to new API.
…te macro vtable gen

- Add Variance enum with computed_variance() methods to Shape
- Add ShapeFlags bitflags with UNTAGGED flag
- Add tag/content fields to Shape for enum tagging
- Add Field::should_skip_deserializing() helper
- Export VTableDirect, VTableErased, Attr, FieldBuilder, ShapeBuilder, Variance, ShapeFlags, HashProxy to digamma prelude
- Add 𝟋drop_for helper for vtable construction
- Update gen_vtable_instant() to use VTableDirect::builder_for pattern with direct trait refs
- Fix facet-pretty ExtensionAttr -> Attr rename
@github-actions github-actions bot added the ⏳ needs-triage Needs review label Dec 8, 2025
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

⚠️ Automatic labeling failed (likely rate limit). This PR needs manual triage.

1 similar comment
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

⚠️ Automatic labeling failed (likely rate limit). This PR needs manual triage.

…on crates

- vtable_direct! and vtable_indirect! macros now auto-add drop_in_place
- Fix Arc<T>, Arc<str>, Arc<[U]>, Box<T> to have drop_in_place
- Add Attr::get_as<T>() convenience method
- Export EnumTypeBuilder, VariantBuilder to digamma prelude
- Replace .default_fn().is_some() with .has_default() in deserializers
- Replace .vtable.display().is_some() with .vtable.has_display()
- Replace .vtable.parse().is_some() with .vtable.has_parse()
- Replace ExtensionAttr with Attr in facet-shapelike

facet-core tests now pass (41/41)
…vtable API

- Add Attr::new() and Attr::new_shape() constructors using OxRef
- Migrate facet-value to VTableIndirect API
- Update facet-shapelike to access attr.data.ptr()/shape instead of old fields
- Add TypeLike::Undefined variant for new Type::Undefined enum case
- Fix facet-kdl to use attr.get_as() instead of unsafe data_ref()
- Remove NonNull wrappers since PtrConst/PtrMut::new() take raw pointers
- Fix Ptr::from_ref to use PtrConst::new().into()
- Fix __attr! macro to use Attr::new() with OxRef
- Fix predicate/make_t variants in attr grammar
- Fix Self reference in const blocks by passing concrete type
- Fix field-level proxy to generate full ProxyDef
- Fix skip_serializing_if to wrap in type-erased wrapper
- Fix enum gen_vtable call with 5th argument
- Update ndarray.rs test to use ShapeBuilder API
The previous code tried to use #struct_type #bgp_display::method() which
generates invalid tokens like GenericValue<T>::method() inside &const blocks.
The <Self> syntax works correctly and refers to the monomorphized type.
- Change MarkerTraits::EMPTY to MarkerTraits::empty()
- Change .with_*() methods to use | operator with constants
- Fix ndarray.rs test to use 'static lifetime and proper type_name function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💥 breaking Breaking API changes 🧹 code quality keep it sparkly ⚙️ core facet-core crate, core types and traits 📜 derive Related to the derive macro 💅 devex Developer experience ✨ enhancement New feature or request 🏷️ macros facet-macros, proc-macro implementation ⏳ needs-triage Needs review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants