Return to defining crate_hash similarly to other query providers

This commit is contained in:
Tyson Nottingham 2021-01-06 12:41:36 -08:00
parent 62139ffad4
commit 0962e5eba9

View file

@ -44,7 +44,10 @@ pub fn provide_extern(providers: &mut Providers) {
let ($def_id, $other) = def_id_arg.into_args(); let ($def_id, $other) = def_id_arg.into_args();
assert!(!$def_id.is_local()); assert!(!$def_id.is_local());
if $tcx.dep_graph.is_fully_enabled() { // External query providers call `crate_hash` in order to register a dependency
// on the crate metadata. The exception is `crate_hash` itself, which obviously
// doesn't need to do this (and can't, as it would cause a query cycle).
if stringify!($name) != "crate_hash" && $tcx.dep_graph.is_fully_enabled() {
$tcx.ensure().crate_hash($def_id.krate); $tcx.ensure().crate_hash($def_id.krate);
} }
@ -53,24 +56,8 @@ pub fn provide_extern(providers: &mut Providers) {
$compute $compute
})* })*
// The other external query providers call `crate_hash` in order to register a
// dependency on the crate metadata. The `crate_hash` implementation differs in
// that it doesn't need to do this (and can't, as it would cause a query cycle).
fn crate_hash<'tcx>(
tcx: TyCtxt<'tcx>,
def_id_arg: ty::query::query_keys::crate_hash<'tcx>,
) -> ty::query::query_values::crate_hash<'tcx> {
let _prof_timer = tcx.prof.generic_activity("metadata_decode_entry_crate_hash");
let (def_id, _) = def_id_arg.into_args();
assert!(!def_id.is_local());
CStore::from_tcx(tcx).get_crate_data(def_id.krate).root.hash
}
*providers = Providers { *providers = Providers {
$($name,)* $($name,)*
crate_hash,
..*providers ..*providers
}; };
} }
@ -206,6 +193,7 @@ fn into_args(self) -> (DefId, DefId) {
}) })
} }
crate_disambiguator => { cdata.root.disambiguator } crate_disambiguator => { cdata.root.disambiguator }
crate_hash => { cdata.root.hash }
crate_host_hash => { cdata.host_hash } crate_host_hash => { cdata.host_hash }
original_crate_name => { cdata.root.name } original_crate_name => { cdata.root.name }