Skip to content

Commit 89736e8

Browse files
committed
rustc: remove ImplOrTraitItemId and TraitDef's associated_type_names.
1 parent 8734aaa commit 89736e8

File tree

26 files changed

+130
-233
lines changed

26 files changed

+130
-233
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub enum DepNode<D: Clone + Debug> {
108108
ItemSignature(D),
109109
FieldTy(D),
110110
SizedConstraint(D),
111-
ImplOrTraitItemIds(D),
111+
ImplOrTraitItemDefIds(D),
112112
InherentImpls(D),
113113

114114
// The set of impls for a given trait. Ultimately, it would be
@@ -157,7 +157,7 @@ impl<D: Clone + Debug> DepNode<D> {
157157
ImplOrTraitItems,
158158
ItemSignature,
159159
FieldTy,
160-
ImplOrTraitItemIds,
160+
ImplOrTraitItemDefIds,
161161
InherentImpls,
162162
TraitImpls,
163163
ReprHints,
@@ -225,7 +225,7 @@ impl<D: Clone + Debug> DepNode<D> {
225225
ItemSignature(ref d) => op(d).map(ItemSignature),
226226
FieldTy(ref d) => op(d).map(FieldTy),
227227
SizedConstraint(ref d) => op(d).map(SizedConstraint),
228-
ImplOrTraitItemIds(ref d) => op(d).map(ImplOrTraitItemIds),
228+
ImplOrTraitItemDefIds(ref d) => op(d).map(ImplOrTraitItemDefIds),
229229
InherentImpls(ref d) => op(d).map(InherentImpls),
230230
TraitImpls(ref d) => op(d).map(TraitImpls),
231231
TraitItems(ref d) => op(d).map(TraitItems),

src/librustc/middle/cstore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub trait CrateStore<'tcx> {
157157
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
158158

159159
// impl info
160-
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
160+
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId>;
161161
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
162162
-> Option<ty::TraitRef<'tcx>>;
163163
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
@@ -329,7 +329,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
329329
}
330330

331331
// impl info
332-
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
332+
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId>
333333
{ bug!("impl_or_trait_items") }
334334
fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
335335
-> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }

src/librustc/middle/dead.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,12 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
470470
// This is done to handle the case where, for example, the static
471471
// method of a private type is used, but the type itself is never
472472
// called directly.
473-
let impl_items = self.tcx.impl_or_trait_item_ids.borrow();
473+
let impl_items = self.tcx.impl_or_trait_item_def_ids.borrow();
474474
if let Some(impl_list) =
475475
self.tcx.inherent_impls.borrow().get(&self.tcx.map.local_def_id(id)) {
476476
for impl_did in impl_list.iter() {
477-
for item_did in impl_items.get(impl_did).unwrap().iter() {
478-
if let Some(item_node_id) =
479-
self.tcx.map.as_local_node_id(item_did.def_id()) {
477+
for &item_did in &impl_items[impl_did][..] {
478+
if let Some(item_node_id) = self.tcx.map.as_local_node_id(item_did) {
480479
if self.live_symbols.contains(&item_node_id) {
481480
return true;
482481
}

src/librustc/middle/stability.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,9 @@ fn is_internal<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span) -> bool {
695695

696696
fn is_staged_api<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> bool {
697697
match tcx.trait_item_of_item(id) {
698-
Some(ty::MethodTraitItemId(trait_method_id))
699-
if trait_method_id != id => {
700-
is_staged_api(tcx, trait_method_id)
701-
}
698+
Some(trait_method_id) if trait_method_id != id => {
699+
is_staged_api(tcx, trait_method_id)
700+
}
702701
_ => {
703702
*tcx.stability.borrow_mut().staged_api.entry(id.krate).or_insert_with(
704703
|| tcx.sess.cstore.is_staged_api(id.krate))

src/librustc/traits/specialize/specialization_graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ impl<'a, 'gcx, 'tcx> Node {
304304
/// An iterator over the items defined within a trait or impl.
305305
pub struct NodeItems<'a, 'tcx: 'a> {
306306
tcx: TyCtxt<'a, 'tcx, 'tcx>,
307-
items: Rc<Vec<ty::ImplOrTraitItemId>>,
307+
items: Rc<Vec<DefId>>,
308308
idx: usize
309309
}
310310

311311
impl<'a, 'tcx> Iterator for NodeItems<'a, 'tcx> {
312312
type Item = ImplOrTraitItem<'tcx>;
313313
fn next(&mut self) -> Option<ImplOrTraitItem<'tcx>> {
314314
if self.idx < self.items.len() {
315-
let item_def_id = self.items[self.idx].def_id();
315+
let item_def_id = self.items[self.idx];
316316
let items_table = self.tcx.impl_or_trait_items.borrow();
317317
let item = items_table[&item_def_id].clone();
318318
self.idx += 1;

src/librustc/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub struct GlobalCtxt<'tcx> {
331331
pub impl_or_trait_items: RefCell<DepTrackingMap<maps::ImplOrTraitItems<'tcx>>>,
332332

333333
/// Maps from an impl/trait def-id to a list of the def-ids of its items
334-
pub impl_or_trait_item_ids: RefCell<DepTrackingMap<maps::ImplOrTraitItemIds<'tcx>>>,
334+
pub impl_or_trait_item_def_ids: RefCell<DepTrackingMap<maps::ImplOrTraitItemDefIds<'tcx>>>,
335335

336336
/// A cache for the trait_items() routine; note that the routine
337337
/// itself pushes the `TraitItems` dependency node.
@@ -728,7 +728,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
728728
rcache: RefCell::new(FnvHashMap()),
729729
tc_cache: RefCell::new(FnvHashMap()),
730730
impl_or_trait_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
731-
impl_or_trait_item_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
731+
impl_or_trait_item_def_ids: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
732732
trait_items_cache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
733733
ty_param_defs: RefCell::new(NodeMap()),
734734
normalized_cache: RefCell::new(FnvHashMap()),
@@ -1396,7 +1396,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13961396
self.trait_items_cache.memoize(trait_did, || {
13971397
let def_ids = self.impl_or_trait_items(trait_did);
13981398
Rc::new(def_ids.iter()
1399-
.map(|d| self.impl_or_trait_item(d.def_id()))
1399+
.map(|&def_id| self.impl_or_trait_item(def_id))
14001400
.collect())
14011401
})
14021402
}

src/librustc/ty/maps.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ dep_map_ty! { Tcache: ItemSignature(DefId) -> Ty<'tcx> }
3434
dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics<'tcx> }
3535
dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
3636
dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
37-
dep_map_ty! { ImplOrTraitItemIds: ImplOrTraitItemIds(DefId)
38-
-> Rc<Vec<ty::ImplOrTraitItemId>> }
37+
dep_map_ty! { ImplOrTraitItemDefIds: ImplOrTraitItemDefIds(DefId) -> Rc<Vec<DefId>> }
3938
dep_map_ty! { ImplTraitRefs: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>> }
4039
dep_map_ty! { TraitDefs: ItemSignature(DefId) -> &'tcx ty::TraitDef<'tcx> }
4140
dep_map_ty! { AdtDefs: ItemSignature(DefId) -> ty::AdtDefMaster<'tcx> }

src/librustc/ty/mod.rs

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use self::ImplOrTraitItemId::*;
1211
pub use self::Variance::*;
1312
pub use self::DtorKind::*;
1413
pub use self::ImplOrTraitItemContainer::*;
@@ -190,18 +189,6 @@ pub enum ImplOrTraitItem<'tcx> {
190189
}
191190

192191
impl<'tcx> ImplOrTraitItem<'tcx> {
193-
fn id(&self) -> ImplOrTraitItemId {
194-
match *self {
195-
ConstTraitItem(ref associated_const) => {
196-
ConstTraitItemId(associated_const.def_id)
197-
}
198-
MethodTraitItem(ref method) => MethodTraitItemId(method.def_id),
199-
TypeTraitItem(ref associated_type) => {
200-
TypeTraitItemId(associated_type.def_id)
201-
}
202-
}
203-
}
204-
205192
pub fn def(&self) -> Def {
206193
match *self {
207194
ConstTraitItem(ref associated_const) => Def::AssociatedConst(associated_const.def_id),
@@ -250,23 +237,6 @@ impl<'tcx> ImplOrTraitItem<'tcx> {
250237
}
251238
}
252239

253-
#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable)]
254-
pub enum ImplOrTraitItemId {
255-
ConstTraitItemId(DefId),
256-
MethodTraitItemId(DefId),
257-
TypeTraitItemId(DefId),
258-
}
259-
260-
impl ImplOrTraitItemId {
261-
pub fn def_id(&self) -> DefId {
262-
match *self {
263-
ConstTraitItemId(def_id) => def_id,
264-
MethodTraitItemId(def_id) => def_id,
265-
TypeTraitItemId(def_id) => def_id,
266-
}
267-
}
268-
}
269-
270240
#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable)]
271241
pub enum Visibility {
272242
/// Visible everywhere (including in other crates).
@@ -2276,8 +2246,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22762246
}
22772247

22782248
pub fn provided_trait_methods(self, id: DefId) -> Vec<Rc<Method<'gcx>>> {
2279-
self.impl_or_trait_items(id).iter().filter_map(|id| {
2280-
match self.impl_or_trait_item(id.def_id()) {
2249+
self.impl_or_trait_items(id).iter().filter_map(|&def_id| {
2250+
match self.impl_or_trait_item(def_id) {
22812251
MethodTraitItem(ref m) if m.has_body => Some(m.clone()),
22822252
_ => None
22832253
}
@@ -2321,9 +2291,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23212291
.expect("missing ImplOrTraitItem in metadata"))
23222292
}
23232293

2324-
pub fn impl_or_trait_items(self, id: DefId) -> Rc<Vec<ImplOrTraitItemId>> {
2294+
pub fn impl_or_trait_items(self, id: DefId) -> Rc<Vec<DefId>> {
23252295
lookup_locally_or_in_crate_store(
2326-
"impl_or_trait_items", id, &self.impl_or_trait_item_ids,
2296+
"impl_or_trait_items", id, &self.impl_or_trait_item_def_ids,
23272297
|| Rc::new(self.sess.cstore.impl_or_trait_items(id)))
23282298
}
23292299

@@ -2600,7 +2570,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26002570
let impl_items = self.sess.cstore.impl_or_trait_items(primitive_def_id);
26012571

26022572
// Store the implementation info.
2603-
self.impl_or_trait_item_ids.borrow_mut().insert(primitive_def_id, Rc::new(impl_items));
2573+
self.impl_or_trait_item_def_ids.borrow_mut().insert(primitive_def_id, Rc::new(impl_items));
26042574
self.populated_external_primitive_impls.borrow_mut().insert(primitive_def_id);
26052575
}
26062576

@@ -2627,7 +2597,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26272597
for &impl_def_id in &inherent_impls {
26282598
// Store the implementation info.
26292599
let impl_items = self.sess.cstore.impl_or_trait_items(impl_def_id);
2630-
self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
2600+
self.impl_or_trait_item_def_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
26312601
}
26322602

26332603
self.inherent_impls.borrow_mut().insert(type_id, inherent_impls);
@@ -2669,15 +2639,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26692639

26702640
// For any methods that use a default implementation, add them to
26712641
// the map. This is a bit unfortunate.
2672-
for impl_item_def_id in &impl_items {
2673-
let method_def_id = impl_item_def_id.def_id();
2642+
for &impl_item_def_id in &impl_items {
26742643
// load impl items eagerly for convenience
26752644
// FIXME: we may want to load these lazily
2676-
self.impl_or_trait_item(method_def_id);
2645+
self.impl_or_trait_item(impl_item_def_id);
26772646
}
26782647

26792648
// Store the implementation info.
2680-
self.impl_or_trait_item_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
2649+
self.impl_or_trait_item_def_ids.borrow_mut().insert(impl_def_id, Rc::new(impl_items));
26812650
}
26822651

26832652
def.flags.set(def.flags.get() | TraitFlags::IMPLS_VALID);
@@ -2766,19 +2735,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27662735
/// is already that of the original trait method, then the return value is
27672736
/// the same).
27682737
/// Otherwise, return `None`.
2769-
pub fn trait_item_of_item(self, def_id: DefId) -> Option<ImplOrTraitItemId> {
2738+
pub fn trait_item_of_item(self, def_id: DefId) -> Option<DefId> {
27702739
let impl_or_trait_item = match self.impl_or_trait_items.borrow().get(&def_id) {
27712740
Some(m) => m.clone(),
27722741
None => return None,
27732742
};
27742743
match impl_or_trait_item.container() {
2775-
TraitContainer(_) => Some(impl_or_trait_item.id()),
2744+
TraitContainer(_) => Some(impl_or_trait_item.def_id()),
27762745
ImplContainer(def_id) => {
27772746
self.trait_id_of_impl(def_id).and_then(|trait_did| {
27782747
let name = impl_or_trait_item.name();
27792748
self.trait_items(trait_did).iter()
27802749
.find(|item| item.name() == name)
2781-
.map(|item| item.id())
2750+
.map(|item| item.def_id())
27822751
})
27832752
}
27842753
}

src/librustc/ty/trait_def.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use ty;
1515
use ty::fast_reject;
1616
use ty::{Ty, TyCtxt, TraitRef};
1717
use std::cell::{Cell, RefCell};
18-
use syntax::ast::Name;
1918
use hir;
2019
use util::nodemap::FnvHashMap;
2120

@@ -38,10 +37,6 @@ pub struct TraitDef<'tcx> {
3837

3938
pub trait_ref: ty::TraitRef<'tcx>,
4039

41-
/// A list of the associated types defined in this trait. Useful
42-
/// for resolving `X::Foo` type markers.
43-
pub associated_type_names: Vec<Name>,
44-
4540
// Impls of a trait. To allow for quicker lookup, the impls are indexed by a
4641
// simplified version of their `Self` type: impls with a simplifiable `Self`
4742
// are stored in `nonblanket_impls` keyed by it, while all other impls are
@@ -82,15 +77,13 @@ impl<'a, 'gcx, 'tcx> TraitDef<'tcx> {
8277
paren_sugar: bool,
8378
generics: &'tcx ty::Generics<'tcx>,
8479
trait_ref: ty::TraitRef<'tcx>,
85-
associated_type_names: Vec<Name>,
8680
def_path_hash: u64)
8781
-> TraitDef<'tcx> {
8882
TraitDef {
8983
paren_sugar: paren_sugar,
9084
unsafety: unsafety,
9185
generics: generics,
9286
trait_ref: trait_ref,
93-
associated_type_names: associated_type_names,
9487
nonblanket_impls: RefCell::new(FnvHashMap()),
9588
blanket_impls: RefCell::new(vec![]),
9689
flags: Cell::new(ty::TraitFlags::NO_TRAIT_FLAGS),

src/librustc_const_eval/eval.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,14 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10811081
match selection {
10821082
traits::VtableImpl(ref impl_data) => {
10831083
let ac = tcx.impl_or_trait_items(impl_data.impl_def_id)
1084-
.iter().filter_map(|id| {
1085-
match *id {
1086-
ty::ConstTraitItemId(def_id) => {
1087-
Some(tcx.impl_or_trait_item(def_id))
1088-
}
1084+
.iter().filter_map(|&def_id| {
1085+
match tcx.impl_or_trait_item(def_id) {
1086+
ty::ConstTraitItem(ic) => Some(ic),
10891087
_ => None
10901088
}
1091-
}).find(|ic| ic.name() == ti.name);
1089+
}).find(|ic| ic.name == ti.name);
10921090
match ac {
1093-
Some(ic) => lookup_const_by_id(tcx, ic.def_id(), None),
1091+
Some(ic) => lookup_const_by_id(tcx, ic.def_id, None),
10941092
None => match ti.node {
10951093
hir::ConstTraitItem(ref ty, Some(ref expr)) => {
10961094
Some((&*expr, tcx.ast_ty_to_prim_ty(ty)))

src/librustc_metadata/common.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ pub const tag_item_predicates: usize = 0x95;
166166

167167
pub const tag_unsafety: usize = 0x9a;
168168

169-
pub const tag_associated_type_names: usize = 0x9b;
170-
pub const tag_associated_type_name: usize = 0x9c;
171-
172169
pub const tag_polarity: usize = 0x9d;
173170

174171
pub const tag_macro_defs: usize = 0x10e; // top-level only

src/librustc_metadata/csearch.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,15 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
179179
result
180180
}
181181

182-
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<ty::ImplOrTraitItemId> {
182+
fn impl_or_trait_items(&self, def_id: DefId) -> Vec<DefId> {
183183
self.dep_graph.read(DepNode::MetaData(def_id));
184-
let cdata = self.get_crate_data(def_id.krate);
185-
decoder::get_impl_or_trait_items(&cdata, def_id.index)
184+
let mut result = vec![];
185+
let crate_data = self.get_crate_data(def_id.krate);
186+
let get_crate_data = |cnum| self.get_crate_data(cnum);
187+
decoder::each_child_of_item(&crate_data, def_id.index, get_crate_data, |def, _, _| {
188+
result.push(def.def_id());
189+
});
190+
result
186191
}
187192

188193
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity

0 commit comments

Comments
 (0)