From aff620de1e5e0791b7c91f765cf17f3214848230 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Wed, 23 Apr 2014 00:59:42 +0200 Subject: rustc: Remove moved_variables_set --- src/librustc/driver/driver.rs | 5 +-- src/librustc/middle/borrowck/mod.rs | 3 -- src/librustc/middle/moves.rs | 21 +--------- .../compile-fail/borrowck-preserve-box-in-field.rs | 39 +++++++++++++++++++ .../compile-fail/borrowck-preserve-box-in-uniq.rs | 39 +++++++++++++++++++ src/test/compile-fail/borrowck-preserve-box.rs | 37 ++++++++++++++++++ .../compile-fail/borrowck-preserve-cond-box.rs | 45 ++++++++++++++++++++++ .../compile-fail/borrowck-preserve-expl-deref.rs | 39 +++++++++++++++++++ .../compile-fail/regions-appearance-constraint.rs | 35 +++++++++++++++++ .../run-pass/borrowck-preserve-box-in-field.rs | 37 ------------------ src/test/run-pass/borrowck-preserve-box-in-uniq.rs | 37 ------------------ src/test/run-pass/borrowck-preserve-box.rs | 35 ----------------- src/test/run-pass/borrowck-preserve-cond-box.rs | 45 ---------------------- src/test/run-pass/borrowck-preserve-expl-deref.rs | 37 ------------------ src/test/run-pass/regions-appearance-constraint.rs | 36 ----------------- 15 files changed, 236 insertions(+), 254 deletions(-) create mode 100644 src/test/compile-fail/borrowck-preserve-box-in-field.rs create mode 100644 src/test/compile-fail/borrowck-preserve-box-in-uniq.rs create mode 100644 src/test/compile-fail/borrowck-preserve-box.rs create mode 100644 src/test/compile-fail/borrowck-preserve-cond-box.rs create mode 100644 src/test/compile-fail/borrowck-preserve-expl-deref.rs create mode 100644 src/test/compile-fail/regions-appearance-constraint.rs delete mode 100644 src/test/run-pass/borrowck-preserve-box-in-field.rs delete mode 100644 src/test/run-pass/borrowck-preserve-box-in-uniq.rs delete mode 100644 src/test/run-pass/borrowck-preserve-box.rs delete mode 100644 src/test/run-pass/borrowck-preserve-cond-box.rs delete mode 100644 src/test/run-pass/borrowck-preserve-expl-deref.rs delete mode 100644 src/test/run-pass/regions-appearance-constraint.rs diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index ebac18086c0..10650b747bd 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -348,8 +348,7 @@ pub fn phase_3_run_analysis_passes(sess: Session, time(time_passes, "effect checking", (), |_| middle::effect::check_crate(&ty_cx, krate)); - let middle::moves::MoveMaps {moves_map, moved_variables_set, - capture_map} = + let middle::moves::MoveMaps {moves_map, capture_map} = time(time_passes, "compute moves", (), |_| middle::moves::compute_moves(&ty_cx, krate)); @@ -361,11 +360,9 @@ pub fn phase_3_run_analysis_passes(sess: Session, time(time_passes, "borrow checking", (), |_| middle::borrowck::check_crate(&ty_cx, &moves_map, - &moved_variables_set, &capture_map, krate)); drop(moves_map); - drop(moved_variables_set); time(time_passes, "kind checking", (), |_| kind::check_crate(&ty_cx, krate)); diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 47aa7907b5a..5504393e7c2 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -77,13 +77,11 @@ impl<'a> Visitor<()> for BorrowckCtxt<'a> { pub fn check_crate(tcx: &ty::ctxt, moves_map: &NodeSet, - moved_variables_set: &NodeSet, capture_map: &moves::CaptureMap, krate: &ast::Crate) { let mut bccx = BorrowckCtxt { tcx: tcx, moves_map: moves_map, - moved_variables_set: moved_variables_set, capture_map: capture_map, stats: @BorrowStats { loaned_paths_same: Cell::new(0), @@ -168,7 +166,6 @@ fn borrowck_fn(this: &mut BorrowckCtxt, pub struct BorrowckCtxt<'a> { tcx: &'a ty::ctxt, moves_map: &'a NodeSet, - moved_variables_set: &'a NodeSet, capture_map: &'a moves::CaptureMap, // Statistics: diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 53d3dec6713..1e44e1ab7f9 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -101,11 +101,6 @@ borrow checker and trans, for example, only care about the outermost expressions that are moved. It is more efficient therefore just to store those entries. -Sometimes though we want to know the variables that are moved (in -particular in the borrow checker). For these cases, the set -`moved_variables_set` just collects the ids of variables that are -moved. - Finally, the `capture_map` maps from the node_id of a closure expression to an array of `CaptureVar` structs detailing which variables are captured and how (by ref, by copy, by move). @@ -170,7 +165,6 @@ pub struct MoveMaps { * pub Note: The `moves_map` stores expression ids that are moves, * whereas this set stores the ids of the variables that are * moved at some point */ - pub moved_variables_set: NodeSet, pub capture_map: CaptureMap } @@ -206,7 +200,6 @@ pub fn compute_moves(tcx: &ty::ctxt, krate: &Crate) -> MoveMaps { tcx: tcx, move_maps: MoveMaps { moves_map: NodeSet::new(), - moved_variables_set: NodeSet::new(), capture_map: NodeMap::new() } }; @@ -326,19 +319,6 @@ impl<'a> VisitContext<'a> { debug!("comp_mode = {:?}", comp_mode); match expr.node { - ExprPath(..) => { - match comp_mode { - Move => { - let def = self.tcx.def_map.borrow().get_copy(&expr.id); - let r = moved_variable_node_id_from_def(def); - for &id in r.iter() { - self.move_maps.moved_variables_set.insert(id); - } - } - Read => {} - } - } - ExprUnary(UnDeref, base) => { // *base if !self.use_overloaded_operator(expr, base, []) { // Moving out of *base moves out of base. @@ -475,6 +455,7 @@ impl<'a> VisitContext<'a> { self.use_expr(base, Read); } + ExprPath(..) | ExprInlineAsm(..) | ExprBreak(..) | ExprAgain(..) | diff --git a/src/test/compile-fail/borrowck-preserve-box-in-field.rs b/src/test/compile-fail/borrowck-preserve-box-in-field.rs new file mode 100644 index 00000000000..ff138451e93 --- /dev/null +++ b/src/test/compile-fail/borrowck-preserve-box-in-field.rs @@ -0,0 +1,39 @@ +// ignore-pretty + +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = @F {f: ~3}; + borrow(x.f, |b_x| { + //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + //~^ NOTE borrow occurs due to use of `x` in closure + x = @F {f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs b/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs new file mode 100644 index 00000000000..b06eb0d6ba2 --- /dev/null +++ b/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs @@ -0,0 +1,39 @@ +// ignore-pretty + +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = ~@F{f: ~3}; + borrow(x.f, |b_x| { + //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + //~^ NOTE borrow occurs due to use of `x` in closure + *x = @F{f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/compile-fail/borrowck-preserve-box.rs b/src/test/compile-fail/borrowck-preserve-box.rs new file mode 100644 index 00000000000..1a920c7871e --- /dev/null +++ b/src/test/compile-fail/borrowck-preserve-box.rs @@ -0,0 +1,37 @@ +// ignore-pretty + +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +pub fn main() { + let mut x = @3; + borrow(x, |b_x| { + //~^ ERROR cannot borrow `x` as mutable because `*x` is also borrowed as immutable + assert_eq!(*b_x, 3); + assert_eq!(&(*x) as *int, &(*b_x) as *int); + //~^ NOTE borrow occurs due to use of `x` in closure + x = @22; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/compile-fail/borrowck-preserve-cond-box.rs b/src/test/compile-fail/borrowck-preserve-cond-box.rs new file mode 100644 index 00000000000..7000e2351dd --- /dev/null +++ b/src/test/compile-fail/borrowck-preserve-cond-box.rs @@ -0,0 +1,45 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn testfn(cond: bool) { + let mut x = @3; + let mut y = @4; + + // borrow x and y + let r_x = &*x; + let r_y = &*y; + let mut r = r_x; + let mut exp = 3; + + if cond { + r = r_y; + exp = 4; + } + + println!("*r = {}, exp = {}", *r, exp); + assert_eq!(*r, exp); + + x = @5; //~ERROR cannot assign to `x` because it is borrowed + y = @6; //~ERROR cannot assign to `y` because it is borrowed + + println!("*r = {}, exp = {}", *r, exp); + assert_eq!(*r, exp); + assert_eq!(x, @5); + assert_eq!(y, @6); +} + +pub fn main() { + testfn(true); + testfn(false); +} diff --git a/src/test/compile-fail/borrowck-preserve-expl-deref.rs b/src/test/compile-fail/borrowck-preserve-expl-deref.rs new file mode 100644 index 00000000000..aeabf6d9f8b --- /dev/null +++ b/src/test/compile-fail/borrowck-preserve-expl-deref.rs @@ -0,0 +1,39 @@ +// ignore-pretty + +// Copyright 2012-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// exec-env:RUST_POISON_ON_FREE=1 + +#![feature(managed_boxes)] + +fn borrow(x: &int, f: |x: &int|) { + let before = *x; + f(x); + let after = *x; + assert_eq!(before, after); +} + +struct F { f: ~int } + +pub fn main() { + let mut x = @F {f: ~3}; + borrow((*x).f, |b_x| { + //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable + assert_eq!(*b_x, 3); + assert_eq!(&(*x.f) as *int, &(*b_x) as *int); + //~^ NOTE borrow occurs due to use of `x` in closure + x = @F {f: ~4}; + + println!("&*b_x = {:p}", &(*b_x)); + assert_eq!(*b_x, 3); + assert!(&(*x.f) as *int != &(*b_x) as *int); + }) +} diff --git a/src/test/compile-fail/regions-appearance-constraint.rs b/src/test/compile-fail/regions-appearance-constraint.rs new file mode 100644 index 00000000000..68bbebb8cb0 --- /dev/null +++ b/src/test/compile-fail/regions-appearance-constraint.rs @@ -0,0 +1,35 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test no-special rooting is used for managed boxes + +#![feature(managed_boxes)] + +fn testfn(cond: bool) { + let mut x = @3; + let mut y = @4; + + let mut a = &*x; + + let mut exp = 3; + if cond { + a = &*y; + + exp = 4; + } + + x = @5; //~ERROR cannot assign to `x` because it is borrowed + y = @6; //~ERROR cannot assign to `y` because it is borrowed + assert_eq!(*a, exp); + assert_eq!(x, @5); + assert_eq!(y, @6); +} + +pub fn main() {} diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs deleted file mode 100644 index f05b8c67d77..00000000000 --- a/src/test/run-pass/borrowck-preserve-box-in-field.rs +++ /dev/null @@ -1,37 +0,0 @@ -// ignore-pretty - -// Copyright 2012-2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// exec-env:RUST_POISON_ON_FREE=1 - -#![feature(managed_boxes)] - -fn borrow(x: &int, f: |x: &int|) { - let before = *x; - f(x); - let after = *x; - assert_eq!(before, after); -} - -struct F { f: ~int } - -pub fn main() { - let mut x = @F {f: ~3}; - borrow(x.f, |b_x| { - assert_eq!(*b_x, 3); - assert_eq!(&(*x.f) as *int, &(*b_x) as *int); - x = @F {f: ~4}; - - println!("&*b_x = {:p}", &(*b_x)); - assert_eq!(*b_x, 3); - assert!(&(*x.f) as *int != &(*b_x) as *int); - }) -} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs deleted file mode 100644 index 0896d4de625..00000000000 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ /dev/null @@ -1,37 +0,0 @@ -// ignore-pretty - -// Copyright 2012-2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// exec-env:RUST_POISON_ON_FREE=1 - -#![feature(managed_boxes)] - -fn borrow(x: &int, f: |x: &int|) { - let before = *x; - f(x); - let after = *x; - assert_eq!(before, after); -} - -struct F { f: ~int } - -pub fn main() { - let mut x = ~@F{f: ~3}; - borrow(x.f, |b_x| { - assert_eq!(*b_x, 3); - assert_eq!(&(*x.f) as *int, &(*b_x) as *int); - *x = @F{f: ~4}; - - println!("&*b_x = {:p}", &(*b_x)); - assert_eq!(*b_x, 3); - assert!(&(*x.f) as *int != &(*b_x) as *int); - }) -} diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs deleted file mode 100644 index cfb9a4b91df..00000000000 --- a/src/test/run-pass/borrowck-preserve-box.rs +++ /dev/null @@ -1,35 +0,0 @@ -// ignore-pretty - -// Copyright 2012-2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// exec-env:RUST_POISON_ON_FREE=1 - -#![feature(managed_boxes)] - -fn borrow(x: &int, f: |x: &int|) { - let before = *x; - f(x); - let after = *x; - assert_eq!(before, after); -} - -pub fn main() { - let mut x = @3; - borrow(x, |b_x| { - assert_eq!(*b_x, 3); - assert_eq!(&(*x) as *int, &(*b_x) as *int); - x = @22; - - println!("&*b_x = {:p}", &(*b_x)); - assert_eq!(*b_x, 3); - assert!(&(*x) as *int != &(*b_x) as *int); - }) -} diff --git a/src/test/run-pass/borrowck-preserve-cond-box.rs b/src/test/run-pass/borrowck-preserve-cond-box.rs deleted file mode 100644 index 52ea474dbf5..00000000000 --- a/src/test/run-pass/borrowck-preserve-cond-box.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// exec-env:RUST_POISON_ON_FREE=1 - -#![feature(managed_boxes)] - -fn testfn(cond: bool) { - let mut x = @3; - let mut y = @4; - - // borrow x and y - let r_x = &*x; - let r_y = &*y; - let mut r = r_x; - let mut exp = 3; - - if cond { - r = r_y; - exp = 4; - } - - println!("*r = {}, exp = {}", *r, exp); - assert_eq!(*r, exp); - - x = @5; - y = @6; - - println!("*r = {}, exp = {}", *r, exp); - assert_eq!(*r, exp); - assert_eq!(x, @5); - assert_eq!(y, @6); -} - -pub fn main() { - testfn(true); - testfn(false); -} diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs deleted file mode 100644 index 749c8063950..00000000000 --- a/src/test/run-pass/borrowck-preserve-expl-deref.rs +++ /dev/null @@ -1,37 +0,0 @@ -// ignore-pretty - -// Copyright 2012-2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// exec-env:RUST_POISON_ON_FREE=1 - -#![feature(managed_boxes)] - -fn borrow(x: &int, f: |x: &int|) { - let before = *x; - f(x); - let after = *x; - assert_eq!(before, after); -} - -struct F { f: ~int } - -pub fn main() { - let mut x = @F {f: ~3}; - borrow((*x).f, |b_x| { - assert_eq!(*b_x, 3); - assert_eq!(&(*x.f) as *int, &(*b_x) as *int); - x = @F {f: ~4}; - - println!("&*b_x = {:p}", &(*b_x)); - assert_eq!(*b_x, 3); - assert!(&(*x.f) as *int != &(*b_x) as *int); - }) -} diff --git a/src/test/run-pass/regions-appearance-constraint.rs b/src/test/run-pass/regions-appearance-constraint.rs deleted file mode 100644 index a65a878b3c7..00000000000 --- a/src/test/run-pass/regions-appearance-constraint.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/* Tests conditional rooting of the box y */ - -#![feature(managed_boxes)] - -fn testfn(cond: bool) { - let mut x = @3; - let mut y = @4; - - let mut a = &*x; - - let mut exp = 3; - if cond { - a = &*y; - - exp = 4; - } - - x = @5; - y = @6; - assert_eq!(*a, exp); - assert_eq!(x, @5); - assert_eq!(y, @6); -} - -pub fn main() { -} -- cgit 1.4.1-3-g733a5