Get rid of terrible way for iterating over provided methods.

This commit is contained in:
Michael Sullivan 2013-06-19 12:50:12 -07:00
parent d161e630d8
commit 5e26808141
4 changed files with 14 additions and 46 deletions

View File

@ -24,11 +24,6 @@ use syntax::ast;
use syntax::ast_map;
use syntax::diagnostic::expect;
pub struct ProvidedTraitMethodInfo {
ty: ty::Method,
def_id: ast::def_id
}
pub struct StaticMethodInfo {
ident: ast::ident,
def_id: ast::def_id,
@ -134,7 +129,7 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
pub fn get_provided_trait_methods(tcx: ty::ctxt,
def: ast::def_id)
-> ~[ProvidedTraitMethodInfo] {
-> ~[@ty::Method] {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)

View File

@ -14,7 +14,7 @@ use core::prelude::*;
use metadata::cstore::crate_metadata;
use metadata::common::*;
use metadata::csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
use metadata::csearch::StaticMethodInfo;
use metadata::csearch;
use metadata::cstore;
use metadata::decoder;
@ -752,7 +752,7 @@ pub fn get_trait_method_def_ids(cdata: cmd,
pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
id: ast::node_id, tcx: ty::ctxt) ->
~[ProvidedTraitMethodInfo] {
~[@ty::Method] {
let data = cdata.data;
let item = lookup_item(id, data);
let mut result = ~[];
@ -763,13 +763,8 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
if item_method_sort(mth) != 'p' { loop; }
let ty_method = get_method(intr, cdata, did.node, tcx);
let provided_trait_method_info = ProvidedTraitMethodInfo {
ty: ty_method,
def_id: did
};
vec::push(&mut result, provided_trait_method_info);
vec::push(&mut result,
@get_method(intr, cdata, did.node, tcx));
}
return result;

View File

@ -3649,7 +3649,7 @@ pub fn def_has_ty_params(def: ast::def) -> bool {
}
}
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@Method] {
if is_local(id) {
match cx.items.find(&id.node) {
Some(&ast_map::node_item(@ast::item {
@ -3657,13 +3657,13 @@ pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
_
}, _)) =>
match ast_util::split_trait_methods(*ms) {
(_, p) => p.map(|method| method.ident)
(_, p) => p.map(|m| method(cx, ast_util::local_def(m.id)))
},
_ => cx.sess.bug(fmt!("provided_trait_methods: %? is not a trait",
id))
}
} else {
csearch::get_provided_trait_methods(cx, id).map(|ifo| ifo.ty.ident)
csearch::get_provided_trait_methods(cx, id)
}
}

View File

@ -333,7 +333,8 @@ impl CoherenceChecker {
let impl_poly_type = ty::lookup_item_type(tcx, impl_id);
for self.each_provided_trait_method(trait_ref.def_id) |trait_method| {
let provided = ty::provided_trait_methods(tcx, trait_ref.def_id);
for provided.iter().advance |trait_method| {
// Synthesize an ID.
let new_id = parse::next_node_id(tcx.sess.parse_sess);
let new_did = local_def(new_id);
@ -347,7 +348,7 @@ impl CoherenceChecker {
impl_id,
trait_ref,
new_did,
trait_method);
*trait_method);
debug!("new_method_ty=%s", new_method_ty.repr(tcx));
@ -526,29 +527,6 @@ impl CoherenceChecker {
}
}
pub fn each_provided_trait_method(&self,
trait_did: ast::def_id,
f: &fn(x: @ty::Method) -> bool)
-> bool {
// Make a list of all the names of the provided methods.
// XXX: This is horrible.
let mut provided_method_idents = HashSet::new();
let tcx = self.crate_context.tcx;
let r = ty::provided_trait_methods(tcx, trait_did);
for r.iter().advance |ident| {
provided_method_idents.insert(*ident);
}
for ty::trait_methods(tcx, trait_did).iter().advance |&method| {
if provided_method_idents.contains(&method.ident) {
if !f(method) {
return false;
}
}
}
return true;
}
pub fn polytypes_unify(&self,
polytype_a: ty_param_bounds_and_ty,
polytype_b: ty_param_bounds_and_ty)
@ -729,9 +707,9 @@ impl CoherenceChecker {
}
// Default methods
let r = ty::provided_trait_methods(tcx, trait_did);
for r.iter().advance |ident| {
debug!("inserting provided method %s", ident.repr(tcx));
provided_names.insert(*ident);
for r.iter().advance |method| {
debug!("inserting provided method %s", method.ident.repr(tcx));
provided_names.insert(method.ident);
}
let r = ty::trait_methods(tcx, trait_did);