Skip to content

Commit 6d48456

Browse files
committed
auto merge of #6372 : brson/rust/intrinsics, r=catamorphism
...s
2 parents 54eafc0 + 7bd4217 commit 6d48456

File tree

6 files changed

+25
-54
lines changed

6 files changed

+25
-54
lines changed

src/libcore/cast.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,17 @@
1212
1313
use sys;
1414
use unstable;
15-
16-
pub mod rusti {
17-
#[abi = "rust-intrinsic"]
18-
#[link_name = "rusti"]
19-
pub extern "rust-intrinsic" {
20-
fn forget<T>(x: T);
21-
22-
fn transmute<T,U>(e: T) -> U;
23-
}
24-
}
15+
use unstable::intrinsics;
2516

2617
/// Casts the value at `src` to U. The two types must have the same length.
2718
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
28-
let mut dest: U = unstable::intrinsics::init();
19+
let mut dest: U = intrinsics::init();
2920
{
30-
let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
31-
let src_ptr: *u8 = rusti::transmute(src);
32-
unstable::intrinsics::memmove64(dest_ptr,
33-
src_ptr,
34-
sys::size_of::<U>() as u64);
21+
let dest_ptr: *mut u8 = transmute(&mut dest);
22+
let src_ptr: *u8 = transmute(src);
23+
intrinsics::memmove64(dest_ptr,
24+
src_ptr,
25+
sys::size_of::<U>() as u64);
3526
}
3627
dest
3728
}
@@ -45,7 +36,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
4536
* reinterpret_cast on pointer types.
4637
*/
4738
#[inline(always)]
48-
pub unsafe fn forget<T>(thing: T) { rusti::forget(thing); }
39+
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
4940

5041
/**
5142
* Force-increment the reference count on a shared box. If used
@@ -65,7 +56,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
6556
*/
6657
#[inline(always)]
6758
pub unsafe fn transmute<L, G>(thing: L) -> G {
68-
rusti::transmute(thing)
59+
intrinsics::transmute(thing)
6960
}
7061

7162
/// Coerce an immutable reference to be mutable.

src/libcore/stackwalk.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#[doc(hidden)]; // FIXME #3538
1212

1313
use cast::transmute;
14+
use unstable::intrinsics;
1415

1516
pub type Word = uint;
1617

@@ -75,13 +76,6 @@ fn test_simple_deep() {
7576

7677
fn frame_address(f: &fn(x: *u8)) {
7778
unsafe {
78-
rusti::frame_address(f)
79-
}
80-
}
81-
82-
pub mod rusti {
83-
#[abi = "rust-intrinsic"]
84-
pub extern "rust-intrinsic" {
85-
pub fn frame_address(f: &once fn(x: *u8));
79+
intrinsics::frame_address(f)
8680
}
8781
}

src/libcore/sys.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use libc;
1919
use libc::{c_void, c_char, size_t};
2020
use repr;
2121
use str;
22+
use unstable::intrinsics;
2223

2324
pub type FreeGlue<'self> = &'self fn(*TypeDesc, *c_void);
2425

@@ -38,16 +39,6 @@ pub struct Closure {
3839
env: *(),
3940
}
4041

41-
pub mod rusti {
42-
#[abi = "rust-intrinsic"]
43-
pub extern "rust-intrinsic" {
44-
fn get_tydesc<T>() -> *();
45-
fn size_of<T>() -> uint;
46-
fn pref_align_of<T>() -> uint;
47-
fn min_align_of<T>() -> uint;
48-
}
49-
}
50-
5142
pub mod rustrt {
5243
use libc::{c_char, size_t};
5344

@@ -81,7 +72,7 @@ pub fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
8172
*/
8273
#[inline(always)]
8374
pub fn get_type_desc<T>() -> *TypeDesc {
84-
unsafe { rusti::get_tydesc::<T>() as *TypeDesc }
75+
unsafe { intrinsics::get_tydesc::<T>() as *TypeDesc }
8576
}
8677

8778
/// Returns a pointer to a type descriptor.
@@ -93,7 +84,7 @@ pub fn get_type_desc_val<T>(_val: &T) -> *TypeDesc {
9384
/// Returns the size of a type
9485
#[inline(always)]
9586
pub fn size_of<T>() -> uint {
96-
unsafe { rusti::size_of::<T>() }
87+
unsafe { intrinsics::size_of::<T>() }
9788
}
9889

9990
/// Returns the size of the type that `_val` points to
@@ -128,7 +119,7 @@ pub fn nonzero_size_of_val<T>(_val: &T) -> uint {
128119
*/
129120
#[inline(always)]
130121
pub fn min_align_of<T>() -> uint {
131-
unsafe { rusti::min_align_of::<T>() }
122+
unsafe { intrinsics::min_align_of::<T>() }
132123
}
133124

134125
/// Returns the ABI-required minimum alignment of the type of the value that
@@ -141,7 +132,7 @@ pub fn min_align_of_val<T>(_val: &T) -> uint {
141132
/// Returns the preferred alignment of a type
142133
#[inline(always)]
143134
pub fn pref_align_of<T>() -> uint {
144-
unsafe { rusti::pref_align_of::<T>() }
135+
unsafe { intrinsics::pref_align_of::<T>() }
145136
}
146137

147138
/// Returns the preferred alignment of the type of the value that

src/libcore/unstable/intrinsics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,16 @@ pub extern "rust-intrinsic" {
114114
/// `forget` is unsafe because the caller is responsible for
115115
/// ensuring the argument is deallocated already.
116116
pub unsafe fn forget<T>(_: T) -> ();
117+
pub fn transmute<T,U>(e: T) -> U;
117118

118119
/// Returns `true` if a type requires drop glue.
119120
pub fn needs_drop<T>() -> bool;
120121

121122
// XXX: intrinsic uses legacy modes and has reference to TyDesc
122123
// and TyVisitor which are in librustc
123124
//fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor) -> ();
124-
// XXX: intrinsic uses legacy modes
125-
//fn frame_address(f: &once fn(*u8));
125+
126+
pub fn frame_address(f: &once fn(*u8));
126127

127128
/// Get the address of the `__morestack` stack growth function.
128129
pub fn morestack_addr() -> *();

src/libstd/arena.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,7 @@ use core::sys::TypeDesc;
4343
use core::sys;
4444
use core::uint;
4545
use core::vec;
46-
47-
pub mod rusti {
48-
#[abi = "rust-intrinsic"]
49-
pub extern "rust-intrinsic" {
50-
fn move_val_init<T>(dst: &mut T, src: T);
51-
fn needs_drop<T>() -> bool;
52-
}
53-
}
46+
use core::unstable::intrinsics;
5447

5548
pub mod rustrt {
5649
use core::libc::size_t;
@@ -208,7 +201,7 @@ pub impl Arena {
208201
let tydesc = sys::get_type_desc::<T>();
209202
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
210203
let ptr: *mut T = transmute(ptr);
211-
rusti::move_val_init(&mut (*ptr), op());
204+
intrinsics::move_val_init(&mut (*ptr), op());
212205
return transmute(ptr);
213206
}
214207
}
@@ -261,7 +254,7 @@ pub impl Arena {
261254
// has *not* been initialized yet.
262255
*ty_ptr = transmute(tydesc);
263256
// Actually initialize it
264-
rusti::move_val_init(&mut(*ptr), op());
257+
intrinsics::move_val_init(&mut(*ptr), op());
265258
// Now that we are done, update the tydesc to indicate that
266259
// the object is there.
267260
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
@@ -276,7 +269,7 @@ pub impl Arena {
276269
unsafe {
277270
// XXX: Borrow check
278271
let this = transmute_mut_region(self);
279-
if !rusti::needs_drop::<T>() {
272+
if !intrinsics::needs_drop::<T>() {
280273
return this.alloc_pod(op);
281274
}
282275
// XXX: Borrow check

src/libstd/priority_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
//! A priority queue implemented with a binary heap
1212
1313
use core::old_iter::BaseIter;
14+
use core::unstable::intrinsics::{move_val_init, init};
15+
use core::unstable::intrinsics::uninit;
1416
use core::util::{replace, swap};
15-
use core::unstable::intrinsics::{init, move_val_init};
1617

1718
pub struct PriorityQueue<T> {
1819
priv data: ~[T],

0 commit comments

Comments
 (0)