diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-02-26 16:21:26 +0200 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-03-02 22:38:21 +0200 |
| commit | 6755fb8ba2300a121cb14bd79327c3eb730bc55d (patch) | |
| tree | c5ac2bcc040c3ded0be760b28dac745caf947082 /src/test | |
| parent | 5907ed63d329daefcd1680813d57e5ca00cd2fc2 (diff) | |
| download | rust-6755fb8ba2300a121cb14bd79327c3eb730bc55d.tar.gz rust-6755fb8ba2300a121cb14bd79327c3eb730bc55d.zip | |
schedule drops on bindings only after initializing them
This reduces the number of dynamic drops in libstd from 1141 to 899. However, without this change, the next patch would have created much more dynamic drops. A basic merge unswitching hack reduced the number of dynamic drops to 644, with no effect on stack usage. I should be writing a more dedicated drop unswitching pass. No performance measurements.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/mir-opt/storage_ranges.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/mir_drop_order.rs | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src/test/mir-opt/storage_ranges.rs b/src/test/mir-opt/storage_ranges.rs index 933bfa8df2e..c63db741e5a 100644 --- a/src/test/mir-opt/storage_ranges.rs +++ b/src/test/mir-opt/storage_ranges.rs @@ -31,8 +31,8 @@ fn main() { // _3 = &_4; // StorageDead(_5); // _2 = (); -// StorageDead(_4); // StorageDead(_3); +// StorageDead(_4); // StorageLive(_6); // _6 = const 1i32; // _0 = (); diff --git a/src/test/run-pass/mir_drop_order.rs b/src/test/run-pass/mir_drop_order.rs new file mode 100644 index 00000000000..55ac5ca067b --- /dev/null +++ b/src/test/run-pass/mir_drop_order.rs @@ -0,0 +1,42 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::cell::RefCell; + +pub struct DropLogger<'a> { + id: usize, + log: &'a RefCell<Vec<usize>> +} + +impl<'a> Drop for DropLogger<'a> { + fn drop(&mut self) { + self.log.borrow_mut().push(self.id); + } +} + +fn main() { + let log = RefCell::new(vec![]); + let d = |id| DropLogger { id: id, log: &log }; + let get = || -> Vec<_> { + let mut m = log.borrow_mut(); + let n = m.drain(..); + n.collect() + }; + + { + let _x = (d(0), &d(1), d(2), &d(3)); + // all borrows are extended - nothing has been dropped yet + assert_eq!(get(), vec![]); + } + // in a let-statement, extended lvalues are dropped + // *after* the let result (tho they have the same scope + // as far as scope-based borrowck goes). + assert_eq!(get(), vec![0, 2, 3, 1]); +} |
