Skip to content

Commit e62f483

Browse files
committed
Create trait_def table.
1 parent 618138b commit e62f483

File tree

6 files changed

+16
-72
lines changed

6 files changed

+16
-72
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -909,37 +909,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
909909
)
910910
}
911911

912-
fn get_trait_def(self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
913-
match self.kind(item_id) {
914-
EntryKind::Trait(data) => {
915-
let data = data.decode((self, sess));
916-
ty::TraitDef::new(
917-
self.local_def_id(item_id),
918-
data.unsafety,
919-
data.paren_sugar,
920-
data.has_auto_impl,
921-
data.is_marker,
922-
data.skip_array_during_method_dispatch,
923-
data.specialization_kind,
924-
self.def_path_hash(item_id),
925-
data.must_implement_one_of,
926-
)
927-
}
928-
EntryKind::TraitAlias => ty::TraitDef::new(
929-
self.local_def_id(item_id),
930-
hir::Unsafety::Normal,
931-
false,
932-
false,
933-
false,
934-
false,
935-
ty::trait_def::TraitSpecializationKind::None,
936-
self.def_path_hash(item_id),
937-
None,
938-
),
939-
_ => bug!("def-index does not refer to trait or trait alias"),
940-
}
941-
}
942-
943912
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
944913
let data = match kind {
945914
EntryKind::Variant(data) | EntryKind::Struct(data) | EntryKind::Union(data) => {
@@ -1172,7 +1141,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11721141
callback(exp);
11731142
}
11741143
}
1175-
EntryKind::Enum | EntryKind::Trait(..) => {}
1144+
EntryKind::Enum | EntryKind::Trait => {}
11761145
_ => bug!("`for_each_module_child` is called on a non-module: {:?}", self.def_kind(id)),
11771146
}
11781147
}
@@ -1187,7 +1156,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11871156

11881157
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
11891158
match self.kind(id) {
1190-
EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait(_) => {
1159+
EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait => {
11911160
self.get_expn_that_defined(id, sess)
11921161
}
11931162
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
@@ -1396,7 +1365,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13961365
_ => return None,
13971366
}
13981367
def_key.parent.and_then(|parent_index| match self.kind(parent_index) {
1399-
EntryKind::Trait(_) | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
1368+
EntryKind::Trait | EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
14001369
_ => None,
14011370
})
14021371
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
153153
asyncness => { table }
154154
fn_arg_names => { table }
155155
generator_kind => { table }
156+
trait_def => { table }
156157

157-
trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
158158
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
159159
adt_destructor => {
160160
let _ = cdata;

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,19 +1474,16 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14741474
}
14751475
hir::ItemKind::Trait(..) => {
14761476
let trait_def = self.tcx.trait_def(def_id);
1477-
let data = TraitData {
1478-
unsafety: trait_def.unsafety,
1479-
paren_sugar: trait_def.paren_sugar,
1480-
has_auto_impl: self.tcx.trait_is_auto(def_id),
1481-
is_marker: trait_def.is_marker,
1482-
skip_array_during_method_dispatch: trait_def.skip_array_during_method_dispatch,
1483-
specialization_kind: trait_def.specialization_kind,
1484-
must_implement_one_of: trait_def.must_implement_one_of.clone(),
1485-
};
1477+
record!(self.tables.trait_def[def_id] <- trait_def);
1478+
1479+
EntryKind::Trait
1480+
}
1481+
hir::ItemKind::TraitAlias(..) => {
1482+
let trait_def = self.tcx.trait_def(def_id);
1483+
record!(self.tables.trait_def[def_id] <- trait_def);
14861484

1487-
EntryKind::Trait(self.lazy(data))
1485+
EntryKind::TraitAlias
14881486
}
1489-
hir::ItemKind::TraitAlias(..) => EntryKind::TraitAlias,
14901487
hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) => {
14911488
bug!("cannot encode info for item {:?}", item)
14921489
}

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ define_tables! {
320320
asyncness: Table<DefIndex, Lazy!(hir::IsAsync)>,
321321
fn_arg_names: Table<DefIndex, Lazy!([Ident])>,
322322
generator_kind: Table<DefIndex, Lazy!(hir::GeneratorKind)>,
323+
trait_def: Table<DefIndex, Lazy!(ty::TraitDef)>,
323324

324325
trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
325326
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
@@ -360,7 +361,7 @@ enum EntryKind {
360361
ProcMacro(MacroKind),
361362
Closure,
362363
Generator,
363-
Trait(Lazy<TraitData>),
364+
Trait,
364365
Impl,
365366
AssocFn(Lazy<AssocFnData>),
366367
AssocType(AssocContainer),
@@ -377,17 +378,6 @@ struct VariantData {
377378
is_non_exhaustive: bool,
378379
}
379380

380-
#[derive(TyEncodable, TyDecodable)]
381-
struct TraitData {
382-
unsafety: hir::Unsafety,
383-
paren_sugar: bool,
384-
has_auto_impl: bool,
385-
is_marker: bool,
386-
skip_array_during_method_dispatch: bool,
387-
specialization_kind: ty::trait_def::TraitSpecializationKind,
388-
must_implement_one_of: Option<Box<[Ident]>>,
389-
}
390-
391381
/// Describes whether the container of an associated item
392382
/// is a trait or an impl and whether, in a trait, it has
393383
/// a default, or an in impl, whether it's marked "default".

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ use crate::ty::{Ident, Ty, TyCtxt};
55
use hir::def_id::LOCAL_CRATE;
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
8-
use rustc_hir::definitions::DefPathHash;
98
use std::iter;
109

1110
use rustc_data_structures::fx::FxIndexMap;
1211
use rustc_errors::ErrorGuaranteed;
1312
use rustc_macros::HashStable;
1413

1514
/// A trait's definition with type information.
16-
#[derive(HashStable)]
15+
#[derive(HashStable, Encodable, Decodable)]
1716
pub struct TraitDef {
18-
// We already have the def_path_hash below, no need to hash it twice
19-
#[stable_hasher(ignore)]
2017
pub def_id: DefId,
2118

2219
pub unsafety: hir::Unsafety,
@@ -43,18 +40,14 @@ pub struct TraitDef {
4340
/// on this trait.
4441
pub specialization_kind: TraitSpecializationKind,
4542

46-
/// The ICH of this trait's DefPath, cached here so it doesn't have to be
47-
/// recomputed all the time.
48-
pub def_path_hash: DefPathHash,
49-
5043
/// List of functions from `#[rustc_must_implement_one_of]` attribute one of which
5144
/// must be implemented.
5245
pub must_implement_one_of: Option<Box<[Ident]>>,
5346
}
5447

5548
/// Whether this trait is treated specially by the standard library
5649
/// specialization lint.
57-
#[derive(HashStable, PartialEq, Clone, Copy, TyEncodable, TyDecodable)]
50+
#[derive(HashStable, PartialEq, Clone, Copy, Encodable, Decodable)]
5851
pub enum TraitSpecializationKind {
5952
/// The default. Specializing on this trait is not allowed.
6053
None,
@@ -92,7 +85,6 @@ impl<'tcx> TraitDef {
9285
is_marker: bool,
9386
skip_array_during_method_dispatch: bool,
9487
specialization_kind: TraitSpecializationKind,
95-
def_path_hash: DefPathHash,
9688
must_implement_one_of: Option<Box<[Ident]>>,
9789
) -> TraitDef {
9890
TraitDef {
@@ -103,7 +95,6 @@ impl<'tcx> TraitDef {
10395
is_marker,
10496
skip_array_during_method_dispatch,
10597
specialization_kind,
106-
def_path_hash,
10798
must_implement_one_of,
10899
}
109100
}

compiler/rustc_typeck/src/collect.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
12181218
} else {
12191219
ty::trait_def::TraitSpecializationKind::None
12201220
};
1221-
let def_path_hash = tcx.def_path_hash(def_id);
1222-
12231221
let must_implement_one_of = tcx
12241222
.get_attrs(def_id)
12251223
.iter()
@@ -1326,7 +1324,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
13261324
is_marker,
13271325
skip_array_during_method_dispatch,
13281326
spec_kind,
1329-
def_path_hash,
13301327
must_implement_one_of,
13311328
)
13321329
}

0 commit comments

Comments
 (0)