Repository navigation
Make #[track_caller] async fn track the caller, not the poller/awaiter - #163396
theemathas wants to merge 9 commits into
Conversation
f21a754 to
7e01c99
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7e01c99 to
c87bff0
Compare
| if is_in_trait_impl { | ||
| // Check if we need to "inherit" #[track_caller] from the trait definition. | ||
| let Some(trait_item_def_id) = | ||
| self.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id()) | ||
| else { | ||
| self.dcx().span_delayed_bug(span, "could not resolve trait item being implemented"); | ||
| return false; | ||
| }; | ||
| return find_attr!(self.tcx, trait_item_def_id, TrackCaller(_)); | ||
| } |
There was a problem hiding this comment.
I don't understand what this is doing, but I'm doing the same thing as this existing code:
rust/compiler/rustc_ast_lowering/src/item.rs
Lines 1148 to 1155 in c1070d6
| /// | ||
| /// FIXME(async_fn_track_caller): What if the Location is stored inside a coroutine upvar? | ||
| fn resolve_tracked_call_location(body: &Body, inherited: Option<MirConst>) -> MirConst { |
There was a problem hiding this comment.
What is this, and do I need to modify it?
|
cc @rust-lang/miri Some changes occurred to the CTFE machinery Some changes occurred in compiler/rustc_attr_ir cc @jdonszelmann, @JonathanBrouwer Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
c87bff0 to
b14e6ed
Compare
This comment was marked as resolved.
This comment was marked as resolved.
b14e6ed to
e1d818f
Compare
This comment has been minimized.
This comment has been minimized.
e1d818f to
6fcdc09
Compare
|
I split up the implementation into multiple commits, hopefully making reviewing easier. (And also hopefully making it less confusing for me.) |
6fcdc09 to
473dbf0
Compare
#[track_caller] async fn track the caller, not the poller#[track_caller] async fn track the caller, not the poller/awaiter
473dbf0 to
57abba7
Compare
|
I've reimplemented this PR in the Miri portion so that it doesn't walk the stack, but instead passes the caller location argument down the stack, as per @RalfJung's suggestion. |
This comment has been minimized.
This comment has been minimized.
2f38293 to
4598eb9
Compare
|
cc @bjorn3 |
This comment has been minimized.
This comment has been minimized.
4598eb9 to
9c81c0d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…try> Make `#[track_caller] async fn` track the caller, not the poller/awaiter try-job: dist-x86_64-linux
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Added tests that are verified locally to pass for cranelift. @rustbot ready Edit: Maybe it might be better if I use |
822ca16 to
aa2bf51
Compare
…ter. Part 1: AST lowering
…ter. Part 2: MIR building
…ter. Part 3: misc
…ter. Part 4: codegen
…ter. Part 5: Miri
…ter. Part 6: Cranelift
aa2bf51 to
f857e66
Compare
|
Tested locally for cranelift by applying the following change and running diff --git a/tests/ui/async-await/track-caller/panic-track-caller.rs b/tests/ui/async-await/track-caller/panic-track-caller.rs
index 99dec25fdca..248db622bf6 100644
--- a/tests/ui/async-await/track-caller/panic-track-caller.rs
+++ b/tests/ui/async-await/track-caller/panic-track-caller.rs
@@ -1,15 +1,15 @@
// This test is duplicated (with changes) at
// src/tools/miri/tests/pass/async-panic-track-caller.rs
-
+//@ no-prefer-dynamic
//@ run-pass
//@ edition:2024
//@ revisions: nofeat afn cls afn_cls nofeat_opt afn_opt cls_opt afn_cls_opt
-//@[nofeat_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000
-//@[afn_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000
-//@[cls_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000
-//@[afn_cls_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000
+//@[nofeat_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000 -Cpanic=abort
+//@[afn_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000 -Cpanic=abort
+//@[cls_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000 -Cpanic=abort
+//@[afn_cls_opt] compile-flags: -O -Zinline-mir-hint-threshold=1000 -Cpanic=abort
+//@ compile-flags: -Cpanic=abort
// gate-test-async_fn_track_caller
-//
#![feature(stmt_expr_attributes, coroutines, coroutine_trait, gen_blocks)]
#![cfg_attr(any(afn, afn_cls, afn_opt, afn_cls_opt), feature(async_fn_track_caller))]
#![cfg_attr(any(cls, afn_cls, cls_opt, afn_cls_opt), feature(closure_track_caller))] |
View all comments
An LLM was used to locate relevant code, suggest ideas, and review the code. However, I manually wrote all code, and I take all responsibility for all code written and all decisions made.
Tracking issue (
async_fn_track_caller): #110011Related tracking issue (
closure_track_caller): #87417This PR is stacked on top of #163262 (first commit in this PR) and #163746 (the second commit in this PR, which was cherry-picked in). The third commit adds extensive tests for behavior touched in this PR. Commits 4-9 are the actual implementation, and also modification of the tests to reflect this new behavior.
This PR makes coroutines desugared from
#[track_caller] async fntrack the caller of the function, not the poller/awaiter of the coroutine. This is done as per T-lang's decision at #110011 (comment). The implementation modifies AST lowering to add an upvar to the coroutine, which stores the relevant caller location.In both codegen and in consteval/miri, we read the relevant upvar from the coroutine at the point in time where we need access to the
&Locationreference (either when we call thecaller_locationintrinsic, when we panic, or when we call another#[track_caller]function). We only dereference this reference as needed, when we actually need theLocationinformation.This PR changes the behavior of
async fn, but not ofasyncclosures, due to difficulties I've noted at #t-compiler/help > Help with `async_fn_track_caller` @ 💬This PR's implementation assumes that the desired behavior in #110011 (comment) is the behavior that I think makes the most sense.
This PR corrects the behavior of #163406 when the
async_fn_track_callerfeature is enabled, but does not give a warning when the feature is disabled (resulting in the pre-existing broken behavior).The tests pass on cranelift when I run
./x test ui --test-codegen-backend cranelift -- async-await/track-caller/panic-track-caller-no-unwind.rs. (Cranelift doesn't support unwinding.)r? compiler