Make Session.has_global_allocator thread-safe

This commit is contained in:
John Kåre Alsaker 2018-04-01 08:24:46 +02:00
parent 73b26f7f51
commit 7d33d1a84e
3 changed files with 4 additions and 6 deletions

View file

@ -161,7 +161,7 @@ pub struct Session {
pub jobserver_from_env: Option<Client>,
/// Metadata about the allocators for the current crate being compiled
pub has_global_allocator: Cell<bool>,
pub has_global_allocator: Once<bool>,
}
pub struct PerfStats {
@ -1142,7 +1142,7 @@ pub fn build_session_(
});
(*GLOBAL_JOBSERVER).clone()
},
has_global_allocator: Cell::new(false),
has_global_allocator: Once::new(),
};
sess

View file

@ -812,9 +812,7 @@ impl<'a> CrateLoader<'a> {
fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
let has_global_allocator = has_global_allocator(krate);
if has_global_allocator {
self.sess.has_global_allocator.set(true);
}
self.sess.has_global_allocator.set(has_global_allocator);
// Check to see if we actually need an allocator. This desire comes
// about through the `#![needs_allocator]` attribute and is typically

View file

@ -459,7 +459,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
let has_default_lib_allocator =
attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
let has_global_allocator = tcx.sess.has_global_allocator.get();
let has_global_allocator = *tcx.sess.has_global_allocator.get();
let root = self.lazy(&CrateRoot {
name: tcx.crate_name(LOCAL_CRATE),
extra_filename: tcx.sess.opts.cg.extra_filename.clone(),