-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing continuation to function crashes compiler #7
Comments
So this is actually type-sound, as the type of We run into an issue however when trying to emit Thorin code for this, because thorin encodes returns with another parameter, so the type of the fn blub (cont: fn(fn() -> !) -> !, ret: fn() -> !) = ret()
fn while_loop_continue() = while_loop_head()
fn test_while_...() = blub(while_loop_continue) The solution ? Well Artic actually has some code already to deal with this edge case, but it isn't used in all contexts it seems, in particular when auto-casting it doesn't get called, so this is hopefully a simple refactor to fix. |
Wrote a fix (6cf219d), the output now looks sensible:
|
Is this fixed? Can we close the issue? |
I think so, I did write a fix, sadly the specifics are fuzzy to me. Since there was no activity afterwards, I guess that did it! Another issue can be opened if a similar problem arises. |
I'm afraid the problem does not appear to be resolved completely as I've run into it again. The following example fn ohnoes(throw: fn(&[u8]) -> ()) {
throw("");
}
#[export]
fn test() -> () {
let throw = return;
let handle_failure = @|msg: &[u8]| {
throw()
};
ohnoes(handle_failure);
} results in
And this slight variation of the example: fn ohnoes(throw: fn() -> ()) {
throw();
}
#[export]
fn test() -> () {
let throw = return;
let handle_failure = @|| {
throw()
};
ohnoes(handle_failure);
} triggers
|
I just debugged this, basically |
I'm afraid this now seems to break the following code that's part of the runtime (reduced sample): #[import(cc = "thorin")] fn opencl(_dev: i32, _grid: (i32, i32, i32), _block: (i32, i32, i32), _body: fn() -> ()) -> ();
struct WorkItem {}
struct Accelerator {
exec : fn(fn(WorkItem) -> ()) -> fn((i32, i32, i32), (i32, i32, i32)) -> (), // fn(grid, block)->()
}
fn @opencl_accelerator(dev: i32) = Accelerator {
exec = @|body| |grid, block| {
opencl(dev, grid, block, || @body(WorkItem {}))
}
}; produces
|
I also get an |
Sorry, that's what I get for pushing a "trivial" fix, on a Friday no less! I rolled back the patch and pushed again. I will open another issue on Monday to keep track of the wider problem. |
The following code will reproduce the issue:
Compiling the above code results in:
I assume this may be caused by the incorrect return type in the function type of the parameter the continuation is passed to.
One workaround seems to be wrapping the continuation in a lambda:
The text was updated successfully, but these errors were encountered: