diff options
| author | bors <bors@rust-lang.org> | 2025-06-28 13:31:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-28 13:31:12 +0000 |
| commit | 7ba34c704529e7fcab80130c3fe40efe415d61b5 (patch) | |
| tree | 09cafdf5278af9aa4dae3846f7f213765652e1c8 | |
| parent | b63223c152212832ce37a109e26cc5f84c577532 (diff) | |
| parent | d0321192532f3b32e187e43a183c92c31fcfe83a (diff) | |
| download | rust-7ba34c704529e7fcab80130c3fe40efe415d61b5.tar.gz rust-7ba34c704529e7fcab80130c3fe40efe415d61b5.zip | |
Auto merge of #142317 - compiler-errors:perf-fold, r=lcnr
Don't fold in Instantiate when there's nothing to fold Maybe this helps idk r? lcnr
| -rw-r--r-- | compiler/rustc_type_ir/src/binder.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 927a2ce84ea..a7b915c4845 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -622,6 +622,17 @@ impl<I: Interner, T: TypeFoldable<I>> ty::EarlyBinder<I, T> { where A: SliceLike<Item = I::GenericArg>, { + // 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: <https://github.com/rust-lang/rust/pull/142317> + if args.is_empty() { + 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) } |
