From 2b52d65c7719b058bed004e666b010585e01a1c1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 10 Jun 2025 21:09:35 +0000 Subject: [PATCH] Don't fold in Instantiate when there's nothing to fold --- compiler/rustc_type_ir/src/binder.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 55c0a3bba9f2b..b744bcc40dbdf 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -622,6 +622,17 @@ impl> ty::EarlyBinder { where A: SliceLike, { + // Nothing to fold, so let's avoid visiting things and possibly re-hashing/equating + // them when interning. Perf testing found this to be a modest improvement. + // See: + if args.is_empty() { + debug_assert!( + !self.value.has_param(), + "{:?} has parameters, but no args were provided in instantiate", + self.value, + ); + return self.value; + } let mut folder = ArgFolder { cx, args: args.as_slice(), binders_passed: 0 }; self.value.fold_with(&mut folder) }