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: resolve: diagnostics: index out of bounds #127302

Closed
matthiaskrgr opened this issue Jul 4, 2024 · 3 comments · Fixed by #127310
Closed

ICE: resolve: diagnostics: index out of bounds #127302

matthiaskrgr opened this issue Jul 4, 2024 · 3 comments · Fixed by #127310
Assignees
Labels
C-bug Category: This is a bug. 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

mod config;

fn run() {
    match &args.cmd {
        crate::config => {}
    }

    println!(, args.ctx.compiler.display());
}
original code

original:

use crate::config::{Profile, Scenario};
use clap::Parser;
use std::path::PathBuf;
use std::process::Command;

mod config;

/// Performs profiling or benchmarking with [`rustc-perf`](https://github.com/rust-lang/rustc-perf)
/// using a locally built compiler.
#[derive(Debug, clap::Parser)]
// Hide arguments from BuildContext in the default usage string.
// Clap does not seem to have a way of disabling the usage of these arguments.
#[clap(override_usage = "rustc-perf-wrapper [OPTIONS] <COMMAND>")]
pub struct Args {
    #[clap(subcommand)]
    cmd: PerfCommand,

    #[clap(flatten)]
    opts: SharedOpts,

    #[clap(flatten)]
    ctx: BuildContext,
}

#[derive(Debug, clap::Parser)]
enum PerfCommand {
    /// Run `profile_local eprintln`.
    /// This executes the compiler on the given benchmarks and stores its stderr output.
    Eprintln,
    /// Run `profile_local samply`
    /// This executes the compiler on the given benchmarks and profiles it with `samply`.
    /// You need to install `samply`, e.g. using `cargo install samply`.
    Samply,
    /// Run `profile_local cachegrind`.
    /// This executes the compiler on the given benchmarks under `Cachegrind`.
    Cachegrind,
}

impl PerfCommand {
    fn is_profiling(&self) -> bool {
        match self {
            PerfCommand::Eprintln | PerfCommand::Samply | PerfCommand::Cachegrind => true,
        }
    }
}

#[derive(Debug, clap::Parser)]
struct SharedOpts {
    /// Select the benchmarks that you want to run (separated by commas).
    /// If unspecified, all benchmarks will be executed.
    #[clap(long, global = true, value_delimiter = ',')]
    include: Vec<String>,
    /// Select the scenarios that should be benchmarked.
    #[clap(
        long,
        global = true,
        value_delimiter = ',',
        default_value = "Full,IncrFull,IncrUnchanged,IncrPatched"
    )]
    scenarios: Vec<Scenario>,
    /// Select the profiles that should be benchmarked.
    #[clap(long, global = true, value_delimiter = ',', default_value = "Check,Debug,Opt")]
    profiles: Vec<Profile>,
}

/// These arguments are mostly designed to be passed from bootstrap, not by users
/// directly.
#[derive(Debug, clap::Parser)]
struct BuildContext {
    /// Compiler binary that will be benchmarked/profiled.
    #[clap(long, hide = true, env = "RUSTC_REAL")]
    compiler: PathBuf,
    /// rustc-perf collector binary that will be used for running benchmarks/profilers.
    #[clap(long, hide = true, env = "PERF_COLLECTOR")]
    collector: PathBuf,
    /// Directory where to store results.
    #[clap(long, hide = true, env = "Opt")]
    results_dir: PathBuf,
}

fn main() {
    let args = Args::parse();
    run(args);
}

fn run(args: Args) {
    let mut cmd = Command::new(args.ctx.collector);
    match &args.cmd {
        crate::config => {
            cmd.arg("profile_local").arg("eprintln");
        }
        PerfCommand::Samply => {
            cmd.arg("profile_local").arg("samply");
        }
        PerfCommand::Cachegrind => {
            cmd.arg("profile_local").arg("cachegrind");
        }
    }
    if args.cmd.is_profiling() {
        cmd.arg("--out-dir").arg(&args.ctx.results_dir);
    }

    if !args.opts.include.is_empty() {
        cmd.arg("--include").arg(args.opts.include.join(","));
    }
    if !args.opts.profiles.is_empty() {
        cmd.arg("--profiles")
            .arg(args.opts.profiles.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(","));
    }
    if !args.opts.scenarios.is_empty() {
        cmd.arg("--scenarios")
            .arg(args.opts.scenarios.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(","));
    }
    cmd.arg(&args.ctx.compiler);

    println!("Running `rustc-perf` using `{}`", args.ctx.compiler.display());

    const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");

    let rustc_perf_dir = cmd.arg("profile_local").arg("cachegrind");

    // We need to set the working directory to `src/tools/perf`, so that it can find the directory
    // with compile-time benchmarks.
    let cmd = cmd.current_dir(rustc_perf_dir);
    cmd.status().expect("error while running rustc-perf collector");

    if args.cmd.is_profiling() {
        println!("You can find the results at `{}`", args.ctx.results_dir.display());
    }
}

Version information

rustc 1.81.0-nightly (f6fa358a1 2024-07-04)
binary: rustc
commit-hash: f6fa358a182b2f8e4d5a10faac4dae950493c9bc
commit-date: 2024-07-04
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0583]: file not found for module `config`
 --> /tmp/icemaker_global_tempdir.WdyOOymswk5H/rustc_testrunner_tmpdir_reporting.dG14bWmC4qrQ/mvce.rs:1:1
  |
1 | mod config;
  | ^^^^^^^^^^^
  |
  = help: to create the module `config`, create file "/tmp/icemaker_global_tempdir.WdyOOymswk5H/rustc_testrunner_tmpdir_reporting.dG14bWmC4qrQ/config.rs" or "/tmp/icemaker_global_tempdir.WdyOOymswk5H/rustc_testrunner_tmpdir_reporting.dG14bWmC4qrQ/config/mod.rs"
  = note: if there is a `mod config` elsewhere in the crate already, import it with `use crate::...` instead

error: expected expression, found `,`
 --> /tmp/icemaker_global_tempdir.WdyOOymswk5H/rustc_testrunner_tmpdir_reporting.dG14bWmC4qrQ/mvce.rs:8:14
  |
8 |     println!(, args.ctx.compiler.display());
  |              ^ expected expression

thread 'rustc' panicked at compiler/rustc_resolve/src/diagnostics.rs:1996:34:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0:     0x76deff0aa3f5 - std::backtrace_rs::backtrace::libunwind::trace::h73c4a5a82946f188
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x76deff0aa3f5 - std::backtrace_rs::backtrace::trace_unsynchronized::h66bd8e410294fbd3
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x76deff0aa3f5 - std::sys::backtrace::_print_fmt::hb9e65fc9c7ac6d6e
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/backtrace.rs:68:5
   3:     0x76deff0aa3f5 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h56d833b1a79a4276
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/backtrace.rs:44:22
   4:     0x76deff0f9afb - core::fmt::rt::Argument::fmt::hc32dc24ee2c3c046
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/core/src/fmt/rt.rs:173:76
   5:     0x76deff0f9afb - core::fmt::write::h0c2be896c08b71a0
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/core/src/fmt/mod.rs:1174:21
   6:     0x76deff09ef9f - std::io::Write::write_fmt::hd597cc0828a1a5ca
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/io/mod.rs:1835:15
   7:     0x76deff0aa1ce - std::sys::backtrace::_print::hf48ef3d02d6d31e8
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/backtrace.rs:47:5
   8:     0x76deff0aa1ce - std::sys::backtrace::print::h05b7f4664de58efe
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/backtrace.rs:34:9
   9:     0x76deff0acb19 - std::panicking::default_hook::{{closure}}::hc3ea390825de35c9
  10:     0x76deff0ac8bc - std::panicking::default_hook::h521299cbf4e30a49
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/panicking.rs:292:9
  11:     0x76defb5f357a - std[caa84339ab768cae]::panicking::update_hook::<alloc[54f829ca486ed3b]::boxed::Box<rustc_driver_impl[e9ee6b77457f9bdb]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x76deff0ad43f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb2cb1c891e5e4b40
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/alloc/src/boxed.rs:2078:9
  13:     0x76deff0ad43f - std::panicking::rust_panic_with_hook::h0ac0539b5fae4f20
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/panicking.rs:804:13
  14:     0x76deff0ad067 - std::panicking::begin_panic_handler::{{closure}}::hf0cbda46bbff161d
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/panicking.rs:670:13
  15:     0x76deff0aa8b9 - std::sys::backtrace::__rust_end_short_backtrace::h75f023a7fb034423
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/backtrace.rs:171:18
  16:     0x76deff0accf4 - rust_begin_unwind
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/panicking.rs:661:5
  17:     0x76deff0f60b3 - core::panicking::panic_fmt::h0da9b5c2c50916e3
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/core/src/panicking.rs:74:14
  18:     0x76deff0f62a7 - core::panicking::panic_bounds_check::h476d633097f3f17f
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/core/src/panicking.rs:276:5
  19:     0x76defc074a89 - <thin_vec[ba00729393108166]::ThinVec<rustc_ast[a56d9dd1e44135e3]::ast::PathSegment> as core[157e79db371603af]::iter::traits::collect::FromIterator<rustc_ast[a56d9dd1e44135e3]::ast::PathSegment>>::from_iter::<core[157e79db371603af]::iter::adapters::map::Map<core[157e79db371603af]::ops::range::RangeInclusive<usize>, <rustc_resolve[58215800da2ac039]::Resolver>::report_path_resolution_error::{closure#3}>>
  20:     0x76defdb2de8f - <rustc_resolve[58215800da2ac039]::Resolver>::resolve_path_with_ribs
  21:     0x76defd558278 - <rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor>::smart_resolve_path_fragment
  22:     0x76defd548947 - <rustc_ast[a56d9dd1e44135e3]::ast::Pat>::walk::<<rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor>::resolve_pattern_inner::{closure#0}>
  23:     0x76defd545b00 - <rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor>::resolve_expr
  24:     0x76defd543f97 - <rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor>::resolve_block
  25:     0x76defd550f73 - <rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor as rustc_ast[a56d9dd1e44135e3]::visit::Visitor>::visit_fn
  26:     0x76defd532b15 - rustc_ast[a56d9dd1e44135e3]::visit::walk_assoc_item::<rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor, rustc_ast[a56d9dd1e44135e3]::ast::ItemKind>
  27:     0x76defd53a025 - <rustc_resolve[58215800da2ac039]::late::LateResolutionVisitor as rustc_ast[a56d9dd1e44135e3]::visit::Visitor>::visit_item
  28:     0x76defddda8e2 - <rustc_resolve[58215800da2ac039]::Resolver>::resolve_crate::{closure#0}
  29:     0x76defddd55dc - <rustc_resolve[58215800da2ac039]::Resolver>::resolve_crate
  30:     0x76defd1a14a8 - rustc_interface[33f4fa0fe46dc2c6]::passes::resolver_for_lowering_raw
  31:     0x76defd1a071b - rustc_query_impl[e955fb0a776e71ef]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e955fb0a776e71ef]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8a7c1b66a7523888]::query::erase::Erased<[u8; 16usize]>>
  32:     0x76defd1a0709 - <rustc_query_impl[e955fb0a776e71ef]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[157e79db371603af]::ops::function::FnOnce<(rustc_middle[8a7c1b66a7523888]::ty::context::TyCtxt, ())>>::call_once
  33:     0x76defdaed9c5 - rustc_query_system[a8bf9cf64c356e0c]::query::plumbing::try_execute_query::<rustc_query_impl[e955fb0a776e71ef]::DynamicConfig<rustc_query_system[a8bf9cf64c356e0c]::query::caches::SingleCache<rustc_middle[8a7c1b66a7523888]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[e955fb0a776e71ef]::plumbing::QueryCtxt, false>
  34:     0x76defdaed661 - rustc_query_impl[e955fb0a776e71ef]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  35:     0x76defda0f023 - rustc_interface[33f4fa0fe46dc2c6]::interface::run_compiler::<core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>, rustc_driver_impl[e9ee6b77457f9bdb]::run_compiler::{closure#0}>::{closure#1}
  36:     0x76defd99f7c9 - std[caa84339ab768cae]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[33f4fa0fe46dc2c6]::util::run_in_thread_with_globals<rustc_interface[33f4fa0fe46dc2c6]::util::run_in_thread_pool_with_globals<rustc_interface[33f4fa0fe46dc2c6]::interface::run_compiler<core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>, rustc_driver_impl[e9ee6b77457f9bdb]::run_compiler::{closure#0}>::{closure#1}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>::{closure#0}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>
  37:     0x76defd99f57a - <<std[caa84339ab768cae]::thread::Builder>::spawn_unchecked_<rustc_interface[33f4fa0fe46dc2c6]::util::run_in_thread_with_globals<rustc_interface[33f4fa0fe46dc2c6]::util::run_in_thread_pool_with_globals<rustc_interface[33f4fa0fe46dc2c6]::interface::run_compiler<core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>, rustc_driver_impl[e9ee6b77457f9bdb]::run_compiler::{closure#0}>::{closure#1}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>::{closure#0}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[157e79db371603af]::result::Result<(), rustc_span[e8e47b51bb05c75f]::ErrorGuaranteed>>::{closure#2} as core[157e79db371603af]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x76deff0b729b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h507a4dd6c7871549
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/alloc/src/boxed.rs:2064:9
  39:     0x76deff0b729b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb1a130911dd94fde
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/alloc/src/boxed.rs:2064:9
  40:     0x76deff0b729b - std::sys::pal::unix::thread::Thread::new::thread_start::h9226f55bc19703c1
                               at /rustc/f6fa358a182b2f8e4d5a10faac4dae950493c9bc/library/std/src/sys/pal/unix/thread.rs:108:17
  41:     0x76def80a6ded - <unknown>
  42:     0x76def812a0dc - <unknown>
  43:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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.81.0-nightly (f6fa358a1 2024-07-04) running on x86_64-unknown-linux-gnu

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

For more information about this error, try `rustc --explain E0583`.

@matthiaskrgr matthiaskrgr added the C-bug Category: This is a bug. label Jul 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 4, 2024
@matthiaskrgr
Copy link
Member Author

I suspect this could be #127203 cc @chenyukang

@matthiaskrgr matthiaskrgr added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 4, 2024
@chenyukang chenyukang self-assigned this Jul 4, 2024
@chenyukang
Copy link
Member

@matthiaskrgr
what's the command line to reproduce it?
I build nightly version and cannot reproduce it by only compiling the code.

also I checked playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021

@chenyukang
Copy link
Member

Ok, got it, we can not use 2021 edition in the command line.

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 5, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 12, 2024
…rt-ice, r=estebank

Fix import suggestion ice

Fixes rust-lang#127302

rust-lang#127302 only crash in edition 2015
rust-lang#120074 can only reproduced in edition 2021
so I added revisions in test file.
@bors bors closed this as completed in afb2fbf Jul 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 13, 2024
Rollup merge of rust-lang#127310 - chenyukang:yukang-fix-suggest-import-ice, r=estebank

Fix import suggestion ice

Fixes rust-lang#127302

rust-lang#127302 only crash in edition 2015
rust-lang#120074 can only reproduced in edition 2021
so I added revisions in test file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants