about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Kadel <richkadel@google.com>2020-11-11 20:01:10 -0800
committerRich Kadel <richkadel@google.com>2020-11-11 20:36:41 -0800
commiteb9f2bb3b0a3f7e712efa28743acf6134d49de5c (patch)
tree43ef7d2aa49caaedd6cb0ada913ed8d5e7e169ec
parentbd0eb07af2deaff2c9f1e7553ea97341787779cd (diff)
downloadrust-eb9f2bb3b0a3f7e712efa28743acf6134d49de5c.tar.gz
rust-eb9f2bb3b0a3f7e712efa28743acf6134d49de5c.zip
Overcome Sync issues with non-parallel compiler
Per Mark's recommendation at:
https://github.com/rust-lang/rust/pull/78963#issuecomment-725790071
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs12
-rw-r--r--compiler/rustc_mir/src/transform/coverage/tests.rs19
2 files changed, 22 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 0042b4a3a42..d4f299b3f37 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -611,6 +611,18 @@ pub struct TyS<'tcx> {
     outer_exclusive_binder: ty::DebruijnIndex,
 }
 
+impl<'tcx> TyS<'tcx> {
+    /// A constructor used only for internal testing.
+    #[allow(rustc::usage_of_ty_tykind)]
+    pub fn make_for_test(
+        kind: TyKind<'tcx>,
+        flags: TypeFlags,
+        outer_exclusive_binder: ty::DebruijnIndex,
+    ) -> TyS<'tcx> {
+        TyS { kind, flags, outer_exclusive_binder }
+    }
+}
+
 // `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
 #[cfg(target_arch = "x86_64")]
 static_assert_size!(TyS<'_>, 32);
diff --git a/compiler/rustc_mir/src/transform/coverage/tests.rs b/compiler/rustc_mir/src/transform/coverage/tests.rs
index 2231fe6427f..3e305a58c6b 100644
--- a/compiler/rustc_mir/src/transform/coverage/tests.rs
+++ b/compiler/rustc_mir/src/transform/coverage/tests.rs
@@ -7,18 +7,19 @@ use rustc_data_structures::graph::WithNumNodes;
 use rustc_data_structures::graph::WithSuccessors;
 use rustc_index::vec::{Idx, IndexVec};
 use rustc_middle::mir::*;
-use rustc_middle::ty::{self, TyS};
+use rustc_middle::ty::{self, DebruijnIndex, TyS, TypeFlags};
 use rustc_span::DUMMY_SP;
 
-use std::lazy::SyncOnceCell;
-
-fn dummy_ty<'tcx>() -> &'static TyS<'tcx> {
-    static DUMMY_TYS: SyncOnceCell<TyS<'_>> = SyncOnceCell::new();
+fn dummy_ty() -> &'static TyS<'static> {
+    thread_local! {
+        static DUMMY_TYS: &'static TyS<'static> = Box::leak(box TyS::make_for_test(
+            ty::Bool,
+            TypeFlags::empty(),
+            DebruijnIndex::from_usize(0),
+        ));
+    }
 
-    &DUMMY_TYS.get_or_init(|| {
-        let fake_type_bytes = vec![0 as u8; std::mem::size_of::<TyS<'_>>()];
-        unsafe { std::ptr::read_unaligned::<TyS<'_>>(fake_type_bytes.as_ptr() as *const TyS<'_>) }
-    })
+    &DUMMY_TYS.with(|tys| *tys)
 }
 
 struct MockBlocks<'tcx> {