Skip to content

Commit 9d6b9d6

Browse files
committedSep 24, 2017
typeck::check::coercion - roll back failed unsizing type vars
This wraps unsizing coercions within an additional level of `commit_if_ok`, which rolls back type variables if the unsizing coercion fails. This prevents a large amount of type-variables from accumulating while type-checking a large function, e.g. shaving 2GB off one of the 4GB peaks in #36799.
1 parent acb73db commit 9d6b9d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎src/librustc_typeck/check/coercion.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
187187
}
188188

189189
// Consider coercing the subtype to a DST
190-
let unsize = self.coerce_unsized(a, b);
190+
//
191+
// NOTE: this is wrapped in a `commit_if_ok` because it creates
192+
// a "spurious" type variable, and we don't want to have that
193+
// type variable in memory if the coercion fails.
194+
let unsize = self.commit_if_ok(|_| self.coerce_unsized(a, b));
191195
if unsize.is_ok() {
192196
debug!("coerce: unsize successful");
193197
return unsize;

0 commit comments

Comments
 (0)
Please sign in to comment.