Skip to content

Commit 416e629

Browse files
committed
Rename the code that replaces unbound variables to "freshen" rather than "skolemize" -- strictly speaking, this is not skolemization, because it is not discharging quantifiers. Also, the trait selection code will still be doing true skolemization, so it would be a confusing overlap of names.
1 parent 3cf0fbe commit 416e629

File tree

6 files changed

+104
-100
lines changed

6 files changed

+104
-100
lines changed

src/librustc/middle/infer/skolemize.rs renamed to src/librustc/middle/infer/freshen.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Skolemization is the process of replacing unknown variables with fresh types. The idea is that
12-
//! the type, after skolemization, contains no inference variables but instead contains either a
11+
//! Freshening is the process of replacing unknown variables with fresh types. The idea is that
12+
//! the type, after freshening, contains no inference variables but instead contains either a
1313
//! value for each variable or fresh "arbitrary" types wherever a variable would have been.
1414
//!
15-
//! Skolemization is used primarily to get a good type for inserting into a cache. The result
15+
//! Freshening is used primarily to get a good type for inserting into a cache. The result
1616
//! summarizes what the type inferencer knows "so far". The primary place it is used right now is
1717
//! in the trait matching algorithm, which needs to be able to cache whether an `impl` self type
1818
//! matches some other type X -- *without* affecting `X`. That means if that if the type `X` is in
1919
//! fact an unbound type variable, we want the match to be regarded as ambiguous, because depending
2020
//! on what type that type variable is ultimately assigned, the match may or may not succeed.
2121
//!
22-
//! Note that you should be careful not to allow the output of skolemization to leak to the user in
23-
//! error messages or in any other form. Skolemization is only really useful as an internal detail.
22+
//! Note that you should be careful not to allow the output of freshening to leak to the user in
23+
//! error messages or in any other form. Freshening is only really useful as an internal detail.
2424
//!
25-
//! __An important detail concerning regions.__ The skolemizer also replaces *all* regions with
25+
//! __An important detail concerning regions.__ The freshener also replaces *all* regions with
2626
//! 'static. The reason behind this is that, in general, we do not take region relationships into
2727
//! account when making type-overloaded decisions. This is important because of the design of the
2828
//! region inferencer, which is not based on unification but rather on accumulating and then
@@ -39,47 +39,47 @@ use std::collections::hash_map;
3939
use super::InferCtxt;
4040
use super::unify::InferCtxtMethodsForSimplyUnifiableTypes;
4141

42-
pub struct TypeSkolemizer<'a, 'tcx:'a> {
42+
pub struct TypeFreshener<'a, 'tcx:'a> {
4343
infcx: &'a InferCtxt<'a, 'tcx>,
44-
skolemization_count: uint,
45-
skolemization_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
44+
freshen_count: uint,
45+
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
4646
}
4747

48-
impl<'a, 'tcx> TypeSkolemizer<'a, 'tcx> {
49-
pub fn new(infcx: &'a InferCtxt<'a, 'tcx>) -> TypeSkolemizer<'a, 'tcx> {
50-
TypeSkolemizer {
48+
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
49+
pub fn new(infcx: &'a InferCtxt<'a, 'tcx>) -> TypeFreshener<'a, 'tcx> {
50+
TypeFreshener {
5151
infcx: infcx,
52-
skolemization_count: 0,
53-
skolemization_map: hash_map::HashMap::new(),
52+
freshen_count: 0,
53+
freshen_map: hash_map::HashMap::new(),
5454
}
5555
}
5656

57-
fn skolemize<F>(&mut self,
58-
opt_ty: Option<Ty<'tcx>>,
59-
key: ty::InferTy,
60-
skolemizer: F)
61-
-> Ty<'tcx> where
57+
fn freshen<F>(&mut self,
58+
opt_ty: Option<Ty<'tcx>>,
59+
key: ty::InferTy,
60+
freshener: F)
61+
-> Ty<'tcx> where
6262
F: FnOnce(uint) -> ty::InferTy,
6363
{
6464
match opt_ty {
6565
Some(ty) => { return ty.fold_with(self); }
6666
None => { }
6767
}
6868

69-
match self.skolemization_map.entry(key) {
69+
match self.freshen_map.entry(key) {
7070
hash_map::Occupied(entry) => *entry.get(),
7171
hash_map::Vacant(entry) => {
72-
let index = self.skolemization_count;
73-
self.skolemization_count += 1;
74-
let t = ty::mk_infer(self.infcx.tcx, skolemizer(index));
72+
let index = self.freshen_count;
73+
self.freshen_count += 1;
74+
let t = ty::mk_infer(self.infcx.tcx, freshener(index));
7575
entry.set(t);
7676
t
7777
}
7878
}
7979
}
8080
}
8181

82-
impl<'a, 'tcx> TypeFolder<'tcx> for TypeSkolemizer<'a, 'tcx> {
82+
impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
8383
fn tcx<'b>(&'b self) -> &'b ty::ctxt<'tcx> {
8484
self.infcx.tcx
8585
}
@@ -106,37 +106,37 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeSkolemizer<'a, 'tcx> {
106106
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
107107
match t.sty {
108108
ty::ty_infer(ty::TyVar(v)) => {
109-
self.skolemize(self.infcx.type_variables.borrow().probe(v),
109+
self.freshen(self.infcx.type_variables.borrow().probe(v),
110110
ty::TyVar(v),
111-
ty::SkolemizedTy)
111+
ty::FreshTy)
112112
}
113113

114114
ty::ty_infer(ty::IntVar(v)) => {
115-
self.skolemize(self.infcx.probe_var(v),
116-
ty::IntVar(v),
117-
ty::SkolemizedIntTy)
115+
self.freshen(self.infcx.probe_var(v),
116+
ty::IntVar(v),
117+
ty::FreshIntTy)
118118
}
119119

120120
ty::ty_infer(ty::FloatVar(v)) => {
121-
self.skolemize(self.infcx.probe_var(v),
122-
ty::FloatVar(v),
123-
ty::SkolemizedIntTy)
121+
self.freshen(self.infcx.probe_var(v),
122+
ty::FloatVar(v),
123+
ty::FreshIntTy)
124124
}
125125

126-
ty::ty_infer(ty::SkolemizedTy(c)) |
127-
ty::ty_infer(ty::SkolemizedIntTy(c)) => {
128-
if c >= self.skolemization_count {
126+
ty::ty_infer(ty::FreshTy(c)) |
127+
ty::ty_infer(ty::FreshIntTy(c)) => {
128+
if c >= self.freshen_count {
129129
self.tcx().sess.bug(
130-
format!("Encountered a skolemized type with id {} \
130+
format!("Encountered a freshend type with id {} \
131131
but our counter is only at {}",
132132
c,
133-
self.skolemization_count).as_slice());
133+
self.freshen_count).as_slice());
134134
}
135135
t
136136
}
137137

138138
ty::ty_open(..) => {
139-
self.tcx().sess.bug("Cannot skolemize an open existential type");
139+
self.tcx().sess.bug("Cannot freshen an open existential type");
140140
}
141141

142142
ty::ty_bool |

src/librustc/middle/infer/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use self::TypeOrigin::*;
1919
pub use self::ValuePairs::*;
2020
pub use self::fixup_err::*;
2121
pub use middle::ty::IntVarValue;
22-
pub use self::skolemize::TypeSkolemizer;
22+
pub use self::freshen::TypeFreshener;
2323

2424
use middle::subst;
2525
use middle::subst::Substs;
@@ -57,7 +57,7 @@ pub mod lattice;
5757
pub mod lub;
5858
pub mod region_inference;
5959
pub mod resolve;
60-
mod skolemize;
60+
mod freshen;
6161
pub mod sub;
6262
pub mod type_variable;
6363
pub mod unify;
@@ -505,8 +505,8 @@ pub struct CombinedSnapshot {
505505
}
506506

507507
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
508-
pub fn skolemize<T:TypeFoldable<'tcx>>(&self, t: T) -> T {
509-
t.fold_with(&mut self.skolemizer())
508+
pub fn freshen<T:TypeFoldable<'tcx>>(&self, t: T) -> T {
509+
t.fold_with(&mut self.freshener())
510510
}
511511

512512
pub fn type_var_diverges(&'a self, ty: Ty) -> bool {
@@ -516,8 +516,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
516516
}
517517
}
518518

519-
pub fn skolemizer<'b>(&'b self) -> TypeSkolemizer<'b, 'tcx> {
520-
skolemize::TypeSkolemizer::new(self)
519+
pub fn freshener<'b>(&'b self) -> TypeFreshener<'b, 'tcx> {
520+
freshen::TypeFreshener::new(self)
521521
}
522522

523523
pub fn combine_fields<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)

0 commit comments

Comments
 (0)