1
Fork 0

convert librustc record types to structs

specifically:

freevars::freevar_entry
ty::{field_ty,AutoAdjustment,AutoRef}
mod::{method_param,method_map_entry}
This commit is contained in:
Erick Tryzelaar 2013-01-16 19:24:10 -08:00 committed by Tim Chevalier
parent d5d77b9351
commit 28da4ecdaa
14 changed files with 146 additions and 86 deletions

View file

@ -930,14 +930,18 @@ fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
let item = lookup_item(id, data); let item = lookup_item(id, data);
let mut result = ~[]; let mut result = ~[];
for reader::tagged_docs(item, tag_item_field) |an_item| { for reader::tagged_docs(item, tag_item_field) |an_item| {
let f = item_family(an_item); let f = item_family(an_item);
if f == PublicField || f == PrivateField || f == InheritedField { if f == PublicField || f == PrivateField || f == InheritedField {
let name = item_name(intr, an_item); let name = item_name(intr, an_item);
let did = item_def_id(an_item, cdata); let did = item_def_id(an_item, cdata);
let mt = field_mutability(an_item); let mt = field_mutability(an_item);
result.push({ident: name, id: did, vis: result.push(ty::field_ty {
family_to_visibility(f), mutability: mt}); ident: name,
} id: did, vis:
family_to_visibility(f),
mutability: mt,
});
}
} }
result result
} }

View file

@ -448,16 +448,20 @@ impl ast::def: tr {
impl ty::AutoAdjustment: tr { impl ty::AutoAdjustment: tr {
fn tr(xcx: extended_decode_ctxt) -> ty::AutoAdjustment { fn tr(xcx: extended_decode_ctxt) -> ty::AutoAdjustment {
{autoderefs: self.autoderefs, ty::AutoAdjustment {
autoref: self.autoref.map(|ar| ar.tr(xcx))} autoderefs: self.autoderefs,
autoref: self.autoref.map(|ar| ar.tr(xcx)),
}
} }
} }
impl ty::AutoRef: tr { impl ty::AutoRef: tr {
fn tr(xcx: extended_decode_ctxt) -> ty::AutoRef { fn tr(xcx: extended_decode_ctxt) -> ty::AutoRef {
{kind: self.kind, ty::AutoRef {
region: self.region.tr(xcx), kind: self.kind,
mutbl: self.mutbl} region: self.region.tr(xcx),
mutbl: self.mutbl,
}
} }
} }
@ -503,7 +507,10 @@ impl reader::Decoder: ebml_decoder_helper {
impl freevar_entry: tr { impl freevar_entry: tr {
fn tr(xcx: extended_decode_ctxt) -> freevar_entry { fn tr(xcx: extended_decode_ctxt) -> freevar_entry {
{def: self.def.tr(xcx), span: self.span.tr(xcx)} freevar_entry {
def: self.def.tr(xcx),
span: self.span.tr(xcx),
}
} }
} }
@ -533,21 +540,20 @@ fn encode_method_map_entry(ecx: @e::encode_ctxt,
impl reader::Decoder: read_method_map_entry_helper { impl reader::Decoder: read_method_map_entry_helper {
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry { fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
do self.read_rec { do self.read_rec {
{self_arg: method_map_entry {
self.read_field(~"self_arg", 0u, || { self_arg: self.read_field(~"self_arg", 0u, || {
self.read_arg(xcx) self.read_arg(xcx)
}), }),
explicit_self: explicit_self: self.read_field(~"explicit_self", 2u, || {
self.read_field(~"explicit_self", 2u, || {
let self_type: ast::self_ty_ = Decodable::decode(&self); let self_type: ast::self_ty_ = Decodable::decode(&self);
self_type self_type
}), }),
origin: origin: self.read_field(~"origin", 1u, || {
self.read_field(~"origin", 1u, || { let method_origin: method_origin =
let method_origin: method_origin = Decodable::decode(&self);
Decodable::decode(&self); method_origin.tr(xcx)
method_origin.tr(xcx) }),
})} }
} }
} }
} }
@ -559,7 +565,12 @@ impl method_origin: tr {
typeck::method_static(did.tr(xcx)) typeck::method_static(did.tr(xcx))
} }
typeck::method_param(ref mp) => { typeck::method_param(ref mp) => {
typeck::method_param({trait_id:(*mp).trait_id.tr(xcx),.. (*mp)}) typeck::method_param(
typeck::method_param {
trait_id: mp.trait_id.tr(xcx),
.. *mp
}
)
} }
typeck::method_trait(did, m, vstore) => { typeck::method_trait(did, m, vstore) => {
typeck::method_trait(did.tr(xcx), m, vstore) typeck::method_trait(did.tr(xcx), m, vstore)

View file

@ -34,10 +34,10 @@ export has_freevars;
// (The def_upvar will already have been stripped). // (The def_upvar will already have been stripped).
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type freevar_entry = { struct freevar_entry {
def: ast::def, //< The variable being accessed free. def: ast::def, //< The variable being accessed free.
span: span //< First span where it is accessed (there can be multiple) span: span //< First span where it is accessed (there can be multiple)
}; }
type freevar_info = @~[@freevar_entry]; type freevar_info = @~[@freevar_entry];
type freevar_map = HashMap<ast::node_id, freevar_info>; type freevar_map = HashMap<ast::node_id, freevar_info>;
@ -79,7 +79,10 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
if i == depth { // Made it to end of loop if i == depth { // Made it to end of loop
let dnum = ast_util::def_id_of_def(def).node; let dnum = ast_util::def_id_of_def(def).node;
if !seen.contains_key(dnum) { if !seen.contains_key(dnum) {
refs.push(@{def:def, span:expr.span}); refs.push(@freevar_entry {
def: def,
span: expr.span,
});
seen.insert(dnum, ()); seen.insert(dnum, ());
} }
} }

View file

@ -132,7 +132,11 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
// XXX: External crates. // XXX: External crates.
} }
} }
method_param({trait_id: trait_id, method_num: method_num, _}) | method_param(method_param {
trait_id: trait_id,
method_num: method_num,
_
}) |
method_trait(trait_id, method_num, _) | method_trait(trait_id, method_num, _) |
method_self(trait_id, method_num) => { method_self(trait_id, method_num) => {
if trait_id.crate == local_crate { if trait_id.crate == local_crate {

View file

@ -209,8 +209,12 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
}) })
} }
} }
typeck::method_param({trait_id:trait_id, method_num:off, typeck::method_param(typeck::method_param {
param_num:p, bound_num:b}) => { trait_id: trait_id,
method_num: off,
param_num: p,
bound_num: b
}) => {
match bcx.fcx.param_substs { match bcx.fcx.param_substs {
Some(ref substs) => { Some(ref substs) => {
let vtbl = base::find_vtable(bcx.tcx(), substs, p, b); let vtbl = base::find_vtable(bcx.tcx(), substs, p, b);

View file

@ -182,7 +182,10 @@ fn traverse_inline_body(cx: ctx, body: blk) {
} }
expr_field(_, _, _) => { expr_field(_, _, _) => {
match cx.method_map.find(e.id) { match cx.method_map.find(e.id) {
Some({origin: typeck::method_static(did), _}) => { Some(typeck::method_map_entry {
origin: typeck::method_static(did),
_
}) => {
traverse_def_id(cx, did); traverse_def_id(cx, did);
} }
_ => () _ => ()
@ -190,7 +193,10 @@ fn traverse_inline_body(cx: ctx, body: blk) {
} }
expr_method_call(*) => { expr_method_call(*) => {
match cx.method_map.find(e.id) { match cx.method_map.find(e.id) {
Some({origin: typeck::method_static(did), _}) => { Some(typeck::method_map_entry {
origin: typeck::method_static(did),
_
}) => {
traverse_def_id(cx, did); traverse_def_id(cx, did);
} }
Some(_) => {} Some(_) => {}

View file

@ -233,7 +233,10 @@ fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) {
} }
} }
} }
typeck::method_param({param_num: param, _}) => { typeck::method_param(typeck::method_param {
param_num: param,
_
}) => {
cx.uses[param] |= use_tydesc; cx.uses[param] |= use_tydesc;
} }
typeck::method_trait(*) | typeck::method_self(*) => (), typeck::method_trait(*) | typeck::method_self(*) => (),

View file

@ -272,12 +272,12 @@ enum vstore {
vstore_slice(Region) vstore_slice(Region)
} }
type field_ty = { struct field_ty {
ident: ident, ident: ident,
id: def_id, id: def_id,
vis: ast::visibility, vis: ast::visibility,
mutability: ast::struct_mutability mutability: ast::struct_mutability,
}; }
/// How an lvalue is to be used. /// How an lvalue is to be used.
#[auto_encode] #[auto_encode]
@ -356,18 +356,18 @@ impl region_variance : cmp::Eq {
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
pub type AutoAdjustment = { pub struct AutoAdjustment {
autoderefs: uint, autoderefs: uint,
autoref: Option<AutoRef> autoref: Option<AutoRef>
}; }
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
pub type AutoRef = { pub struct AutoRef {
kind: AutoRefKind, kind: AutoRefKind,
region: Region, region: Region,
mutbl: ast::mutability mutbl: ast::mutability
}; }
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
@ -3086,8 +3086,9 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
// and then the method bounds themselves... // and then the method bounds themselves...
ty::lookup_item_type(tcx, did).bounds ty::lookup_item_type(tcx, did).bounds
} }
typeck::method_param({trait_id:trt_id, typeck::method_param(typeck::method_param {
method_num:n_mth, _}) | trait_id: trt_id,
method_num: n_mth, _}) |
typeck::method_trait(trt_id, n_mth, _) | typeck::method_trait(trt_id, n_mth, _) |
typeck::method_self(trt_id, n_mth) => { typeck::method_self(trt_id, n_mth) => {
// ...trait methods bounds, in contrast, include only the // ...trait methods bounds, in contrast, include only the
@ -4075,25 +4076,27 @@ pure fn is_public(f: field_ty) -> bool {
} }
fn struct_field_tys(fields: ~[@struct_field]) -> ~[field_ty] { fn struct_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
let mut rslt = ~[]; do fields.map |field| {
for fields.each |field| {
match field.node.kind { match field.node.kind {
named_field(ident, mutability, visibility) => { named_field(ident, mutability, visibility) => {
rslt.push({ident: ident, field_ty {
id: ast_util::local_def(field.node.id), ident: ident,
vis: visibility, id: ast_util::local_def(field.node.id),
mutability: mutability}); vis: visibility,
mutability: mutability,
}
} }
unnamed_field => { unnamed_field => {
rslt.push({ident: field_ty {
syntax::parse::token::special_idents::unnamed_field, ident:
id: ast_util::local_def(field.node.id), syntax::parse::token::special_idents::unnamed_field,
vis: ast::public, id: ast_util::local_def(field.node.id),
mutability: ast::struct_immutable}); vis: ast::public,
mutability: ast::struct_immutable,
}
} }
} }
} }
rslt
} }
// Return a list of fields corresponding to the struct's items // Return a list of fields corresponding to the struct's items

View file

@ -455,10 +455,13 @@ impl LookupContext {
explicit_self: method.self_ty, explicit_self: method.self_ty,
num_method_tps: method.tps.len(), num_method_tps: method.tps.len(),
self_mode: get_mode_from_self_type(method.self_ty), self_mode: get_mode_from_self_type(method.self_ty),
origin: method_param({trait_id:init_trait_id, origin: method_param(
method_num:pos, method_param {
param_num:param_ty.idx, trait_id: init_trait_id,
bound_num:this_bound_idx}) method_num: pos,
param_num: param_ty.idx,
bound_num: this_bound_idx,
})
}; };
debug!("pushing inherent candidate for param: %?", cand); debug!("pushing inherent candidate for param: %?", cand);
@ -834,10 +837,14 @@ impl LookupContext {
Some(move mme) => { Some(move mme) => {
self.fcx.write_adjustment( self.fcx.write_adjustment(
self.self_expr.id, self.self_expr.id,
@{autoderefs: autoderefs, @ty::AutoAdjustment {
autoref: Some({kind: kind, autoderefs: autoderefs,
region: region, autoref: Some(ty::AutoRef {
mutbl: *mutbl})}); kind: kind,
region: region,
mutbl: *mutbl,
}),
});
return Some(mme); return Some(mme);
} }
} }
@ -1004,10 +1011,14 @@ impl LookupContext {
}; };
self.fcx.write_ty_substs(self.callee_id, fty, all_substs); self.fcx.write_ty_substs(self.callee_id, fty, all_substs);
return {self_arg: {mode: ast::expl(candidate.self_mode), method_map_entry {
ty: candidate.rcvr_ty}, self_arg: {
explicit_self: candidate.explicit_self, mode: ast::expl(candidate.self_mode),
origin: candidate.origin}; ty: candidate.rcvr_ty,
},
explicit_self: candidate.explicit_self,
origin: candidate.origin,
}
} }
fn enforce_trait_instance_limitations(&self, fn enforce_trait_instance_limitations(&self,
@ -1050,7 +1061,7 @@ impl LookupContext {
method_static(method_id) | method_self(method_id, _) => { method_static(method_id) | method_self(method_id, _) => {
bad = self.tcx().destructors.contains_key(method_id); bad = self.tcx().destructors.contains_key(method_id);
} }
method_param({trait_id: trait_id, _}) | method_param(method_param { trait_id: trait_id, _ }) |
method_trait(trait_id, _, _) => { method_trait(trait_id, _, _) => {
bad = self.tcx().destructor_for_type.contains_key(trait_id); bad = self.tcx().destructor_for_type.contains_key(trait_id);
} }

View file

@ -730,7 +730,10 @@ impl @fn_ctxt {
fn write_autoderef_adjustment(node_id: ast::node_id, derefs: uint) { fn write_autoderef_adjustment(node_id: ast::node_id, derefs: uint) {
if derefs == 0 { return; } if derefs == 0 { return; }
self.write_adjustment(node_id, @{autoderefs: derefs, autoref: None}); self.write_adjustment(
node_id,
@ty::AutoAdjustment { autoderefs: derefs, autoref: None }
);
} }
fn write_adjustment(node_id: ast::node_id, adj: @ty::AutoAdjustment) { fn write_adjustment(node_id: ast::node_id, adj: @ty::AutoAdjustment) {

View file

@ -324,7 +324,9 @@ fn constrain_auto_ref(
let adjustment = rcx.fcx.inh.adjustments.find(expr.id); let adjustment = rcx.fcx.inh.adjustments.find(expr.id);
let region = match adjustment { let region = match adjustment {
Some(@{autoref: Some(ref auto_ref), _}) => auto_ref.region, Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => {
auto_ref.region
},
_ => { return; } _ => { return; }
}; };

View file

@ -20,6 +20,7 @@ use middle::typeck::check::{fn_ctxt, lookup_local, self_info};
use middle::typeck::infer::{force_all, resolve_all, resolve_region}; use middle::typeck::infer::{force_all, resolve_all, resolve_region};
use middle::typeck::infer::{resolve_type}; use middle::typeck::infer::{resolve_type};
use middle::typeck::infer; use middle::typeck::infer;
use middle::typeck::method_map_entry;
use middle::typeck::{vtable_param, vtable_trait, write_substs_to_tcx}; use middle::typeck::{vtable_param, vtable_trait, write_substs_to_tcx};
use middle::typeck::{write_ty_to_tcx}; use middle::typeck::{write_ty_to_tcx};
use util::ppaux; use util::ppaux;
@ -63,8 +64,11 @@ fn resolve_method_map_entry(fcx: @fn_ctxt, sp: span, id: ast::node_id)
for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| { for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| {
fcx.ccx.method_map.insert( fcx.ccx.method_map.insert(
id, id,
{self_arg: {mode: mme.self_arg.mode, ty: *t}, method_map_entry {
..*mme}); self_arg: {mode: mme.self_arg.mode, ty: *t},
.. *mme
}
);
} }
} }
} }
@ -91,14 +95,16 @@ fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id)
Some(*autoref) Some(*autoref)
} }
Ok(r) => { Ok(r) => {
Some({region: r, ..*autoref}) Some(ty::AutoRef {region: r, ..*autoref})
} }
} }
} }
None => None None => None
}; };
let resolved_adj = @{autoref: resolved_autoref, ..*adj}; let resolved_adj = @ty::AutoAdjustment {
autoref: resolved_autoref,
..*adj};
debug!("Adjustments for node %d: %?", id, resolved_adj); debug!("Adjustments for node %d: %?", id, resolved_adj);
fcx.tcx().adjustments.insert(id, resolved_adj); fcx.tcx().adjustments.insert(id, resolved_adj);
} }

View file

@ -275,9 +275,9 @@ priv impl Assign {
do sub.tys(a, nr_b).chain |_t| { do sub.tys(a, nr_b).chain |_t| {
let r_a = self.infcx.next_region_var_nb(self.span); let r_a = self.infcx.next_region_var_nb(self.span);
do sub.contraregions(r_a, r_b).chain |_r| { do sub.contraregions(r_a, r_b).chain |_r| {
Ok(Some(@{ Ok(Some(@ty::AutoAdjustment {
autoderefs: autoderefs, autoderefs: autoderefs,
autoref: Some({ autoref: Some(ty::AutoRef {
kind: kind, kind: kind,
region: r_a, region: r_a,
mutbl: m mutbl: m

View file

@ -142,7 +142,7 @@ pub enum method_origin {
// with a bounded trait. // with a bounded trait.
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type method_param = { struct method_param {
// the trait containing the method to be invoked // the trait containing the method to be invoked
trait_id: ast::def_id, trait_id: ast::def_id,
@ -154,10 +154,10 @@ type method_param = {
param_num: uint, param_num: uint,
// index of the bound for this type parameter which specifies the trait // index of the bound for this type parameter which specifies the trait
bound_num: uint bound_num: uint,
}; }
pub type method_map_entry = { pub struct method_map_entry {
// the type and mode of the self parameter, which is not reflected // the type and mode of the self parameter, which is not reflected
// in the fn type (FIXME #3446) // in the fn type (FIXME #3446)
self_arg: ty::arg, self_arg: ty::arg,
@ -166,8 +166,8 @@ pub type method_map_entry = {
explicit_self: ast::self_ty_, explicit_self: ast::self_ty_,
// method details being invoked // method details being invoked
origin: method_origin origin: method_origin,
}; }
// maps from an expression id that corresponds to a method call to the details // maps from an expression id that corresponds to a method call to the details
// of the method to be invoked // of the method to be invoked