Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_span::def_id::{CrateNum, LocalDefId};
use rustc_span::{ExpnHash, ExpnId};

use crate::mir;
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex};
use crate::ty::{Ty, TyCtxt};

macro_rules! declare_hooks {
Expand Down Expand Up @@ -107,6 +108,13 @@ declare_hooks! {
///
/// Creates the MIR for a given `DefId`, including unreachable code.
hook build_mir_inner_impl(def: LocalDefId) -> mir::Body<'tcx>;

hook try_mark_green(dep_node: &crate::dep_graph::DepNode) -> bool;

hook encode_all_query_results(
encoder: &mut CacheEncoder<'_, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex
) -> ();
}

#[cold]
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::hash_map::Entry;
use std::mem;
use std::sync::Arc;
use std::{fmt, mem};

use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::Mmap;
Expand Down Expand Up @@ -261,7 +261,7 @@ impl OnDiskCache {
tcx.sess.time("encode_query_results", || {
let enc = &mut encoder;
let qri = &mut query_result_index;
(tcx.query_system.fns.encode_query_results)(tcx, enc, qri);
tcx.encode_all_query_results(enc, qri);
});

// Encode side effects.
Expand Down Expand Up @@ -508,7 +508,7 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
// tag matches and the correct amount of bytes was read.
fn decode_tagged<D, T, V>(decoder: &mut D, expected_tag: T) -> V
where
T: Decodable<D> + Eq + std::fmt::Debug,
T: Decodable<D> + Eq + fmt::Debug,
V: Decodable<D>,
D: Decoder,
{
Expand Down Expand Up @@ -829,6 +829,13 @@ pub struct CacheEncoder<'a, 'tcx> {
symbol_index_table: FxHashMap<u32, usize>,
}

impl<'a, 'tcx> fmt::Debug for CacheEncoder<'a, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Add more details here if/when necessary.
f.write_str("CacheEncoder")
}
}

impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
#[inline]
fn source_file_index(&mut self, source_file: Arc<SourceFile>) -> SourceFileIndex {
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use rustc_macros::HashStable;
use rustc_span::{ErrorGuaranteed, Span};
pub use sealed::IntoQueryParam;

use crate::dep_graph;
use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
use crate::ich::StableHashingContext;
use crate::queries::{ExternProviders, Providers, QueryArenas, QueryVTables};
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use crate::query::on_disk_cache::OnDiskCache;
use crate::query::stack::{QueryStackDeferred, QueryStackFrame, QueryStackFrameExtra};
use crate::query::{QueryCache, QueryInfo, QueryJob};
use crate::ty::TyCtxt;
Expand Down Expand Up @@ -216,17 +215,6 @@ impl<'tcx, C: QueryCache> QueryVTable<'tcx, C> {
}
}

pub struct QuerySystemFns {
pub local_providers: Providers,
pub extern_providers: ExternProviders,
pub encode_query_results: for<'tcx> fn(
tcx: TyCtxt<'tcx>,
encoder: &mut CacheEncoder<'_, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex,
),
pub try_mark_green: for<'tcx> fn(tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepNode) -> bool,
}

pub struct QuerySystem<'tcx> {
pub arenas: WorkerLocal<QueryArenas<'tcx>>,
pub query_vtables: QueryVTables<'tcx>,
Expand All @@ -237,7 +225,8 @@ pub struct QuerySystem<'tcx> {
/// This is `None` if we are not incremental compilation mode
pub on_disk_cache: Option<OnDiskCache>,

pub fns: QuerySystemFns,
pub local_providers: Providers,
pub extern_providers: ExternProviders,

pub jobs: AtomicU64,
}
Expand Down Expand Up @@ -327,10 +316,6 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn at(self, span: Span) -> TyCtxtAt<'tcx> {
TyCtxtAt { tcx: self, span }
}

pub fn try_mark_green(self, dep_node: &dep_graph::DepNode) -> bool {
(self.query_system.fns.try_mark_green)(self, dep_node)
}
}

macro_rules! query_helper_param_ty {
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_data_structures::sync::AtomicU64;
use rustc_middle::dep_graph;
use rustc_middle::queries::{self, ExternProviders, Providers};
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use rustc_middle::query::plumbing::{QuerySystem, QuerySystemFns, QueryVTable};
use rustc_middle::query::plumbing::{QuerySystem, QueryVTable};
use rustc_middle::query::{AsLocalKey, QueryCache, QueryMode};
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;
Expand Down Expand Up @@ -59,12 +59,8 @@ pub fn query_system<'tcx>(
arenas: Default::default(),
query_vtables: make_query_vtables(incremental),
on_disk_cache,
fns: QuerySystemFns {
local_providers,
extern_providers,
encode_query_results: encode_all_query_results,
try_mark_green,
},
local_providers,
extern_providers,
jobs: AtomicU64::new(1),
}
}
Expand All @@ -74,4 +70,6 @@ rustc_middle::rustc_with_all_queries! { define_queries! }
pub fn provide(providers: &mut rustc_middle::util::Providers) {
providers.hooks.alloc_self_profile_query_strings = alloc_self_profile_query_strings;
providers.hooks.query_key_hash_verify_all = query_key_hash_verify_all;
providers.hooks.encode_all_query_results = encode_all_query_results;
providers.hooks.try_mark_green = try_mark_green;
}
6 changes: 3 additions & 3 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ macro_rules! hash_result {

macro_rules! call_provider {
([][$tcx:expr, $name:ident, $key:expr]) => {{
($tcx.query_system.fns.local_providers.$name)($tcx, $key)
($tcx.query_system.local_providers.$name)($tcx, $key)
}};
([(separate_provide_extern) $($rest:tt)*][$tcx:expr, $name:ident, $key:expr]) => {{
if let Some(key) = $key.as_local_key() {
($tcx.query_system.fns.local_providers.$name)($tcx, key)
($tcx.query_system.local_providers.$name)($tcx, key)
} else {
($tcx.query_system.fns.extern_providers.$name)($tcx, $key)
($tcx.query_system.extern_providers.$name)($tcx, $key)
}
}};
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
Expand Down
Loading