Skip to content

RustFuture: Clarify Send bound and switch to RawWaker #2574

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

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Jun 19, 2025

Updated the unsafe impl Send for WrappedFuture docstring. I believe the new docs describe the situation more accurately.

Moved back to using RawWaker because I want to drop the need for WrappedFuture to be Send. WrappedFuture will not always be Send when wasm-unstable-single-threaded is enabled. The current waker creation depends on RustFuture being Send which depends on WrappedFuture being Send (https://doc.rust-lang.org/std/task/struct.Waker.html#impl-From%3CArc%3CW%3E%3E-for-Waker).

As a side bonus, I think the tracing printouts will improve.

@bendk bendk requested a review from a team as a code owner June 19, 2025 15:52
@bendk bendk requested review from badboy and removed request for a team June 19, 2025 15:52
//
// In addition, `WrappedFuture::result` can be a raw pointer which is `!Send`.
// This `!Send` bound is because Rust can't uphold safety guarantees for raw pointers.
// However, this code does in fact treat the pointers correctly, for example we only return them across the FFI once.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhugman Does this seem correct to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// If the `wasm-unstable-single-threaded` feature is enabled, then the wrapped future may not be `Send`, and thus `WrappedFuture` is not Send either.
// This seems okay for now, since if `wasm-unstable-single-threaded` then futures should stay on one thread.

This seems correct.

I'm not sure I can comment on the rest of the comment though.

@bendk bendk force-pushed the push-ypnrlvnttsvo branch from e1d440a to 91cd353 Compare June 19, 2025 15:53
Updated the `unsafe impl `Send` for WrappedFuture` docstring.
I believe the new docs describe the situation more accurately.

Moved back to using `RawWaker` because I want to drop the need for
WrappedFuture to be `Send`. `WrappedFuture` will not always be `Send`
when `wasm-unstable-single-threaded` is enabled. The current waker
creation depends on `RustFuture` being `Send` which depends on
`WrappedFuture` being `Send`
(https://doc.rust-lang.org/std/task/struct.Waker.html#impl-From%3CArc%3CW%3E%3E-for-Waker).

As a side bonus, I think the tracing printouts will improve.
@bendk bendk merged commit 7986803 into mozilla:main Jun 23, 2025
5 checks passed
@bendk bendk deleted the push-ypnrlvnttsvo branch June 23, 2025 15:03
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.

3 participants