Skip to content

Commit 4260126

Browse files
committed
---
yaml --- r: 31048 b: refs/heads/incoming c: e16dbb7 h: refs/heads/master v: v3
1 parent ff1ea39 commit 4260126

File tree

14 files changed

+205
-24
lines changed

14 files changed

+205
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: e3cb70fa8a6f9163352f26ae2614ab4c9a261838
9+
refs/heads/incoming: e16dbb7888504ef5d0de0c14493fc8ecc492ee30
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/at_vec.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ extern mod rustrt {
2121
#[abi = "rust-intrinsic"]
2222
extern mod rusti {
2323
#[legacy_exports];
24+
#[cfg(stage0)]
2425
fn move_val_init<T>(&dst: T, -src: T);
26+
#[cfg(stage1)]
27+
#[cfg(stage2)]
28+
fn move_val_init<T>(dst: &mut T, -src: T);
2529
}
2630

2731
/// Returns the number of elements the vector can hold without reallocating
@@ -176,7 +180,9 @@ pub mod raw {
176180
push_slow(v, move initval);
177181
}
178182
}
183+
179184
// This doesn't bother to make sure we have space.
185+
#[cfg(stage0)]
180186
#[inline(always)] // really pretty please
181187
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
182188
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
@@ -186,6 +192,18 @@ pub mod raw {
186192
let p = ptr::offset(p, fill) as *mut T;
187193
rusti::move_val_init(*p, move initval);
188194
}
195+
// This doesn't bother to make sure we have space.
196+
#[cfg(stage1)]
197+
#[cfg(stage2)]
198+
#[inline(always)] // really pretty please
199+
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
200+
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
201+
let fill = (**repr).unboxed.fill;
202+
(**repr).unboxed.fill += sys::size_of::<T>();
203+
let p = addr_of(&((**repr).unboxed.data));
204+
let p = ptr::offset(p, fill) as *mut T;
205+
rusti::move_val_init(&mut(*p), move initval);
206+
}
189207

190208
pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
191209
reserve_at_least(v, v.len() + 1u);

branches/incoming/src/libcore/vec.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ extern mod rustrt {
1818

1919
#[abi = "rust-intrinsic"]
2020
extern mod rusti {
21+
#[cfg(stage0)]
2122
fn move_val_init<T>(&dst: T, -src: T);
23+
#[cfg(stage1)]
24+
#[cfg(stage2)]
25+
fn move_val_init<T>(dst: &mut T, -src: T);
2226
}
2327

28+
2429
/// Returns true if a vector contains no elements
2530
pub pure fn is_empty<T>(v: &[const T]) -> bool {
2631
as_const_buf(v, |_p, len| len == 0u)
@@ -98,6 +103,7 @@ pub pure fn len<T>(v: &[const T]) -> uint {
98103
* Creates an immutable vector of size `n_elts` and initializes the elements
99104
* to the value returned by the function `op`.
100105
*/
106+
#[cfg(stage0)]
101107
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
102108
unsafe {
103109
let mut v = with_capacity(n_elts);
@@ -112,6 +118,22 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
112118
return move v;
113119
}
114120
}
121+
#[cfg(stage1)]
122+
#[cfg(stage2)]
123+
pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
124+
unsafe {
125+
let mut v = with_capacity(n_elts);
126+
do as_mut_buf(v) |p, _len| {
127+
let mut i: uint = 0u;
128+
while i < n_elts {
129+
rusti::move_val_init(&mut(*ptr::mut_offset(p, i)), op(i));
130+
i += 1u;
131+
}
132+
}
133+
raw::set_len(&mut v, n_elts);
134+
return move v;
135+
}
136+
}
115137

116138
/**
117139
* Creates and initializes an immutable vector.
@@ -481,6 +503,7 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
481503
}
482504
}
483505

506+
#[cfg(stage0)]
484507
// This doesn't bother to make sure we have space.
485508
#[inline(always)] // really pretty please
486509
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
@@ -491,6 +514,18 @@ unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
491514
let p = ptr::offset(p, fill) as *mut T;
492515
rusti::move_val_init(*p, move initval);
493516
}
517+
#[cfg(stage1)]
518+
#[cfg(stage2)]
519+
// This doesn't bother to make sure we have space.
520+
#[inline(always)] // really pretty please
521+
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
522+
let repr: **raw::VecRepr = ::cast::transmute(v);
523+
let fill = (**repr).unboxed.fill;
524+
(**repr).unboxed.fill += sys::size_of::<T>();
525+
let p = addr_of(&((**repr).unboxed.data));
526+
let p = ptr::offset(p, fill) as *mut T;
527+
rusti::move_val_init(&mut(*p), move initval);
528+
}
494529

495530
#[inline(never)]
496531
fn push_slow<T>(v: &mut ~[T], initval: T) {
@@ -1758,6 +1793,18 @@ pub mod raw {
17581793
as_const_buf(v, |p, _len| *ptr::const_offset(p, i))
17591794
}
17601795

1796+
#[cfg(stage0)]
1797+
#[inline(always)]
1798+
pub unsafe fn init_elem<T>(v: &[mut T], i: uint, val: T) {
1799+
let mut box = Some(move val);
1800+
do as_mut_buf(v) |p, _len| {
1801+
let mut box2 = None;
1802+
box2 <-> box;
1803+
rusti::move_val_init(*ptr::mut_offset(p, i),
1804+
option::unwrap(move box2));
1805+
}
1806+
}
1807+
#[cfg(stage1)]
17611808
/**
17621809
* Unchecked vector index assignment. Does not drop the
17631810
* old value and hence is only suitable when the vector
@@ -1769,7 +1816,7 @@ pub mod raw {
17691816
do as_mut_buf(v) |p, _len| {
17701817
let mut box2 = None;
17711818
box2 <-> box;
1772-
rusti::move_val_init(*ptr::mut_offset(p, i),
1819+
rusti::move_val_init(&mut(*ptr::mut_offset(p, i)),
17731820
option::unwrap(move box2));
17741821
}
17751822
}

branches/incoming/src/libstd/arena.rs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ use libc::size_t;
3131

3232
#[abi = "rust-intrinsic"]
3333
extern mod rusti {
34+
#[cfg(stage0)]
3435
fn move_val_init<T>(&dst: T, -src: T);
36+
#[cfg(stage1)]
37+
#[cfg(stage2)]
38+
fn move_val_init<T>(dst: &mut T, -src: T);
3539
fn needs_drop<T>() -> bool;
3640
}
41+
3742
extern mod rustrt {
3843
#[rust_stack]
3944
fn rust_call_tydesc_glue(root: *u8, tydesc: *TypeDesc, field: size_t);
@@ -127,6 +132,8 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
127132
(reinterpret_cast(&(p & !1)), p & 1 == 1)
128133
}
129134

135+
// tjc: Can get rid of the duplication post-snapshot
136+
#[cfg(stage0)]
130137
// The duplication between the POD and non-POD functions is annoying.
131138
impl &Arena {
132139
// Functions for the POD part of the arena
@@ -234,6 +241,114 @@ impl &Arena {
234241
} else { self.alloc_nonpod(op) }
235242
}
236243
}
244+
#[cfg(stage1)]
245+
#[cfg(stage2)]
246+
impl &Arena {
247+
// Functions for the POD part of the arena
248+
fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 {
249+
// Allocate a new chunk.
250+
let chunk_size = at_vec::capacity(self.pod_head.data);
251+
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
252+
self.chunks = @Cons(copy self.pod_head, self.chunks);
253+
self.pod_head =
254+
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
255+
256+
return self.alloc_pod_inner(n_bytes, align);
257+
}
258+
259+
#[inline(always)]
260+
fn alloc_pod_inner(n_bytes: uint, align: uint) -> *u8 {
261+
let head = &mut self.pod_head;
262+
263+
let start = round_up_to(head.fill, align);
264+
let end = start + n_bytes;
265+
if end > at_vec::capacity(head.data) {
266+
return self.alloc_pod_grow(n_bytes, align);
267+
}
268+
head.fill = end;
269+
270+
//debug!("idx = %u, size = %u, align = %u, fill = %u",
271+
// start, n_bytes, align, head.fill);
272+
273+
unsafe {
274+
ptr::offset(vec::raw::to_ptr(head.data), start)
275+
}
276+
}
277+
278+
#[inline(always)]
279+
fn alloc_pod<T>(op: fn() -> T) -> &self/T {
280+
unsafe {
281+
let tydesc = sys::get_type_desc::<T>();
282+
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
283+
let ptr: *mut T = reinterpret_cast(&ptr);
284+
rusti::move_val_init(&mut (*ptr), op());
285+
return reinterpret_cast(&ptr);
286+
}
287+
}
288+
289+
// Functions for the non-POD part of the arena
290+
fn alloc_nonpod_grow(n_bytes: uint, align: uint) -> (*u8, *u8) {
291+
// Allocate a new chunk.
292+
let chunk_size = at_vec::capacity(self.head.data);
293+
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
294+
self.chunks = @Cons(copy self.head, self.chunks);
295+
self.head =
296+
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
297+
298+
return self.alloc_nonpod_inner(n_bytes, align);
299+
}
300+
301+
#[inline(always)]
302+
fn alloc_nonpod_inner(n_bytes: uint, align: uint) -> (*u8, *u8) {
303+
let head = &mut self.head;
304+
305+
let tydesc_start = head.fill;
306+
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
307+
let start = round_up_to(after_tydesc, align);
308+
let end = start + n_bytes;
309+
if end > at_vec::capacity(head.data) {
310+
return self.alloc_nonpod_grow(n_bytes, align);
311+
}
312+
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
313+
314+
//debug!("idx = %u, size = %u, align = %u, fill = %u",
315+
// start, n_bytes, align, head.fill);
316+
317+
unsafe {
318+
let buf = vec::raw::to_ptr(head.data);
319+
return (ptr::offset(buf, tydesc_start), ptr::offset(buf, start));
320+
}
321+
}
322+
323+
#[inline(always)]
324+
fn alloc_nonpod<T>(op: fn() -> T) -> &self/T {
325+
unsafe {
326+
let tydesc = sys::get_type_desc::<T>();
327+
let (ty_ptr, ptr) =
328+
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
329+
let ty_ptr: *mut uint = reinterpret_cast(&ty_ptr);
330+
let ptr: *mut T = reinterpret_cast(&ptr);
331+
// Write in our tydesc along with a bit indicating that it
332+
// has *not* been initialized yet.
333+
*ty_ptr = reinterpret_cast(&tydesc);
334+
// Actually initialize it
335+
rusti::move_val_init(&mut(*ptr), op());
336+
// Now that we are done, update the tydesc to indicate that
337+
// the object is there.
338+
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
339+
340+
return reinterpret_cast(&ptr);
341+
}
342+
}
343+
344+
// The external interface
345+
#[inline(always)]
346+
fn alloc<T>(op: fn() -> T) -> &self/T {
347+
if !rusti::needs_drop::<T>() {
348+
self.alloc_pod(op)
349+
} else { self.alloc_nonpod(op) }
350+
}
351+
}
237352

238353
#[test]
239354
fn test_arena_destructors() {

branches/incoming/src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ impl parser {
570570

571571
fn parse_arg_mode() -> mode {
572572
if self.eat(token::BINOP(token::AND)) {
573+
self.warn(~"Obsolete syntax has no effect");
573574
expl(by_mutbl_ref)
574575
} else if self.eat(token::BINOP(token::MINUS)) {
575576
expl(by_move)

branches/incoming/src/rustc/middle/typeck/check.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
26012601
~"addr_of" => (1u, ~[arg(ast::by_ref, param(ccx, 0u))],
26022602
ty::mk_imm_ptr(tcx, param(ccx, 0u))),
26032603
~"move_val" | ~"move_val_init" => {
2604-
(1u, ~[arg(ast::by_mutbl_ref, param(ccx, 0u)),
2604+
(1u, ~[arg(ast::by_copy,
2605+
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)),
2606+
param(ccx, 0u))),
26052607
arg(ast::by_move, param(ccx, 0u))],
26062608
ty::mk_nil(tcx))
26072609
}

branches/incoming/src/test/compile-fail/borrowck-lend-args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ fn borrow_from_arg_imm_ref(&&v: ~int) {
44
borrow(v);
55
}
66

7-
fn borrow_from_arg_mut_ref(&v: ~int) {
8-
borrow(v); //~ ERROR illegal borrow unless pure
7+
fn borrow_from_arg_mut_ref(v: &mut ~int) {
8+
borrow(*v); //~ ERROR illegal borrow unless pure
99
//~^ NOTE impure due to access to impure function
1010
}
1111

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#[forbid(deprecated_mode)];
22

33
fn foo(_f: fn(&i: int)) { //~ ERROR explicit mode
4+
//~^ WARNING Obsolete syntax has no effect
45
}
56

67
type Bar = fn(&i: int); //~ ERROR explicit mode
8+
//~^ WARNING Obsolete syntax has no effect
79

810
fn main() {
911
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
extern mod std;
22
use cmp::Eq;
33

4-
fn f<T:Eq>(&o: Option<T>) {
5-
assert o == option::None;
4+
fn f<T:Eq>(o: &mut Option<T>) {
5+
assert *o == option::None;
66
}
77

88
fn main() {
9-
f::<int>(option::None);
9+
f::<int>(&mut option::None);
1010
//~^ ERROR illegal borrow: creating mutable alias to static item
1111
}

branches/incoming/src/test/compile-fail/liveness-dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
fn f1(&x: int) {
2-
x = 1; // no error
1+
fn f1(x: &mut int) {
2+
*x = 1; // no error
33
}
44

55
fn f2() {

branches/incoming/src/test/compile-fail/liveness-move-from-args.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ fn from_by_value_arg(++x: int) {
44
take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode
55
}
66

7-
fn from_by_mut_ref_arg(&x: int) {
8-
take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode
9-
}
10-
117
fn from_by_ref_arg(&&x: int) {
128
take(x); //~ ERROR illegal move from argument `x`, which is not copy or move mode
139
}

branches/incoming/src/test/compile-fail/liveness-unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn f1(x: int) {
22
//~^ WARNING unused variable: `x`
33
}
44

5-
fn f1b(&x: int) {
5+
fn f1b(x: &mut int) {
66
//~^ WARNING unused variable: `x`
77
}
88

0 commit comments

Comments
 (0)