提交 34bd1691 编写于 作者: B bors

auto merge of #15091 : nikomatsakis/rust/issue-5527-rename-types, r=pcwalton

Some cleanups I'm sick of rebasing.

r? @pcwalton (do you agree with new names?)
......@@ -193,7 +193,7 @@ pub fn get_struct_fields(cstore: &cstore::CStore,
pub fn get_type(tcx: &ty::ctxt,
def: ast::DefId)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_type(&*cdata, def.node, tcx)
......@@ -206,7 +206,7 @@ pub fn get_trait_def(tcx: &ty::ctxt, def: ast::DefId) -> ty::TraitDef {
}
pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
def: ast::DefId) -> ty::ty_param_bounds_and_ty {
def: ast::DefId) -> ty::Polytype {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(class_id.krate);
let all_items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items);
......@@ -224,7 +224,7 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
def)).to_string()
});
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: ty::Generics {types: VecPerParamSpace::empty(),
regions: VecPerParamSpace::empty()},
ty: ty
......
......@@ -422,7 +422,7 @@ pub fn get_trait_def(cdata: Cmd,
}
pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {
let item = lookup_item(id, cdata.data());
......@@ -432,7 +432,7 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
let rp_defs = item_region_param_defs(item, cdata);
ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: ty::Generics {types: tp_defs,
regions: rp_defs},
ty: t
......
......@@ -196,11 +196,11 @@ fn encode_item_variances(ebml_w: &mut Encoder,
fn encode_bounds_and_type(ebml_w: &mut Encoder,
ecx: &EncodeContext,
tpt: &ty::ty_param_bounds_and_ty) {
encode_ty_type_param_defs(ebml_w, ecx, &tpt.generics.types,
pty: &ty::Polytype) {
encode_ty_type_param_defs(ebml_w, ecx, &pty.generics.types,
tag_items_data_item_ty_param_bounds);
encode_region_param_defs(ebml_w, &tpt.generics.regions);
encode_type(ecx, ebml_w, tpt.ty);
encode_region_param_defs(ebml_w, &pty.generics.regions);
encode_type(ecx, ebml_w, pty.ty);
}
fn encode_variant_id(ebml_w: &mut Encoder, vid: DefId) {
......@@ -772,8 +772,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
encode_stability(ebml_w, stab);
// The type for methods gets encoded twice, which is unfortunate.
let tpt = lookup_item_type(ecx.tcx, m.def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = lookup_item_type(ecx.tcx, m.def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
let elem = ast_map::PathName(m.ident.name);
encode_path(ebml_w, impl_path.chain(Some(elem).move_iter()));
......@@ -785,7 +785,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
}
for &ast_method in ast_method_opt.iter() {
let any_types = !tpt.generics.types.is_empty();
let any_types = !pty.generics.types.is_empty();
if any_types || is_default_impl || should_inline(ast_method.attrs.as_slice()) {
encode_inlined_item(ecx, ebml_w,
IIMethodRef(local_def(parent_id), false,
......@@ -1218,8 +1218,8 @@ fn add_to_index(item: &Item, ebml_w: &Encoder,
fn_style_static_method_family(
method_ty.fty.fn_style));
let tpt = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
}
_ => {
......@@ -1242,8 +1242,8 @@ fn add_to_index(item: &Item, ebml_w: &Encoder,
// this.
if method_ty.explicit_self != SelfStatic {
// FIXME: I feel like there is something funny going on.
let tpt = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
}
encode_method_sort(ebml_w, 'p');
encode_inlined_item(ecx, ebml_w,
......
......@@ -839,9 +839,9 @@ trait ebml_writer_helpers {
fn emit_type_param_def(&mut self,
ecx: &e::EncodeContext,
type_param_def: &ty::TypeParameterDef);
fn emit_tpbt(&mut self,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
fn emit_polytype(&mut self,
ecx: &e::EncodeContext,
pty: ty::Polytype);
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs);
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
}
......@@ -865,26 +865,26 @@ fn emit_type_param_def(&mut self,
});
}
fn emit_tpbt(&mut self,
fn emit_polytype(&mut self,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty) {
self.emit_struct("ty_param_bounds_and_ty", 2, |this| {
pty: ty::Polytype) {
self.emit_struct("Polytype", 2, |this| {
this.emit_struct_field("generics", 0, |this| {
this.emit_struct("Generics", 2, |this| {
this.emit_struct_field("types", 0, |this| {
Ok(encode_vec_per_param_space(
this, &tpbt.generics.types,
this, &pty.generics.types,
|this, def| this.emit_type_param_def(ecx, def)))
});
this.emit_struct_field("regions", 1, |this| {
Ok(encode_vec_per_param_space(
this, &tpbt.generics.regions,
this, &pty.generics.regions,
|this, def| def.encode(this).unwrap()))
})
})
});
this.emit_struct_field("ty", 1, |this| {
Ok(this.emit_ty(ecx, tpbt.ty))
Ok(this.emit_ty(ecx, pty.ty))
})
});
}
......@@ -1030,11 +1030,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
for &tpbt in tcx.tcache.borrow().find(&lid).iter() {
for &pty in tcx.tcache.borrow().find(&lid).iter() {
ebml_w.tag(c::tag_table_tcache, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_tpbt(ecx, tpbt.clone());
ebml_w.emit_polytype(ecx, pty.clone());
})
})
}
......@@ -1142,8 +1142,8 @@ trait ebml_decoder_decoder_helpers {
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
-> ty::TypeParameterDef;
fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty;
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
-> ty::Polytype;
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs;
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment;
fn convert_def_id(&mut self,
......@@ -1245,10 +1245,10 @@ fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
}).unwrap()
}
fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty {
self.read_struct("ty_param_bounds_and_ty", 2, |this| {
Ok(ty::ty_param_bounds_and_ty {
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
-> ty::Polytype {
self.read_struct("Polytype", 2, |this| {
Ok(ty::Polytype {
generics: this.read_struct_field("generics", 0, |this| {
this.read_struct("Generics", 2, |this| {
Ok(ty::Generics {
......@@ -1408,9 +1408,9 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
}
c::tag_table_tcache => {
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
let pty = val_dsr.read_polytype(xcx);
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
dcx.tcx.tcache.borrow_mut().insert(lid, tpbt);
dcx.tcx.tcache.borrow_mut().insert(lid, pty);
}
c::tag_table_param_defs => {
let bounds = val_dsr.read_type_param_def(xcx);
......
......@@ -721,7 +721,7 @@ fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
impl<'a> AstConv for Context<'a>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty {
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype {
ty::lookup_item_type(self.tcx, id)
}
......
......@@ -1026,21 +1026,16 @@ pub struct ParameterEnvironment {
/// A polytype.
///
/// - `bounds`: The list of bounds for each type parameter. The length of the
/// list also tells you how many type parameters there are.
///
/// - `rp`: true if the type is region-parameterized. Types can have at
/// most one region parameter, always called `&self`.
///
/// - `ty`: the base type. May have reference to the (unsubstituted) bound
/// region `&self` or to (unsubstituted) ty_param types
/// - `generics`: the set of type parameters and their bounds
/// - `ty`: the base types, which may reference the parameters defined
/// in `generics`
#[deriving(Clone)]
pub struct ty_param_bounds_and_ty {
pub struct Polytype {
pub generics: Generics,
pub ty: t
}
/// As `ty_param_bounds_and_ty` but for a trait ref.
/// As `Polytype` but for a trait ref.
pub struct TraitDef {
pub generics: Generics,
pub bounds: BuiltinBounds,
......@@ -1054,12 +1049,7 @@ pub struct ItemSubsts {
pub substs: Substs,
}
pub struct ty_param_substs_and_ty {
pub substs: Substs,
pub ty: ty::t
}
pub type type_cache = RefCell<DefIdMap<ty_param_bounds_and_ty>>;
pub type type_cache = RefCell<DefIdMap<Polytype>>;
pub type node_type_table = RefCell<HashMap<uint,t>>;
......@@ -3848,7 +3838,7 @@ pub fn enum_variant_with_id(cx: &ctxt,
// the type cache. Returns the type parameters and type.
pub fn lookup_item_type(cx: &ctxt,
did: ast::DefId)
-> ty_param_bounds_and_ty {
-> Polytype {
lookup_locally_or_in_crate_store(
"tcache", did, &mut *cx.tcache.borrow_mut(),
|| csearch::get_type(cx, did))
......@@ -3946,7 +3936,7 @@ pub fn lookup_field_type(tcx: &ctxt,
} else {
let mut tcache = tcx.tcache.borrow_mut();
match tcache.find(&id) {
Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
Some(&Polytype {ty, ..}) => ty,
None => {
let tpt = csearch::get_field_type(tcx, struct_id, id);
tcache.insert(id, tpt.clone());
......
......@@ -53,10 +53,9 @@
use middle::def;
use middle::lang_items::FnMutTraitLangItem;
use rl = middle::resolve_lifetime;
use middle::subst::{Subst, Substs};
use middle::subst;
use middle::ty::ty_param_substs_and_ty;
use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
use middle::ty;
use middle::typeck::TypeAndSubsts;
use middle::typeck::lookup_def_tcx;
use middle::typeck::rscope::RegionScope;
use middle::typeck::rscope;
......@@ -71,7 +70,7 @@
pub trait AstConv {
fn tcx<'a>(&'a self) -> &'a ty::ctxt;
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty;
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype;
fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef>;
// what type should we use when a type is omitted?
......@@ -154,7 +153,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
rscope: &RS,
decl_generics: &ty::Generics,
self_ty: Option<ty::t>,
path: &ast::Path) -> subst::Substs
path: &ast::Path) -> Substs
{
/*!
* Given a path `path` that refers to an item `I` with the
......@@ -172,13 +171,13 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
// Note: in the case of traits, the self parameter is also
// defined, but we don't currently create a `type_param_def` for
// `Self` because it is implicit.
assert!(decl_generics.regions.all(|d| d.space == subst::TypeSpace));
assert!(decl_generics.types.all(|d| d.space != subst::FnSpace));
assert!(decl_generics.regions.all(|d| d.space == TypeSpace));
assert!(decl_generics.types.all(|d| d.space != FnSpace));
// If the type is parameterized by the this region, then replace this
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
let expected_num_region_params = decl_generics.regions.len(subst::TypeSpace);
let expected_num_region_params = decl_generics.regions.len(TypeSpace);
let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len();
let regions = if expected_num_region_params == supplied_num_region_params {
path.segments.last().unwrap().lifetimes.iter().map(
......@@ -204,7 +203,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
};
// Convert the type parameters supplied by the user.
let ty_param_defs = decl_generics.types.get_vec(subst::TypeSpace);
let ty_param_defs = decl_generics.types.get_vec(TypeSpace);
let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).count();
let formal_ty_param_count = ty_param_defs.len();
let required_ty_param_count = ty_param_defs.iter()
......@@ -246,7 +245,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
.map(|a_t| ast_ty_to_ty(this, rscope, &**a_t))
.collect();
let mut substs = subst::Substs::new_type(tps, regions);
let mut substs = Substs::new_type(tps, regions);
match self_ty {
None => {
......@@ -258,14 +257,14 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
// "declared" (in other words, this should be a
// trait-ref).
assert!(decl_generics.types.get_self().is_some());
substs.types.push(subst::SelfSpace, ty);
substs.types.push(SelfSpace, ty);
}
}
for param in ty_param_defs.slice_from(supplied_ty_param_count).iter() {
let default = param.default.unwrap();
let default = default.subst_spanned(tcx, &substs, Some(path.span));
substs.types.push(subst::TypeSpace, default);
substs.types.push(TypeSpace, default);
}
substs
......@@ -289,17 +288,17 @@ pub fn ast_path_to_ty<AC:AstConv,RS:RegionScope>(
rscope: &RS,
did: ast::DefId,
path: &ast::Path)
-> ty_param_substs_and_ty
-> TypeAndSubsts
{
let tcx = this.tcx();
let ty::ty_param_bounds_and_ty {
let ty::Polytype {
generics: generics,
ty: decl_ty
} = this.get_item_ty(did);
let substs = ast_path_substs(this, rscope, &generics, None, path);
let ty = decl_ty.subst(tcx, &substs);
ty_param_substs_and_ty { substs: substs, ty: ty }
TypeAndSubsts { substs: substs, ty: ty }
}
pub static NO_REGIONS: uint = 1;
......@@ -547,11 +546,11 @@ pub fn trait_ref_for_unboxed_function<AC:AstConv,
let output_type = ast_ty_to_ty(this,
rscope,
&*unboxed_function.decl.output);
let mut substs = subst::Substs::new_type(vec!(input_tuple, output_type),
let mut substs = Substs::new_type(vec!(input_tuple, output_type),
Vec::new());
match self_ty {
Some(s) => substs.types.push(subst::SelfSpace, s),
Some(s) => substs.types.push(SelfSpace, s),
None => ()
}
......
......@@ -133,10 +133,10 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
match v_def.variant_def_ids() {
Some((enm, var)) => {
// Assign the pattern the type of the *enum*, not the variant.
let enum_tpt = ty::lookup_item_type(tcx, enm);
let enum_pty = ty::lookup_item_type(tcx, enm);
instantiate_path(pcx.fcx,
path,
enum_tpt,
enum_pty,
v_def,
pat.span,
pat.id);
......@@ -190,16 +190,16 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
let s_def_id = s_def.def_id();
// Assign the pattern the type of the struct.
let ctor_tpt = ty::lookup_item_type(tcx, s_def_id);
let struct_tpt = if ty::is_fn_ty(ctor_tpt.ty) {
ty::ty_param_bounds_and_ty {ty: ty::ty_fn_ret(ctor_tpt.ty),
..ctor_tpt}
let ctor_pty = ty::lookup_item_type(tcx, s_def_id);
let struct_pty = if ty::is_fn_ty(ctor_pty.ty) {
ty::Polytype {ty: ty::ty_fn_ret(ctor_pty.ty),
..ctor_pty}
} else {
ctor_tpt
ctor_pty
};
instantiate_path(pcx.fcx,
path,
struct_tpt,
struct_pty,
s_def,
pat.span,
pat.id);
......@@ -478,9 +478,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
ast::PatEnum(..) |
ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
let const_did = tcx.def_map.borrow().get_copy(&pat.id).def_id();
let const_tpt = ty::lookup_item_type(tcx, const_did);
demand::suptype(fcx, pat.span, expected, const_tpt.ty);
fcx.write_ty(pat.id, const_tpt.ty);
let const_pty = ty::lookup_item_type(tcx, const_did);
demand::suptype(fcx, pat.span, expected, const_pty.ty);
fcx.write_ty(pat.id, const_pty.ty);
}
ast::PatIdent(bm, ref name, sub) if pat_is_binding(&tcx.def_map, pat) => {
let typ = fcx.local_ty(pat.span, pat.id);
......
......@@ -93,6 +93,7 @@ trait `ToStr` imported, and I call `to_str()` on a value of type `T`,
use middle::typeck::{MethodStatic, MethodObject};
use middle::typeck::{param_index};
use middle::typeck::check::regionmanip::replace_late_bound_regions_in_fn_sig;
use middle::typeck::TypeAndSubsts;
use util::common::indenter;
use util::ppaux;
use util::ppaux::Repr;
......@@ -688,7 +689,7 @@ fn push_candidates_from_impl(&mut self,
// variables for each parameter:
let span = self.self_expr.map_or(self.span, |e| e.span);
let vcx = self.fcx.vtable_context();
let ty::ty_param_substs_and_ty {
let TypeAndSubsts {
substs: impl_substs,
ty: impl_ty
} = impl_self_ty(&vcx, span, impl_did);
......
......@@ -85,7 +85,7 @@
use middle::subst;
use middle::subst::{Subst, Substs, VecPerParamSpace, ParamSpace};
use middle::ty::{FnSig, VariantInfo};
use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty};
use middle::ty::{Polytype};
use middle::ty::{ParamTy, Disr, ExprTyProvider};
use middle::ty;
use middle::ty_fold::TypeFolder;
......@@ -109,6 +109,7 @@
use middle::typeck::no_params;
use middle::typeck::{require_same_types, vtable_map};
use middle::typeck::{MethodCall, MethodMap};
use middle::typeck::{TypeAndSubsts};
use middle::lang_items::TypeIdLangItem;
use util::common::{block_query, indenter, loop_query};
use util::ppaux;
......@@ -644,20 +645,20 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
it.id);
}
ast::ItemFn(ref decl, _, _, _, ref body) => {
let fn_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
let fn_pty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
let param_env = ty::construct_parameter_environment(ccx.tcx,
&fn_tpt.generics,
&fn_pty.generics,
body.id);
check_bare_fn(ccx, &**decl, &**body, it.id, fn_tpt.ty, param_env);
check_bare_fn(ccx, &**decl, &**body, it.id, fn_pty.ty, param_env);
}
ast::ItemImpl(_, ref opt_trait_ref, _, ref ms) => {
debug!("ItemImpl {} with id {}", token::get_ident(it.ident), it.id);
let impl_tpt = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
let impl_pty = ty::lookup_item_type(ccx.tcx, ast_util::local_def(it.id));
for m in ms.iter() {
check_method_body(ccx, &impl_tpt.generics, &**m);
check_method_body(ccx, &impl_pty.generics, &**m);
}
match *opt_trait_ref {
......@@ -669,7 +670,7 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
ast_trait_ref,
&*impl_trait_ref,
ms.as_slice());
vtable::resolve_impl(ccx.tcx, it, &impl_tpt.generics, &*impl_trait_ref);
vtable::resolve_impl(ccx.tcx, it, &impl_pty.generics, &*impl_trait_ref);
}
None => { }
}
......@@ -693,8 +694,8 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
check_struct(ccx, it.id, it.span);
}
ast::ItemTy(ref t, ref generics) => {
let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id);
check_bounds_are_used(ccx, t.span, &generics.ty_params, tpt_ty);
let pty_ty = ty::node_id_to_type(ccx.tcx, it.id);
check_bounds_are_used(ccx, t.span, &generics.ty_params, pty_ty);
}
ast::ItemForeignMod(ref m) => {
if m.abi == abi::RustIntrinsic {
......@@ -703,8 +704,8 @@ pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
}
} else {
for item in m.items.iter() {
let tpt = ty::lookup_item_type(ccx.tcx, local_def(item.id));
if !tpt.generics.types.is_empty() {
let pty = ty::lookup_item_type(ccx.tcx, local_def(item.id));
if !pty.generics.types.is_empty() {
ccx.tcx.sess.span_err(item.span, "foreign items may not have type parameters");
}
......@@ -1048,7 +1049,7 @@ fn compare_impl_method(tcx: &ty::ctxt,
impl<'a> AstConv for FnCtxt<'a> {
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.ccx.tcx }
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty {
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype {
ty::lookup_item_type(self.tcx(), id)
}
......@@ -1791,7 +1792,7 @@ fn check_expr_with_lvalue_pref(fcx: &FnCtxt, expr: &ast::Expr,
pub fn impl_self_ty(vcx: &VtableContext,
span: Span, // (potential) receiver for this impl
did: ast::DefId)
-> ty_param_substs_and_ty {
-> TypeAndSubsts {
let tcx = vcx.tcx();
let ity = ty::lookup_item_type(tcx, did);
......@@ -1805,7 +1806,7 @@ pub fn impl_self_ty(vcx: &VtableContext,
let substs = subst::Substs::new_type(tps, rps);
let substd_ty = raw_ty.subst(tcx, &substs);
ty_param_substs_and_ty { substs: substs, ty: substd_ty }
TypeAndSubsts { substs: substs, ty: substd_ty }
}
// Only for fields! Returns <none> for methods>
......@@ -2855,8 +2856,8 @@ fn check_struct_enum_variant(fcx: &FnCtxt,
}
ast::ExprPath(ref pth) => {
let defn = lookup_def(fcx, pth.span, id);
let tpt = ty_param_bounds_and_ty_for_def(fcx, expr.span, defn);
instantiate_path(fcx, pth, tpt, defn, expr.span, expr.id);
let pty = polytype_for_def(fcx, expr.span, defn);
instantiate_path(fcx, pth, pty, defn, expr.span, expr.id);
}
ast::ExprInlineAsm(ref ia) => {
for &(_, ref input) in ia.inputs.iter() {
......@@ -3751,10 +3752,10 @@ pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> def::Def {
}
// Returns the type parameter count and the type for the given definition.
pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
sp: Span,
defn: def::Def)
-> ty_param_bounds_and_ty {
pub fn polytype_for_def(fcx: &FnCtxt,
sp: Span,
defn: def::Def)
-> Polytype {
match defn {
def::DefArg(nid, _) | def::DefLocal(nid, _) |
def::DefBinding(nid, _) => {
......@@ -3767,7 +3768,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
return ty::lookup_item_type(fcx.ccx.tcx, id);
}
def::DefUpvar(_, inner, _, _) => {
return ty_param_bounds_and_ty_for_def(fcx, sp, *inner);
return polytype_for_def(fcx, sp, *inner);
}
def::DefTrait(_) |
def::DefTy(_) |
......@@ -3803,7 +3804,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
// number of type parameters and type.
pub fn instantiate_path(fcx: &FnCtxt,
path: &ast::Path,
polytype: ty_param_bounds_and_ty,
polytype: Polytype,
def: def::Def,
span: Span,
node_id: ast::NodeId) {
......
......@@ -23,6 +23,7 @@
use middle::typeck::{vtable_static, vtable_param, vtable_error};
use middle::typeck::{param_index};
use middle::typeck::MethodCall;
use middle::typeck::TypeAndSubsts;
use middle::subst;
use middle::subst::{Subst, VecPerParamSpace};
use util::common::indenter;
......@@ -353,7 +354,7 @@ fn search_for_vtable(vcx: &VtableContext,
// FIXME: document a bit more what this means
//
// FIXME(#5781) this should be mk_eqty not mk_subty
let ty::ty_param_substs_and_ty {
let TypeAndSubsts {
substs: substs,
ty: for_ty
} = impl_self_ty(vcx, span, impl_did);
......
......@@ -23,7 +23,7 @@
use middle::ty::{ImplContainer, lookup_item_type};
use middle::ty::{t, ty_bool, ty_char, ty_bot, ty_box, ty_enum, ty_err};
use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_nil};
use middle::ty::{ty_param, ty_param_bounds_and_ty, ty_ptr};
use middle::ty::{ty_param, Polytype, ty_ptr};
use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup};
use middle::ty::{ty_uint, ty_uniq, ty_bare_fn, ty_closure};
use middle::ty::type_is_ty_var;
......@@ -378,7 +378,7 @@ fn instantiate_default_methods(&self,
// construct the polytype for the method based on the
// method_ty. it will have all the generics from the
// impl, plus its own.
let new_polytype = ty::ty_param_bounds_and_ty {
let new_polytype = ty::Polytype {
generics: new_method_ty.generics.clone(),
ty: ty::mk_bare_fn(tcx, new_method_ty.fty.clone())
};
......@@ -487,8 +487,8 @@ fn iter_impls_of_trait_local(&self, trait_def_id: DefId, f: |DefId|) {
}
fn polytypes_unify(&self,
polytype_a: ty_param_bounds_and_ty,
polytype_b: ty_param_bounds_and_ty)
polytype_a: Polytype,
polytype_b: Polytype)
-> bool {
let universally_quantified_a =
self.universally_quantify_polytype(polytype_a);
......@@ -503,7 +503,7 @@ fn polytypes_unify(&self,
// Converts a polytype to a monotype by replacing all parameters with
// type variables. Returns the monotype and the type variables created.
fn universally_quantify_polytype(&self, polytype: ty_param_bounds_and_ty)
fn universally_quantify_polytype(&self, polytype: Polytype)
-> UniversalQuantificationResult
{
let substitutions =
......@@ -526,7 +526,7 @@ fn can_unify_universally_quantified<'a>(&self,
}
fn get_self_type_for_implementation(&self, impl_did: DefId)
-> ty_param_bounds_and_ty {
-> Polytype {
self.crate_context.tcx.tcache.borrow().get_copy(&impl_did)
}
......@@ -748,7 +748,7 @@ pub fn make_substs_for_receiver_types(tcx: &ty::ctxt,
fn subst_receiver_types_in_method_ty(tcx: &ty::ctxt,
impl_id: ast::DefId,
impl_poly_type: &ty::ty_param_bounds_and_ty,
impl_poly_type: &ty::Polytype,
trait_ref: &ty::TraitRef,
new_def_id: ast::DefId,
method: &ty::Method,
......
......@@ -24,9 +24,9 @@
that they are generic types that may have type parameters (more
mathematically phrased, they are universally quantified over a set of
type parameters). Polytypes are represented by an instance of
`ty::ty_param_bounds_and_ty`. This combines the core type along with
a list of the bounds for each parameter. Type parameters themselves
are represented as `ty_param()` instances.
`ty::Polytype`. This combines the core type along with a list of the
bounds for each parameter. Type parameters themselves are represented
as `ty_param()` instances.
*/
......@@ -38,7 +38,7 @@
use middle::subst;
use middle::subst::{Substs};
use middle::ty::{ImplContainer, MethodContainer, TraitContainer};
use middle::ty::{ty_param_bounds_and_ty};
use middle::ty::{Polytype};
use middle::ty;
use middle::typeck::astconv::{AstConv, ty_of_arg};
use middle::typeck::astconv::{ast_ty_to_ty};
......@@ -84,7 +84,7 @@ fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
pub fn collect_item_types(ccx: &CrateCtxt, krate: &ast::Crate) {
fn collect_intrinsic_type(ccx: &CrateCtxt,
lang_item: ast::DefId) {
let ty::ty_param_bounds_and_ty { ty: ty, .. } =
let ty::Polytype { ty: ty, .. } =
ccx.get_item_ty(lang_item);
ccx.tcx.intrinsic_defs.borrow_mut().insert(lang_item, ty);
}
......@@ -113,7 +113,7 @@ fn to_ty<RS:RegionScope>(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t {
impl<'a> AstConv for CrateCtxt<'a> {
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty {
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype {
if id.krate != ast::LOCAL_CRATE {
return csearch::get_type(self.tcx, id)
}
......@@ -167,12 +167,12 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
}
ast::StructVariantKind(struct_def) => {
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics_for_type(ccx, generics),
ty: enum_ty
};
convert_struct(ccx, &*struct_def, tpt, variant.node.id);
convert_struct(ccx, &*struct_def, pty, variant.node.id);
let input_tys: Vec<_> = struct_def.fields.iter().map(
|f| ty::node_id_to_type(ccx.tcx, f.node.id)).collect();
......@@ -180,12 +180,12 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
}
};
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics_for_type(ccx, generics),
ty: result_ty
};
tcx.tcache.borrow_mut().insert(local_def(variant.node.id), tpt);
tcx.tcache.borrow_mut().insert(local_def(variant.node.id), pty);
write_ty_to_tcx(tcx, variant.node.id, result_ty);
}
......@@ -251,7 +251,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
fn make_static_method_ty(ccx: &CrateCtxt, m: &ty::Method) {
ccx.tcx.tcache.borrow_mut().insert(
m.def_id,
ty_param_bounds_and_ty {
Polytype {
generics: m.generics.clone(),
ty: ty::mk_bare_fn(ccx.tcx, m.fty.clone()) });
}
......@@ -295,7 +295,7 @@ pub fn convert_field(ccx: &CrateCtxt,
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */
ccx.tcx.tcache.borrow_mut().insert(local_def(v.node.id),
ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: struct_generics.clone(),
ty: tt
});
......@@ -347,7 +347,7 @@ fn convert_methods(ccx: &CrateCtxt,
fty.repr(ccx.tcx));
tcx.tcache.borrow_mut().insert(
local_def(m.id),
ty_param_bounds_and_ty {
Polytype {
generics: mty.generics.clone(),
ty: fty
});
......@@ -422,10 +422,10 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
ast::ItemForeignMod(_) | ast::ItemMod(_) | ast::ItemMac(_) => {}
ast::ItemEnum(ref enum_definition, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "enumeration");
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
let pty = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, pty.ty);
get_enum_variant_types(ccx,
tpt.ty,
pty.ty,
enum_definition.variants.as_slice(),
generics);
},
......@@ -435,7 +435,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
write_ty_to_tcx(tcx, it.id, selfty);
tcx.tcache.borrow_mut().insert(local_def(it.id),
ty_param_bounds_and_ty {
Polytype {
generics: ty_generics.clone(),
ty: selfty});
......@@ -484,10 +484,10 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
ensure_no_ty_param_bounds(ccx, it.span, generics, "structure");
// Write the class type.
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
let pty = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, pty.ty);
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
// Write the super-struct type, if it exists.
match struct_def.super_struct {
......@@ -498,38 +498,38 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) {
_ => {},
}
convert_struct(ccx, &*struct_def, tpt, it.id);
convert_struct(ccx, &*struct_def, pty, it.id);
},
ast::ItemTy(_, ref generics) => {
ensure_no_ty_param_bounds(ccx, it.span, generics, "type");
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
let pty = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, pty.ty);
},
ast::ItemFn(_, _, abi, ref generics, _) => {
ensure_generics_abi(ccx, it.span, abi, generics);
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
let pty = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, pty.ty);
},
_ => {
// This call populates the type cache with the converted type
// of the item in passing. All we have to do here is to write
// it into the node type table.
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
let pty = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, pty.ty);
},
}
}
pub fn convert_struct(ccx: &CrateCtxt,
struct_def: &ast::StructDef,
tpt: ty::ty_param_bounds_and_ty,
pty: ty::Polytype,
id: ast::NodeId) {
let tcx = ccx.tcx;
// Write the type of each of the members and check for duplicate fields.
let mut seen_fields: HashMap<ast::Name, Span> = HashMap::new();
let field_tys = struct_def.fields.iter().map(|f| {
let result = convert_field(ccx, &tpt.generics, f, local_def(id));
let result = convert_field(ccx, &pty.generics, f, local_def(id));
if result.name != special_idents::unnamed_field.name {
let dup = match seen_fields.find(&result.name) {
......@@ -589,7 +589,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
};
tcx.superstructs.borrow_mut().insert(local_def(id), super_struct);
let substs = mk_item_substs(ccx, &tpt.generics);
let substs = mk_item_substs(ccx, &pty.generics);
let selfty = ty::mk_struct(tcx, local_def(id), substs);
// If this struct is enum-like or tuple-like, create the type of its
......@@ -601,7 +601,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
// Enum-like.
write_ty_to_tcx(tcx, ctor_id, selfty);
tcx.tcache.borrow_mut().insert(local_def(ctor_id), tpt);
tcx.tcache.borrow_mut().insert(local_def(ctor_id), pty);
} else if struct_def.fields.get(0).node.kind.is_unnamed() {
// Tuple-like.
let inputs: Vec<_> = struct_def.fields.iter().map(
......@@ -613,8 +613,8 @@ pub fn convert_struct(ccx: &CrateCtxt,
selfty);
write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty);
tcx.tcache.borrow_mut().insert(local_def(ctor_id),
ty_param_bounds_and_ty {
generics: tpt.generics,
Polytype {
generics: pty.generics,
ty: ctor_fn_ty
});
}
......@@ -633,10 +633,10 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: &ast::ForeignItem) {
// convenient way to extract the ABI. - ndm
let abi = ccx.tcx.map.get_foreign_abi(i.id);
let tpt = ty_of_foreign_item(ccx, i, abi);
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
let pty = ty_of_foreign_item(ccx, i, abi);
write_ty_to_tcx(ccx.tcx, i.id, pty.ty);
ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), tpt);
ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), pty);
}
pub fn instantiate_trait_ref(ccx: &CrateCtxt,
......@@ -814,20 +814,20 @@ fn ensure_supertraits(ccx: &CrateCtxt,
}
pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {
let def_id = local_def(it.id);
let tcx = ccx.tcx;
match tcx.tcache.borrow().find(&def_id) {
Some(tpt) => return tpt.clone(),
Some(pty) => return pty.clone(),
_ => {}
}
match it.node {
ast::ItemStatic(t, _, _) => {
let typ = ccx.to_ty(&ExplicitRscope, &*t);
let tpt = no_params(typ);
let pty = no_params(typ);
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemFn(decl, fn_style, abi, ref generics, _) => {
let ty_generics = ty_generics_for_fn_or_method(ccx, generics,
......@@ -837,47 +837,47 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
fn_style,
abi,
&*decl);
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics,
ty: ty::mk_bare_fn(ccx.tcx, tofd)
};
debug!("type of {} (id {}) is {}",
token::get_ident(it.ident),
it.id,
ppaux::ty_to_str(tcx, tpt.ty));
ppaux::ty_to_str(tcx, pty.ty));
ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemTy(t, ref generics) => {
match tcx.tcache.borrow_mut().find(&local_def(it.id)) {
Some(tpt) => return tpt.clone(),
Some(pty) => return pty.clone(),
None => { }
}
let tpt = {
let pty = {
let ty = ccx.to_ty(&ExplicitRscope, &*t);
ty_param_bounds_and_ty {
Polytype {
generics: ty_generics_for_type(ccx, generics),
ty: ty
}
};
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemEnum(_, ref generics) => {
// Create a new generic polytype.
let ty_generics = ty_generics_for_type(ccx, generics);
let substs = mk_item_substs(ccx, &ty_generics);
let t = ty::mk_enum(tcx, local_def(it.id), substs);
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics,
ty: t
};
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemTrait(..) => {
tcx.sess.span_bug(it.span, "invoked ty_of_item on trait");
......@@ -886,13 +886,13 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
let ty_generics = ty_generics_for_type(ccx, generics);
let substs = mk_item_substs(ccx, &ty_generics);
let t = ty::mk_struct(tcx, local_def(it.id), substs);
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics,
ty: t
};
tcx.tcache.borrow_mut().insert(local_def(it.id), tpt.clone());
return tpt;
tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone());
return pty;
}
ast::ItemImpl(..) | ast::ItemMod(_) |
ast::ItemForeignMod(_) | ast::ItemMac(_) => fail!(),
......@@ -901,7 +901,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::Item)
pub fn ty_of_foreign_item(ccx: &CrateCtxt,
it: &ast::ForeignItem,
abi: abi::Abi) -> ty::ty_param_bounds_and_ty
abi: abi::Abi) -> ty::Polytype
{
match it.node {
ast::ForeignItemFn(fn_decl, ref generics) => {
......@@ -912,7 +912,7 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
abi)
}
ast::ForeignItemStatic(t, _) => {
ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: ty::Generics::empty(),
ty: ast_ty_to_ty(ccx, &ExplicitRscope, &*t)
}
......@@ -1158,7 +1158,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
def_id: ast::DefId,
ast_generics: &ast::Generics,
abi: abi::Abi)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {
for i in decl.inputs.iter() {
match (*i).pat.node {
......@@ -1190,13 +1190,13 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
output: output_ty,
variadic: decl.variadic}
});
let tpt = ty_param_bounds_and_ty {
let pty = Polytype {
generics: ty_generics_for_fn_or_method,
ty: t_fn
};
ccx.tcx.tcache.borrow_mut().insert(def_id, tpt.clone());
return tpt;
ccx.tcx.tcache.borrow_mut().insert(def_id, pty.clone());
return pty;
}
pub fn mk_item_substs(ccx: &CrateCtxt,
......
......@@ -1052,7 +1052,7 @@ fn rebuild_arg_ty_or_output(&self,
};
match a_def {
def::DefTy(did) | def::DefStruct(did) => {
let ty::ty_param_bounds_and_ty {
let ty::Polytype {
generics: generics,
ty: _
} = ty::lookup_item_type(self.tcx, did);
......
......@@ -176,6 +176,11 @@ pub enum ExprAdjustment {
AutoObject
}
pub struct TypeAndSubsts {
pub substs: subst::Substs,
pub ty: ty::t,
}
impl MethodCall {
pub fn expr(id: ast::NodeId) -> MethodCall {
MethodCall {
......@@ -302,8 +307,8 @@ pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
lookup_def_tcx(ccx.tcx, sp, id)
}
pub fn no_params(t: ty::t) -> ty::ty_param_bounds_and_ty {
ty::ty_param_bounds_and_ty {
pub fn no_params(t: ty::t) -> ty::Polytype {
ty::Polytype {
generics: ty::Generics {types: VecPerParamSpace::empty(),
regions: VecPerParamSpace::empty()},
ty: t
......
......@@ -748,9 +748,9 @@ fn repr(&self, tcx: &ctxt) -> String {
}
}
impl Repr for ty::ty_param_bounds_and_ty {
impl Repr for ty::Polytype {
fn repr(&self, tcx: &ctxt) -> String {
format!("ty_param_bounds_and_ty {{generics: {}, ty: {}}}",
format!("Polytype {{generics: {}, ty: {}}}",
self.generics.repr(tcx),
self.ty.repr(tcx))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册