From a1459c3fca5f9b35918d576a7bf79ce15d279719 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Wed, 6 Dec 2023 07:22:44 +0000 Subject: [PATCH] fix small perf regressions --- compiler/rustc_middle/src/infer/canonical.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index c231a0f0b64..232c84158ef 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -34,7 +34,7 @@ use crate::infer::MemberConstraint; use crate::mir::ConstraintCategory; use crate::ty::GenericArg; -use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt}; +use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt}; pub type Canonical<'tcx, V> = IrCanonical, V>; @@ -315,6 +315,16 @@ pub fn get_or_insert( &mut OriginalQueryValues<'tcx>, ) -> Canonical<'tcx, ty::ParamEnv<'tcx>>, ) -> Canonical<'tcx, ty::ParamEnv<'tcx>> { + if !key.has_type_flags( + TypeFlags::HAS_INFER | TypeFlags::HAS_PLACEHOLDER | TypeFlags::HAS_FREE_REGIONS, + ) { + return Canonical { + max_universe: ty::UniverseIndex::ROOT, + variables: List::empty(), + value: key, + }; + } + assert_eq!(state.var_values.len(), 0); assert_eq!(state.universe_map.len(), 1); debug_assert_eq!(&*state.universe_map, &[ty::UniverseIndex::ROOT]);