Skip to content

Commit 47c04bf

Browse files
committed
---
yaml --- r: 111508 b: refs/heads/master c: 1e5a112 h: refs/heads/master v: v3
1 parent 16bc29f commit 47c04bf

File tree

10 files changed

+157
-190
lines changed

10 files changed

+157
-190
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8f3cfe064bf4669082ec2d195f214cc36b36b568
2+
refs/heads/master: 1e5a112922fbac2a6f2d0aa9e6eb90bc3a4422a5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b5dd3f05fe95168b5569d0f519636149479eb6ac
55
refs/heads/try: 38201d7c6bf0c32b0e5bdc8ecd63976ebc1b3a4c

trunk/src/librustc/metadata/csearch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ pub fn get_enum_variants(tcx: &ty::ctxt, def: ast::DefId)
114114
}
115115

116116
/// Returns information about the given implementation.
117-
pub fn get_impl(tcx: &ty::ctxt, impl_def_id: ast::DefId)
118-
-> ty::Impl {
119-
let cdata = tcx.sess.cstore.get_crate_data(impl_def_id.krate);
120-
decoder::get_impl(tcx.sess.cstore.intr.clone(), &*cdata, impl_def_id.node, tcx)
117+
pub fn get_impl_methods(cstore: &cstore::CStore, impl_def_id: ast::DefId)
118+
-> Vec<ast::DefId> {
119+
let cdata = cstore.get_crate_data(impl_def_id.krate);
120+
decoder::get_impl_methods(&*cdata, impl_def_id.node)
121121
}
122122

123123
pub fn get_method(tcx: &ty::ctxt, def: ast::DefId) -> ty::Method {

trunk/src/librustc/metadata/decoder.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -733,32 +733,17 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
733733
}
734734
}
735735

736-
fn item_impl_methods(intr: Rc<IdentInterner>, cdata: Cmd, item: ebml::Doc,
737-
tcx: &ty::ctxt) -> Vec<@ty::Method> {
738-
let mut rslt = Vec::new();
739-
reader::tagged_docs(item, tag_item_impl_method, |doc| {
736+
/// Returns information about the given implementation.
737+
pub fn get_impl_methods(cdata: Cmd, impl_id: ast::NodeId) -> Vec<ast::DefId> {
738+
let mut methods = Vec::new();
739+
reader::tagged_docs(lookup_item(impl_id, cdata.data()),
740+
tag_item_impl_method, |doc| {
740741
let m_did = reader::with_doc_data(doc, parse_def_id);
741-
rslt.push(@get_method(intr.clone(), cdata, m_did.node, tcx));
742+
methods.push(translate_def_id(cdata, m_did));
742743
true
743744
});
744745

745-
rslt
746-
}
747-
748-
/// Returns information about the given implementation.
749-
pub fn get_impl(intr: Rc<IdentInterner>, cdata: Cmd, impl_id: ast::NodeId,
750-
tcx: &ty::ctxt)
751-
-> ty::Impl {
752-
let data = cdata.data();
753-
let impl_item = lookup_item(impl_id, data);
754-
ty::Impl {
755-
did: ast::DefId {
756-
krate: cdata.cnum,
757-
node: impl_id,
758-
},
759-
ident: item_name(&*intr, impl_item),
760-
methods: item_impl_methods(intr, cdata, impl_item, tcx),
761-
}
746+
methods
762747
}
763748

764749
pub fn get_method_name_and_explicit_self(

trunk/src/librustc/metadata/encoder.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,12 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
398398
ebml_w: &mut Encoder,
399399
exp: &middle::resolve::Export2)
400400
-> bool {
401+
let impl_methods = ecx.tcx.impl_methods.borrow();
401402
match ecx.tcx.inherent_impls.borrow().find(&exp.def_id) {
402403
Some(implementations) => {
403-
for &base_impl in implementations.borrow().iter() {
404-
for &m in base_impl.methods.iter() {
404+
for base_impl_did in implementations.borrow().iter() {
405+
for &method_did in impl_methods.get(base_impl_did).iter() {
406+
let m = ty::method(ecx.tcx, method_did);
405407
if m.explicit_self == ast::SelfStatic {
406408
encode_reexported_static_method(ebml_w, exp, m.def_id, m.ident);
407409
}
@@ -822,9 +824,9 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
822824
match ecx.tcx.inherent_impls.borrow().find(&def_id) {
823825
None => {}
824826
Some(implementations) => {
825-
for implementation in implementations.borrow().iter() {
827+
for &impl_def_id in implementations.borrow().iter() {
826828
ebml_w.start_tag(tag_items_data_item_inherent_impl);
827-
encode_def_id(ebml_w, implementation.did);
829+
encode_def_id(ebml_w, impl_def_id);
828830
ebml_w.end_tag();
829831
}
830832
}
@@ -838,9 +840,9 @@ fn encode_extension_implementations(ecx: &EncodeContext,
838840
match ecx.tcx.trait_impls.borrow().find(&trait_def_id) {
839841
None => {}
840842
Some(implementations) => {
841-
for implementation in implementations.borrow().iter() {
843+
for &impl_def_id in implementations.borrow().iter() {
842844
ebml_w.start_tag(tag_items_data_item_extension_impl);
843-
encode_def_id(ebml_w, implementation.did);
845+
encode_def_id(ebml_w, impl_def_id);
844846
ebml_w.end_tag();
845847
}
846848
}
@@ -1028,8 +1030,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
10281030
ItemImpl(_, ref opt_trait, ty, ref ast_methods) => {
10291031
// We need to encode information about the default methods we
10301032
// have inherited, so we drive this based on the impl structure.
1031-
let impls = tcx.impls.borrow();
1032-
let imp = impls.get(&def_id);
1033+
let impl_methods = tcx.impl_methods.borrow();
1034+
let methods = impl_methods.get(&def_id);
10331035

10341036
add_to_index(item, ebml_w, index);
10351037
ebml_w.start_tag(tag_items_data_item);
@@ -1046,9 +1048,9 @@ fn encode_info_for_item(ecx: &EncodeContext,
10461048
}
10471049
_ => {}
10481050
}
1049-
for method in imp.methods.iter() {
1051+
for &method_def_id in methods.iter() {
10501052
ebml_w.start_tag(tag_item_impl_method);
1051-
let s = def_to_str(method.def_id);
1053+
let s = def_to_str(method_def_id);
10521054
ebml_w.writer.write(s.as_bytes());
10531055
ebml_w.end_tag();
10541056
}
@@ -1067,18 +1069,19 @@ fn encode_info_for_item(ecx: &EncodeContext,
10671069
// appear first in the impl structure, in the same order they do
10681070
// in the ast. This is a little sketchy.
10691071
let num_implemented_methods = ast_methods.len();
1070-
for (i, m) in imp.methods.iter().enumerate() {
1072+
for (i, &method_def_id) in methods.iter().enumerate() {
10711073
let ast_method = if i < num_implemented_methods {
10721074
Some(*ast_methods.get(i))
10731075
} else { None };
10741076

10751077
index.push(entry {
1076-
val: m.def_id.node as i64,
1078+
val: method_def_id.node as i64,
10771079
pos: ebml_w.writer.tell().unwrap(),
10781080
});
1081+
let m = ty::method(tcx, method_def_id);
10791082
encode_info_for_method(ecx,
10801083
ebml_w,
1081-
*m,
1084+
m,
10821085
path.clone(),
10831086
false,
10841087
item.id,

trunk/src/librustc/middle/dead.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ impl<'a> DeadVisitor<'a> {
336336
// This is done to handle the case where, for example, the static
337337
// method of a private type is used, but the type itself is never
338338
// called directly.
339-
let def_id = local_def(id);
340-
match self.tcx.inherent_impls.borrow().find(&def_id) {
339+
let impl_methods = self.tcx.impl_methods.borrow();
340+
match self.tcx.inherent_impls.borrow().find(&local_def(id)) {
341341
None => (),
342342
Some(impl_list) => {
343-
for impl_ in impl_list.borrow().iter() {
344-
for method in impl_.methods.iter() {
345-
if self.live_symbols.contains(&method.def_id.node) {
343+
for impl_did in impl_list.borrow().iter() {
344+
for method_did in impl_methods.get(impl_did).iter() {
345+
if self.live_symbols.contains(&method_did.node) {
346346
return true;
347347
}
348348
}

trunk/src/librustc/middle/trans/meth.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,22 @@ pub fn trans_static_method_callee(bcx: &Block,
221221
}
222222
}
223223

224-
pub fn method_with_name(ccx: &CrateContext,
225-
impl_id: ast::DefId,
226-
name: ast::Name) -> ast::DefId {
224+
fn method_with_name(ccx: &CrateContext,
225+
impl_id: ast::DefId,
226+
name: ast::Name) -> ast::DefId {
227227
match ccx.impl_method_cache.borrow().find_copy(&(impl_id, name)) {
228228
Some(m) => return m,
229229
None => {}
230230
}
231231

232-
let imp = ccx.tcx.impls.borrow();
233-
let imp = imp.find(&impl_id)
234-
.expect("could not find impl while translating");
235-
let meth = imp.methods.iter().find(|m| m.ident.name == name)
236-
.expect("could not find method while translating");
232+
let methods = ccx.tcx.impl_methods.borrow();
233+
let methods = methods.find(&impl_id)
234+
.expect("could not find impl while translating");
235+
let meth_did = methods.iter().find(|&did| ty::method(&ccx.tcx, *did).ident.name == name)
236+
.expect("could not find method while translating");
237237

238-
ccx.impl_method_cache.borrow_mut().insert((impl_id, name), meth.def_id);
239-
meth.def_id
238+
ccx.impl_method_cache.borrow_mut().insert((impl_id, name), *meth_did);
239+
*meth_did
240240
}
241241

242242
fn trans_monomorphized_callee<'a>(bcx: &'a Block<'a>,

trunk/src/librustc/middle/ty.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ impl Method {
116116
}
117117
}
118118

119-
pub struct Impl {
120-
pub did: DefId,
121-
pub ident: Ident,
122-
pub methods: Vec<@Method>,
123-
}
124-
125119
#[deriving(Clone, Eq, TotalEq, Hash)]
126120
pub struct mt {
127121
pub ty: t,
@@ -320,18 +314,18 @@ pub struct ctxt {
320314
pub destructors: RefCell<DefIdSet>,
321315

322316
// Maps a trait onto a list of impls of that trait.
323-
pub trait_impls: RefCell<DefIdMap<@RefCell<Vec<@Impl>>>>,
317+
pub trait_impls: RefCell<DefIdMap<@RefCell<Vec<ast::DefId>>>>,
324318

325-
// Maps a def_id of a type to a list of its inherent impls.
319+
// Maps a DefId of a type to a list of its inherent impls.
326320
// Contains implementations of methods that are inherent to a type.
327321
// Methods in these implementations don't need to be exported.
328-
pub inherent_impls: RefCell<DefIdMap<@RefCell<Vec<@Impl>>>>,
322+
pub inherent_impls: RefCell<DefIdMap<@RefCell<Vec<ast::DefId>>>>,
329323

330-
// Maps a def_id of an impl to an Impl structure.
324+
// Maps a DefId of an impl to a list of its methods.
331325
// Note that this contains all of the impls that we know about,
332326
// including ones in other crates. It's not clear that this is the best
333327
// way to do it.
334-
pub impls: RefCell<DefIdMap<@Impl>>,
328+
pub impl_methods: RefCell<DefIdMap<Vec<ast::DefId>>>,
335329

336330
// Set of used unsafe nodes (functions or blocks). Unsafe nodes not
337331
// present in this set can be warned about.
@@ -1126,7 +1120,7 @@ pub fn mk_ctxt(s: Session,
11261120
destructors: RefCell::new(DefIdSet::new()),
11271121
trait_impls: RefCell::new(DefIdMap::new()),
11281122
inherent_impls: RefCell::new(DefIdMap::new()),
1129-
impls: RefCell::new(DefIdMap::new()),
1123+
impl_methods: RefCell::new(DefIdMap::new()),
11301124
used_unsafe: RefCell::new(NodeSet::new()),
11311125
used_mut_nodes: RefCell::new(NodeSet::new()),
11321126
impl_vtables: RefCell::new(DefIdMap::new()),
@@ -4384,15 +4378,15 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> @ItemVariances {
43844378
/// Records a trait-to-implementation mapping.
43854379
pub fn record_trait_implementation(tcx: &ctxt,
43864380
trait_def_id: DefId,
4387-
implementation: @Impl) {
4381+
impl_def_id: DefId) {
43884382
match tcx.trait_impls.borrow().find(&trait_def_id) {
43894383
Some(impls_for_trait) => {
4390-
impls_for_trait.borrow_mut().push(implementation);
4384+
impls_for_trait.borrow_mut().push(impl_def_id);
43914385
return;
43924386
}
43934387
None => {}
43944388
}
4395-
tcx.trait_impls.borrow_mut().insert(trait_def_id, @RefCell::new(vec!(implementation)));
4389+
tcx.trait_impls.borrow_mut().insert(trait_def_id, @RefCell::new(vec!(impl_def_id)));
43964390
}
43974391

43984392
/// Populates the type context with all the implementations for the given type
@@ -4407,40 +4401,36 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
44074401
}
44084402

44094403
csearch::each_implementation_for_type(&tcx.sess.cstore, type_id,
4410-
|implementation_def_id| {
4411-
let implementation = @csearch::get_impl(tcx, implementation_def_id);
4404+
|impl_def_id| {
4405+
let methods = csearch::get_impl_methods(&tcx.sess.cstore, impl_def_id);
44124406

44134407
// Record the trait->implementation mappings, if applicable.
4414-
let associated_traits = csearch::get_impl_trait(tcx,
4415-
implementation.did);
4408+
let associated_traits = csearch::get_impl_trait(tcx, impl_def_id);
44164409
for trait_ref in associated_traits.iter() {
4417-
record_trait_implementation(tcx,
4418-
trait_ref.def_id,
4419-
implementation);
4410+
record_trait_implementation(tcx, trait_ref.def_id, impl_def_id);
44204411
}
44214412

44224413
// For any methods that use a default implementation, add them to
44234414
// the map. This is a bit unfortunate.
4424-
for method in implementation.methods.iter() {
4425-
for source in method.provided_source.iter() {
4426-
tcx.provided_method_sources.borrow_mut()
4427-
.insert(method.def_id, *source);
4415+
for &method_def_id in methods.iter() {
4416+
for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4417+
tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
44284418
}
44294419
}
44304420

44314421
// Store the implementation info.
4432-
tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
4422+
tcx.impl_methods.borrow_mut().insert(impl_def_id, methods);
44334423

44344424
// If this is an inherent implementation, record it.
44354425
if associated_traits.is_none() {
44364426
match tcx.inherent_impls.borrow().find(&type_id) {
44374427
Some(implementation_list) => {
4438-
implementation_list.borrow_mut().push(implementation);
4428+
implementation_list.borrow_mut().push(impl_def_id);
44394429
return;
44404430
}
44414431
None => {}
44424432
}
4443-
tcx.inherent_impls.borrow_mut().insert(type_id, @RefCell::new(vec!(implementation)));
4433+
tcx.inherent_impls.borrow_mut().insert(type_id, @RefCell::new(vec!(impl_def_id)));
44444434
}
44454435
});
44464436

@@ -4461,22 +4451,21 @@ pub fn populate_implementations_for_trait_if_necessary(
44614451

44624452
csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id,
44634453
|implementation_def_id| {
4464-
let implementation = @csearch::get_impl(tcx, implementation_def_id);
4454+
let methods = csearch::get_impl_methods(&tcx.sess.cstore, implementation_def_id);
44654455

44664456
// Record the trait->implementation mapping.
4467-
record_trait_implementation(tcx, trait_id, implementation);
4457+
record_trait_implementation(tcx, trait_id, implementation_def_id);
44684458

44694459
// For any methods that use a default implementation, add them to
44704460
// the map. This is a bit unfortunate.
4471-
for method in implementation.methods.iter() {
4472-
for source in method.provided_source.iter() {
4473-
tcx.provided_method_sources.borrow_mut()
4474-
.insert(method.def_id, *source);
4461+
for &method_def_id in methods.iter() {
4462+
for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4463+
tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
44754464
}
44764465
}
44774466

44784467
// Store the implementation info.
4479-
tcx.impls.borrow_mut().insert(implementation_def_id, implementation);
4468+
tcx.impl_methods.borrow_mut().insert(implementation_def_id, methods);
44804469
});
44814470

44824471
tcx.populated_external_traits.borrow_mut().insert(trait_id);

0 commit comments

Comments
 (0)