Skip to content

Commit

Permalink
Rename misleading contains_managed to owns_managed
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Nov 5, 2013
1 parent f3191a4 commit 3d1f3f4
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ fn compile_submatch_continue(mut bcx: @mut Block,
let pat_ty = node_id_type(bcx, pat_id);
let llbox = Load(bcx, val);
let unboxed = match ty::get(pat_ty).sty {
ty::ty_uniq(*) if !ty::type_contents(bcx.tcx(), pat_ty).contains_managed() => llbox,
ty::ty_uniq(*) if !ty::type_contents(bcx.tcx(), pat_ty).owns_managed() => llbox,
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
};
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
Expand Down Expand Up @@ -2220,7 +2220,7 @@ fn bind_irrefutable_pat(bcx: @mut Block,
let pat_ty = node_id_type(bcx, pat.id);
let llbox = Load(bcx, val);
let unboxed = match ty::get(pat_ty).sty {
ty::ty_uniq(*) if !ty::type_contents(bcx.tcx(), pat_ty).contains_managed() => llbox,
ty::ty_uniq(*) if !ty::type_contents(bcx.tcx(), pat_ty).owns_managed() => llbox,
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
};
bcx = bind_irrefutable_pat(bcx, inner, unboxed, binding_mode);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {
}

pub fn heap_for_unique(bcx: @mut Block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
heap_managed_unique
} else {
heap_exchange
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
}

fn heap_for_unique_closure(bcx: @mut Block, t: ty::t) -> heap {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
heap_managed_unique
} else {
heap_exchange_closure
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 @@ -566,7 +566,7 @@ impl Datum {
}
};

if !header && !ty::type_contents(bcx.tcx(), content_ty).contains_managed() {
if !header && !ty::type_contents(bcx.tcx(), content_ty).owns_managed() {
let ptr = self.to_value_llval(bcx);
let ty = type_of::type_of(bcx.ccx(), content_ty);
let body = PointerCast(bcx, ptr, ty.ptr_to());
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ fn type_metadata(cx: &mut CrateContext,
ty::vstore_fixed(len) => {
fixed_vec_metadata(cx, mt.ty, len, usage_site_span)
}
ty::vstore_uniq if ty::type_contents(cx.tcx, mt.ty).contains_managed() => {
ty::vstore_uniq if ty::type_contents(cx.tcx, mt.ty).owns_managed() => {
let boxed_vec_metadata = boxed_vec_metadata(cx, mt.ty, usage_site_span);
pointer_type_metadata(cx, t, boxed_vec_metadata)
}
Expand All @@ -2077,7 +2077,7 @@ fn type_metadata(cx: &mut CrateContext,
}
}
},
ty::ty_uniq(ref mt) if ty::type_contents(cx.tcx, mt.ty).contains_managed() => {
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) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {

let has_header = match ty::get(t).sty {
ty::ty_box(*) => true,
ty::ty_uniq(*) => ty::type_contents(ccx.tcx, t).contains_managed(),
ty::ty_uniq(*) => ty::type_contents(ccx.tcx, t).owns_managed(),
_ => false
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
let tp_ty = substs.tys[0];
Ret(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)));
}
"contains_managed" => {
"owns_managed" => {
let tp_ty = substs.tys[0];
Ret(bcx, C_bool(ty::type_contents(ccx.tcx, tp_ty).contains_managed()));
Ret(bcx, C_bool(ty::type_contents(ccx.tcx, tp_ty).owns_managed()));
}
"visit_tydesc" => {
let td = get_param(decl, first_real_arg);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Reflector {
ty::ty_evec(ref mt, vst) => {
let (name, extra) = self.vstore_name_and_extra(t, vst);
let extra = extra + self.c_mt(mt);
if "uniq" == name && ty::type_contents(bcx.tcx(), t).contains_managed() {
if "uniq" == name && ty::type_contents(bcx.tcx(), t).owns_managed() {
self.visit("evec_uniq_managed", extra)
} else {
self.visit(~"evec_" + name, extra)
Expand All @@ -195,7 +195,7 @@ impl Reflector {
}
ty::ty_uniq(ref mt) => {
let extra = self.c_mt(mt);
if ty::type_contents(bcx.tcx(), t).contains_managed() {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
self.visit("uniq_managed", extra)
} else {
self.visit("uniq", extra)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn get_alloc(bcx: @mut Block, vptr: ValueRef) -> ValueRef {
}

pub fn get_bodyptr(bcx: @mut Block, vptr: ValueRef, t: ty::t) -> ValueRef {
if ty::type_contents(bcx.tcx(), t).contains_managed() {
if ty::type_contents(bcx.tcx(), t).owns_managed() {
GEPi(bcx, vptr, [0u, abi::box_field_body])
} else {
vptr
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_opaque_box => Type::opaque_box(cx).ptr_to(),
ty::ty_uniq(ref mt) => {
let ty = type_of(cx, mt.ty);
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
if ty::type_contents(cx.tcx, mt.ty).owns_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
Expand All @@ -235,7 +235,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_evec(ref mt, ty::vstore_uniq) => {
let ty = type_of(cx, mt.ty);
let ty = Type::vec(cx.sess.targ_cfg.arch, &ty);
if ty::type_contents(cx.tcx, mt.ty).contains_managed() {
if ty::type_contents(cx.tcx, mt.ty).owns_managed() {
Type::unique(cx, &ty).ptr_to()
} else {
ty.ptr_to()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/uniq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn make_free_glue(bcx: @mut Block, vptrptr: ValueRef, box_ty: ty::t)
let body_datum = box_datum.box_body(bcx);
let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
body_datum.ty);
if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
if ty::type_contents(bcx.tcx(), box_ty).owns_managed() {
glue::trans_free(bcx, box_datum.val)
} else {
glue::trans_exchange_free(bcx, box_datum.val)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ impl TypeContents {
!self.intersects(TC::Nonsendable)
}

pub fn contains_managed(&self) -> bool {
pub fn owns_managed(&self) -> bool {
self.intersects(TC::OwnsManaged)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
ty::mk_nil())
}
"needs_drop" => (1u, ~[], ty::mk_bool()),
"contains_managed" => (1u, ~[], ty::mk_bool()),
"owns_managed" => (1u, ~[], ty::mk_bool()),
"atomic_xchg" | "atomic_xadd" | "atomic_xsub" |
"atomic_xchg_acq" | "atomic_xadd_acq" | "atomic_xsub_acq" |
"atomic_xchg_rel" | "atomic_xadd_rel" | "atomic_xsub_rel" => {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/unstable/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,13 @@ extern "rust-intrinsic" {
pub fn needs_drop<T>() -> bool;

/// Returns `true` if a type is managed (will be allocated on the local heap)
#[cfg(stage0)]
pub fn contains_managed<T>() -> bool;

/// Returns `true` if a type is managed (will be allocated on the local heap)
#[cfg(not(stage0))]
pub fn owns_managed<T>() -> bool;

pub fn visit_tydesc(td: *TyDesc, tv: &mut TyVisitor);

/// Get the address of the `__morestack` stack growth function.
Expand Down
29 changes: 21 additions & 8 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,19 @@ use mem::size_of;
use uint;
use unstable::finally::Finally;
use unstable::intrinsics;
use unstable::intrinsics::{get_tydesc, contains_managed};
use unstable::intrinsics::{get_tydesc};
use unstable::raw::{Box, Repr, Slice, Vec};
use vec;
use util;

#[cfg(not(stage0))]
use unstable::intrinsics::owns_managed;

#[cfg(stage0)]
unsafe fn owns_managed<T>() -> bool {
intrinsics::contains_managed::<T>()
}

/**
* Creates and initializes an owned vector.
*
Expand Down Expand Up @@ -180,7 +188,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
#[inline]
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
unsafe {
if contains_managed::<T>() {
if owns_managed::<T>() {
let mut vec = ~[];
vec.reserve(capacity);
vec
Expand Down Expand Up @@ -1401,7 +1409,7 @@ impl<T> OwnedVector<T> for ~[T] {
if self.capacity() < n {
unsafe {
let td = get_tydesc::<T>();
if contains_managed::<T>() {
if owns_managed::<T>() {
let ptr: *mut *mut Box<Vec<()>> = cast::transmute(self);
::at_vec::raw::reserve_raw(td, ptr, n);
} else {
Expand Down Expand Up @@ -1437,7 +1445,7 @@ impl<T> OwnedVector<T> for ~[T] {
#[inline]
fn capacity(&self) -> uint {
unsafe {
if contains_managed::<T>() {
if owns_managed::<T>() {
let repr: **Box<Vec<()>> = cast::transmute(self);
(**repr).data.alloc / mem::nonzero_size_of::<T>()
} else {
Expand All @@ -1460,7 +1468,7 @@ impl<T> OwnedVector<T> for ~[T] {
#[inline]
fn push(&mut self, t: T) {
unsafe {
if contains_managed::<T>() {
if owns_managed::<T>() {
let repr: **Box<Vec<()>> = cast::transmute(&mut *self);
let fill = (**repr).data.fill;
if (**repr).data.alloc <= fill {
Expand All @@ -1482,7 +1490,7 @@ impl<T> OwnedVector<T> for ~[T] {
// This doesn't bother to make sure we have space.
#[inline] // really pretty please
unsafe fn push_fast<T>(this: &mut ~[T], t: T) {
if contains_managed::<T>() {
if owns_managed::<T>() {
let repr: **mut Box<Vec<u8>> = cast::transmute(this);
let fill = (**repr).data.fill;
(**repr).data.fill += mem::nonzero_size_of::<T>();
Expand Down Expand Up @@ -2057,9 +2065,14 @@ pub mod raw {
use mem;
use unstable::intrinsics;
use vec::{with_capacity, ImmutableVector, MutableVector};
use unstable::intrinsics::contains_managed;
use unstable::raw::{Box, Vec, Slice};

#[cfg(not(stage0))]
use unstable::intrinsics::owns_managed;

#[cfg(stage0)]
use vec::owns_managed;

/**
* Sets the length of a vector
*
Expand All @@ -2069,7 +2082,7 @@ pub mod raw {
*/
#[inline]
pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
if contains_managed::<T>() {
if owns_managed::<T>() {
let repr: **mut Box<Vec<()>> = cast::transmute(v);
(**repr).data.fill = new_len * mem::nonzero_size_of::<T>();
} else {
Expand Down

0 comments on commit 3d1f3f4

Please sign in to comment.