Skip to content

Even more thread-safety changes #49558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e5a602e
Add OneThread which only allows its inner value to be used in one thread
Zoxc Apr 1, 2018
60d0cbe
Add insert_same extension to HashMap
Zoxc Apr 1, 2018
26f16e8
Add a Once type for values which are only written once
Zoxc Apr 1, 2018
49a2b80
Make sure the lint store is only used on one thread
Zoxc Apr 1, 2018
472b416
Querify all_traits
Zoxc Apr 1, 2018
cf3b790
Make recursion_limit and type_length_limit thread-safe
Zoxc Apr 1, 2018
05c4ea4
Remove derive_macros
Zoxc Apr 1, 2018
7aa7198
Make PerfStats thread-safe and remove unused fields
Zoxc Apr 1, 2018
27adb31
Combine Session.entry_fn and Session.entry_type and make them thread-…
Zoxc Apr 1, 2018
e82b6c4
Make Session.plugin_registrar_fn and Session.derive_registrar_fn thre…
Zoxc Apr 1, 2018
753cd9a
Make sure Session.incr_comp_session is only used on one thread
Zoxc Apr 1, 2018
a23e90a
Remove Cell from const_eval_stack_frame_limit and const_eval_step_limit
Zoxc Apr 1, 2018
a46f059
Disable optimization fuel when using multiple threads
Zoxc Apr 1, 2018
904e2b6
Make Session::features_untracked thread-safe
Zoxc Apr 1, 2018
b0c7bda
Make Session.code_stats thread-safe
Zoxc Apr 1, 2018
8380539
Make sure Session.next_node_id is only used on one thread
Zoxc Apr 1, 2018
271c8d3
Make Session.crate_disambiguator thread-safe
Zoxc Apr 1, 2018
73b26f7
Make sure Session.imported_macro_spans is only used on one thread
Zoxc Apr 1, 2018
7d33d1a
Make Session.has_global_allocator thread-safe
Zoxc Apr 1, 2018
0e51d48
Make sure Session.plugin_llvm_passes is only used on one thread
Zoxc Apr 1, 2018
046af1c
Make sure Session.plugin_attributes is only used on one thread
Zoxc Apr 1, 2018
cbf8ad4
Make Session.crate_types thread-safe
Zoxc Apr 1, 2018
66488a5
Make Session.dependency_formats thread-safe
Zoxc Apr 1, 2018
dacf9ba
Make Session.injected_allocator and Session.allocator_kind thread-safe
Zoxc Apr 1, 2018
006f9b2
Make Session.injected_panic_runtime thread-safe
Zoxc Apr 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make Session.injected_allocator and Session.allocator_kind thread-safe
  • Loading branch information
Zoxc committed Apr 10, 2018
commit dacf9ba00fb8d6b7202a1ed5f06febe3fd2cf9b4
8 changes: 4 additions & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ pub struct Session {
/// 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 injected_allocator: Cell<Option<CrateNum>>,
pub allocator_kind: Cell<Option<AllocatorKind>>,
pub injected_allocator: Once<Option<CrateNum>>,
pub allocator_kind: Once<Option<AllocatorKind>>,
pub injected_panic_runtime: Cell<Option<CrateNum>>,

/// Map from imported macro spans (which consist of
Expand Down Expand Up @@ -1105,8 +1105,8 @@ pub fn build_session_(
const_eval_stack_frame_limit: 100,
const_eval_step_limit: 1_000_000,
next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
injected_allocator: Cell::new(None),
allocator_kind: Cell::new(None),
injected_allocator: Once::new(),
allocator_kind: Once::new(),
injected_panic_runtime: Cell::new(None),
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ impl<'a> CrateLoader<'a> {
needs_allocator = needs_allocator || data.needs_allocator(self.sess);
});
if !needs_allocator {
self.sess.injected_allocator.set(None);
self.sess.allocator_kind.set(None);
return
}

Expand All @@ -842,6 +844,8 @@ impl<'a> CrateLoader<'a> {
}
}
if !need_lib_alloc && !need_exe_alloc {
self.sess.injected_allocator.set(None);
self.sess.allocator_kind.set(None);
return
}

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

Expand Down Expand Up @@ -922,6 +927,9 @@ impl<'a> CrateLoader<'a> {
};

let allocation_crate_data = exe_allocation_crate_data.or_else(|| {
// No allocator was injected
self.sess.injected_allocator.set(None);

if attr::contains_name(&krate.attrs, "default_lib_allocator") {
// Prefer self as the allocator if there's a collision
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
codegen_units.len());

// Translate an allocator shim, if any
let allocator_module = if let Some(kind) = tcx.sess.allocator_kind.get() {
let allocator_module = if let Some(kind) = *tcx.sess.allocator_kind.get() {
unsafe {
let llmod_id = "allocator";
let (llcx, llmod) =
Expand Down