Skip to content

Commit 2b52d65

Browse files
Don't fold in Instantiate when there's nothing to fold
1 parent 100199c commit 2b52d65

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compiler/rustc_type_ir/src/binder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,17 @@ impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> {
622622
where
623623
A: SliceLike<Item = I::GenericArg>,
624624
{
625+
// Nothing to fold, so let's avoid visiting things and possibly re-hashing/equating
626+
// them when interning. Perf testing found this to be a modest improvement.
627+
// See: <https://github.com/rust-lang/rust/pull/142317>
628+
if args.is_empty() {
629+
debug_assert!(
630+
!self.value.has_param(),
631+
"{:?} has parameters, but no args were provided in instantiate",
632+
self.value,
633+
);
634+
return self.value;
635+
}
625636
let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 };
626637
self.value.fold_with(&mut folder)
627638
}

0 commit comments

Comments
 (0)