Skip to content

Commit

Permalink
Rollup merge of rust-lang#57674 - dotdash:erase_reg, r=varkor
Browse files Browse the repository at this point in the history
Avoid erase_regions_ty queries if there are no regions to erase

It's overall faster to perform this extra check than to perform the
query, even if the result is already in the query cache.
  • Loading branch information
Centril authored Jan 28, 2019
2 parents f21f83d + da06898 commit 76dbfdd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/librustc/ty/erase_regions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ty::{self, Ty, TyCtxt};
use ty::{self, Ty, TyCtxt, TypeFlags};
use ty::fold::{TypeFolder, TypeFoldable};

pub(super) fn provide(providers: &mut ty::query::Providers<'_>) {
Expand All @@ -21,6 +21,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn erase_regions<T>(self, value: &T) -> T
where T : TypeFoldable<'tcx>
{
// If there's nothing to erase avoid performing the query at all
if !value.has_type_flags(TypeFlags::HAS_RE_LATE_BOUND | TypeFlags::HAS_FREE_REGIONS) {
return value.clone();
}

let value1 = value.fold_with(&mut RegionEraserVisitor { tcx: self });
debug!("erase_regions({:?}) = {:?}", value, value1);
value1
Expand Down

0 comments on commit 76dbfdd

Please sign in to comment.