From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_query_impl/Cargo.toml | 2 +- compiler/rustc_query_impl/src/lib.rs | 1 - compiler/rustc_query_impl/src/on_disk_cache.rs | 6 +- compiler/rustc_query_impl/src/plumbing.rs | 66 ++++++++++++---------- compiler/rustc_query_impl/src/profiling_support.rs | 4 +- 5 files changed, 42 insertions(+), 37 deletions(-) (limited to 'compiler/rustc_query_impl') diff --git a/compiler/rustc_query_impl/Cargo.toml b/compiler/rustc_query_impl/Cargo.toml index b2111a126..46e776264 100644 --- a/compiler/rustc_query_impl/Cargo.toml +++ b/compiler/rustc_query_impl/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.0" edition = "2021" [lib] -doctest = false + [dependencies] measureme = "10.0.0" diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index d426a2b6b..2d243e13c 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -34,7 +34,6 @@ use rustc_query_system::query::*; pub use rustc_query_system::query::{deadlock, QueryContext}; pub use rustc_query_system::query::QueryConfig; -pub(crate) use rustc_query_system::query::QueryVTable; mod on_disk_cache; pub use on_disk_cache::OnDiskCache; diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index ac9653b90..70c481fb0 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -227,7 +227,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { *self.serialized_data.write() = None; } - fn serialize<'tcx>(&self, tcx: TyCtxt<'tcx>, encoder: FileEncoder) -> FileEncodeResult { + fn serialize(&self, tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult { // Serializing the `DepGraph` should not modify it. tcx.dep_graph.with_ignore(|| { // Allocate `SourceFileIndex`es. @@ -787,7 +787,7 @@ impl<'a, 'tcx> Decodable> for DefId { // which means that the definition with this hash is guaranteed to // still exist in the current compilation session. d.tcx.def_path_hash_to_def_id(def_path_hash, &mut || { - panic!("Failed to convert DefPathHash {:?}", def_path_hash) + panic!("Failed to convert DefPathHash {def_path_hash:?}") }) } } @@ -965,7 +965,7 @@ impl<'a, 'tcx> Encodable> for Symbol { s.emit_str(self.as_str()); } Entry::Occupied(o) => { - let x = o.get().clone(); + let x = *o.get(); s.emit_u8(SYMBOL_OFFSET); s.emit_usize(x); } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 8d5d84c5d..6125ad4ef 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -66,7 +66,7 @@ impl QueryContext for QueryCtxt<'_> { tls::with_related_context(**self, |icx| icx.query) } - fn try_collect_active_jobs(&self) -> Option { + fn try_collect_active_jobs(&self) -> Option> { self.queries.try_collect_active_jobs(**self) } @@ -195,7 +195,7 @@ impl<'tcx> QueryCtxt<'tcx> { #[derive(Clone, Copy)] pub(crate) struct QueryStruct<'tcx> { - pub try_collect_active_jobs: fn(QueryCtxt<'tcx>, &mut QueryMap) -> Option<()>, + pub try_collect_active_jobs: fn(QueryCtxt<'tcx>, &mut QueryMap) -> Option<()>, pub alloc_self_profile_query_strings: fn(TyCtxt<'tcx>, &mut QueryKeyStringCache), pub encode_query_results: Option, &mut CacheEncoder<'_, 'tcx>, &mut EncodedDepNodeIndex)>, @@ -313,7 +313,7 @@ pub(crate) fn create_query_frame< key: K, kind: DepKind, name: &'static str, -) -> QueryStackFrame { +) -> QueryStackFrame { // Disable visible paths printing for performance reasons. // Showing visible path instead of any path is not that important in production. let description = ty::print::with_no_visible_paths!( @@ -321,7 +321,7 @@ pub(crate) fn create_query_frame< ty::print::with_forced_impl_filename_line!(do_describe(tcx.tcx, key)) ); let description = - if tcx.sess.verbose() { format!("{} [{:?}]", description, name) } else { description }; + if tcx.sess.verbose() { format!("{description} [{name:?}]") } else { description }; let span = if kind == dep_graph::DepKind::def_span { // The `def_span` query is used to calculate `default_span`, // so exit to avoid infinite recursion. @@ -346,7 +346,7 @@ pub(crate) fn create_query_frame< }; let ty_adt_id = key.ty_adt_id(); - QueryStackFrame::new(name, description, span, def_id, def_kind, ty_adt_id, hash) + QueryStackFrame::new(description, span, def_id, def_kind, kind, ty_adt_id, hash) } fn try_load_from_on_disk_cache<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) @@ -378,7 +378,7 @@ fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool where Q: QueryConfig>, Q::Key: DepNodeParams>, - Q::Value: Value>, + Q::Value: Value, DepKind>, { // We must avoid ever having to call `force_from_dep_node()` for a // `DepNode::codegen_unit`: @@ -402,7 +402,7 @@ where #[cfg(debug_assertions)] let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered(); let tcx = QueryCtxt::from_tcx(tcx); - force_query::(tcx, key, dep_node); + force_query::(tcx, key, dep_node); true } else { false @@ -480,7 +480,7 @@ macro_rules! define_queries { type Cache = query_storage::$name<'tcx>; #[inline(always)] - fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState + fn query_state<'a>(tcx: QueryCtxt<'tcx>) -> &'a QueryState where QueryCtxt<'tcx>: 'a { &tcx.queries.$name @@ -493,28 +493,32 @@ macro_rules! define_queries { &tcx.query_caches.$name } + fn execute_query(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Stored { + tcx.$name(key) + } + #[inline] - fn make_vtable(tcx: QueryCtxt<'tcx>, key: &Self::Key) -> - QueryVTable, Self::Key, Self::Value> - { - let compute = get_provider!([$($modifiers)*][tcx, $name, key]); - let cache_on_disk = Self::cache_on_disk(tcx.tcx, key); - QueryVTable { - anon: is_anon!([$($modifiers)*]), - eval_always: is_eval_always!([$($modifiers)*]), - depth_limit: depth_limit!([$($modifiers)*]), - feedable: feedable!([$($modifiers)*]), - dep_kind: dep_graph::DepKind::$name, - hash_result: hash_result!([$($modifiers)*]), - handle_cycle_error: handle_cycle_error!([$($modifiers)*]), - compute, - try_load_from_disk: if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None }, - } + // 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 execute_query(tcx: TyCtxt<'tcx>, k: Self::Key) -> Self::Stored { - tcx.$name(k) + #[inline] + fn try_load_from_disk(qcx: QueryCtxt<'tcx>, key: &Self::Key) -> rustc_query_system::query::TryLoadFromDisk, Self> { + let cache_on_disk = Self::cache_on_disk(qcx.tcx, key); + if cache_on_disk { should_ever_cache_on_disk!([$($modifiers)*]) } else { None } } + + const ANON: bool = is_anon!([$($modifiers)*]); + const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]); + const DEPTH_LIMIT: bool = depth_limit!([$($modifiers)*]); + const FEEDABLE: bool = feedable!([$($modifiers)*]); + + const DEP_KIND: rustc_middle::dep_graph::DepKind = dep_graph::DepKind::$name; + const HANDLE_CYCLE_ERROR: rustc_query_system::HandleCycleError = handle_cycle_error!([$($modifiers)*]); + + const HASH_RESULT: rustc_query_system::query::HashResult, Self> = hash_result!([$($modifiers)*]); })* #[allow(nonstandard_style)] @@ -587,9 +591,10 @@ macro_rules! define_queries { use $crate::plumbing::{QueryStruct, QueryCtxt}; use $crate::profiling_support::QueryKeyStringCache; use rustc_query_system::query::QueryMap; + use rustc_middle::dep_graph::DepKind; pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> { - fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap) -> Option<()> { + fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap) -> Option<()> { None } fn noop_alloc_self_profile_query_strings(_: TyCtxt<'_>, _: &mut QueryKeyStringCache) {} @@ -675,7 +680,8 @@ macro_rules! define_queries_struct { $( $(#[$attr])* $name: QueryState< - as QueryConfig>>::Key + as QueryConfig>>::Key, + rustc_middle::dep_graph::DepKind, >, )* } @@ -684,7 +690,7 @@ macro_rules! define_queries_struct { pub(crate) fn try_collect_active_jobs( &'tcx self, tcx: TyCtxt<'tcx>, - ) -> Option { + ) -> Option> { let tcx = QueryCtxt { tcx, queries: self }; let mut jobs = QueryMap::default(); @@ -718,7 +724,7 @@ macro_rules! define_queries_struct { mode: QueryMode, ) -> Option> { let qcx = QueryCtxt { tcx, queries: self }; - get_query::, _>(qcx, span, key, mode) + get_query::, _, rustc_middle::dep_graph::DepKind>(qcx, span, key, mode) })* } }; diff --git a/compiler/rustc_query_impl/src/profiling_support.rs b/compiler/rustc_query_impl/src/profiling_support.rs index 81114f2cd..4743170e9 100644 --- a/compiler/rustc_query_impl/src/profiling_support.rs +++ b/compiler/rustc_query_impl/src/profiling_support.rs @@ -111,7 +111,7 @@ impl IntoSelfProfilingString for T { &self, builder: &mut QueryKeyStringBuilder<'_, '_>, ) -> StringId { - let s = format!("{:?}", self); + let s = format!("{self:?}"); builder.profiler.alloc_string(&s[..]) } } @@ -278,7 +278,7 @@ pub(crate) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>( /// If we are recording only summary data, the ids will point to /// just the query names. If we are recording query keys too, we /// allocate the corresponding strings here. -pub fn alloc_self_profile_query_strings<'tcx>(tcx: TyCtxt<'tcx>) { +pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) { if !tcx.prof.enabled() { return; } -- cgit v1.2.3