-
Notifications
You must be signed in to change notification settings - Fork 756
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
attributes: fix compile error with instrumented async functions #1616
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments.
davidbarsky
approved these changes
Oct 5, 2021
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
## Motivation The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). ## Solution This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments. I've also added tests reproducing issue #1615 Fixes #1615
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
## Motivation The changes in #1607 introduced a potential compilation error when using the `#[instrument]` attribute on `async fn`s that return a type that includes a closure or is otherwise unnameable. This is because the future's body code was quoted in two separate places in order to have a separate branch when the span is statically disabled. This means that when a closure is returned, it will technically have two distinct types based on whether or not the span is enabled, since it originates from two separate source code locations (although `quote_spanned!` obscures this, so the compiler diagnostic will appear to have two closures originating from the same location). ## Solution This branch fixes this issue by changing the code generated for `#[instrument]`ed async functions. Unfortunately, for async functions, we can't have the optimization of not creating the span at all when the level is disabled, because we need to create the span _before_ creating the future, as it may borrow arguments. I've also added tests reproducing issue #1615 Fixes #1615
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
# 0.1.17 (October 1, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
# 0.1.17 (October 1, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
# 0.1.18 (October 5, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([#1614]) [#1617]: #1617 [#1616]: #1616 [#1614]: #1614
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
hawkw
added a commit
that referenced
this pull request
Oct 5, 2021
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
hawkw
added a commit
that referenced
this pull request
Oct 6, 2021
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1605]: #1605 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
kaffarell
pushed a commit
to kaffarell/tracing
that referenced
this pull request
May 22, 2024
# 0.1.18 (October 5, 2021) This release fixes issues introduced in v0.1.17. ### Fixed - fixed mismatched types compiler error that may occur when using `#[instrument]` on an `async fn` that returns an `impl Trait` value that includes a closure ([tokio-rs#1616]) - fixed false positives for `clippy::suspicious_else_formatting` warnings due to rust-lang/rust-clippy#7760 and rust-lang/rust-clippy#6249 ([tokio-rs#1617]) - fixed `clippy::let_unit_value` lints when using `#[instrument]` ([tokio-rs#1614]) [tokio-rs#1617]: tokio-rs#1617 [tokio-rs#1616]: tokio-rs#1616 [tokio-rs#1614]: tokio-rs#1614
kaffarell
pushed a commit
to kaffarell/tracing
that referenced
this pull request
May 22, 2024
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([tokio-rs#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([tokio-rs#1600], [tokio-rs#1605], [tokio-rs#1614], [tokio-rs#1616], [tokio-rs#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([tokio-rs#1602]) - Documentation fixes and improvements ([tokio-rs#1595], [tokio-rs#1601], [tokio-rs#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [tokio-rs#1585]: tokio-rs#1585 [tokio-rs#1595]: tokio-rs#1596 [tokio-rs#1597]: tokio-rs#1597 [tokio-rs#1600]: tokio-rs#1600 [tokio-rs#1601]: tokio-rs#1601 [tokio-rs#1602]: tokio-rs#1602 [tokio-rs#1605]: tokio-rs#1605 [tokio-rs#1614]: tokio-rs#1614 [tokio-rs#1616]: tokio-rs#1616 [tokio-rs#1617]: tokio-rs#1617
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The changes in #1607 introduced a potential compilation error when using
the
#[instrument]
attribute onasync fn
s that return a type thatincludes a closure or is otherwise unnameable. This is because the
future's body code was quoted in two separate places in order to have a
separate branch when the span is statically disabled. This means that
when a closure is returned, it will technically have two distinct types
based on whether or not the span is enabled, since it originates from
two separate source code locations (although
quote_spanned!
obscuresthis, so the compiler diagnostic will appear to have two closures
originating from the same location).
Solution
This branch fixes this issue by changing the code generated for
#[instrument]
ed async functions. Unfortunately, for async functions,we can't have the optimization of not creating the span at all when the
level is disabled, because we need to create the span before creating
the future, as it may borrow arguments.
Fixes #1615