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.
This commit is contained in:
parent
56237d75b4
commit
e1cf38ac18
7 changed files with 16 additions and 9 deletions
|
@ -227,6 +227,7 @@ 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>;
|
||||
}
|
||||
|
||||
pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
|
||||
|
|
|
@ -2,7 +2,6 @@ pub use self::code_stats::{DataTypeKind, SizeKind, FieldInfo, VariantInfo};
|
|||
use self::code_stats::CodeStats;
|
||||
|
||||
use crate::dep_graph::cgu_reuse_tracker::CguReuseTracker;
|
||||
use crate::hir::def_id::CrateNum;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
|
||||
use crate::lint;
|
||||
|
@ -105,7 +104,6 @@ pub struct Session {
|
|||
/// dependency if it didn't already find one, and this tracks what was
|
||||
/// injected.
|
||||
pub allocator_kind: Once<Option<AllocatorKind>>,
|
||||
pub injected_panic_runtime: Once<Option<CrateNum>>,
|
||||
|
||||
/// Map from imported macro spans (which consist of
|
||||
/// the localized span for the macro body) to the
|
||||
|
@ -1182,7 +1180,6 @@ fn build_session_(
|
|||
type_length_limit: Once::new(),
|
||||
const_eval_stack_frame_limit: 100,
|
||||
allocator_kind: Once::new(),
|
||||
injected_panic_runtime: Once::new(),
|
||||
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
|
||||
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
|
||||
cgu_reuse_tracker,
|
||||
|
|
|
@ -1338,6 +1338,10 @@ 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 features(self) -> &'tcx feature_gate::Features {
|
||||
self.features_query(LOCAL_CRATE)
|
||||
}
|
||||
|
|
|
@ -531,7 +531,7 @@ impl<'a> CrateLoader<'a> {
|
|||
});
|
||||
if !any_non_rlib {
|
||||
info!("panic runtime injection skipped, only generating rlib");
|
||||
self.sess.injected_panic_runtime.set(None);
|
||||
self.cstore.injected_panic_runtime = None;
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ impl<'a> CrateLoader<'a> {
|
|||
// we just don't need one at all, then we're done here and there's
|
||||
// nothing else to do.
|
||||
if !needs_panic_runtime || runtime_found {
|
||||
self.sess.injected_panic_runtime.set(None);
|
||||
self.cstore.injected_panic_runtime = None;
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -600,7 +600,7 @@ impl<'a> CrateLoader<'a> {
|
|||
name, desired_strategy.desc()));
|
||||
}
|
||||
|
||||
self.sess.injected_panic_runtime.set(Some(cnum));
|
||||
self.cstore.injected_panic_runtime = Some(cnum);
|
||||
self.inject_dependency_if(cnum, "a panic runtime",
|
||||
&|data| data.root.needs_panic_runtime);
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ crate struct CrateMetadata {
|
|||
#[derive(Clone)]
|
||||
pub struct CStore {
|
||||
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
|
||||
pub(crate) injected_panic_runtime: Option<CrateNum>,
|
||||
}
|
||||
|
||||
pub enum LoadedMacro {
|
||||
|
@ -116,6 +117,7 @@ impl Default for CStore {
|
|||
// corresponding `CrateNum`. This first entry will always remain
|
||||
// `None`.
|
||||
metas: IndexVec::from_elem_n(None, 1),
|
||||
injected_panic_runtime: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList {
|
|||
//
|
||||
// Things like allocators and panic runtimes may not have been activated
|
||||
// quite yet, so do so here.
|
||||
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
|
||||
activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
|
||||
&|cnum| tcx.is_panic_runtime(cnum));
|
||||
|
||||
// When dylib B links to dylib A, then when using B we must also link to A.
|
||||
|
@ -244,7 +244,6 @@ fn add_library(
|
|||
}
|
||||
|
||||
fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
|
||||
let sess = &tcx.sess;
|
||||
let crates = cstore::used_crates(tcx, RequireStatic);
|
||||
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
|
||||
return None
|
||||
|
@ -264,7 +263,7 @@ fn attempt_static(tcx: TyCtxt<'_>) -> Option<DependencyList> {
|
|||
// Our allocator/panic runtime may not have been linked above if it wasn't
|
||||
// explicitly linked, which is the case for any injected dependency. Handle
|
||||
// that here and activate them.
|
||||
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
|
||||
activate_injected_dep(tcx.injected_panic_runtime(), &mut ret,
|
||||
&|cnum| tcx.is_panic_runtime(cnum));
|
||||
|
||||
Some(ret)
|
||||
|
|
|
@ -527,4 +527,8 @@ impl CrateStore for cstore::CStore {
|
|||
{
|
||||
rmeta::METADATA_HEADER
|
||||
}
|
||||
|
||||
fn injected_panic_runtime(&self) -> Option<CrateNum> {
|
||||
self.injected_panic_runtime
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue