diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 51cebbfb52c5..0cbc94f379d8 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -226,7 +226,7 @@ pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashM pub fn get_type<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) - -> ty::Polytype<'tcx> { + -> ty::TypeScheme<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_type(&*cdata, def.node, tcx) @@ -239,7 +239,7 @@ pub fn get_trait_def<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) -> ty::TraitDe } pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId, - def: ast::DefId) -> ty::Polytype<'tcx> { + def: ast::DefId) -> ty::TypeScheme<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(class_id.krate); let all_items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items); @@ -257,7 +257,7 @@ pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId, def)).to_string() }); let ty = decoder::item_type(def, the_field, tcx, &*cdata); - ty::Polytype { + ty::TypeScheme { generics: ty::Generics::empty(), ty: ty, } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 4447af809e4b..ce04a9029929 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -387,7 +387,7 @@ pub fn get_trait_def<'tcx>(cdata: Cmd, } pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>) - -> ty::Polytype<'tcx> { + -> ty::TypeScheme<'tcx> { let item = lookup_item(id, cdata.data()); @@ -396,7 +396,7 @@ pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>) let generics = doc_generics(item, tcx, cdata, tag_item_generics); - ty::Polytype { + ty::TypeScheme { generics: generics, ty: t } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 2a670b308b6b..6d79419b3863 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -142,7 +142,7 @@ fn encode_item_variances(rbml_w: &mut Encoder, fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder, ecx: &EncodeContext<'a, 'tcx>, - pty: &ty::Polytype<'tcx>) { + pty: &ty::TypeScheme<'tcx>) { encode_generics(rbml_w, ecx, &pty.generics, tag_item_generics); encode_type(ecx, rbml_w, pty.ty); } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index e8627dfa64b0..a135701a9c43 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -838,8 +838,8 @@ trait rbml_writer_helpers<'tcx> { predicate: &ty::Predicate<'tcx>); fn emit_trait_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, ty: &ty::TraitRef<'tcx>); - fn emit_polytype<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, - pty: ty::Polytype<'tcx>); + fn emit_type_scheme<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, + type_scheme: ty::TypeScheme<'tcx>); fn emit_substs<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, substs: &subst::Substs<'tcx>); fn emit_existential_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::ExistentialBounds); @@ -951,33 +951,33 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { }); } - fn emit_polytype<'b>(&mut self, - ecx: &e::EncodeContext<'b, 'tcx>, - pty: ty::Polytype<'tcx>) { + fn emit_type_scheme<'b>(&mut self, + ecx: &e::EncodeContext<'b, 'tcx>, + type_scheme: ty::TypeScheme<'tcx>) { use serialize::Encoder; - self.emit_struct("Polytype", 2, |this| { + self.emit_struct("TypeScheme", 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, &pty.generics.types, + this, &type_scheme.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, &pty.generics.regions, + this, &type_scheme.generics.regions, |this, def| def.encode(this).unwrap())) }); this.emit_struct_field("predicates", 2, |this| { Ok(encode_vec_per_param_space( - this, &pty.generics.predicates, + this, &type_scheme.generics.predicates, |this, def| this.emit_predicate(ecx, def))) }) }) }); this.emit_struct_field("ty", 1, |this| { - Ok(this.emit_ty(ecx, pty.ty)) + Ok(this.emit_ty(ecx, type_scheme.ty)) }) }); } @@ -1252,11 +1252,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext, } let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; - for &pty in tcx.tcache.borrow().get(&lid).iter() { + for &type_scheme in tcx.tcache.borrow().get(&lid).iter() { rbml_w.tag(c::tag_table_tcache, |rbml_w| { rbml_w.id(id); rbml_w.tag(c::tag_table_val, |rbml_w| { - rbml_w.emit_polytype(ecx, pty.clone()); + rbml_w.emit_type_scheme(ecx, type_scheme.clone()); }) }) } @@ -1369,8 +1369,8 @@ trait rbml_decoder_decoder_helpers<'tcx> { -> ty::TypeParameterDef<'tcx>; fn read_predicate<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> ty::Predicate<'tcx>; - fn read_polytype<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) - -> ty::Polytype<'tcx>; + fn read_type_scheme<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) + -> ty::TypeScheme<'tcx>; fn read_existential_bounds<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> ty::ExistentialBounds; fn read_substs<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) @@ -1591,10 +1591,10 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { }).unwrap() } - fn read_polytype<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) - -> ty::Polytype<'tcx> { - self.read_struct("Polytype", 2, |this| { - Ok(ty::Polytype { + fn read_type_scheme<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) + -> ty::TypeScheme<'tcx> { + self.read_struct("TypeScheme", 2, |this| { + Ok(ty::TypeScheme { generics: this.read_struct_field("generics", 0, |this| { this.read_struct("Generics", 2, |this| { Ok(ty::Generics { @@ -1939,9 +1939,9 @@ fn decode_side_tables(dcx: &DecodeContext, .insert(id, capture_mode); } c::tag_table_tcache => { - let pty = val_dsr.read_polytype(dcx); + let type_scheme = val_dsr.read_type_scheme(dcx); let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id }; - dcx.tcx.tcache.borrow_mut().insert(lid, pty); + dcx.tcx.tcache.borrow_mut().insert(lid, type_scheme); } c::tag_table_param_defs => { let bounds = val_dsr.read_type_param_def(dcx); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index b3e9f85c69c7..c082c12da5bf 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -695,7 +695,7 @@ pub struct ctxt<'tcx> { pub map: ast_map::Map<'tcx>, pub intrinsic_defs: RefCell>>, pub freevars: RefCell, - pub tcache: RefCell>>, + pub tcache: RefCell>>, pub rcache: RefCell>>, pub short_names_cache: RefCell, String>>, pub tc_cache: RefCell, TypeContents>>, @@ -2029,18 +2029,23 @@ impl<'tcx> ParameterEnvironment<'tcx> { } } -/// A polytype. +/// A "type scheme", in ML terminology, is a type combined with some +/// set of generic types that the type is, well, generic over. In Rust +/// terms, it is the "type" of a fn item or struct -- this type will +/// include various generic parameters that must be substituted when +/// the item/struct is referenced. That is called converting the type +/// scheme to a monotype. /// /// - `generics`: the set of type parameters and their bounds /// - `ty`: the base types, which may reference the parameters defined /// in `generics` #[deriving(Clone, Show)] -pub struct Polytype<'tcx> { +pub struct TypeScheme<'tcx> { pub generics: Generics<'tcx>, pub ty: Ty<'tcx> } -/// As `Polytype` but for a trait ref. +/// As `TypeScheme` but for a trait ref. pub struct TraitDef<'tcx> { pub unsafety: ast::Unsafety, @@ -5102,7 +5107,7 @@ pub fn enum_variant_with_id<'tcx>(cx: &ctxt<'tcx>, // the type cache. Returns the type parameters and type. pub fn lookup_item_type<'tcx>(cx: &ctxt<'tcx>, did: ast::DefId) - -> Polytype<'tcx> { + -> TypeScheme<'tcx> { lookup_locally_or_in_crate_store( "tcache", did, &mut *cx.tcache.borrow_mut(), || csearch::get_type(cx, did)) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 3a383dd5a3b7..ae8324d9a4f1 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -929,9 +929,9 @@ impl<'tcx> Repr<'tcx> for ast::DefId { } } -impl<'tcx> Repr<'tcx> for ty::Polytype<'tcx> { +impl<'tcx> Repr<'tcx> for ty::TypeScheme<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { - format!("Polytype {{generics: {}, ty: {}}}", + format!("TypeScheme {{generics: {}, ty: {}}}", self.generics.repr(tcx), self.ty.repr(tcx)) } diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index dab4c0273d07..c0697c2a238d 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -514,8 +514,8 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>( return val; } - // Polytype of the function item (may have type params) - let fn_tpt = ty::lookup_item_type(tcx, def_id); + // Type scheme of the function item (may have type params) + let fn_type_scheme = ty::lookup_item_type(tcx, def_id); // Find the actual function pointer. let mut val = { @@ -524,7 +524,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>( get_item_val(ccx, def_id.node) } else { // External reference. - trans_external_path(ccx, def_id, fn_tpt.ty) + trans_external_path(ccx, def_id, fn_type_scheme.ty) } }; @@ -551,7 +551,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>( // This can occur on either a crate-local or crate-external // reference. It also occurs when testing libcore and in some // other weird situations. Annoying. - let llty = type_of::type_of_fn_from_ty(ccx, fn_tpt.ty); + let llty = type_of::type_of_fn_from_ty(ccx, fn_type_scheme.ty); let llptrty = llty.ptr_to(); if val_ty(val) != llptrty { debug!("trans_fn_ref_with_vtables(): casting pointer!"); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d6f1f5fedc58..859cb88ea9a1 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -16,11 +16,11 @@ //! somewhat differently during the collect and check phases, //! particularly with respect to looking up the types of top-level //! items. In the collect phase, the crate context is used as the -//! `AstConv` instance; in this phase, the `get_item_ty()` function +//! `AstConv` instance; in this phase, the `get_item_type_scheme()` function //! triggers a recursive call to `ty_of_item()` (note that //! `ast_ty_to_ty()` will detect recursive types and report an error). //! In the check phase, when the FnCtxt is used as the `AstConv`, -//! `get_item_ty()` just looks up the item type in `tcx.tcache`. +//! `get_item_type_scheme()` just looks up the item type in `tcx.tcache`. //! //! The `RegionScope` trait controls what happens when the user does //! not specify a region in some location where a region is required @@ -70,7 +70,7 @@ use syntax::print::pprust; pub trait AstConv<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx>; + fn get_item_type_scheme(&self, id: ast::DefId) -> ty::TypeScheme<'tcx>; fn get_trait_def(&self, id: ast::DefId) -> Rc>; /// Return an (optional) substitution to convert bound type parameters that @@ -650,10 +650,10 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( -> TypeAndSubsts<'tcx> { let tcx = this.tcx(); - let ty::Polytype { + let ty::TypeScheme { generics, ty: decl_ty - } = this.get_item_ty(did); + } = this.get_item_type_scheme(did); let substs = ast_path_substs_for_ty(this, rscope, @@ -678,10 +678,10 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>( where AC : AstConv<'tcx>, RS : RegionScope { let tcx = this.tcx(); - let ty::Polytype { + let ty::TypeScheme { generics, ty: decl_ty - } = this.get_item_ty(did); + } = this.get_item_type_scheme(did); let wants_params = generics.has_type_params(TypeSpace) || generics.has_region_params(TypeSpace); diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 09a5dd521f88..4fbae6378006 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -79,9 +79,9 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, } ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => { let const_did = tcx.def_map.borrow()[pat.id].clone().def_id(); - let const_pty = ty::lookup_item_type(tcx, const_did); - fcx.write_ty(pat.id, const_pty.ty); - demand::suptype(fcx, pat.span, expected, const_pty.ty); + let const_scheme = ty::lookup_item_type(tcx, const_did); + fcx.write_ty(pat.id, const_scheme.ty); + demand::suptype(fcx, pat.span, expected, const_scheme.ty); } ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => { let typ = fcx.local_ty(pat.span, pat.id); @@ -395,16 +395,16 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &ast::Pat, let enum_def = def.variant_def_ids() .map_or_else(|| def.def_id(), |(enum_def, _)| enum_def); - let ctor_pty = ty::lookup_item_type(tcx, enum_def); - let path_ty = if ty::is_fn_ty(ctor_pty.ty) { - ty::Polytype { - ty: ty::ty_fn_ret(ctor_pty.ty).unwrap(), - ..ctor_pty + let ctor_scheme = ty::lookup_item_type(tcx, enum_def); + let path_scheme = if ty::is_fn_ty(ctor_scheme.ty) { + ty::TypeScheme { + ty: ty::ty_fn_ret(ctor_scheme.ty).unwrap(), + ..ctor_scheme } } else { - ctor_pty + ctor_scheme }; - instantiate_path(pcx.fcx, path, path_ty, def, pat.span, pat.id); + instantiate_path(pcx.fcx, path, path_scheme, def, pat.span, pat.id); let pat_ty = fcx.node_ty(pat.id); demand::eqtype(fcx, pat.span, expected, pat_ty); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index dfa41c2707e8..bb1b24f4b487 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -91,7 +91,7 @@ use middle::pat_util::{mod, pat_id_map}; use middle::region::CodeExtent; use middle::subst::{mod, Subst, Substs, VecPerParamSpace, ParamSpace}; use middle::traits; -use middle::ty::{FnSig, VariantInfo, Polytype}; +use middle::ty::{FnSig, VariantInfo, TypeScheme}; use middle::ty::{Disr, ParamTy, ParameterEnvironment}; use middle::ty::{mod, Ty}; use middle::ty::liberate_late_bound_regions; @@ -1510,7 +1510,7 @@ fn check_cast(fcx: &FnCtxt, impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { fn tcx(&self) -> &ty::ctxt<'tcx> { self.ccx.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { + fn get_item_type_scheme(&self, id: ast::DefId) -> ty::TypeScheme<'tcx> { ty::lookup_item_type(self.tcx(), id) } @@ -1739,14 +1739,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { def_id: ast::DefId) -> TypeAndSubsts<'tcx> { - let polytype = + let type_scheme = ty::lookup_item_type(self.tcx(), def_id); let substs = self.infcx().fresh_substs_for_generics( span, - &polytype.generics); + &type_scheme.generics); let bounds = - polytype.generics.to_bounds(self.tcx(), &substs); + type_scheme.generics.to_bounds(self.tcx(), &substs); self.add_obligations_for_parameters( traits::ObligationCause::new( span, @@ -1754,7 +1754,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { traits::ItemObligation(def_id)), &bounds); let monotype = - polytype.ty.subst(self.tcx(), &substs); + type_scheme.ty.subst(self.tcx(), &substs); TypeAndSubsts { ty: monotype, @@ -3829,7 +3829,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, } ast::ExprPath(ref pth) => { let defn = lookup_def(fcx, pth.span, id); - let pty = polytype_for_def(fcx, expr.span, defn); + let pty = type_scheme_for_def(fcx, expr.span, defn); instantiate_path(fcx, pth, pty, defn, expr.span, expr.id); // We always require that the type provided as the value for @@ -4922,10 +4922,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 polytype_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, - sp: Span, - defn: def::Def) - -> Polytype<'tcx> { +pub fn type_scheme_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + sp: Span, + defn: def::Def) + -> TypeScheme<'tcx> { match defn { def::DefLocal(nid) | def::DefUpvar(nid, _, _) => { let typ = fcx.local_ty(sp, nid); @@ -4969,15 +4969,15 @@ pub fn polytype_for_def<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // number of type parameters and type. pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, path: &ast::Path, - polytype: Polytype<'tcx>, + type_scheme: TypeScheme<'tcx>, def: def::Def, span: Span, node_id: ast::NodeId) { - debug!("instantiate_path(path={}, def={}, node_id={}, polytype={})", + debug!("instantiate_path(path={}, def={}, node_id={}, type_scheme={})", path.repr(fcx.tcx()), def.repr(fcx.tcx()), node_id, - polytype.repr(fcx.tcx())); + type_scheme.repr(fcx.tcx())); // We need to extract the type parameters supplied by the user in // the path `path`. Due to the current setup, this is a bit of a @@ -5102,8 +5102,8 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // Next, examine the definition, and determine how many type // parameters we expect from each space. - let type_defs = &polytype.generics.types; - let region_defs = &polytype.generics.regions; + let type_defs = &type_scheme.generics.types; + let region_defs = &type_scheme.generics.regions; // Now that we have categorized what space the parameters for each // segment belong to, let's sort out the parameters that the user @@ -5151,12 +5151,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // the fn itself). Those should be replaced with fresh variables // now. These can appear either on the type being referenced, or // on the associated bounds. - let bounds = polytype.generics.to_bounds(fcx.tcx(), &substs); + let bounds = type_scheme.generics.to_bounds(fcx.tcx(), &substs); let (ty_late_bound, bounds) = fcx.infcx().replace_late_bound_regions_with_fresh_var( span, infer::FnCall, - &ty::Binder((polytype.ty, bounds))).0; + &ty::Binder((type_scheme.ty, bounds))).0; debug!("after late-bounds have been replaced: ty_late_bound={}", ty_late_bound.repr(fcx.tcx())); debug!("after late-bounds have been replaced: bounds={}", bounds.repr(fcx.tcx())); diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 258177bb7209..3ddc81d40a5d 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -147,8 +147,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> { item.span, region::CodeExtent::from_node_id(item.id), Some(&mut this.cache)); - let polytype = ty::lookup_item_type(fcx.tcx(), local_def(item.id)); - let item_ty = polytype.ty.subst(fcx.tcx(), &fcx.inh.param_env.free_substs); + let type_scheme = ty::lookup_item_type(fcx.tcx(), local_def(item.id)); + let item_ty = type_scheme.ty.subst(fcx.tcx(), &fcx.inh.param_env.free_substs); bounds_checker.check_traits_in_ty(item_ty); }); } @@ -313,14 +313,14 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> { match t.sty{ ty::ty_struct(type_id, substs) | ty::ty_enum(type_id, substs) => { - let polytype = ty::lookup_item_type(self.fcx.tcx(), type_id); + let type_scheme = ty::lookup_item_type(self.fcx.tcx(), type_id); if self.binding_count == 0 { self.fcx.add_obligations_for_parameters( traits::ObligationCause::new(self.span, self.fcx.body_id, traits::ItemObligation(type_id)), - &polytype.generics.to_bounds(self.tcx(), substs)); + &type_scheme.generics.to_bounds(self.tcx(), substs)); } else { // There are two circumstances in which we ignore // region obligations. @@ -344,7 +344,7 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> { // // (I believe we should do the same for traits, but // that will require an RFC. -nmatsakis) - let bounds = polytype.generics.to_bounds(self.tcx(), substs); + let bounds = type_scheme.generics.to_bounds(self.tcx(), substs); let bounds = filter_to_trait_obligations(bounds); self.fcx.add_obligations_for_parameters( traits::ObligationCause::new(self.span, diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index f92c7764a69b..30039f2ecc1c 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -23,7 +23,7 @@ use middle::ty::RegionEscape; use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId}; use middle::ty::{ParameterEnvironment, TypeTraitItemId, lookup_item_type}; use middle::ty::{Ty, ty_bool, ty_char, ty_closure, ty_enum, ty_err}; -use middle::ty::{ty_param, Polytype, ty_ptr}; +use middle::ty::{ty_param, TypeScheme, ty_ptr}; use middle::ty::{ty_rptr, ty_struct, ty_trait, ty_tup}; use middle::ty::{ty_str, ty_vec, ty_float, ty_infer, ty_int, ty_open}; use middle::ty::{ty_uint, ty_unboxed_closure, ty_uniq, ty_bare_fn}; @@ -206,7 +206,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { debug!("instantiate_default_methods(impl_id={}, trait_ref={})", impl_id, trait_ref.repr(tcx)); - let impl_poly_type = ty::lookup_item_type(tcx, impl_id); + let impl_type_scheme = ty::lookup_item_type(tcx, impl_id); let prov = ty::provided_trait_methods(tcx, trait_ref.def_id); for trait_method in prov.iter() { @@ -221,7 +221,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { Rc::new(subst_receiver_types_in_method_ty( tcx, impl_id, - &impl_poly_type, + &impl_type_scheme, trait_ref, new_did, &**trait_method, @@ -233,7 +233,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { // 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::Polytype { + let new_polytype = ty::TypeScheme { generics: new_method_ty.generics.clone(), ty: ty::mk_bare_fn(tcx, Some(new_did), tcx.mk_bare_fn(new_method_ty.fty.clone())) @@ -275,7 +275,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } fn get_self_type_for_implementation(&self, impl_did: DefId) - -> Polytype<'tcx> { + -> TypeScheme<'tcx> { self.crate_context.tcx.tcache.borrow()[impl_did].clone() } @@ -535,7 +535,7 @@ fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id: fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>, impl_id: ast::DefId, - impl_poly_type: &ty::Polytype<'tcx>, + impl_type_scheme: &ty::TypeScheme<'tcx>, trait_ref: &ty::TraitRef<'tcx>, new_def_id: ast::DefId, method: &ty::Method<'tcx>, @@ -554,10 +554,10 @@ fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>, for &space in [subst::TypeSpace, subst::SelfSpace].iter() { method_generics.types.replace( space, - impl_poly_type.generics.types.get_slice(space).to_vec()); + impl_type_scheme.generics.types.get_slice(space).to_vec()); method_generics.regions.replace( space, - impl_poly_type.generics.regions.get_slice(space).to_vec()); + impl_type_scheme.generics.regions.get_slice(space).to_vec()); } debug!("subst_receiver_types_in_method_ty: method_generics={}", diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8d07f1e43550..74cfbb117e9a 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -23,8 +23,8 @@ Unlike most of the types that are present in Rust, the types computed for each item are in fact polytypes. In "layman's terms", this means 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::Polytype`. This combines the core type along with a list of the +type parameters). TypeSchemes are represented by an instance of +`ty::TypeScheme`. This combines the core type along with a list of the bounds for each parameter. Type parameters themselves are represented as `ty_param()` instances. @@ -43,7 +43,7 @@ use middle::resolve_lifetime; use middle::subst; use middle::subst::{Substs}; use middle::ty::{AsPredicate, ImplContainer, ImplOrTraitItemContainer, TraitContainer}; -use middle::ty::{mod, RegionEscape, Ty, Polytype}; +use middle::ty::{mod, RegionEscape, Ty, TypeScheme}; use middle::ty_fold::{mod, TypeFolder, TypeFoldable}; use middle::infer; use rscope::*; @@ -70,8 +70,8 @@ use syntax::visit; pub fn collect_item_types(ccx: &CrateCtxt) { fn collect_intrinsic_type(ccx: &CrateCtxt, lang_item: ast::DefId) { - let ty::Polytype { ty, .. } = - ccx.get_item_ty(lang_item); + let ty::TypeScheme { ty, .. } = + ccx.get_item_type_scheme(lang_item); ccx.tcx.intrinsic_defs.borrow_mut().insert(lang_item, ty); } @@ -154,7 +154,7 @@ impl<'a,'tcx> ToTy<'tcx> for CrateCtxt<'a,'tcx> { impl<'a, 'tcx> AstConv<'tcx> for CrateCtxt<'a, 'tcx> { fn tcx(&self) -> &ty::ctxt<'tcx> { self.tcx } - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { + fn get_item_type_scheme(&self, id: ast::DefId) -> ty::TypeScheme<'tcx> { if id.krate != ast::LOCAL_CRATE { return csearch::get_type(self.tcx, id) } @@ -170,8 +170,8 @@ impl<'a, 'tcx> AstConv<'tcx> for CrateCtxt<'a, 'tcx> { } x => { self.tcx.sess.bug(format!("unexpected sort of node \ - in get_item_ty(): {}", - x)[]); + in get_item_type_scheme(): {}", + x).as_slice()); } } } @@ -227,7 +227,7 @@ pub fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } ast::StructVariantKind(ref struct_def) => { - let pty = Polytype { + let scheme = TypeScheme { generics: ty_generics_for_type_or_impl( ccx, generics, @@ -235,12 +235,12 @@ pub fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty: enum_ty }; - convert_struct(ccx, &**struct_def, pty, variant.node.id); + convert_struct(ccx, &**struct_def, scheme, variant.node.id); enum_ty } }; - let pty = Polytype { + let scheme = TypeScheme { generics: ty_generics_for_type_or_impl( ccx, generics, @@ -248,7 +248,7 @@ pub fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ty: result_ty }; - tcx.tcache.borrow_mut().insert(variant_def_id, pty); + tcx.tcache.borrow_mut().insert(variant_def_id, scheme); write_ty_to_tcx(tcx, variant.node.id, result_ty); } @@ -353,7 +353,7 @@ fn collect_trait_methods<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, fn make_method_ty<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, m: &ty::Method<'tcx>) { ccx.tcx.tcache.borrow_mut().insert( m.def_id, - Polytype { + TypeScheme { generics: m.generics.clone(), ty: ty::mk_bare_fn(ccx.tcx, Some(m.def_id), ccx.tcx.mk_bare_fn(m.fty.clone())) }); } @@ -416,7 +416,7 @@ pub fn convert_field<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, 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::Polytype { + ty::TypeScheme { generics: struct_generics.clone(), ty: tt }); @@ -536,7 +536,7 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, fty.repr(tcx)); tcx.tcache.borrow_mut().insert( m_def_id, - Polytype { + TypeScheme { generics: mty.generics.clone(), ty: fty }); @@ -1034,11 +1034,11 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { // These don't define types. ast::ItemForeignMod(_) | ast::ItemMod(_) | ast::ItemMac(_) => {} ast::ItemEnum(ref enum_definition, ref generics) => { - let pty = ty_of_item(ccx, it); - write_ty_to_tcx(tcx, it.id, pty.ty); + let scheme = ty_of_item(ccx, it); + write_ty_to_tcx(tcx, it.id, scheme.ty); get_enum_variant_types(ccx, - pty.ty, - enum_definition.variants[], + scheme.ty, + enum_definition.variants.as_slice(), generics); }, ast::ItemImpl(_, @@ -1058,7 +1058,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { tcx.tcache .borrow_mut() .insert(local_def(it.id), - Polytype { + TypeScheme { generics: ty_generics.clone(), ty: selfty, }); @@ -1105,7 +1105,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { tcx.tcache .borrow_mut() .insert(local_def(typedef.id), - Polytype { + TypeScheme { generics: ty::Generics::empty(), ty: typ, }); @@ -1202,12 +1202,12 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { }, ast::ItemStruct(ref struct_def, _) => { // Write the class type. - let pty = ty_of_item(ccx, it); - write_ty_to_tcx(tcx, it.id, pty.ty); + let scheme = ty_of_item(ccx, it); + write_ty_to_tcx(tcx, it.id, scheme.ty); - tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); + tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); - convert_struct(ccx, &**struct_def, pty, it.id); + convert_struct(ccx, &**struct_def, scheme, it.id); }, ast::ItemTy(_, ref generics) => { ensure_no_ty_param_bounds(ccx, it.span, generics, "type"); @@ -1218,22 +1218,22 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::Item) { // 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 pty = ty_of_item(ccx, it); - write_ty_to_tcx(tcx, it.id, pty.ty); + let scheme = ty_of_item(ccx, it); + write_ty_to_tcx(tcx, it.id, scheme.ty); }, } } pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, struct_def: &ast::StructDef, - pty: ty::Polytype<'tcx>, + scheme: ty::TypeScheme<'tcx>, id: ast::NodeId) { let tcx = ccx.tcx; // Write the type of each of the members and check for duplicate fields. let mut seen_fields: FnvHashMap = FnvHashMap::new(); let field_tys = struct_def.fields.iter().map(|f| { - let result = convert_field(ccx, &pty.generics, f, local_def(id)); + let result = convert_field(ccx, &scheme.generics, f, local_def(id)); if result.name != special_idents::unnamed_field.name { let dup = match seen_fields.get(&result.name) { @@ -1258,7 +1258,7 @@ pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, tcx.struct_fields.borrow_mut().insert(local_def(id), Rc::new(field_tys)); - let substs = mk_item_substs(ccx, &pty.generics); + let substs = mk_item_substs(ccx, &scheme.generics); let selfty = ty::mk_struct(tcx, local_def(id), tcx.mk_substs(substs)); // If this struct is enum-like or tuple-like, create the type of its @@ -1270,7 +1270,7 @@ pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, // Enum-like. write_ty_to_tcx(tcx, ctor_id, selfty); - tcx.tcache.borrow_mut().insert(local_def(ctor_id), pty); + tcx.tcache.borrow_mut().insert(local_def(ctor_id), scheme); } else if struct_def.fields[0].node.kind.is_unnamed() { // Tuple-like. let inputs: Vec<_> = struct_def.fields.iter().map( @@ -1282,8 +1282,8 @@ pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, selfty); write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty); tcx.tcache.borrow_mut().insert(local_def(ctor_id), - Polytype { - generics: pty.generics, + TypeScheme { + generics: scheme.generics, ty: ctor_fn_ty }); } @@ -1302,10 +1302,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 pty = ty_of_foreign_item(ccx, i, abi); - write_ty_to_tcx(ccx.tcx, i.id, pty.ty); + let scheme = ty_of_foreign_item(ccx, i, abi); + write_ty_to_tcx(ccx.tcx, i.id, scheme.ty); - ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), pty); + ccx.tcx.tcache.borrow_mut().insert(local_def(i.id), scheme); } fn get_trait_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, @@ -1429,19 +1429,19 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) - -> ty::Polytype<'tcx> { + -> ty::TypeScheme<'tcx> { let def_id = local_def(it.id); let tcx = ccx.tcx; - if let Some(pty) = tcx.tcache.borrow().get(&def_id) { - return pty.clone(); + if let Some(scheme) = tcx.tcache.borrow().get(&def_id) { + return scheme.clone(); } match it.node { ast::ItemStatic(ref t, _, _) | ast::ItemConst(ref t, _) => { let typ = ccx.to_ty(&ExplicitRscope, &**t); - let pty = no_params(typ); + let scheme = no_params(typ); - tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); - return pty; + tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); + return scheme; } ast::ItemFn(ref decl, unsafety, abi, ref generics, _) => { let ty_generics = ty_generics_for_fn_or_method( @@ -1456,27 +1456,27 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) }; astconv::ty_of_bare_fn(&fcx, unsafety, abi, &**decl) }; - let pty = Polytype { + let scheme = TypeScheme { generics: ty_generics, ty: ty::mk_bare_fn(ccx.tcx, Some(local_def(it.id)), ccx.tcx.mk_bare_fn(tofd)) }; debug!("type of {} (id {}) is {}", token::get_ident(it.ident), it.id, - pty.repr(tcx)); + scheme.repr(tcx)); - ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); - return pty; + ccx.tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); + return scheme; } ast::ItemTy(ref t, ref generics) => { match tcx.tcache.borrow_mut().get(&local_def(it.id)) { - Some(pty) => return pty.clone(), + Some(scheme) => return scheme.clone(), None => { } } - let pty = { + let scheme = { let ty = ccx.to_ty(&ExplicitRscope, &**t); - Polytype { + TypeScheme { generics: ty_generics_for_type_or_impl( ccx, generics, @@ -1485,8 +1485,8 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) } }; - tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); - return pty; + tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); + return scheme; } ast::ItemEnum(_, ref generics) => { // Create a new generic polytype. @@ -1496,13 +1496,13 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) DontCreateTypeParametersForAssociatedTypes); let substs = mk_item_substs(ccx, &ty_generics); let t = ty::mk_enum(tcx, local_def(it.id), tcx.mk_substs(substs)); - let pty = Polytype { + let scheme = TypeScheme { generics: ty_generics, ty: t }; - tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); - return pty; + tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); + return scheme; } ast::ItemTrait(..) => { tcx.sess.span_bug(it.span, "invoked ty_of_item on trait"); @@ -1514,13 +1514,13 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) DontCreateTypeParametersForAssociatedTypes); let substs = mk_item_substs(ccx, &ty_generics); let t = ty::mk_struct(tcx, local_def(it.id), tcx.mk_substs(substs)); - let pty = Polytype { + let scheme = TypeScheme { generics: ty_generics, ty: t }; - tcx.tcache.borrow_mut().insert(local_def(it.id), pty.clone()); - return pty; + tcx.tcache.borrow_mut().insert(local_def(it.id), scheme.clone()); + return scheme; } ast::ItemImpl(..) | ast::ItemMod(_) | ast::ItemForeignMod(_) | ast::ItemMac(_) => panic!(), @@ -1529,7 +1529,7 @@ pub fn ty_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::Item) pub fn ty_of_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, it: &ast::ForeignItem, - abi: abi::Abi) -> ty::Polytype<'tcx> + abi: abi::Abi) -> ty::TypeScheme<'tcx> { match it.node { ast::ForeignItemFn(ref fn_decl, ref generics) => { @@ -1540,7 +1540,7 @@ pub fn ty_of_foreign_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, abi) } ast::ForeignItemStatic(ref t, _) => { - ty::Polytype { + ty::TypeScheme { generics: ty::Generics::empty(), ty: ast_ty_to_ty(ccx, &ExplicitRscope, &**t) } @@ -2107,7 +2107,7 @@ pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, def_id: ast::DefId, ast_generics: &ast::Generics, abi: abi::Abi) - -> ty::Polytype<'tcx> { + -> ty::TypeScheme<'tcx> { for i in decl.inputs.iter() { match (*i).pat.node { ast::PatIdent(_, _, _) => (), @@ -2144,16 +2144,16 @@ pub fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, abi: abi, unsafety: ast::Unsafety::Unsafe, sig: ty::Binder(ty::FnSig {inputs: input_tys, - output: output, - variadic: decl.variadic}) - })); - let pty = Polytype { + output: output, + variadic: decl.variadic}), + }); + let scheme = TypeScheme { generics: ty_generics_for_fn_or_method, ty: t_fn }; - ccx.tcx.tcache.borrow_mut().insert(def_id, pty.clone()); - return pty; + ccx.tcx.tcache.borrow_mut().insert(def_id, scheme.clone()); + return scheme; } pub fn mk_item_substs<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 3418cded022c..a903c8b0d55a 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -159,8 +159,8 @@ fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId) lookup_def_tcx(ccx.tcx, sp, id) } -fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> { - ty::Polytype { +fn no_params<'tcx>(t: Ty<'tcx>) -> ty::TypeScheme<'tcx> { + ty::TypeScheme { generics: ty::Generics { types: VecPerParamSpace::empty(), regions: VecPerParamSpace::empty(),