about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2015-01-07 09:36:11 -0500
committerNiko Matsakis <niko@alum.mit.edu>2015-01-07 14:07:58 -0500
commitbdc1bfd8f1740461d2ee39ba41f5245ed8913a2a (patch)
tree6f526ab32a41d2a5326abf558fdf539cef077b75
parent2a8cb678e61e91c160d80794b5fdd723d0d4211c (diff)
Rename common::normalize to common::erase_regions
-rw-r--r--src/librustc/middle/ty_fold.rs5
-rw-r--r--src/librustc_trans/trans/callee.rs2
-rw-r--r--src/librustc_trans/trans/closure.rs2
-rw-r--r--src/librustc_trans/trans/common.rs22
-rw-r--r--src/librustc_trans/trans/type_of.rs2
5 files changed, 20 insertions, 13 deletions
diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs
index 424e357d8d4..e18e62948fb 100644
--- a/src/librustc/middle/ty_fold.rs
+++ b/src/librustc/middle/ty_fold.rs
@@ -853,7 +853,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
 ///////////////////////////////////////////////////////////////////////////
 // Region eraser
 //
-// Replaces all free regions with 'static. Useful in trans.
+// Replaces all free regions with 'static. Useful in contexts, such as
+// method probing, where precise region relationships are not
+// important. Note that in trans you should use
+// `common::erase_regions` instead.
 
 pub struct RegionEraser<'a, 'tcx: 'a> {
     tcx: &'a ty::ctxt<'tcx>,
diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs
index b7b486f1d0a..4cfd831a325 100644
--- a/src/librustc_trans/trans/callee.rs
+++ b/src/librustc_trans/trans/callee.rs
@@ -265,7 +265,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
     let _icx = push_ctxt("trans_fn_pointer_shim");
     let tcx = ccx.tcx();
 
-    let bare_fn_ty = normalize_ty(tcx, bare_fn_ty);
+    let bare_fn_ty = erase_regions(tcx, &bare_fn_ty);
     match ccx.fn_pointer_shims().borrow().get(&bare_fn_ty) {
         Some(&llval) => { return llval; }
         None => { }
diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs
index ad2ed67b22c..06a1182b1f4 100644
--- a/src/librustc_trans/trans/closure.rs
+++ b/src/librustc_trans/trans/closure.rs
@@ -466,7 +466,7 @@ pub fn get_or_create_declaration_if_unboxed_closure<'a, 'tcx>(ccx: &CrateContext
 
     // Normalize type so differences in regions and typedefs don't cause
     // duplicate declarations
-    let function_type = normalize_ty(ccx.tcx(), function_type);
+    let function_type = erase_regions(ccx.tcx(), &function_type);
     let params = match function_type.sty {
         ty::ty_unboxed_closure(_, _, ref substs) => substs.types.clone(),
         _ => unreachable!()
diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs
index 237fc185636..bdec9ad378b 100644
--- a/src/librustc_trans/trans/common.rs
+++ b/src/librustc_trans/trans/common.rs
@@ -58,16 +58,21 @@ use util::nodemap::FnvHashSet;
 
 pub use trans::context::CrateContext;
 
-/// Returns an equivalent type with all the typedefs and self regions removed.
-pub fn normalize_ty<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
-    let u = TypeNormalizer(cx).fold_ty(ty);
-    debug!("normalize_ty({}) = {}",
-           ty.repr(cx), u.repr(cx));
-    return u;
+/// Returns an equivalent value with all free regions removed (note
+/// that late-bound regions remain, because they are important for
+/// subtyping, but they are anonymized and normalized as well). This
+/// is a stronger, caching version of `ty_fold::erase_regions`.
+pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T
+    where T : TypeFoldable<'tcx> + Repr<'tcx>
+{
+    let value1 = value.fold_with(&mut RegionEraser(cx));
+    debug!("erase_regions({}) = {}",
+           value.repr(cx), value1.repr(cx));
+    return value1;
 
-    struct TypeNormalizer<'a, 'tcx: 'a>(&'a ty::ctxt<'tcx>);
+    struct RegionEraser<'a, 'tcx: 'a>(&'a ty::ctxt<'tcx>);
 
-    impl<'a, 'tcx> TypeFolder<'tcx> for TypeNormalizer<'a, 'tcx> {
+    impl<'a, 'tcx> TypeFolder<'tcx> for RegionEraser<'a, 'tcx> {
         fn tcx(&self) -> &ty::ctxt<'tcx> { self.0 }
 
         fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
@@ -84,7 +89,6 @@ pub fn normalize_ty<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
         fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
             where T : TypeFoldable<'tcx> + Repr<'tcx>
         {
-            // FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
             let u = ty::anonymize_late_bound_regions(self.tcx(), t);
             ty_fold::super_fold_binder(self, &u)
         }
diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs
index 19d50cdd483..ef5394f06b3 100644
--- a/src/librustc_trans/trans/type_of.rs
+++ b/src/librustc_trans/trans/type_of.rs
@@ -285,7 +285,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
     // Rust types are defined as the same LLVM types.  If we don't do
     // this then, e.g. `Option<{myfield: bool}>` would be a different
     // type than `Option<myrec>`.
-    let t_norm = normalize_ty(cx.tcx(), t);
+    let t_norm = erase_regions(cx.tcx(), &t);
 
     if t != t_norm {
         let llty = type_of(cx, t_norm);