Skip to content

Commit 1160cf8

Browse files
committed
Auto merge of rust-lang#85884 - rust-lang:revert-85153-qresolve, r=michaelwoerister
Revert "Reduce the amount of untracked state in TyCtxt" Reverts rust-lang#85153 Fixes rust-lang#85878 The performance hit is massive, and was not visible in the in-review perf run. r? `@Aaron1011`
2 parents 80af6b0 + 0f0f313 commit 1160cf8

File tree

49 files changed

+255
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+255
-234
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3677,7 +3677,6 @@ dependencies = [
36773677
"rustc_incremental",
36783678
"rustc_index",
36793679
"rustc_llvm",
3680-
"rustc_metadata",
36813680
"rustc_middle",
36823681
"rustc_serialize",
36833682
"rustc_session",

compiler/rustc_ast/src/expand/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_span::symbol::{sym, Symbol};
22

3-
#[derive(Clone, Debug, Copy, HashStable_Generic)]
3+
#[derive(Clone, Copy)]
44
pub enum AllocatorKind {
55
Global,
66
Default,

compiler/rustc_ast_lowering/src/lib.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_ast::walk_list;
4343
use rustc_ast::{self as ast, *};
4444
use rustc_ast_pretty::pprust;
4545
use rustc_data_structures::captures::Captures;
46-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
46+
use rustc_data_structures::fx::FxHashSet;
4747
use rustc_data_structures::sync::Lrc;
4848
use rustc_errors::{struct_span_err, Applicability};
4949
use rustc_hir as hir;
@@ -198,7 +198,7 @@ pub trait ResolverAstLowering {
198198

199199
fn next_node_id(&mut self) -> NodeId;
200200

201-
fn take_trait_map(&mut self) -> NodeMap<Vec<hir::TraitCandidate>>;
201+
fn trait_map(&self) -> &NodeMap<Vec<hir::TraitCandidate>>;
202202

203203
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId>;
204204

@@ -501,13 +501,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
501501
let proc_macros =
502502
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
503503

504-
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
505-
for (k, v) in self.resolver.take_trait_map().into_iter() {
506-
if let Some(Some(hir_id)) = self.node_id_to_hir_id.get(k) {
507-
let map = trait_map.entry(hir_id.owner).or_default();
508-
map.insert(hir_id.local_id, v.into_boxed_slice());
509-
}
510-
}
504+
let trait_map = self
505+
.resolver
506+
.trait_map()
507+
.iter()
508+
.filter_map(|(&k, v)| {
509+
self.node_id_to_hir_id.get(k).and_then(|id| id.as_ref()).map(|id| (*id, v.clone()))
510+
})
511+
.collect();
511512

512513
let mut def_id_to_hir_id = IndexVec::default();
513514

compiler/rustc_codegen_cranelift/src/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn codegen(
1919
});
2020
if any_dynamic_crate {
2121
false
22-
} else if let Some(kind) = tcx.allocator_kind(()) {
22+
} else if let Some(kind) = tcx.allocator_kind() {
2323
codegen_inner(module, unwind_context, kind);
2424
true
2525
} else {

compiler/rustc_codegen_cranelift/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ extern crate rustc_fs_util;
1414
extern crate rustc_hir;
1515
extern crate rustc_incremental;
1616
extern crate rustc_index;
17-
extern crate rustc_metadata;
1817
extern crate rustc_session;
1918
extern crate rustc_span;
2019
extern crate rustc_target;

compiler/rustc_codegen_cranelift/src/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O)
1010
use std::io::Write;
1111

1212
let metadata = tcx.encode_metadata();
13-
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
13+
let mut compressed = tcx.metadata_encoding_version();
1414
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
1515

1616
object.add_rustc_section(

compiler/rustc_codegen_llvm/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_hir = { path = "../rustc_hir" }
2727
rustc_incremental = { path = "../rustc_incremental" }
2828
rustc_index = { path = "../rustc_index" }
2929
rustc_llvm = { path = "../rustc_llvm" }
30-
rustc_metadata = { path = "../rustc_metadata" }
3130
rustc_session = { path = "../rustc_session" }
3231
rustc_serialize = { path = "../rustc_serialize" }
3332
rustc_target = { path = "../rustc_target" }

compiler/rustc_codegen_llvm/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn write_compressed_metadata<'tcx>(
6363
let section_name = if tcx.sess.target.is_like_osx { "__DATA,.rustc" } else { ".rustc" };
6464

6565
let (metadata_llcx, metadata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
66-
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
66+
let mut compressed = tcx.metadata_encoding_version();
6767
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
6868

6969
let llmeta = common::bytes_in_context(metadata_llcx, &compressed);

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn exported_symbols_provider_local(
180180
symbols.push((exported_symbol, SymbolExportLevel::C));
181181
}
182182

183-
if tcx.allocator_kind(()).is_some() {
183+
if tcx.allocator_kind().is_some() {
184184
for method in ALLOCATOR_METHODS {
185185
let symbol_name = format!("__rust_{}", method.name);
186186
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
517517
});
518518
let allocator_module = if any_dynamic_crate {
519519
None
520-
} else if let Some(kind) = tcx.allocator_kind(()) {
520+
} else if let Some(kind) = tcx.allocator_kind() {
521521
let llmod_id =
522522
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
523523
let mut modules = backend.new_metadata(tcx, &llmod_id);

compiler/rustc_data_structures/src/stable_hasher.rs

+32
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,35 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>(
550550
entries.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
551551
entries.hash_stable(hcx, hasher);
552552
}
553+
554+
/// A vector container that makes sure that its items are hashed in a stable
555+
/// order.
556+
#[derive(Debug)]
557+
pub struct StableVec<T>(Vec<T>);
558+
559+
impl<T> StableVec<T> {
560+
pub fn new(v: Vec<T>) -> Self {
561+
StableVec(v)
562+
}
563+
}
564+
565+
impl<T> ::std::ops::Deref for StableVec<T> {
566+
type Target = Vec<T>;
567+
568+
fn deref(&self) -> &Vec<T> {
569+
&self.0
570+
}
571+
}
572+
573+
impl<T, HCX> HashStable<HCX> for StableVec<T>
574+
where
575+
T: HashStable<HCX> + ToStableHashKey<HCX>,
576+
{
577+
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
578+
let StableVec(ref v) = *self;
579+
580+
let mut sorted: Vec<_> = v.iter().map(|x| x.to_stable_hash_key(hcx)).collect();
581+
sorted.sort_unstable();
582+
sorted.hash_stable(hcx, hasher);
583+
}
584+
}

compiler/rustc_hir/src/arena.rs

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ macro_rules! arena_types {
4343
[] stmt: rustc_hir::Stmt<$tcx>,
4444
[] field_def: rustc_hir::FieldDef<$tcx>,
4545
[] trait_item_ref: rustc_hir::TraitItemRef,
46-
[] trait_candidate: rustc_hir::TraitCandidate,
4746
[] ty: rustc_hir::Ty<$tcx>,
4847
[] type_binding: rustc_hir::TypeBinding<$tcx>,
4948
[] variant: rustc_hir::Variant<$tcx>,

compiler/rustc_hir/src/definitions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::debug;
2525
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
2626
/// stores the `DefIndex` of its parent.
2727
/// There is one `DefPathTable` for each crate.
28-
#[derive(Clone, Default, Debug)]
28+
#[derive(Clone, Default)]
2929
pub struct DefPathTable {
3030
index_to_key: IndexVec<DefIndex, DefKey>,
3131
def_path_hashes: IndexVec<DefIndex, DefPathHash>,
@@ -107,7 +107,7 @@ impl DefPathTable {
107107
/// The definition table containing node definitions.
108108
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s.
109109
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s.
110-
#[derive(Clone, Debug)]
110+
#[derive(Clone)]
111111
pub struct Definitions {
112112
table: DefPathTable,
113113

compiler/rustc_hir/src/hir.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-tidy-filelength
22
use crate::def::{CtorKind, DefKind, Res};
33
use crate::def_id::DefId;
4-
crate use crate::hir_id::{HirId, ItemLocalId};
4+
crate use crate::hir_id::HirId;
55
use crate::{itemlikevisit, LangItem};
66

77
use rustc_ast::util::parser::ExprPrecedence;
@@ -10,7 +10,6 @@ use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, TraitObject
1010
pub use rustc_ast::{BorrowKind, ImplPolarity, IsAuto};
1111
pub use rustc_ast::{CaptureBy, Movability, Mutability};
1212
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
13-
use rustc_data_structures::fx::FxHashMap;
1413
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
1514
use rustc_macros::HashStable_Generic;
1615
use rustc_span::source_map::Spanned;
@@ -659,9 +658,7 @@ pub struct Crate<'hir> {
659658
/// they are declared in the static array generated by proc_macro_harness.
660659
pub proc_macros: Vec<HirId>,
661660

662-
/// Map indicating what traits are in scope for places where this
663-
/// is relevant; generated by resolve.
664-
pub trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Box<[TraitCandidate]>>>,
661+
pub trait_map: BTreeMap<HirId, Vec<TraitCandidate>>,
665662

666663
/// Collected attributes from HIR nodes.
667664
pub attrs: BTreeMap<HirId, &'hir [Attribute]>,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
524524
}
525525

526526
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
527-
Ok(vec![self.tcx.crate_name(cnum).to_string()])
527+
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
528528
}
529529
fn path_qualified(
530530
self,

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ pub fn create_global_ctxt<'tcx>(
799799
query_result_on_disk_cache,
800800
queries.as_dyn(),
801801
&crate_name,
802-
outputs,
802+
&outputs,
803803
)
804804
})
805805
});

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ impl<'tcx> LateContext<'tcx> {
922922
}
923923

924924
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
925-
Ok(vec![self.tcx.crate_name(cnum)])
925+
Ok(vec![self.tcx.original_crate_name(cnum)])
926926
}
927927

928928
fn path_qualified(

compiler/rustc_metadata/src/creader.rs

-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ pub struct CStore {
5151
unused_externs: Vec<Symbol>,
5252
}
5353

54-
impl std::fmt::Debug for CStore {
55-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56-
f.debug_struct("CStore").finish_non_exhaustive()
57-
}
58-
}
59-
6054
pub struct CrateLoader<'a> {
6155
// Immutable configuration.
6256
sess: &'a Session,

compiler/rustc_metadata/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@ mod rmeta;
3131
pub mod creader;
3232
pub mod dynamic_lib;
3333
pub mod locator;
34-
35-
pub use rmeta::METADATA_HEADER;

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::creader::{CStore, LoadedMacro};
22
use crate::foreign_modules;
33
use crate::native_libs;
4-
use crate::rmeta::encoder;
4+
use crate::rmeta::{self, encoder};
55

66
use rustc_ast as ast;
77
use rustc_ast::expand::allocator::AllocatorKind;
@@ -187,8 +187,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
187187
foreign_modules => { cdata.get_foreign_modules(tcx) }
188188
crate_hash => { cdata.root.hash }
189189
crate_host_hash => { cdata.host_hash }
190-
crate_name => { cdata.root.name }
191-
is_private_dep => { cdata.private_dep }
190+
original_crate_name => { cdata.root.name }
192191

193192
extra_filename => { cdata.root.extra_filename.clone() }
194193

@@ -205,6 +204,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
205204
let r = *cdata.dep_kind.lock();
206205
r
207206
}
207+
crate_name => { cdata.root.name }
208208
item_children => {
209209
let mut result = SmallVec::<[_; 8]>::new();
210210
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
@@ -477,6 +477,10 @@ impl CrateStore for CStore {
477477
self.get_crate_data(cnum).root.name
478478
}
479479

480+
fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool {
481+
self.get_crate_data(cnum).private_dep
482+
}
483+
480484
fn stable_crate_id_untracked(&self, cnum: CrateNum) -> StableCrateId {
481485
self.get_crate_data(cnum).root.stable_crate_id
482486
}
@@ -524,6 +528,10 @@ impl CrateStore for CStore {
524528
encoder::encode_metadata(tcx)
525529
}
526530

531+
fn metadata_encoding_version(&self) -> &[u8] {
532+
rmeta::METADATA_HEADER
533+
}
534+
527535
fn allocator_kind(&self) -> Option<AllocatorKind> {
528536
self.allocator_kind()
529537
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
445445
}
446446

447447
fn encode_def_path_table(&mut self) {
448-
let table = self.tcx.resolutions(()).definitions.def_path_table();
448+
let table = self.tcx.hir().definitions().def_path_table();
449449
if self.is_proc_macro {
450450
for def_index in std::iter::once(CRATE_DEF_INDEX)
451451
.chain(self.tcx.hir().krate().proc_macros.iter().map(|p| p.owner.local_def_index))
@@ -1062,7 +1062,7 @@ impl EncodeContext<'a, 'tcx> {
10621062

10631063
let data = ModData {
10641064
reexports,
1065-
expansion: tcx.resolutions(()).definitions.expansion_that_defined(local_def_id),
1065+
expansion: tcx.hir().definitions().expansion_that_defined(local_def_id),
10661066
};
10671067

10681068
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
@@ -1673,7 +1673,7 @@ impl EncodeContext<'a, 'tcx> {
16731673
.iter()
16741674
.map(|&cnum| {
16751675
let dep = CrateDep {
1676-
name: self.tcx.crate_name(cnum),
1676+
name: self.tcx.original_crate_name(cnum),
16771677
hash: self.tcx.crate_hash(cnum),
16781678
host_hash: self.tcx.crate_host_hash(cnum),
16791679
kind: self.tcx.dep_kind(cnum),
@@ -1754,7 +1754,7 @@ impl EncodeContext<'a, 'tcx> {
17541754
.map(|(trait_def_id, mut impls)| {
17551755
// Bring everything into deterministic order for hashing
17561756
impls.sort_by_cached_key(|&(index, _)| {
1757-
tcx.hir().def_path_hash(LocalDefId { local_def_index: index })
1757+
tcx.hir().definitions().def_path_hash(LocalDefId { local_def_index: index })
17581758
});
17591759

17601760
TraitImpls {

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const METADATA_VERSION: u8 = 5;
5151
/// This header is followed by the position of the `CrateRoot`,
5252
/// which is encoded as a 32-bit big-endian unsigned integer,
5353
/// and further followed by the rustc version string.
54-
pub const METADATA_HEADER: &[u8; 8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
54+
crate const METADATA_HEADER: &[u8; 8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
5555

5656
/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
5757
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).

compiler/rustc_middle/src/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
285285
// required that their size stay the same, but we don't want to change
286286
// it inadvertently. This assert just ensures we're aware of any change.
287287
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
288-
static_assert_size!(DepNode, 18);
288+
static_assert_size!(DepNode, 17);
289289

290290
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
291291
static_assert_size!(DepNode, 24);

0 commit comments

Comments
 (0)