Skip to content

Commit

Permalink
Make Session.injected_panic_runtime thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Apr 10, 2018
1 parent dacf9ba commit 006f9b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
//
// Things like allocators and panic runtimes may not have been activated
// quite yet, so do so here.
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
activate_injected_allocator(sess, &mut ret);

Expand Down Expand Up @@ -302,7 +302,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
// Our allocator/panic runtime may not have been linked above if it wasn't
// explicitly linked, which is the case for any injected dependency. Handle
// that here and activate them.
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
activate_injected_allocator(sess, &mut ret);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct Session {
/// injected.
pub injected_allocator: Once<Option<CrateNum>>,
pub allocator_kind: Once<Option<AllocatorKind>>,
pub injected_panic_runtime: Cell<Option<CrateNum>>,
pub injected_panic_runtime: Once<Option<CrateNum>>,

/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
Expand Down Expand Up @@ -1107,7 +1107,7 @@ pub fn build_session_(
next_node_id: OneThread::new(Cell::new(NodeId::new(1))),
injected_allocator: Once::new(),
allocator_kind: Once::new(),
injected_panic_runtime: Cell::new(None),
injected_panic_runtime: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(HashMap::new())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
ignored_attr_names: ich::compute_ignored_attr_names(),
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ impl<'a> CrateLoader<'a> {
});
if !any_non_rlib {
info!("panic runtime injection skipped, only generating rlib");
self.sess.injected_panic_runtime.set(None);
return
}

Expand Down Expand Up @@ -646,6 +647,7 @@ impl<'a> CrateLoader<'a> {
// we just don't need one at all, then we're done here and there's
// nothing else to do.
if !needs_panic_runtime || runtime_found {
self.sess.injected_panic_runtime.set(None);
return
}

Expand Down

0 comments on commit 006f9b2

Please sign in to comment.