rust/compiler/rustc_ty_utils/src
bors c241e14650 Auto merge of #136593 - lukas-code:ty-value-perf, r=oli-obk
valtree performance tuning

Summary: This PR makes type checking of code with many type-level constants faster.

After https://github.com/rust-lang/rust/pull/136180 was merged, we observed a small perf regression (https://github.com/rust-lang/rust/pull/136318#issuecomment-2635562821). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates: 6c1d960d88/compiler/rustc_type_ir/src/fast_reject.rs (L486-L487)

This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with `feature(adt_const_params)`, so the fast reject code doesn't have to do a deep compare of the valtrees.

Note that we can't just compare the interned consts themselves in the fast reject, because sometimes `'static` lifetimes in the type are be replaced with inference variables (due to canonicalization) on one side but not the other.

A less invasive alternative that I considered is simply avoiding copies introduced by https://github.com/rust-lang/rust/pull/136180 and comparing the valtrees it in-place (see commit: 9e91e50ac5 / perf results: https://github.com/rust-lang/rust/pull/136593#issuecomment-2642303245), however that was still measurably slower than interning.

There are some minor regressions in secondary benchmarks: These happen due to changes in memory allocations and seem acceptable to me. The crates that make heavy use of valtrees show no significant changes in memory usage.
2025-02-13 15:27:30 +00:00
..
layout make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00
abi.rs Auto merge of #136954 - jhpratt:rollup-koefsot, r=jhpratt 2025-02-13 02:13:24 +00:00
assoc.rs Split hir TyKind and ConstArgKind in two and update hir::Visitor 2025-01-23 06:01:36 +00:00
common_traits.rs move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
consts.rs intern valtrees 2025-02-13 00:38:17 +01:00
errors.rs Add warn(unreachable_pub) to rustc_ty_utils. 2024-09-03 08:50:33 +10:00
implied_bounds.rs Rustfmt 2025-02-08 22:12:13 +00:00
instance.rs Rename tcx.ensure() to tcx.ensure_ok() 2025-02-01 12:38:54 +11:00
layout.rs Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr 2025-02-10 12:49:18 +00:00
lib.rs compiler: pre-move code for fixing enum layout ICEs 2024-10-20 02:09:22 -07:00
needs_drop.rs Begin to implement type system layer of unsafe binders 2024-12-22 21:57:57 +00:00
opaque_types.rs Encode cross-crate opaque type origin 2024-10-31 01:35:13 +00:00
representability.rs rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00
sig_types.rs nit: Make get_infer_ret_ty name more consistent with is_suggestable_infer_ty 2025-01-02 23:39:16 +00:00
structural_match.rs TypingMode 🤔 2024-10-29 17:01:24 +01:00
ty.rs rename BitSet to DenseBitSet 2025-01-11 11:34:01 +00:00