Skip to content

Commit

Permalink
Rollup merge of rust-lang#59091 - Zoxc:eval_always, r=michaelwoerister
Browse files Browse the repository at this point in the history
Combine input and eval_always query types

Hardcoding `Krate` as a dependency of `eval_always` queries doesn't really make sense if we want to use the query system before HIR lowering / hashing. Without that hardcoding they become pretty much identical to `input` queries, so I combined them to a single type. This will regress the `clean` incremental scenario, but that isn't terribly common.

r? @michaelwoerister
  • Loading branch information
Centril authored Mar 28, 2019
2 parents f90ac4f + 629e3a3 commit edad34b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 85 deletions.
78 changes: 30 additions & 48 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ macro_rules! is_anon_attr {
($attr:ident) => (false);
}

macro_rules! is_input_attr {
(input) => (true);
($attr:ident) => (false);
}

macro_rules! is_eval_always_attr {
(eval_always) => (true);
($attr:ident) => (false);
Expand All @@ -99,10 +94,6 @@ macro_rules! contains_anon_attr {
($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
}

macro_rules! contains_input_attr {
($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
}

macro_rules! contains_eval_always_attr {
($($attr:ident),*) => ({$(is_eval_always_attr!($attr) | )* false});
}
Expand Down Expand Up @@ -151,7 +142,7 @@ macro_rules! define_dep_nodes {
}
}

// FIXME: Make `is_anon`, `is_input`, `is_eval_always` and `has_params` properties
// FIXME: Make `is_anon`, `is_eval_always` and `has_params` properties
// of queries
#[inline(always)]
pub fn is_anon(&self) -> bool {
Expand All @@ -162,15 +153,6 @@ macro_rules! define_dep_nodes {
}
}

#[inline(always)]
pub fn is_input(&self) -> bool {
match *self {
$(
DepKind :: $variant => { contains_input_attr!($($attr),*) }
)*
}
}

#[inline(always)]
pub fn is_eval_always(&self) -> bool {
match *self {
Expand Down Expand Up @@ -438,17 +420,17 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
// access to the krate, but you must remember to add suitable
// edges yourself for the individual items that you read.
[input] Krate,
[eval_always] Krate,

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

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

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

// Represents different phases in the compiler.
[] RegionScopeTree(DefId),
Expand Down Expand Up @@ -481,7 +463,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] CollectModItemTypes(DefId),

[] Reachability,
[eval_always] CrateVariances,
[] CrateVariances,

// Nodes representing bits of computed IR in the tcx. Each shared
// table in the tcx (or elsewhere) maps to one of these
Expand Down Expand Up @@ -534,7 +516,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// The set of impls for a given trait.
[] TraitImpls(DefId),

[input] AllLocalTraitImpls,
[eval_always] AllLocalTraitImpls,

[anon] TraitSelect,

Expand All @@ -546,7 +528,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
// to make type debuginfo to be source location independent. Declaring
// DefSpan an input makes sure that changes to these are always detected
// regardless of HIR hashing.
[input] DefSpan(DefId),
[eval_always] DefSpan(DefId),
[] LookupStability(DefId),
[] LookupDeprecationEntry(DefId),
[] ConstIsRvaluePromotableToStatic(DefId),
Expand All @@ -564,10 +546,10 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] IsCompilerBuiltins(CrateNum),
[] HasGlobalAllocator(CrateNum),
[] HasPanicHandler(CrateNum),
[input] ExternCrate(DefId),
[eval_always] ExternCrate(DefId),
[] Specializes { impl1: DefId, impl2: DefId },
[input] InScopeTraits(DefIndex),
[input] ModuleExports(DefId),
[eval_always] InScopeTraits(DefIndex),
[eval_always] ModuleExports(DefId),
[] IsSanitizerRuntime(CrateNum),
[] IsProfilerRuntime(CrateNum),
[] GetPanicStrategy(CrateNum),
Expand All @@ -580,10 +562,10 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] EntryFn(CrateNum),
[] PluginRegistrarFn(CrateNum),
[] ProcMacroDeclsStatic(CrateNum),
[input] CrateDisambiguator(CrateNum),
[input] CrateHash(CrateNum),
[input] OriginalCrateName(CrateNum),
[input] ExtraFileName(CrateNum),
[eval_always] CrateDisambiguator(CrateNum),
[eval_always] CrateHash(CrateNum),
[eval_always] OriginalCrateName(CrateNum),
[eval_always] ExtraFileName(CrateNum),

[] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
[] AllTraitImplementations(CrateNum),
Expand All @@ -592,16 +574,16 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] IsDllimportForeignItem(DefId),
[] IsStaticallyIncludedForeignItem(DefId),
[] NativeLibraryKind(DefId),
[input] LinkArgs,
[eval_always] LinkArgs,

[] ResolveLifetimes(CrateNum),
[] NamedRegion(DefIndex),
[] IsLateBound(DefIndex),
[] ObjectLifetimeDefaults(DefIndex),

[] Visibility(DefId),
[input] DepKind(CrateNum),
[input] CrateName(CrateNum),
[eval_always] DepKind(CrateNum),
[eval_always] CrateName(CrateNum),
[] ItemChildren(DefId),
[] ExternModStmtCnum(DefId),
[eval_always] GetLibFeatures,
Expand All @@ -610,24 +592,24 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] DefinedLangItems(CrateNum),
[] MissingLangItems(CrateNum),
[] VisibleParentMap,
[input] MissingExternCrateItem(CrateNum),
[input] UsedCrateSource(CrateNum),
[input] PostorderCnums,

[input] Freevars(DefId),
[input] MaybeUnusedTraitImport(DefId),
[input] MaybeUnusedExternCrates,
[input] NamesImportedByGlobUse(DefId),
[eval_always] MissingExternCrateItem(CrateNum),
[eval_always] UsedCrateSource(CrateNum),
[eval_always] PostorderCnums,

[eval_always] Freevars(DefId),
[eval_always] MaybeUnusedTraitImport(DefId),
[eval_always] MaybeUnusedExternCrates,
[eval_always] NamesImportedByGlobUse(DefId),
[eval_always] StabilityIndex,
[eval_always] AllTraits,
[input] AllCrateNums,
[eval_always] AllCrateNums,
[] ExportedSymbols(CrateNum),
[eval_always] CollectAndPartitionMonoItems,
[] IsCodegenedItem(DefId),
[] CodegenUnit(InternedString),
[] BackendOptimizationLevel(CrateNum),
[] CompileCodegenUnit(InternedString),
[input] OutputFilenames,
[eval_always] OutputFilenames,
[] NormalizeProjectionTy(CanonicalProjectionGoal<'tcx>),
[] NormalizeTyAfterErasingRegions(ParamEnvAnd<'tcx, Ty<'tcx>>),
[] ImpliedOutlivesBounds(CanonicalTyGoal<'tcx>),
Expand All @@ -646,11 +628,11 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] SubstituteNormalizeAndTestPredicates { key: (DefId, SubstsRef<'tcx>) },
[] MethodAutoderefSteps(CanonicalTyGoal<'tcx>),

[input] TargetFeaturesWhitelist,
[eval_always] TargetFeaturesWhitelist,

[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },

[input] Features,
[eval_always] Features,

[] ForeignModules(CrateNum),

Expand Down
41 changes: 8 additions & 33 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,7 @@ impl DepGraph {
|_| None,
|data, key, fingerprint, _| {
let mut current = data.borrow_mut();
let krate_idx = current.node_to_node_index[
&DepNode::new_no_params(DepKind::Krate)
];
current.alloc_node(key, smallvec![krate_idx], fingerprint)
current.alloc_node(key, smallvec![], fingerprint)
},
hash_result)
}
Expand Down Expand Up @@ -576,7 +573,7 @@ impl DepGraph {
tcx: TyCtxt<'_, '_, '_>,
dep_node: &DepNode
) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> {
debug_assert!(!dep_node.kind.is_input());
debug_assert!(!dep_node.kind.is_eval_always());

// Return None if the dep graph is disabled
let data = self.data.as_ref()?;
Expand Down Expand Up @@ -620,8 +617,8 @@ impl DepGraph {
debug_assert!(data.colors.get(prev_dep_node_index).is_none());
}

// We never try to mark inputs as green
debug_assert!(!dep_node.kind.is_input());
// We never try to mark eval_always nodes as green
debug_assert!(!dep_node.kind.is_eval_always());

debug_assert_eq!(data.previous.index_to_node(prev_dep_node_index), *dep_node);

Expand Down Expand Up @@ -658,8 +655,8 @@ impl DepGraph {
let dep_dep_node = &data.previous.index_to_node(dep_dep_node_index);

// We don't know the state of this dependency. If it isn't
// an input node, let's try to mark it green recursively.
if !dep_dep_node.kind.is_input() {
// an eval_always node, let's try to mark it green recursively.
if !dep_dep_node.kind.is_eval_always() {
debug!("try_mark_previous_green({:?}) --- state of dependency {:?} \
is unknown, trying to mark it green", dep_node,
dep_dep_node);
Expand Down Expand Up @@ -694,7 +691,7 @@ impl DepGraph {
}
}
_ => {
// For other kinds of inputs it's OK to be
// For other kinds of nodes it's OK to be
// forced.
}
}
Expand Down Expand Up @@ -1017,33 +1014,11 @@ impl CurrentDepGraph {
task_deps: TaskDeps,
fingerprint: Fingerprint
) -> DepNodeIndex {
// If this is an input node, we expect that it either has no
// dependencies, or that it just depends on DepKind::CrateMetadata
// or DepKind::Krate. This happens for some "thin wrapper queries"
// like `crate_disambiguator` which sometimes have zero deps (for
// when called for LOCAL_CRATE) or they depend on a CrateMetadata
// node.
if cfg!(debug_assertions) {
if node.kind.is_input() && task_deps.reads.len() > 0 &&
// FIXME(mw): Special case for DefSpan until Spans are handled
// better in general.
node.kind != DepKind::DefSpan &&
task_deps.reads.iter().any(|&i| {
!(self.data[i].node.kind == DepKind::CrateMetadata ||
self.data[i].node.kind == DepKind::Krate)
})
{
bug!("Input node {:?} with unexpected reads: {:?}",
node,
task_deps.reads.iter().map(|&i| self.data[i].node).collect::<Vec<_>>())
}
}

self.alloc_node(node, task_deps.reads, fingerprint)
}

fn complete_anon_task(&mut self, kind: DepKind, task_deps: TaskDeps) -> DepNodeIndex {
debug_assert!(!kind.is_input());
debug_assert!(!kind.is_eval_always());

let mut fingerprint = self.anon_id_seed;
let mut hasher = StableHasher::new();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Forest {
&self.krate
}

/// This is internally in the depedency tracking system.
/// This is used internally in the dependency tracking system.
/// Use the `krate` method to ensure your dependency on the
/// crate is tracked.
pub fn untracked_krate<'hir>(&'hir self) -> &'hir Crate {
Expand Down
10 changes: 7 additions & 3 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
return result;
}

if !dep_node.kind.is_input() {
if !dep_node.kind.is_eval_always() {
// The diagnostics for this query will be
// promoted to the current session during
// try_mark_green(), so we can ignore them here.
Expand Down Expand Up @@ -601,9 +601,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub(super) fn ensure_query<Q: QueryDescription<'gcx>>(self, key: Q::Key) -> () {
let dep_node = Q::to_dep_node(self, &key);

// Ensuring an "input" or anonymous query makes no sense
if dep_node.kind.is_eval_always() {
let _ = self.get_query::<Q>(DUMMY_SP, key);
return;
}

// Ensuring an anonymous query makes no sense
assert!(!dep_node.kind.is_anon());
assert!(!dep_node.kind.is_input());
if self.dep_graph.try_mark_green_and_read(self, &dep_node).is_none() {
// A None return from `try_mark_green_and_read` means that this is either
// a new dep node or that the dep node has already been marked red.
Expand Down

0 comments on commit edad34b

Please sign in to comment.