Auto merge of #142289 - fmease:maybe-perf-gen-args, r=compiler-errors

[perf] `GenericArgs`-related: Change asserts to debug asserts & use more slice interning over iterable interning

1. The 1st commit yields the following perf gains: [#142289 (comment)](https://github.com/rust-lang/rust/pull/142289#issuecomment-2964041303).
2. The 2nd commit might also have a minor positive perf impact, however that one wasn't tested in isolation.

For reference, the initial approach c7e6accd79 (results: https://github.com/rust-lang/rust/pull/142289#issuecomment-2961076587) had a lot more changes (apart from what's now contained in commit 1 and 2) which seemed to be perf irrelevant (cf. the partial countercheck in 6f82bf1cfe (results: https://github.com/rust-lang/rust/pull/142289#issuecomment-2968393647).
This commit is contained in:
bors 2025-06-14 19:42:04 +00:00
commit 49a8ba0684
3 changed files with 5 additions and 6 deletions

View file

@ -276,8 +276,7 @@ fn create_generic_args<'tcx>(
tcx.impl_trait_header(parent).unwrap().trait_ref.instantiate_identity().args;
let trait_args = ty::GenericArgs::identity_for_item(tcx, sig_id);
let method_args =
tcx.mk_args_from_iter(trait_args.iter().skip(callee_generics.parent_count));
let method_args = tcx.mk_args(&trait_args[callee_generics.parent_count..]);
let method_args = build_generic_args(tcx, sig_id, def_id, method_args);
tcx.mk_args_from_iter(parent_args.iter().chain(method_args))

View file

@ -4,7 +4,7 @@
pub mod tls;
use std::assert_matches::{assert_matches, debug_assert_matches};
use std::assert_matches::debug_assert_matches;
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::env::VarError;
@ -283,9 +283,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
def_id: DefId,
args: ty::GenericArgsRef<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
let trait_def_id = self.parent(def_id);
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
let trait_generics = self.generics_of(trait_def_id);
(
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)),

View file

@ -588,7 +588,7 @@ impl<'tcx> GenericArgs<'tcx> {
}
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
tcx.mk_args_from_iter(self.iter().take(generics.count()))
tcx.mk_args(&self[..generics.count()])
}
pub fn print_as_list(&self) -> String {