Skip to content

Commit 42baef9

Browse files
committed
Move DepNodeExt outside of the macro.
1 parent f06e3d9 commit 42baef9

File tree

1 file changed

+78
-85
lines changed

1 file changed

+78
-85
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

+78-85
Original file line numberDiff line numberDiff line change
@@ -375,91 +375,10 @@ macro_rules! define_dep_nodes {
375375
)*
376376
}
377377

378-
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
379-
380-
pub trait DepNodeExt: Sized {
381-
/// Construct a DepNode from the given DepKind and DefPathHash. This
382-
/// method will assert that the given DepKind actually requires a
383-
/// single DefId/DefPathHash parameter.
384-
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
385-
386-
/// Extracts the DefId corresponding to this DepNode. This will work
387-
/// if two conditions are met:
388-
///
389-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
390-
/// 2. the item that the DefPath refers to exists in the current tcx.
391-
///
392-
/// Condition (1) is determined by the DepKind variant of the
393-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
394-
/// refers to something from the previous compilation session that
395-
/// has been removed.
396-
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
397-
398-
/// Used in testing
399-
fn from_label_string(label: &str, def_path_hash: DefPathHash)
400-
-> Result<Self, ()>;
401-
402-
/// Used in testing
403-
fn has_label_string(label: &str) -> bool;
404-
}
405-
406-
impl DepNodeExt for DepNode {
407-
/// Construct a DepNode from the given DepKind and DefPathHash. This
408-
/// method will assert that the given DepKind actually requires a
409-
/// single DefId/DefPathHash parameter.
410-
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
411-
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
412-
DepNode {
413-
kind,
414-
hash: def_path_hash.0,
415-
}
416-
}
417-
418-
/// Extracts the DefId corresponding to this DepNode. This will work
419-
/// if two conditions are met:
420-
///
421-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
422-
/// 2. the item that the DefPath refers to exists in the current tcx.
423-
///
424-
/// Condition (1) is determined by the DepKind variant of the
425-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
426-
/// refers to something from the previous compilation session that
427-
/// has been removed.
428-
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
429-
if self.kind.can_reconstruct_query_key() {
430-
let def_path_hash = DefPathHash(self.hash);
431-
tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
432-
} else {
433-
None
434-
}
435-
}
436-
437-
/// Used in testing
438-
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
439-
match label {
440-
$(stringify!($name) => {
441-
let kind = &dep_kind::$name;
442-
443-
if !kind.can_reconstruct_query_key() {
444-
Err(())
445-
} else if kind.has_params() {
446-
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
447-
} else {
448-
Ok(DepNode::new_no_params(kind))
449-
}
450-
})*
451-
_ => Err(()),
452-
}
453-
}
454-
455-
/// Used in testing
456-
fn has_label_string(label: &str) -> bool {
457-
match label {
458-
$(
459-
stringify!($name) => true,
460-
)*
461-
_ => false,
462-
}
378+
fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> {
379+
match label {
380+
$(stringify!($name) => Ok(&dep_kind::$name),)*
381+
_ => Err(()),
463382
}
464383
}
465384

@@ -728,6 +647,80 @@ impl<D: Decoder> Decodable<D> for &dyn DepKindTrait {
728647
}
729648
}
730649

650+
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
651+
652+
pub trait DepNodeExt: Sized {
653+
/// Construct a DepNode from the given DepKind and DefPathHash. This
654+
/// method will assert that the given DepKind actually requires a
655+
/// single DefId/DefPathHash parameter.
656+
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
657+
658+
/// Extracts the DefId corresponding to this DepNode. This will work
659+
/// if two conditions are met:
660+
///
661+
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
662+
/// 2. the item that the DefPath refers to exists in the current tcx.
663+
///
664+
/// Condition (1) is determined by the DepKind variant of the
665+
/// DepNode. Condition (2) might not be fulfilled if a DepNode
666+
/// refers to something from the previous compilation session that
667+
/// has been removed.
668+
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
669+
670+
/// Used in testing
671+
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<Self, ()>;
672+
673+
/// Used in testing
674+
fn has_label_string(label: &str) -> bool;
675+
}
676+
677+
impl DepNodeExt for DepNode {
678+
/// Construct a DepNode from the given DepKind and DefPathHash. This
679+
/// method will assert that the given DepKind actually requires a
680+
/// single DefId/DefPathHash parameter.
681+
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
682+
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
683+
DepNode { kind, hash: def_path_hash.0 }
684+
}
685+
686+
/// Extracts the DefId corresponding to this DepNode. This will work
687+
/// if two conditions are met:
688+
///
689+
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
690+
/// 2. the item that the DefPath refers to exists in the current tcx.
691+
///
692+
/// Condition (1) is determined by the DepKind variant of the
693+
/// DepNode. Condition (2) might not be fulfilled if a DepNode
694+
/// refers to something from the previous compilation session that
695+
/// has been removed.
696+
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
697+
if self.kind.can_reconstruct_query_key() {
698+
let def_path_hash = DefPathHash(self.hash);
699+
tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
700+
} else {
701+
None
702+
}
703+
}
704+
705+
/// Used in testing
706+
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
707+
let kind = dep_kind_from_label_string(label)?;
708+
709+
if !kind.can_reconstruct_query_key() {
710+
Err(())
711+
} else if kind.has_params() {
712+
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
713+
} else {
714+
Ok(DepNode::new_no_params(kind))
715+
}
716+
}
717+
718+
/// Used in testing
719+
fn has_label_string(label: &str) -> bool {
720+
dep_kind_from_label_string(label).is_ok()
721+
}
722+
}
723+
731724
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
732725
#[inline]
733726
fn can_reconstruct_query_key() -> bool {

0 commit comments

Comments
 (0)