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

ICE: inconsistent resolution for an import #124490

Closed
matthiaskrgr opened this issue Apr 28, 2024 · 5 comments · Fixed by #124840 or #126065
Closed

ICE: inconsistent resolution for an import #124490

matthiaskrgr opened this issue Apr 28, 2024 · 5 comments · Fixed by #124840 or #126065
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

use io::{self as std};
use std::collections::{self as io};

original:

use std::collections::{self as io};
use io::{self as std};

Version information

rustc 1.80.0-nightly (91d5e4af8 2024-04-28)
binary: rustc
commit-hash: 91d5e4af8674bde06096bac1e7ac04af0e94c691
commit-date: 2024-04-28
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zunstable-options --edition=2024

Program output

error: internal compiler error: compiler/rustc_resolve/src/imports.rs:884:25: inconsistent resolution for an import
 --> /tmp/icemaker_global_tempdir.7N3g3X1DaYFn/rustc_testrunner_tmpdir_reporting.hyRGLJm0FCJ6/mvce.rs:2:24
  |
2 | use std::collections::{self as io};
  |                        ^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_resolve/src/imports.rs:884:25:
Box<dyn Any>
stack backtrace:
   0:     0x7b6b0a636035 - std::backtrace_rs::backtrace::libunwind::trace::ha90ea7a57c64b8ab
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7b6b0a636035 - std::backtrace_rs::backtrace::trace_unsynchronized::ha58e55f622939b6e
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7b6b0a636035 - std::sys_common::backtrace::_print_fmt::h687007ed504e7e64
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7b6b0a636035 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hecfae54cdc6fec81
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7b6b0a68529b - core::fmt::rt::Argument::fmt::h1cf6305de42401ed
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/core/src/fmt/rt.rs:165:63
   5:     0x7b6b0a68529b - core::fmt::write::hb74fc275648248fb
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/core/src/fmt/mod.rs:1157:21
   6:     0x7b6b0a62abdf - std::io::Write::write_fmt::h5209ffd8e6502f0c
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/io/mod.rs:1832:15
   7:     0x7b6b0a635e0e - std::sys_common::backtrace::_print::h168707047d27c84e
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7b6b0a635e0e - std::sys_common::backtrace::print::h2942d174d6b0e46d
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7b6b0a638779 - std::panicking::default_hook::{{closure}}::h4215c46ca923b014
  10:     0x7b6b0a6384bd - std::panicking::default_hook::h887f937d01fa1b64
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/panicking.rs:298:9
  11:     0x7b6b06e40a1c - std[aaff33ccdb7ea7e2]::panicking::update_hook::<alloc[d1c3a5de2ae3927d]::boxed::Box<rustc_driver_impl[d0a4257edbfecd8c]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7b6b0a638e76 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfe27c2dc23f9f057
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/alloc/src/boxed.rs:2036:9
  13:     0x7b6b0a638e76 - std::panicking::rust_panic_with_hook::h6ef218c13552449b
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/panicking.rs:799:13
  14:     0x7b6b06e70374 - std[aaff33ccdb7ea7e2]::panicking::begin_panic::<rustc_errors[6ff9940fea39db99]::ExplicitBug>::{closure#0}
  15:     0x7b6b06e6cff6 - std[aaff33ccdb7ea7e2]::sys_common::backtrace::__rust_end_short_backtrace::<std[aaff33ccdb7ea7e2]::panicking::begin_panic<rustc_errors[6ff9940fea39db99]::ExplicitBug>::{closure#0}, !>
  16:     0x7b6b06e6ccd6 - std[aaff33ccdb7ea7e2]::panicking::begin_panic::<rustc_errors[6ff9940fea39db99]::ExplicitBug>
  17:     0x7b6b06e79181 - <rustc_errors[6ff9940fea39db99]::diagnostic::BugAbort as rustc_errors[6ff9940fea39db99]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7b6b076ede48 - <rustc_errors[6ff9940fea39db99]::DiagCtxt>::span_bug::<rustc_span[6a84a2dd20c85103]::span_encoding::Span, alloc[d1c3a5de2ae3927d]::string::String>
  19:     0x7b6b0770a73d - rustc_middle[783a1d49f02736b7]::util::bug::opt_span_bug_fmt::<rustc_span[6a84a2dd20c85103]::span_encoding::Span>::{closure#0}
  20:     0x7b6b0770a76a - rustc_middle[783a1d49f02736b7]::ty::context::tls::with_opt::<rustc_middle[783a1d49f02736b7]::util::bug::opt_span_bug_fmt<rustc_span[6a84a2dd20c85103]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7b6b07704c8b - rustc_middle[783a1d49f02736b7]::ty::context::tls::with_context_opt::<rustc_middle[783a1d49f02736b7]::ty::context::tls::with_opt<rustc_middle[783a1d49f02736b7]::util::bug::opt_span_bug_fmt<rustc_span[6a84a2dd20c85103]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7b6b05906ec7 - rustc_middle[783a1d49f02736b7]::util::bug::span_bug_fmt::<rustc_span[6a84a2dd20c85103]::span_encoding::Span>
  23:     0x7b6b0923d880 - <rustc_resolve[956dd1017de6f360]::Resolver>::resolve_crate::{closure#0}
  24:     0x7b6b09234c9c - <rustc_resolve[956dd1017de6f360]::Resolver>::resolve_crate
  25:     0x7b6b0881032b - rustc_interface[3360209938edb6a7]::passes::resolver_for_lowering_raw
  26:     0x7b6b0880f567 - rustc_query_impl[77a161a94332e7e1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[77a161a94332e7e1]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[783a1d49f02736b7]::query::erase::Erased<[u8; 16usize]>>
  27:     0x7b6b0880f555 - <rustc_query_impl[77a161a94332e7e1]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[8db7010e98043ac]::ops::function::FnOnce<(rustc_middle[783a1d49f02736b7]::ty::context::TyCtxt, ())>>::call_once
  28:     0x7b6b09002e85 - rustc_query_system[61cd216fcfa07925]::query::plumbing::try_execute_query::<rustc_query_impl[77a161a94332e7e1]::DynamicConfig<rustc_query_system[61cd216fcfa07925]::query::caches::SingleCache<rustc_middle[783a1d49f02736b7]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[77a161a94332e7e1]::plumbing::QueryCtxt, false>
  29:     0x7b6b09002a01 - rustc_query_impl[77a161a94332e7e1]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7b6b08ea30be - rustc_interface[3360209938edb6a7]::interface::run_compiler::<core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>, rustc_driver_impl[d0a4257edbfecd8c]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7b6b08e727c9 - std[aaff33ccdb7ea7e2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3360209938edb6a7]::util::run_in_thread_with_globals<rustc_interface[3360209938edb6a7]::util::run_in_thread_pool_with_globals<rustc_interface[3360209938edb6a7]::interface::run_compiler<core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>, rustc_driver_impl[d0a4257edbfecd8c]::run_compiler::{closure#0}>::{closure#1}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>::{closure#0}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>
  32:     0x7b6b08e72576 - <<std[aaff33ccdb7ea7e2]::thread::Builder>::spawn_unchecked_<rustc_interface[3360209938edb6a7]::util::run_in_thread_with_globals<rustc_interface[3360209938edb6a7]::util::run_in_thread_pool_with_globals<rustc_interface[3360209938edb6a7]::interface::run_compiler<core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>, rustc_driver_impl[d0a4257edbfecd8c]::run_compiler::{closure#0}>::{closure#1}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>::{closure#0}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8db7010e98043ac]::result::Result<(), rustc_span[6a84a2dd20c85103]::ErrorGuaranteed>>::{closure#2} as core[8db7010e98043ac]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7b6b0a642cab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1c1c6804813d5e77
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/alloc/src/boxed.rs:2022:9
  34:     0x7b6b0a642cab - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3d84aa3b40a67b8f
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/alloc/src/boxed.rs:2022:9
  35:     0x7b6b0a642cab - std::sys::pal::unix::thread::Thread::new::thread_start::h60cefba2ee6cce64
                               at /rustc/91d5e4af8674bde06096bac1e7ac04af0e94c691/library/std/src/sys/pal/unix/thread.rs:108:17
  36:     0x7b6b0a3e155a - <unknown>
  37:     0x7b6b0a45ea3c - <unknown>
  38:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.80.0-nightly (91d5e4af8 2024-04-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -Z dump-mir-dir=dir

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: aborting due to 1 previous error


@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Apr 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 28, 2024
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Apr 28, 2024

also crashes with just --edition=2021

@jieyouxu jieyouxu added A-resolve Area: Name resolution S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 28, 2024
@matthiaskrgr
Copy link
Member Author

Regression in nightly-2023-07-01

commit[0] 2023-06-29: Auto merge of #112682 - spastorino:new-rpitit-21, r=compiler-errors
commit[1] 2023-06-30: Auto merge of #113116 - nnethercote:codegen-opts, r=oli-obk
commit[2] 2023-06-30: Auto merge of #113162 - matthiaskrgr:rollup-fct3wj7, r=matthiaskrgr
commit[3] 2023-06-30: Auto merge of #113188 - matthiaskrgr:rollup-j3abaks, r=matthiaskrgr
commit[4] 2023-06-30: Auto merge of #106619 - agausmann:avr-object-file, r=nagisa
commit[5] 2023-06-30: Auto merge of #109524 - bzEq:aix-embed-llvmbc, r=nagisa
commit[6] 2023-06-30: Auto merge of #113200 - ferrocene:pa-fix-mir-opt-bless, r=oli-obk

I suspect this is #112086

@Noratrieb
Copy link
Member

Noratrieb commented Apr 28, 2024

use std::collections as x;
use x as std;

slightly more minimal (ordering is irrelevant)

@bvanjoi
Copy link
Contributor

bvanjoi commented Apr 29, 2024

more reduced:

mod a {
    pub mod b {
        pub mod c {}
    } 
}

use a::*;

use b::c;
use c as b;

fn main() {}

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 9, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue May 29, 2024
resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? `@petrochenkov`
fmease added a commit to fmease/rust that referenced this issue Jun 4, 2024
resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? `@petrochenkov`
@bors bors closed this as completed in 69a8c13 Jun 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2024
Rollup merge of rust-lang#124840 - bvanjoi:fix-124490, r=petrochenkov

resolve: mark it undetermined if single import is not has any bindings

- Fixes rust-lang#124490
- Fixes rust-lang#125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root::a::b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root::a::b` introduced by `use a::*` and ultimately return `root::a::b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root::a::b::c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root::a::b::c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? ``@petrochenkov``
@matthiaskrgr
Copy link
Member Author

Again, the original example still crashes.

@matthiaskrgr matthiaskrgr reopened this Jun 6, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jun 7, 2024
mark binding undetermined if target name exist and not obtained

- Fixes rust-lang#124490
- Fixes rust-lang#125013

Following up on rust-lang#124840, I think handling only `target_bindings` is sufficient.

r? `@petrochenkov`
@bors bors closed this as completed in 4bca296 Jun 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 8, 2024
Rollup merge of rust-lang#126065 - bvanjoi:fix-124490, r=petrochenkov

mark binding undetermined if target name exist and not obtained

- Fixes rust-lang#124490
- Fixes rust-lang#125013

Following up on rust-lang#124840, I think handling only `target_bindings` is sufficient.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants