Skip to content

Commit 75cd8f9

Browse files
committed
rustc_typeck: remove the "preload all impls ever" workaround in coherence.
1 parent 592165f commit 75cd8f9

File tree

4 files changed

+4
-102
lines changed

4 files changed

+4
-102
lines changed

src/librustc/metadata/csearch.rs

-9
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,6 @@ pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum)
304304
decoder::get_native_libraries(&*cdata)
305305
}
306306

307-
pub fn each_impl<F>(cstore: &cstore::CStore,
308-
crate_num: ast::CrateNum,
309-
callback: F) where
310-
F: FnMut(ast::DefId),
311-
{
312-
let cdata = cstore.get_crate_data(crate_num);
313-
decoder::each_impl(&*cdata, callback)
314-
}
315-
316307
pub fn each_inherent_implementation_for_type<F>(cstore: &cstore::CStore,
317308
def_id: ast::DefId,
318309
callback: F) where

src/librustc/metadata/decoder.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1344,16 +1344,6 @@ fn reverse_translate_def_id(cdata: Cmd, did: ast::DefId) -> Option<ast::DefId> {
13441344
None
13451345
}
13461346

1347-
pub fn each_impl<F>(cdata: Cmd, mut callback: F) where
1348-
F: FnMut(ast::DefId),
1349-
{
1350-
let impls_doc = reader::get_doc(rbml::Doc::new(cdata.data()), tag_impls);
1351-
let _ = reader::tagged_docs(impls_doc, tag_impls_impl, |impl_doc| {
1352-
callback(item_def_id(impl_doc, cdata));
1353-
true
1354-
});
1355-
}
1356-
13571347
pub fn each_inherent_implementation_for_type<F>(cdata: Cmd,
13581348
id: ast::NodeId,
13591349
mut callback: F)

src/librustc_typeck/coherence/mod.rs

+3-77
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
// mappings. That mapping code resides here.
1717

1818

19-
use metadata::csearch::{each_impl, get_impl_trait};
20-
use metadata::csearch;
2119
use middle::subst::{self, Subst};
2220
use middle::ty::RegionEscape;
2321
use middle::ty::{ImplContainer, ImplOrTraitItemId, ConstTraitItemId};
24-
use middle::ty::{MethodTraitItemId, TypeTraitItemId};
25-
use middle::ty::{ParameterEnvironment, lookup_item_type};
22+
use middle::ty::{MethodTraitItemId, TypeTraitItemId, ParameterEnvironment};
2623
use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err};
2724
use middle::ty::{ty_param, TypeScheme, ty_ptr};
2825
use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup};
@@ -33,7 +30,6 @@ use middle::ty;
3330
use CrateCtxt;
3431
use middle::infer::InferCtxt;
3532
use middle::infer::new_infer_ctxt;
36-
use std::collections::HashSet;
3733
use std::cell::RefCell;
3834
use std::rc::Rc;
3935
use syntax::ast::{Crate, DefId};
@@ -130,11 +126,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
130126
Rc::new((*v.borrow()).clone()));
131127
}
132128

133-
// Bring in external crates. It's fine for this to happen after the
134-
// coherence checks, because we ensure by construction that no errors
135-
// can happen at link time.
136-
self.add_external_crates();
137-
138129
// Populate the table of destructors. It might seem a bit strange to
139130
// do this here, but it's actually the most convenient place, since
140131
// the coherence tables contain the trait -> type mappings.
@@ -267,11 +258,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
267258
trait_def.record_impl(self.crate_context.tcx, impl_def_id, impl_trait_ref);
268259
}
269260

270-
fn get_self_type_for_implementation(&self, impl_did: DefId)
271-
-> TypeScheme<'tcx> {
272-
self.crate_context.tcx.tcache.borrow().get(&impl_did).unwrap().clone()
273-
}
274-
275261
// Converts an implementation in the AST to a vector of items.
276262
fn create_impl_from_item(&self, item: &Item) -> Vec<ImplOrTraitItemId> {
277263
match item.node {
@@ -313,66 +299,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
313299
}
314300
}
315301

316-
// External crate handling
317-
318-
fn add_external_impl(&self,
319-
impls_seen: &mut HashSet<DefId>,
320-
impl_def_id: DefId) {
321-
let tcx = self.crate_context.tcx;
322-
let impl_items = csearch::get_impl_items(&tcx.sess.cstore,
323-
impl_def_id);
324-
325-
// Make sure we don't visit the same implementation multiple times.
326-
if !impls_seen.insert(impl_def_id) {
327-
// Skip this one.
328-
return
329-
}
330-
// Good. Continue.
331-
332-
let _ = lookup_item_type(tcx, impl_def_id);
333-
let associated_traits = get_impl_trait(tcx, impl_def_id);
334-
335-
// Do a sanity check.
336-
assert!(associated_traits.is_some());
337-
338-
// Record all the trait items.
339-
if let Some(trait_ref) = associated_traits {
340-
self.add_trait_impl(trait_ref, impl_def_id);
341-
}
342-
343-
// For any methods that use a default implementation, add them to
344-
// the map. This is a bit unfortunate.
345-
for item_def_id in &impl_items {
346-
let impl_item = ty::impl_or_trait_item(tcx, item_def_id.def_id());
347-
match impl_item {
348-
ty::MethodTraitItem(ref method) => {
349-
if let Some(source) = method.provided_source {
350-
tcx.provided_method_sources
351-
.borrow_mut()
352-
.insert(item_def_id.def_id(), source);
353-
}
354-
}
355-
_ => {}
356-
}
357-
}
358-
359-
tcx.impl_items.borrow_mut().insert(impl_def_id, impl_items);
360-
}
361-
362-
// Adds implementations and traits from external crates to the coherence
363-
// info.
364-
fn add_external_crates(&self) {
365-
let mut impls_seen = HashSet::new();
366-
367-
let crate_store = &self.crate_context.tcx.sess.cstore;
368-
crate_store.iter_crate_data(|crate_number, _crate_metadata| {
369-
each_impl(crate_store, crate_number, |def_id| {
370-
assert_eq!(crate_number, def_id.krate);
371-
self.add_external_impl(&mut impls_seen, def_id)
372-
})
373-
})
374-
}
375-
376302
//
377303
// Destructors
378304
//
@@ -395,7 +321,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
395321
}
396322
let method_def_id = items[0];
397323

398-
let self_type = self.get_self_type_for_implementation(impl_did);
324+
let self_type = ty::lookup_item_type(tcx, impl_did);
399325
match self_type.ty.sty {
400326
ty::ty_enum(type_def_id, _) |
401327
ty::ty_struct(type_def_id, _) |
@@ -451,7 +377,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
451377
return
452378
}
453379

454-
let self_type = self.get_self_type_for_implementation(impl_did);
380+
let self_type = ty::lookup_item_type(tcx, impl_did);
455381
debug!("check_implementations_of_copy: self_type={} (bound)",
456382
self_type.repr(tcx));
457383

src/librustc_typeck/coherence/overlap.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,9 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
4848
// check_for_overlapping_impls_of_trait() check, since that
4949
// check can populate this table further with impls from other
5050
// crates.
51-
let trait_defs : Vec<&ty::TraitDef> = {
52-
let d = self.tcx.trait_defs.borrow();
53-
d.values().map(|&v|v).collect()
54-
};
51+
let trait_defs: Vec<_> = self.tcx.trait_defs.borrow().values().cloned().collect();
5552

5653
for trait_def in trait_defs {
57-
// FIXME -- it seems like this method actually pushes
58-
// duplicate impls onto the list
5954
ty::populate_implementations_for_trait_if_necessary(
6055
self.tcx,
6156
trait_def.trait_ref.def_id);

0 commit comments

Comments
 (0)