Skip to content
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

WIP: Correctly instrument non-lazy Futures functions #1865

Closed
wants to merge 1 commit into from

Conversation

Swatinem
Copy link
Contributor

So far this is just a failing testcase of how I think the testcase from #1863 should behave at runtime.

I will be working on fixing up the code generation next.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

overall, this solution looks correct, i don't see any issues with the change. i did comment on some naming and other style nits --- currently, a lot of the code references the async-trait crate specifically, but this code will now work with all functions returning async blocks, regardless of whether they are generated by async-trait. so, it would be nice for the naming and comments to be updated to reflect that.

Comment on lines 377 to 388
#[instrument]
fn manual_impl_future() -> impl Future<Output = ()> {
async move {
tracing::trace!(poll = true);
}
}
#[instrument]
fn manual_box_pin() -> Pin<Box<dyn Future<Output = ()>>> {
Box::pin(async move {
tracing::trace!(poll = true);
})
}
Copy link
Member

Choose a reason for hiding this comment

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

nit, take it or leave it: personally, i think it would be nice if the boxed and non-boxed versions were in separate tests, so that we can always test both cases even if one fails, and know which one is broken. for example, my guess is that the Box::pin version currently does work on master, while the impl Future version doesn't; it would be nice if the tests indicated that.

Comment on lines 422 to 430
#[instrument]
fn hybrid_non_lazy_async() -> impl Future<Output = ()> {
tracing::trace!(call = true);
async move {
tracing::trace!(poll = true);
}
}
#[instrument]
fn hybrid_non_lazy_async_boxed() -> Pin<Box<dyn Future<Output = ()>>> {
tracing::trace!(call = true);
Box::pin(async move {
tracing::trace!(poll = true);
})
}
Copy link
Member

Choose a reason for hiding this comment

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

similarly, i have a slight preference for having separate tests for the pinned and unpinned cases.

Comment on lines 440 to 452
enum AsyncTraitKind<'a> {
// old construction. Contains the function
Function(&'a ItemFn),
// new construction. Contains a reference to the async block
Async(&'a ExprAsync),
// new construction. Contains a reference to the async block, and a bool
// indicating if the return value is a `Box::pin`
Async {
async_expr: &'a ExprAsync,
pinned_box: bool,
},
}
Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure if this should still be called AsyncTraitKind. since #[instrument] now handles all functions returning async blocks, not just those generated by the #[async_trait] macro, i think it would be nice to rename this type (and other types) to reflect that.

Async {
async_expr: &'a ExprAsync,
pinned_box: bool,
},
}

pub(crate) struct AsyncTraitInfo<'block> {
Copy link
Member

Choose a reason for hiding this comment

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

similarly, it seems like this is now used for all functions returning async blocks, not just those generated by async-trait. we should probably rename it.

Comment on lines 443 to 444
// new construction. Contains a reference to the async block, and a bool
// indicating if the return value is a `Box::pin`
Copy link
Member

Choose a reason for hiding this comment

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

maybe also re-word this comment to not be async-trait specific, as well?

Comment on lines 512 to 513
// check that the move 'keyword' is present
async_expr.capture?;
Copy link
Member

Choose a reason for hiding this comment

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

hmm, should we try to handle functions returning async blocks without the move keyword, too?

@hawkw
Copy link
Member

hawkw commented Jan 28, 2022

@Swatinem do you want to keep this PR open? AFAICT, it's been superseded by your other branches, is that correct?

@Swatinem
Copy link
Contributor Author

I will just close this for now. It has a failing test that I want to eventually succeed, but I want to work through some refactors first.

@Swatinem Swatinem closed this Jan 29, 2022
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