parent
30fe55066a
commit
71f054ddd0
8 changed files with 0 additions and 258 deletions
|
|
@ -59,7 +59,6 @@ use middle::trans::meth;
|
|||
use middle::trans::inline;
|
||||
use middle::trans::tvec;
|
||||
use middle::trans::type_of;
|
||||
use middle::trans::write_guard;
|
||||
use middle::ty::struct_fields;
|
||||
use middle::ty::{AutoBorrowObj, AutoDerefRef, AutoAddEnv, AutoObject, AutoUnsafe};
|
||||
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef};
|
||||
|
|
@ -1676,8 +1675,6 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
|
|||
derefs: uint)
|
||||
-> DatumBlock<'a, Expr> {
|
||||
let ccx = bcx.ccx();
|
||||
let bcx = write_guard::root_and_write_guard(&datum, bcx, expr.span,
|
||||
expr.id, derefs);
|
||||
|
||||
debug!("deref_once(expr={}, datum={}, derefs={})",
|
||||
expr.repr(bcx.tcx()),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ pub mod monomorphize;
|
|||
pub mod controlflow;
|
||||
pub mod glue;
|
||||
pub mod datum;
|
||||
pub mod write_guard;
|
||||
pub mod callee;
|
||||
pub mod expr;
|
||||
pub mod common;
|
||||
|
|
|
|||
|
|
@ -1,63 +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 <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.
|
||||
|
||||
//! Logic relating to rooting and write guards for managed values.
|
||||
//! This code is primarily for use by datum;
|
||||
//! it exists in its own module both to keep datum.rs bite-sized
|
||||
//! and for each in debugging (e.g., so you can use
|
||||
//! `RUST_LOG=rustc::middle::trans::write_guard`).
|
||||
|
||||
|
||||
use middle::borrowck::{RootInfo, root_map_key};
|
||||
use middle::trans::cleanup;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::*;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::ast;
|
||||
|
||||
pub fn root_and_write_guard<'a, K:KindOps>(datum: &Datum<K>,
|
||||
bcx: &'a Block<'a>,
|
||||
span: Span,
|
||||
expr_id: ast::NodeId,
|
||||
derefs: uint) -> &'a Block<'a> {
|
||||
let key = root_map_key { id: expr_id, derefs: derefs };
|
||||
debug!("write_guard::root_and_write_guard(key={:?})", key);
|
||||
|
||||
// root the autoderef'd value, if necessary:
|
||||
//
|
||||
// (Note: root'd values are always boxes)
|
||||
let ccx = bcx.ccx();
|
||||
match ccx.maps.root_map.find(&key) {
|
||||
None => bcx,
|
||||
Some(&root_info) => root(datum, bcx, span, key, root_info)
|
||||
}
|
||||
}
|
||||
|
||||
fn root<'a, K:KindOps>(datum: &Datum<K>,
|
||||
bcx: &'a Block<'a>,
|
||||
_span: Span,
|
||||
root_key: root_map_key,
|
||||
root_info: RootInfo) -> &'a Block<'a> {
|
||||
//! In some cases, borrowck will decide that an @T value must be
|
||||
//! rooted for the program to be safe. In that case, we will call
|
||||
//! this function, which will stash a copy away until we exit the
|
||||
//! scope `scope_id`.
|
||||
|
||||
debug!("write_guard::root(root_key={:?}, root_info={:?}, datum={:?})",
|
||||
root_key, root_info, datum.to_str(bcx.ccx()));
|
||||
|
||||
// Root the datum. Note that we must zero this value,
|
||||
// because sometimes we root on one path but not another.
|
||||
// See e.g. #4904.
|
||||
lvalue_scratch_datum(
|
||||
bcx, datum.ty, "__write_guard", true,
|
||||
cleanup::AstScope(root_info.scope), (),
|
||||
|(), bcx, llval| datum.shallow_copy_and_take(bcx, llval)).bcx
|
||||
}
|
||||
|
|
@ -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 <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.
|
||||
|
||||
// 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);
|
||||
})
|
||||
}
|
||||
|
|
@ -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 <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.
|
||||
|
||||
// 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);
|
||||
})
|
||||
}
|
||||
|
|
@ -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 <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.
|
||||
|
||||
// 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);
|
||||
})
|
||||
}
|
||||
|
|
@ -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 <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.
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
|
@ -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 <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.
|
||||
|
||||
// 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);
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue