mozilla/rust — pull request #8123 by dotdash (2013-07-30 09:16:34+00:00)
Title: Allow early release of rvalues in assignments

The rvalues in assignments might be temporaries (like function return
values) that could be freed immediately after the assignment is done. But
currently, they live to the end of the enclosing scope. For managed
box, this currently means that there is an extra ref count that keeps
the value alive. This leads to a huge memory usage peak in the
expansion phase of compilation with rustc, because all intermediate
expansion results are kept alive till the end of phase 2, instead of
being freed immediately after their last "usable" ref is dropped.

As a stop-gap solution, we can add a scope around the assignment during
translation, which means that the temporary value is dropped right away.
It's only a stop-gap solution because once we switch from refcounting to
garbage collection, it won't help anymore and the code should switch to
either RC or ~ for Crate data, but for now this reduces the peak memory
usage when compiling librustc by about 100MB on my x86_64 Linux box.