-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Improve how QueryCache/QueryState/QueryEngine are stored
#152835
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
Changes from all commits
e45224c
06cd823
2bc5167
4a5ee04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,7 @@ pub use sealed::IntoQueryParam; | |
| use crate::dep_graph; | ||
| use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex}; | ||
| use crate::ich::StableHashingContext; | ||
| use crate::queries::{ | ||
| ExternProviders, PerQueryVTables, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates, | ||
| }; | ||
| use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables}; | ||
| use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache}; | ||
| use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra}; | ||
| use crate::query::{QueryCache, QueryInfo, QueryJob}; | ||
|
|
@@ -113,7 +111,7 @@ pub enum EnsureMode { | |
| Done, | ||
| } | ||
|
|
||
| /// Stores function pointers and other metadata for a particular query. | ||
| /// Stores data and metadata (e.g. function pointers) for a particular query. | ||
| pub struct QueryVTable<'tcx, C: QueryCache> { | ||
| pub name: &'static str, | ||
|
|
||
|
|
@@ -129,10 +127,8 @@ pub struct QueryVTable<'tcx, C: QueryCache> { | |
| pub dep_kind: DepKind, | ||
| /// How this query deals with query cycle errors. | ||
| pub cycle_error_handling: CycleErrorHandling, | ||
| // Offset of this query's state field in the QueryStates struct | ||
| pub query_state: usize, | ||
| // Offset of this query's cache field in the QueryCaches struct | ||
| pub query_cache: usize, | ||
| pub state: QueryState<'tcx, C::Key>, | ||
| pub cache: C, | ||
| pub will_cache_on_disk_for_key_fn: Option<WillCacheOnDiskForKeyFn<'tcx, C::Key>>, | ||
|
|
||
| /// Function pointer that calls `tcx.$query(key)` for this query and | ||
|
|
@@ -161,6 +157,8 @@ pub struct QueryVTable<'tcx, C: QueryCache> { | |
| /// | ||
| /// Used when reporting query cycle errors and similar problems. | ||
| pub description_fn: fn(TyCtxt<'tcx>, C::Key) -> String, | ||
|
|
||
| pub execute_query_fn: fn(TyCtxt<'tcx>, Span, C::Key, QueryMode) -> Option<C::Value>, | ||
|
Member
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. Remark (pre-existing): This field could really use some docs and maybe a better name, because what it does and doesn't do is fairly subtle. But that's a pre-existing concern, so I don't want to block this PR on it.
Contributor
Author
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. If you want to suggest a comment I can drop it in.
Member
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. I don’t have something prepared, but I’ll add it to my TODO list to come back and look at this for a follow-up PR. |
||
| } | ||
|
|
||
| impl<'tcx, C: QueryCache> fmt::Debug for QueryVTable<'tcx, C> { | ||
|
|
@@ -181,30 +179,6 @@ impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> { | |
| self.will_cache_on_disk_for_key_fn.map_or(false, |f| f(tcx, key)) | ||
| } | ||
|
|
||
| // Don't use this method to access query results, instead use the methods on TyCtxt. | ||
| #[inline(always)] | ||
| pub fn query_state(&self, tcx: TyCtxt<'tcx>) -> &'tcx QueryState<'tcx, C::Key> { | ||
| // Safety: | ||
| // This is just manually doing the subfield referencing through pointer math. | ||
| unsafe { | ||
| &*(&tcx.query_system.states as *const QueryStates<'tcx>) | ||
| .byte_add(self.query_state) | ||
| .cast::<QueryState<'tcx, C::Key>>() | ||
| } | ||
| } | ||
|
|
||
| // Don't use this method to access query results, instead use the methods on TyCtxt. | ||
| #[inline(always)] | ||
| pub fn query_cache(&self, tcx: TyCtxt<'tcx>) -> &'tcx C { | ||
| // Safety: | ||
| // This is just manually doing the subfield referencing through pointer math. | ||
| unsafe { | ||
| &*(&tcx.query_system.caches as *const QueryCaches<'tcx>) | ||
| .byte_add(self.query_cache) | ||
| .cast::<C>() | ||
| } | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub fn try_load_from_disk( | ||
| &self, | ||
|
|
@@ -243,7 +217,6 @@ impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> { | |
| } | ||
|
|
||
| pub struct QuerySystemFns { | ||
| pub engine: QueryEngine, | ||
| pub local_providers: Providers, | ||
| pub extern_providers: ExternProviders, | ||
| pub encode_query_results: for<'tcx> fn( | ||
|
|
@@ -255,10 +228,8 @@ pub struct QuerySystemFns { | |
| } | ||
|
|
||
| pub struct QuerySystem<'tcx> { | ||
| pub states: QueryStates<'tcx>, | ||
| pub arenas: WorkerLocal<QueryArenas<'tcx>>, | ||
| pub caches: QueryCaches<'tcx>, | ||
| pub query_vtables: PerQueryVTables<'tcx>, | ||
| pub query_vtables: QueryVTables<'tcx>, | ||
|
|
||
| /// This provides access to the incremental compilation on-disk cache for query results. | ||
| /// Do not access this directly. It is only meant to be used by | ||
|
|
@@ -521,13 +492,6 @@ macro_rules! define_callbacks { | |
| )* | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct QueryCaches<'tcx> { | ||
| $( | ||
| pub $name: $name::Storage<'tcx>, | ||
| )* | ||
| } | ||
|
|
||
| impl<'tcx> $crate::query::TyCtxtEnsureOk<'tcx> { | ||
| $( | ||
| $(#[$attr])* | ||
|
|
@@ -546,8 +510,8 @@ macro_rules! define_callbacks { | |
| (crate::query::inner::query_ensure) | ||
| )( | ||
| self.tcx, | ||
| self.tcx.query_system.fns.engine.$name, | ||
| &self.tcx.query_system.caches.$name, | ||
| self.tcx.query_system.query_vtables.$name.execute_query_fn, | ||
| &self.tcx.query_system.query_vtables.$name.cache, | ||
| $crate::query::IntoQueryParam::into_query_param(key), | ||
| $crate::query::EnsureMode::Ok, | ||
| ) | ||
|
|
@@ -562,8 +526,8 @@ macro_rules! define_callbacks { | |
| pub fn $name(self, key: query_helper_param_ty!($($K)*)) { | ||
| crate::query::inner::query_ensure( | ||
| self.tcx, | ||
| self.tcx.query_system.fns.engine.$name, | ||
| &self.tcx.query_system.caches.$name, | ||
| self.tcx.query_system.query_vtables.$name.execute_query_fn, | ||
| &self.tcx.query_system.query_vtables.$name.cache, | ||
| $crate::query::IntoQueryParam::into_query_param(key), | ||
| $crate::query::EnsureMode::Done, | ||
| ); | ||
|
|
@@ -591,8 +555,8 @@ macro_rules! define_callbacks { | |
|
|
||
| erase::restore_val::<$V>(inner::query_get_at( | ||
| self.tcx, | ||
| self.tcx.query_system.fns.engine.$name, | ||
| &self.tcx.query_system.caches.$name, | ||
| self.tcx.query_system.query_vtables.$name.execute_query_fn, | ||
| &self.tcx.query_system.query_vtables.$name.cache, | ||
| self.span, | ||
| $crate::query::IntoQueryParam::into_query_param(key), | ||
| )) | ||
|
|
@@ -615,7 +579,6 @@ macro_rules! define_callbacks { | |
| self.tcx, | ||
| dep_graph::DepKind::$name, | ||
| &self.tcx.query_system.query_vtables.$name, | ||
| &self.tcx.query_system.caches.$name, | ||
| key, | ||
| erased_value, | ||
| ); | ||
|
|
@@ -625,21 +588,12 @@ macro_rules! define_callbacks { | |
| )* | ||
|
|
||
| /// Holds a `QueryVTable` for each query. | ||
| /// | ||
| /// ("Per" just makes this pluralized name more visually distinct.) | ||
| pub struct PerQueryVTables<'tcx> { | ||
| pub struct QueryVTables<'tcx> { | ||
| $( | ||
| pub $name: ::rustc_middle::query::plumbing::QueryVTable<'tcx, $name::Storage<'tcx>>, | ||
| )* | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct QueryStates<'tcx> { | ||
| $( | ||
| pub $name: $crate::query::QueryState<'tcx, $name::Key<'tcx>>, | ||
| )* | ||
| } | ||
|
|
||
| pub struct Providers { | ||
| $( | ||
| /// This is the provider for the query. Use `Find references` on this to | ||
|
|
@@ -699,17 +653,6 @@ macro_rules! define_callbacks { | |
| impl Clone for ExternProviders { | ||
| fn clone(&self) -> Self { *self } | ||
| } | ||
|
|
||
| pub struct QueryEngine { | ||
| $( | ||
| pub $name: for<'tcx> fn( | ||
| TyCtxt<'tcx>, | ||
| Span, | ||
| $name::Key<'tcx>, | ||
| $crate::query::QueryMode, | ||
| ) -> Option<$crate::query::erase::Erased<$V>>, | ||
| )* | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.