Skip to content

Commit 99425a1

Browse files
committed
Revert "[perf] Tweak GenericArgs-related functions"
This reverts commit 22cb22e.
1 parent 22cb22e commit 99425a1

File tree

6 files changed

+17
-50
lines changed

6 files changed

+17
-50
lines changed

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ 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 = tcx.mk_args(&trait_args[callee_generics.parent_count..]);
279+
let method_args =
280+
tcx.mk_args_from_iter(trait_args.iter().skip(callee_generics.parent_count));
280281
let method_args = build_generic_args(tcx, sig_id, def_id, method_args);
281282

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

compiler/rustc_middle/src/ty/context.rs

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

55
pub mod tls;
66

7-
use std::assert_matches::debug_assert_matches;
7+
use std::assert_matches::{assert_matches, debug_assert_matches};
88
use std::borrow::Borrow;
99
use std::cmp::Ordering;
1010
use std::env::VarError;
@@ -263,35 +263,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
263263
}
264264
}
265265

266-
fn trait_ref_for_alias(
267-
self,
268-
def_id: DefId,
269-
args: ty::GenericArgsRef<'tcx>,
270-
) -> ty::TraitRef<'tcx> {
271-
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
272-
let trait_def_id = self.parent(def_id);
273-
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
274-
let trait_generics = self.generics_of(trait_def_id);
275-
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics))
276-
}
277-
278-
fn own_args_for_alias(
279-
self,
280-
def_id: DefId,
281-
args: ty::GenericArgsRef<'tcx>,
282-
) -> &'tcx [ty::GenericArg<'tcx>] {
283-
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
284-
&args[self.generics_of(def_id).parent_count..]
285-
}
286-
287266
fn trait_ref_and_own_args_for_alias(
288267
self,
289268
def_id: DefId,
290269
args: ty::GenericArgsRef<'tcx>,
291270
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
292-
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
271+
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
293272
let trait_def_id = self.parent(def_id);
294-
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
273+
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
295274
let trait_generics = self.generics_of(trait_def_id);
296275
(
297276
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(&self[..generics.count()])
591+
tcx.mk_args_from_iter(self.iter().take(generics.count()))
592592
}
593593

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

compiler/rustc_type_ir/src/interner.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,6 @@ pub trait Interner:
176176

177177
fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind;
178178

179-
fn trait_ref_for_alias(
180-
self,
181-
def_id: Self::DefId,
182-
args: Self::GenericArgs,
183-
) -> ty::TraitRef<Self>;
184-
185-
fn own_args_for_alias(
186-
self,
187-
def_id: Self::DefId,
188-
args: Self::GenericArgs,
189-
) -> Self::GenericArgsSlice;
190-
191179
fn trait_ref_and_own_args_for_alias(
192180
self,
193181
def_id: Self::DefId,

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,14 @@ impl<I: Interner> AliasTerm<I> {
664664
interner.parent(self.def_id)
665665
}
666666

667+
/// Extracts the underlying trait reference and own args from this projection.
668+
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
669+
/// then this function would return a `T: StreamingIterator` trait reference and
670+
/// `['a]` as the own args.
671+
pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
672+
interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
673+
}
674+
667675
/// Extracts the underlying trait reference from this projection.
668676
/// For example, if this is a projection of `<T as Iterator>::Item`,
669677
/// then this function would return a `T: Iterator` trait reference.
@@ -672,22 +680,14 @@ impl<I: Interner> AliasTerm<I> {
672680
/// consider calling [Self::trait_ref_and_own_args] to get those
673681
/// as well.
674682
pub fn trait_ref(self, interner: I) -> TraitRef<I> {
675-
interner.trait_ref_for_alias(self.def_id, self.args)
683+
self.trait_ref_and_own_args(interner).0
676684
}
677685

678686
/// Extract the own args from this projection.
679687
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
680688
/// then this function would return the slice `['a]` as the own args.
681689
pub fn own_args(self, interner: I) -> I::GenericArgsSlice {
682-
interner.own_args_for_alias(self.def_id, self.args)
683-
}
684-
685-
/// Extracts the underlying trait reference and own args from this projection.
686-
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
687-
/// then this function would return a `T: StreamingIterator` trait reference and
688-
/// `['a]` as the own args.
689-
pub fn trait_ref_and_own_args(self, interner: I) -> (TraitRef<I>, I::GenericArgsSlice) {
690-
interner.trait_ref_and_own_args_for_alias(self.def_id, self.args)
690+
self.trait_ref_and_own_args(interner).1
691691
}
692692
}
693693

compiler/rustc_type_ir/src/ty_kind.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,7 @@ impl<I: Interner> AliasTy<I> {
510510
/// consider calling [Self::trait_ref_and_own_args] to get those
511511
/// as well.
512512
pub fn trait_ref(self, interner: I) -> ty::TraitRef<I> {
513-
debug_assert_eq!(self.kind(interner), AliasTyKind::Projection);
514-
interner.trait_ref_for_alias(self.def_id, self.args)
513+
self.trait_ref_and_own_args(interner).0
515514
}
516515
}
517516

0 commit comments

Comments
 (0)