Skip to content

Commit 851649d

Browse files
committed
---
yaml --- r: 141006 b: refs/heads/try2 c: 0d1331f h: refs/heads/master v: v3
1 parent 8c725a6 commit 851649d

File tree

122 files changed

+1043
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1043
-885
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d951da82768685cacba7444dae10ede2a71efedb
8+
refs/heads/try2: 0d1331f4a0cade66349a4c22315899210ad9b6a7
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*.diff
4040
*.rej
4141
*.swp
42+
*.swo
4243
*.tmp
4344
*.pyc
4445
*.elc

branches/try2/.swo

72 KB
Binary file not shown.

branches/try2/doc/tutorial-borrowed-ptr.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ point, but allocated in a different place:
4242
~~~
4343
# struct Point {x: float, y: float}
4444
let on_the_stack : Point = Point {x: 3.0, y: 4.0};
45-
let shared_box : @Point = @Point {x: 5.0, y: 1.0};
46-
let unique_box : ~Point = ~Point {x: 7.0, y: 9.0};
45+
let managed_box : @Point = @Point {x: 5.0, y: 1.0};
46+
let owned_box : ~Point = ~Point {x: 7.0, y: 9.0};
4747
~~~
4848

4949
Suppose we wanted to write a procedure that computed the distance between any
5050
two points, no matter where they were stored. For example, we might like to
51-
compute the distance between `on_the_stack` and `shared_box`, or between
52-
`shared_box` and `unique_box`. One option is to define a function that takes
51+
compute the distance between `on_the_stack` and `managed_box`, or between
52+
`managed_box` and `owned_box`. One option is to define a function that takes
5353
two arguments of type `Point`—that is, it takes the points by value. But if we
5454
define it this way, calling the function will cause the points to be
5555
copied. For points, this is probably not so bad, but often copies are
@@ -73,11 +73,11 @@ Now we can call `compute_distance()` in various ways:
7373
~~~
7474
# struct Point {x: float, y: float}
7575
# let on_the_stack : Point = Point{x: 3.0, y: 4.0};
76-
# let shared_box : @Point = @Point{x: 5.0, y: 1.0};
77-
# let unique_box : ~Point = ~Point{x: 7.0, y: 9.0};
76+
# let managed_box : @Point = @Point{x: 5.0, y: 1.0};
77+
# let owned_box : ~Point = ~Point{x: 7.0, y: 9.0};
7878
# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f }
79-
compute_distance(&on_the_stack, shared_box);
80-
compute_distance(shared_box, unique_box);
79+
compute_distance(&on_the_stack, managed_box);
80+
compute_distance(managed_box, owned_box);
8181
~~~
8282

8383
Here, the `&` operator takes the address of the variable
@@ -87,11 +87,11 @@ value. We also call this _borrowing_ the local variable
8787
`on_the_stack`, because we have created an alias: that is, another
8888
name for the same data.
8989

90-
In contrast, we can pass the boxes `shared_box` and `unique_box` to
90+
In contrast, we can pass the boxes `managed_box` and `owned_box` to
9191
`compute_distance` directly. The compiler automatically converts a box like
9292
`@Point` or `~Point` to a borrowed pointer like `&Point`. This is another form
93-
of borrowing: in this case, the caller lends the contents of the shared or
94-
unique box to the callee.
93+
of borrowing: in this case, the caller lends the contents of the managed or
94+
owned box to the callee.
9595

9696
Whenever a caller lends data to a callee, there are some limitations on what
9797
the caller can do with the original. For example, if the contents of a
@@ -155,7 +155,7 @@ let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f},
155155
size: Size {w: 3f, h: 4f}};
156156
let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f},
157157
size: Size {w: 3f, h: 4f}};
158-
let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f},
158+
let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f},
159159
size: Size {w: 3f, h: 4f}};
160160
~~~
161161

@@ -168,7 +168,7 @@ operator. For example, I could write:
168168
# struct Rectangle {origin: Point, size: Size}
169169
# let rect_stack = &Rectangle {origin: Point {x: 1f, y: 2f}, size: Size {w: 3f, h: 4f}};
170170
# let rect_managed = @Rectangle {origin: Point {x: 3f, y: 4f}, size: Size {w: 3f, h: 4f}};
171-
# let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
171+
# let rect_owned = ~Rectangle {origin: Point {x: 5f, y: 6f}, size: Size {w: 3f, h: 4f}};
172172
# fn compute_distance(p1: &Point, p2: &Point) -> float { 0f }
173173
compute_distance(&rect_stack.origin, &rect_managed.origin);
174174
~~~
@@ -179,7 +179,7 @@ as well as from the managed box, and then compute the distance between them.
179179
# Borrowing managed boxes and rooting
180180

181181
We’ve seen a few examples so far of borrowing heap boxes, both managed
182-
and unique. Up till this point, we’ve glossed over issues of
182+
and owned. Up till this point, we’ve glossed over issues of
183183
safety. As stated in the introduction, at runtime a borrowed pointer
184184
is simply a pointer, nothing more. Therefore, avoiding C's problems
185185
with dangling pointers requires a compile-time safety check.
@@ -258,18 +258,18 @@ fn example2() {
258258
Now if `x` is reassigned, the pointer `y` will still remain valid. This
259259
process is called *rooting*.
260260

261-
# Borrowing unique boxes
261+
# Borrowing owned boxes
262262

263263
The previous example demonstrated *rooting*, the process by which the
264264
compiler ensures that managed boxes remain live for the duration of a
265-
borrow. Unfortunately, rooting does not work for borrows of unique
266-
boxes, because it is not possible to have two references to a unique
265+
borrow. Unfortunately, rooting does not work for borrows of owned
266+
boxes, because it is not possible to have two references to a owned
267267
box.
268268

269-
For unique boxes, therefore, the compiler will only allow a borrow *if
270-
the compiler can guarantee that the unique box will not be reassigned
269+
For owned boxes, therefore, the compiler will only allow a borrow *if
270+
the compiler can guarantee that the owned box will not be reassigned
271271
or moved for the lifetime of the pointer*. This does not necessarily
272-
mean that the unique box is stored in immutable memory. For example,
272+
mean that the owned box is stored in immutable memory. For example,
273273
the following function is legal:
274274

275275
~~~
@@ -294,7 +294,7 @@ and `x` is declared as mutable. However, the compiler can prove that
294294
and in fact is mutated later in the function.
295295

296296
It may not be clear why we are so concerned about mutating a borrowed
297-
variable. The reason is that the runtime system frees any unique box
297+
variable. The reason is that the runtime system frees any owned box
298298
_as soon as its owning reference changes or goes out of
299299
scope_. Therefore, a program like this is illegal (and would be
300300
rejected by the compiler):
@@ -342,7 +342,7 @@ which has been freed.
342342

343343
In fact, the compiler can apply the same kind of reasoning to any
344344
memory that is _(uniquely) owned by the stack frame_. So we could
345-
modify the previous example to introduce additional unique pointers
345+
modify the previous example to introduce additional owned pointers
346346
and structs, and the compiler will still be able to detect possible
347347
mutations:
348348

@@ -366,7 +366,7 @@ invalidate the pointer `y`.
366366
# Borrowing and enums
367367

368368
The previous example showed that the type system forbids any borrowing
369-
of unique boxes found in aliasable, mutable memory. This restriction
369+
of owned boxes found in aliasable, mutable memory. This restriction
370370
prevents pointers from pointing into freed memory. There is one other
371371
case where the compiler must be very careful to ensure that pointers
372372
remain valid: pointers into the interior of an `enum`.
@@ -462,14 +462,14 @@ of a `float` as if it were a struct with two fields would be a memory
462462
safety violation.
463463

464464
So, in fact, for every `ref` binding, the compiler will impose the
465-
same rules as the ones we saw for borrowing the interior of a unique
465+
same rules as the ones we saw for borrowing the interior of a owned
466466
box: it must be able to guarantee that the `enum` will not be
467467
overwritten for the duration of the borrow. In fact, the compiler
468468
would accept the example we gave earlier. The example is safe because
469469
the shape pointer has type `&Shape`, which means "borrowed pointer to
470470
immutable memory containing a `shape`". If, however, the type of that
471471
pointer were `&mut Shape`, then the ref binding would be ill-typed.
472-
Just as with unique boxes, the compiler will permit `ref` bindings
472+
Just as with owned boxes, the compiler will permit `ref` bindings
473473
into data owned by the stack frame even if the data are mutable,
474474
but otherwise it requires that the data reside in immutable memory.
475475

@@ -550,7 +550,7 @@ guarantees; in fact, it cannot guarantee that the pointer will remain
550550
valid at all once it returns, as the parameter `p` may or may not be
551551
live in the caller. Therefore, the compiler will report an error here.
552552

553-
In general, if you borrow a managed (or unique) box to create a
553+
In general, if you borrow a managed (or owned) box to create a
554554
borrowed pointer, the pointer will only be valid within the function
555555
and cannot be returned. This is why the typical way to return borrowed
556556
pointers is to take borrowed pointers as input (the only other case in

branches/try2/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ to a borrowed pointer.
17791779
# fn draw_value(self) { ... }
17801780
# }
17811781
# let s = Circle(Point { x: 1f, y: 2f }, 3f);
1782-
// As with typical function arguments, managed and unique pointers
1782+
// As with typical function arguments, managed and owned pointers
17831783
// are automatically converted to borrowed pointers
17841784
17851785
(@s).draw_borrowed();

branches/try2/src/compiletest/runtest.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
264264
fatal(~"gdb failed to execute");
265265
}
266266

267-
let num_check_lines = vec::len(check_lines);
267+
let num_check_lines = check_lines.len();
268268
if num_check_lines > 0 {
269269
// check if each line in props.check_lines appears in the
270270
// output (in order)
@@ -303,7 +303,7 @@ fn check_error_patterns(props: &TestProps,
303303
if str::contains(line, *next_err_pat) {
304304
debug!("found error pattern %s", *next_err_pat);
305305
next_err_idx += 1u;
306-
if next_err_idx == vec::len(props.error_patterns) {
306+
if next_err_idx == props.error_patterns.len() {
307307
debug!("found all error patterns");
308308
done = true;
309309
break;
@@ -315,8 +315,8 @@ fn check_error_patterns(props: &TestProps,
315315

316316
let missing_patterns =
317317
vec::slice(props.error_patterns, next_err_idx,
318-
vec::len(props.error_patterns));
319-
if vec::len(missing_patterns) == 1u {
318+
props.error_patterns.len());
319+
if missing_patterns.len() == 1u {
320320
fatal_ProcRes(fmt!("error pattern '%s' not found!",
321321
missing_patterns[0]), ProcRes);
322322
} else {
@@ -333,7 +333,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
333333

334334
// true if we found the error in question
335335
let mut found_flags = vec::from_elem(
336-
vec::len(expected_errors), false);
336+
expected_errors.len(), false);
337337

338338
if ProcRes.status == 0 {
339339
fatal(~"process did not return an error status");
@@ -377,7 +377,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
377377
}
378378
}
379379

380-
for uint::range(0u, vec::len(found_flags)) |i| {
380+
for uint::range(0u, found_flags.len()) |i| {
381381
if !found_flags[i] {
382382
let ee = &expected_errors[i];
383383
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",

branches/try2/src/libcore/either.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ fn test_lefts() {
201201
fn test_lefts_none() {
202202
let input: ~[Either<int, int>] = ~[Right(10), Right(10)];
203203
let result = lefts(input);
204-
assert_eq!(vec::len(result), 0u);
204+
assert_eq!(result.len(), 0u);
205205
}
206206

207207
#[test]
208208
fn test_lefts_empty() {
209209
let input: ~[Either<int, int>] = ~[];
210210
let result = lefts(input);
211-
assert_eq!(vec::len(result), 0u);
211+
assert_eq!(result.len(), 0u);
212212
}
213213

214214
#[test]
@@ -222,14 +222,14 @@ fn test_rights() {
222222
fn test_rights_none() {
223223
let input: ~[Either<int, int>] = ~[Left(10), Left(10)];
224224
let result = rights(input);
225-
assert_eq!(vec::len(result), 0u);
225+
assert_eq!(result.len(), 0u);
226226
}
227227

228228
#[test]
229229
fn test_rights_empty() {
230230
let input: ~[Either<int, int>] = ~[];
231231
let result = rights(input);
232-
assert_eq!(vec::len(result), 0u);
232+
assert_eq!(result.len(), 0u);
233233
}
234234

235235
#[test]
@@ -247,22 +247,22 @@ fn test_partition() {
247247
fn test_partition_no_lefts() {
248248
let input: ~[Either<int, int>] = ~[Right(10), Right(11)];
249249
let (lefts, rights) = partition(input);
250-
assert_eq!(vec::len(lefts), 0u);
251-
assert_eq!(vec::len(rights), 2u);
250+
assert_eq!(lefts.len(), 0u);
251+
assert_eq!(rights.len(), 2u);
252252
}
253253

254254
#[test]
255255
fn test_partition_no_rights() {
256256
let input: ~[Either<int, int>] = ~[Left(10), Left(11)];
257257
let (lefts, rights) = partition(input);
258-
assert_eq!(vec::len(lefts), 2u);
259-
assert_eq!(vec::len(rights), 0u);
258+
assert_eq!(lefts.len(), 2u);
259+
assert_eq!(rights.len(), 0u);
260260
}
261261

262262
#[test]
263263
fn test_partition_empty() {
264264
let input: ~[Either<int, int>] = ~[];
265265
let (lefts, rights) = partition(input);
266-
assert_eq!(vec::len(lefts), 0u);
267-
assert_eq!(vec::len(rights), 0u);
266+
assert_eq!(lefts.len(), 0u);
267+
assert_eq!(rights.len(), 0u);
268268
}

branches/try2/src/libcore/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ impl<T:Reader> ReaderUtil for T {
673673

674674
fn read_char(&self) -> char {
675675
let c = self.read_chars(1);
676-
if vec::len(c) == 0 {
676+
if c.len() == 0 {
677677
return -1 as char; // FIXME will this stay valid? // #2004
678678
}
679-
assert!((vec::len(c) == 1));
679+
assert!(c.len() == 1);
680680
return c[0];
681681
}
682682

@@ -1802,7 +1802,7 @@ mod tests {
18021802
fn test_readchars_empty() {
18031803
do io::with_str_reader(~"") |inp| {
18041804
let res : ~[char] = inp.read_chars(128);
1805-
assert!((vec::len(res) == 0));
1805+
assert!(res.len() == 0);
18061806
}
18071807
}
18081808

@@ -1841,10 +1841,10 @@ mod tests {
18411841
fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
18421842
do io::with_str_reader(s) |inp| {
18431843
let res : ~[char] = inp.read_chars(len);
1844-
if (len <= vec::len(ivals)) {
1845-
assert!((vec::len(res) == len));
1844+
if len <= ivals.len() {
1845+
assert!(res.len() == len);
18461846
}
1847-
assert!(vec::slice(ivals, 0u, vec::len(res)) ==
1847+
assert!(vec::slice(ivals, 0u, res.len()) ==
18481848
vec::map(res, |x| *x as int));
18491849
}
18501850
}

branches/try2/src/libcore/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ pub fn self_exe_path() -> Option<Path> {
412412
KERN_PROC as c_int,
413413
KERN_PROC_PATHNAME as c_int, -1 as c_int];
414414
let mut sz = sz;
415-
sysctl(vec::raw::to_ptr(mib), vec::len(mib) as ::libc::c_uint,
415+
sysctl(vec::raw::to_ptr(mib), mib.len() as ::libc::c_uint,
416416
buf as *mut c_void, &mut sz, ptr::null(),
417417
0u as size_t) == (0 as c_int)
418418
}
@@ -1492,7 +1492,7 @@ mod tests {
14921492
#[ignore]
14931493
fn test_env_getenv() {
14941494
let e = env();
1495-
assert!(vec::len(e) > 0u);
1495+
assert!(e.len() > 0u);
14961496
for e.each |p| {
14971497
let (n, v) = copy *p;
14981498
debug!(copy n);
@@ -1583,7 +1583,7 @@ mod tests {
15831583
fn list_dir() {
15841584
let dirs = os::list_dir(&Path("."));
15851585
// Just assuming that we've got some contents in the current directory
1586-
assert!((vec::len(dirs) > 0u));
1586+
assert!(dirs.len() > 0u);
15871587
15881588
for dirs.each |dir| {
15891589
debug!(copy *dir);

branches/try2/src/libcore/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub mod ptr_tests {
441441
let arr_ptr = &arr[0];
442442
let mut ctr = 0;
443443
let mut iteration_count = 0;
444-
array_each_with_len(arr_ptr, vec::len(arr),
444+
array_each_with_len(arr_ptr, arr.len(),
445445
|e| {
446446
let actual = str::raw::from_c_str(e);
447447
let expected = copy expected_arr[ctr];

branches/try2/src/libcore/rt/uv/uvll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub unsafe fn accept(server: *c_void, client: *c_void) -> c_int {
230230

231231
pub unsafe fn write<T>(req: *uv_write_t, stream: *T, buf_in: &[uv_buf_t], cb: *u8) -> c_int {
232232
let buf_ptr = vec::raw::to_ptr(buf_in);
233-
let buf_cnt = vec::len(buf_in) as i32;
233+
let buf_cnt = buf_in.len() as i32;
234234
return rust_uv_write(req as *c_void, stream as *c_void, buf_ptr, buf_cnt, cb);
235235
}
236236
pub unsafe fn read_start(stream: *uv_stream_t, on_alloc: *u8, on_read: *u8) -> c_int {

0 commit comments

Comments
 (0)