Skip to content

Commit

Permalink
Rename Ctxt and CTX to Tcx and Qcx
Browse files Browse the repository at this point in the history
This makes it consistent and clear which context is used.
  • Loading branch information
Noratrieb committed Nov 6, 2022
1 parent 16558bd commit 6d26ea8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_query_system/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<Key, Value> Cache<Key, Value> {
}

impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
pub fn get<CTX: DepContext>(&self, key: &Key, tcx: CTX) -> Option<Value> {
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
Some(self.hashmap.borrow().get(key)?.get(tcx))
}

Expand All @@ -46,7 +46,7 @@ impl<T: Clone> WithDepNode<T> {
WithDepNode { dep_node, cached_value }
}

pub fn get<CTX: DepContext>(&self, tcx: CTX) -> T {
pub fn get<Tcx: DepContext>(&self, tcx: Tcx) -> T {
tcx.dep_graph().read_index(self.dep_node);
self.cached_value.clone()
}
Expand Down
36 changes: 18 additions & 18 deletions compiler/rustc_query_system/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ impl<K: DepKind> DepNode<K> {
/// Creates a new, parameterless DepNode. This method will assert
/// that the DepNode corresponding to the given DepKind actually
/// does not require any parameters.
pub fn new_no_params<Ctxt>(tcx: Ctxt, kind: K) -> DepNode<K>
pub fn new_no_params<Tcx>(tcx: Tcx, kind: K) -> DepNode<K>
where
Ctxt: super::DepContext<DepKind = K>,
Tcx: super::DepContext<DepKind = K>,
{
debug_assert_eq!(tcx.fingerprint_style(kind), FingerprintStyle::Unit);
DepNode { kind, hash: Fingerprint::ZERO.into() }
}

pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
pub fn construct<Tcx, Key>(tcx: Tcx, kind: K, arg: &Key) -> DepNode<K>
where
Ctxt: super::DepContext<DepKind = K>,
Key: DepNodeParams<Ctxt>,
Tcx: super::DepContext<DepKind = K>,
Key: DepNodeParams<Tcx>,
{
let hash = arg.to_fingerprint(tcx);
let dep_node = DepNode { kind, hash: hash.into() };
Expand All @@ -93,9 +93,9 @@ impl<K: DepKind> DepNode<K> {
/// Construct a DepNode from the given DepKind and DefPathHash. This
/// method will assert that the given DepKind actually requires a
/// single DefId/DefPathHash parameter.
pub fn from_def_path_hash<Ctxt>(tcx: Ctxt, def_path_hash: DefPathHash, kind: K) -> Self
pub fn from_def_path_hash<Tcx>(tcx: Tcx, def_path_hash: DefPathHash, kind: K) -> Self
where
Ctxt: super::DepContext<DepKind = K>,
Tcx: super::DepContext<DepKind = K>,
{
debug_assert!(tcx.fingerprint_style(kind) == FingerprintStyle::DefPathHash);
DepNode { kind, hash: def_path_hash.0.into() }
Expand All @@ -108,18 +108,18 @@ impl<K: DepKind> fmt::Debug for DepNode<K> {
}
}

pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
pub trait DepNodeParams<Tcx: DepContext>: fmt::Debug + Sized {
fn fingerprint_style() -> FingerprintStyle;

/// This method turns the parameters of a DepNodeConstructor into an opaque
/// Fingerprint to be used in DepNode.
/// Not all DepNodeParams support being turned into a Fingerprint (they
/// don't need to if the corresponding DepNode is anonymous).
fn to_fingerprint(&self, _: Ctxt) -> Fingerprint {
fn to_fingerprint(&self, _: Tcx) -> Fingerprint {
panic!("Not implemented. Accidentally called on anonymous node?")
}

fn to_debug_str(&self, _: Ctxt) -> String {
fn to_debug_str(&self, _: Tcx) -> String {
format!("{:?}", self)
}

Expand All @@ -129,10 +129,10 @@ pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
/// It is always valid to return `None` here, in which case incremental
/// compilation will treat the query as having changed instead of forcing it.
fn recover(tcx: Ctxt, dep_node: &DepNode<Ctxt::DepKind>) -> Option<Self>;
fn recover(tcx: Tcx, dep_node: &DepNode<Tcx::DepKind>) -> Option<Self>;
}

impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
impl<Tcx: DepContext, T> DepNodeParams<Tcx> for T
where
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
{
Expand All @@ -142,7 +142,7 @@ where
}

#[inline(always)]
default fn to_fingerprint(&self, tcx: Ctxt) -> Fingerprint {
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint {
tcx.with_stable_hashing_context(|mut hcx| {
let mut hasher = StableHasher::new();
self.hash_stable(&mut hcx, &mut hasher);
Expand All @@ -151,12 +151,12 @@ where
}

#[inline(always)]
default fn to_debug_str(&self, _: Ctxt) -> String {
default fn to_debug_str(&self, _: Tcx) -> String {
format!("{:?}", *self)
}

#[inline(always)]
default fn recover(_: Ctxt, _: &DepNode<Ctxt::DepKind>) -> Option<Self> {
default fn recover(_: Tcx, _: &DepNode<Tcx::DepKind>) -> Option<Self> {
None
}
}
Expand All @@ -166,7 +166,7 @@ where
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
/// jump table instead of large matches.
pub struct DepKindStruct<CTX: DepContext> {
pub struct DepKindStruct<Tcx: DepContext> {
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
/// When their result is needed, it is recomputed. They are useful for fine-grained
/// dependency tracking, and caching within one compiler invocation.
Expand Down Expand Up @@ -216,10 +216,10 @@ pub struct DepKindStruct<CTX: DepContext> {
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
/// `DefId` in `tcx.def_path_hash_to_def_id`.
pub force_from_dep_node: Option<fn(tcx: CTX, dep_node: DepNode<CTX::DepKind>) -> bool>,
pub force_from_dep_node: Option<fn(tcx: Tcx, dep_node: DepNode<Tcx::DepKind>) -> bool>,

/// Invoke a query to put the on-disk cached value in memory.
pub try_load_from_on_disk_cache: Option<fn(CTX, DepNode<CTX::DepKind>)>,
pub try_load_from_on_disk_cache: Option<fn(Tcx, DepNode<Tcx::DepKind>)>,
}

/// A "work product" corresponds to a `.o` (or other) file that we
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ impl<K: DepKind> DepGraph<K> {

/// Executes something within an "anonymous" task, that is, a task the
/// `DepNode` of which is determined by the list of inputs it read from.
pub fn with_anon_task<Ctxt: DepContext<DepKind = K>, OP, R>(
pub fn with_anon_task<Tcx: DepContext<DepKind = K>, OP, R>(
&self,
cx: Ctxt,
cx: Tcx,
dep_kind: K,
op: OP,
) -> (R, DepNodeIndex)
Expand Down Expand Up @@ -571,9 +571,9 @@ impl<K: DepKind> DepGraph<K> {
/// A node will have an index, when it's already been marked green, or when we can mark it
/// green. This function will mark the current task as a reader of the specified node, when
/// a node index can be found for that node.
pub fn try_mark_green<Ctxt: QueryContext<DepKind = K>>(
pub fn try_mark_green<Qcx: QueryContext<DepKind = K>>(
&self,
qcx: Ctxt,
qcx: Qcx,
dep_node: &DepNode<K>,
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
Expand All @@ -599,9 +599,9 @@ impl<K: DepKind> DepGraph<K> {
}

#[instrument(skip(self, qcx, data, parent_dep_node_index), level = "debug")]
fn try_mark_parent_green<Ctxt: QueryContext<DepKind = K>>(
fn try_mark_parent_green<Qcx: QueryContext<DepKind = K>>(
&self,
qcx: Ctxt,
qcx: Qcx,
data: &DepGraphData<K>,
parent_dep_node_index: SerializedDepNodeIndex,
dep_node: &DepNode<K>,
Expand Down Expand Up @@ -687,9 +687,9 @@ impl<K: DepKind> DepGraph<K> {

/// Try to mark a dep-node which existed in the previous compilation session as green.
#[instrument(skip(self, qcx, data, prev_dep_node_index), level = "debug")]
fn try_mark_previous_green<Ctxt: QueryContext<DepKind = K>>(
fn try_mark_previous_green<Qcx: QueryContext<DepKind = K>>(
&self,
qcx: Ctxt,
qcx: Qcx,
data: &DepGraphData<K>,
prev_dep_node_index: SerializedDepNodeIndex,
dep_node: &DepNode<K>,
Expand Down Expand Up @@ -755,9 +755,9 @@ impl<K: DepKind> DepGraph<K> {
/// This may be called concurrently on multiple threads for the same dep node.
#[cold]
#[inline(never)]
fn emit_side_effects<Ctxt: QueryContext<DepKind = K>>(
fn emit_side_effects<Qcx: QueryContext<DepKind = K>>(
&self,
qcx: Ctxt,
qcx: Qcx,
data: &DepGraphData<K>,
dep_node_index: DepNodeIndex,
side_effects: QuerySideEffects,
Expand Down Expand Up @@ -799,7 +799,7 @@ impl<K: DepKind> DepGraph<K> {
//
// This method will only load queries that will end up in the disk cache.
// Other queries will not be executed.
pub fn exec_cache_promotions<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
pub fn exec_cache_promotions<Tcx: DepContext<DepKind = K>>(&self, tcx: Tcx) {
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");

let data = self.data.as_ref().unwrap();
Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_query_system/src/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
use std::fmt::Debug;
use std::hash::Hash;

pub trait QueryConfig<CTX: QueryContext> {
pub trait QueryConfig<Qcx: QueryContext> {
const NAME: &'static str;

type Key: Eq + Hash + Clone + Debug;
Expand All @@ -21,47 +21,47 @@ pub trait QueryConfig<CTX: QueryContext> {
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<Self::Key>
fn query_state<'a>(tcx: Qcx) -> &'a QueryState<Self::Key>
where
CTX: 'a;
Qcx: 'a;

// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_cache<'a>(tcx: CTX) -> &'a Self::Cache
fn query_cache<'a>(tcx: Qcx) -> &'a Self::Cache
where
CTX: 'a;
Qcx: 'a;

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn make_vtable(tcx: CTX, key: &Self::Key) -> QueryVTable<CTX, Self::Key, Self::Value>;
fn make_vtable(tcx: Qcx, key: &Self::Key) -> QueryVTable<Qcx, Self::Key, Self::Value>;

fn cache_on_disk(tcx: CTX::DepContext, key: &Self::Key) -> bool;
fn cache_on_disk(tcx: Qcx::DepContext, key: &Self::Key) -> bool;

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn execute_query(tcx: CTX::DepContext, k: Self::Key) -> Self::Stored;
fn execute_query(tcx: Qcx::DepContext, k: Self::Key) -> Self::Stored;
}

#[derive(Copy, Clone)]
pub struct QueryVTable<CTX: QueryContext, K, V> {
pub struct QueryVTable<Qcx: QueryContext, K, V> {
pub anon: bool,
pub dep_kind: CTX::DepKind,
pub dep_kind: Qcx::DepKind,
pub eval_always: bool,
pub depth_limit: bool,

pub compute: fn(CTX::DepContext, K) -> V,
pub compute: fn(Qcx::DepContext, K) -> V,
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
pub handle_cycle_error: HandleCycleError,
// NOTE: this is also `None` if `cache_on_disk()` returns false, not just if it's unsupported by the query
pub try_load_from_disk: Option<fn(CTX, SerializedDepNodeIndex) -> Option<V>>,
pub try_load_from_disk: Option<fn(Qcx, SerializedDepNodeIndex) -> Option<V>>,
}

impl<CTX: QueryContext, K, V> QueryVTable<CTX, K, V> {
pub(crate) fn to_dep_node(&self, tcx: CTX::DepContext, key: &K) -> DepNode<CTX::DepKind>
impl<Qcx: QueryContext, K, V> QueryVTable<Qcx, K, V> {
pub(crate) fn to_dep_node(&self, tcx: Qcx::DepContext, key: &K) -> DepNode<Qcx::DepKind>
where
K: crate::dep_graph::DepNodeParams<CTX::DepContext>,
K: crate::dep_graph::DepNodeParams<Qcx::DepContext>,
{
DepNode::construct(tcx, self.dep_kind, key)
}

pub(crate) fn compute(&self, tcx: CTX::DepContext, key: K) -> V {
pub(crate) fn compute(&self, tcx: Qcx::DepContext, key: K) -> V {
(self.compute)(tcx, key)
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_query_system/src/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ pub(crate) fn report_cycle<'a>(
cycle_diag.into_diagnostic(&sess.parse_sess.span_diagnostic)
}

pub fn print_query_stack<CTX: QueryContext>(
qcx: CTX,
pub fn print_query_stack<Qcx: QueryContext>(
qcx: Qcx,
mut current_query: Option<QueryJobId>,
handler: &Handler,
num_frames: Option<usize>,
Expand Down
Loading

0 comments on commit 6d26ea8

Please sign in to comment.