Skip to content

Commit d99e0c6

Browse files
committed
Auto merge of #66697 - petrochenkov:nocstore, r=eddyb
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
2 parents c4375c9 + e84c926 commit d99e0c6

File tree

18 files changed

+338
-324
lines changed

18 files changed

+338
-324
lines changed

Diff for: src/librustc/middle/cstore.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ impl ExternCrate {
146146
pub fn is_direct(&self) -> bool {
147147
self.dependency_of == LOCAL_CRATE
148148
}
149+
150+
pub fn rank(&self) -> impl PartialOrd {
151+
// Prefer:
152+
// - direct extern crate to indirect
153+
// - shorter paths to longer
154+
(self.is_direct(), !self.path_len)
155+
}
149156
}
150157

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

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

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

Diff for: src/librustc/session/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ pub struct Session {
133133
/// false positives about a job server in our environment.
134134
pub jobserver: Client,
135135

136-
/// Metadata about the allocators for the current crate being compiled.
137-
pub has_global_allocator: Once<bool>,
138-
139136
/// Cap lint level specified by a driver specifically.
140137
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
141138

@@ -1180,7 +1177,6 @@ fn build_session_(
11801177
print_fuel_crate,
11811178
print_fuel,
11821179
jobserver: jobserver::client(),
1183-
has_global_allocator: Once::new(),
11841180
driver_lint_caps,
11851181
trait_methods_not_found: Lock::new(Default::default()),
11861182
confused_type_with_std_module: Lock::new(Default::default()),

Diff for: src/librustc/ty/context.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1307,10 +1307,6 @@ impl<'tcx> TyCtxt<'tcx> {
13071307
self.all_crate_nums(LOCAL_CRATE)
13081308
}
13091309

1310-
pub fn injected_panic_runtime(self) -> Option<CrateNum> {
1311-
self.cstore.injected_panic_runtime()
1312-
}
1313-
13141310
pub fn allocator_kind(self) -> Option<AllocatorKind> {
13151311
self.cstore.allocator_kind()
13161312
}
@@ -1391,8 +1387,8 @@ impl<'tcx> TyCtxt<'tcx> {
13911387

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

13981394
#[inline(always)]
@@ -2999,14 +2995,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
29992995
assert_eq!(cnum, LOCAL_CRATE);
30002996
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked())
30012997
};
3002-
providers.crate_host_hash = |tcx, cnum| {
3003-
assert_ne!(cnum, LOCAL_CRATE);
3004-
tcx.cstore.crate_host_hash_untracked(cnum)
3005-
};
3006-
providers.postorder_cnums = |tcx, cnum| {
3007-
assert_eq!(cnum, LOCAL_CRATE);
3008-
tcx.arena.alloc_slice(&tcx.cstore.postorder_cnums_untracked())
3009-
};
30102998
providers.output_filenames = |tcx, cnum| {
30112999
assert_eq!(cnum, LOCAL_CRATE);
30123000
tcx.output_filenames.clone()

Diff for: src/librustc_interface/passes.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_data_structures::{box_region_allow_access, declare_box_region_type, pa
2525
use rustc_data_structures::sync::{Lrc, ParallelIterator, par_iter};
2626
use rustc_errors::PResult;
2727
use rustc_incremental;
28-
use rustc_metadata::cstore;
2928
use rustc_mir as mir;
3029
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
3130
use rustc_passes::{self, ast_validation, hir_stats, layout_test};
@@ -728,15 +727,15 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
728727
rustc_passes::provide(providers);
729728
rustc_traits::provide(providers);
730729
middle::region::provide(providers);
731-
cstore::provide(providers);
730+
rustc_metadata::provide(providers);
732731
lint::provide(providers);
733732
rustc_lint::provide(providers);
734733
rustc_codegen_utils::provide(providers);
735734
rustc_codegen_ssa::provide(providers);
736735
}
737736

738737
pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) {
739-
cstore::provide_extern(providers);
738+
rustc_metadata::provide_extern(providers);
740739
rustc_codegen_ssa::provide_extern(providers);
741740
}
742741

0 commit comments

Comments
 (0)