Skip to content

Commit 97c82d8

Browse files
committed
Revert "rustdoc: Store DefId's in ItemId on heap for decreasing Item's size"
This reverts commit 41a345d4c46dad1a98c9993bc78513415994e8ba.
1 parent 45d3dae commit 97c82d8

16 files changed

+109
-115
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
113113
name: None,
114114
attrs: Default::default(),
115115
visibility: Inherited,
116-
def_id: ItemId::Auto(box ImplId { trait_: trait_def_id, for_: item_def_id }),
116+
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
117117
kind: box ImplItem(Impl {
118118
span: Span::dummy(),
119119
unsafety: hir::Unsafety::Normal,

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
9696
name: None,
9797
attrs: Default::default(),
9898
visibility: Inherited,
99-
def_id: ItemId::Blanket(box ImplId { trait_: trait_def_id, for_: item_def_id }),
99+
def_id: ItemId::Blanket { trait_: trait_def_id, for_: item_def_id },
100100
kind: box ImplItem(Impl {
101101
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
102102
unsafety: hir::Unsafety::Normal,

src/librustdoc/clean/types.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1818
use rustc_data_structures::thin_vec::ThinVec;
1919
use rustc_hir as hir;
2020
use rustc_hir::def::{CtorKind, DefKind, Res};
21-
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
21+
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
2222
use rustc_hir::lang_items::LangItem;
2323
use rustc_hir::{BodyId, Mutability};
2424
use rustc_index::vec::IndexVec;
@@ -50,59 +50,61 @@ use self::Type::*;
5050

5151
crate type ItemIdSet = FxHashSet<ItemId>;
5252

53-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
54-
crate struct ImplId {
55-
crate trait_: DefId,
56-
crate for_: DefId,
57-
}
58-
59-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
53+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
6054
crate enum ItemId {
6155
/// A "normal" item that uses a [`DefId`] for identification.
6256
DefId(DefId),
6357
/// Identifier that is used for auto traits.
64-
Auto(Box<ImplId>),
58+
Auto { trait_: DefId, for_: DefId },
6559
/// Identifier that is used for blanket implementations.
66-
Blanket(Box<ImplId>),
60+
Blanket { trait_: DefId, for_: DefId },
6761
/// Identifier for primitive types.
6862
Primitive(CrateNum),
6963
}
7064

7165
impl ItemId {
7266
#[inline]
73-
crate fn is_local(&self) -> bool {
67+
crate fn is_local(self) -> bool {
7468
match self {
75-
ItemId::Auto(box ImplId { for_: id, .. })
76-
| ItemId::Blanket(box ImplId { for_: id, .. })
69+
ItemId::Auto { for_: id, .. }
70+
| ItemId::Blanket { for_: id, .. }
7771
| ItemId::DefId(id) => id.is_local(),
78-
ItemId::Primitive(krate) => *krate == LOCAL_CRATE,
72+
ItemId::Primitive(krate) => krate == LOCAL_CRATE,
7973
}
8074
}
8175

8276
#[inline]
8377
#[track_caller]
84-
crate fn expect_def_id(&self) -> DefId {
78+
crate fn expect_def_id(self) -> DefId {
8579
self.as_def_id()
8680
.unwrap_or_else(|| panic!("ItemId::expect_def_id: `{:?}` isn't a DefId", self))
8781
}
8882

8983
#[inline]
90-
crate fn as_def_id(&self) -> Option<DefId> {
84+
crate fn as_def_id(self) -> Option<DefId> {
9185
match self {
92-
ItemId::DefId(id) => Some(*id),
86+
ItemId::DefId(id) => Some(id),
9387
_ => None,
9488
}
9589
}
9690

9791
#[inline]
98-
crate fn krate(&self) -> CrateNum {
99-
match *self {
100-
ItemId::Auto(box ImplId { for_: id, .. })
101-
| ItemId::Blanket(box ImplId { for_: id, .. })
92+
crate fn krate(self) -> CrateNum {
93+
match self {
94+
ItemId::Auto { for_: id, .. }
95+
| ItemId::Blanket { for_: id, .. }
10296
| ItemId::DefId(id) => id.krate,
10397
ItemId::Primitive(krate) => krate,
10498
}
10599
}
100+
101+
#[inline]
102+
crate fn index(self) -> Option<DefIndex> {
103+
match self {
104+
ItemId::DefId(id) => Some(id.index),
105+
_ => None,
106+
}
107+
}
106108
}
107109

108110
impl From<DefId> for ItemId {
@@ -377,7 +379,7 @@ impl Item {
377379
{
378380
*span
379381
} else {
380-
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
382+
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(|| Span::dummy())
381383
}
382384
}
383385

src/librustdoc/core.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ impl<'tcx> DocContext<'tcx> {
128128

129129
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
130130
/// (This avoids a slice-index-out-of-bounds panic.)
131-
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: &ItemId) -> Option<HirId> {
132-
match *def_id {
131+
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: ItemId) -> Option<HirId> {
132+
match def_id {
133133
ItemId::DefId(real_id) => {
134134
real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
135135
}
@@ -432,7 +432,7 @@ crate fn run_global_ctxt(
432432
);
433433
tcx.struct_lint_node(
434434
crate::lint::MISSING_CRATE_LEVEL_DOCS,
435-
DocContext::as_local_hir_id(tcx, &krate.module.def_id).unwrap(),
435+
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
436436
|lint| {
437437
let mut diag =
438438
lint.build("no documentation found for this crate's top-level module");

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
290290
// A crate has a module at its root, containing all items,
291291
// which should not be indexed. The crate-item itself is
292292
// inserted later on when serializing the search-index.
293-
if item.def_id.as_def_id().map_or(false, |did| did.index != CRATE_DEF_INDEX) {
293+
if item.def_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
294294
let desc = item.doc_value().map_or_else(String::new, |x| {
295295
short_markdown_summary(&x.as_str(), &item.link_names(&self.cache))
296296
});

src/librustdoc/html/render/mod.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ fn assoc_const(
753753
w,
754754
"{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}",
755755
extra,
756-
it.visibility.print_with_space(it.def_id.clone(), cx),
756+
it.visibility.print_with_space(it.def_id, cx),
757757
naive_assoc_href(it, link, cx),
758758
it.name.as_ref().unwrap(),
759759
ty.print(cx)
@@ -872,7 +872,7 @@ fn render_assoc_item(
872872
.unwrap_or_else(|| format!("#{}.{}", ty, name))
873873
}
874874
};
875-
let vis = meth.visibility.print_with_space(meth.def_id.clone(), cx).to_string();
875+
let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
876876
let constness =
877877
print_constness_with_space(&header.constness, meth.const_stability(cx.tcx()));
878878
let asyncness = header.asyncness.print_with_space();
@@ -984,7 +984,7 @@ fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
984984
}
985985
}
986986

987-
#[derive(Clone)]
987+
#[derive(Copy, Clone)]
988988
enum AssocItemLink<'a> {
989989
Anchor(Option<&'a str>),
990990
GotoSource(ItemId, &'a FxHashSet<Symbol>),
@@ -994,7 +994,7 @@ impl<'a> AssocItemLink<'a> {
994994
fn anchor(&self, id: &'a str) -> Self {
995995
match *self {
996996
AssocItemLink::Anchor(_) => AssocItemLink::Anchor(Some(&id)),
997-
ref other => other.clone(),
997+
ref other => *other,
998998
}
999999
}
10001000
}
@@ -1306,14 +1306,7 @@ fn render_impl(
13061306
} else {
13071307
// In case the item isn't documented,
13081308
// provide short documentation from the trait.
1309-
document_short(
1310-
&mut doc_buffer,
1311-
it,
1312-
cx,
1313-
link.clone(),
1314-
parent,
1315-
show_def_docs,
1316-
);
1309+
document_short(&mut doc_buffer, it, cx, link, parent, show_def_docs);
13171310
}
13181311
}
13191312
} else {
@@ -1324,7 +1317,7 @@ fn render_impl(
13241317
}
13251318
}
13261319
} else {
1327-
document_short(&mut doc_buffer, item, cx, link.clone(), parent, show_def_docs);
1320+
document_short(&mut doc_buffer, item, cx, link, parent, show_def_docs);
13281321
}
13291322
}
13301323
let w = if short_documented && trait_.is_some() { interesting } else { boring };
@@ -1452,7 +1445,7 @@ fn render_impl(
14521445
trait_item,
14531446
if trait_.is_some() { &i.impl_item } else { parent },
14541447
parent,
1455-
link.clone(),
1448+
link,
14561449
render_mode,
14571450
false,
14581451
trait_.map(|t| &t.trait_),

src/librustdoc/html/render/print_item.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
245245
// (which is the position in the vector).
246246
indices.dedup_by_key(|i| {
247247
(
248-
items[*i].def_id.clone(),
248+
items[*i].def_id,
249249
if items[*i].name.as_ref().is_some() { Some(full_path(cx, &items[*i])) } else { None },
250250
items[*i].type_(),
251251
if items[*i].is_import() { *i } else { 0 },
@@ -288,14 +288,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
288288
Some(ref src) => write!(
289289
w,
290290
"<div class=\"item-left\"><code>{}extern crate {} as {};",
291-
myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
291+
myitem.visibility.print_with_space(myitem.def_id, cx),
292292
anchor(myitem.def_id.expect_def_id(), &*src.as_str(), cx),
293293
myitem.name.as_ref().unwrap(),
294294
),
295295
None => write!(
296296
w,
297297
"<div class=\"item-left\"><code>{}extern crate {};",
298-
myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
298+
myitem.visibility.print_with_space(myitem.def_id, cx),
299299
anchor(
300300
myitem.def_id.expect_def_id(),
301301
&*myitem.name.as_ref().unwrap().as_str(),
@@ -336,7 +336,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
336336
<div class=\"item-right docblock-short\">{stab_tags}</div>",
337337
stab = stab.unwrap_or_default(),
338338
add = add,
339-
vis = myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
339+
vis = myitem.visibility.print_with_space(myitem.def_id, cx),
340340
imp = import.print(cx),
341341
stab_tags = stab_tags.unwrap_or_default(),
342342
);
@@ -437,7 +437,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
437437
}
438438

439439
fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
440-
let vis = it.visibility.print_with_space(it.def_id.clone(), cx).to_string();
440+
let vis = it.visibility.print_with_space(it.def_id, cx).to_string();
441441
let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx()));
442442
let asyncness = f.header.asyncness.print_with_space();
443443
let unsafety = f.header.unsafety.print_with_space();
@@ -489,7 +489,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
489489
write!(
490490
w,
491491
"{}{}{}trait {}{}{}",
492-
it.visibility.print_with_space(it.def_id.clone(), cx),
492+
it.visibility.print_with_space(it.def_id, cx),
493493
t.unsafety.print_with_space(),
494494
if t.is_auto { "auto " } else { "" },
495495
it.name.as_ref().unwrap(),
@@ -710,10 +710,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
710710

711711
for implementor in foreign {
712712
let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx());
713-
let assoc_link = AssocItemLink::GotoSource(
714-
implementor.impl_item.def_id.clone(),
715-
&provided_methods,
716-
);
713+
let assoc_link =
714+
AssocItemLink::GotoSource(implementor.impl_item.def_id, &provided_methods);
717715
render_impl(
718716
w,
719717
cx,
@@ -917,7 +915,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
917915
write!(
918916
w,
919917
"{}enum {}{}{}",
920-
it.visibility.print_with_space(it.def_id.clone(), cx),
918+
it.visibility.print_with_space(it.def_id, cx),
921919
it.name.as_ref().unwrap(),
922920
e.generics.print(cx),
923921
print_where_clause(&e.generics, cx, 0, true),
@@ -1105,7 +1103,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
11051103
write!(
11061104
w,
11071105
"{vis}const {name}: {typ}",
1108-
vis = it.visibility.print_with_space(it.def_id.clone(), cx),
1106+
vis = it.visibility.print_with_space(it.def_id, cx),
11091107
name = it.name.as_ref().unwrap(),
11101108
typ = c.type_.print(cx),
11111109
);
@@ -1195,7 +1193,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
11951193
write!(
11961194
w,
11971195
"{vis}static {mutability}{name}: {typ}</pre>",
1198-
vis = it.visibility.print_with_space(it.def_id.clone(), cx),
1196+
vis = it.visibility.print_with_space(it.def_id, cx),
11991197
mutability = s.mutability.print_with_space(),
12001198
name = it.name.as_ref().unwrap(),
12011199
typ = s.type_.print(cx)
@@ -1209,7 +1207,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
12091207
write!(
12101208
w,
12111209
" {}type {};\n}}</pre>",
1212-
it.visibility.print_with_space(it.def_id.clone(), cx),
1210+
it.visibility.print_with_space(it.def_id, cx),
12131211
it.name.as_ref().unwrap(),
12141212
);
12151213

@@ -1364,7 +1362,7 @@ fn render_union(
13641362
write!(
13651363
w,
13661364
"{}{}{}",
1367-
it.visibility.print_with_space(it.def_id.clone(), cx),
1365+
it.visibility.print_with_space(it.def_id, cx),
13681366
if structhead { "union " } else { "" },
13691367
it.name.as_ref().unwrap()
13701368
);
@@ -1386,7 +1384,7 @@ fn render_union(
13861384
write!(
13871385
w,
13881386
" {}{}: {},\n{}",
1389-
field.visibility.print_with_space(field.def_id.clone(), cx),
1387+
field.visibility.print_with_space(field.def_id, cx),
13901388
field.name.as_ref().unwrap(),
13911389
ty.print(cx),
13921390
tab
@@ -1416,7 +1414,7 @@ fn render_struct(
14161414
write!(
14171415
w,
14181416
"{}{}{}",
1419-
it.visibility.print_with_space(it.def_id.clone(), cx),
1417+
it.visibility.print_with_space(it.def_id, cx),
14201418
if structhead { "struct " } else { "" },
14211419
it.name.as_ref().unwrap()
14221420
);
@@ -1442,7 +1440,7 @@ fn render_struct(
14421440
w,
14431441
"\n{} {}{}: {},",
14441442
tab,
1445-
field.visibility.print_with_space(field.def_id.clone(), cx),
1443+
field.visibility.print_with_space(field.def_id, cx),
14461444
field.name.as_ref().unwrap(),
14471445
ty.print(cx),
14481446
);
@@ -1476,7 +1474,7 @@ fn render_struct(
14761474
write!(
14771475
w,
14781476
"{}{}",
1479-
field.visibility.print_with_space(field.def_id.clone(), cx),
1477+
field.visibility.print_with_space(field.def_id, cx),
14801478
ty.print(cx),
14811479
)
14821480
}

0 commit comments

Comments
 (0)