diff options
| author | bors <bors@rust-lang.org> | 2023-02-16 22:10:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-16 22:10:10 +0000 |
| commit | 947b696ce0ce42c98b8fb82ffa0735ade051466c (patch) | |
| tree | 35768557e506f47a11e729260131ab417143b1c7 /compiler/rustc_query_impl/src | |
| parent | 9a7cc6c32f1a690f86827e4724bcda85e506ef35 (diff) | |
| parent | caf29b27277fd4fca4b372938e2fecf12dd12c78 (diff) | |
| download | rust-947b696ce0ce42c98b8fb82ffa0735ade051466c.tar.gz rust-947b696ce0ce42c98b8fb82ffa0735ade051466c.zip | |
Auto merge of #107833 - Zoxc:arena-query-clean, r=cjgillot
Factor query arena allocation out from query caches This moves the logic for arena allocation out from the query caches into conditional code in the query system. The specialized arena caches are removed. A new `QuerySystem` type is added in `rustc_middle` which contains the arenas, providers and query caches. Performance seems to be slightly regressed: <table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.8053s</td><td align="right">1.8109s</td><td align="right"> 0.31%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2600s</td><td align="right">0.2597s</td><td align="right"> -0.10%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.9973s</td><td align="right">1.0006s</td><td align="right"> 0.34%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.6048s</td><td align="right">1.6051s</td><td align="right"> 0.02%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.2992s</td><td align="right">6.3159s</td><td align="right"> 0.26%</td></tr><tr><td>Total</td><td align="right">10.9664s</td><td align="right">10.9922s</td><td align="right"> 0.23%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">1.0017s</td><td align="right"> 0.17%</td></tr></table> Incremental performance is a bit worse: <table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check:initial</td><td align="right">2.2103s</td><td align="right">2.2247s</td><td align="right"> 0.65%</td></tr><tr><td>🟣 <b>hyper</b>:check:initial</td><td align="right">0.3335s</td><td align="right">0.3349s</td><td align="right"> 0.41%</td></tr><tr><td>🟣 <b>regex</b>:check:initial</td><td align="right">1.2597s</td><td align="right">1.2650s</td><td align="right"> 0.42%</td></tr><tr><td>🟣 <b>syn</b>:check:initial</td><td align="right">2.0521s</td><td align="right">2.0613s</td><td align="right"> 0.45%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check:initial</td><td align="right">7.8275s</td><td align="right">7.8583s</td><td align="right"> 0.39%</td></tr><tr><td>Total</td><td align="right">13.6832s</td><td align="right">13.7442s</td><td align="right"> 0.45%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">1.0046s</td><td align="right"> 0.46%</td></tr></table> It does seem like LLVM optimizers struggle a bit with the current state of the query system. Based on top of https://github.com/rust-lang/rust/pull/107782 and https://github.com/rust-lang/rust/pull/107802. r? `@cjgillot`
Diffstat (limited to 'compiler/rustc_query_impl/src')
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 48 |
2 files changed, 34 insertions, 18 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 2d243e13cc2..d7708a3bc3f 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -21,7 +21,9 @@ use rustc_data_structures::sync::AtomicU64; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::{self, DepKindStruct}; use rustc_middle::query::Key; -use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values}; +use rustc_middle::ty::query::{ + query_keys, query_provided, query_provided_to_value, query_storage, query_values, +}; use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine}; use rustc_middle::ty::TyCtxt; use rustc_span::Span; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 49309db564e..532c1b52f53 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -293,14 +293,14 @@ macro_rules! get_provider { } macro_rules! should_ever_cache_on_disk { - ([]) => {{ - None + ([]$yes:tt $no:tt) => {{ + $no }}; - ([(cache) $($rest:tt)*]) => {{ - Some($crate::plumbing::try_load_from_disk::<Self::Value>) + ([(cache) $($rest:tt)*]$yes:tt $no:tt) => {{ + $yes }}; - ([$other:tt $($modifiers:tt)*]) => { - should_ever_cache_on_disk!([$($modifiers)*]) + ([$other:tt $($modifiers:tt)*]$yes:tt $no:tt) => { + should_ever_cache_on_disk!([$($modifiers)*]$yes $no) }; } @@ -472,7 +472,6 @@ macro_rules! define_queries { $(impl<'tcx> QueryConfig<QueryCtxt<'tcx>> for queries::$name<'tcx> { type Key = query_keys::$name<'tcx>; type Value = query_values::$name<'tcx>; - type Stored = query_stored::$name<'tcx>; const NAME: &'static str = stringify!($name); #[inline] @@ -493,24 +492,39 @@ macro_rules! define_queries { fn query_cache<'a>(tcx: QueryCtxt<'tcx>) -> &'a Self::Cache where 'tcx:'a { - &tcx.query_caches.$name + &tcx.query_system.caches.$name } - fn execute_query(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Stored { + fn execute_query(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value { tcx.$name(key) } #[inline] - // key is only sometimes used #[allow(unused_variables)] - fn compute(qcx: QueryCtxt<'tcx>, key: &Self::Key) -> fn(TyCtxt<'tcx>, Self::Key) -> Self::Value { - get_provider!([$($modifiers)*][qcx, $name, key]) + fn compute(qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value { + query_provided_to_value::$name( + qcx.tcx, + get_provider!([$($modifiers)*][qcx, $name, key])(qcx.tcx, key) + ) } #[inline] - fn try_load_from_disk(qcx: QueryCtxt<'tcx>, key: &Self::Key) -> rustc_query_system::query::TryLoadFromDisk<QueryCtxt<'tcx>, Self> { - let cache_on_disk = Self::cache_on_disk(qcx.tcx, key); - if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None } + fn try_load_from_disk(_qcx: QueryCtxt<'tcx>, _key: &Self::Key) -> rustc_query_system::query::TryLoadFromDisk<QueryCtxt<'tcx>, Self> { + should_ever_cache_on_disk!([$($modifiers)*] { + if Self::cache_on_disk(_qcx.tcx, _key) { + Some(|qcx: QueryCtxt<'tcx>, dep_node| { + let value = $crate::plumbing::try_load_from_disk::<query_provided::$name<'tcx>>( + qcx, + dep_node + ); + value.map(|value| query_provided_to_value::$name(qcx.tcx, value)) + }) + } else { + None + } + } { + None + }) } const ANON: bool = is_anon!([$($modifiers)*]); @@ -633,7 +647,7 @@ macro_rules! define_queries { $crate::profiling_support::alloc_self_profile_query_strings_for_query_cache( tcx, stringify!($name), - &tcx.query_caches.$name, + &tcx.query_system.caches.$name, string_cache, ) }, @@ -725,7 +739,7 @@ macro_rules! define_queries_struct { span: Span, key: <queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key, mode: QueryMode, - ) -> Option<query_stored::$name<'tcx>> { + ) -> Option<query_values::$name<'tcx>> { let qcx = QueryCtxt { tcx, queries: self }; get_query::<queries::$name<'tcx>, _, rustc_middle::dep_graph::DepKind>(qcx, span, key, mode) })* |
