-
-
Notifications
You must be signed in to change notification settings - Fork 90
Refactor VTable system: Direct/Indirect styles, OxRef/OxMut, builder patterns #1148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
fasterthanlime
wants to merge
15
commits into
main
Choose a base branch
from
vtable-code-sharing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+21,325
−15,078
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b8e4666 to
a0775e1
Compare
219c28c to
c1ed049
Compare
Closed
1588c6d to
a7ab835
Compare
d66eafd to
85056de
Compare
…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
d83d0ca to
b95feac
Compare
|
|
1 similar comment
|
|
…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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Major architectural refactor of the facet vtable system for better code sharing and reduced binary bloat.
Key Changes
New Pointer Types
ThinPtr/WidePtrin favor ofPtrConst<'a>/PtrMut<'a>/PtrUninit<'a>OxRef<'a>/OxMut<'a>- shaped pointers bundling ptr + shapeOx<'a>enum for ownership tracking (like Cow for shaped pointers)VTable Refactor
*const ()/*mut (), returnsTdirectlyOxRef/OxMut, returnsOption<T>Shape::call_*helpers dispatch to either style transparentlyBuilder Patterns Everywhere
vtable_direct!macro for sized types with compile-time known traitsVTableIndirect::builder()for generic containers with runtime dispatchHash Support via HashProxy
H: Hasher, can't store directly in vtableHashProxytype-erases the hasher for vtable storageReorganized Impls
impls_core/impls_alloc/impls_std→impls/core/alloc/std/cratesinternal/module for facet's own types (Shape, Def, etc.)MarkerTraits on Shape
.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.mdfor the full migration guide. Key mappings:ThinPtr*const ()orPtrConst<'a>vtable_ref!(value_vtable!(...))vtable_direct!(T => Debug, ...)fnitemsshape.is_type::<T>()shape.is_shape(T::SHAPE)