Skip to content

Commit

Permalink
auto merge of rust-lang#11485 : eddyb/rust/sweep-old-rust, r=nikomats…
Browse files Browse the repository at this point in the history
…akis
  • Loading branch information
bors committed Jan 14, 2014
2 parents b77a7e7 + 509fc92 commit 9075025
Show file tree
Hide file tree
Showing 39 changed files with 189 additions and 260 deletions.
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::ExplicitSelf_ {
match explicit_self_kind as char {
's' => ast::SelfStatic,
'v' => ast::SelfValue(get_mutability(string[1])),
'@' => ast::SelfBox(get_mutability(string[1])),
'@' => ast::SelfBox,
'~' => ast::SelfUniq(get_mutability(string[1])),
// FIXME(#4846) expl. region
'&' => ast::SelfRegion(None, get_mutability(string[1])),
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,8 @@ fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::Explic
ebml_w.writer.write(&[ '&' as u8 ]);
encode_mutability(ebml_w, m);
}
SelfBox(m) => {
SelfBox => {
ebml_w.writer.write(&[ '@' as u8 ]);
encode_mutability(ebml_w, m);
}
SelfUniq(m) => {
ebml_w.writer.write(&[ '~' as u8 ]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_self(st.tcx, did);
}
'@' => return ty::mk_box(st.tcx, parse_ty(st, |x,y| conv(x,y))),
'~' => return ty::mk_uniq(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
'*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'&' => {
let r = parse_region(st, |x,y| conv(x,y));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ fn enc_sty(w: &mut MemWriter, cx: @ctxt, st: &ty::sty) {
mywrite!(w, "]");
}
ty::ty_box(typ) => { mywrite!(w, "@"); enc_ty(w, cx, typ); }
ty::ty_uniq(mt) => { mywrite!(w, "~"); enc_mt(w, cx, mt); }
ty::ty_uniq(typ) => { mywrite!(w, "~"); enc_ty(w, cx, typ); }
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
ty::ty_rptr(r, mt) => {
mywrite!(w, "&");
Expand Down
51 changes: 7 additions & 44 deletions src/librustc/middle/borrowck/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ data as mutable).
2. `LIFETIME(LV, LT, MQ)`: The lifetime of the borrow does not exceed
the lifetime of the value being borrowed. This pass is also
responsible for inserting root annotations to keep managed values
alive and for dynamically freezing `@mut` boxes.
alive.
3. `RESTRICTIONS(LV, LT, ACTIONS) = RS`: This pass checks and computes the
restrictions to maintain memory safety. These are the restrictions
Expand Down Expand Up @@ -308,22 +308,17 @@ be borrowed if MQ is immutable or const:
### Checking mutability of mutable pointer types
`&mut T` and `@mut T` can be frozen, so it is acceptable to borrow
them as either imm or mut:
`&mut T` can be frozen, so it is acceptable to borrow it as either imm or mut:
MUTABILITY(*LV, MQ) // M-Deref-Borrowed-Mut
TYPE(LV) = &mut Ty
MUTABILITY(*LV, MQ) // M-Deref-Managed-Mut
TYPE(LV) = @mut Ty
## Checking lifetime
These rules aim to ensure that no data is borrowed for a scope that
exceeds its lifetime. In addition, these rules manage the rooting and
dynamic freezing of `@` and `@mut` values. These two computations wind
up being intimately related. Formally, we define a predicate
`LIFETIME(LV, LT, MQ)`, which states that "the lvalue `LV` can be
These rules aim to ensure that no data is borrowed for a scope that exceeds
its lifetime. In addition, these rules manage the rooting of `@` values.
These two computations wind up being intimately related. Formally, we define
a predicate `LIFETIME(LV, LT, MQ)`, which states that "the lvalue `LV` can be
safely borrowed for the lifetime `LT` with mutability `MQ`". The Rust
code corresponding to this predicate is the module
`middle::borrowck::gather_loans::lifetime`.
Expand Down Expand Up @@ -352,7 +347,7 @@ The scope of a managed referent is also the scope of the pointer. This
is a conservative approximation, since there may be other aliases fo
that same managed box that would cause it to live longer:
SCOPE(*LV) = SCOPE(LV) if LV has type @T or @mut T
SCOPE(*LV) = SCOPE(LV) if LV has type @T
The scope of a borrowed referent is the scope associated with the
pointer. This is a conservative approximation, since the data that
Expand Down Expand Up @@ -441,29 +436,6 @@ makes a note in a side-table that the box `LV` must be rooted into the
stack when `*LV` is evaluated, and that this root can be released when
the scope `LT` exits.
### Checking lifetime for derefs of managed, mutable pointers
Loans of the contents of mutable managed pointers are simpler in some
ways that loans of immutable managed pointers, because we can never
rely on the user to root them (since the contents are, after all,
mutable). This means that the burden always falls to the compiler, so
there is only one rule:
LIFETIME(*LV, LT, MQ) // L-Deref-Managed-Mut-Compiler-Root
TYPE(LV) = @mut Ty
LT <= innermost enclosing loop/func
ROOT LV at *LV for LT
LOCK LV at *LV as MQ for LT
Note that there is an additional clause this time `LOCK LV at *LV as
MQ for LT`. This clause states that in addition to rooting `LV`, the
compiler should also "lock" the box dynamically, meaning that we
register that the box has been borrowed as mutable or immutable,
depending on `MQ`. This lock will fail if the box has already been
borrowed and either the old loan or the new loan is a mutable loan
(multiple immutable loans are okay). The lock is released as we exit
the scope `LT`.
## Computing the restrictions
The final rules govern the computation of *restrictions*, meaning that
Expand Down Expand Up @@ -835,15 +807,6 @@ prohibited from both freezes and claims. This would avoid the need to
prevent `const` borrows of the base pointer when the referent is
borrowed.
### Restrictions for loans of mutable managed referents
With `@mut` referents, we don't make any static guarantees. But as a
convenience, we still register a restriction against `*LV`, because
that way if we *can* find a simple static error, we will:
RESTRICTIONS(*LV, LT, ACTIONS) = [*LV, ACTIONS] // R-Deref-Managed-Borrowed
TYPE(LV) = @mut Ty
# Moves and initialization
The borrow checker is also in charge of ensuring that:
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
//
// As a second example, consider *this* scenario:
//
// let x = @mut @Some(3);
// let x = @@Some(3);
// match x { @@Some(y) {...} @@None {...} }
//
// Here again, `x` need only be rooted in the `some` arm.
Expand All @@ -156,7 +156,7 @@ impl<'a> GuaranteeLifetimeContext<'a> {
// with a second basic block. However, the naive approach
// also yielded suboptimal results for patterns like:
//
// let x = @mut @...;
// let x = @@...;
// match x { @@some_variant(y) | @@some_other_variant(y) =>
//
// The reason is that we would root the value once for
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ fn visit_fn(v: &mut LivenessVisitor,
match *fk {
visit::FkMethod(_, _, method) => {
match method.explicit_self.node {
SelfValue(_) | SelfRegion(..) | SelfBox(_) | SelfUniq(_) => {
SelfValue(_) | SelfRegion(..) | SelfBox | SelfUniq(_) => {
fn_maps.add_variable(Arg(method.self_id,
special_idents::self_));
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,18 @@ pub fn malloc_raw_dyn<'a>(
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
} else {
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
let (mk_fn, langcall) = match heap {
let langcall = match heap {
heap_managed | heap_managed_unique => {
(ty::mk_imm_box,
require_alloc_fn(bcx, t, MallocFnLangItem))
require_alloc_fn(bcx, t, MallocFnLangItem)
}
heap_exchange_closure => {
(ty::mk_imm_box,
require_alloc_fn(bcx, t, ClosureExchangeMallocFnLangItem))
require_alloc_fn(bcx, t, ClosureExchangeMallocFnLangItem)
}
_ => fail!("heap_exchange already handled")
};

// Grab the TypeRef type of box_ptr_ty.
let box_ptr_ty = mk_fn(bcx.tcx(), t);
let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
let llty = type_of(ccx, box_ptr_ty);

// Get the tydesc for the body:
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ impl EnvValue {
}
}

pub fn mk_tuplified_uniq_cbox_ty(tcx: ty::ctxt, cdata_ty: ty::t) -> ty::t {
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
return ty::mk_imm_uniq(tcx, cbox_ty);
}

// Given a closure ty, emits a corresponding tuple ty
pub fn mk_closure_tys(tcx: ty::ctxt,
bound_values: &[EnvValue])
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl Datum {

let (content_ty, header) = match ty::get(self.ty).sty {
ty::ty_box(typ) => (typ, true),
ty::ty_uniq(mt) => (mt.ty, false),
ty::ty_uniq(typ) => (typ, false),
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) => {
let unit_ty = ty::sequence_element_type(bcx.tcx(), self.ty);
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
Expand Down
17 changes: 10 additions & 7 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2164,12 +2164,15 @@ fn type_metadata(cx: &CrateContext,
}
}
},
ty::ty_uniq(ref mt) if ty::type_contents(cx.tcx, mt.ty).owns_managed() => {
create_pointer_to_box_metadata(cx, t, mt.ty)
},
ty::ty_uniq(ref mt) |
ty::ty_ptr(ref mt) |
ty::ty_rptr(_, ref mt) => {
ty::ty_uniq(typ) => {
if ty::type_contents(cx.tcx, typ).owns_managed() {
create_pointer_to_box_metadata(cx, t, typ)
} else {
let pointee = type_metadata(cx, typ, usage_site_span);
pointer_type_metadata(cx, t, pointee)
}
}
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {
let pointee = type_metadata(cx, mt.ty, usage_site_span);
pointer_type_metadata(cx, t, pointee)
},
Expand All @@ -2193,7 +2196,7 @@ fn type_metadata(cx: &CrateContext,

let mut created_types = debug_context(cx).created_types.borrow_mut();
created_types.get().insert(cache_id, type_metadata);
return type_metadata;
type_metadata
}

#[deriving(Eq)]
Expand Down
14 changes: 9 additions & 5 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,26 @@ fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
}

if field == abi::tydesc_field_take_glue && ty::type_is_boxed(t) {
return ty::mk_imm_box(tcx, ty::mk_nil());
return ty::mk_box(tcx, ty::mk_nil());
}

if field == abi::tydesc_field_drop_glue {
match ty::get(t).sty {
ty::ty_box(typ)
if !ty::type_needs_drop(tcx, typ) =>
return ty::mk_imm_box(tcx, ty::mk_nil()),
return ty::mk_box(tcx, ty::mk_nil()),

ty::ty_vec(mt, ty::vstore_box)
if !ty::type_needs_drop(tcx, mt.ty) =>
return ty::mk_imm_box(tcx, ty::mk_nil()),
return ty::mk_box(tcx, ty::mk_nil()),

ty::ty_uniq(mt) | ty::ty_vec(mt, ty::vstore_uniq)
ty::ty_uniq(typ)
if !ty::type_needs_drop(tcx, typ) =>
return ty::mk_uniq(tcx, ty::mk_nil()),

ty::ty_vec(mt, ty::vstore_uniq)
if !ty::type_needs_drop(tcx, mt.ty) =>
return ty::mk_imm_uniq(tcx, ty::mk_nil()),
return ty::mk_uniq(tcx, ty::mk_nil()),

_ => {}
}
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl<'a> Reflector<'a> {
self.visit("vec", values)
}

// Should rename to str_*/vec_*.
ty::ty_str(vst) => {
let (name, extra) = self.vstore_name_and_extra(t, vst);
self.visit(~"estr_" + name, extra)
Expand All @@ -189,15 +190,19 @@ impl<'a> Reflector<'a> {
self.visit(~"evec_" + name, extra)
}
}
// Should remove mt from box and uniq.
ty::ty_box(typ) => {
let extra = self.c_mt(&ty::mt {
ty: typ,
mutbl: ast::MutImmutable,
});
self.visit("box", extra)
}
ty::ty_uniq(ref mt) => {
let extra = self.c_mt(mt);
ty::ty_uniq(typ) => {
let extra = self.c_mt(&ty::mt {
ty: typ,
mutbl: ast::MutImmutable,
});
if ty::type_contents(bcx.tcx(), t).owns_managed() {
self.visit("uniq_managed", extra)
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ pub fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
let unit_ty = ty::sequence_element_type(tcx, t);
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
match ty::get(t).sty {
ty::ty_str(ty::vstore_uniq) | ty::ty_vec(_, ty::vstore_uniq) => {
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
}
ty::ty_str(ty::vstore_box) | ty::ty_vec(_, ty::vstore_box) => {
ty::mk_imm_box(tcx, unboxed_vec_ty)
}
_ => tcx.sess.bug("non boxed-vec type \
in tvec::expand_boxed_vec_ty")
ty::ty_str(ty::vstore_uniq) | ty::ty_vec(_, ty::vstore_uniq) => {
ty::mk_uniq(tcx, unboxed_vec_ty)
}
ty::ty_str(ty::vstore_box) | ty::ty_vec(_, ty::vstore_box) => {
ty::mk_box(tcx, unboxed_vec_ty)
}
_ => tcx.sess.bug("non boxed-vec type \
in tvec::expand_boxed_vec_ty")
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ pub fn type_of(cx: &CrateContext, t: ty::t) -> Type {
let ty = type_of(cx, typ);
Type::smart_ptr(cx, &ty).ptr_to()
}
ty::ty_uniq(ref mt) => {
let ty = type_of(cx, mt.ty);
if ty::type_contents(cx.tcx, mt.ty).owns_managed() {
ty::ty_uniq(typ) => {
let ty = type_of(cx, typ);
if ty::type_contents(cx.tcx, typ).owns_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/write_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// 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
//! (`@` and `@mut`). This code is primarily for use by datum;
//! 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`).
Expand Down
Loading

0 comments on commit 9075025

Please sign in to comment.