Skip to content

Commit 7d33d1a

Browse files
committed
Make Session.has_global_allocator thread-safe
1 parent 73b26f7 commit 7d33d1a

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

src/librustc/session/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct Session {
161161
pub jobserver_from_env: Option<Client>,
162162

163163
/// Metadata about the allocators for the current crate being compiled
164-
pub has_global_allocator: Cell<bool>,
164+
pub has_global_allocator: Once<bool>,
165165
}
166166

167167
pub struct PerfStats {
@@ -1142,7 +1142,7 @@ pub fn build_session_(
11421142
});
11431143
(*GLOBAL_JOBSERVER).clone()
11441144
},
1145-
has_global_allocator: Cell::new(false),
1145+
has_global_allocator: Once::new(),
11461146
};
11471147

11481148
sess

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,7 @@ impl<'a> CrateLoader<'a> {
812812

813813
fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
814814
let has_global_allocator = has_global_allocator(krate);
815-
if has_global_allocator {
816-
self.sess.has_global_allocator.set(true);
817-
}
815+
self.sess.has_global_allocator.set(has_global_allocator);
818816

819817
// Check to see if we actually need an allocator. This desire comes
820818
// about through the `#![needs_allocator]` attribute and is typically

src/librustc_metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
459459
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
460460
let has_default_lib_allocator =
461461
attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
462-
let has_global_allocator = tcx.sess.has_global_allocator.get();
462+
let has_global_allocator = *tcx.sess.has_global_allocator.get();
463463
let root = self.lazy(&CrateRoot {
464464
name: tcx.crate_name(LOCAL_CRATE),
465465
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),

0 commit comments

Comments
 (0)