-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Internal Compiler Error on stable (Broken MIR) #96512
Comments
I've discovered that destructuring the enum variant outside of the async block fixes the issue |
@conradludgate amazing that you did reduce your testcase like that. struct Variant;
enum Enum {
Variant(Variant),
}
fn spawn<T>(_: T)
where
T: std::future::Future Send 'static,
T::Output: Send 'static,
{
}
async fn dispatch(_: Variant) {}
fn main() {
let eh = Enum::Variant(Variant);
spawn(async move {
let Enum::Variant(value) = eh;
dispatch(value).await;
});
} Regressed in rollup #91555 probably in #91450 searched nightlies: from nightly-2021-12-01 to nightly-2022-04-24 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --end=2022-04-24 --without-cargo --access=github --regress=ice |
Reduced a bit more (requires an edition with precise captures, I think): struct Struct;
enum Enum { Variant(Struct) }
fn main() {
let _enum = Enum::Variant(Struct);
|| {
let Enum::Variant(_value) = _enum;
};
} |
If no one is yet investigating this, I'd like to pick it up |
So far, I've found 2 issues that cause this behaviour. The first is that it's having trouble in this context to get the field type of the single variant enum:
Fix is easy, - ty::Adt(adt_def, substs) if !adt_def.is_enum() => {
ty::Adt(adt_def, substs) if adt_def.variants().len() == 1 => { The second issue is that the MIR is being badly formed. Looking at the traces, I see
Which hints to me that the code is not being read as let Enum::Variant(_value) = _enum; but instead let Enum::Variant(Struct(_value)) = _enum; |
Yeah, it looks like constructed MIR is incorrect. One issue seems to be in There seems to be one more issue when constructing the capture - the downcasting operation is completely missing. While the documentation for MIR
I think that is an outdated information. |
I also just noticed the Downcast issue. In my traces, I do see the variant projection using this Downcast for just a single variant, and the suspect PR changes does seem to ignore all Downcast projections (there's a little bit of discussion taking place on zulip https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/reading.20MIR.20.28.2396512.29/near/280855883) |
Should the fix be
|
@arora-aman or @roxelo might be in a better position to give advice here. I think we should keep and / or add downcast where they are currently missing (e.g., when constructing the closure), and fix how projections corresponding to captured prefix are removed. As far the latter aspect is concerned, I think the issue is in the following lines ( rust/compiler/rustc_mir_build/src/build/expr/as_place.rs Lines 271 to 278 in 905fd73
|
I vaguely recall we relied on this to detect if we had a multi variant enum, in which case we would completely capture the root variable. Edit: Ignore that, scrolling into the code bit more, there is comment that Downcast can be expected for single-variant enums |
@conradludgate are you still planning to work on this issue? |
Not currently, I spent a few full days looking but I don't want to risk burning out debugging something that I don't completely understand 😓. I hope I at least narrowed it down a bit |
…-aman Fix precise field capture of univariant enums When constructing a MIR from a THIR field expression, introduce an additional downcast projection before accessing a field of an enum. When rebasing a place builder on top of a captured place, account for the fact that a single HIR enum field projection corresponds to two MIR projection elements: a downcast element and a field element. Fixes rust-lang#95271. Fixes rust-lang#96299. Fixes rust-lang#96512. Fixes rust-lang#97378. r? `@nikomatsakis` `@arora-aman`
Code
There's only so much that I can share. The code that seems to be erroring is similar to
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: