Skip to content

Commit 79ce5bb

Browse files
committed
Add a test for the size of important types.
We have size checks like these for many different parts of the compiler: AST, HIR, MIR, etc. Those ones all use `static_assert_size!` from `rustc_index`, but because rustdoc-json-types is distributed as its own crate it can't depend on `rustc_index`. So I've just put the checks in a unit test. Note that `Item` is currently very large! Making the sizes of these things explicit and tested is the first step towards making them smaller.
1 parent 55b9b4d commit 79ce5bb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/rustdoc-json-types/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,30 @@ fn test_union_info_roundtrip() {
3838
let decoded: ItemEnum = bincode::deserialize(&encoded).unwrap();
3939
assert_eq!(u, decoded);
4040
}
41+
42+
// The memory used by a `Crate` can get large. These types are the ones that
43+
// contribute the most to its size. Ideally we'd use static assertions for
44+
// these tests but that would require adding some kind of dependency that we
45+
// don't want to rustdoc-json-types.
46+
#[test]
47+
#[cfg(target_pointer_width = "64")]
48+
fn test_type_sizes() {
49+
// tidy-alphabetical-start
50+
assert_eq!(size_of::<AssocItemConstraint>(), 112);
51+
assert_eq!(size_of::<Crate>(), 184);
52+
assert_eq!(size_of::<ExternalCrate>(), 48);
53+
assert_eq!(size_of::<FunctionPointer>(), 168);
54+
assert_eq!(size_of::<GenericArg>(), 80);
55+
assert_eq!(size_of::<GenericArgs>(), 104);
56+
assert_eq!(size_of::<GenericBound>(), 72);
57+
assert_eq!(size_of::<GenericParamDef>(), 136);
58+
assert_eq!(size_of::<Impl>(), 304);
59+
assert_eq!(size_of::<Item>(), 552);
60+
assert_eq!(size_of::<ItemSummary>(), 32);
61+
assert_eq!(size_of::<PolyTrait>(), 64);
62+
assert_eq!(size_of::<PreciseCapturingArg>(), 32);
63+
assert_eq!(size_of::<TargetFeature>(), 80);
64+
assert_eq!(size_of::<Type>(), 80);
65+
assert_eq!(size_of::<WherePredicate>(), 160);
66+
// tidy-alphabetical-end
67+
}

0 commit comments

Comments
 (0)