-
Notifications
You must be signed in to change notification settings - Fork 232
[C#] Simple Async support #1346
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # Cargo.lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a solid start, thanks!
return (uint)CallbackCode.Yield; | ||
"#); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to add a "TODO" comment here to remember to defer dropping borrowed resources until a result is returned (i.e. just before calling {name}TaskReturn
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done
"# | ||
); | ||
|
||
let task_return_param = match &sig.results[..] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task return function could accept up to 16 core parameters (e.g. 2 for a string
, 5 for a tuple<string, list<u8>, u32>
, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping I'll be forced to address all these shortcuts as I go through enabling the tests. If not, then I've added a TODO here and I can address the todo's at the end.
crates/csharp/src/function.rs
Outdated
let requires_async_return_buffer_param = is_async && sig.results.len() >= 1; | ||
let async_return_buffer = if requires_async_return_buffer_param { | ||
let buffer = self.emit_allocation_for_type(&sig.results); | ||
uwriteln!(self.src, "//TODO: store somewhere with the TaskCompletionSource."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use new TaskCompletionSource(object? state)
-> Task.AsyncState
Probably with some (internal?) helper struct/class to hold allocations and handles that you need to cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've updated the comment here, as per the remark above I'm hoping to be forced to address all these as I go through enabling the tests.
Could you please create and link a gist with the generated code ? Thank you. |
https://gist.github.com/yowl/72b406c9604b5ff4c170e441fb3e88c8 Has the code gen and copies of the harness code from this repo. |
Have reverted the code gen interop output as that is a bigger change than can be snuck in here. |
This PR add the very minimal changes to enable the first async functions tests to pass. These tests return immediately which means a lot of the callback, waitable, changes are not done yet. There are no TaskCompletionSources created, we just set the return value on the task. User code will look like
https://github.com/bytecodealliance/wit-bindgen/pull/1346/files#diff-f34015927bd91d8f86e20e1a9258891caad407de6a499fcf977cb1165c89b3a5
and
https://github.com/bytecodealliance/wit-bindgen/pull/1346/files#diff-756d40996fd1204ae5975dd4da40e815b827d804c27b13dd36f69b6612ced825
Which should be idiomatic.
Thanks @dicej for the help in Zulip.