Optimize plug_leaks some more.

This commit avoids the `resolve_type_vars_if_possible` call in
`plug_leaks` when `skol_map` is empty, which is the common case. It also
changes the signature of `plug_leaks` slightly to avoid the need for a
`clone` of `value`. These changes give speed-ups of up a few percent on
some of the rustc-benchmarks.
This commit is contained in:
Nicholas Nethercote 2016-09-30 17:44:48 +10:00
parent 1fece3d84b
commit 3779971dbb
3 changed files with 6 additions and 6 deletions

View File

@ -749,7 +749,7 @@ pub fn leak_check(&self,
pub fn plug_leaks<T>(&self,
skol_map: SkolemizationMap<'tcx>,
snapshot: &CombinedSnapshot,
value: &T) -> T
value: T) -> T
where T : TypeFoldable<'tcx>
{
debug!("plug_leaks(skol_map={:?}, value={:?})",
@ -757,7 +757,7 @@ pub fn plug_leaks<T>(&self,
value);
if skol_map.is_empty() {
return self.resolve_type_vars_if_possible(value);
return value;
}
// Compute a mapping from the "taint set" of each skolemized
@ -779,7 +779,7 @@ pub fn plug_leaks<T>(&self,
// Remove any instantiated type variables from `value`; those can hide
// references to regions from the `fold_regions` code below.
let value = self.resolve_type_vars_if_possible(value);
let value = self.resolve_type_vars_if_possible(&value);
// Map any skolemization byproducts back to a late-bound
// region. Put that late-bound region at whatever the outermost

View File

@ -171,7 +171,7 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
Ok(result) => {
let span = obligation.cause.span;
match infcx.leak_check(false, span, &skol_map, snapshot) {
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, &result)),
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)),
Err(e) => Err(MismatchedProjectionTypes { err: e }),
}
}

View File

@ -1980,7 +1980,7 @@ fn collect_predicates_for_types(&mut self,
normalized_ty,
&[]);
obligations.push(skol_obligation);
this.infcx().plug_leaks(skol_map, snapshot, &obligations)
this.infcx().plug_leaks(skol_map, snapshot, obligations)
})
}).collect()
}
@ -2899,7 +2899,7 @@ fn impl_or_trait_obligations(&mut self,
predicate: predicate.value
}))
}).collect();
self.infcx().plug_leaks(skol_map, snapshot, &predicates)
self.infcx().plug_leaks(skol_map, snapshot, predicates)
}
}