Skip to content

Commit 91bc11c

Browse files
committed
---
yaml --- r: 10688 b: refs/heads/snap-stage3 c: 20b5ca3 h: refs/heads/master v: v3
1 parent 9eb5911 commit 91bc11c

File tree

108 files changed

+1056
-585
lines changed

Some content is hidden

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

108 files changed

+1056
-585
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: bf92940f72bf4eb0e2881b275dc76772c93b8f47
4+
refs/heads/snap-stage3: 20b5ca3d2ffaf7b26a0f13c5490d06a889455f07
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/RELEASES.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
Version 0.3 (June 2012) - not yet!
2+
-----------------------------------
3+
4+
* ~1500 changes, numerous bugfixes
5+
6+
* New coding conveniences
7+
* Integer-literal suffix inference
8+
* Per-module control over warnings, errors
9+
* #[cfg(windows)] and #[cfg(unix)] attributes
10+
11+
* Semantic cleanup
12+
* Resolve pass and exhaustiveness checker rewritten
13+
* Borrow-check taking over from alias-analysis
14+
* Liveness taking over from last-use, typestate
15+
* Extensive work on region pointers
16+
17+
* Experimental new language features
18+
* Slices and fixed-size, interior-allocated vectors
19+
* #!-comments for lang versioning, shell execution
20+
* More work on classes
21+
* Type reflection
22+
23+
* Removal of various obsolete features
24+
* Keywords: be, prove, syntax, note, mutable, do, bind
25+
* Constructs: do-while loops, fn binding,
26+
27+
* Compiler reorganization
28+
* Syntax-layer of compiler split into separate crate
29+
* Clang (from LLVM project) integrated into build
30+
* Typechecker split into sub-modules
31+
32+
* New library code
33+
* New time functions
34+
* Extension methods for many built-in types
35+
* Arc: atomic-refcount read-only / exclusive-use shared cells
36+
* Par: parallel map and search routines
37+
* Extensive work on libuv interface
38+
* Much vector code moved to libraries
39+
* Syntax extensions: #line, #col, #file, #mod,
40+
#stringify, #include, #include_str, #include_bin.
41+
42+
* Tool improvements
43+
* Cargo automatically resolves dependencies
44+
145
Version 0.2 (March 2012)
246
-------------------------
347

branches/snap-stage3/doc/tutorial.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,26 @@ Like vectors, strings are always unique. You can wrap them in a shared
13771377
box to share them. Unlike vectors, there is no mutable variant of
13781378
strings. They are always immutable.
13791379
1380-
NOTE: Section on resources removed. ToDo: document classes and destructors
1380+
## Resources
1381+
1382+
Resources are data types that have a destructor associated with them.
1383+
1384+
~~~~
1385+
# fn close_file_desc(x: int) {}
1386+
resource file_desc(fd: int) {
1387+
close_file_desc(fd);
1388+
}
1389+
~~~~
1390+
1391+
This defines a type `file_desc` and a constructor of the same name,
1392+
which takes an integer. The type has an associated destructor procedure,
1393+
whose contents are specified by the block. Values of such a type can not
1394+
be copied, and when they are destroyed (by going out of scope, or, when
1395+
boxed, when their box is cleaned up), their body runs. In the example
1396+
above, this would cause the given file descriptor to be closed.
1397+
1398+
NOTE: We're considering alternative approaches for data types with
1399+
destructors. Resources might go away in the future.
13811400
13821401
# Argument passing
13831402
@@ -1562,7 +1581,7 @@ without any sophistication).
15621581
## Kinds
15631582
15641583
Perhaps surprisingly, the 'copy' (duplicate) operation is not defined
1565-
for all Rust types. Resource types (classes with destructors) cannot be
1584+
for all Rust types. Resource types (types with destructors) can not be
15661585
copied, and neither can any type whose copying would require copying a
15671586
resource (such as records or unique boxes containing a resource).
15681587

branches/snap-stage3/src/libcore/arc.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ type arc_data<T> = {
2424
data: T
2525
};
2626

27-
class arc_destruct<T> {
28-
let data: *libc::c_void;
29-
new(data: *libc::c_void) { self.data = data; }
30-
drop unsafe {
31-
let data: ~arc_data<T> = unsafe::reinterpret_cast(self.data);
32-
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
33-
assert new_count >= 0;
34-
if new_count == 0 {
35-
// drop glue takes over.
36-
} else {
37-
unsafe::forget(data);
38-
}
39-
}
27+
resource arc_destruct<T>(data: *libc::c_void) {
28+
unsafe {
29+
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
30+
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
31+
assert new_count >= 0;
32+
if new_count == 0 {
33+
// drop glue takes over.
34+
} else {
35+
unsafe::forget(data);
36+
}
37+
}
4038
}
4139

4240
type arc<T: const> = arc_destruct<T>;
@@ -54,7 +52,7 @@ fn arc<T: const>(-data: T) -> arc<T> {
5452
wrapper."]
5553
fn get<T: const>(rc: &a.arc<T>) -> &a.T {
5654
unsafe {
57-
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
55+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
5856
// Cast us back into the correct region
5957
let r = unsafe::reinterpret_cast(&ptr.data);
6058
unsafe::forget(ptr);
@@ -69,12 +67,12 @@ object. However, one of the `arc` objects can be sent to another task,
6967
allowing them to share the underlying data."]
7068
fn clone<T: const>(rc: &arc<T>) -> arc<T> {
7169
unsafe {
72-
let ptr: ~arc_data<T> = unsafe::reinterpret_cast((*rc).data);
70+
let ptr: ~arc_data<T> = unsafe::reinterpret_cast(**rc);
7371
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
7472
assert new_count >= 2;
7573
unsafe::forget(ptr);
7674
}
77-
arc_destruct((*rc).data)
75+
arc_destruct(**rc)
7876
}
7977

8078
// An arc over mutable data that is protected by a lock.
@@ -95,19 +93,17 @@ impl methods<T: send> for exclusive<T> {
9593
fn clone() -> exclusive<T> {
9694
unsafe {
9795
// this makes me nervous...
98-
let ptr: ~arc_data<ex_data<T>> =
99-
unsafe::reinterpret_cast(self.data);
96+
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
10097
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
10198
assert new_count > 1;
10299
unsafe::forget(ptr);
103100
}
104-
arc_destruct(self.data)
101+
arc_destruct(*self)
105102
}
106103

107104
fn with<U>(f: fn(sys::condition, x: &T) -> U) -> U {
108105
unsafe {
109-
let ptr: ~arc_data<ex_data<T>> =
110-
unsafe::reinterpret_cast(self.data);
106+
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
111107
let r = {
112108
let rec: &ex_data<T> = &(*ptr).data;
113109
rec.lock.lock_cond() {|c|
@@ -127,10 +123,8 @@ type get_chan<T: const send> = chan<chan<arc<T>>>;
127123
// (terminate, get)
128124
type shared_arc<T: const send> = (shared_arc_res, get_chan<T>);
129125

130-
class shared_arc_res {
131-
let c: comm::chan<()>;
132-
new(c: comm::chan<()>) { self.c = c; }
133-
drop { self.c.send(()); }
126+
resource shared_arc_res(c: comm::chan<()>) {
127+
c.send(());
134128
}
135129

136130
fn shared_arc<T: send const>(-data: T) -> shared_arc<T> {

branches/snap-stage3/src/libcore/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn test_recv_chan_wrong_task() {
440440
let po = port();
441441
let ch = chan(po);
442442
send(ch, "flower");
443-
assert result::is_failure(task::try {||
443+
assert result::is_err(task::try {||
444444
recv_chan(ch)
445445
})
446446
}

branches/snap-stage3/src/libcore/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import option::extensions;
1111
import option_iter::extensions;
1212
import ptr::extensions;
1313
import rand::extensions;
14+
import result::extensions;
1415

1516
export path, option, some, none, unreachable;
1617
export extensions;

branches/snap-stage3/src/libcore/io.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ impl <T: reader, C> of reader for {base: T, cleanup: C} {
224224
fn tell() -> uint { self.base.tell() }
225225
}
226226

227-
class FILE_res {
228-
let f: *libc::FILE;
229-
new(f: *libc::FILE) { self.f = f; }
230-
drop { libc::fclose(self.f); }
231-
}
227+
resource FILE_res(f: *libc::FILE) { libc::fclose(f); }
232228

233229
fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
234230
if cleanup {
@@ -387,11 +383,7 @@ impl of writer for fd_t {
387383
fn flush() -> int { 0 }
388384
}
389385

390-
class fd_res {
391-
let fd: fd_t;
392-
new(fd: fd_t) { self.fd = fd; }
393-
drop { libc::close(self.fd); }
394-
}
386+
resource fd_res(fd: fd_t) { libc::close(fd); }
395387

396388
fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
397389
if cleanup {
@@ -703,17 +695,13 @@ mod fsync {
703695
}
704696

705697

706-
// Artifacts that need to fsync on destruction
707-
class res<t> {
708-
let arg: arg<t>;
709-
new(-arg: arg<t>) { self.arg <- arg; }
710-
drop {
711-
alt self.arg.opt_level {
712-
option::none { }
713-
option::some(level) {
714-
// fail hard if not succesful
715-
assert(self.arg.fsync_fn(self.arg.val, level) != -1);
716-
}
698+
// Resource of artifacts that need to fsync on destruction
699+
resource res<t>(arg: arg<t>) {
700+
alt arg.opt_level {
701+
option::none { }
702+
option::some(level) {
703+
// fail hard if not succesful
704+
assert(arg.fsync_fn(arg.val, level) != -1);
717705
}
718706
}
719707
}
@@ -730,7 +718,7 @@ mod fsync {
730718
fn FILE_res_sync(&&file: FILE_res, opt_level: option<level>,
731719
blk: fn(&&res<*libc::FILE>)) {
732720
blk(res({
733-
val: file.f, opt_level: opt_level,
721+
val: *file, opt_level: opt_level,
734722
fsync_fn: fn@(&&file: *libc::FILE, l: level) -> int {
735723
ret os::fsync_fd(libc::fileno(file), l) as int;
736724
}
@@ -741,7 +729,7 @@ mod fsync {
741729
fn fd_res_sync(&&fd: fd_res, opt_level: option<level>,
742730
blk: fn(&&res<fd_t>)) {
743731
blk(res({
744-
val: fd.fd, opt_level: opt_level,
732+
val: *fd, opt_level: opt_level,
745733
fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
746734
ret os::fsync_fd(fd, l) as int;
747735
}

branches/snap-stage3/src/libcore/option.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ fn test_unwrap_str() {
140140

141141
#[test]
142142
fn test_unwrap_resource() {
143-
class r {
144-
let i: @mut int;
145-
new(i: @mut int) { self.i = i; }
146-
drop { *(self.i) += 1; }
143+
resource r(i: @mut int) {
144+
*i += 1;
147145
}
148146
let i = @mut 0;
149147
{

branches/snap-stage3/src/libcore/priv.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,8 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) unsafe {
181181
let _unweaken = unweaken(ch);
182182
f(po);
183183

184-
class unweaken {
185-
let ch: comm::chan<()>;
186-
new(ch: comm::chan<()>) { self.ch = ch; }
187-
drop unsafe {
188-
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
189-
}
184+
resource unweaken(ch: comm::chan<()>) unsafe {
185+
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(ch));
190186
}
191187
}
192188

@@ -236,5 +232,5 @@ fn test_weaken_task_fail() unsafe {
236232
fail;
237233
}
238234
};
239-
assert result::is_failure(res);
235+
assert result::is_err(res);
240236
}

branches/snap-stage3/src/libcore/rand.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,10 @@ impl extensions for rng {
230230

231231
}
232232

233-
class rand_res {
234-
let c: *rctx;
235-
new(c: *rctx) { self.c = c; }
236-
drop { rustrt::rand_free(self.c); }
237-
}
233+
resource rand_res(c: *rctx) { rustrt::rand_free(c); }
238234

239235
impl of rng for @rand_res {
240-
fn next() -> u32 { ret rustrt::rand_next((*self).c); }
236+
fn next() -> u32 { ret rustrt::rand_next(**self); }
241237
}
242238

243239
#[doc = "Create a new random seed for seeded_rng"]

0 commit comments

Comments
 (0)