Skip to content

Commit 771dd54

Browse files
committed
Rename Polytype to TypeScheme to differentiate type schemes (early bound) from higher-ranked things (late-bound), which also use the Poly prefix.
1 parent 986f654 commit 771dd54

File tree

14 files changed

+158
-153
lines changed

14 files changed

+158
-153
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashM
226226

227227
pub fn get_type<'tcx>(tcx: &ty::ctxt<'tcx>,
228228
def: ast::DefId)
229-
-> ty::Polytype<'tcx> {
229+
-> ty::TypeScheme<'tcx> {
230230
let cstore = &tcx.sess.cstore;
231231
let cdata = cstore.get_crate_data(def.krate);
232232
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
239239
}
240240

241241
pub fn get_field_type<'tcx>(tcx: &ty::ctxt<'tcx>, class_id: ast::DefId,
242-
def: ast::DefId) -> ty::Polytype<'tcx> {
242+
def: ast::DefId) -> ty::TypeScheme<'tcx> {
243243
let cstore = &tcx.sess.cstore;
244244
let cdata = cstore.get_crate_data(class_id.krate);
245245
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,
257257
def)).to_string()
258258
});
259259
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
260-
ty::Polytype {
260+
ty::TypeScheme {
261261
generics: ty::Generics::empty(),
262262
ty: ty,
263263
}

src/librustc/metadata/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub fn get_trait_def<'tcx>(cdata: Cmd,
387387
}
388388

389389
pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>)
390-
-> ty::Polytype<'tcx> {
390+
-> ty::TypeScheme<'tcx> {
391391

392392
let item = lookup_item(id, cdata.data());
393393

@@ -396,7 +396,7 @@ pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>)
396396

397397
let generics = doc_generics(item, tcx, cdata, tag_item_generics);
398398

399-
ty::Polytype {
399+
ty::TypeScheme {
400400
generics: generics,
401401
ty: t
402402
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn encode_item_variances(rbml_w: &mut Encoder,
142142

143143
fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
144144
ecx: &EncodeContext<'a, 'tcx>,
145-
pty: &ty::Polytype<'tcx>) {
145+
pty: &ty::TypeScheme<'tcx>) {
146146
encode_generics(rbml_w, ecx, &pty.generics, tag_item_generics);
147147
encode_type(ecx, rbml_w, pty.ty);
148148
}

src/librustc/middle/astencode.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ trait rbml_writer_helpers<'tcx> {
838838
predicate: &ty::Predicate<'tcx>);
839839
fn emit_trait_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
840840
ty: &ty::TraitRef<'tcx>);
841-
fn emit_polytype<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
842-
pty: ty::Polytype<'tcx>);
841+
fn emit_type_scheme<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
842+
type_scheme: ty::TypeScheme<'tcx>);
843843
fn emit_substs<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
844844
substs: &subst::Substs<'tcx>);
845845
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> {
951951
});
952952
}
953953

954-
fn emit_polytype<'b>(&mut self,
955-
ecx: &e::EncodeContext<'b, 'tcx>,
956-
pty: ty::Polytype<'tcx>) {
954+
fn emit_type_scheme<'b>(&mut self,
955+
ecx: &e::EncodeContext<'b, 'tcx>,
956+
type_scheme: ty::TypeScheme<'tcx>) {
957957
use serialize::Encoder;
958958

959-
self.emit_struct("Polytype", 2, |this| {
959+
self.emit_struct("TypeScheme", 2, |this| {
960960
this.emit_struct_field("generics", 0, |this| {
961961
this.emit_struct("Generics", 2, |this| {
962962
this.emit_struct_field("types", 0, |this| {
963963
Ok(encode_vec_per_param_space(
964-
this, &pty.generics.types,
964+
this, &type_scheme.generics.types,
965965
|this, def| this.emit_type_param_def(ecx, def)))
966966
});
967967
this.emit_struct_field("regions", 1, |this| {
968968
Ok(encode_vec_per_param_space(
969-
this, &pty.generics.regions,
969+
this, &type_scheme.generics.regions,
970970
|this, def| def.encode(this).unwrap()))
971971
});
972972
this.emit_struct_field("predicates", 2, |this| {
973973
Ok(encode_vec_per_param_space(
974-
this, &pty.generics.predicates,
974+
this, &type_scheme.generics.predicates,
975975
|this, def| this.emit_predicate(ecx, def)))
976976
})
977977
})
978978
});
979979
this.emit_struct_field("ty", 1, |this| {
980-
Ok(this.emit_ty(ecx, pty.ty))
980+
Ok(this.emit_ty(ecx, type_scheme.ty))
981981
})
982982
});
983983
}
@@ -1252,11 +1252,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12521252
}
12531253

12541254
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
1255-
for &pty in tcx.tcache.borrow().get(&lid).iter() {
1255+
for &type_scheme in tcx.tcache.borrow().get(&lid).iter() {
12561256
rbml_w.tag(c::tag_table_tcache, |rbml_w| {
12571257
rbml_w.id(id);
12581258
rbml_w.tag(c::tag_table_val, |rbml_w| {
1259-
rbml_w.emit_polytype(ecx, pty.clone());
1259+
rbml_w.emit_type_scheme(ecx, type_scheme.clone());
12601260
})
12611261
})
12621262
}
@@ -1369,8 +1369,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
13691369
-> ty::TypeParameterDef<'tcx>;
13701370
fn read_predicate<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13711371
-> ty::Predicate<'tcx>;
1372-
fn read_polytype<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1373-
-> ty::Polytype<'tcx>;
1372+
fn read_type_scheme<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1373+
-> ty::TypeScheme<'tcx>;
13741374
fn read_existential_bounds<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
13751375
-> ty::ExistentialBounds;
13761376
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> {
15911591
}).unwrap()
15921592
}
15931593

1594-
fn read_polytype<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1595-
-> ty::Polytype<'tcx> {
1596-
self.read_struct("Polytype", 2, |this| {
1597-
Ok(ty::Polytype {
1594+
fn read_type_scheme<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
1595+
-> ty::TypeScheme<'tcx> {
1596+
self.read_struct("TypeScheme", 2, |this| {
1597+
Ok(ty::TypeScheme {
15981598
generics: this.read_struct_field("generics", 0, |this| {
15991599
this.read_struct("Generics", 2, |this| {
16001600
Ok(ty::Generics {
@@ -1939,9 +1939,9 @@ fn decode_side_tables(dcx: &DecodeContext,
19391939
.insert(id, capture_mode);
19401940
}
19411941
c::tag_table_tcache => {
1942-
let pty = val_dsr.read_polytype(dcx);
1942+
let type_scheme = val_dsr.read_type_scheme(dcx);
19431943
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
1944-
dcx.tcx.tcache.borrow_mut().insert(lid, pty);
1944+
dcx.tcx.tcache.borrow_mut().insert(lid, type_scheme);
19451945
}
19461946
c::tag_table_param_defs => {
19471947
let bounds = val_dsr.read_type_param_def(dcx);

src/librustc/middle/ty.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ pub struct ctxt<'tcx> {
695695
pub map: ast_map::Map<'tcx>,
696696
pub intrinsic_defs: RefCell<DefIdMap<Ty<'tcx>>>,
697697
pub freevars: RefCell<FreevarMap>,
698-
pub tcache: RefCell<DefIdMap<Polytype<'tcx>>>,
698+
pub tcache: RefCell<DefIdMap<TypeScheme<'tcx>>>,
699699
pub rcache: RefCell<FnvHashMap<creader_cache_key, Ty<'tcx>>>,
700700
pub short_names_cache: RefCell<FnvHashMap<Ty<'tcx>, String>>,
701701
pub tc_cache: RefCell<FnvHashMap<Ty<'tcx>, TypeContents>>,
@@ -2029,18 +2029,23 @@ impl<'tcx> ParameterEnvironment<'tcx> {
20292029
}
20302030
}
20312031

2032-
/// A polytype.
2032+
/// A "type scheme", in ML terminology, is a type combined with some
2033+
/// set of generic types that the type is, well, generic over. In Rust
2034+
/// terms, it is the "type" of a fn item or struct -- this type will
2035+
/// include various generic parameters that must be substituted when
2036+
/// the item/struct is referenced. That is called converting the type
2037+
/// scheme to a monotype.
20332038
///
20342039
/// - `generics`: the set of type parameters and their bounds
20352040
/// - `ty`: the base types, which may reference the parameters defined
20362041
/// in `generics`
20372042
#[deriving(Clone, Show)]
2038-
pub struct Polytype<'tcx> {
2043+
pub struct TypeScheme<'tcx> {
20392044
pub generics: Generics<'tcx>,
20402045
pub ty: Ty<'tcx>
20412046
}
20422047

2043-
/// As `Polytype` but for a trait ref.
2048+
/// As `TypeScheme` but for a trait ref.
20442049
pub struct TraitDef<'tcx> {
20452050
pub unsafety: ast::Unsafety,
20462051

@@ -5102,7 +5107,7 @@ pub fn enum_variant_with_id<'tcx>(cx: &ctxt<'tcx>,
51025107
// the type cache. Returns the type parameters and type.
51035108
pub fn lookup_item_type<'tcx>(cx: &ctxt<'tcx>,
51045109
did: ast::DefId)
5105-
-> Polytype<'tcx> {
5110+
-> TypeScheme<'tcx> {
51065111
lookup_locally_or_in_crate_store(
51075112
"tcache", did, &mut *cx.tcache.borrow_mut(),
51085113
|| csearch::get_type(cx, did))

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,9 @@ impl<'tcx> Repr<'tcx> for ast::DefId {
929929
}
930930
}
931931

932-
impl<'tcx> Repr<'tcx> for ty::Polytype<'tcx> {
932+
impl<'tcx> Repr<'tcx> for ty::TypeScheme<'tcx> {
933933
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
934-
format!("Polytype {{generics: {}, ty: {}}}",
934+
format!("TypeScheme {{generics: {}, ty: {}}}",
935935
self.generics.repr(tcx),
936936
self.ty.repr(tcx))
937937
}

src/librustc_trans/trans/callee.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
514514
return val;
515515
}
516516

517-
// Polytype of the function item (may have type params)
518-
let fn_tpt = ty::lookup_item_type(tcx, def_id);
517+
// Type scheme of the function item (may have type params)
518+
let fn_type_scheme = ty::lookup_item_type(tcx, def_id);
519519

520520
// Find the actual function pointer.
521521
let mut val = {
@@ -524,7 +524,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
524524
get_item_val(ccx, def_id.node)
525525
} else {
526526
// External reference.
527-
trans_external_path(ccx, def_id, fn_tpt.ty)
527+
trans_external_path(ccx, def_id, fn_type_scheme.ty)
528528
}
529529
};
530530

@@ -551,7 +551,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
551551
// This can occur on either a crate-local or crate-external
552552
// reference. It also occurs when testing libcore and in some
553553
// other weird situations. Annoying.
554-
let llty = type_of::type_of_fn_from_ty(ccx, fn_tpt.ty);
554+
let llty = type_of::type_of_fn_from_ty(ccx, fn_type_scheme.ty);
555555
let llptrty = llty.ptr_to();
556556
if val_ty(val) != llptrty {
557557
debug!("trans_fn_ref_with_vtables(): casting pointer!");

src/librustc_typeck/astconv.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
//! somewhat differently during the collect and check phases,
1717
//! particularly with respect to looking up the types of top-level
1818
//! items. In the collect phase, the crate context is used as the
19-
//! `AstConv` instance; in this phase, the `get_item_ty()` function
19+
//! `AstConv` instance; in this phase, the `get_item_type_scheme()` function
2020
//! triggers a recursive call to `ty_of_item()` (note that
2121
//! `ast_ty_to_ty()` will detect recursive types and report an error).
2222
//! In the check phase, when the FnCtxt is used as the `AstConv`,
23-
//! `get_item_ty()` just looks up the item type in `tcx.tcache`.
23+
//! `get_item_type_scheme()` just looks up the item type in `tcx.tcache`.
2424
//!
2525
//! The `RegionScope` trait controls what happens when the user does
2626
//! not specify a region in some location where a region is required
@@ -70,7 +70,7 @@ use syntax::print::pprust;
7070

7171
pub trait AstConv<'tcx> {
7272
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>;
73-
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx>;
73+
fn get_item_type_scheme(&self, id: ast::DefId) -> ty::TypeScheme<'tcx>;
7474
fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef<'tcx>>;
7575

7676
/// 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>(
650650
-> TypeAndSubsts<'tcx>
651651
{
652652
let tcx = this.tcx();
653-
let ty::Polytype {
653+
let ty::TypeScheme {
654654
generics,
655655
ty: decl_ty
656-
} = this.get_item_ty(did);
656+
} = this.get_item_type_scheme(did);
657657

658658
let substs = ast_path_substs_for_ty(this,
659659
rscope,
@@ -678,10 +678,10 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
678678
where AC : AstConv<'tcx>, RS : RegionScope
679679
{
680680
let tcx = this.tcx();
681-
let ty::Polytype {
681+
let ty::TypeScheme {
682682
generics,
683683
ty: decl_ty
684-
} = this.get_item_ty(did);
684+
} = this.get_item_type_scheme(did);
685685

686686
let wants_params =
687687
generics.has_type_params(TypeSpace) || generics.has_region_params(TypeSpace);

src/librustc_typeck/check/_match.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
7979
}
8080
ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
8181
let const_did = tcx.def_map.borrow()[pat.id].clone().def_id();
82-
let const_pty = ty::lookup_item_type(tcx, const_did);
83-
fcx.write_ty(pat.id, const_pty.ty);
84-
demand::suptype(fcx, pat.span, expected, const_pty.ty);
82+
let const_scheme = ty::lookup_item_type(tcx, const_did);
83+
fcx.write_ty(pat.id, const_scheme.ty);
84+
demand::suptype(fcx, pat.span, expected, const_scheme.ty);
8585
}
8686
ast::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map, pat) => {
8787
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,
395395
let enum_def = def.variant_def_ids()
396396
.map_or_else(|| def.def_id(), |(enum_def, _)| enum_def);
397397

398-
let ctor_pty = ty::lookup_item_type(tcx, enum_def);
399-
let path_ty = if ty::is_fn_ty(ctor_pty.ty) {
400-
ty::Polytype {
401-
ty: ty::ty_fn_ret(ctor_pty.ty).unwrap(),
402-
..ctor_pty
398+
let ctor_scheme = ty::lookup_item_type(tcx, enum_def);
399+
let path_scheme = if ty::is_fn_ty(ctor_scheme.ty) {
400+
ty::TypeScheme {
401+
ty: ty::ty_fn_ret(ctor_scheme.ty).unwrap(),
402+
..ctor_scheme
403403
}
404404
} else {
405-
ctor_pty
405+
ctor_scheme
406406
};
407-
instantiate_path(pcx.fcx, path, path_ty, def, pat.span, pat.id);
407+
instantiate_path(pcx.fcx, path, path_scheme, def, pat.span, pat.id);
408408

409409
let pat_ty = fcx.node_ty(pat.id);
410410
demand::eqtype(fcx, pat.span, expected, pat_ty);

0 commit comments

Comments
 (0)