Skip to content

Commit 5a19fbb

Browse files
committed
Box ItemKind::Impl
This brings the size of ItemKind down from 128 to 88 bytes. Hopefully this will have perf improvements.
1 parent 84ee982 commit 5a19fbb

File tree

54 files changed

+101
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+101
-78
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
134134
let old_len = self.in_scope_lifetimes.len();
135135

136136
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
137-
hir::ItemKind::Impl(hir::Impl { ref generics, .. })
137+
hir::ItemKind::Impl(box hir::Impl { ref generics, .. })
138138
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
139139
_ => &[],
140140
};
@@ -431,7 +431,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
431431
// to not cause an assertion failure inside the `lower_defaultness` function.
432432
let has_val = true;
433433
let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
434-
hir::ItemKind::Impl(hir::Impl {
434+
hir::ItemKind::Impl(box hir::Impl {
435435
unsafety: self.lower_unsafety(unsafety),
436436
polarity,
437437
defaultness,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
//! in the HIR, especially for multiple identifiers.
3232
3333
#![feature(array_value_iter)]
34+
#![feature(box_patterns)]
35+
#![feature(box_syntax)]
3436
#![feature(crate_visibility_modifier)]
3537
#![feature(or_patterns)]
3638
#![recursion_limit = "256"]

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,9 +2562,12 @@ pub enum ItemKind<'hir> {
25622562
TraitAlias(Generics<'hir>, GenericBounds<'hir>),
25632563

25642564
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
2565-
Impl(Impl<'hir>),
2565+
Impl(Box<Impl<'hir>>),
25662566
}
25672567

2568+
#[cfg(target_arch = "x86_64")]
2569+
static_assert_size!(ItemKind<'_>, 88);
2570+
25682571
#[derive(Debug, HashStable_Generic)]
25692572
pub struct Impl<'hir> {
25702573
pub unsafety: Unsafety,
@@ -2593,7 +2596,7 @@ impl ItemKind<'_> {
25932596
| ItemKind::Struct(_, ref generics)
25942597
| ItemKind::Union(_, ref generics)
25952598
| ItemKind::Trait(_, _, ref generics, _, _)
2596-
| ItemKind::Impl(Impl { ref generics, .. }) => generics,
2599+
| ItemKind::Impl(box Impl { ref generics, .. }) => generics,
25972600
_ => return None,
25982601
})
25992602
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
611611
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
612612
visitor.visit_enum_def(enum_definition, generics, item.hir_id, item.span)
613613
}
614-
ItemKind::Impl(Impl {
614+
ItemKind::Impl(box Impl {
615615
unsafety: _,
616616
defaultness: _,
617617
polarity: _,

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
#![feature(array_value_iter)]
6+
#![feature(box_patterns)]
67
#![feature(crate_visibility_modifier)]
78
#![feature(const_fn)] // For the unsizing cast on `&[]`
89
#![feature(const_panic)]

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(box_patterns)]
12
#![feature(or_patterns)]
23
#![recursion_limit = "256"]
34

@@ -684,7 +685,7 @@ impl<'a> State<'a> {
684685
self.head(visibility_qualified(&item.vis, "union"));
685686
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
686687
}
687-
hir::ItemKind::Impl(hir::Impl {
688+
hir::ItemKind::Impl(box hir::Impl {
688689
unsafety,
689690
polarity,
690691
defaultness,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
346346
Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => {
347347
match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) {
348348
Some(Node::Item(Item {
349-
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
349+
kind: ItemKind::Impl(box hir::Impl { self_ty, .. }),
350350
..
351351
})) => Some((*ident, self_ty)),
352352
_ => None,
@@ -368,7 +368,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
368368
let impl_did = tcx.hir().local_def_id(*impl_node);
369369
match tcx.hir().get_if_local(impl_did.to_def_id()) {
370370
Some(Node::Item(Item {
371-
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
371+
kind: ItemKind::Impl(box hir::Impl { self_ty, .. }),
372372
..
373373
})) if trait_objects.iter().all(|did| {
374374
// FIXME: we should check `self_ty` against the receiver

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
542542
return;
543543
}
544544
}
545-
hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), items, .. }) => {
545+
hir::ItemKind::Impl(box hir::Impl { of_trait: Some(ref trait_ref), items, .. }) => {
546546
// If the trait is private, add the impl items to `private_traits` so they don't get
547547
// reported for missing docs.
548548
let real_trait = trait_ref.path.res.def_id();

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![cfg_attr(test, feature(test))]
3030
#![feature(array_windows)]
3131
#![feature(bool_to_option)]
32+
#![feature(box_patterns)]
3233
#![feature(box_syntax)]
3334
#![feature(crate_visibility_modifier)]
3435
#![feature(iter_order_by)]

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2+
#![feature(box_patterns)]
23
#![feature(core_intrinsics)]
34
#![feature(crate_visibility_modifier)]
45
#![feature(drain_filter)]

0 commit comments

Comments
 (0)