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

rustc_metadata: Privatize more things and a couple of other refactorings #66697

Merged
merged 13 commits into from
Nov 29, 2019
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
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()
}
Copy link
Member

@RalfJung RalfJung Nov 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miri was relying on injected_panic_runtime... is there a replacement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, something like

tcx.crates().iter().find(|cnum| tcx.is_panic_runtime(cnum))

should work without re-exposing things privatized in this PR.

(If that's not ok, I can send a PR re-adding tcx.injected_panic_runtime().)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to work, thanks! (modulo some extra *)

See rust-lang/miri#1085


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