Skip to content

Commit 469f873

Browse files
Comment out a currently failing test
DO NOT SUBMIT!
1 parent e89f50a commit 469f873

6 files changed

Lines changed: 41 additions & 44 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ use std::sync::Arc;
4141
use rustc_ast::node_id::NodeMap;
4242
use rustc_ast::visit::Visitor;
4343
use rustc_ast::{self as ast, *};
44-
use rustc_attr_parsing::{AttributeParser, EmitAttribute, Late, OmitDoc};
45-
//use rustc_data_structures::fingerprint::Fingerprint;
44+
use rustc_attr_parsing::{AttributeParser, EmitAttribute, Late, OmitDoc};
45+
use rustc_data_structures::fingerprint::Fingerprint;
4646
use rustc_data_structures::fx::FxIndexSet;
4747
use rustc_data_structures::sorted_map::SortedMap;
48-
//use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
48+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4949
use rustc_data_structures::steal::Steal;
5050
use rustc_data_structures::tagged_ptr::TaggedRef;
5151
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
@@ -57,7 +57,7 @@ use rustc_hir::{
5757
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
5858
LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr,
5959
};
60-
use rustc_index::{Idx, IndexVec};
60+
use rustc_index::{Idx, IndexSlice, IndexVec};
6161
use rustc_macros::extension;
6262
use rustc_middle::hir::{self as mid_hir};
6363
use rustc_middle::span_bug;
@@ -507,7 +507,7 @@ fn index_crate<'a, 'b>(
507507

508508
/// Compute the hash for the HIR of the full crate.
509509
/// This hash will then be part of the crate_hash which is stored in the metadata.
510-
/*fn compute_hir_hash(
510+
fn compute_hir_hash(
511511
tcx: TyCtxt<'_>,
512512
owners: &IndexSlice<LocalDefId, hir::MaybeOwner<'_>>,
513513
) -> Fingerprint {
@@ -526,7 +526,7 @@ fn index_crate<'a, 'b>(
526526
hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
527527
stable_hasher.finish()
528528
})
529-
}*/
529+
}
530530

531531
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
532532
// Queries that borrow `resolver_for_lowering`.
@@ -562,11 +562,14 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
562562
}
563563

564564
// Don't hash unless necessary, because it's expensive.
565-
// let opt_hir_hash =
566-
// if tcx.needs_crate_hash() { Some(tcx.crate_hash(LOCAL_CRATE)) } else { None };
565+
let opt_hir_hash = if tcx.needs_crate_hash() && !tcx.needs_metadata() {
566+
Some(compute_hir_hash(tcx, &owners))
567+
} else {
568+
None
569+
};
567570

568571
let delayed_resolver = Steal::new((resolver, krate));
569-
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, None)
572+
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)
570573
}
571574

572575
/// Lowers an AST owner corresponding to `def_id`, now only delegations are lowered this way.

compiler/rustc_data_structures/src/svh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::fingerprint::Fingerprint;
2323
HashStable_NoContext
2424
)]
2525
pub struct Svh {
26-
pub hash: Fingerprint,
26+
hash: Fingerprint,
2727
}
2828

2929
impl Svh {

compiler/rustc_metadata/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
5454
None
5555
};
5656

57-
if tcx.needs_metadata() || tcx.needs_crate_hash() {
57+
if tcx.needs_metadata() {
5858
encode_metadata(tcx, &metadata_filename, metadata_stub_filename.as_deref());
5959
} else {
6060
// Always create a file at `metadata_filename`, even if we have nothing to write to it.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ use std::any::Any;
22
use std::mem;
33
use std::sync::Arc;
44

5+
use rustc_data_structures::fingerprint::Fingerprint;
6+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
7+
use rustc_data_structures::svh::Svh;
58
use rustc_hir::attrs::Deprecation;
69
use rustc_hir::def::{CtorKind, DefKind};
710
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
811
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
912
use rustc_middle::arena::ArenaAllocatable;
1013
use rustc_middle::bug;
1114
use rustc_middle::metadata::{AmbigModChild, ModChild};
15+
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
1216
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1317
use rustc_middle::middle::stability::DeprecationEntry;
1418
use rustc_middle::queries::ExternProviders;
@@ -20,7 +24,7 @@ use rustc_serialize::Decoder;
2024
use rustc_session::StableCrateId;
2125
use rustc_session::cstore::{CrateStore, ExternCrate};
2226
use rustc_span::hygiene::ExpnId;
23-
use rustc_span::{Span, Symbol, kw};
27+
use rustc_span::{Span, Symbol, kw, with_metavar_spans};
2428

2529
use super::{Decodable, DecodeIterator};
2630
use crate::creader::{CStore, LoadedMacro};
@@ -752,17 +756,20 @@ fn provide_cstore_hooks(providers: &mut Providers) {
752756
};
753757

754758
providers.queries.crate_hash = |tcx: TyCtxt<'_>, _: LocalCrate| {
755-
*tcx.untracked()
756-
.local_crate_hash
757-
.get()
758-
.expect("crate_hash(LOCAL_CRATE) called before metadata encoding")
759+
if tcx.needs_metadata() {
760+
*tcx.untracked()
761+
.local_crate_hash
762+
.get()
763+
.expect("crate_hash(LOCAL_CRATE) called before metadata encoding")
764+
} else {
765+
crate_hash(tcx)
766+
}
759767
};
760768
}
761769

762-
/*pub(super) fn crate_hash(tcx: TyCtxt<'_>, cnum: rustc_hir::def_id::CrateNum) -> Svh {
763-
let cstore = CStore::from_tcx(tcx);
764-
let crate_data = cstore.get_crate_data(cnum);
765-
crate_data.root.header.hash
770+
pub(super) fn crate_hash(tcx: TyCtxt<'_>) -> Svh {
771+
let krate = tcx.hir_crate(());
772+
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
766773

767774
let upstream_crates = upstream_crates(tcx);
768775

@@ -800,7 +807,7 @@ fn provide_cstore_hooks(providers: &mut Providers) {
800807

801808
let crate_hash: Fingerprint = tcx.with_stable_hashing_context(|mut hcx| {
802809
let mut stable_hasher = StableHasher::new();
803-
metadata_hash.hash_stable(&mut hcx, &mut stable_hasher);
810+
hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher);
804811
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
805812
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
806813
debugger_visualizers.hash_stable(&mut hcx, &mut stable_hasher);
@@ -847,4 +854,4 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
847854
.collect();
848855
upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id);
849856
upstream_crates
850-
}*/
857+
}

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ pub mod place;
88

99
use std::sync::Arc;
1010

11-
//use rustc_hir::def_id::LOCAL_CRATE;
1211
use rustc_ast::{self as ast};
1312
use rustc_data_structures::fingerprint::Fingerprint;
1413
use rustc_data_structures::fx::FxIndexSet;
1514
use rustc_data_structures::sorted_map::SortedMap;
1615
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1716
use rustc_data_structures::steal::Steal;
18-
use rustc_data_structures::svh::Svh;
1917
use rustc_data_structures::sync::{DynSend, DynSync, try_par_for_each_in};
2018
use rustc_hir::def::{DefKind, Res};
2119
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
2220
use rustc_hir::*;
2321
use rustc_index::IndexVec;
2422
use rustc_macros::{Decodable, Encodable, HashStable};
25-
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
23+
use rustc_span::{ErrorGuaranteed, ExpnId, HashStableContext, Span};
2624

2725
use crate::query::Providers;
2826
use crate::ty::{ResolverAstLowering, TyCtxt};
@@ -33,8 +31,8 @@ use crate::ty::{ResolverAstLowering, TyCtxt};
3331
/// For more details, see the [rustc dev guide].
3432
///
3533
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
34+
#[derive(Debug)]
3635
pub struct Crate<'hir> {
37-
// tcx: TyCtxt<'hir>,
3836
// This field is private by intention, access it through `owner` method.
3937
owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
4038
// Ids of delayed AST owners which are lowered through `lower_delayed_owner` query.
@@ -43,27 +41,17 @@ pub struct Crate<'hir> {
4341
// and then stolen and dropped in `force_delayed_owners_lowering`.
4442
pub delayed_resolver: Steal<(ResolverAstLowering<'hir>, Arc<ast::Crate>)>,
4543
// Only present when incr. comp. is enabled.
46-
pub opt_hash: Option<Svh>,
47-
}
48-
49-
impl std::fmt::Debug for Crate<'_> {
50-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51-
f.debug_struct("Crate")
52-
.field("owners", &self.owners)
53-
.field("delayed_ids", &self.delayed_ids)
54-
.field("delayed_resolver", &self.delayed_resolver)
55-
.finish()
56-
}
44+
pub opt_hir_hash: Option<Fingerprint>,
5745
}
5846

5947
impl<'hir> Crate<'hir> {
6048
pub fn new(
6149
owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
6250
delayed_ids: FxIndexSet<LocalDefId>,
6351
delayed_resolver: Steal<(ResolverAstLowering<'hir>, Arc<ast::Crate>)>,
64-
opt_hash: Option<Svh>,
52+
opt_hir_hash: Option<Fingerprint>,
6553
) -> Crate<'hir> {
66-
Crate { owners, delayed_ids, delayed_resolver, opt_hash }
54+
Crate { owners, delayed_ids, delayed_resolver, opt_hir_hash }
6755
}
6856

6957
/// Serves as an entry point for getting `MaybeOwner`. As owner can either be in
@@ -88,11 +76,12 @@ impl<'hir> Crate<'hir> {
8876
}
8977
}
9078

91-
/*impl<Hcx: HashStableContext> HashStable<Hcx> for Crate<'_> {
79+
impl<Hcx: HashStableContext> HashStable<Hcx> for Crate<'_> {
9280
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
93-
self.tcx.crate_hash(LOCAL_CRATE).hash_stable(hcx, hasher)
81+
let Crate { opt_hir_hash, .. } = self;
82+
opt_hir_hash.unwrap().hash_stable(hcx, hasher)
9483
}
95-
}*/
84+
}
9685

9786
/// Gather the LocalDefId for each item-like within a module, including items contained within
9887
/// bodies. The Ids are in visitor order. This is used to partition a pass between modules.

compiler/rustc_query_impl/src/query_impl.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//use rustc_data_structures::fingerprint::Fingerprint;
21
use rustc_middle::queries::TaggedQueryKey;
32
use rustc_middle::query::erase::{self, Erased};
43
use rustc_middle::query::{AsLocalQueryKey, QueryMode, QueryVTable};
@@ -190,7 +189,6 @@ macro_rules! define_queries {
190189
hash_value_fn: Some(|hcx, erased_value: &erase::Erased<Value<'tcx>>| {
191190
let value = erase::restore_val(*erased_value);
192191
rustc_middle::dep_graph::hash_result(hcx, &value)
193-
//Fingerprint::new(0, 0)
194192
}),
195193

196194
format_value: |erased_value: &erase::Erased<Value<'tcx>>| {

0 commit comments

Comments
 (0)