Skip to content

Commit b3a4fe7

Browse files
committed
Pass DepContext and QueryContext by value when practical
1 parent 9bb6e60 commit b3a4fe7

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
7474
type DepKind = DepKind;
7575

7676
#[inline]
77-
fn with_stable_hashing_context<R>(&self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
78-
TyCtxt::with_stable_hashing_context(*self, f)
77+
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
78+
TyCtxt::with_stable_hashing_context(self, f)
7979
}
8080

8181
#[inline]

compiler/rustc_query_impl/src/plumbing.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
5353
}
5454

5555
impl QueryContext for QueryCtxt<'_> {
56-
fn next_job_id(&self) -> QueryJobId {
56+
fn next_job_id(self) -> QueryJobId {
5757
QueryJobId(
5858
NonZeroU64::new(
5959
self.queries.jobs.fetch_add(1, rustc_data_structures::sync::Ordering::Relaxed),
@@ -62,31 +62,31 @@ impl QueryContext for QueryCtxt<'_> {
6262
)
6363
}
6464

65-
fn current_query_job(&self) -> Option<QueryJobId> {
66-
tls::with_related_context(**self, |icx| icx.query)
65+
fn current_query_job(self) -> Option<QueryJobId> {
66+
tls::with_related_context(*self, |icx| icx.query)
6767
}
6868

69-
fn try_collect_active_jobs(&self) -> Option<QueryMap<DepKind>> {
70-
self.queries.try_collect_active_jobs(**self)
69+
fn try_collect_active_jobs(self) -> Option<QueryMap<DepKind>> {
70+
self.queries.try_collect_active_jobs(*self)
7171
}
7272

7373
// Interactions with on_disk_cache
74-
fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects {
74+
fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects {
7575
self.queries
7676
.on_disk_cache
7777
.as_ref()
78-
.map(|c| c.load_side_effects(**self, prev_dep_node_index))
78+
.map(|c| c.load_side_effects(*self, prev_dep_node_index))
7979
.unwrap_or_default()
8080
}
8181

82-
fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
82+
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects) {
8383
if let Some(c) = self.queries.on_disk_cache.as_ref() {
8484
c.store_side_effects(dep_node_index, side_effects)
8585
}
8686
}
8787

8888
fn store_side_effects_for_anon_node(
89-
&self,
89+
self,
9090
dep_node_index: DepNodeIndex,
9191
side_effects: QuerySideEffects,
9292
) {
@@ -100,7 +100,7 @@ impl QueryContext for QueryCtxt<'_> {
100100
/// captured during execution and the actual result.
101101
#[inline(always)]
102102
fn start_query<R>(
103-
&self,
103+
self,
104104
token: QueryJobId,
105105
depth_limit: bool,
106106
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
@@ -109,14 +109,14 @@ impl QueryContext for QueryCtxt<'_> {
109109
// The `TyCtxt` stored in TLS has the same global interner lifetime
110110
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
111111
// when accessing the `ImplicitCtxt`.
112-
tls::with_related_context(**self, move |current_icx| {
112+
tls::with_related_context(*self, move |current_icx| {
113113
if depth_limit && !self.recursion_limit().value_within_limit(current_icx.query_depth) {
114114
self.depth_limit_error(token);
115115
}
116116

117117
// Update the `ImplicitCtxt` to point to our new query job.
118118
let new_icx = ImplicitCtxt {
119-
tcx: **self,
119+
tcx: *self,
120120
query: Some(token),
121121
diagnostics,
122122
query_depth: current_icx.query_depth + depth_limit as usize,
@@ -130,7 +130,7 @@ impl QueryContext for QueryCtxt<'_> {
130130
})
131131
}
132132

133-
fn depth_limit_error(&self, job: QueryJobId) {
133+
fn depth_limit_error(self, job: QueryJobId) {
134134
let mut span = None;
135135
let mut layout_of_depth = None;
136136
if let Some(map) = self.try_collect_active_jobs() {

compiler/rustc_query_system/src/dep_graph/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub trait DepContext: Copy {
2323
type DepKind: self::DepKind;
2424

2525
/// Create a hashing context for hashing new results.
26-
fn with_stable_hashing_context<R>(&self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
26+
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
2727

2828
/// Access the DepGraph.
2929
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
@@ -37,7 +37,7 @@ pub trait DepContext: Copy {
3737
fn dep_kind_info(&self, dep_node: Self::DepKind) -> &DepKindStruct<Self>;
3838

3939
#[inline(always)]
40-
fn fingerprint_style(&self, kind: Self::DepKind) -> FingerprintStyle {
40+
fn fingerprint_style(self, kind: Self::DepKind) -> FingerprintStyle {
4141
let data = self.dep_kind_info(kind);
4242
if data.is_anon {
4343
return FingerprintStyle::Opaque;
@@ -47,7 +47,7 @@ pub trait DepContext: Copy {
4747

4848
#[inline(always)]
4949
/// Return whether this kind always require evaluation.
50-
fn is_eval_always(&self, kind: Self::DepKind) -> bool {
50+
fn is_eval_always(self, kind: Self::DepKind) -> bool {
5151
self.dep_kind_info(kind).is_eval_always
5252
}
5353

compiler/rustc_query_system/src/query/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,22 @@ impl QuerySideEffects {
101101
}
102102

103103
pub trait QueryContext: HasDepContext {
104-
fn next_job_id(&self) -> QueryJobId;
104+
fn next_job_id(self) -> QueryJobId;
105105

106106
/// Get the query information from the TLS context.
107-
fn current_query_job(&self) -> Option<QueryJobId>;
107+
fn current_query_job(self) -> Option<QueryJobId>;
108108

109-
fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>>;
109+
fn try_collect_active_jobs(self) -> Option<QueryMap<Self::DepKind>>;
110110

111111
/// Load side effects associated to the node in the previous session.
112-
fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
112+
fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
113113

114114
/// Register diagnostics for the given node, for use in next session.
115-
fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
115+
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
116116

117117
/// Register diagnostics for the given node, for use in next session.
118118
fn store_side_effects_for_anon_node(
119-
&self,
119+
self,
120120
dep_node_index: DepNodeIndex,
121121
side_effects: QuerySideEffects,
122122
);
@@ -125,12 +125,12 @@ pub trait QueryContext: HasDepContext {
125125
/// new query job while it executes. It returns the diagnostics
126126
/// captured during execution and the actual result.
127127
fn start_query<R>(
128-
&self,
128+
self,
129129
token: QueryJobId,
130130
depth_limit: bool,
131131
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
132132
compute: impl FnOnce() -> R,
133133
) -> R;
134134

135-
fn depth_limit_error(&self, job: QueryJobId);
135+
fn depth_limit_error(self, job: QueryJobId);
136136
}

0 commit comments

Comments
 (0)