Skip to content
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

Revert "Reduce the amount of untracked state in TyCtxt" #85884

Merged
merged 1 commit into from
Jun 1, 2021
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: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,6 @@ dependencies = [
"rustc_incremental",
"rustc_index",
"rustc_llvm",
"rustc_metadata",
"rustc_middle",
"rustc_serialize",
"rustc_session",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::symbol::{sym, Symbol};

#[derive(Clone, Debug, Copy, HashStable_Generic)]
#[derive(Clone, Copy)]
pub enum AllocatorKind {
Global,
Default,
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use rustc_ast::walk_list;
use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
Expand Down Expand Up @@ -198,7 +198,7 @@ pub trait ResolverAstLowering {

fn next_node_id(&mut self) -> NodeId;

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

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

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

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

let mut def_id_to_hir_id = IndexVec::default();

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn codegen(
});
if any_dynamic_crate {
false
} else if let Some(kind) = tcx.allocator_kind(()) {
} else if let Some(kind) = tcx.allocator_kind() {
codegen_inner(module, unwind_context, kind);
true
} else {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern crate rustc_fs_util;
extern crate rustc_hir;
extern crate rustc_incremental;
extern crate rustc_index;
extern crate rustc_metadata;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) fn write_metadata<O: WriteMetadata>(tcx: TyCtxt<'_>, object: &mut O)
use std::io::Write;

let metadata = tcx.encode_metadata();
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
let mut compressed = tcx.metadata_encoding_version();
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();

object.add_rustc_section(
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rustc_hir = { path = "../rustc_hir" }
rustc_incremental = { path = "../rustc_incremental" }
rustc_index = { path = "../rustc_index" }
rustc_llvm = { path = "../rustc_llvm" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_session = { path = "../rustc_session" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_target = { path = "../rustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn write_compressed_metadata<'tcx>(
let section_name = if tcx.sess.target.is_like_osx { "__DATA,.rustc" } else { ".rustc" };

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

let llmeta = common::bytes_in_context(metadata_llcx, &compressed);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn exported_symbols_provider_local(
symbols.push((exported_symbol, SymbolExportLevel::C));
}

if tcx.allocator_kind(()).is_some() {
if tcx.allocator_kind().is_some() {
for method in ALLOCATOR_METHODS {
let symbol_name = format!("__rust_{}", method.name);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
});
let allocator_module = if any_dynamic_crate {
None
} else if let Some(kind) = tcx.allocator_kind(()) {
} else if let Some(kind) = tcx.allocator_kind() {
let llmod_id =
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
let mut modules = backend.new_metadata(tcx, &llmod_id);
Expand Down
32 changes: 32 additions & 0 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,35 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>(
entries.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
entries.hash_stable(hcx, hasher);
}

/// A vector container that makes sure that its items are hashed in a stable
/// order.
#[derive(Debug)]
pub struct StableVec<T>(Vec<T>);

impl<T> StableVec<T> {
pub fn new(v: Vec<T>) -> Self {
StableVec(v)
}
}

impl<T> ::std::ops::Deref for StableVec<T> {
type Target = Vec<T>;

fn deref(&self) -> &Vec<T> {
&self.0
}
}

impl<T, HCX> HashStable<HCX> for StableVec<T>
where
T: HashStable<HCX> + ToStableHashKey<HCX>,
{
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
let StableVec(ref v) = *self;

let mut sorted: Vec<_> = v.iter().map(|x| x.to_stable_hash_key(hcx)).collect();
sorted.sort_unstable();
sorted.hash_stable(hcx, hasher);
}
}
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ macro_rules! arena_types {
[] stmt: rustc_hir::Stmt<$tcx>,
[] field_def: rustc_hir::FieldDef<$tcx>,
[] trait_item_ref: rustc_hir::TraitItemRef,
[] trait_candidate: rustc_hir::TraitCandidate,
[] ty: rustc_hir::Ty<$tcx>,
[] type_binding: rustc_hir::TypeBinding<$tcx>,
[] variant: rustc_hir::Variant<$tcx>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::debug;
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
/// stores the `DefIndex` of its parent.
/// There is one `DefPathTable` for each crate.
#[derive(Clone, Default, Debug)]
#[derive(Clone, Default)]
pub struct DefPathTable {
index_to_key: IndexVec<DefIndex, DefKey>,
def_path_hashes: IndexVec<DefIndex, DefPathHash>,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl DefPathTable {
/// The definition table containing node definitions.
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s.
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s.
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Definitions {
table: DefPathTable,

Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-tidy-filelength
use crate::def::{CtorKind, DefKind, Res};
use crate::def_id::DefId;
crate use crate::hir_id::{HirId, ItemLocalId};
crate use crate::hir_id::HirId;
use crate::{itemlikevisit, LangItem};

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

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

/// Collected attributes from HIR nodes.
pub attrs: BTreeMap<HirId, &'hir [Attribute]>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
Ok(vec![self.tcx.crate_name(cnum).to_string()])
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
}
fn path_qualified(
self,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ pub fn create_global_ctxt<'tcx>(
query_result_on_disk_cache,
queries.as_dyn(),
&crate_name,
outputs,
&outputs,
)
})
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ impl<'tcx> LateContext<'tcx> {
}

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

fn path_qualified(
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ pub struct CStore {
unused_externs: Vec<Symbol>,
}

impl std::fmt::Debug for CStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CStore").finish_non_exhaustive()
}
}

pub struct CrateLoader<'a> {
// Immutable configuration.
sess: &'a Session,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ mod rmeta;
pub mod creader;
pub mod dynamic_lib;
pub mod locator;

pub use rmeta::METADATA_HEADER;
14 changes: 11 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::creader::{CStore, LoadedMacro};
use crate::foreign_modules;
use crate::native_libs;
use crate::rmeta::encoder;
use crate::rmeta::{self, encoder};

use rustc_ast as ast;
use rustc_ast::expand::allocator::AllocatorKind;
Expand Down Expand Up @@ -187,8 +187,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
foreign_modules => { cdata.get_foreign_modules(tcx) }
crate_hash => { cdata.root.hash }
crate_host_hash => { cdata.host_hash }
crate_name => { cdata.root.name }
is_private_dep => { cdata.private_dep }
original_crate_name => { cdata.root.name }

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

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

fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool {
self.get_crate_data(cnum).private_dep
}

fn stable_crate_id_untracked(&self, cnum: CrateNum) -> StableCrateId {
self.get_crate_data(cnum).root.stable_crate_id
}
Expand Down Expand Up @@ -524,6 +528,10 @@ impl CrateStore for CStore {
encoder::encode_metadata(tcx)
}

fn metadata_encoding_version(&self) -> &[u8] {
rmeta::METADATA_HEADER
}

fn allocator_kind(&self) -> Option<AllocatorKind> {
self.allocator_kind()
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}

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

let data = ModData {
reexports,
expansion: tcx.resolutions(()).definitions.expansion_that_defined(local_def_id),
expansion: tcx.hir().definitions().expansion_that_defined(local_def_id),
};

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

TraitImpls {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const METADATA_VERSION: u8 = 5;
/// This header is followed by the position of the `CrateRoot`,
/// which is encoded as a 32-bit big-endian unsigned integer,
/// and further followed by the rustc version string.
pub const METADATA_HEADER: &[u8; 8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
crate const METADATA_HEADER: &[u8; 8] = &[b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];

/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
// required that their size stay the same, but we don't want to change
// it inadvertently. This assert just ensures we're aware of any change.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
static_assert_size!(DepNode, 18);
static_assert_size!(DepNode, 17);

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
static_assert_size!(DepNode, 24);
Expand Down
Loading