Skip to content

Add no_hash to query macro and move some queries over #59315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,7 @@ dependencies = [
name = "rustc_macros"
version = "0.1.0"
dependencies = [
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
19 changes: 0 additions & 19 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>

// Represents the MIR for a fn; also used as the task node for
// things read/modify that MIR.
[] MirConstQualif(DefId),
[] MirBuilt(DefId),
[] MirConst(DefId),
[] MirValidated(DefId),
[] MirOptimized(DefId),
[] MirShim { instance_def: InstanceDef<'tcx> },

[] BorrowCheckKrate,
Expand All @@ -485,7 +480,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] CollectModItemTypes(DefId),

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

// Nodes representing bits of computed IR in the tcx. Each shared
Expand Down Expand Up @@ -544,7 +538,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[anon] TraitSelect,

[] ParamEnv(DefId),
[] Environment(DefId),
[] DescribeDef(DefId),

// FIXME(mw): DefSpans are not really inputs since they are derived from
Expand All @@ -571,7 +564,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[] HasGlobalAllocator(CrateNum),
[] HasPanicHandler(CrateNum),
[input] ExternCrate(DefId),
[eval_always] LintLevels,
[] Specializes { impl1: DefId, impl2: DefId },
[input] InScopeTraits(DefIndex),
[input] ModuleExports(DefId),
Expand Down Expand Up @@ -621,14 +613,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
[input] UsedCrateSource(CrateNum),
[input] PostorderCnums,

// These queries are not expected to have inputs -- as a result, they
// are not good candidates for "replay" because they are essentially
// pure functions of their input (and hence the expectation is that
// no caller would be green **apart** from just these
// queries). Making them anonymous avoids hashing the result, which
// may save a bit of time.
[anon] EraseRegionsTy { ty: Ty<'tcx> },

[input] Freevars(DefId),
[input] MaybeUnusedTraitImport(DefId),
[input] MaybeUnusedExternCrates,
Expand Down Expand Up @@ -667,9 +651,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>

[input] Features,

[] ProgramClausesFor(DefId),
[] ProgramClausesForEnv(traits::Environment<'tcx>),
[] WasmImportModuleMap(CrateNum),
[] ForeignModules(CrateNum),

[] UpstreamMonomorphizations(CrateNum),
Expand Down
91 changes: 88 additions & 3 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::ty::query::QueryDescription;
use crate::ty::query::queries;
use crate::ty::TyCtxt;
use crate::ty;
use crate::hir::def_id::CrateNum;
use crate::ty::{self, Ty, TyCtxt};
use crate::hir::def_id::{DefId, CrateNum};
use crate::dep_graph::SerializedDepNodeIndex;
use crate::traits;
use std::borrow::Cow;

// Each of these queries corresponds to a function pointer field in the
Expand Down Expand Up @@ -55,6 +55,11 @@ rustc_queries! {
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLibrary>> {
desc { "looking up the native libraries of a linked crate" }
}

query lint_levels(_: CrateNum) -> Lrc<lint::LintLevelMap> {
eval_always
desc { "computing the lint levels for items in this crate" }
}
}

Codegen {
Expand All @@ -63,4 +68,84 @@ rustc_queries! {
desc { "checking if the crate is_panic_runtime" }
}
}

Codegen {
/// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct
/// constructors.
query mir_keys(_: CrateNum) -> Lrc<DefIdSet> {
desc { "getting a list of all mir_keys" }
}

/// Maps DefId's that have an associated Mir to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
query mir_const_qualif(key: DefId) -> (u8, Lrc<BitSet<mir::Local>>) {
cache { key.is_local() }
}

/// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code.
query mir_built(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {}

/// Fetch the MIR for a given `DefId` up till the point where it is
/// ready for const evaluation.
///
/// See the README for the `mir` module for details.
query mir_const(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
no_hash
}

query mir_validated(_: DefId) -> &'tcx Steal<mir::Mir<'tcx>> {
no_hash
}

/// MIR after our optimization passes have run. This is MIR that is ready
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> {
cache { key.is_local() }
load_cached(tcx, id) {
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
.try_load_query_result(tcx, id);
mir.map(|x| tcx.alloc_mir(x))
}
}
}

TypeChecking {
// Erases regions from `ty` to yield a new type.
// Normally you would just use `tcx.erase_regions(&value)`,
// however, which uses this query as a kind of cache.
query erase_regions_ty(ty: Ty<'tcx>) -> Ty<'tcx> {
// This query is not expected to have input -- as a result, it
// is not a good candidates for "replay" because it is essentially a
// pure function of its input (and hence the expectation is that
// no caller would be green **apart** from just these
// queries). Making it anonymous avoids hashing the result, which
// may save a bit of time.
anon
no_force
desc { "erasing regions from `{:?}`", ty }
}

query program_clauses_for(_: DefId) -> Clauses<'tcx> {
desc { "generating chalk-style clauses" }
}

query program_clauses_for_env(_: traits::Environment<'tcx>) -> Clauses<'tcx> {
no_force
desc { "generating chalk-style clauses for environment" }
}

// Get the chalk-style environment of the given item.
query environment(_: DefId) -> traits::Environment<'tcx> {
desc { "return a chalk-style environment" }
}
}

Linking {
query wasm_import_module_map(_: CrateNum) -> Lrc<FxHashMap<DefId, String>> {
desc { "wasm import module map" }
}
}
}
60 changes: 1 addition & 59 deletions src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, ty: Ty<'tcx>) -> Cow<'static, str> {
format!("erasing regions from `{:?}`", ty).into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
fn describe(tcx: TyCtxt<'_, '_, '_>, (_, def_id): (DefId, DefId)) -> Cow<'static, str> {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
Expand Down Expand Up @@ -431,12 +425,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_eval_raw<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::mir_keys<'tcx> {
fn describe(_: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"getting a list of all mir_keys".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, instance: ty::Instance<'tcx>) -> Cow<'static, str> {
format!("computing the symbol for `{}`", instance).into()
Expand Down Expand Up @@ -617,12 +605,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::analysis<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"computing the lint levels for items in this crate".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: (DefId, DefId)) -> Cow<'static, str> {
"computing whether impls specialize one another".into()
Expand Down Expand Up @@ -898,21 +880,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
#[inline]
fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool {
def_id.is_local()
}

fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: SerializedDepNodeIndex)
-> Option<Self::Value> {
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
.try_load_query_result(tcx, id);
mir.map(|x| tcx.alloc_mir(x))
}
}

impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
fn describe(tcx: TyCtxt<'_, '_, '_>, key: (DefId, SubstsRef<'tcx>)) -> Cow<'static, str> {
format!("testing substituted normalized predicates:`{}`", tcx.def_path_str(key.0)).into()
Expand All @@ -937,33 +904,9 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx>
}
}

impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
"generating chalk-style clauses".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: traits::Environment<'tcx>) -> Cow<'static, str> {
"generating chalk-style clauses for environment".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::environment<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
"return a chalk-style environment".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::wasm_import_module_map<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"wasm import module map".into()
}
}

impl<'tcx> QueryDescription<'tcx> for queries::dllimport_foreign_items<'tcx> {
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
"wasm import module map".into()
"dllimport_foreign_items".into()
}
}

Expand Down Expand Up @@ -997,7 +940,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {

impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(mir_const_qualif, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
Expand Down
62 changes: 0 additions & 62 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,34 +205,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
[] fn inherent_impls: InherentImpls(DefId) -> Lrc<Vec<DefId>>,
},

Codegen {
/// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct
/// constructors.
[] fn mir_keys: mir_keys(CrateNum) -> Lrc<DefIdSet>,

/// Maps DefId's that have an associated Mir to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),

/// Fetch the MIR for a given `DefId` right after it's built - this includes
/// unreachable code.
[] fn mir_built: MirBuilt(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,

/// Fetch the MIR for a given `DefId` up till the point where it is
/// ready for const evaluation.
///
/// See the README for the `mir` module for details.
[no_hash] fn mir_const: MirConst(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,

[no_hash] fn mir_validated: MirValidated(DefId) -> &'tcx Steal<mir::Mir<'tcx>>,

/// MIR after our optimization passes have run. This is MIR that is ready
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
[] fn optimized_mir: MirOptimized(DefId) -> &'tcx mir::Mir<'tcx>,
},

TypeChecking {
/// The result of unsafety-checking this `DefId`.
[] fn unsafety_check_result: UnsafetyCheckResult(DefId) -> mir::UnsafetyCheckResult,
Expand Down Expand Up @@ -443,7 +415,6 @@ rustc_query_append! { [define_queries!][ <'tcx>

Other {
[] fn module_exports: ModuleExports(DefId) -> Option<Lrc<Vec<Export>>>,
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
},

TypeChecking {
Expand Down Expand Up @@ -583,11 +554,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
},

TypeChecking {
// Erases regions from `ty` to yield a new type.
// Normally you would just use `tcx.erase_regions(&value)`,
// however, which uses this query as a kind of cache.
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,

/// Do not call this query directly: invoke `normalize` instead.
[] fn normalize_projection_ty: NormalizeProjectionTy(
CanonicalProjectionGoal<'tcx>
Expand Down Expand Up @@ -711,22 +677,6 @@ rustc_query_append! { [define_queries!][ <'tcx>

[] fn features_query: features_node(CrateNum) -> Lrc<feature_gate::Features>,
},

TypeChecking {
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,

[] fn program_clauses_for_env: ProgramClausesForEnv(
traits::Environment<'tcx>
) -> Clauses<'tcx>,

// Get the chalk-style environment of the given item.
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
},

Linking {
[] fn wasm_import_module_map: WasmImportModuleMap(CrateNum)
-> Lrc<FxHashMap<DefId, String>>,
},
]}

//////////////////////////////////////////////////////////////////////
Expand All @@ -742,10 +692,6 @@ fn codegen_fn_attrs<'tcx>(id: DefId) -> DepConstructor<'tcx> {
DepConstructor::CodegenFnAttrs { 0: id }
}

fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
DepConstructor::EraseRegionsTy { ty }
}

fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
DepConstructor::TypeParamPredicates {
item_id,
Expand Down Expand Up @@ -796,10 +742,6 @@ fn const_eval_raw_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>
DepConstructor::ConstEvalRaw { param_env }
}

fn mir_keys<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
DepConstructor::MirKeys
}

fn crate_variances<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
DepConstructor::CrateVariances
}
Expand All @@ -824,10 +766,6 @@ fn layout_dep_node<'tcx>(param_env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> DepConst
DepConstructor::Layout { param_env }
}

fn lint_levels_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
DepConstructor::LintLevels
}

fn specializes_node<'tcx>((a, b): (DefId, DefId)) -> DepConstructor<'tcx> {
DepConstructor::Specializes { impl1: a, impl2: b }
}
Expand Down
Loading