Skip to content

Commit 0c86f59

Browse files
committed
---
yaml --- r: 13534 b: refs/heads/master c: a14df27 h: refs/heads/master v: v3
1 parent 32e4a62 commit 0c86f59

Some content is hidden

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

61 files changed

+1019
-517
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: 8103611b7f6860dbbff40bcac8f22788692223b4
2+
refs/heads/master: a14df270dc18cd13965e741967eaeac443e20466
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/doc/rust.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,3 @@ h3 a:link, h3 a:visited { color: black; }
5151
.cm-s-default span.cm-bracket {color: #cc7;}
5252
.cm-s-default span.cm-tag {color: #170;}
5353
.cm-s-default span.cm-attribute {color: #00c;}
54-
55-
h1.title {
56-
background-image: url('http://www.rust-lang.org/logos/rust-logo-32x32-blk.png');
57-
background-repeat: no-repeat;
58-
background-position: right;
59-
}

trunk/mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ RUNTIME_CS_$(1) := \
7070
rt/rust_cc.cpp \
7171
rt/rust_debug.cpp \
7272
rt/rust_box_annihilator.cpp \
73+
rt/rust_cond_lock.cpp \
7374
rt/memory_region.cpp \
7475
rt/boxed_region.cpp \
7576
rt/arch/$$(HOST_$(1))/context.cpp \

trunk/src/cargo/cargo.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,7 @@ fn load_link(mis: [@ast::meta_item]) -> (option<str>,
238238
}
239239

240240
fn load_crate(filename: str) -> option<crate> {
241-
let cm = codemap::new_codemap();
242-
let handler = diagnostic::mk_handler(none);
243-
let sess = @{
244-
cm: cm,
245-
mut next_id: 1,
246-
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
247-
mut chpos: 0u,
248-
mut byte_pos: 0u
249-
};
241+
let sess = parse::new_parse_sess(none);
250242
let c = parse::parse_crate_from_crate_file(filename, [], sess);
251243

252244
let mut name = none;

trunk/src/fuzzer/fuzzer.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,7 @@ fn check_compiling(filename: str) -> happiness {
416416

417417
fn parse_and_print(code: @str) -> str {
418418
let filename = "tmp.rs";
419-
let cm = codemap::new_codemap();
420-
let handler = diagnostic::mk_handler(none);
421-
let sess = @{
422-
cm: cm,
423-
mut next_id: 1,
424-
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
425-
mut chpos: 0u,
426-
mut byte_pos: 0u
427-
};
419+
let sess = parse::new_parse_sess(option::none);
428420
write_file(filename, *code);
429421
let crate = parse::parse_crate_from_source_str(
430422
filename, code, [], sess);
@@ -566,15 +558,7 @@ fn check_variants(files: [str], cx: context) {
566558
}
567559

568560
log(error, "check_variants: " + file);
569-
let cm = codemap::new_codemap();
570-
let handler = diagnostic::mk_handler(none);
571-
let sess = @{
572-
cm: cm,
573-
mut next_id: 1,
574-
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
575-
mut chpos: 0u,
576-
mut byte_pos: 0u
577-
};
561+
let sess = parse::new_parse_sess(option::none);
578562
let crate =
579563
parse::parse_crate_from_source_str(
580564
file,

trunk/src/libstd/arc.rs renamed to trunk/src/libcore/arc.rs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
share immutable data between tasks."]
33

44
import comm::{port, chan, methods};
5+
import sys::methods;
56

67
export arc, get, clone, shared_arc, get_arc;
78

9+
export exclusive, methods;
10+
811
#[abi = "cdecl"]
912
native mod rustrt {
1013
#[rust_stack]
@@ -16,12 +19,12 @@ native mod rustrt {
1619
-> libc::intptr_t;
1720
}
1821

19-
type arc_data<T: const> = {
22+
type arc_data<T> = {
2023
mut count: libc::intptr_t,
2124
data: T
2225
};
2326

24-
resource arc_destruct<T: const>(data: *libc::c_void) {
27+
resource arc_destruct<T>(data: *libc::c_void) {
2528
unsafe {
2629
let data: ~arc_data<T> = unsafe::reinterpret_cast(data);
2730
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
@@ -71,6 +74,46 @@ fn clone<T: const>(rc: &arc<T>) -> arc<T> {
7174
arc_destruct(**rc)
7275
}
7376

77+
// An arc over mutable data that is protected by a lock.
78+
type ex_data<T> = {lock: sys::lock_and_signal, data: T};
79+
type exclusive<T> = arc_destruct<ex_data<T>>;
80+
81+
fn exclusive<T>(-data: T) -> exclusive<T> {
82+
let data = ~{mut count: 1, data: {lock: sys::create_lock(),
83+
data: data}};
84+
unsafe {
85+
let ptr = unsafe::reinterpret_cast(data);
86+
unsafe::forget(data);
87+
arc_destruct(ptr)
88+
}
89+
}
90+
91+
impl methods<T> for exclusive<T> {
92+
fn clone() -> exclusive<T> {
93+
unsafe {
94+
// this makes me nervous...
95+
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
96+
rustrt::rust_atomic_increment(&mut ptr.count);
97+
unsafe::forget(ptr);
98+
}
99+
arc_destruct(*self)
100+
}
101+
102+
fn with<U>(f: fn(sys::condition, x: &T) -> U) -> U {
103+
unsafe {
104+
let ptr: ~arc_data<ex_data<T>> = unsafe::reinterpret_cast(*self);
105+
let r = {
106+
let rec: &ex_data<T> = &(*ptr).data;
107+
rec.lock.lock_cond() {|c|
108+
f(c, &rec.data)
109+
}
110+
};
111+
unsafe::forget(ptr);
112+
r
113+
}
114+
}
115+
}
116+
74117
// Convenience code for sharing arcs between tasks
75118

76119
type get_chan<T: const send> = chan<chan<arc<T>>>;
@@ -115,6 +158,7 @@ fn get_arc<T: send const>(c: get_chan<T>) -> arc::arc<T> {
115158
#[cfg(test)]
116159
mod tests {
117160
import comm::*;
161+
import future::future;
118162

119163
#[test]
120164
fn manually_share_arc() {
@@ -160,4 +204,31 @@ mod tests {
160204

161205
assert p.recv() == ();
162206
}
207+
208+
#[test]
209+
fn exclusive_arc() {
210+
let mut futures = [];
211+
212+
let num_tasks = 10u;
213+
let count = 1000u;
214+
215+
let total = exclusive(~mut 0u);
216+
217+
for uint::range(0u, num_tasks) {|_i|
218+
let total = total.clone();
219+
futures += [future::spawn({||
220+
for uint::range(0u, count) {|_i|
221+
total.with {|_cond, count|
222+
**count += 1u;
223+
}
224+
}
225+
})];
226+
};
227+
228+
for futures.each {|f| f.get() };
229+
230+
total.with {|_cond, total|
231+
assert **total == num_tasks * count
232+
};
233+
}
163234
}

trunk/src/libcore/core.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export float, f32, f64;
3939
export box, char, str, ptr, vec, bool;
4040
export either, option, result, iter;
4141
export libc, os, io, run, rand, sys, unsafe, logging;
42-
export comm, task, future;
42+
export arc, comm, task, future;
4343
export extfmt;
4444
export tuple;
4545
export to_str;
@@ -175,6 +175,7 @@ mod dvec_iter {
175175
}
176176

177177
// Concurrency
178+
mod arc;
178179
mod comm;
179180
mod task;
180181
mod future;

trunk/src/libcore/dvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl extensions<A> for dvec<A> {
129129
#[doc = "Overwrite the current contents"]
130130
fn set(+w: [mut A]) {
131131
self.check_not_borrowed();
132-
self.data <- w; //FIXME check for recursive use (#2607)
132+
self.data <- w;
133133
}
134134
}
135135

trunk/src/libcore/extfmt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ mod ct {
9494
}
9595
let mut i = 0u;
9696
while i < lim {
97-
let curr = str::slice(s, i, i+1u);
97+
let size = str::utf8_char_width(s[i]);
98+
let curr = str::slice(s, i, i+size);
9899
if str::eq(curr, "%") {
99100
i += 1u;
100101
if i >= lim {
@@ -110,7 +111,7 @@ mod ct {
110111
pieces += [rs.piece];
111112
i = rs.next;
112113
}
113-
} else { buf += curr; i += 1u; }
114+
} else { buf += curr; i += size; }
114115
}
115116
flush_buf(buf, pieces);
116117
ret pieces;

trunk/src/libcore/sys.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export min_align_of;
77
export pref_align_of;
88
export refcount;
99
export log_str;
10+
export create_lock, lock_and_signal, condition, methods;
1011

1112
enum type_desc = {
1213
first_param: **libc::c_int,
@@ -15,11 +16,20 @@ enum type_desc = {
1516
// Remaining fields not listed
1617
};
1718

19+
type rust_cond_lock = *libc::c_void;
20+
1821
#[abi = "cdecl"]
1922
native mod rustrt {
2023
pure fn refcount(t: *()) -> libc::intptr_t;
2124
fn unsupervise();
2225
pure fn shape_log_str(t: *sys::type_desc, data: *()) -> str;
26+
27+
fn rust_create_cond_lock() -> rust_cond_lock;
28+
fn rust_destroy_cond_lock(lock: rust_cond_lock);
29+
fn rust_lock_cond_lock(lock: rust_cond_lock);
30+
fn rust_unlock_cond_lock(lock: rust_cond_lock);
31+
fn rust_wait_cond_lock(lock: rust_cond_lock);
32+
fn rust_signal_cond_lock(lock: rust_cond_lock) -> bool;
2333
}
2434

2535
#[abi = "rust-intrinsic"]
@@ -74,6 +84,46 @@ pure fn log_str<T>(t: T) -> str {
7484
}
7585
}
7686

87+
resource lock_and_signal(lock: rust_cond_lock) {
88+
rustrt::rust_destroy_cond_lock(lock);
89+
}
90+
91+
enum condition {
92+
condition_(rust_cond_lock)
93+
}
94+
95+
resource unlock(lock: rust_cond_lock) {
96+
rustrt::rust_unlock_cond_lock(lock);
97+
}
98+
99+
fn create_lock() -> lock_and_signal {
100+
lock_and_signal(rustrt::rust_create_cond_lock())
101+
}
102+
103+
impl methods for lock_and_signal {
104+
fn lock<T>(f: fn() -> T) -> T {
105+
rustrt::rust_lock_cond_lock(*self);
106+
let _r = unlock(*self);
107+
f()
108+
}
109+
110+
fn lock_cond<T>(f: fn(condition) -> T) -> T {
111+
rustrt::rust_lock_cond_lock(*self);
112+
let _r = unlock(*self);
113+
f(condition_(*self))
114+
}
115+
}
116+
117+
impl methods for condition {
118+
fn wait() {
119+
rustrt::rust_wait_cond_lock(*self);
120+
}
121+
122+
fn signal() -> bool {
123+
rustrt::rust_signal_cond_lock(*self)
124+
}
125+
}
126+
77127
#[cfg(test)]
78128
mod tests {
79129

@@ -121,6 +171,26 @@ mod tests {
121171
assert pref_align_of::<uint>() == 8u;
122172
assert pref_align_of::<*uint>() == 8u;
123173
}
174+
175+
#[test]
176+
fn condition_variable() {
177+
let lock = arc::arc(create_lock());
178+
let lock2 = arc::clone(&lock);
179+
180+
task::spawn {|move lock2|
181+
let lock = arc::get(&lock2);
182+
(*lock).lock_cond {|c|
183+
c.wait();
184+
}
185+
}
186+
187+
let mut signaled = false;
188+
while !signaled {
189+
(*arc::get(&lock)).lock_cond {|c|
190+
signaled = c.signal()
191+
}
192+
}
193+
}
124194
}
125195

126196
// Local Variables:

trunk/src/libstd/std.rc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export net, net_tcp;
1919
export uv, uv_ll, uv_iotask, uv_global_loop;
2020
export c_vec, util, timer;
2121
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap;
22-
export rope, arena, arc, par;
22+
export rope, arena, par;
2323
export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
2424
export test, tempfile, serialization;
2525
export cmp;
@@ -69,7 +69,6 @@ mod term;
6969
mod time;
7070
mod prettyprint;
7171
mod arena;
72-
mod arc;
7372
mod par;
7473
mod cmp;
7574

trunk/src/libsyntax/ast.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import std::serialization::{serializer,
1717
deserialize_str,
1818
serialize_bool,
1919
deserialize_bool};
20+
import parse::token;
21+
2022

2123
/* Note #1972 -- spans are serialized but not deserialized */
2224
fn serialize_span<S>(_s: S, _v: span) {
@@ -371,6 +373,13 @@ enum blk_sort {
371373
}
372374
*/
373375

376+
#[auto_serialize]
377+
enum token_tree {
378+
/* for macro invocations; parsing is the macro's job */
379+
tt_delim([token_tree]),
380+
tt_flat(span, token::token)
381+
}
382+
374383
#[auto_serialize]
375384
type mac = spanned<mac_>;
376385

@@ -386,6 +395,7 @@ type mac_body = option<mac_body_>;
386395
#[auto_serialize]
387396
enum mac_ {
388397
mac_invoc(@path, mac_arg, mac_body),
398+
mac_invoc_tt(@path, token_tree), //will kill mac_invoc and steal its name
389399
mac_embed_type(@ty),
390400
mac_embed_block(blk),
391401
mac_ellipsis,

trunk/src/libsyntax/ast_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
455455
visit_expr: fn@(e: @expr) {
456456
vfn(e.id);
457457
alt e.node {
458-
expr_unary(_, _) | expr_binary(_, _, _) {
458+
expr_index(*) | expr_assign_op(*) |
459+
expr_unary(*) | expr_binary(*) {
459460
vfn(ast_util::op_expr_callee_id(e));
460461
}
461462
_ { /* fallthrough */ }

0 commit comments

Comments
 (0)