]> git.lizzy.rs Git - rust.git/commitdiff
Make Session.plugin_registrar_fn and Session.derive_registrar_fn thread-safe
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sun, 1 Apr 2018 06:18:10 +0000 (08:18 +0200)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Tue, 10 Apr 2018 12:40:25 +0000 (14:40 +0200)
src/librustc/session/mod.rs
src/librustc_trans/back/symbol_export.rs
src/librustc_trans_utils/symbol_names.rs

index 97b73fac1a42f7ce2a7c550506c2ace314d0e2c9..8d3215e69cd28b155884a612c783d27fc562bdde 100644 (file)
@@ -71,8 +71,8 @@ pub struct Session {
     pub parse_sess: ParseSess,
     /// For a library crate, this is always none
     pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
-    pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
-    pub derive_registrar_fn: Cell<Option<ast::NodeId>>,
+    pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
+    pub derive_registrar_fn: Once<Option<ast::NodeId>>,
     pub default_sysroot: Option<PathBuf>,
     /// The name of the root source file of the crate, in the local file system.
     /// `None` means that there is no source file.
@@ -1094,8 +1094,8 @@ pub fn build_session_(
         parse_sess: p_s,
         // For a library crate, this is always none
         entry_fn: Once::new(),
-        plugin_registrar_fn: Cell::new(None),
-        derive_registrar_fn: Cell::new(None),
+        plugin_registrar_fn: Once::new(),
+        derive_registrar_fn: Once::new(),
         default_sysroot,
         local_crate_source_file,
         working_dir,
index acd2a7657307c4db2d1a6d2d69c1a53336bcb06c..965a34eccb862d1fdbe2879b00f2bd752ce26697 100644 (file)
@@ -157,12 +157,12 @@ fn reachable_non_generics_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         })
         .collect();
 
-    if let Some(id) = tcx.sess.derive_registrar_fn.get() {
+    if let Some(id) = *tcx.sess.derive_registrar_fn.get() {
         let def_id = tcx.hir.local_def_id(id);
         reachable_non_generics.insert(def_id, SymbolExportLevel::C);
     }
 
-    if let Some(id) = tcx.sess.plugin_registrar_fn.get() {
+    if let Some(id) = *tcx.sess.plugin_registrar_fn.get() {
         let def_id = tcx.hir.local_def_id(id);
         reachable_non_generics.insert(def_id, SymbolExportLevel::C);
     }
index af174f7ce8516f2eef0b536ce3313951a73ee4f4..f3b7326b21071793b878b3d854b134a8aa31cdf2 100644 (file)
@@ -244,11 +244,11 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
     let node_id = tcx.hir.as_local_node_id(def_id);
 
     if let Some(id) = node_id {
-        if tcx.sess.plugin_registrar_fn.get() == Some(id) {
+        if *tcx.sess.plugin_registrar_fn.get() == Some(id) {
             let disambiguator = tcx.sess.local_crate_disambiguator();
             return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
         }
-        if tcx.sess.derive_registrar_fn.get() == Some(id) {
+        if *tcx.sess.derive_registrar_fn.get() == Some(id) {
             let disambiguator = tcx.sess.local_crate_disambiguator();
             return tcx.sess.generate_derive_registrar_symbol(disambiguator);
         }