Skip to content

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:54:32: could not fully normalize #94204

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

Open
JonathanWoollett-Light opened this issue Feb 21, 2022 · 5 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. 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

@JonathanWoollett-Light
Copy link

Code

The code cannot easily be entirely summarised in a small segment. It involves a criterion benchmark on a library.

Specifically running cargo bench in on this branch (https://github.com/JonathanWoollett-Light/static-la/tree/bench-error) triggers the error.

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (82af160c2 2021-11-10)
binary: rustc
commit-hash: 82af160c2cb9c349a0373cba98d8ad7f911f0d34
commit-date: 2021-11-10
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:54:32: could not fully normalize `<static_la::MatrixSxS<T, L, M> as static_la::Matmul<static_la::MatrixSxS<T, M, N>>>::Output`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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: rustc 1.58.0-nightly (82af160c2 2021-11-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<static_la::MatrixSxS<T, L, M> as static_la::matmul::Matmul<static_la::MatrixSxS<T, M, N>>>::Output`
#1 [fn_abi_of_instance] computing call ABI of `<static_la::MatrixSxS<i32, 2_usize, 3_usize> as static_la::matmul::Matmul<static_la::MatrixSxS<i32, 3_usize, 2_usize>>>::matmul`
end of query stack
warning: `static-la` (bench "benchmarks") generated 12 warnings
error: could not compile `static-la`; 12 warnings emitted
warning: build failed, waiting for other jobs to finish...
error: build failed
jonathan@jonathan-MS-7B22:~/Projects/static-la$ 
Backtrace

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:54:32: could not fully normalize `<static_la::MatrixSxS<T, L, M> as static_la::Matmul<static_la::MatrixSxS<T, M, N>>>::Output`

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_infer::infer::InferCtxtBuilder>::enter::<rustc_middle::ty::subst::GenericArg, rustc_traits::normalize_erasing_regions::normalize_after_erasing_regions<rustc_middle::ty::subst::GenericArg>::{closure#0}>
   8: <rustc_traits::normalize_erasing_regions::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::subst::GenericArg>)>>::call_once
   9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::subst::GenericArg>, rustc_middle::ty::subst::GenericArg>>
  10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::normalize_generic_arg_after_erasing_regions
  11: rustc_middle::ty::util::fold_list::<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder, &rustc_middle::ty::TyS, <&rustc_middle::ty::list::List<&rustc_middle::ty::TyS> as rustc_middle::ty::fold::TypeFoldable>::super_fold_with<rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder>::{closure#0}>
  12: rustc_middle::ty::layout::fn_abi_of_instance
  13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<(rustc_middle::ty::instance::Instance, &rustc_middle::ty::list::List<&rustc_middle::ty::TyS>)>, core::result::Result<&rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS>, rustc_middle::ty::layout::FnAbiError>>>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::fn_abi_of_instance
  15: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  16: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  17: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
  18: rustc_codegen_llvm::base::compile_codegen_unit
  19: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  20: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  21: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorReported>>
  22: <rustc_interface::queries::Queries>::ongoing_codegen
  23: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  24: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
  25: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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: rustc 1.58.0-nightly (82af160c2 2021-11-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<static_la::MatrixSxS<T, L, M> as static_la::matmul::Matmul<static_la::MatrixSxS<T, M, N>>>::Output`
#1 [fn_abi_of_instance] computing call ABI of `<static_la::MatrixSxS<i32, 2_usize, 3_usize> as static_la::matmul::Matmul<static_la::MatrixSxS<i32, 3_usize, 2_usize>>>::matmul`
end of query stack
warning: `static-la` (bench "benchmarks") generated 12 warnings
error: could not compile `static-la`; 12 warnings emitted
jonathan@jonathan-MS-7B22:~/Projects/static-la$ 

@JonathanWoollett-Light JonathanWoollett-Light added 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. labels Feb 21, 2022
@JonathanWoollett-Light
Copy link
Author

JonathanWoollett-Light commented Feb 22, 2022

To add a simpler example of what I beleive to be the same error.

Cargo.toml:

[package]
name = "test-bin"
version = "0.1.0"
edition = "2021"
[dependencies]
static-la = "0.2.4"

src/main.rs:

use static_la::Matmul;
fn main() {
    let l = static_la::MatrixSxS::<f32,2,2>::from([[0.,1.],[2.,3.]]);
    let lt = l.transpose();
    // The errors arises from `l.matmul(&lt);` and a few other operations which change the return type.
    let _ = l.matmul(&lt);
}

Notably this errors only arises in doc tests, benchmarks and external usage. The exact same code executed in a test within the project does not produce an error.

@JonathanWoollett-Light
Copy link
Author

Adding #![feature(generic_const_exprs)] fixes the error. Although I'm not sure this prevents this being a bug still.

@JohnTitor JohnTitor added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example A-const-generics Area: const generics (parameters and arguments) labels Mar 3, 2023
@moxian

This comment has been minimized.

@rustbot rustbot added F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Mar 28, 2025
@moxian

This comment has been minimized.

@rustbot rustbot added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example and removed S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Mar 28, 2025
@moxian
Copy link
Contributor

moxian commented Mar 28, 2025

Minimization for the original issue on 1.58.0:

// lib.rs
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

pub trait Matmul {
    type Output;

    fn matmul(&self) -> Self::Output;
}

impl<const M: usize> Matmul for MatrixSxS<M>
where
    [(); M * M]:,
{
    type Output = ();

    fn matmul(&self) -> Self::Output {
        todo!()
    }
}

pub struct MatrixSxS<const ROWS: usize> {
    data: [(); ROWS],
}
impl<const ROWS: usize> MatrixSxS<ROWS> {
    pub fn new() -> Self {
        todo!()
    }
}
// main.rs
use static_la::Matmul;

fn main() {
    let l = static_la::MatrixSxS::<0>::new();
    let _ = l.matmul();
}

This has been fixed in nightly-2022-03-11

cargo output
   Compiling static-la v0.2.4 (...)
   Compiling mycrate v0.1.0 (H:\work\my\trash\rust-mini\thing)
error: failed to evaluate generic const expression
  --> H:\work\my\trash\rust-mini\static-la\src\lib.rs:13:10
   |
13 |     [(); M * M]:,
   |          ^^^^^
   |
   = note: the crate this constant originates from uses `#![feature(generic_const_exprs)]`
help: consider enabling this feature
   |
1  | #![feature(generic_const_exprs)]
   |

error: could not compile `mycrate` due to previous error

I believe the test in #94440 covers this case well enough. The issue can probably be closed.

@rustbot label: -E-needs-mcve +S-has-mcve -requires-nightly +requires-incomplete-features

@rustbot rustbot added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue requires-incomplete-features This issue requires the use of incomplete features. and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example requires-nightly This issue requires a nightly compiler in some way. labels Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. 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
Development

No branches or pull requests

4 participants