Skip to content

Commit d64d26c

Browse files
committed
debugged a compiler ICE when merging local::borrow changes into the main io branch and modified the incoming new file lang.rs to be api-compatible
1 parent d4de99a commit d64d26c

File tree

10 files changed

+60
-22
lines changed

10 files changed

+60
-22
lines changed

src/libstd/macros.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,29 @@ macro_rules! rtassert (
3838
} )
3939
)
4040

41+
42+
// The do_abort function was originally inside the abort macro, but
43+
// this was ICEing the compiler so it has been moved outside. Now this
44+
// seems to work?
45+
pub fn do_abort() -> ! {
46+
unsafe { ::libc::abort(); }
47+
}
48+
4149
macro_rules! abort(
4250
($( $msg:expr),+) => ( {
4351
rtdebug!($($msg),+);
4452

45-
do_abort();
53+
// do_abort();
54+
55+
// NB: This is in a fn to avoid putting the `unsafe` block in
56+
// a macro, which causes spurious 'unnecessary unsafe block'
57+
// warnings.
58+
// fn do_abort() -> ! {
59+
// unsafe { ::libc::abort(); }
60+
// }
61+
62+
::macros::do_abort();
4663

47-
// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
48-
// which causes spurious 'unnecessary unsafe block' warnings.
49-
fn do_abort() -> ! {
50-
unsafe { ::libc::abort(); }
51-
}
5264
} )
5365
)
66+

src/libstd/rt/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ impl<T> ChanOne<T> {
120120
match oldstate {
121121
STATE_BOTH => {
122122
// Port is not waiting yet. Nothing to do
123-
do Local::borrow::<Scheduler> |sched| {
123+
do Local::borrow::<Scheduler, ()> |sched| {
124124
rtdebug!("non-rendezvous send");
125125
sched.metrics.non_rendezvous_sends += 1;
126126
}
127127
}
128128
STATE_ONE => {
129-
do Local::borrow::<Scheduler> |sched| {
129+
do Local::borrow::<Scheduler, ()> |sched| {
130130
rtdebug!("rendezvous send");
131131
sched.metrics.rendezvous_sends += 1;
132132
}

src/libstd/rt/local.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub trait Local {
1818
fn put(value: ~Self);
1919
fn take() -> ~Self;
2020
fn exists() -> bool;
21-
fn borrow(f: &fn(&mut Self));
21+
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
2222
unsafe fn unsafe_borrow() -> *mut Self;
2323
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
2424
}
@@ -27,7 +27,20 @@ impl Local for Scheduler {
2727
fn put(value: ~Scheduler) { unsafe { local_ptr::put(value) }}
2828
fn take() -> ~Scheduler { unsafe { local_ptr::take() } }
2929
fn exists() -> bool { local_ptr::exists() }
30-
fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } }
30+
fn borrow<T>(f: &fn(&mut Scheduler) -> T) -> T {
31+
let mut res: Option<T> = None;
32+
let res_ptr: *mut Option<T> = &mut res;
33+
unsafe {
34+
do local_ptr::borrow |sched| {
35+
let result = f(sched);
36+
*res_ptr = Some(result);
37+
}
38+
}
39+
match res {
40+
Some(r) => { r }
41+
None => abort!("function failed!")
42+
}
43+
}
3144
unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() }
3245
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> { abort!("unimpl") }
3346
}
@@ -36,8 +49,8 @@ impl Local for Task {
3649
fn put(_value: ~Task) { abort!("unimpl") }
3750
fn take() -> ~Task { abort!("unimpl") }
3851
fn exists() -> bool { abort!("unimpl") }
39-
fn borrow(f: &fn(&mut Task)) {
40-
do Local::borrow::<Scheduler> |sched| {
52+
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
53+
do Local::borrow::<Scheduler, T> |sched| {
4154
match sched.current_task {
4255
Some(~ref mut task) => {
4356
f(&mut *task.task)
@@ -74,7 +87,7 @@ impl Local for IoFactoryObject {
7487
fn put(_value: ~IoFactoryObject) { abort!("unimpl") }
7588
fn take() -> ~IoFactoryObject { abort!("unimpl") }
7689
fn exists() -> bool { abort!("unimpl") }
77-
fn borrow(_f: &fn(&mut IoFactoryObject)) { abort!("unimpl") }
90+
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { abort!("unimpl") }
7891
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
7992
let sched = Local::unsafe_borrow::<Scheduler>();
8093
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();
@@ -115,4 +128,16 @@ mod test {
115128
}
116129
let _scheduler: ~Scheduler = Local::take();
117130
}
131+
132+
#[test]
133+
fn borrow_with_return() {
134+
let scheduler = ~new_test_uv_sched();
135+
Local::put(scheduler);
136+
let res = do Local::borrow::<Scheduler,bool> |_sched| {
137+
true
138+
};
139+
assert!(res)
140+
let _scheduler: ~Scheduler = Local::take();
141+
}
142+
118143
}

src/libstd/rt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn context() -> RuntimeContext {
208208
} else {
209209
if Local::exists::<Scheduler>() {
210210
let context = ::cell::empty_cell();
211-
do Local::borrow::<Scheduler> |sched| {
211+
do Local::borrow::<Scheduler, ()> |sched| {
212212
if sched.in_task_context() {
213213
context.put_back(TaskContext);
214214
} else {

src/libstd/rt/sched.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ mod test {
683683
assert_eq!(count, MAX);
684684

685685
fn run_task(count_ptr: *mut int) {
686-
do Local::borrow::<Scheduler> |sched| {
686+
do Local::borrow::<Scheduler, ()> |sched| {
687687
let task = ~do Coroutine::new(&mut sched.stack_pool) {
688688
unsafe {
689689
*count_ptr = *count_ptr + 1;

src/libstd/rt/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Task {
6262
pub fn run(&mut self, f: &fn()) {
6363
// This is just an assertion that `run` was called unsafely
6464
// and this instance of Task is still accessible.
65-
do Local::borrow::<Task> |task| {
65+
do Local::borrow::<Task, ()> |task| {
6666
assert!(ptr::ref_eq(task, self));
6767
}
6868

@@ -87,7 +87,7 @@ impl Task {
8787
fn destroy(&mut self) {
8888
// This is just an assertion that `destroy` was called unsafely
8989
// and this instance of Task is still accessible.
90-
do Local::borrow::<Task> |task| {
90+
do Local::borrow::<Task, ()> |task| {
9191
assert!(ptr::ref_eq(task, self));
9292
}
9393
match self.storage {

src/libstd/rt/tube.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ mod test {
155155
if i == 100 { return; }
156156

157157
let tube = Cell(Cell(tube));
158-
do Local::borrow::<Scheduler> |sched| {
158+
do Local::borrow::<Scheduler, ()> |sched| {
159159
let tube = tube.take();
160160
do sched.event_loop.callback {
161161
let mut tube = tube.take();

src/libstd/rt/uv/uvio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mod test_remote {
167167
let mut tube = Tube::new();
168168
let tube_clone = tube.clone();
169169
let remote_cell = cell::empty_cell();
170-
do Local::borrow::<Scheduler>() |sched| {
170+
do Local::borrow::<Scheduler, ()>() |sched| {
171171
let tube_clone = tube_clone.clone();
172172
let tube_clone_cell = Cell(tube_clone);
173173
let remote = do sched.event_loop.remote_callback {

src/libstd/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub fn failing() -> bool {
514514
}
515515
_ => {
516516
let mut unwinding = false;
517-
do Local::borrow::<Task> |local| {
517+
do Local::borrow::<Task, ()> |local| {
518518
unwinding = match local.unwinder {
519519
Some(unwinder) => {
520520
unwinder.unwinding

src/libstd/unstable/lang.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
244244
}
245245
_ => {
246246
let mut alloc = ::ptr::null();
247-
do Local::borrow::<Task> |task| {
247+
do Local::borrow::<Task,()> |task| {
248248
alloc = task.heap.alloc(td as *c_void, size as uint) as *c_char;
249249
}
250250
return alloc;
@@ -262,7 +262,7 @@ pub unsafe fn local_free(ptr: *c_char) {
262262
rustrt::rust_upcall_free_noswitch(ptr);
263263
}
264264
_ => {
265-
do Local::borrow::<Task> |task| {
265+
do Local::borrow::<Task,()> |task| {
266266
task.heap.free(ptr as *c_void);
267267
}
268268
}

0 commit comments

Comments
 (0)