Skip to content

Commit 3779971

Browse files
committed
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.
1 parent 1fece3d commit 3779971

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/librustc/infer/higher_ranked/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -749,15 +749,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
749749
pub fn plug_leaks<T>(&self,
750750
skol_map: SkolemizationMap<'tcx>,
751751
snapshot: &CombinedSnapshot,
752-
value: &T) -> T
752+
value: T) -> T
753753
where T : TypeFoldable<'tcx>
754754
{
755755
debug!("plug_leaks(skol_map={:?}, value={:?})",
756756
skol_map,
757757
value);
758758

759759
if skol_map.is_empty() {
760-
return self.resolve_type_vars_if_possible(value);
760+
return value;
761761
}
762762

763763
// Compute a mapping from the "taint set" of each skolemized
@@ -779,7 +779,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
779779

780780
// Remove any instantiated type variables from `value`; those can hide
781781
// references to regions from the `fold_regions` code below.
782-
let value = self.resolve_type_vars_if_possible(value);
782+
let value = self.resolve_type_vars_if_possible(&value);
783783

784784
// Map any skolemization byproducts back to a late-bound
785785
// region. Put that late-bound region at whatever the outermost

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
171171
Ok(result) => {
172172
let span = obligation.cause.span;
173173
match infcx.leak_check(false, span, &skol_map, snapshot) {
174-
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, &result)),
174+
Ok(()) => Ok(infcx.plug_leaks(skol_map, snapshot, result)),
175175
Err(e) => Err(MismatchedProjectionTypes { err: e }),
176176
}
177177
}

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
19801980
normalized_ty,
19811981
&[]);
19821982
obligations.push(skol_obligation);
1983-
this.infcx().plug_leaks(skol_map, snapshot, &obligations)
1983+
this.infcx().plug_leaks(skol_map, snapshot, obligations)
19841984
})
19851985
}).collect()
19861986
}
@@ -2899,7 +2899,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
28992899
predicate: predicate.value
29002900
}))
29012901
}).collect();
2902-
self.infcx().plug_leaks(skol_map, snapshot, &predicates)
2902+
self.infcx().plug_leaks(skol_map, snapshot, predicates)
29032903
}
29042904
}
29052905

0 commit comments

Comments
 (0)