-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Take impl Into<DefId>
for query methods on TyCtxt
#70961
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62b5aff
Make query helpers on `TyCtxt` take `impl Into<DefId>`
ecstatic-morse 10ed501
Impl `From<LocalDefId>` for `DefId`
ecstatic-morse 0d4639d
Fix inference fallout
ecstatic-morse 6e5a210
Remove call to `to_def_id` before calling query helper
ecstatic-morse fd8cf3c
Simplify macro
ecstatic-morse beeacdb
Use custom trait instead of `Into`
ecstatic-morse f0c7733
Apply suggestions from review
ecstatic-morse 04c91a0
Add `#[inline(always)]` to `into_query_param`
ecstatic-morse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,18 +234,23 @@ macro_rules! hash_result { | |
|
||
macro_rules! define_queries { | ||
(<$tcx:tt> $($category:tt { | ||
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)* | ||
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)* | ||
},)*) => { | ||
define_queries_inner! { <$tcx> | ||
$($( $(#[$attr])* category<$category> [$($modifiers)*] fn $name: $node($K) -> $V,)*)* | ||
$($( $(#[$attr])* category<$category> [$($modifiers)*] fn $name: $node($($K)*) -> $V,)*)* | ||
} | ||
} | ||
} | ||
|
||
macro_rules! query_helper_param_ty { | ||
(DefId) => { impl IntoQueryParam<DefId> }; | ||
($K:ty) => { $K }; | ||
} | ||
|
||
macro_rules! define_queries_inner { | ||
(<$tcx:tt> | ||
$($(#[$attr:meta])* category<$category:tt> | ||
[$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)*) => { | ||
[$($modifiers:tt)*] fn $name:ident: $node:ident($($K:tt)*) -> $V:ty,)*) => { | ||
|
||
use std::mem; | ||
use crate::{ | ||
|
@@ -263,7 +268,7 @@ macro_rules! define_queries_inner { | |
#[allow(nonstandard_style)] | ||
#[derive(Clone, Debug)] | ||
pub enum Query<$tcx> { | ||
$($(#[$attr])* $name($K)),* | ||
$($(#[$attr])* $name($($K)*)),* | ||
} | ||
|
||
impl<$tcx> Query<$tcx> { | ||
|
@@ -321,7 +326,7 @@ macro_rules! define_queries_inner { | |
} | ||
|
||
$(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> { | ||
type Key = $K; | ||
type Key = $($K)*; | ||
type Value = $V; | ||
const NAME: &'static str = stringify!($name); | ||
const CATEGORY: ProfileCategory = $category; | ||
|
@@ -332,7 +337,7 @@ macro_rules! define_queries_inner { | |
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]); | ||
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$node; | ||
|
||
type Cache = query_storage!([$($modifiers)*][$K, $V]); | ||
type Cache = query_storage!([$($modifiers)*][$($K)*, $V]); | ||
|
||
#[inline(always)] | ||
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> { | ||
|
@@ -380,8 +385,8 @@ macro_rules! define_queries_inner { | |
impl TyCtxtEnsure<$tcx> { | ||
$($(#[$attr])* | ||
#[inline(always)] | ||
pub fn $name(self, key: $K) { | ||
ensure_query::<queries::$name<'_>, _>(self.tcx, key) | ||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) { | ||
ensure_query::<queries::$name<'_>, _>(self.tcx, key.into_query_param()) | ||
Comment on lines
-383
to
+389
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, are these changes needed? "ensuring" should be rather rare AFAIK? |
||
})* | ||
} | ||
|
||
|
@@ -421,7 +426,7 @@ macro_rules! define_queries_inner { | |
|
||
$($(#[$attr])* | ||
#[inline(always)] | ||
pub fn $name(self, key: $K) -> $V { | ||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V { | ||
self.at(DUMMY_SP).$name(key) | ||
})* | ||
|
||
|
@@ -458,14 +463,14 @@ macro_rules! define_queries_inner { | |
impl TyCtxtAt<$tcx> { | ||
$($(#[$attr])* | ||
#[inline(always)] | ||
pub fn $name(self, key: $K) -> $V { | ||
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key) | ||
pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> $V { | ||
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into_query_param()) | ||
})* | ||
} | ||
|
||
define_provider_struct! { | ||
tcx: $tcx, | ||
input: ($(([$($modifiers)*] [$name] [$K] [$V]))*) | ||
input: ($(([$($modifiers)*] [$name] [$($K)*] [$V]))*) | ||
} | ||
|
||
impl<$tcx> Copy for Providers<$tcx> {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try adding
#[inline(always)]
to this (andto_def_id
if it doesn't have it).Although, wait, are we using this at all now? Is the slowdown just from going through the noop impl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used exactly once as a test 6e5a210. I'm skeptical that this will help, since no
into_query_param
call appears in the optimized binary, and theDefId
queries I looked at inline down toget_query
. There's no predicting the optimizer though.