rustc: rename ty::method to ty::Method and add ctor
This commit is contained in:
parent
18f6a51d0a
commit
729708d112
9 changed files with 107 additions and 75 deletions
|
|
@ -22,7 +22,7 @@ use syntax::ast_map;
|
|||
use syntax::diagnostic::expect;
|
||||
|
||||
pub struct ProvidedTraitMethodInfo {
|
||||
ty: ty::method,
|
||||
ty: ty::Method,
|
||||
def_id: ast::def_id
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id,
|
|||
}
|
||||
|
||||
pub fn get_method(tcx: ty::ctxt,
|
||||
def: ast::def_id) -> ty::method
|
||||
def: ast::def_id) -> ty::Method
|
||||
{
|
||||
let cdata = cstore::get_crate_data(tcx.cstore, def.crate);
|
||||
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ pub fn get_method_name_and_explicit_self(
|
|||
}
|
||||
|
||||
pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
||||
tcx: ty::ctxt) -> ty::method
|
||||
tcx: ty::ctxt) -> ty::Method
|
||||
{
|
||||
let method_doc = lookup_item(id, cdata.data);
|
||||
let def_id = item_def_id(method_doc, cdata);
|
||||
|
|
@ -771,18 +771,19 @@ pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
|
|||
let fty = doc_method_fty(method_doc, tcx, cdata);
|
||||
let vis = item_visibility(method_doc);
|
||||
let explicit_self = get_explicit_self(method_doc);
|
||||
ty::method {
|
||||
ident: name,
|
||||
generics: ty::Generics {
|
||||
|
||||
ty::Method::new(
|
||||
name,
|
||||
ty::Generics {
|
||||
type_param_defs: type_param_defs,
|
||||
region_param: None
|
||||
},
|
||||
transformed_self_ty: transformed_self_ty,
|
||||
fty: fty,
|
||||
explicit_self: explicit_self,
|
||||
vis: vis,
|
||||
def_id: def_id
|
||||
}
|
||||
transformed_self_ty,
|
||||
fty,
|
||||
explicit_self,
|
||||
vis,
|
||||
def_id
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_trait_method_def_ids(cdata: cmd,
|
||||
|
|
@ -824,18 +825,19 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
|
|||
|
||||
let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata);
|
||||
let explicit_self = get_explicit_self(mth);
|
||||
let ty_method = ty::method {
|
||||
ident: name,
|
||||
generics: ty::Generics {
|
||||
|
||||
let ty_method = ty::Method::new(
|
||||
name,
|
||||
ty::Generics {
|
||||
type_param_defs: type_param_defs,
|
||||
region_param: None
|
||||
},
|
||||
transformed_self_ty: transformed_self_ty,
|
||||
fty: fty,
|
||||
explicit_self: explicit_self,
|
||||
vis: ast::public,
|
||||
def_id: did
|
||||
};
|
||||
transformed_self_ty,
|
||||
fty,
|
||||
explicit_self,
|
||||
ast::public,
|
||||
did
|
||||
);
|
||||
let provided_trait_method_info = ProvidedTraitMethodInfo {
|
||||
ty: ty_method,
|
||||
def_id: did
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ fn encode_path(ecx: @EncodeContext,
|
|||
fn encode_reexported_static_method(ecx: @EncodeContext,
|
||||
ebml_w: &mut writer::Encoder,
|
||||
exp: &middle::resolve::Export2,
|
||||
m: @ty::method) {
|
||||
m: @ty::Method) {
|
||||
debug!("(encode static trait method) reexport '%s::%s'",
|
||||
*exp.name, *ecx.tcx.sess.str_of(m.ident));
|
||||
ebml_w.start_tag(tag_items_data_item_reexport);
|
||||
|
|
@ -625,7 +625,7 @@ fn encode_info_for_struct_ctor(ecx: @EncodeContext,
|
|||
|
||||
fn encode_method_ty_fields(ecx: @EncodeContext,
|
||||
ebml_w: &mut writer::Encoder,
|
||||
method_ty: &ty::method) {
|
||||
method_ty: &ty::Method) {
|
||||
encode_def_id(ebml_w, method_ty.def_id);
|
||||
encode_name(ecx, ebml_w, method_ty.ident);
|
||||
encode_ty_type_param_defs(ebml_w, ecx,
|
||||
|
|
@ -652,7 +652,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
|
|||
ebml_w.start_tag(tag_items_data_item);
|
||||
|
||||
let method_def_id = local_def(m.id);
|
||||
let method_ty: @ty::method = ty::method(ecx.tcx, method_def_id);
|
||||
let method_ty = ty::method(ecx.tcx, method_def_id);
|
||||
encode_method_ty_fields(ecx, ebml_w, method_ty);
|
||||
|
||||
match m.explicit_self.node {
|
||||
|
|
@ -948,7 +948,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
|
|||
for ty::trait_method_def_ids(tcx, local_def(item.id)).eachi |i, &method_def_id| {
|
||||
assert!(method_def_id.crate == ast::local_crate);
|
||||
|
||||
let method_ty: @ty::method = ty::method(tcx, method_def_id);
|
||||
let method_ty = ty::method(tcx, method_def_id);
|
||||
|
||||
index.push(entry {val: method_def_id.node, pos: ebml_w.writer.tell()});
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ use syntax::parse::token::special_idents;
|
|||
|
||||
pub struct Reflector {
|
||||
visitor_val: ValueRef,
|
||||
visitor_methods: @~[@ty::method],
|
||||
visitor_methods: @~[@ty::Method],
|
||||
final_bcx: block,
|
||||
tydesc_ty: TypeRef,
|
||||
bcx: block
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ pub struct field {
|
|||
mt: mt
|
||||
}
|
||||
|
||||
pub struct method {
|
||||
pub struct Method {
|
||||
ident: ast::ident,
|
||||
generics: ty::Generics,
|
||||
transformed_self_ty: Option<ty::t>,
|
||||
|
|
@ -63,6 +63,33 @@ pub struct method {
|
|||
def_id: ast::def_id
|
||||
}
|
||||
|
||||
pub impl Method {
|
||||
fn new(ident: ast::ident,
|
||||
generics: ty::Generics,
|
||||
transformed_self_ty: Option<ty::t>,
|
||||
fty: BareFnTy,
|
||||
explicit_self: ast::explicit_self_,
|
||||
vis: ast::visibility,
|
||||
def_id: ast::def_id) -> Method {
|
||||
// Check the invariants.
|
||||
if explicit_self == ast::sty_static {
|
||||
assert!(transformed_self_ty.is_none());
|
||||
} else {
|
||||
assert!(transformed_self_ty.is_some());
|
||||
}
|
||||
|
||||
Method {
|
||||
ident: ident,
|
||||
generics: generics,
|
||||
transformed_self_ty: transformed_self_ty,
|
||||
fty: fty,
|
||||
explicit_self: explicit_self,
|
||||
vis: vis,
|
||||
def_id: def_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
pub struct mt {
|
||||
ty: t,
|
||||
|
|
@ -254,13 +281,13 @@ struct ctxt_ {
|
|||
node_type_substs: @mut HashMap<node_id, ~[t]>,
|
||||
|
||||
// Maps from a method to the method "descriptor"
|
||||
methods: @mut HashMap<def_id, @method>,
|
||||
methods: @mut HashMap<def_id, @Method>,
|
||||
|
||||
// Maps from a trait def-id to a list of the def-ids of its methods
|
||||
trait_method_def_ids: @mut HashMap<def_id, @~[def_id]>,
|
||||
|
||||
// A cache for the trait_methods() routine
|
||||
trait_methods_cache: @mut HashMap<def_id, @~[@method]>,
|
||||
trait_methods_cache: @mut HashMap<def_id, @~[@Method]>,
|
||||
|
||||
trait_refs: @mut HashMap<node_id, @TraitRef>,
|
||||
trait_defs: @mut HashMap<def_id, @TraitDef>,
|
||||
|
|
@ -3498,7 +3525,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field])
|
|||
fields.map(|f| tcx.sess.str_of(f.ident))));
|
||||
}
|
||||
|
||||
pub fn method_idx(id: ast::ident, meths: &[@method]) -> Option<uint> {
|
||||
pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option<uint> {
|
||||
vec::position(meths, |m| m.ident == id)
|
||||
}
|
||||
|
||||
|
|
@ -3822,12 +3849,12 @@ fn lookup_locally_or_in_crate_store<V:Copy>(
|
|||
return v;
|
||||
}
|
||||
|
||||
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @method {
|
||||
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @Method {
|
||||
let method_def_id = ty::trait_method_def_ids(cx, trait_did)[idx];
|
||||
ty::method(cx, method_def_id)
|
||||
}
|
||||
|
||||
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
|
||||
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@Method] {
|
||||
match cx.trait_methods_cache.find(&trait_did) {
|
||||
Some(&methods) => methods,
|
||||
None => {
|
||||
|
|
@ -3839,7 +3866,7 @@ pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn method(cx: ctxt, id: ast::def_id) -> @method {
|
||||
pub fn method(cx: ctxt, id: ast::def_id) -> @Method {
|
||||
lookup_locally_or_in_crate_store(
|
||||
"methods", id, cx.methods,
|
||||
|| @csearch::get_method(cx, id))
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ pub struct LookupContext<'self> {
|
|||
pub struct Candidate {
|
||||
rcvr_ty: ty::t,
|
||||
rcvr_substs: ty::substs,
|
||||
method_ty: @ty::method,
|
||||
method_ty: @ty::Method,
|
||||
origin: method_origin,
|
||||
}
|
||||
|
||||
|
|
@ -469,7 +469,7 @@ pub impl<'self> LookupContext<'self> {
|
|||
did: def_id,
|
||||
substs: &ty::substs) {
|
||||
struct MethodInfo {
|
||||
method_ty: @ty::method,
|
||||
method_ty: @ty::Method,
|
||||
trait_def_id: ast::def_id,
|
||||
index: uint
|
||||
}
|
||||
|
|
|
|||
|
|
@ -527,7 +527,7 @@ pub impl CoherenceChecker {
|
|||
#[cfg(stage0)]
|
||||
fn each_provided_trait_method(&self,
|
||||
trait_did: ast::def_id,
|
||||
f: &fn(x: @ty::method) -> bool) {
|
||||
f: &fn(@ty::Method) -> bool) {
|
||||
// Make a list of all the names of the provided methods.
|
||||
// XXX: This is horrible.
|
||||
let mut provided_method_idents = HashSet::new();
|
||||
|
|
@ -547,7 +547,7 @@ pub impl CoherenceChecker {
|
|||
#[cfg(not(stage0))]
|
||||
fn each_provided_trait_method(&self,
|
||||
trait_did: ast::def_id,
|
||||
f: &fn(x: @ty::method) -> bool) -> bool {
|
||||
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();
|
||||
|
|
@ -1073,7 +1073,7 @@ fn subst_receiver_types_in_method_ty(
|
|||
impl_id: ast::node_id,
|
||||
trait_ref: &ty::TraitRef,
|
||||
new_def_id: ast::def_id,
|
||||
method: &ty::method) -> ty::method
|
||||
method: &ty::Method) -> ty::Method
|
||||
{
|
||||
/*!
|
||||
* Substitutes the values for the receiver's type parameters
|
||||
|
|
@ -1117,19 +1117,22 @@ fn subst_receiver_types_in_method_ty(
|
|||
tps: combined_tps
|
||||
};
|
||||
|
||||
ty::method {
|
||||
ident: method.ident,
|
||||
ty::Method::new(
|
||||
method.ident,
|
||||
|
||||
// method types *can* appear in the generic bounds
|
||||
method.generics.subst(tcx, &combined_substs),
|
||||
|
||||
// method tps cannot appear in the self_ty, so use `substs` from trait ref
|
||||
transformed_self_ty: method.transformed_self_ty.subst(tcx, &trait_ref.substs),
|
||||
method.transformed_self_ty.subst(tcx, &trait_ref.substs),
|
||||
|
||||
// method types *can* appear in the generic bounds or the fty
|
||||
generics: method.generics.subst(tcx, &combined_substs),
|
||||
fty: method.fty.subst(tcx, &combined_substs),
|
||||
explicit_self: method.explicit_self,
|
||||
vis: method.vis,
|
||||
def_id: new_def_id
|
||||
}
|
||||
// method types *can* appear in the fty
|
||||
method.fty.subst(tcx, &combined_substs),
|
||||
|
||||
method.explicit_self,
|
||||
method.vis,
|
||||
new_def_id
|
||||
)
|
||||
}
|
||||
|
||||
pub fn check_coherence(crate_context: @mut CrateCtxt, crate: @crate) {
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
|
|||
}, _) => {
|
||||
let trait_ty_generics = ty_generics(ccx, region_paramd, generics, 0);
|
||||
|
||||
// For each method, construct a suitable ty::method and
|
||||
// For each method, construct a suitable ty::Method and
|
||||
// store it into the `tcx.methods` table:
|
||||
for ms.each |m| {
|
||||
let ty_method = @match m {
|
||||
|
|
@ -270,7 +270,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
|
|||
|
||||
fn make_static_method_ty(ccx: &CrateCtxt,
|
||||
trait_id: ast::node_id,
|
||||
m: &ty::method,
|
||||
m: &ty::Method,
|
||||
trait_ty_generics: &ty::Generics) {
|
||||
// If declaration is
|
||||
//
|
||||
|
|
@ -379,7 +379,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
|
|||
m_explicit_self: &ast::explicit_self,
|
||||
m_generics: &ast::Generics,
|
||||
m_purity: &ast::purity,
|
||||
m_decl: &ast::fn_decl) -> ty::method
|
||||
m_decl: &ast::fn_decl) -> ty::Method
|
||||
{
|
||||
let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id));
|
||||
let rscope = MethodRscope::new(m_explicit_self.node, trait_rp, trait_generics);
|
||||
|
|
@ -387,16 +387,16 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
|
|||
astconv::ty_of_method(this, &rscope, *m_purity, &m_generics.lifetimes,
|
||||
trait_self_ty, *m_explicit_self, m_decl);
|
||||
let num_trait_type_params = trait_generics.ty_params.len();
|
||||
ty::method {
|
||||
ident: *m_ident,
|
||||
generics: ty_generics(this, None, m_generics, num_trait_type_params),
|
||||
transformed_self_ty: transformed_self_ty,
|
||||
fty: fty,
|
||||
explicit_self: m_explicit_self.node,
|
||||
ty::Method::new(
|
||||
*m_ident,
|
||||
ty_generics(this, None, m_generics, num_trait_type_params),
|
||||
transformed_self_ty,
|
||||
fty,
|
||||
m_explicit_self.node,
|
||||
// assume public, because this is only invoked on trait methods
|
||||
vis: ast::public,
|
||||
def_id: local_def(*m_id)
|
||||
}
|
||||
ast::public,
|
||||
local_def(*m_id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
|
|||
pub fn compare_impl_method(tcx: ty::ctxt,
|
||||
impl_tps: uint,
|
||||
cm: &ConvertedMethod,
|
||||
trait_m: &ty::method,
|
||||
trait_m: &ty::Method,
|
||||
trait_substs: &ty::substs,
|
||||
self_ty: ty::t) {
|
||||
debug!("compare_impl_method()");
|
||||
|
|
@ -723,7 +723,7 @@ pub fn convert_field(ccx: &CrateCtxt,
|
|||
}
|
||||
|
||||
pub struct ConvertedMethod {
|
||||
mty: @ty::method,
|
||||
mty: @ty::Method,
|
||||
id: ast::node_id,
|
||||
span: span,
|
||||
body_id: ast::node_id
|
||||
|
|
@ -776,7 +776,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
|
|||
untransformed_rcvr_ty: ty::t,
|
||||
rcvr_generics: &ast::Generics,
|
||||
rcvr_visibility: ast::visibility,
|
||||
method_generics: &ast::Generics) -> ty::method
|
||||
method_generics: &ast::Generics) -> ty::Method
|
||||
{
|
||||
let rscope = MethodRscope::new(m.explicit_self.node,
|
||||
rp,
|
||||
|
|
@ -794,15 +794,15 @@ pub fn convert_methods(ccx: &CrateCtxt,
|
|||
let method_vis = m.vis.inherit_from(rcvr_visibility);
|
||||
|
||||
let num_rcvr_type_params = rcvr_generics.ty_params.len();
|
||||
ty::method {
|
||||
ident: m.ident,
|
||||
generics: ty_generics(ccx, None, &m.generics, num_rcvr_type_params),
|
||||
transformed_self_ty: transformed_self_ty,
|
||||
fty: fty,
|
||||
explicit_self: m.explicit_self.node,
|
||||
vis: method_vis,
|
||||
def_id: local_def(m.id)
|
||||
}
|
||||
ty::Method::new(
|
||||
m.ident,
|
||||
ty_generics(ccx, None, &m.generics, num_rcvr_type_params),
|
||||
transformed_self_ty,
|
||||
fty,
|
||||
m.explicit_self.node,
|
||||
method_vis,
|
||||
local_def(m.id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
use metadata::encoder;
|
||||
use middle::ty::{ReSkolemized, ReVar};
|
||||
use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid};
|
||||
use middle::ty::{br_fresh, ctxt, field, method};
|
||||
use middle::ty::{br_fresh, ctxt, field};
|
||||
use middle::ty::{mt, t, param_ty};
|
||||
use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region,
|
||||
re_empty};
|
||||
|
|
@ -375,7 +375,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn method_to_str(cx: ctxt, m: method) -> ~str {
|
||||
fn method_to_str(cx: ctxt, m: ty::Method) -> ~str {
|
||||
bare_fn_to_str(cx,
|
||||
m.fty.purity,
|
||||
m.fty.abis,
|
||||
|
|
@ -633,7 +633,7 @@ impl Repr for ty::Generics {
|
|||
}
|
||||
}
|
||||
|
||||
impl Repr for ty::method {
|
||||
impl Repr for ty::Method {
|
||||
fn repr(&self, tcx: ctxt) -> ~str {
|
||||
fmt!("method {ident: %s, generics: %s, transformed_self_ty: %s, \
|
||||
fty: %s, explicit_self: %s, vis: %s, def_id: %s}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue