-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Drop tracking ICE involving await in left hand side of assignment (-Zdrop-tracking
)
#102383
Comments
@rustbot label +T-compiler +C-bug |
@rustbot label +AsyncAwait-Triaged |
After playing a little bit with this today, as posted also on Zulip I can have a thesis that can make sense, I take a look to the following crates report https://crater-reports.s3.amazonaws.com/pr-97334-1/try%23b755f8b9936d084e0363ce6b393c7e444a37080e/gh/88IO.blogpost-rs/log.txt where the message crash is the following one Broken MIR: generator contains type CurrentUser in MIR, but typeck only knows about {ResumeTy, &Handler, serenity::prelude::Context, serenity::model::channel::Message, impl std::future::Future<Output = CurrentUser>, (), bool, String, Arc<serenity::http::Http>, impl std::future::Future<Output = Result<serenity::model::channel::Message, SerenityError>>, Handler, Option<regex::Captures>, regex::Captures, u64, Token, impl std::future::Future<Output = Result<Response<egg_mode::tweet::Tweet>, egg_mode::error::Error>>, impl std::future::Future<Output = Result<Reaction, SerenityError>>, &DraftTweet, DraftTweet, impl std::future::Future<Output = Result<Response<egg_mode::tweet::Tweet>, egg_mode::error::Error>>, Response<egg_mode::tweet::Tweet>, impl std::future::Future<Output = Result<serenity::model::channel::Message, SerenityError>>} and [&Handler, serenity::prelude::Context, serenity::model::channel::Message] Where the MIR known type does not know the type CurrentUser but knows the type |
Yeah, so for some more background, this bug is with a new generator capture analysis called Drop Tracking. Drop tracking is more precise than the current analysis, which means that it finds fewer types in the generator type than before (basically, the current analysis has a lot of false positives and drop tracking has less of them). This analysis happens during type checking, and then the code is lowered to MIR. In MIR a similar analysis is done to find the values that need to be captured as part of the generator state. The MIR analysis is also more conservative than in strictly needs to be (it also has false positives), so sometimes we have to make drop tracking less aggressive than it could be to match the MIR analysis. We've had a lot of bugs like that so far, so I would expect that's what's going on here. That said, it could also be that the drop tracking analysis is bad and is missing something that it actually should be finding. |
Minimal Exaple to reproduce it pub struct File<B> {
block: B,
}
pub async fn commit<B: Clone>(this: &mut File<B>) {
async {}.await;
async {}.await;
async {}.await;
async {}.await;
let file = async { &this }.await;
*async { &mut this.block }.await = file.block.clone();
}
fn main() {
let mut file = File {
block: String::new(),
};
let _ = async move {
commit(&mut file).await;
};
} |
@rustbot claim |
Taking a look at this one this sprint |
passing the task to @bryangarza noted that I had a couple of think on my plate already and I do not want have to much fun alone! I will be available for help if needed! |
fyi @vincenzopalazzo I have been looking at other tasks so I have not been able to get to this -- unassigned myself for now |
@eholk has this been fixed? Can you still reproduce this ice? |
This issue still reproduces with |
-Zdrop-tracking
)
I found another instance of this: use std::collections::HashMap;
fn main() {
let _ = real_main();
}
async fn nop() {}
async fn real_main() {
nop().await;
nop().await;
nop().await;
nop().await;
let mut map: HashMap<(), ()> = HashMap::new();
map.insert((), nop().await);
} Once again we have the four load-bearing |
@rustbot claim I'm going to take a look at fixing this. |
Okay, I made some progress this afternoon so I wanted to update here. The problem is that we refer to yields by where they come up in a post-order traversal of the HIR tree, but we have some disagreement in how they are counted. For a loop that gets desugared from a I've started a branch that will eventually have a fix, but for now I've just added some more debug logging and assertions to detect this drift better. I looked for places in |
…r=wesleywiser [drop tracking] Visit break expressions This fixes rust-lang#102383 by remembering to visit the expression in `break expr` when building the drop tracking CFG. Missing this step was causing an off-by-one error which meant after a number of awaits we'd be looking for dropped values at the wrong point in the code. Additionally, this changes the order of traversal for assignment expressions to visit the rhs and then the lhs. This matches what is done elsewhere. Finally, this improves some of the debugging output (for example, the CFG visualizer) to make it easier to figure out these sorts of issues.
…r=wesleywiser [drop tracking] Visit break expressions This fixes rust-lang#102383 by remembering to visit the expression in `break expr` when building the drop tracking CFG. Missing this step was causing an off-by-one error which meant after a number of awaits we'd be looking for dropped values at the wrong point in the code. Additionally, this changes the order of traversal for assignment expressions to visit the rhs and then the lhs. This matches what is done elsewhere. Finally, this improves some of the debugging output (for example, the CFG visualizer) to make it easier to figure out these sorts of issues.
This was found during the most recent crater run for #97334. The test case below is reduced from https://github.com/haydnv/tinychain.
This ICEs with the following message:
My guess is that the
B
that MIR and typeck disagree on is the one produced byfile.block.clone()
.Weirdly, if any of the
async {}.await
lines are removed, the program compiles successfully.The text was updated successfully, but these errors were encountered: