Get rid of resolve::MethodInfo. Closes #4946.
This commit is contained in:
parent
f0a69b1a43
commit
2ea61204f6
@ -15,7 +15,7 @@
|
||||
use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use metadata;
|
||||
use middle::{ty, resolve};
|
||||
use middle::ty;
|
||||
|
||||
use std::vec;
|
||||
use reader = extra::ebml::reader;
|
||||
@ -97,10 +97,10 @@ pub fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id)
|
||||
}
|
||||
|
||||
/// Returns information about the given implementation.
|
||||
pub fn get_impl(cstore: @mut cstore::CStore, impl_def_id: ast::def_id)
|
||||
-> resolve::Impl {
|
||||
let cdata = cstore::get_crate_data(cstore, impl_def_id.crate);
|
||||
decoder::get_impl(cstore.intr, cdata, impl_def_id.node)
|
||||
pub fn get_impl(tcx: ty::ctxt, impl_def_id: ast::def_id)
|
||||
-> ty::Impl {
|
||||
let cdata = cstore::get_crate_data(tcx.cstore, impl_def_id.crate);
|
||||
decoder::get_impl(tcx.cstore.intr, cdata, impl_def_id.node, tcx)
|
||||
}
|
||||
|
||||
pub fn get_method(tcx: ty::ctxt, def: ast::def_id) -> ty::Method {
|
||||
|
@ -20,7 +20,7 @@
|
||||
use metadata::tydecode::{parse_ty_data, parse_def_id,
|
||||
parse_type_param_def_data,
|
||||
parse_bare_fn_ty_data, parse_trait_ref_data};
|
||||
use middle::{ty, resolve};
|
||||
use middle::ty;
|
||||
|
||||
use std::hash::HashUtil;
|
||||
use std::int;
|
||||
@ -795,34 +795,29 @@ fn get_mutability(ch: u8) -> ast::mutability {
|
||||
}
|
||||
|
||||
fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
|
||||
base_tps: uint) -> ~[@resolve::MethodInfo] {
|
||||
tcx: ty::ctxt) -> ~[@ty::Method] {
|
||||
let mut rslt = ~[];
|
||||
for reader::tagged_docs(item, tag_item_impl_method) |doc| {
|
||||
let m_did = reader::with_doc_data(doc, parse_def_id);
|
||||
let mth_item = lookup_item(m_did.node, cdata.data);
|
||||
let explicit_self = get_explicit_self(mth_item);
|
||||
rslt.push(@resolve::MethodInfo {
|
||||
did: translate_def_id(cdata, m_did),
|
||||
n_tps: item_ty_param_count(mth_item) - base_tps,
|
||||
ident: item_name(intr, mth_item),
|
||||
explicit_self: explicit_self});
|
||||
rslt.push(@get_method(intr, cdata, m_did.node, tcx));
|
||||
}
|
||||
|
||||
rslt
|
||||
}
|
||||
|
||||
/// Returns information about the given implementation.
|
||||
pub fn get_impl(intr: @ident_interner, cdata: cmd, impl_id: ast::node_id)
|
||||
-> resolve::Impl {
|
||||
pub fn get_impl(intr: @ident_interner, cdata: cmd, impl_id: ast::node_id,
|
||||
tcx: ty::ctxt)
|
||||
-> ty::Impl {
|
||||
let data = cdata.data;
|
||||
let impl_item = lookup_item(impl_id, data);
|
||||
let base_tps = item_ty_param_count(impl_item);
|
||||
resolve::Impl {
|
||||
ty::Impl {
|
||||
did: ast::def_id {
|
||||
crate: cdata.cnum,
|
||||
node: impl_id,
|
||||
},
|
||||
ident: item_name(intr, impl_item),
|
||||
methods: item_impl_methods(intr, cdata, impl_item, base_tps),
|
||||
methods: item_impl_methods(intr, cdata, impl_item, tcx),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
|
||||
for base_impl.methods.iter().advance |&m| {
|
||||
if m.explicit_self == ast::sty_static {
|
||||
encode_reexported_static_method(ecx, ebml_w, exp,
|
||||
m.did, m.ident);
|
||||
m.def_id, m.ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,24 +55,6 @@ pub struct binding_info {
|
||||
// Map from the name in a pattern to its binding mode.
|
||||
pub type BindingMap = HashMap<ident,binding_info>;
|
||||
|
||||
// Implementation resolution
|
||||
//
|
||||
// FIXME #4946: This kind of duplicates information kept in
|
||||
// ty::method. Maybe it should go away.
|
||||
|
||||
pub struct MethodInfo {
|
||||
did: def_id,
|
||||
n_tps: uint,
|
||||
ident: ident,
|
||||
explicit_self: explicit_self_
|
||||
}
|
||||
|
||||
pub struct Impl {
|
||||
did: def_id,
|
||||
ident: ident,
|
||||
methods: ~[@MethodInfo]
|
||||
}
|
||||
|
||||
// Trait method resolution
|
||||
pub type TraitMap = HashMap<node_id,@mut ~[def_id]>;
|
||||
|
||||
|
@ -344,8 +344,8 @@ pub fn method_with_name(ccx: &mut CrateContext,
|
||||
let meth = imp.methods.iter().find_(|m| m.ident == name)
|
||||
.expect("could not find method while translating");
|
||||
|
||||
ccx.impl_method_cache.insert((impl_id, name), meth.did);
|
||||
meth.did
|
||||
ccx.impl_method_cache.insert((impl_id, name), meth.def_id);
|
||||
meth.def_id
|
||||
}
|
||||
|
||||
pub fn trans_monomorphized_callee(bcx: block,
|
||||
|
@ -16,7 +16,6 @@
|
||||
use middle::lang_items::{TyDescStructLangItem, TyVisitorTraitLangItem};
|
||||
use middle::lang_items::OpaqueStructLangItem;
|
||||
use middle::freevars;
|
||||
use middle::resolve::{Impl, MethodInfo};
|
||||
use middle::resolve;
|
||||
use middle::ty;
|
||||
use middle::subst::Subst;
|
||||
@ -96,6 +95,12 @@ pub fn new(ident: ast::ident,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Impl {
|
||||
did: def_id,
|
||||
ident: ident,
|
||||
methods: ~[@Method]
|
||||
}
|
||||
|
||||
#[deriving(Clone, Eq, IterBytes)]
|
||||
pub struct mt {
|
||||
ty: t,
|
||||
|
@ -527,7 +527,7 @@ pub fn push_inherent_impl_candidates_for_type(&self, did: def_id) {
|
||||
|
||||
pub fn push_candidates_from_impl(&self,
|
||||
candidates: &mut ~[Candidate],
|
||||
impl_info: &resolve::Impl) {
|
||||
impl_info: &ty::Impl) {
|
||||
if !self.impl_dups.insert(impl_info.did) {
|
||||
return; // already visited
|
||||
}
|
||||
@ -543,7 +543,7 @@ pub fn push_candidates_from_impl(&self,
|
||||
}
|
||||
};
|
||||
|
||||
let method = ty::method(self.tcx(), impl_info.methods[idx].did);
|
||||
let method = ty::method(self.tcx(), impl_info.methods[idx].def_id);
|
||||
|
||||
// determine the `self` of the impl with fresh
|
||||
// variables for each parameter:
|
||||
|
@ -17,9 +17,8 @@
|
||||
|
||||
use metadata::csearch::{each_path, get_impl_trait};
|
||||
use metadata::csearch;
|
||||
use metadata::cstore::{CStore, iter_crate_data};
|
||||
use metadata::cstore::iter_crate_data;
|
||||
use metadata::decoder::{dl_def, dl_field, dl_impl};
|
||||
use middle::resolve::{Impl, MethodInfo};
|
||||
use middle::ty::{ProvidedMethodSource, get};
|
||||
use middle::ty::{lookup_item_type, subst};
|
||||
use middle::ty::{substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err};
|
||||
@ -31,6 +30,7 @@
|
||||
use middle::ty::{type_is_ty_var};
|
||||
use middle::subst::Subst;
|
||||
use middle::ty;
|
||||
use middle::ty::{Impl, Method};
|
||||
use middle::typeck::CrateCtxt;
|
||||
use middle::typeck::infer::combine::Combine;
|
||||
use middle::typeck::infer::InferCtxt;
|
||||
@ -38,7 +38,7 @@
|
||||
use middle::typeck::infer;
|
||||
use syntax::ast::{crate, def_id, def_struct, def_ty};
|
||||
use syntax::ast::{item, item_enum, item_impl, item_mod, item_struct};
|
||||
use syntax::ast::{local_crate, method, trait_ref, ty_path};
|
||||
use syntax::ast::{local_crate, trait_ref, ty_path};
|
||||
use syntax::ast;
|
||||
use syntax::ast_map::node_item;
|
||||
use syntax::ast_map;
|
||||
@ -149,16 +149,6 @@ pub fn get_base_type_def_id(inference_context: @mut InferCtxt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
|
||||
@MethodInfo {
|
||||
did: local_def(ast_method.id),
|
||||
n_tps: ast_method.generics.ty_params.len(),
|
||||
ident: ast_method.ident,
|
||||
explicit_self: ast_method.explicit_self.node
|
||||
}
|
||||
}
|
||||
|
||||
pub fn CoherenceChecker(crate_context: @mut CrateCtxt) -> CoherenceChecker {
|
||||
CoherenceChecker {
|
||||
crate_context: crate_context,
|
||||
@ -291,7 +281,7 @@ pub fn check_implementation(&self,
|
||||
pub fn instantiate_default_methods(&self,
|
||||
impl_id: ast::def_id,
|
||||
trait_ref: &ty::TraitRef,
|
||||
all_methods: &mut ~[@MethodInfo]) {
|
||||
all_methods: &mut ~[@Method]) {
|
||||
let tcx = self.crate_context.tcx;
|
||||
debug!("instantiate_default_methods(impl_id=%?, trait_ref=%s)",
|
||||
impl_id, trait_ref.repr(tcx));
|
||||
@ -316,6 +306,7 @@ pub fn instantiate_default_methods(&self,
|
||||
*trait_method);
|
||||
|
||||
debug!("new_method_ty=%s", new_method_ty.repr(tcx));
|
||||
all_methods.push(new_method_ty);
|
||||
|
||||
// construct the polytype for the method based on the method_ty
|
||||
let new_generics = ty::Generics {
|
||||
@ -344,14 +335,6 @@ pub fn instantiate_default_methods(&self,
|
||||
|
||||
self.crate_context.tcx.provided_method_sources.insert(new_did,
|
||||
source);
|
||||
|
||||
let method_info = @MethodInfo {
|
||||
did: new_did,
|
||||
n_tps: trait_method.generics.type_param_defs.len(),
|
||||
ident: trait_method.ident,
|
||||
explicit_self: trait_method.explicit_self
|
||||
};
|
||||
all_methods.push(method_info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,7 +546,7 @@ pub fn trait_ref_to_trait_def_id(&self, trait_ref: &trait_ref) -> def_id {
|
||||
// here for historical reasons
|
||||
pub fn check_trait_methods_are_implemented(
|
||||
&self,
|
||||
all_methods: &mut ~[@MethodInfo],
|
||||
all_methods: &mut ~[@Method],
|
||||
trait_did: def_id,
|
||||
trait_ref_span: span) {
|
||||
|
||||
@ -628,11 +611,12 @@ pub fn ast_type_is_defined_in_local_crate(&self, original_type: &ast::Ty)
|
||||
|
||||
// Converts an implementation in the AST to an Impl structure.
|
||||
pub fn create_impl_from_item(&self, item: @item) -> @Impl {
|
||||
let tcx = self.crate_context.tcx;
|
||||
match item.node {
|
||||
item_impl(_, ref trait_refs, _, ref ast_methods) => {
|
||||
let mut methods = ~[];
|
||||
for ast_methods.iter().advance |ast_method| {
|
||||
methods.push(method_to_MethodInfo(*ast_method));
|
||||
methods.push(ty::method(tcx, local_def(ast_method.id)));
|
||||
}
|
||||
|
||||
for trait_refs.iter().advance |trait_ref| {
|
||||
@ -682,12 +666,12 @@ pub fn span_of_impl(&self, implementation: @Impl) -> span {
|
||||
|
||||
pub fn add_external_impl(&self,
|
||||
impls_seen: &mut HashSet<def_id>,
|
||||
crate_store: @mut CStore,
|
||||
impl_def_id: def_id) {
|
||||
let implementation = csearch::get_impl(crate_store, impl_def_id);
|
||||
let tcx = self.crate_context.tcx;
|
||||
let implementation = csearch::get_impl(tcx, impl_def_id);
|
||||
|
||||
debug!("coherence: adding impl from external crate: %s",
|
||||
ty::item_path_str(self.crate_context.tcx, implementation.did));
|
||||
ty::item_path_str(tcx, implementation.did));
|
||||
|
||||
// Make sure we don't visit the same implementation multiple times.
|
||||
if !impls_seen.insert(implementation.did) {
|
||||
@ -696,9 +680,8 @@ pub fn add_external_impl(&self,
|
||||
}
|
||||
// Good. Continue.
|
||||
|
||||
let self_type = lookup_item_type(self.crate_context.tcx,
|
||||
implementation.did);
|
||||
let associated_traits = get_impl_trait(self.crate_context.tcx,
|
||||
let self_type = lookup_item_type(tcx, implementation.did);
|
||||
let associated_traits = get_impl_trait(tcx,
|
||||
implementation.did);
|
||||
|
||||
// Do a sanity check to make sure that inherent methods have base
|
||||
@ -708,12 +691,10 @@ pub fn add_external_impl(&self,
|
||||
dummy_sp(),
|
||||
self_type.ty) {
|
||||
None => {
|
||||
let session = self.crate_context.tcx.sess;
|
||||
session.bug(fmt!("no base type for external impl with no \
|
||||
tcx.sess.bug(fmt!("no base type for external impl with no \
|
||||
trait: %s (type %s)!",
|
||||
session.str_of(implementation.ident),
|
||||
ty_to_str(self.crate_context.tcx,
|
||||
self_type.ty)));
|
||||
tcx.sess.str_of(implementation.ident),
|
||||
ty_to_str(tcx, self_type.ty)));
|
||||
}
|
||||
Some(_) => {} // Nothing to do.
|
||||
}
|
||||
@ -756,8 +737,7 @@ pub fn add_external_impl(&self,
|
||||
}
|
||||
}
|
||||
|
||||
self.crate_context.tcx.impls.insert(implementation.did,
|
||||
implementation);
|
||||
tcx.impls.insert(implementation.did, implementation);
|
||||
}
|
||||
|
||||
// Adds implementations and traits from external crates to the coherence
|
||||
@ -770,9 +750,7 @@ pub fn add_external_crates(&self) {
|
||||
for each_path(crate_store, crate_number) |_, def_like, _| {
|
||||
match def_like {
|
||||
dl_impl(def_id) => {
|
||||
self.add_external_impl(&mut impls_seen,
|
||||
crate_store,
|
||||
def_id)
|
||||
self.add_external_impl(&mut impls_seen, def_id)
|
||||
}
|
||||
dl_def(_) | dl_field => loop, // Skip this.
|
||||
}
|
||||
@ -802,7 +780,7 @@ pub fn populate_destructor_table(&self) {
|
||||
// We'll error out later. For now, just don't ICE.
|
||||
loop;
|
||||
}
|
||||
let method_def_id = impl_info.methods[0].did;
|
||||
let method_def_id = impl_info.methods[0].def_id;
|
||||
|
||||
let self_type = self.get_self_type_for_implementation(*impl_info);
|
||||
match ty::get(self_type.ty).sty {
|
||||
|
Loading…
Reference in New Issue
Block a user