Skip to content

Don't fold in Instantiate when there's nothing to fold #142317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_type_ir/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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)
}
Expand Down
Loading