Skip to content

Commit e1cf38a

Browse files
Move injected_panic_runtime to CrateStore
This was essentially a "query" previously (with no key, just always run once when resolving the crate dependencies), and remains so, just now in a way that isn't on Session. This removes the need for the `Once` as well.
1 parent 56237d7 commit e1cf38a

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

src/librustc/middle/cstore.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ pub trait CrateStore {
227227
// utility functions
228228
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
229229
fn metadata_encoding_version(&self) -> &[u8];
230+
fn injected_panic_runtime(&self) -> Option<CrateNum>;
230231
}
231232

232233
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;

src/librustc/session/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
22
use self::code_stats::CodeStats;
33

44
use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker;
5-
use crate::hir::def_id::CrateNum;
65
use rustc_data_structures::fingerprint::Fingerprint;
76

87
use crate::lint;
@@ -105,7 +104,6 @@ pub struct Session {
105104
/// dependency if it didn't already find one, and this tracks what was
106105
/// injected.
107106
pub allocator_kind: Once<Option<AllocatorKind>>,
108-
pub injected_panic_runtime: Once<Option<CrateNum>>,
109107

110108
/// Map from imported macro spans (which consist of
111109
/// the localized span for the macro body) to the
@@ -1182,7 +1180,6 @@ fn build_session_(
11821180
type_length_limit: Once::new(),
11831181
const_eval_stack_frame_limit: 100,
11841182
allocator_kind: Once::new(),
1185-
injected_panic_runtime: Once::new(),
11861183
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
11871184
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
11881185
cgu_reuse_tracker,

src/librustc/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,10 @@ impl<'tcx> TyCtxt<'tcx> {
13381338
self.all_crate_nums(LOCAL_CRATE)
13391339
}
13401340

1341+
pub fn injected_panic_runtime(self) -> Option<CrateNum> {
1342+
self.cstore.injected_panic_runtime()
1343+
}
1344+
13411345
pub fn features(self) -> &'tcx feature_gate::Features {
13421346
self.features_query(LOCAL_CRATE)
13431347
}

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'a> CrateLoader<'a> {
531531
});
532532
if !any_non_rlib {
533533
info!("panic runtime injection skipped, only generating rlib");
534-
self.sess.injected_panic_runtime.set(None);
534+
self.cstore.injected_panic_runtime = None;
535535
return
536536
}
537537

@@ -563,7 +563,7 @@ impl<'a> CrateLoader<'a> {
563563
// we just don't need one at all, then we're done here and there's
564564
// nothing else to do.
565565
if !needs_panic_runtime || runtime_found {
566-
self.sess.injected_panic_runtime.set(None);
566+
self.cstore.injected_panic_runtime = None;
567567
return
568568
}
569569

@@ -600,7 +600,7 @@ impl<'a> CrateLoader<'a> {
600600
name, desired_strategy.desc()));
601601
}
602602

603-
self.sess.injected_panic_runtime.set(Some(cnum));
603+
self.cstore.injected_panic_runtime = Some(cnum);
604604
self.inject_dependency_if(cnum, "a panic runtime",
605605
&|data| data.root.needs_panic_runtime);
606606
}

src/librustc_metadata/cstore.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ crate struct CrateMetadata {
101101
#[derive(Clone)]
102102
pub struct CStore {
103103
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
104+
pub(crate) injected_panic_runtime: Option<CrateNum>,
104105
}
105106

106107
pub enum LoadedMacro {
@@ -116,6 +117,7 @@ impl Default for CStore {
116117
// corresponding `CrateNum`. This first entry will always remain
117118
// `None`.
118119
metas: IndexVec::from_elem_n(None, 1),
120+
injected_panic_runtime: None,
119121
}
120122
}
121123
}

src/librustc_metadata/dependency_format.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList {
184184
//
185185
// Things like allocators and panic runtimes may not have been activated
186186
// quite yet, so do so here.
187-
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
187+
activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
188188
&|cnum| tcx.is_panic_runtime(cnum));
189189

190190
// When dylib B links to dylib A, then when using B we must also link to A.
@@ -244,7 +244,6 @@ fn add_library(
244244
}
245245

246246
fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
247-
let sess = &tcx.sess;
248247
let crates = cstore::used_crates(tcx, RequireStatic);
249248
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
250249
return None
@@ -264,7 +263,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
264263
// Our allocator/panic runtime may not have been linked above if it wasn't
265264
// explicitly linked, which is the case for any injected dependency. Handle
266265
// that here and activate them.
267-
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
266+
activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
268267
&|cnum| tcx.is_panic_runtime(cnum));
269268

270269
Some(ret)

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,8 @@ impl CrateStore for cstore::CStore {
527527
{
528528
rmeta::METADATA_HEADER
529529
}
530+
531+
fn injected_panic_runtime(&self) -> Option<CrateNum> {
532+
self.injected_panic_runtime
533+
}
530534
}

0 commit comments

Comments
 (0)