Skip to content

assorted cleanup/fixes #7842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,6 @@ pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
let ccx = bcx.ccx();
let tcx = ccx.tcx;

fn nuke_ref_count(bcx: block, llbox: ValueRef) {
let _icx = push_ctxt("closure::nuke_ref_count");
// Initialize ref count to arbitrary value for debugging:
let ccx = bcx.ccx();
let llbox = PointerCast(bcx, llbox, Type::opaque_box(ccx).ptr_to());
let ref_cnt = GEPi(bcx, llbox, [0u, abi::box_field_refcnt]);
let rc = C_int(ccx, 0x12345678);
Store(bcx, rc, ref_cnt);
}

// Allocate and initialize the box:
match sigil {
ast::ManagedSigil => {
Expand All @@ -195,7 +185,6 @@ pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
ast::BorrowedSigil => {
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
let llbox = alloc_ty(bcx, cbox_ty, "__closure");
nuke_ref_count(bcx, llbox);
rslt(bcx, llbox)
}
}
Expand Down
34 changes: 6 additions & 28 deletions src/libstd/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ pub fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
#[inline]
#[cfg(target_word_size = "32")]
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
use unstable::intrinsics::memmove32;
memmove32(dst, src as *T, count as u32);
intrinsics::memmove32(dst, src as *T, count as u32);
}

/**
Expand All @@ -93,8 +92,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
#[inline]
#[cfg(target_word_size = "64")]
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
use unstable::intrinsics::memmove64;
memmove64(dst, src as *T, count as u64);
intrinsics::memmove64(dst, src as *T, count as u64);
}

/**
Expand All @@ -106,8 +104,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
#[inline]
#[cfg(target_word_size = "32")]
pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
use unstable::intrinsics::memcpy32;
memcpy32(dst, src as *T, count as u32);
intrinsics::memcpy32(dst, src as *T, count as u32);
}

/**
Expand All @@ -119,8 +116,7 @@ pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: u
#[inline]
#[cfg(target_word_size = "64")]
pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
use unstable::intrinsics::memcpy64;
memcpy64(dst, src as *T, count as u64);
intrinsics::memcpy64(dst, src as *T, count as u64);
}

/**
Expand All @@ -130,8 +126,7 @@ pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: u
#[inline]
#[cfg(target_word_size = "32")]
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
use unstable::intrinsics::memset32;
memset32(dst, c, count as u32);
intrinsics::memset32(dst, c, count as u32);
}

/**
Expand All @@ -141,34 +136,17 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
#[inline]
#[cfg(target_word_size = "64")]
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
use unstable::intrinsics::memset64;
memset64(dst, c, count as u64);
intrinsics::memset64(dst, c, count as u64);
}

/**
* Zeroes out `count * size_of::<T>` bytes of memory at `dst`
*/
#[inline]
#[cfg(not(stage0))]
pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
set_memory(dst, 0, count);
}

/**
* Zeroes out `count * size_of::<T>` bytes of memory at `dst`
*/
#[inline]
#[cfg(stage0)]
pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
let mut count = count * sys::size_of::<T>();
let mut dst = dst as *mut u8;
while count > 0 {
*dst = 0;
dst = mut_offset(dst, 1);
count -= 1;
}
}

/**
* Swap the values at two mutable locations of the same type, without
* deinitialising or copying either one.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}

#[cfg(stage0)]
fn visit_str(&self) -> bool {
self.align_to::<~str>();
if ! self.inner.visit_str() { return false; }
Expand Down
25 changes: 17 additions & 8 deletions src/libstd/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl ReprVisitor {
}

pub fn write_vec_range(&self,
mtbl: uint,
_mtbl: uint,
ptr: *u8,
len: uint,
inner: *TyDesc)
Expand All @@ -218,7 +218,6 @@ impl ReprVisitor {
} else {
self.writer.write_str(", ");
}
self.write_mut_qualifier(mtbl);
self.visit_ptr_inner(p as *c_void, inner);
p = align(ptr::offset(p, sz) as uint, al) as *u8;
left -= dec;
Expand Down Expand Up @@ -269,6 +268,7 @@ impl TyVisitor for ReprVisitor {
}

// Type no longer exists, vestigial function.
#[cfg(stage0)]
fn visit_str(&self) -> bool { fail!(); }

fn visit_estr_box(&self) -> bool {
Expand Down Expand Up @@ -302,18 +302,16 @@ impl TyVisitor for ReprVisitor {
}
}

fn visit_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
fn visit_uniq(&self, _mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
self.write_mut_qualifier(mtbl);
do self.get::<*c_void> |b| {
self.visit_ptr_inner(*b, inner);
}
}

#[cfg(not(stage0))]
fn visit_uniq_managed(&self, mtbl: uint, inner: *TyDesc) -> bool {
fn visit_uniq_managed(&self, _mtbl: uint, inner: *TyDesc) -> bool {
self.writer.write_char('~');
self.write_mut_qualifier(mtbl);
do self.get::<&managed::raw::BoxRepr> |b| {
let p = ptr::to_unsafe_ptr(&b.data) as *c_void;
self.visit_ptr_inner(p, inner);
Expand Down Expand Up @@ -348,10 +346,20 @@ impl TyVisitor for ReprVisitor {
fn visit_evec_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&VecRepr> |b| {
self.writer.write_char('@');
self.write_mut_qualifier(mtbl);
self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner);
}
}

#[cfg(stage0)]
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&VecRepr> |b| {
self.writer.write_char('~');
self.write_unboxed_vec_repr(mtbl, &b.unboxed, inner);
}
}

#[cfg(not(stage0))]
fn visit_evec_uniq(&self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<&UnboxedVecRepr> |b| {
self.writer.write_char('~');
Expand Down Expand Up @@ -613,13 +621,14 @@ fn test_repr() {
exact_test(&(@"hello"), "@\"hello\"");
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");

// FIXME #4210: the mut fields are a bit off here.
exact_test(&(@10), "@10");
exact_test(&(@mut 10), "@10");
exact_test(&(@mut 10), "@10"); // FIXME: #4210: incorrect
exact_test(&((@mut 10, 2)), "(@mut 10, 2)");
exact_test(&(~10), "~10");
exact_test(&(&10), "&10");
let mut x = 10;
exact_test(&(&mut x), "&mut 10");
exact_test(&(@mut [1, 2]), "@mut [1, 2]");

exact_test(&(1,), "(1,)");
exact_test(&(@[1,2,3,4,5,6,7,8]),
Expand Down
1 change: 0 additions & 1 deletion src/libstd/unstable/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub trait TyVisitor {
fn visit_f64(&self) -> bool;

fn visit_char(&self) -> bool;
fn visit_str(&self) -> bool;

fn visit_estr_box(&self) -> bool;
fn visit_estr_uniq(&self) -> bool;
Expand Down
8 changes: 0 additions & 8 deletions src/test/run-pass/reflect-visit-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}

fn visit_str(&self) -> bool {
self.align_to::<~str>();
if ! self.inner.visit_str() { return false; }
self.bump_past::<~str>();
true
}

fn visit_estr_box(&self) -> bool {
self.align_to::<@str>();
if ! self.inner.visit_estr_box() { return false; }
Expand Down Expand Up @@ -556,7 +549,6 @@ impl TyVisitor for my_visitor {
fn visit_f64(&self) -> bool { true }

fn visit_char(&self) -> bool { true }
fn visit_str(&self) -> bool { true }

fn visit_estr_box(&self) -> bool { true }
fn visit_estr_uniq(&self) -> bool { true }
Expand Down
1 change: 0 additions & 1 deletion src/test/run-pass/reflect-visit-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl TyVisitor for MyVisitor {
fn visit_f64(&self) -> bool { true }

fn visit_char(&self) -> bool { true }
fn visit_str(&self) -> bool { true }

fn visit_estr_box(&self) -> bool { true }
fn visit_estr_uniq(&self) -> bool { true }
Expand Down