Skip to content

Commit 4ef7e4f

Browse files
committed
---
yaml --- r: 13647 b: refs/heads/master c: 986662c h: refs/heads/master i: 13645: 954cc94 13643: 4e9f894 13639: 34c1ad8 13631: 4849b1e v: v3
1 parent 663e7f6 commit 4ef7e4f

File tree

11 files changed

+63
-110
lines changed

11 files changed

+63
-110
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 25aa3605952719fbfc7ccb998a7980fad6df2eb1
2+
refs/heads/master: 986662cebd3f41911cb72c18f4e824a4856b009b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/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> {

trunk/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
}

trunk/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
{

trunk/src/libcore/priv.rs

Lines changed: 2 additions & 6 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

trunk/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"]

trunk/src/libcore/run.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ fn run_program(prog: str, args: [str]) -> int {
170170
#[doc ="
171171
Spawns a process and returns a program
172172
173-
The returned value is a boxed class containing a <program> object that can
174-
be used for sending and receiving data over the standard file descriptors.
175-
The class will ensure that file descriptors are closed properly.
173+
The returned value is a boxed resource containing a <program> object that can
174+
be used for sending and recieving data over the standard file descriptors.
175+
The resource will ensure that file descriptors are closed properly.
176176
177177
# Arguments
178178
@@ -181,7 +181,7 @@ The class will ensure that file descriptors are closed properly.
181181
182182
# Return value
183183
184-
A class with a <program> field
184+
A boxed resource of <program>
185185
"]
186186
fn start_program(prog: str, args: [str]) -> program {
187187
let pipe_input = os::pipe();
@@ -221,20 +221,16 @@ fn start_program(prog: str, args: [str]) -> program {
221221
libc::fclose(r.out_file);
222222
libc::fclose(r.err_file);
223223
}
224-
class prog_res {
225-
let r: prog_repr;
226-
new(-r: prog_repr) { self.r = r; }
227-
drop { destroy_repr(self.r); }
228-
}
224+
resource prog_res(r: prog_repr) { destroy_repr(r); }
229225

230226
impl of program for prog_res {
231-
fn get_id() -> pid_t { ret self.r.pid; }
232-
fn input() -> io::writer { io::fd_writer(self.r.in_fd, false) }
233-
fn output() -> io::reader { io::FILE_reader(self.r.out_file, false) }
234-
fn err() -> io::reader { io::FILE_reader(self.r.err_file, false) }
235-
fn close_input() { close_repr_input(self.r); }
236-
fn finish() -> int { finish_repr(self.r) }
237-
fn destroy() { destroy_repr(self.r); }
227+
fn get_id() -> pid_t { ret self.pid; }
228+
fn input() -> io::writer { io::fd_writer(self.in_fd, false) }
229+
fn output() -> io::reader { io::FILE_reader(self.out_file, false) }
230+
fn err() -> io::reader { io::FILE_reader(self.err_file, false) }
231+
fn close_input() { close_repr_input(*self); }
232+
fn finish() -> int { finish_repr(*self) }
233+
fn destroy() { destroy_repr(*self); }
238234
}
239235
let repr = {pid: pid,
240236
mut in_fd: pipe_input.out,

trunk/src/libcore/sys.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,16 @@ pure fn log_str<T>(t: T) -> str {
8585
}
8686
}
8787

88-
class lock_and_signal {
89-
let lock: rust_cond_lock;
90-
new(lock: rust_cond_lock) { self.lock = lock; }
91-
drop { rustrt::rust_destroy_cond_lock(self.lock); }
88+
resource lock_and_signal(lock: rust_cond_lock) {
89+
rustrt::rust_destroy_cond_lock(lock);
9290
}
9391

9492
enum condition {
9593
condition_(rust_cond_lock)
9694
}
9795

98-
class unlock {
99-
let lock: rust_cond_lock;
100-
new(lock: rust_cond_lock) { self.lock = lock; }
101-
drop { rustrt::rust_unlock_cond_lock(self.lock); }
96+
resource unlock(lock: rust_cond_lock) {
97+
rustrt::rust_unlock_cond_lock(lock);
10298
}
10399

104100
fn create_lock() -> lock_and_signal {
@@ -107,15 +103,15 @@ fn create_lock() -> lock_and_signal {
107103

108104
impl methods for lock_and_signal {
109105
fn lock<T>(f: fn() -> T) -> T {
110-
rustrt::rust_lock_cond_lock(self.lock);
111-
let _r = unlock(self.lock);
106+
rustrt::rust_lock_cond_lock(*self);
107+
let _r = unlock(*self);
112108
f()
113109
}
114110

115111
fn lock_cond<T>(f: fn(condition) -> T) -> T {
116-
rustrt::rust_lock_cond_lock(self.lock);
117-
let _r = unlock(self.lock);
118-
f(condition_(self.lock))
112+
rustrt::rust_lock_cond_lock(*self);
113+
let _r = unlock(*self);
114+
f(condition_(*self))
119115
}
120116
}
121117

trunk/src/libcore/task.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,9 @@ Temporarily make the task unkillable
482482
483483
"]
484484
unsafe fn unkillable(f: fn()) {
485-
class allow_failure {
486-
let i: (); // since a class must have at least one field
487-
new(_i: ()) { self.i = (); }
488-
drop { rustrt::rust_task_allow_kill(); }
485+
resource allow_failure(_i: ()) {
486+
rustrt::rust_task_allow_kill();
489487
}
490-
491488
let _allow_failure = allow_failure(());
492489
rustrt::rust_task_inhibit_kill();
493490
f();

trunk/src/rustc/middle/trans/reachable.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ fn traverse_all_resources(cx: ctx, crate_mod: _mod) {
209209
visit_item: {|i, cx, v|
210210
visit::visit_item(i, cx, v);
211211
alt i.node {
212-
item_res(*) {
213-
traverse_public_item(cx, i);
214-
}
215-
// Classes with dtors too!
216-
item_class(_, _, _, _, some(_), _) {
212+
item_res(_, _, _, _, _, _) {
217213
traverse_public_item(cx, i);
218214
}
219215
_ {}

trunk/src/rustc/middle/ty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
14961496
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
14971497
ty_ptr(_) { kind_implicitly_sendable() | kind_const() }
14981498
// Implicit copyability of strs is configurable
1499-
ty_str {
1499+
ty_str | ty_estr(vstore_uniq) {
15001500
if cx.vecs_implicitly_copyable {
15011501
kind_implicitly_sendable() | kind_const()
15021502
} else { kind_sendable() | kind_const() }
@@ -1526,7 +1526,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
15261526
remove_implicit(mutable_type_kind(cx, tm))
15271527
}
15281528
// Implicit copyability of vecs is configurable
1529-
ty_vec(tm) {
1529+
ty_vec(tm) | ty_evec(tm, vstore_uniq) {
15301530
if cx.vecs_implicitly_copyable {
15311531
mutable_type_kind(cx, tm)
15321532
} else { remove_implicit(mutable_type_kind(cx, tm)) }
@@ -1544,17 +1544,13 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
15441544
kind_implicitly_copyable()
15451545
}
15461546
}
1547-
ty_evec(tm, vstore_uniq) {
1548-
remove_implicit(mutable_type_kind(cx, tm))
1549-
}
15501547
ty_evec(tm, vstore_fixed(_)) {
15511548
mutable_type_kind(cx, tm)
15521549
}
15531550

15541551
// All estrs are copyable; uniques and interiors are sendable.
15551552
ty_estr(vstore_box) |
15561553
ty_estr(vstore_slice(_)) { kind_implicitly_copyable() | kind_const() }
1557-
ty_estr(vstore_uniq) { kind_sendable() | kind_const() }
15581554
ty_estr(vstore_fixed(_)) { kind_implicitly_sendable() | kind_const() }
15591555

15601556
// Records lower to the lowest of their members.

0 commit comments

Comments
 (0)