Skip to content

Commit

Permalink
Auto merge of #68944 - Zoxc:hir-map, r=eddyb
Browse files Browse the repository at this point in the history
Use queries for the HIR map

r? @eddyb cc @michaelwoerister
  • Loading branch information
bors committed Mar 15, 2020
2 parents e0f5df0 + 14fdd85 commit 45ebd58
Show file tree
Hide file tree
Showing 108 changed files with 1,526 additions and 1,626 deletions.
6 changes: 6 additions & 0 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ macro_rules! arena_types {
[] type_binding: rustc_hir::TypeBinding<$tcx>,
[] variant: rustc_hir::Variant<$tcx>,
[] where_predicate: rustc_hir::WherePredicate<$tcx>,

// HIR query types
[few] indexed_hir: rustc::hir::map::IndexedHir<$tcx>,
[few] hir_definitions: rustc::hir::map::definitions::Definitions,
[] hir_owner: rustc::hir::HirOwner<$tcx>,
[] hir_owner_items: rustc::hir::HirOwnerItems<$tcx>,
], $tcx);
)
}
Expand Down
23 changes: 4 additions & 19 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! "infer" some properties for each kind of `DepNode`:
//!
//! * Whether a `DepNode` of a given kind has any parameters at all. Some
//! `DepNode`s, like `AllLocalTraitImpls`, represent global concepts with only one value.
//! `DepNode`s could represent global concepts with only one value.
//! * Whether it is possible, in principle, to reconstruct a query key from a
//! given `DepNode`. Many `DepKind`s only require a single `DefId` parameter,
//! in which case it is possible to map the node's fingerprint back to the
Expand Down Expand Up @@ -223,8 +223,8 @@ macro_rules! define_dep_nodes {
/// 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(kind: DepKind,
def_path_hash: DefPathHash)
pub fn from_def_path_hash(def_path_hash: DefPathHash,
kind: DepKind)
-> DepNode {
debug_assert!(kind.can_reconstruct_query_key() && kind.has_params());
DepNode {
Expand Down Expand Up @@ -280,7 +280,7 @@ macro_rules! define_dep_nodes {
}

if kind.has_params() {
Ok(def_path_hash.to_dep_node(kind))
Ok(DepNode::from_def_path_hash(def_path_hash, kind))
} else {
Ok(DepNode::new_no_params(kind))
}
Expand Down Expand Up @@ -337,28 +337,13 @@ impl fmt::Debug for DepNode {
}
}

impl DefPathHash {
pub fn to_dep_node(self, kind: DepKind) -> DepNode {
DepNode::from_def_path_hash(kind, self)
}
}

rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// We use this for most things when incr. comp. is turned off.
[] Null,

// Represents the body of a function or method. The def-id is that of the
// function/method.
[eval_always] HirBody(DefId),

// Represents the HIR node with the given node-id
[eval_always] Hir(DefId),

// Represents metadata from an extern crate.
[eval_always] CrateMetadata(CrateNum),

[eval_always] AllLocalTraitImpls,

[anon] TraitSelect,

[] CompileCodegenUnit(Symbol),
Expand Down
45 changes: 15 additions & 30 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,28 +225,6 @@ impl DepGraph {
)
}

/// Creates a new dep-graph input with value `input`
pub fn input_task<'a, C, R>(&self, key: DepNode, cx: C, input: R) -> (R, DepNodeIndex)
where
C: DepGraphSafe + StableHashingContextProvider<'a>,
R: for<'b> HashStable<StableHashingContext<'b>>,
{
fn identity_fn<C, A>(_: C, arg: A) -> A {
arg
}

self.with_task_impl(
key,
cx,
input,
true,
identity_fn,
|_| None,
|data, key, fingerprint, _| data.alloc_node(key, SmallVec::new(), fingerprint),
hash_result::<R>,
)
}

fn with_task_impl<'a, C, A, R>(
&self,
key: DepNode,
Expand Down Expand Up @@ -676,18 +654,25 @@ impl DepGraph {
continue;
}
} else {
// FIXME: This match is just a workaround for incremental bugs and should
// be removed. https://github.com/rust-lang/rust/issues/62649 is one such
// bug that must be fixed before removing this.
match dep_dep_node.kind {
DepKind::Hir | DepKind::HirBody | DepKind::CrateMetadata => {
DepKind::hir_owner
| DepKind::hir_owner_items
| DepKind::CrateMetadata => {
if let Some(def_id) = dep_dep_node.extract_def_id(tcx) {
if def_id_corresponds_to_hir_dep_node(tcx, def_id) {
// The `DefPath` has corresponding node,
// and that node should have been marked
// either red or green in `data.colors`.
bug!(
"DepNode {:?} should have been \
if dep_dep_node.kind == DepKind::CrateMetadata {
// The `DefPath` has corresponding node,
// and that node should have been marked
// either red or green in `data.colors`.
bug!(
"DepNode {:?} should have been \
pre-marked as red or green but wasn't.",
dep_dep_node
);
dep_dep_node
);
}
} else {
// This `DefPath` does not have a
// corresponding `DepNode` (e.g. a
Expand Down
Loading

0 comments on commit 45ebd58

Please sign in to comment.