Skip to content

Commit 49a8ba0

Browse files
committed
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)](#142289 (comment)). 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 c7e6acc (results: #142289 (comment)) 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 6f82bf1 (results: #142289 (comment)).
2 parents cc87afd + 3a31f62 commit 49a8ba0

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ fn create_generic_args<'tcx>(
276276
tcx.impl_trait_header(parent).unwrap().trait_ref.instantiate_identity().args;
277277

278278
let trait_args = ty::GenericArgs::identity_for_item(tcx, sig_id);
279-
let method_args =
280-
tcx.mk_args_from_iter(trait_args.iter().skip(callee_generics.parent_count));
279+
let method_args = tcx.mk_args(&trait_args[callee_generics.parent_count..]);
281280
let method_args = build_generic_args(tcx, sig_id, def_id, method_args);
282281

283282
tcx.mk_args_from_iter(parent_args.iter().chain(method_args))

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pub mod tls;
66

7-
use std::assert_matches::{assert_matches, debug_assert_matches};
7+
use std::assert_matches::debug_assert_matches;
88
use std::borrow::Borrow;
99
use std::cmp::Ordering;
1010
use std::env::VarError;
@@ -283,9 +283,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
283283
def_id: DefId,
284284
args: ty::GenericArgsRef<'tcx>,
285285
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
286-
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
286+
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
287287
let trait_def_id = self.parent(def_id);
288-
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
288+
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
289289
let trait_generics = self.generics_of(trait_def_id);
290290
(
291291
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)),

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ impl<'tcx> GenericArgs<'tcx> {
588588
}
589589

590590
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
591-
tcx.mk_args_from_iter(self.iter().take(generics.count()))
591+
tcx.mk_args(&self[..generics.count()])
592592
}
593593

594594
pub fn print_as_list(&self) -> String {

0 commit comments

Comments
 (0)