Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 79a5762

Browse files
committed
Move DepNodeExt outside of the macro.
1 parent b5c496d commit 79a5762

File tree

1 file changed

+91
-95
lines changed

1 file changed

+91
-95
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 91 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -191,101 +191,10 @@ macro_rules! define_dep_nodes {
191191
)*
192192
}
193193

194-
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
195-
196-
// We keep a lot of `DepNode`s in memory during compilation. It's not
197-
// required that their size stay the same, but we don't want to change
198-
// it inadvertently. This assert just ensures we're aware of any change.
199-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
200-
static_assert_size!(DepNode, 17);
201-
202-
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
203-
static_assert_size!(DepNode, 24);
204-
205-
pub trait DepNodeExt: Sized {
206-
/// Construct a DepNode from the given DepKind and DefPathHash. This
207-
/// method will assert that the given DepKind actually requires a
208-
/// single DefId/DefPathHash parameter.
209-
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
210-
211-
/// Extracts the DefId corresponding to this DepNode. This will work
212-
/// if two conditions are met:
213-
///
214-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
215-
/// 2. the item that the DefPath refers to exists in the current tcx.
216-
///
217-
/// Condition (1) is determined by the DepKind variant of the
218-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
219-
/// refers to something from the previous compilation session that
220-
/// has been removed.
221-
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
222-
223-
/// Used in testing
224-
fn from_label_string(label: &str, def_path_hash: DefPathHash)
225-
-> Result<Self, ()>;
226-
227-
/// Used in testing
228-
fn has_label_string(label: &str) -> bool;
229-
}
230-
231-
impl DepNodeExt for DepNode {
232-
/// Construct a DepNode from the given DepKind and DefPathHash. This
233-
/// method will assert that the given DepKind actually requires a
234-
/// single DefId/DefPathHash parameter.
235-
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
236-
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
237-
DepNode {
238-
kind,
239-
hash: def_path_hash.0.into(),
240-
}
241-
}
242-
243-
/// Extracts the DefId corresponding to this DepNode. This will work
244-
/// if two conditions are met:
245-
///
246-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
247-
/// 2. the item that the DefPath refers to exists in the current tcx.
248-
///
249-
/// Condition (1) is determined by the DepKind variant of the
250-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
251-
/// refers to something from the previous compilation session that
252-
/// has been removed.
253-
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
254-
if self.kind.can_reconstruct_query_key() {
255-
tcx.queries.on_disk_cache.as_ref()?.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
256-
} else {
257-
None
258-
}
259-
}
260-
261-
/// Used in testing
262-
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
263-
let kind = match label {
264-
$(
265-
stringify!($variant) => DepKind::$variant,
266-
)*
267-
_ => return Err(()),
268-
};
269-
270-
if !kind.can_reconstruct_query_key() {
271-
return Err(());
272-
}
273-
274-
if kind.has_params() {
275-
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
276-
} else {
277-
Ok(DepNode::new_no_params(kind))
278-
}
279-
}
280-
281-
/// Used in testing
282-
fn has_label_string(label: &str) -> bool {
283-
match label {
284-
$(
285-
stringify!($variant) => true,
286-
)*
287-
_ => false,
288-
}
194+
fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> {
195+
match label {
196+
$(stringify!($variant) => Ok(DepKind::$variant),)*
197+
_ => Err(()),
289198
}
290199
}
291200

@@ -312,6 +221,93 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
312221
[] CompileCodegenUnit(Symbol),
313222
]);
314223

224+
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
225+
226+
// We keep a lot of `DepNode`s in memory during compilation. It's not
227+
// required that their size stay the same, but we don't want to change
228+
// it inadvertently. This assert just ensures we're aware of any change.
229+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
230+
static_assert_size!(DepNode, 17);
231+
232+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
233+
static_assert_size!(DepNode, 24);
234+
235+
pub trait DepNodeExt: Sized {
236+
/// Construct a DepNode from the given DepKind and DefPathHash. This
237+
/// method will assert that the given DepKind actually requires a
238+
/// single DefId/DefPathHash parameter.
239+
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
240+
241+
/// Extracts the DefId corresponding to this DepNode. This will work
242+
/// if two conditions are met:
243+
///
244+
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
245+
/// 2. the item that the DefPath refers to exists in the current tcx.
246+
///
247+
/// Condition (1) is determined by the DepKind variant of the
248+
/// DepNode. Condition (2) might not be fulfilled if a DepNode
249+
/// refers to something from the previous compilation session that
250+
/// has been removed.
251+
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
252+
253+
/// Used in testing
254+
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<Self, ()>;
255+
256+
/// Used in testing
257+
fn has_label_string(label: &str) -> bool;
258+
}
259+
260+
impl DepNodeExt for DepNode {
261+
/// Construct a DepNode from the given DepKind and DefPathHash. This
262+
/// method will assert that the given DepKind actually requires a
263+
/// single DefId/DefPathHash parameter.
264+
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
265+
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
266+
DepNode { kind, hash: def_path_hash.0.into() }
267+
}
268+
269+
/// Extracts the DefId corresponding to this DepNode. This will work
270+
/// if two conditions are met:
271+
///
272+
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
273+
/// 2. the item that the DefPath refers to exists in the current tcx.
274+
///
275+
/// Condition (1) is determined by the DepKind variant of the
276+
/// DepNode. Condition (2) might not be fulfilled if a DepNode
277+
/// refers to something from the previous compilation session that
278+
/// has been removed.
279+
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
280+
if self.kind.can_reconstruct_query_key() {
281+
tcx.queries
282+
.on_disk_cache
283+
.as_ref()?
284+
.def_path_hash_to_def_id(tcx, DefPathHash(self.hash.into()))
285+
} else {
286+
None
287+
}
288+
}
289+
290+
/// Used in testing
291+
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
292+
let kind = dep_kind_from_label_string(label)?;
293+
294+
if !kind.can_reconstruct_query_key() {
295+
return Err(());
296+
}
297+
298+
if kind.has_params() {
299+
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
300+
} else {
301+
Ok(DepNode::new_no_params(kind))
302+
}
303+
}
304+
305+
/// Used in testing
306+
fn has_label_string(label: &str) -> bool {
307+
dep_kind_from_label_string(label).is_ok()
308+
}
309+
}
310+
315311
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
316312
#[inline]
317313
fn can_reconstruct_query_key() -> bool {

0 commit comments

Comments
 (0)