Skip to content

Commit

Permalink
Move allocator_kind to CrateStore
Browse files Browse the repository at this point in the history
Similarly to the previous commit, there's no need for this to be in
Session and have a Once around it.
  • Loading branch information
Mark-Simulacrum committed Nov 11, 2019
1 parent e1cf38a commit 2c6d609
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/librustc/middle/cstore.rs
Expand Up @@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
use syntax::ast; use syntax::ast;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::expand::allocator::AllocatorKind;
use rustc_target::spec::Target; use rustc_target::spec::Target;
use rustc_data_structures::sync::{self, MetadataRef}; use rustc_data_structures::sync::{self, MetadataRef};
use rustc_macros::HashStable; use rustc_macros::HashStable;
Expand Down Expand Up @@ -228,6 +229,7 @@ pub trait CrateStore {
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata; fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
fn metadata_encoding_version(&self) -> &[u8]; fn metadata_encoding_version(&self) -> &[u8];
fn injected_panic_runtime(&self) -> Option<CrateNum>; fn injected_panic_runtime(&self) -> Option<CrateNum>;
fn allocator_kind(&self) -> Option<AllocatorKind>;
} }


pub type CrateStoreDyn = dyn CrateStore + sync::Sync; pub type CrateStoreDyn = dyn CrateStore + sync::Sync;
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/session/mod.rs
Expand Up @@ -21,7 +21,6 @@ use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType; use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter}; use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::expand::allocator::AllocatorKind;
use syntax::feature_gate::{self, AttributeType}; use syntax::feature_gate::{self, AttributeType};
use syntax::json::JsonEmitter; use syntax::json::JsonEmitter;
use syntax::source_map; use syntax::source_map;
Expand Down Expand Up @@ -100,11 +99,6 @@ pub struct Session {
/// The maximum number of stackframes allowed in const eval. /// The maximum number of stackframes allowed in const eval.
pub const_eval_stack_frame_limit: usize, pub const_eval_stack_frame_limit: usize,


/// The `metadata::creader` module may inject an allocator/`panic_runtime`
/// dependency if it didn't already find one, and this tracks what was
/// injected.
pub allocator_kind: Once<Option<AllocatorKind>>,

/// Map from imported macro spans (which consist of /// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the /// the localized span for the macro body) to the
/// macro name and definition span in the source crate. /// macro name and definition span in the source crate.
Expand Down Expand Up @@ -1179,7 +1173,6 @@ fn build_session_(
recursion_limit: Once::new(), recursion_limit: Once::new(),
type_length_limit: Once::new(), type_length_limit: Once::new(),
const_eval_stack_frame_limit: 100, const_eval_stack_frame_limit: 100,
allocator_kind: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())), imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)), incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker, cgu_reuse_tracker,
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/ty/context.rs
Expand Up @@ -75,6 +75,7 @@ use syntax::source_map::MultiSpan;
use syntax::feature_gate; use syntax::feature_gate;
use syntax::symbol::{Symbol, kw, sym}; use syntax::symbol::{Symbol, kw, sym};
use syntax_pos::Span; use syntax_pos::Span;
use syntax::expand::allocator::AllocatorKind;


pub struct AllArenas { pub struct AllArenas {
pub interner: SyncDroplessArena, pub interner: SyncDroplessArena,
Expand Down Expand Up @@ -1342,6 +1343,10 @@ impl<'tcx> TyCtxt<'tcx> {
self.cstore.injected_panic_runtime() self.cstore.injected_panic_runtime()
} }


pub fn allocator_kind(self) -> Option<AllocatorKind> {
self.cstore.allocator_kind()
}

pub fn features(self) -> &'tcx feature_gate::Features { pub fn features(self) -> &'tcx feature_gate::Features {
self.features_query(LOCAL_CRATE) self.features_query(LOCAL_CRATE)
} }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Expand Up @@ -194,7 +194,7 @@ fn exported_symbols_provider_local(
symbols.push((exported_symbol, SymbolExportLevel::C)); symbols.push((exported_symbol, SymbolExportLevel::C));
} }


if tcx.sess.allocator_kind.get().is_some() { if tcx.allocator_kind().is_some() {
for method in ALLOCATOR_METHODS { for method in ALLOCATOR_METHODS {
let symbol_name = format!("__rust_{}", method.name); let symbol_name = format!("__rust_{}", method.name);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name)); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/base.rs
Expand Up @@ -549,7 +549,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
}); });
let allocator_module = if any_dynamic_crate { let allocator_module = if any_dynamic_crate {
None None
} else if let Some(kind) = *tcx.sess.allocator_kind.get() { } else if let Some(kind) = tcx.allocator_kind() {
let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE, let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
&["crate"], &["crate"],
Some("allocator")).to_string(); Some("allocator")).to_string();
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/creader.rs
Expand Up @@ -722,7 +722,7 @@ impl<'a> CrateLoader<'a> {
} }
} }


fn inject_allocator_crate(&self, krate: &ast::Crate) { fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
let has_global_allocator = match &*global_allocator_spans(krate) { let has_global_allocator = match &*global_allocator_spans(krate) {
[span1, span2, ..] => { [span1, span2, ..] => {
self.sess.struct_span_err(*span2, "cannot define multiple global allocators") self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
Expand All @@ -742,7 +742,7 @@ impl<'a> CrateLoader<'a> {
needs_allocator = needs_allocator || data.root.needs_allocator; needs_allocator = needs_allocator || data.root.needs_allocator;
}); });
if !needs_allocator { if !needs_allocator {
self.sess.allocator_kind.set(None); self.cstore.allocator_kind = None;
return return
} }


Expand All @@ -758,7 +758,7 @@ impl<'a> CrateLoader<'a> {
} }
}); });
if all_rlib { if all_rlib {
self.sess.allocator_kind.set(None); self.cstore.allocator_kind = None;
return return
} }


Expand Down Expand Up @@ -795,7 +795,7 @@ impl<'a> CrateLoader<'a> {
} }
}); });
if global_allocator.is_some() { if global_allocator.is_some() {
self.sess.allocator_kind.set(Some(AllocatorKind::Global)); self.cstore.allocator_kind = Some(AllocatorKind::Global);
return return
} }


Expand All @@ -816,7 +816,7 @@ impl<'a> CrateLoader<'a> {
add `#[global_allocator]` to a static item \ add `#[global_allocator]` to a static item \
that implements the GlobalAlloc trait."); that implements the GlobalAlloc trait.");
} }
self.sess.allocator_kind.set(Some(AllocatorKind::DefaultLib)); self.cstore.allocator_kind = Some(AllocatorKind::DefaultLib);
} }


fn inject_dependency_if(&self, fn inject_dependency_if(&self,
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -14,6 +14,7 @@ use rustc_data_structures::svh::Svh;
use syntax::ast; use syntax::ast;
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax_expand::base::SyntaxExtension; use syntax_expand::base::SyntaxExtension;
use syntax::expand::allocator::AllocatorKind;
use syntax_pos; use syntax_pos;
use proc_macro::bridge::client::ProcMacro; use proc_macro::bridge::client::ProcMacro;


Expand Down Expand Up @@ -102,6 +103,7 @@ crate struct CrateMetadata {
pub struct CStore { pub struct CStore {
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>, metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
pub(crate) injected_panic_runtime: Option<CrateNum>, pub(crate) injected_panic_runtime: Option<CrateNum>,
pub(crate) allocator_kind: Option<AllocatorKind>,
} }


pub enum LoadedMacro { pub enum LoadedMacro {
Expand All @@ -118,6 +120,7 @@ impl Default for CStore {
// `None`. // `None`.
metas: IndexVec::from_elem_n(None, 1), metas: IndexVec::from_elem_n(None, 1),
injected_panic_runtime: None, injected_panic_runtime: None,
allocator_kind: None,
} }
} }
} }
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Expand Up @@ -31,6 +31,7 @@ use syntax::attr;
use syntax::source_map; use syntax::source_map;
use syntax::source_map::Spanned; use syntax::source_map::Spanned;
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
use syntax::expand::allocator::AllocatorKind;
use syntax_pos::{Span, FileName}; use syntax_pos::{Span, FileName};


macro_rules! provide { macro_rules! provide {
Expand Down Expand Up @@ -531,4 +532,8 @@ impl CrateStore for cstore::CStore {
fn injected_panic_runtime(&self) -> Option<CrateNum> { fn injected_panic_runtime(&self) -> Option<CrateNum> {
self.injected_panic_runtime self.injected_panic_runtime
} }

fn allocator_kind(&self) -> Option<AllocatorKind> {
self.allocator_kind
}
} }

0 comments on commit 2c6d609

Please sign in to comment.