Skip to content

Commit

Permalink
Auto merge of #66697 - petrochenkov:nocstore, r=eddyb
Browse files Browse the repository at this point in the history
rustc_metadata: Privatize more things and a couple of other refactorings

This PR continues #66496 and hits the point of diminishing returns.
All fields of `CrateRoot` and `CrateMetadata` are privatized.
For read-only fields this certainly makes sense, but for a few fields updateable from outside of `rmeta.rs` (mostly `creader.rs`) it was done mostly for consistency, I can make them `pub(crate)` again if requested.

`cstore.rs` (which became small after #66496) was merged into `creader.rs`.

A few things noticed while making the privacy changes were addressed in the remaining refactoring commits.

Fixes #66550
r? @eddyb @Mark-Simulacrum
  • Loading branch information
bors committed Nov 29, 2019
2 parents c4375c9 + e84c926 commit d99e0c6
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 324 deletions.
12 changes: 8 additions & 4 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ impl ExternCrate {
pub fn is_direct(&self) -> bool {
self.dependency_of == LOCAL_CRATE
}

pub fn rank(&self) -> impl PartialOrd {
// Prefer:
// - direct extern crate to indirect
// - shorter paths to longer
(self.is_direct(), !self.path_len)
}
}

#[derive(Copy, Clone, Debug, HashStable)]
Expand Down Expand Up @@ -204,7 +211,7 @@ pub type MetadataLoaderDyn = dyn MetadataLoader + Sync;
/// (it'd break incremental compilation) and should only be called pre-HIR (e.g.
/// during resolve)
pub trait CrateStore {
fn crate_data_as_any(&self, cnum: CrateNum) -> &dyn Any;
fn as_any(&self) -> &dyn Any;

// resolve
fn def_key(&self, def: DefId) -> DefKey;
Expand All @@ -217,9 +224,7 @@ pub trait CrateStore {
fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool;
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
fn crate_host_hash_untracked(&self, cnum: CrateNum) -> Option<Svh>;
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;

// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
Expand All @@ -228,7 +233,6 @@ pub trait CrateStore {
// utility functions
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8];
fn injected_panic_runtime(&self) -> Option<CrateNum>;
fn allocator_kind(&self) -> Option<AllocatorKind>;
}

Expand Down
4 changes: 0 additions & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ pub struct Session {
/// false positives about a job server in our environment.
pub jobserver: Client,

/// Metadata about the allocators for the current crate being compiled.
pub has_global_allocator: Once<bool>,

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,

Expand Down Expand Up @@ -1180,7 +1177,6 @@ fn build_session_(
print_fuel_crate,
print_fuel,
jobserver: jobserver::client(),
has_global_allocator: Once::new(),
driver_lint_caps,
trait_methods_not_found: Lock::new(Default::default()),
confused_type_with_std_module: Lock::new(Default::default()),
Expand Down
16 changes: 2 additions & 14 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,10 +1307,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.all_crate_nums(LOCAL_CRATE)
}

pub fn injected_panic_runtime(self) -> Option<CrateNum> {
self.cstore.injected_panic_runtime()
}

pub fn allocator_kind(self) -> Option<AllocatorKind> {
self.cstore.allocator_kind()
}
Expand Down Expand Up @@ -1391,8 +1387,8 @@ impl<'tcx> TyCtxt<'tcx> {

// Note that this is *untracked* and should only be used within the query
// system if the result is otherwise tracked through queries
pub fn crate_data_as_any(self, cnum: CrateNum) -> &'tcx dyn Any {
self.cstore.crate_data_as_any(cnum)
pub fn cstore_as_any(self) -> &'tcx dyn Any {
self.cstore.as_any()
}

#[inline(always)]
Expand Down Expand Up @@ -2999,14 +2995,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE);
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked())
};
providers.crate_host_hash = |tcx, cnum| {
assert_ne!(cnum, LOCAL_CRATE);
tcx.cstore.crate_host_hash_untracked(cnum)
};
providers.postorder_cnums = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.arena.alloc_slice(&tcx.cstore.postorder_cnums_untracked())
};
providers.output_filenames = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
tcx.output_filenames.clone()
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, pa
use rustc_data_structures::sync::{Lrc, ParallelIterator, par_iter};
use rustc_errors::PResult;
use rustc_incremental;
use rustc_metadata::cstore;
use rustc_mir as mir;
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
Expand Down Expand Up @@ -728,15 +727,15 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
rustc_passes::provide(providers);
rustc_traits::provide(providers);
middle::region::provide(providers);
cstore::provide(providers);
rustc_metadata::provide(providers);
lint::provide(providers);
rustc_lint::provide(providers);
rustc_codegen_utils::provide(providers);
rustc_codegen_ssa::provide(providers);
}

pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) {
cstore::provide_extern(providers);
rustc_metadata::provide_extern(providers);
rustc_codegen_ssa::provide_extern(providers);
}

Expand Down
Loading

0 comments on commit d99e0c6

Please sign in to comment.