Skip to content

Commit 2ea6120

Browse files
committed
Get rid of resolve::MethodInfo. Closes #4946.
1 parent f0a69b1 commit 2ea6120

File tree

8 files changed

+44
-84
lines changed

8 files changed

+44
-84
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use metadata::common::*;
1515
use metadata::cstore;
1616
use metadata::decoder;
1717
use metadata;
18-
use middle::{ty, resolve};
18+
use middle::ty;
1919

2020
use std::vec;
2121
use reader = extra::ebml::reader;
@@ -97,10 +97,10 @@ pub fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id)
9797
}
9898

9999
/// Returns information about the given implementation.
100-
pub fn get_impl(cstore: @mut cstore::CStore, impl_def_id: ast::def_id)
101-
-> resolve::Impl {
102-
let cdata = cstore::get_crate_data(cstore, impl_def_id.crate);
103-
decoder::get_impl(cstore.intr, cdata, impl_def_id.node)
100+
pub fn get_impl(tcx: ty::ctxt, impl_def_id: ast::def_id)
101+
-> ty::Impl {
102+
let cdata = cstore::get_crate_data(tcx.cstore, impl_def_id.crate);
103+
decoder::get_impl(tcx.cstore.intr, cdata, impl_def_id.node, tcx)
104104
}
105105

106106
pub fn get_method(tcx: ty::ctxt, def: ast::def_id) -> ty::Method {

src/librustc/metadata/decoder.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use metadata::decoder;
2020
use metadata::tydecode::{parse_ty_data, parse_def_id,
2121
parse_type_param_def_data,
2222
parse_bare_fn_ty_data, parse_trait_ref_data};
23-
use middle::{ty, resolve};
23+
use middle::ty;
2424

2525
use std::hash::HashUtil;
2626
use std::int;
@@ -795,34 +795,29 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
795795
}
796796

797797
fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
798-
base_tps: uint) -> ~[@resolve::MethodInfo] {
798+
tcx: ty::ctxt) -> ~[@ty::Method] {
799799
let mut rslt = ~[];
800800
for reader::tagged_docs(item, tag_item_impl_method) |doc| {
801801
let m_did = reader::with_doc_data(doc, parse_def_id);
802-
let mth_item = lookup_item(m_did.node, cdata.data);
803-
let explicit_self = get_explicit_self(mth_item);
804-
rslt.push(@resolve::MethodInfo {
805-
did: translate_def_id(cdata, m_did),
806-
n_tps: item_ty_param_count(mth_item) - base_tps,
807-
ident: item_name(intr, mth_item),
808-
explicit_self: explicit_self});
802+
rslt.push(@get_method(intr, cdata, m_did.node, tcx));
809803
}
804+
810805
rslt
811806
}
812807

813808
/// Returns information about the given implementation.
814-
pub fn get_impl(intr: @ident_interner, cdata: cmd, impl_id: ast::node_id)
815-
-> resolve::Impl {
809+
pub fn get_impl(intr: @ident_interner, cdata: cmd, impl_id: ast::node_id,
810+
tcx: ty::ctxt)
811+
-> ty::Impl {
816812
let data = cdata.data;
817813
let impl_item = lookup_item(impl_id, data);
818-
let base_tps = item_ty_param_count(impl_item);
819-
resolve::Impl {
814+
ty::Impl {
820815
did: ast::def_id {
821816
crate: cdata.cnum,
822817
node: impl_id,
823818
},
824819
ident: item_name(intr, impl_item),
825-
methods: item_impl_methods(intr, cdata, impl_item, base_tps),
820+
methods: item_impl_methods(intr, cdata, impl_item, tcx),
826821
}
827822
}
828823

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
402402
for base_impl.methods.iter().advance |&m| {
403403
if m.explicit_self == ast::sty_static {
404404
encode_reexported_static_method(ecx, ebml_w, exp,
405-
m.did, m.ident);
405+
m.def_id, m.ident);
406406
}
407407
}
408408
}

src/librustc/middle/resolve.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,6 @@ pub struct binding_info {
5555
// Map from the name in a pattern to its binding mode.
5656
pub type BindingMap = HashMap<ident,binding_info>;
5757

58-
// Implementation resolution
59-
//
60-
// FIXME #4946: This kind of duplicates information kept in
61-
// ty::method. Maybe it should go away.
62-
63-
pub struct MethodInfo {
64-
did: def_id,
65-
n_tps: uint,
66-
ident: ident,
67-
explicit_self: explicit_self_
68-
}
69-
70-
pub struct Impl {
71-
did: def_id,
72-
ident: ident,
73-
methods: ~[@MethodInfo]
74-
}
75-
7658
// Trait method resolution
7759
pub type TraitMap = HashMap<node_id,@mut ~[def_id]>;
7860

src/librustc/middle/trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ pub fn method_with_name(ccx: &mut CrateContext,
344344
let meth = imp.methods.iter().find_(|m| m.ident == name)
345345
.expect("could not find method while translating");
346346

347-
ccx.impl_method_cache.insert((impl_id, name), meth.did);
348-
meth.did
347+
ccx.impl_method_cache.insert((impl_id, name), meth.def_id);
348+
meth.def_id
349349
}
350350

351351
pub fn trans_monomorphized_callee(bcx: block,

src/librustc/middle/ty.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use middle::const_eval;
1616
use middle::lang_items::{TyDescStructLangItem, TyVisitorTraitLangItem};
1717
use middle::lang_items::OpaqueStructLangItem;
1818
use middle::freevars;
19-
use middle::resolve::{Impl, MethodInfo};
2019
use middle::resolve;
2120
use middle::ty;
2221
use middle::subst::Subst;
@@ -96,6 +95,12 @@ impl Method {
9695
}
9796
}
9897

98+
pub struct Impl {
99+
did: def_id,
100+
ident: ident,
101+
methods: ~[@Method]
102+
}
103+
99104
#[deriving(Clone, Eq, IterBytes)]
100105
pub struct mt {
101106
ty: t,

src/librustc/middle/typeck/check/method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'self> LookupContext<'self> {
527527

528528
pub fn push_candidates_from_impl(&self,
529529
candidates: &mut ~[Candidate],
530-
impl_info: &resolve::Impl) {
530+
impl_info: &ty::Impl) {
531531
if !self.impl_dups.insert(impl_info.did) {
532532
return; // already visited
533533
}
@@ -543,7 +543,7 @@ impl<'self> LookupContext<'self> {
543543
}
544544
};
545545

546-
let method = ty::method(self.tcx(), impl_info.methods[idx].did);
546+
let method = ty::method(self.tcx(), impl_info.methods[idx].def_id);
547547

548548
// determine the `self` of the impl with fresh
549549
// variables for each parameter:

src/librustc/middle/typeck/coherence.rs

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
use metadata::csearch::{each_path, get_impl_trait};
1919
use metadata::csearch;
20-
use metadata::cstore::{CStore, iter_crate_data};
20+
use metadata::cstore::iter_crate_data;
2121
use metadata::decoder::{dl_def, dl_field, dl_impl};
22-
use middle::resolve::{Impl, MethodInfo};
2322
use middle::ty::{ProvidedMethodSource, get};
2423
use middle::ty::{lookup_item_type, subst};
2524
use middle::ty::{substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err};
@@ -31,14 +30,15 @@ use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec};
3130
use middle::ty::{type_is_ty_var};
3231
use middle::subst::Subst;
3332
use middle::ty;
33+
use middle::ty::{Impl, Method};
3434
use middle::typeck::CrateCtxt;
3535
use middle::typeck::infer::combine::Combine;
3636
use middle::typeck::infer::InferCtxt;
3737
use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
3838
use middle::typeck::infer;
3939
use syntax::ast::{crate, def_id, def_struct, def_ty};
4040
use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct};
41-
use syntax::ast::{local_crate, method, trait_ref, ty_path};
41+
use syntax::ast::{local_crate, trait_ref, ty_path};
4242
use syntax::ast;
4343
use syntax::ast_map::node_item;
4444
use syntax::ast_map;
@@ -149,16 +149,6 @@ pub fn get_base_type_def_id(inference_context: @mut InferCtxt,
149149
}
150150
}
151151

152-
153-
pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
154-
@MethodInfo {
155-
did: local_def(ast_method.id),
156-
n_tps: ast_method.generics.ty_params.len(),
157-
ident: ast_method.ident,
158-
explicit_self: ast_method.explicit_self.node
159-
}
160-
}
161-
162152
pub fn CoherenceChecker(crate_context: @mut CrateCtxt) -> CoherenceChecker {
163153
CoherenceChecker {
164154
crate_context: crate_context,
@@ -291,7 +281,7 @@ impl CoherenceChecker {
291281
pub fn instantiate_default_methods(&self,
292282
impl_id: ast::def_id,
293283
trait_ref: &ty::TraitRef,
294-
all_methods: &mut ~[@MethodInfo]) {
284+
all_methods: &mut ~[@Method]) {
295285
let tcx = self.crate_context.tcx;
296286
debug!("instantiate_default_methods(impl_id=%?, trait_ref=%s)",
297287
impl_id, trait_ref.repr(tcx));
@@ -316,6 +306,7 @@ impl CoherenceChecker {
316306
*trait_method);
317307

318308
debug!("new_method_ty=%s", new_method_ty.repr(tcx));
309+
all_methods.push(new_method_ty);
319310

320311
// construct the polytype for the method based on the method_ty
321312
let new_generics = ty::Generics {
@@ -344,14 +335,6 @@ impl CoherenceChecker {
344335

345336
self.crate_context.tcx.provided_method_sources.insert(new_did,
346337
source);
347-
348-
let method_info = @MethodInfo {
349-
did: new_did,
350-
n_tps: trait_method.generics.type_param_defs.len(),
351-
ident: trait_method.ident,
352-
explicit_self: trait_method.explicit_self
353-
};
354-
all_methods.push(method_info);
355338
}
356339
}
357340

@@ -563,7 +546,7 @@ impl CoherenceChecker {
563546
// here for historical reasons
564547
pub fn check_trait_methods_are_implemented(
565548
&self,
566-
all_methods: &mut ~[@MethodInfo],
549+
all_methods: &mut ~[@Method],
567550
trait_did: def_id,
568551
trait_ref_span: span) {
569552

@@ -628,11 +611,12 @@ impl CoherenceChecker {
628611

629612
// Converts an implementation in the AST to an Impl structure.
630613
pub fn create_impl_from_item(&self, item: @item) -> @Impl {
614+
let tcx = self.crate_context.tcx;
631615
match item.node {
632616
item_impl(_, ref trait_refs, _, ref ast_methods) => {
633617
let mut methods = ~[];
634618
for ast_methods.iter().advance |ast_method| {
635-
methods.push(method_to_MethodInfo(*ast_method));
619+
methods.push(ty::method(tcx, local_def(ast_method.id)));
636620
}
637621

638622
for trait_refs.iter().advance |trait_ref| {
@@ -682,12 +666,12 @@ impl CoherenceChecker {
682666

683667
pub fn add_external_impl(&self,
684668
impls_seen: &mut HashSet<def_id>,
685-
crate_store: @mut CStore,
686669
impl_def_id: def_id) {
687-
let implementation = csearch::get_impl(crate_store, impl_def_id);
670+
let tcx = self.crate_context.tcx;
671+
let implementation = csearch::get_impl(tcx, impl_def_id);
688672

689673
debug!("coherence: adding impl from external crate: %s",
690-
ty::item_path_str(self.crate_context.tcx, implementation.did));
674+
ty::item_path_str(tcx, implementation.did));
691675

692676
// Make sure we don't visit the same implementation multiple times.
693677
if !impls_seen.insert(implementation.did) {
@@ -696,9 +680,8 @@ impl CoherenceChecker {
696680
}
697681
// Good. Continue.
698682

699-
let self_type = lookup_item_type(self.crate_context.tcx,
700-
implementation.did);
701-
let associated_traits = get_impl_trait(self.crate_context.tcx,
683+
let self_type = lookup_item_type(tcx, implementation.did);
684+
let associated_traits = get_impl_trait(tcx,
702685
implementation.did);
703686

704687
// Do a sanity check to make sure that inherent methods have base
@@ -708,12 +691,10 @@ impl CoherenceChecker {
708691
dummy_sp(),
709692
self_type.ty) {
710693
None => {
711-
let session = self.crate_context.tcx.sess;
712-
session.bug(fmt!("no base type for external impl with no \
694+
tcx.sess.bug(fmt!("no base type for external impl with no \
713695
trait: %s (type %s)!",
714-
session.str_of(implementation.ident),
715-
ty_to_str(self.crate_context.tcx,
716-
self_type.ty)));
696+
tcx.sess.str_of(implementation.ident),
697+
ty_to_str(tcx, self_type.ty)));
717698
}
718699
Some(_) => {} // Nothing to do.
719700
}
@@ -756,8 +737,7 @@ impl CoherenceChecker {
756737
}
757738
}
758739

759-
self.crate_context.tcx.impls.insert(implementation.did,
760-
implementation);
740+
tcx.impls.insert(implementation.did, implementation);
761741
}
762742

763743
// Adds implementations and traits from external crates to the coherence
@@ -770,9 +750,7 @@ impl CoherenceChecker {
770750
for each_path(crate_store, crate_number) |_, def_like, _| {
771751
match def_like {
772752
dl_impl(def_id) => {
773-
self.add_external_impl(&mut impls_seen,
774-
crate_store,
775-
def_id)
753+
self.add_external_impl(&mut impls_seen, def_id)
776754
}
777755
dl_def(_) | dl_field => loop, // Skip this.
778756
}
@@ -802,7 +780,7 @@ impl CoherenceChecker {
802780
// We'll error out later. For now, just don't ICE.
803781
loop;
804782
}
805-
let method_def_id = impl_info.methods[0].did;
783+
let method_def_id = impl_info.methods[0].def_id;
806784

807785
let self_type = self.get_self_type_for_implementation(*impl_info);
808786
match ty::get(self_type.ty).sty {

0 commit comments

Comments
 (0)