Rename common::normalize to common::erase_regions

This commit is contained in:
Niko Matsakis 2015-01-07 09:36:11 -05:00
parent 2a8cb678e6
commit bdc1bfd8f1
5 changed files with 20 additions and 13 deletions

View file

@ -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>,

View file

@ -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 => { }

View file

@ -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!()

View file

@ -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)
}

View file

@ -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);