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

Support #[track_caller] on async fns #104219

Merged
merged 6 commits into from
Nov 17, 2022

Conversation

bryangarza
Copy link
Contributor

@bryangarza bryangarza commented Nov 9, 2022

Adds #[track_caller] to the generator that is created when we desugar the async fn.

Fixes #78840

Open questions:

  • What is the performance impact of adding #[track_caller] to every GenFuture's poll(...) function, even if it's unused (i.e., the parent span does not set #[track_caller])? We might need to set it only conditionally, if the indirection causes overhead we don't want.

eholk and others added 3 commits October 10, 2022 16:00
This patch allows the usage of the `track_caller` annotation on
generators, as well as sets them conditionally if the parent also has
`track_caller` set.

Also add this annotation on the `GenFuture`'s `poll()` function.
@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2022

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 9, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@bryangarza
Copy link
Contributor Author

r? @eholk

@rustbot rustbot assigned eholk and unassigned jackh726 Nov 9, 2022
compiler/rustc_ast_lowering/src/expr.rs Outdated Show resolved Hide resolved
@@ -86,7 +86,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
allow_gen_future: Some([sym::gen_future][..].into()),
allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()),
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it makes sense to split gen_future and closure_track_caller into separate entires?

I think it's fine like this, since allow_gen_future is only used in one place and since we want track caller to work we also need the closure_track_caller feature. Separating them seems like extra work with little benefit.

@eholk
Copy link
Contributor

eholk commented Nov 10, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2022

📌 Commit 509b947 has been approved by eholk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 10, 2022
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 10, 2022
… r=eholk

Support `#[track_caller]` on async fns

Adds `#[track_caller]` to the generator that is created when we desugar the async fn.

Fixes rust-lang#78840

Open questions:
- What is the performance impact of adding `#[track_caller]` to every `GenFuture`'s `poll(...)` function, even if it's unused (i.e., the parent span does not set `#[track_caller]`)? We might need to set it only conditionally, if the indirection causes overhead we don't want.
@matthiaskrgr
Copy link
Member

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 10, 2022
@bryangarza
Copy link
Contributor Author

The failure

 failures:

---- [ui] src/test/ui/async-await/track-caller/panic-track-caller.rs stdout ----

error: test run failed!
status: exit status: 101
command: "/node-v15.14.0-linux-x64/bin/node" "/checkout/src/etc/wasm32-shim.js" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/async-await/track-caller/panic-track-caller/a.wasm"
stdout: none
--- stderr -------------------------------
RuntimeError: unreachable
    at __rust_start_panic (<anonymous>:wasm-function[94]:0x5a97)
    at rust_panic (<anonymous>:wasm-function[91]:0x5a5d)
    at _ZN3std9panicking20rust_panic_with_hook17h0c233e78e6112adfE (<anonymous>:wasm-function[90]:0x5a2d)
    at _ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17hf994fd019a2fd642E (<anonymous>:wasm-function[77]:0x4a54)
    at _ZN3std10sys_common9backtrace26__rust_end_short_backtrace17ha238eeecdfc892b1E (<anonymous>:wasm-function[76]:0x49b9)
    at rust_begin_unwind (<anonymous>:wasm-function[85]:0x5681)
    at _ZN4core9panicking9panic_fmt17ha1487ae10087c69cE (<anonymous>:wasm-function[140]:0x63bf)
    at _ZN4core9panicking5panic17heb919bbe7cf670eaE (<anonymous>:wasm-function[143]:0x680c)
    at _ZN3std5panic12catch_unwind17h79eba0ed8ab51e6aE (<anonymous>:wasm-function[2]:0x230)
    at _ZN18panic_track_caller4main17h0fa14fb0b64e685eE (<anonymous>:wasm-function[14]:0x66a)
    at _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h363919328fe77852E (<anonymous>:wasm-function[0]:0x1cf)
    at _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h226d7bc4ae73ce06E (<anonymous>:wasm-function[1]:0x1f1)
    at _ZN3std2rt19lang_start_internal17h8bbe173c9dd6e6e6E (<anonymous>:wasm-function[64]:0x3f60)
    at main (<anonymous>:wasm-function[15]:0x6b2)
    at Object.<anonymous> (/checkout/src/etc/wasm32-shim.js:20:20)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
------------------------------------------



failures:
    [ui] src/test/ui/async-await/track-caller/panic-track-caller.rs

test result: FAILED. 13105 passed; 1 failed; 704 ignored; 0 measured; 0 filtered out; finished in 92.50s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=wasm32-unknown-unknown

@bryangarza
Copy link
Contributor Author

bryangarza commented Nov 10, 2022

@matthiaskrgr @eholk do we need to ignore the wasm target? I just noticed this on a few other UI tests

// ignore-wasm no panic or subprocess support
// ignore-emscripten no panic or subprocess support

@tmandry
Copy link
Member

tmandry commented Nov 12, 2022

@bryangarza Please use // needs-unwind instead of ignoring individual targets. That way if std is built with panic=abort the test will still be ignored.

(Alternatively you might be able to let the process abort instead of catching the panic, and assert that the panic output itself contains the desired file/line; not sure how well it will work though.)

@bryangarza
Copy link
Contributor Author

@bryangarza Please use // needs-unwind instead of ignoring individual targets. That way if std is built with panic=abort the test will still be ignored.

(Alternatively you might be able to let the process abort instead of catching the panic, and assert that the panic output itself contains the desired file/line; not sure how well it will work though.)

oh okay thanks, I’ll update it to // needs-unwind tomorrow

@bryangarza
Copy link
Contributor Author

@eholk - I think we can try adding it to the rollup again

@eholk
Copy link
Contributor

eholk commented Nov 15, 2022

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Nov 15, 2022

📌 Commit 79c06fc has been approved by eholk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 15, 2022
@Manishearth
Copy link
Member

@bors p=1

going to close the tree for non-nevers for a while so they can drain out

@bors
Copy link
Contributor

bors commented Nov 17, 2022

⌛ Testing commit 79c06fc with merge b6097f2...

@bors
Copy link
Contributor

bors commented Nov 17, 2022

☀️ Test successful - checks-actions
Approved by: eholk
Pushing b6097f2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 17, 2022
@bors bors merged commit b6097f2 into rust-lang:master Nov 17, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 17, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b6097f2): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Comment on lines +620 to +624
let parent_has_track_caller = self
.attrs
.values()
.find(|attrs| attrs.into_iter().find(|attr| attr.has_name(sym::track_caller)).is_some())
.is_some();
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this is very broken, the parent here might be just a normal function, not necessarily the desugaring of an async fn, see #105134

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…=eholk

Support `#[track_caller]` on async fns

Adds `#[track_caller]` to the generator that is created when we desugar the async fn.

Fixes rust-lang#78840

Open questions:
- What is the performance impact of adding `#[track_caller]` to every `GenFuture`'s `poll(...)` function, even if it's unused (i.e., the parent span does not set `#[track_caller]`)? We might need to set it only conditionally, if the indirection causes overhead we don't want.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[track_caller] does nothing on async fns
10 participants