1
Fork 0

Introduce CompileMonoItem DepNode

This commit is contained in:
bjorn3 2021-04-12 13:58:12 +02:00
parent 67e402f946
commit 15bfd9da85
4 changed files with 38 additions and 9 deletions

View file

@ -32,8 +32,8 @@
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro //! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are //! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
//! needed at runtime in order to construct a valid `DepNode` fingerprint. //! needed at runtime in order to construct a valid `DepNode` fingerprint.
//! However, only `CompileCodegenUnit` is constructed explicitly (with //! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
//! `make_compile_codegen_unit`). //! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
//! //!
//! Because the macro sees what parameters a given `DepKind` requires, it can //! Because the macro sees what parameters a given `DepKind` requires, it can
//! "infer" some properties for each kind of `DepNode`: //! "infer" some properties for each kind of `DepNode`:
@ -46,15 +46,17 @@
//! `DefId` it was computed from. In other cases, too much information gets //! `DefId` it was computed from. In other cases, too much information gets
//! lost during fingerprint computation. //! lost during fingerprint computation.
//! //!
//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only //! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
//! valid `DepNode` instances can be constructed. For example, the API does not //! `DepNode::new()`, ensures that only valid `DepNode` instances can be
//! allow for constructing parameterless `DepNode`s with anything other //! constructed. For example, the API does not allow for constructing
//! than a zeroed out fingerprint. More generally speaking, it relieves the //! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
//! user of the `DepNode` API of having to know how to compute the expected //! More generally speaking, it relieves the user of the `DepNode` API of
//! fingerprint for a given set of node parameters. //! having to know how to compute the expected fingerprint for a given set of
//! node parameters.
//! //!
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html //! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
use crate::mir::mono::MonoItem;
use crate::ty::TyCtxt; use crate::ty::TyCtxt;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
@ -175,6 +177,14 @@ pub mod dep_kind {
can_reconstruct_query_key: || false, can_reconstruct_query_key: || false,
}; };
pub const CompileMonoItem: DepKindStruct = DepKindStruct {
has_params: true,
is_anon: false,
is_eval_always: false,
can_reconstruct_query_key: || false,
};
macro_rules! define_query_dep_kinds { macro_rules! define_query_dep_kinds {
($( ($(
[$($attrs:tt)*] [$($attrs:tt)*]
@ -251,6 +261,10 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below. // WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
[] CompileCodegenUnit(Symbol), [] CompileCodegenUnit(Symbol),
// WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
// Only used by rustc_codegen_cranelift
[] CompileMonoItem(MonoItem),
]); ]);
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys. // WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
@ -259,6 +273,12 @@ crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name) DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
} }
// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
// Be very careful changing this type signature!
crate fn make_compile_mono_item(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
}
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>; pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
// We keep a lot of `DepNode`s in memory during compilation. It's not // We keep a lot of `DepNode`s in memory during compilation. It's not

View file

@ -12,8 +12,8 @@ pub use rustc_query_system::dep_graph::{
SerializedDepNodeIndex, WorkProduct, WorkProductId, SerializedDepNodeIndex, WorkProduct, WorkProductId,
}; };
crate use dep_node::make_compile_codegen_unit;
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt}; pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>; pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>; pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;

View file

@ -181,6 +181,10 @@ impl<'tcx> MonoItem<'tcx> {
} }
.map(|hir_id| tcx.hir().span(hir_id)) .map(|hir_id| tcx.hir().span(hir_id))
} }
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
crate::dep_graph::make_compile_mono_item(tcx, self)
}
} }
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> { impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {

View file

@ -438,6 +438,11 @@ macro_rules! define_queries {
try_load_from_on_disk_cache: |_, _| {}, try_load_from_on_disk_cache: |_, _| {},
}; };
pub const CompileMonoItem: QueryStruct = QueryStruct {
force_from_dep_node: |_, _| false,
try_load_from_on_disk_cache: |_, _| {},
};
$(pub const $name: QueryStruct = { $(pub const $name: QueryStruct = {
const is_anon: bool = is_anon!([$($modifiers)*]); const is_anon: bool = is_anon!([$($modifiers)*]);