Skip to content

Commit 067f1e2

Browse files
committed
Store a reference instead of a Lrc.
1 parent 6afc9dc commit 067f1e2

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
5454
OP: FnOnce() -> R,
5555
{
5656
ty::tls::with_context(|icx| {
57-
let icx = ty::tls::ImplicitCtxt { current_node, task_deps, ..icx.clone() };
57+
let icx =
58+
ty::tls::ImplicitCtxt { current_node: &current_node, task_deps, ..icx.clone() };
5859

5960
ty::tls::enter_context(&icx, op)
6061
})

compiler/rustc_middle/src/ty/context.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub mod tls;
66

77
use crate::arena::Arena;
8-
use crate::dep_graph::{CurrentDepNode, DepGraph, DepKindStruct};
8+
use crate::dep_graph::{CurrentDepNode, DepGraph, DepKindStruct, DepNode};
99
use crate::infer::canonical::CanonicalVarInfo;
1010
use crate::lint::struct_lint_level;
1111
use crate::metadata::ModChild;
@@ -548,7 +548,12 @@ impl<'tcx> GlobalCtxt<'tcx> {
548548
where
549549
F: FnOnce(TyCtxt<'tcx>) -> R,
550550
{
551-
let icx = tls::ImplicitCtxt::new(self);
551+
let current_node = if self.dep_graph.is_fully_enabled() {
552+
CurrentDepNode::Untracked
553+
} else {
554+
CurrentDepNode::regular(DepNode::NULL)
555+
};
556+
let icx = tls::ImplicitCtxt::new(self, &current_node);
552557
tls::enter_context(&icx, || f(icx.tcx))
553558
}
554559
}
@@ -905,25 +910,32 @@ impl<'tcx> TyCtxt<'tcx> {
905910
impl<'tcx> TyCtxt<'tcx> {
906911
#[instrument(level = "trace", skip(self), ret)]
907912
pub fn create_expansion(self, expn_data: ExpnData) -> LocalExpnId {
908-
let current_node = tls::with_related_context(self, |icx| icx.current_node.clone());
909-
let CurrentDepNode::Regular { dep_node, expn_disambiguators } = current_node else {
910-
bug!("creating an expansion outside of a query")
911-
};
912-
self.with_stable_hashing_context(|ctx| {
913-
LocalExpnId::create_untracked_expansion(expn_data, dep_node, ctx, &expn_disambiguators)
913+
tls::with_related_context(self, |icx| {
914+
let CurrentDepNode::Regular { dep_node, expn_disambiguators } = icx.current_node else {
915+
bug!("creating an expansion outside of a query")
916+
};
917+
self.with_stable_hashing_context(|ctx| {
918+
LocalExpnId::create_untracked_expansion(
919+
expn_data,
920+
dep_node,
921+
ctx,
922+
&expn_disambiguators,
923+
)
924+
})
914925
})
915926
}
916927

917928
/// Fill an empty expansion. This method must not be used outside of the resolver.
918929
#[inline]
919930
#[instrument(level = "trace", skip(self))]
920931
pub fn finalize_expansion(self, expn_id: LocalExpnId, expn_data: ExpnData) {
921-
let current_node = tls::with_related_context(self, |icx| icx.current_node.clone());
922-
let CurrentDepNode::Regular { dep_node, expn_disambiguators } = current_node else {
923-
bug!("creating an expansion outside of a query")
924-
};
925-
self.with_stable_hashing_context(|ctx| {
926-
expn_id.set_untracked_expn_data(expn_data, dep_node, ctx, &expn_disambiguators)
932+
tls::with_related_context(self, |icx| {
933+
let CurrentDepNode::Regular { dep_node, expn_disambiguators } = icx.current_node else {
934+
bug!("creating an expansion outside of a query")
935+
};
936+
self.with_stable_hashing_context(|ctx| {
937+
expn_id.set_untracked_expn_data(expn_data, dep_node, ctx, &expn_disambiguators)
938+
})
927939
});
928940
}
929941

compiler/rustc_middle/src/ty/context/tls.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{GlobalCtxt, TyCtxt};
22

3-
use crate::dep_graph::{CurrentDepNode, DepNode, TaskDepsRef};
3+
use crate::dep_graph::{CurrentDepNode, TaskDepsRef};
44
use crate::query::plumbing::QueryJobId;
55
use rustc_data_structures::sync::{self, Lock};
66
use rustc_errors::Diagnostic;
@@ -33,21 +33,16 @@ pub struct ImplicitCtxt<'a, 'tcx> {
3333

3434
/// The DepNode of the query being executed. This is updated by the dep-graph. This is used to
3535
/// know which query created an expansion.
36-
pub current_node: CurrentDepNode,
36+
pub current_node: &'a CurrentDepNode,
3737

3838
/// The current dep graph task. This is used to add dependencies to queries
3939
/// when executing them.
4040
pub task_deps: TaskDepsRef<'a>,
4141
}
4242

4343
impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
44-
pub fn new(gcx: &'tcx GlobalCtxt<'tcx>) -> Self {
44+
pub fn new(gcx: &'tcx GlobalCtxt<'tcx>, current_node: &'a CurrentDepNode) -> Self {
4545
let tcx = TyCtxt { gcx };
46-
let current_node = if tcx.dep_graph.is_fully_enabled() {
47-
CurrentDepNode::Untracked
48-
} else {
49-
CurrentDepNode::regular(DepNode::NULL)
50-
};
5146
ImplicitCtxt {
5247
tcx,
5348
query: None,

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl QueryContext for QueryCtxt<'_> {
142142
query: Some(token),
143143
diagnostics,
144144
query_depth: current_icx.query_depth + depth_limit as usize,
145-
current_node: current_icx.current_node.clone(),
145+
current_node: current_icx.current_node,
146146
task_deps: current_icx.task_deps,
147147
};
148148

compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1515
use crate::ich::StableHashingContext;
1616
use rustc_data_structures::profiling::SelfProfilerRef;
1717
use rustc_data_structures::stable_hasher::Hash64;
18-
use rustc_data_structures::sync::{Lock, Lrc};
18+
use rustc_data_structures::sync::Lock;
1919
use rustc_data_structures::unhash::UnhashMap;
2020
use rustc_serialize::{opaque::FileEncoder, Encodable};
2121
use rustc_session::Session;
@@ -140,24 +140,20 @@ impl FingerprintStyle {
140140
}
141141
}
142142

143-
#[derive(Clone)]
144143
pub enum CurrentDepNode<K> {
145144
Regular {
146145
dep_node: DepNode<K>,
147146
/// Disambiguation map for expansions created while executing
148147
/// the query with this `DepNode`.
149-
expn_disambiguators: Lrc<Lock<UnhashMap<Hash64, u32>>>,
148+
expn_disambiguators: Lock<UnhashMap<Hash64, u32>>,
150149
},
151150
Anonymous,
152151
Untracked,
153152
}
154153

155154
impl<K> CurrentDepNode<K> {
156155
pub fn regular(dep_node: DepNode<K>) -> CurrentDepNode<K> {
157-
CurrentDepNode::Regular {
158-
dep_node,
159-
expn_disambiguators: Lrc::new(Lock::new(UnhashMap::default())),
160-
}
156+
CurrentDepNode::Regular { dep_node, expn_disambiguators: Lock::new(UnhashMap::default()) }
161157
}
162158
}
163159

0 commit comments

Comments
 (0)