rust/compiler/rustc_middle/src/ty
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
..
consts intern valtrees 2025-02-13 00:38:17 +01:00
context Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
inhabitedness use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
print intern valtrees 2025-02-13 00:38:17 +01:00
abstract_const.rs Clean up trivial traversal/lift impl generator macro calls. 2025-02-06 13:31:43 +11:00
adjustment.rs Register const preds for Deref adjustments in HIR typeck 2024-11-04 04:51:31 +00:00
adt.rs Implement and use BikeshedGuaranteedNoDrop for union/unsafe field validity 2025-02-13 03:45:04 +00:00
assoc.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
cast.rs Simplify intra-crate qualifiers. 2025-02-11 14:59:13 +11:00
closure.rs Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
codec.rs intern valtrees 2025-02-13 00:38:17 +01:00
consts.rs intern valtrees 2025-02-13 00:38:17 +01:00
context.rs Auto merge of #136593 - lukas-code:ty-value-perf, r=oli-obk 2025-02-13 15:27:30 +00:00
diagnostics.rs Make comma separated lists of anything easier to make for errors 2025-01-31 20:36:44 +00:00
elaborate_impl.rs Uplift elaboration 2024-07-07 11:28:01 -04:00
erase_regions.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
error.rs Rework "long type names" printing logic 2025-01-31 20:39:01 +00:00
fast_reject.rs Use DeepRejectCtxt to quickly reject ParamEnv candidates 2024-09-02 19:59:18 +03:00
flags.rs introduce ty::Value 2025-01-30 17:47:44 +01:00
fold.rs Rustfmt 2025-02-08 22:12:13 +00:00
generic_args.rs Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
generics.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
impls_ty.rs const-eval interning: accpt interior mutable pointers in final value (but keep rejecting mutable references) 2024-09-10 10:26:16 +02:00
instance.rs Simplify intra-crate qualifiers. 2025-02-11 14:59:13 +11:00
intrinsic.rs add new rustc_const_stable_intrinsic attribute for const-stable intrinsics 2024-11-04 23:27:46 +01:00
layout.rs Auto merge of #135994 - 1c3t3a:rename-unsafe-ptr, r=oli-obk 2025-02-12 23:18:14 +00:00
list.rs De-abstract tagged pointer abstraction 2025-01-12 14:56:10 +00:00
mod.rs intern valtrees 2025-02-13 00:38:17 +01:00
normalize_erasing_regions.rs Account for identity substituted items in symbol mangling 2025-01-09 13:55:40 +01:00
opaque_types.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
parameterized.rs Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different crates 2025-02-02 22:12:49 +07:00
pattern.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
predicate.rs Get rid of ToPolyTraitRef 2025-01-18 18:47:17 +00:00
region.rs introduce LateParamRegionKind 2024-12-18 16:05:44 +01:00
relate.rs Rollup merge of #133362 - compiler-errors:existential-preds, r=BoxyUwU 2024-11-26 12:03:43 -05:00
return_position_impl_trait_in_trait.rs Rollup merge of #135860 - fmease:compiler-mv-obj-save-dyn-compat-ii, r=jieyouxu 2025-01-31 12:28:15 +01:00
rvalue_scopes.rs Rename Scope.id to Scope.local_id, remove trivial accessor 2024-12-19 02:31:58 +00:00
structural_impls.rs intern valtrees 2025-02-13 00:38:17 +01:00
sty.rs Extend the renaming to coerce_unsafe_ptr 2025-02-10 13:01:55 +00:00
trait_def.rs split up #[rustc_deny_explicit_impl] attribute 2024-12-20 16:57:14 +01:00
typeck_results.rs Simplify intra-crate qualifiers. 2025-02-11 14:59:13 +11:00
util.rs Rustfmt 2025-02-08 22:12:13 +00:00
visit.rs Handle rustc-hir-analysis cases of rustc::potential_query_instability lint 2024-10-02 08:28:45 +03:00
vtable.rs Do not treat vtable supertraits as distinct when bound with different bound vars 2025-01-30 15:33:58 +00:00
walk.rs introduce ty::Value 2025-01-30 17:47:44 +01:00