Skip to content

Commit 2c6d609

Browse files
Move allocator_kind to CrateStore
Similarly to the previous commit, there's no need for this to be in Session and have a Once around it.
1 parent e1cf38a commit 2c6d609

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
lines changed

src/librustc/middle/cstore.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
1515
use syntax::ast;
1616
use syntax::symbol::Symbol;
1717
use syntax_pos::Span;
18+
use syntax::expand::allocator::AllocatorKind;
1819
use rustc_target::spec::Target;
1920
use rustc_data_structures::sync::{self, MetadataRef};
2021
use rustc_macros::HashStable;
@@ -228,6 +229,7 @@ pub trait CrateStore {
228229
fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata;
229230
fn metadata_encoding_version(&self) -> &[u8];
230231
fn injected_panic_runtime(&self) -> Option<CrateNum>;
232+
fn allocator_kind(&self) -> Option<AllocatorKind>;
231233
}
232234

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

src/librustc/session/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use errors::emitter::{Emitter, EmitterWriter};
2121
use errors::emitter::HumanReadableErrorType;
2222
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2323
use syntax::edition::Edition;
24-
use syntax::expand::allocator::AllocatorKind;
2524
use syntax::feature_gate::{self, AttributeType};
2625
use syntax::json::JsonEmitter;
2726
use syntax::source_map;
@@ -100,11 +99,6 @@ pub struct Session {
10099
/// The maximum number of stackframes allowed in const eval.
101100
pub const_eval_stack_frame_limit: usize,
102101

103-
/// The `metadata::creader` module may inject an allocator/`panic_runtime`
104-
/// dependency if it didn't already find one, and this tracks what was
105-
/// injected.
106-
pub allocator_kind: Once<Option<AllocatorKind>>,
107-
108102
/// Map from imported macro spans (which consist of
109103
/// the localized span for the macro body) to the
110104
/// macro name and definition span in the source crate.
@@ -1179,7 +1173,6 @@ fn build_session_(
11791173
recursion_limit: Once::new(),
11801174
type_length_limit: Once::new(),
11811175
const_eval_stack_frame_limit: 100,
1182-
allocator_kind: Once::new(),
11831176
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
11841177
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
11851178
cgu_reuse_tracker,

src/librustc/ty/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use syntax::source_map::MultiSpan;
7575
use syntax::feature_gate;
7676
use syntax::symbol::{Symbol, kw, sym};
7777
use syntax_pos::Span;
78+
use syntax::expand::allocator::AllocatorKind;
7879

7980
pub struct AllArenas {
8081
pub interner: SyncDroplessArena,
@@ -1342,6 +1343,10 @@ impl<'tcx> TyCtxt<'tcx> {
13421343
self.cstore.injected_panic_runtime()
13431344
}
13441345

1346+
pub fn allocator_kind(self) -> Option<AllocatorKind> {
1347+
self.cstore.allocator_kind()
1348+
}
1349+
13451350
pub fn features(self) -> &'tcx feature_gate::Features {
13461351
self.features_query(LOCAL_CRATE)
13471352
}

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn exported_symbols_provider_local(
194194
symbols.push((exported_symbol, SymbolExportLevel::C));
195195
}
196196

197-
if tcx.sess.allocator_kind.get().is_some() {
197+
if tcx.allocator_kind().is_some() {
198198
for method in ALLOCATOR_METHODS {
199199
let symbol_name = format!("__rust_{}", method.name);
200200
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));

src/librustc_codegen_ssa/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
549549
});
550550
let allocator_module = if any_dynamic_crate {
551551
None
552-
} else if let Some(kind) = *tcx.sess.allocator_kind.get() {
552+
} else if let Some(kind) = tcx.allocator_kind() {
553553
let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
554554
&["crate"],
555555
Some("allocator")).to_string();

src/librustc_metadata/creader.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl<'a> CrateLoader<'a> {
722722
}
723723
}
724724

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

@@ -758,7 +758,7 @@ impl<'a> CrateLoader<'a> {
758758
}
759759
});
760760
if all_rlib {
761-
self.sess.allocator_kind.set(None);
761+
self.cstore.allocator_kind = None;
762762
return
763763
}
764764

@@ -795,7 +795,7 @@ impl<'a> CrateLoader<'a> {
795795
}
796796
});
797797
if global_allocator.is_some() {
798-
self.sess.allocator_kind.set(Some(AllocatorKind::Global));
798+
self.cstore.allocator_kind = Some(AllocatorKind::Global);
799799
return
800800
}
801801

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

822822
fn inject_dependency_if(&self,

src/librustc_metadata/cstore.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_data_structures::svh::Svh;
1414
use syntax::ast;
1515
use syntax::edition::Edition;
1616
use syntax_expand::base::SyntaxExtension;
17+
use syntax::expand::allocator::AllocatorKind;
1718
use syntax_pos;
1819
use proc_macro::bridge::client::ProcMacro;
1920

@@ -102,6 +103,7 @@ crate struct CrateMetadata {
102103
pub struct CStore {
103104
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
104105
pub(crate) injected_panic_runtime: Option<CrateNum>,
106+
pub(crate) allocator_kind: Option<AllocatorKind>,
105107
}
106108

107109
pub enum LoadedMacro {
@@ -118,6 +120,7 @@ impl Default for CStore {
118120
// `None`.
119121
metas: IndexVec::from_elem_n(None, 1),
120122
injected_panic_runtime: None,
123+
allocator_kind: None,
121124
}
122125
}
123126
}

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use syntax::attr;
3131
use syntax::source_map;
3232
use syntax::source_map::Spanned;
3333
use syntax::symbol::Symbol;
34+
use syntax::expand::allocator::AllocatorKind;
3435
use syntax_pos::{Span, FileName};
3536

3637
macro_rules! provide {
@@ -531,4 +532,8 @@ impl CrateStore for cstore::CStore {
531532
fn injected_panic_runtime(&self) -> Option<CrateNum> {
532533
self.injected_panic_runtime
533534
}
535+
536+
fn allocator_kind(&self) -> Option<AllocatorKind> {
537+
self.allocator_kind
538+
}
534539
}

0 commit comments

Comments
 (0)