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
This commit is contained in:
parent
d4de99aa6c
commit
d64d26cd39
10 changed files with 60 additions and 22 deletions
|
|
@ -38,16 +38,29 @@ macro_rules! rtassert (
|
|||
} )
|
||||
)
|
||||
|
||||
|
||||
// The do_abort function was originally inside the abort macro, but
|
||||
// this was ICEing the compiler so it has been moved outside. Now this
|
||||
// seems to work?
|
||||
pub fn do_abort() -> ! {
|
||||
unsafe { ::libc::abort(); }
|
||||
}
|
||||
|
||||
macro_rules! abort(
|
||||
($( $msg:expr),+) => ( {
|
||||
rtdebug!($($msg),+);
|
||||
|
||||
do_abort();
|
||||
// do_abort();
|
||||
|
||||
// NB: This is in a fn to avoid putting the `unsafe` block in
|
||||
// a macro, which causes spurious 'unnecessary unsafe block'
|
||||
// warnings.
|
||||
// fn do_abort() -> ! {
|
||||
// unsafe { ::libc::abort(); }
|
||||
// }
|
||||
|
||||
::macros::do_abort();
|
||||
|
||||
// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
|
||||
// which causes spurious 'unnecessary unsafe block' warnings.
|
||||
fn do_abort() -> ! {
|
||||
unsafe { ::libc::abort(); }
|
||||
}
|
||||
} )
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -120,13 +120,13 @@ impl<T> ChanOne<T> {
|
|||
match oldstate {
|
||||
STATE_BOTH => {
|
||||
// Port is not waiting yet. Nothing to do
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
do Local::borrow::<Scheduler, ()> |sched| {
|
||||
rtdebug!("non-rendezvous send");
|
||||
sched.metrics.non_rendezvous_sends += 1;
|
||||
}
|
||||
}
|
||||
STATE_ONE => {
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
do Local::borrow::<Scheduler, ()> |sched| {
|
||||
rtdebug!("rendezvous send");
|
||||
sched.metrics.rendezvous_sends += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub trait Local {
|
|||
fn put(value: ~Self);
|
||||
fn take() -> ~Self;
|
||||
fn exists() -> bool;
|
||||
fn borrow(f: &fn(&mut Self));
|
||||
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
|
||||
unsafe fn unsafe_borrow() -> *mut Self;
|
||||
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
|
||||
}
|
||||
|
|
@ -27,7 +27,20 @@ impl Local for Scheduler {
|
|||
fn put(value: ~Scheduler) { unsafe { local_ptr::put(value) }}
|
||||
fn take() -> ~Scheduler { unsafe { local_ptr::take() } }
|
||||
fn exists() -> bool { local_ptr::exists() }
|
||||
fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } }
|
||||
fn borrow<T>(f: &fn(&mut Scheduler) -> T) -> T {
|
||||
let mut res: Option<T> = None;
|
||||
let res_ptr: *mut Option<T> = &mut res;
|
||||
unsafe {
|
||||
do local_ptr::borrow |sched| {
|
||||
let result = f(sched);
|
||||
*res_ptr = Some(result);
|
||||
}
|
||||
}
|
||||
match res {
|
||||
Some(r) => { r }
|
||||
None => abort!("function failed!")
|
||||
}
|
||||
}
|
||||
unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() }
|
||||
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> { abort!("unimpl") }
|
||||
}
|
||||
|
|
@ -36,8 +49,8 @@ impl Local for Task {
|
|||
fn put(_value: ~Task) { abort!("unimpl") }
|
||||
fn take() -> ~Task { abort!("unimpl") }
|
||||
fn exists() -> bool { abort!("unimpl") }
|
||||
fn borrow(f: &fn(&mut Task)) {
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
|
||||
do Local::borrow::<Scheduler, T> |sched| {
|
||||
match sched.current_task {
|
||||
Some(~ref mut task) => {
|
||||
f(&mut *task.task)
|
||||
|
|
@ -74,7 +87,7 @@ impl Local for IoFactoryObject {
|
|||
fn put(_value: ~IoFactoryObject) { abort!("unimpl") }
|
||||
fn take() -> ~IoFactoryObject { abort!("unimpl") }
|
||||
fn exists() -> bool { abort!("unimpl") }
|
||||
fn borrow(_f: &fn(&mut IoFactoryObject)) { abort!("unimpl") }
|
||||
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { abort!("unimpl") }
|
||||
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
|
||||
let sched = Local::unsafe_borrow::<Scheduler>();
|
||||
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();
|
||||
|
|
@ -115,4 +128,16 @@ mod test {
|
|||
}
|
||||
let _scheduler: ~Scheduler = Local::take();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn borrow_with_return() {
|
||||
let scheduler = ~new_test_uv_sched();
|
||||
Local::put(scheduler);
|
||||
let res = do Local::borrow::<Scheduler,bool> |_sched| {
|
||||
true
|
||||
};
|
||||
assert!(res)
|
||||
let _scheduler: ~Scheduler = Local::take();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ pub fn context() -> RuntimeContext {
|
|||
} else {
|
||||
if Local::exists::<Scheduler>() {
|
||||
let context = ::cell::empty_cell();
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
do Local::borrow::<Scheduler, ()> |sched| {
|
||||
if sched.in_task_context() {
|
||||
context.put_back(TaskContext);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -683,7 +683,7 @@ mod test {
|
|||
assert_eq!(count, MAX);
|
||||
|
||||
fn run_task(count_ptr: *mut int) {
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
do Local::borrow::<Scheduler, ()> |sched| {
|
||||
let task = ~do Coroutine::new(&mut sched.stack_pool) {
|
||||
unsafe {
|
||||
*count_ptr = *count_ptr + 1;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ impl Task {
|
|||
pub fn run(&mut self, f: &fn()) {
|
||||
// This is just an assertion that `run` was called unsafely
|
||||
// and this instance of Task is still accessible.
|
||||
do Local::borrow::<Task> |task| {
|
||||
do Local::borrow::<Task, ()> |task| {
|
||||
assert!(ptr::ref_eq(task, self));
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ impl Task {
|
|||
fn destroy(&mut self) {
|
||||
// This is just an assertion that `destroy` was called unsafely
|
||||
// and this instance of Task is still accessible.
|
||||
do Local::borrow::<Task> |task| {
|
||||
do Local::borrow::<Task, ()> |task| {
|
||||
assert!(ptr::ref_eq(task, self));
|
||||
}
|
||||
match self.storage {
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ mod test {
|
|||
if i == 100 { return; }
|
||||
|
||||
let tube = Cell(Cell(tube));
|
||||
do Local::borrow::<Scheduler> |sched| {
|
||||
do Local::borrow::<Scheduler, ()> |sched| {
|
||||
let tube = tube.take();
|
||||
do sched.event_loop.callback {
|
||||
let mut tube = tube.take();
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ mod test_remote {
|
|||
let mut tube = Tube::new();
|
||||
let tube_clone = tube.clone();
|
||||
let remote_cell = cell::empty_cell();
|
||||
do Local::borrow::<Scheduler>() |sched| {
|
||||
do Local::borrow::<Scheduler, ()>() |sched| {
|
||||
let tube_clone = tube_clone.clone();
|
||||
let tube_clone_cell = Cell(tube_clone);
|
||||
let remote = do sched.event_loop.remote_callback {
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ pub fn failing() -> bool {
|
|||
}
|
||||
_ => {
|
||||
let mut unwinding = false;
|
||||
do Local::borrow::<Task> |local| {
|
||||
do Local::borrow::<Task, ()> |local| {
|
||||
unwinding = match local.unwinder {
|
||||
Some(unwinder) => {
|
||||
unwinder.unwinding
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
|||
}
|
||||
_ => {
|
||||
let mut alloc = ::ptr::null();
|
||||
do Local::borrow::<Task> |task| {
|
||||
do Local::borrow::<Task,()> |task| {
|
||||
alloc = task.heap.alloc(td as *c_void, size as uint) as *c_char;
|
||||
}
|
||||
return alloc;
|
||||
|
|
@ -262,7 +262,7 @@ pub unsafe fn local_free(ptr: *c_char) {
|
|||
rustrt::rust_upcall_free_noswitch(ptr);
|
||||
}
|
||||
_ => {
|
||||
do Local::borrow::<Task> |task| {
|
||||
do Local::borrow::<Task,()> |task| {
|
||||
task.heap.free(ptr as *c_void);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue