-
-
Notifications
You must be signed in to change notification settings - Fork 91
Optional sync futures, async block #125
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
Conversation
* Works with single trait bound.Notfor lifetimes or multiple bounds
|
Hi @dtolnay, kindly review. [SOLVED] Currently when I take my fork as a dependency it fails on syn::* types equality. Any idea? While all is green in async-trait. [dependencies]
async-trait = { git = "https://github.com/BrightOpen/async-trait.git", branch = "feature/sync-futures-#77" }results in a few of these: |
* generated README.md from lib.rs with `cargo readme` * more tests * documentation ofnew feature and improved support for elided lifetimes.
Solved thanks to @link2xt - added "extra-traits" feature for syn. Meanwhile, added docs and tests, updated README.md |
dtolnay
left a comment
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 for the PR. I don't think the async block stuff is a correct change. See for example this code:
use async_trait::async_trait;
#[async_trait]
trait Trait {
async fn f(_: Plop);
}
struct Struct;
#[async_trait]
impl Trait for Struct {
async fn f(_: Plop) {
println!("Struct::f");
}
}
struct Plop;
impl Drop for Plop {
fn drop(&mut self) {
println!("plop");
}
}
async fn standalone_f(_: Plop) {
println!("standalone_f");
}
fn main() {
futures::executor::block_on(Struct::f(Plop));
futures::executor::block_on(standalone_f(Plop));
}Before:
Struct::f
plop
standalone_f
plopThis PR:
plop
Struct::f
standalone_f
plopAs you can see, before this PR the async trait method had behavior that is consistent with an async non-trait method, and after this PR it does something different.
|
Hi @dtolnay, thanks for the feedback. From your example, I understand that an unused value is dropped before the async block is executed. A useful optimization in the discretion of the compiler without effect on functionality. Perhaps the next version of rust will optimize the async fn similarly... What would happen if you used the variable in the printout or explicitly dropped it after? |
dtolnay
left a comment
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.
A useful optimization in the discretion of the compiler without effect on functionality.
This is not correct.
Perhaps the next version of rust will optimize the async fn similarly.
This would definitely not be allowed.
Drop reordering is not "an optimization". Drop order is extremely sensitive and governed by language semantics, not compiler optimization. Drop happening in a precisely defined place is what makes mutex guards possible, for example.
|
I think I'll close for now, since this is pretty hard to review with the unrelated changes included together. Please open a new PR without drop order changes or the readme changes. |
|
The improvements plus better support for |
#[future_is[BOUNDS]]attribute for async fns so you can opt in for Sync or 'static futureasync moveblock instead of inner function as it removed a whole lot of complexity and enabled the 'static stuff