Skip to content

fix lowering results for async exports#1129

Merged
dicej merged 1 commit intobytecodealliance:mainfrom
dicej:async-lower-result-fix
Jan 17, 2025
Merged

fix lowering results for async exports#1129
dicej merged 1 commit intobytecodealliance:mainfrom
dicej:async-lower-result-fix

Conversation

@dicej
Copy link
Copy Markdown
Collaborator

@dicej dicej commented Jan 16, 2025

Previously, we were either dropping the result too early (e.g. wit_bindgen_rt::async_support::ErrorContext) or not at all (e.g. String and Vec) due to the lowering code expecting to pass ownership to the caller, which would later free memory using a post-return function. But async exports don't have post-return functions; they use task.return instead, and they should free any memory (and/or drop handles) after task.return returns. So now we do that!

@dicej dicej requested a review from alexcrichton January 16, 2025 22:51
@dicej dicej force-pushed the async-lower-result-fix branch from d61497b to 3e8b215 Compare January 16, 2025 22:55
@dicej
Copy link
Copy Markdown
Collaborator Author

dicej commented Jan 16, 2025

Oof, looks like I broke the codegen tests 🤦 ; will fix. EDIT: done

Previously, we were either dropping the result too early
(e.g. `wit_bindgen_rt::async_support::ErrorContext`) or not at all
(e.g. `String` and `Vec`) due to the lowering code expecting to pass ownership
to the caller, which would later free memory using a post-return function.  But
async exports don't have post-return functions; they use `task.return` instead,
and they should free any memory (and/or drop handles) after `task.return`
returns.  So now we do that!

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej force-pushed the async-lower-result-fix branch from 3e8b215 to 7003da6 Compare January 16, 2025 23:15
@dicej dicej added this pull request to the merge queue Jan 17, 2025
Merged via the queue into bytecodealliance:main with commit e566d45 Jan 17, 2025
@dicej dicej deleted the async-lower-result-fix branch January 17, 2025 17:16
dicej added a commit to rvolosatovs/wit-bindgen that referenced this pull request Jan 21, 2025
Previously, we were either dropping the result too early
(e.g. `wit_bindgen_rt::async_support::ErrorContext`) or not at all
(e.g. `String` and `Vec`) due to the lowering code expecting to pass ownership
to the caller, which would later free memory using a post-return function.  But
async exports don't have post-return functions; they use `task.return` instead,
and they should free any memory (and/or drop handles) after `task.return`
returns.  So now we do that!

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants