Skip to content

Commit bdc1bfd

Browse files
committed
Rename common::normalize to common::erase_regions
1 parent 2a8cb67 commit bdc1bfd

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/librustc/middle/ty_fold.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,10 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
853853
///////////////////////////////////////////////////////////////////////////
854854
// Region eraser
855855
//
856-
// Replaces all free regions with 'static. Useful in trans.
856+
// Replaces all free regions with 'static. Useful in contexts, such as
857+
// method probing, where precise region relationships are not
858+
// important. Note that in trans you should use
859+
// `common::erase_regions` instead.
857860

858861
pub struct RegionEraser<'a, 'tcx: 'a> {
859862
tcx: &'a ty::ctxt<'tcx>,

src/librustc_trans/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
265265
let _icx = push_ctxt("trans_fn_pointer_shim");
266266
let tcx = ccx.tcx();
267267

268-
let bare_fn_ty = normalize_ty(tcx, bare_fn_ty);
268+
let bare_fn_ty = erase_regions(tcx, &bare_fn_ty);
269269
match ccx.fn_pointer_shims().borrow().get(&bare_fn_ty) {
270270
Some(&llval) => { return llval; }
271271
None => { }

src/librustc_trans/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn get_or_create_declaration_if_unboxed_closure<'a, 'tcx>(ccx: &CrateContext
466466

467467
// Normalize type so differences in regions and typedefs don't cause
468468
// duplicate declarations
469-
let function_type = normalize_ty(ccx.tcx(), function_type);
469+
let function_type = erase_regions(ccx.tcx(), &function_type);
470470
let params = match function_type.sty {
471471
ty::ty_unboxed_closure(_, _, ref substs) => substs.types.clone(),
472472
_ => unreachable!()

src/librustc_trans/trans/common.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@ use util::nodemap::FnvHashSet;
5858

5959
pub use trans::context::CrateContext;
6060

61-
/// Returns an equivalent type with all the typedefs and self regions removed.
62-
pub fn normalize_ty<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
63-
let u = TypeNormalizer(cx).fold_ty(ty);
64-
debug!("normalize_ty({}) = {}",
65-
ty.repr(cx), u.repr(cx));
66-
return u;
61+
/// Returns an equivalent value with all free regions removed (note
62+
/// that late-bound regions remain, because they are important for
63+
/// subtyping, but they are anonymized and normalized as well). This
64+
/// is a stronger, caching version of `ty_fold::erase_regions`.
65+
pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T
66+
where T : TypeFoldable<'tcx> + Repr<'tcx>
67+
{
68+
let value1 = value.fold_with(&mut RegionEraser(cx));
69+
debug!("erase_regions({}) = {}",
70+
value.repr(cx), value1.repr(cx));
71+
return value1;
6772

68-
struct TypeNormalizer<'a, 'tcx: 'a>(&'a ty::ctxt<'tcx>);
73+
struct RegionEraser<'a, 'tcx: 'a>(&'a ty::ctxt<'tcx>);
6974

70-
impl<'a, 'tcx> TypeFolder<'tcx> for TypeNormalizer<'a, 'tcx> {
75+
impl<'a, 'tcx> TypeFolder<'tcx> for RegionEraser<'a, 'tcx> {
7176
fn tcx(&self) -> &ty::ctxt<'tcx> { self.0 }
7277

7378
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> {
8489
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
8590
where T : TypeFoldable<'tcx> + Repr<'tcx>
8691
{
87-
// FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
8892
let u = ty::anonymize_late_bound_regions(self.tcx(), t);
8993
ty_fold::super_fold_binder(self, &u)
9094
}

src/librustc_trans/trans/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub fn type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Type {
285285
// Rust types are defined as the same LLVM types. If we don't do
286286
// this then, e.g. `Option<{myfield: bool}>` would be a different
287287
// type than `Option<myrec>`.
288-
let t_norm = normalize_ty(cx.tcx(), t);
288+
let t_norm = erase_regions(cx.tcx(), &t);
289289

290290
if t != t_norm {
291291
let llty = type_of(cx, t_norm);

0 commit comments

Comments
 (0)