Skip to content

Commit

Permalink
typeck::check::coercion - roll back failed unsizing type vars
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arielb1 committed Sep 24, 2017
1 parent acb73db commit 9d6b9d6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/librustc_typeck/check/coercion.rs
Expand Up @@ -187,7 +187,11 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
}

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

0 comments on commit 9d6b9d6

Please sign in to comment.