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)
}
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);
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
}
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());
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
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) {
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()));
}
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,
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);
}
_ => {
// 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,
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);
}
});
}
- 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))
})
});
}
}
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());
})
})
}
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,
}).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 {
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);
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)
}
/// 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,
pub substs: Substs,
}
-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>>;
// 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))
} 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());
use middle::def;
use middle::lang_items::FnMutTraitLangItem;
use rl = middle::resolve_lifetime;
-use middle::subst::{Subst, Substs};
+use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
use middle::ty;
use middle::typeck::TypeAndSubsts;
-use middle::typeck::rscope;
-use middle::typeck::rscope::{RegionScope};
use middle::typeck::lookup_def_tcx;
use middle::typeck::rscope::RegionScope;
use middle::typeck::rscope;
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?
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
// 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(
};
// 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()
.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 => {
// "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
-> 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 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 => ()
}
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);
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);
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);
use middle::subst;
use middle::subst::{Subst, Substs, VecPerParamSpace, ParamSpace};
use middle::ty::{FnSig, VariantInfo};
-use middle::ty::{ty_param_bounds_and_ty};
+use middle::ty::{Polytype};
use middle::ty::{ParamTy, Disr, ExprTyProvider};
use middle::ty;
use middle::ty_fold::TypeFolder;
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 {
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 => { }
}
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 {
}
} 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");
}
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)
}
}
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() {
}
// 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, _) => {
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(_) |
// 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) {
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;
// 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())
};
}
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);
// 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 =
}
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)
}
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,
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.
*/
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};
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);
}
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)
}
}
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();
}
};
- 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);
}
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()) });
}
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
});
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
});
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);
},
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});
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 {
_ => {},
}
- 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) {
};
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
// 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(
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
});
}
// 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,
}
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,
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");
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!(),
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) => {
abi)
}
ast::ForeignItemStatic(t, _) => {
- ty::ty_param_bounds_and_ty {
+ ty::Polytype {
generics: ty::Generics::empty(),
ty: ast_ty_to_ty(ccx, &ExplicitRscope, &*t)
}
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 {
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,
};
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);
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
}
}
-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))
}