Improve derived implementations for enums with lots of fieldless variants
A number of trait methods like PartialEq::eq or Hash::hash don't actually need a distinct arm for each variant, because the code within the arm only depends on the number and types of the fields in the variants. We can easily exploit this fact to create less and better code for enums with multiple variants that have no fields at all, the extreme case being C-like enums. For nickel.rs and its by now infamous 800 variant enum, this reduces optimized compile times by 25% and non-optimized compile times by 40%. Also peak memory usage is down by almost 40% (310MB down to 190MB). To be fair, most other crates don't benefit nearly as much, because they don't have as huge enums. The crates in the Rust distribution that I measured saw basically no change in compile times (I only tried optimized builds) and only 1-2% reduction in peak memory usage.
This commit is contained in:
parent
c049541741
commit
0eeb14eaba
13 changed files with 44 additions and 7 deletions
|
|
@ -58,6 +58,7 @@ fn expand(cx: &mut ExtCtxt,
|
|||
ret_ty: Literal(Path::new_local("isize")),
|
||||
attributes: vec![],
|
||||
is_unsafe: false,
|
||||
unify_fieldless_variants: true,
|
||||
combine_substructure: combine_substructure(box |cx, span, substr| {
|
||||
let zero = cx.expr_isize(span, 0);
|
||||
cs_fold(false,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ fn expand(cx: &mut ExtCtxt,
|
|||
ret_ty: Literal(Path::new_local("isize")),
|
||||
attributes: vec![],
|
||||
is_unsafe: false,
|
||||
unify_fieldless_variants: true,
|
||||
combine_substructure: combine_substructure(Box::new(totalsum_substructure)),
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue