• 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

93.48
/facet-core/src/impls_std/hashmap.rs
1
use core::hash::BuildHasher;
2
use core::ptr::NonNull;
3
use std::collections::HashMap;
4
use std::hash::RandomState;
5

6
use crate::ptr::{PtrConst, PtrMut};
7

8
use crate::{
9
    Def, Facet, IterVTable, MapDef, MapVTable, Shape, Type, TypeParam, UserType, ValueVTable,
10
    value_vtable,
11
};
12

13
type HashMapIterator<'mem, K, V> = std::collections::hash_map::Iter<'mem, K, V>;
14

15
// TODO: Debug, PartialEq, Eq for HashMap, HashSet
16
unsafe impl<'a, K, V, S> Facet<'a> for HashMap<K, V, S>
17
where
18
    K: Facet<'a> + core::cmp::Eq + core::hash::Hash,
19
    V: Facet<'a>,
20
    S: 'a + Default + BuildHasher,
21
{
22
    const SHAPE: &'static Shape = &const {
23
        Shape {
24
            id: Shape::id_of::<Self>(),
25
            layout: Shape::layout_of::<Self>(),
26
            vtable: ValueVTable {
27
                type_name: |f, opts| {
56✔
28
                    write!(f, "{}<", Self::SHAPE.type_identifier)?;
56✔
29
                    if let Some(opts) = opts.for_children() {
56✔
30
                        K::SHAPE.vtable.type_name()(f, opts)?;
56✔
31
                        write!(f, ", ")?;
56✔
32
                        V::SHAPE.vtable.type_name()(f, opts)?;
56✔
33
                    } else {
NEW
34
                        write!(f, "…")?;
×
35
                    }
36
                    write!(f, ">")
56✔
37
                },
56✔
38
                drop_in_place: ValueVTable::drop_in_place_for::<Self>(),
NEW
39
                default_in_place: Some(|target| unsafe { target.put(Self::default()) }),
×
NEW
40
                ..ValueVTable::new(|_, _| Ok(()))
×
41
            },
42
            ty: Type::User(UserType::Opaque),
43
            def: Def::Map(MapDef {
44
                vtable: &const {
45
                    MapVTable {
46
                        init_in_place_with_capacity_fn: |uninit, capacity| unsafe {
47
                            uninit.put(Self::with_capacity_and_hasher(capacity, S::default()))
67✔
48
                        },
67✔
49
                        insert_fn: |ptr, key, value| unsafe {
50
                            let map = ptr.as_mut::<HashMap<K, V>>();
87✔
51
                            let key = key.read::<K>();
87✔
52
                            let value = value.read::<V>();
87✔
53
                            map.insert(key, value);
87✔
54
                        },
87✔
55
                        len_fn: |ptr| unsafe {
56
                            let map = ptr.get::<HashMap<K, V>>();
5✔
57
                            map.len()
5✔
58
                        },
5✔
59
                        contains_key_fn: |ptr, key| unsafe {
60
                            let map = ptr.get::<HashMap<K, V>>();
12✔
61
                            map.contains_key(key.get())
12✔
62
                        },
12✔
63
                        get_value_ptr_fn: |ptr, key| unsafe {
64
                            let map = ptr.get::<HashMap<K, V>>();
12✔
65
                            map.get(key.get()).map(|v| PtrConst::new(NonNull::from(v)))
12✔
66
                        },
12✔
67
                        iter_vtable: IterVTable {
68
                            init_with_value: Some(|ptr| unsafe {
69
                                let map = ptr.get::<HashMap<K, V>>();
30✔
70
                                let iter: HashMapIterator<'_, K, V> = map.iter();
30✔
71
                                let iter_state = Box::new(iter);
30✔
72
                                PtrMut::new(NonNull::new_unchecked(
30✔
73
                                    Box::into_raw(iter_state) as *mut u8
30✔
74
                                ))
75
                            }),
30✔
76
                            next: |iter_ptr| unsafe {
77
                                let state = iter_ptr.as_mut::<HashMapIterator<'_, K, V>>();
75✔
78
                                state.next().map(|(key, value)| {
75✔
79
                                    (
46✔
80
                                        PtrConst::new(NonNull::from(key)),
46✔
81
                                        PtrConst::new(NonNull::from(value)),
46✔
82
                                    )
46✔
83
                                })
46✔
84
                            },
75✔
85
                            next_back: None,
86
                            size_hint: None,
87
                            dealloc: |iter_ptr| unsafe {
88
                                drop(Box::from_raw(
30✔
89
                                    iter_ptr.as_ptr::<HashMapIterator<'_, K, V>>()
30✔
90
                                        as *mut HashMapIterator<'_, K, V>,
30✔
91
                                ));
92
                            },
30✔
93
                        },
94
                    }
95
                },
96
                k: K::SHAPE,
97
                v: V::SHAPE,
98
            }),
99
            type_identifier: "HashMap",
100
            type_params: &[
101
                TypeParam {
102
                    name: "K",
103
                    shape: K::SHAPE,
104
                },
105
                TypeParam {
106
                    name: "V",
107
                    shape: V::SHAPE,
108
                },
109
            ],
110
            doc: &[],
111
            attributes: &[],
112
            type_tag: None,
113
            inner: None,
114
        }
115
    };
116
}
117

118
unsafe impl Facet<'_> for RandomState {
119
    const SHAPE: &'static Shape = &const {
120
        Shape {
121
            id: Shape::id_of::<Self>(),
122
            layout: Shape::layout_of::<Self>(),
123
            vtable: value_vtable!((), |f, _opts| write!(f, "{}", Self::SHAPE.type_identifier)),
2✔
124
            ty: Type::User(UserType::Opaque),
125
            def: Def::Scalar,
126
            type_identifier: "RandomState",
127
            type_params: &[],
128
            doc: &[],
129
            attributes: &[],
130
            type_tag: None,
131
            inner: None,
132
        }
133
    };
134
}
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