diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-09-21 17:54:39 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-09-24 12:40:29 +0300 |
| commit | 9d6b9d62ba67fd2ff5d97ae958c954ad2c45d04d (patch) | |
| tree | e450f514c2bd1dcfe7e7c0660fbde767f3ce45b9 | |
| parent | acb73dbe8b311eb2ffa640ac3e01795d84159df4 (diff) | |
| download | rust-9d6b9d62ba67fd2ff5d97ae958c954ad2c45d04d.tar.gz rust-9d6b9d62ba67fd2ff5d97ae958c954ad2c45d04d.zip | |
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.
| -rw-r--r-- | src/librustc_typeck/check/coercion.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index cfcdbcc1195..94422f93e59 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -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; |
