Repository: rust
Issue: Compiling `cranelift-codegen` with `-Z next-solver` is very slow
Labels: I-compiletime,T-compiler,C-bug,T-types,WG-trait-system-refactor

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code: https://github.com/bytecodealliance/wasmtime/ at commit https://github.com/bytecodealliance/wasmtime/commit/201b7b4ce4c5946cce8d5cd90ad2b64440864d8b.

```console
git clone git@github.com:bytecodealliance/wasmtime.git
cd wasmtime
git checkout 201b7b4ce4c5946cce8d5cd90ad2b64440864d8b
cd cranelift/codegen
RUSTFLAGS="-Z next-solver" cargo build
```

I expected to see this happen: `cargo build` should succeed in a couple of seconds (which it does without `-Z next-solver`).

Instead, this happened: A clean rebuild with`-Z next-solver` takes 10x longer than without.

These are the hottest functions according to `perf top`:
```
   6,25%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_args
   5,49%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::solve::eval_ctxt::EvalCtxt<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::evaluate_goal_raw
   5,08%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::CtxtInterners>::intern_ty
   4,16%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::CtxtInterners>::intern_predicate
   3,80%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_ty
   2,74%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::resolve::EagerResolver<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_predicate
   2,39%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt>>::finalize
   2,08%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_next_trait_solver::canonicalizer::Canonicalizer<rustc_trait_selection::solve::delegate::SolverDelegate, rustc_middle::ty::context::TyCtxt> as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_predicate
   1,94%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_trait_selection::solve::fulfill::FulfillmentCtxt<rustc_trait_selection::traits::FulfillmentError> as rustc_infer::traits::engine::TraitEngine<rustc_trait_selection::traits::FulfillmentError>>::select_where_possible
   1,83%  librustc_driver-57fe6e1841a504ec.so       [.] <hashbrown::raw::RawTable<((rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty)>>::reserve_rehash::<hashbrown::map::make_hasher<(rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>::{closure#0}>
   1,81%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_canonical_var_infos
   1,52%  librustc_driver-57fe6e1841a504ec.so       [.] <rustc_middle::ty::context::TyCtxt>::mk_predefined_opaques_in_body
   1,37%  librustc_driver-57fe6e1841a504ec.so       [.] <hashbrown::map::HashMap<(rustc_type_ir::DebruijnIndex, rustc_middle::ty::Ty), rustc_middle::ty::Ty, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>>::insert
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```console
$ rustc --version --verbose
rustc 1.83.0-nightly (3ae715c8c 2024-10-07)
binary: rustc
commit-hash: 3ae715c8c63f9aeac47cbf7d8d9dadb3fa32c638
commit-date: 2024-10-07
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1
```