• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 19993677870

06 Dec 2025 08:12PM UTC coverage: 58.752% (+0.05%) from 58.705%
19993677870

push

github

fasterthanlime
Reduce/cordon bloat in facet, introduce bloatbench

Looks into codegen size, compile times etc. - again :) after adding a buuuunch of features.

- [x] Disable miette's default features (derive, which depends on syn) (`b.miette`)
- [x] Don't enable miette fancy by default in facet-json (`b.miette-fancy`)
- [x] Flatten closures in facet-json to avoid generic instantiations (`b.flatten-closures`)
- [x] Get rid of shape_of in Shape derive, use `#field_type` directly (`b.shape-of`)
- [x] Detect known derives in facet-macros, eschew impls! for them (`b.detect-derives`)
- [x] Gate nonzero impls, net impls (`b.gate-impls`)
- [x] Gate doc-comments, vtable-fmt, vtable-cmp, vtable-hash (`b.gate-vtable`)
- [x] Make 'auto trait detection' opt-in (`b.auto-traits-optin`)
- [x] Detect traits from `derive` and from `#[facet(default)]` (`b.derive-traits`)
- [x] Allow manual trait specification via `#[facet(traits(...))]` (`b.manual-traits`)
- [x] Go back to builders (they expand to less code) (`b.builders`)
- [x] VTable restructured with sub-vtables (`format`, `cmp`, `hash`, `markers`) (`b.vtable-substruct`)
- [x] Convert manual impls to ShapeBuilder (`scalar.rs`, `fn_ptr.rs`, `impls_num_complex.rs`) (`b.shapebuilder`)
- [x] **Confirmed**: `#![allow(uncommon_codepoints, nonstandard_style)]` in library = no warnings in consumers (`b.unicode-test`)
- [x] Add `FieldBuilder::new(name, shape_fn, offset)` builder (`b.field-builder`)
- [x] Add `StructTypeBuilder::new(kind, fields)` builder (`b.structtype-builder`)
- [x] Add `VariantBuilder::new(name, data)` builder (`b.variant-builder`)
- [x] Add `EnumTypeBuilder::new(enum_repr, variants)` builder (`b.enumtype-builder`)
- [x] Create `::facet::𝟋` module with type aliases and builder exports (`b.prelude-mod`)
- [x] Update derive macro to use builder pattern for Field, StructType, Variant, EnumType (`b.derive-builders`)

Based on analysis in `facet-bloatbench/MACRO-OPTIMIZATION-ANALYSIS.md`:

- [x] Remove `let mut vtable = const... (continued)

1199 of 3227 new or added lines in 72 files covered. (37.16%)

145 existing lines in 29 files now uncovered.

24253 of 41280 relevant lines covered (58.75%)

504.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.37
/facet-core/src/impls_core/array.rs
1
use core::ptr::NonNull;
2

3
use crate::*;
4

5
unsafe impl<'a, T, const L: usize> Facet<'a> for [T; L]
6
where
7
    T: Facet<'a>,
8
{
9
    const SHAPE: &'static Shape = &const {
10
        Shape {
11
            id: Shape::id_of::<Self>(),
12
            layout: Shape::layout_of::<Self>(),
13
            vtable: ValueVTable {
14
                type_name: |f, opts| {
32✔
15
                    if let Some(opts) = opts.for_children() {
32✔
16
                        write!(f, "[")?;
32✔
17
                        (T::SHAPE.vtable.type_name())(f, opts)?;
32✔
18
                        write!(f, "; {L}]")
32✔
19
                    } else {
NEW
20
                        write!(f, "[…; {L}]")
×
21
                    }
22
                },
32✔
23
                drop_in_place: ValueVTable::drop_in_place_for::<Self>(),
24
                default_in_place: {
25
                    if L == 0 {
26
                        // Zero-length arrays implement `Default` irrespective of the element type
27
                        Some(|target| unsafe { target.assume_init() })
1✔
28
                    } else if L <= 32 && T::SHAPE.vtable.has_default_in_place() {
29
                        Some(|target| unsafe {
30
                            let t_dip = T::SHAPE.vtable.default_in_place.unwrap();
1✔
31
                            let stride = T::SHAPE
1✔
32
                                .layout
1✔
33
                                .sized_layout()
1✔
34
                                .unwrap()
1✔
35
                                .pad_to_align()
1✔
36
                                .size();
1✔
37
                            for idx in 0..L {
1✔
38
                                t_dip(target.field_uninit_at(idx * stride));
1✔
39
                            }
1✔
40
                            target.assume_init()
1✔
41
                        })
1✔
42
                    } else {
43
                        // arrays do not yet implement `Default` for > 32 elements due
44
                        // to specializing the `0` len case
45
                        None
46
                    }
47
                },
48
                clone_into: {
49
                    if T::SHAPE.vtable.has_clone_into() {
50
                        Some(|src, dst| unsafe {
51
                            let src = src.get::<Self>();
1✔
52
                            let t_cip = T::SHAPE.vtable.clone_into.unwrap();
1✔
53
                            let stride = T::SHAPE
1✔
54
                                .layout
1✔
55
                                .sized_layout()
1✔
56
                                .unwrap()
1✔
57
                                .pad_to_align()
1✔
58
                                .size();
1✔
59
                            for (idx, src) in src.iter().enumerate() {
1✔
60
                                (t_cip)(
1✔
61
                                    PtrConst::new(NonNull::from(src)),
1✔
62
                                    dst.field_uninit_at(idx * stride),
1✔
63
                                );
1✔
64
                            }
1✔
65
                            dst.assume_init()
1✔
66
                        })
1✔
67
                    } else {
68
                        None
69
                    }
70
                },
NEW
71
                ..ValueVTable::new(|_, _| Ok(()))
×
72
            },
73
            ty: Type::Sequence(SequenceType::Array(ArrayType { t: T::SHAPE, n: L })),
74
            def: Def::Array(ArrayDef::new(
75
                &const {
76
                    ArrayVTable::new(
77
                        |ptr| unsafe {
78
                            let array = ptr.get::<[T; L]>();
34✔
79
                            PtrConst::new(NonNull::from(array))
34✔
80
                        },
34✔
81
                        |ptr| unsafe {
NEW
82
                            let array = ptr.as_mut::<[T; L]>();
×
NEW
83
                            PtrMut::new(NonNull::from(array))
×
UNCOV
84
                        },
×
85
                    )
86
                },
87
                T::SHAPE,
88
                L,
89
            )),
90
            type_identifier: "&[_; _]",
91
            type_params: &[TypeParam {
92
                name: "T",
93
                shape: T::SHAPE,
94
            }],
95
            doc: &[],
96
            attributes: &[],
97
            type_tag: None,
98
            inner: None,
99
        }
100
    };
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc