Skip to content

Commit

Permalink
Optimize plug_leaks some more.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Oct 3, 2016
1 parent 1fece3d commit 3779971
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/librustc/infer/higher_ranked/mod.rs
Expand Up @@ -749,15 +749,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
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={:?})",
skol_map,
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
Expand All @@ -779,7 +779,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

// 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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/project.rs
Expand Up @@ -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 }),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Expand Up @@ -1980,7 +1980,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
normalized_ty,
&[]);
obligations.push(skol_obligation);
this.infcx().plug_leaks(skol_map, snapshot, &obligations)
this.infcx().plug_leaks(skol_map, snapshot, obligations)
})
}).collect()
}
Expand Down Expand Up @@ -2899,7 +2899,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
predicate: predicate.value
}))
}).collect();
self.infcx().plug_leaks(skol_map, snapshot, &predicates)
self.infcx().plug_leaks(skol_map, snapshot, predicates)
}
}

Expand Down

0 comments on commit 3779971

Please sign in to comment.