From 10f63c06f19b026a27607c46fa788cf7af8ef3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 26 Feb 2023 02:06:00 +0100 Subject: [PATCH] Tweak query accessors --- compiler/rustc_middle/src/ty/query.rs | 20 +++++++------------ .../rustc_query_system/src/query/plumbing.rs | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 3d9a5075d4ade..abdf42c2b2d5e 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -168,11 +168,11 @@ macro_rules! separate_provide_extern_default { } macro_rules! opt_remap_env_constness { - ([][$name:ident]) => {}; - ([(remap_env_constness) $($rest:tt)*][$name:ident]) => { - let $name = $name.without_const(); + ([][$name:expr]) => { $name }; + ([(remap_env_constness) $($rest:tt)*][$name:expr]) => { + $name.without_const() }; - ([$other:tt $($modifiers:tt)*][$name:ident]) => { + ([$other:tt $($modifiers:tt)*][$name:expr]) => { opt_remap_env_constness!([$($modifiers)*][$name]) }; } @@ -276,9 +276,7 @@ macro_rules! define_callbacks { $($(#[$attr])* #[inline(always)] pub fn $name(self, key: query_helper_param_ty!($($K)*)) { - let key = key.into_query_param(); - opt_remap_env_constness!([$($modifiers)*][key]); - + let key = opt_remap_env_constness!([$($modifiers)*][key]).into_query_param(); match try_get_cached(self.tcx, &self.tcx.query_system.caches.$name, &key) { Some(_) => return, None => self.tcx.queries.$name(self.tcx, DUMMY_SP, key, QueryMode::Ensure), @@ -301,9 +299,7 @@ macro_rules! define_callbacks { #[inline(always)] pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V { - let key = key.into_query_param(); - opt_remap_env_constness!([$($modifiers)*][key]); - + let key = opt_remap_env_constness!([$($modifiers)*][key]).into_query_param(); match try_get_cached(self.tcx, &self.tcx.query_system.caches.$name, &key) { Some(value) => value, None => self.tcx.queries.$name(self.tcx, self.span, key, QueryMode::Get).unwrap(), @@ -394,9 +390,7 @@ macro_rules! define_feedable { $(#[$attr])* #[inline(always)] pub fn $name(self, value: query_provided::$name<'tcx>) -> $V { - let key = self.key().into_query_param(); - opt_remap_env_constness!([$($modifiers)*][key]); - + let key = opt_remap_env_constness!([$($modifiers)*][self.key()]).into_query_param(); let tcx = self.tcx; let value = query_provided_to_value::$name(tcx, value); let cache = &tcx.query_system.caches.$name; diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 5499165930db0..6a8399528b980 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -330,7 +330,7 @@ where /// It returns the shard index and a lock guard to the shard, /// which will be used if the query is not in the cache and we need /// to compute it. -#[inline] +#[inline(always)] pub fn try_get_cached(tcx: Tcx, cache: &C, key: &C::Key) -> Option where C: QueryCache,