Skip to content

Commit

Permalink
Tweak query accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Feb 26, 2023
1 parent 34e6673 commit 10f63c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions compiler/rustc_middle/src/ty/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
};
}
Expand Down Expand Up @@ -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),
Expand All @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, C>(tcx: Tcx, cache: &C, key: &C::Key) -> Option<C::Value>
where
C: QueryCache,
Expand Down

0 comments on commit 10f63c0

Please sign in to comment.