Skip to content

Commit eb9f2bb

Browse files
committed
Overcome Sync issues with non-parallel compiler
Per Mark's recommendation at: #78963 (comment)
1 parent bd0eb07 commit eb9f2bb

File tree

2 files changed

+22
-9
lines changed
  • compiler

2 files changed

+22
-9
lines changed

Diff for: compiler/rustc_middle/src/ty/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,18 @@ pub struct TyS<'tcx> {
611611
outer_exclusive_binder: ty::DebruijnIndex,
612612
}
613613

614+
impl<'tcx> TyS<'tcx> {
615+
/// A constructor used only for internal testing.
616+
#[allow(rustc::usage_of_ty_tykind)]
617+
pub fn make_for_test(
618+
kind: TyKind<'tcx>,
619+
flags: TypeFlags,
620+
outer_exclusive_binder: ty::DebruijnIndex,
621+
) -> TyS<'tcx> {
622+
TyS { kind, flags, outer_exclusive_binder }
623+
}
624+
}
625+
614626
// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
615627
#[cfg(target_arch = "x86_64")]
616628
static_assert_size!(TyS<'_>, 32);

Diff for: compiler/rustc_mir/src/transform/coverage/tests.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ use rustc_data_structures::graph::WithNumNodes;
77
use rustc_data_structures::graph::WithSuccessors;
88
use rustc_index::vec::{Idx, IndexVec};
99
use rustc_middle::mir::*;
10-
use rustc_middle::ty::{self, TyS};
10+
use rustc_middle::ty::{self, DebruijnIndex, TyS, TypeFlags};
1111
use rustc_span::DUMMY_SP;
1212

13-
use std::lazy::SyncOnceCell;
14-
15-
fn dummy_ty<'tcx>() -> &'static TyS<'tcx> {
16-
static DUMMY_TYS: SyncOnceCell<TyS<'_>> = SyncOnceCell::new();
13+
fn dummy_ty() -> &'static TyS<'static> {
14+
thread_local! {
15+
static DUMMY_TYS: &'static TyS<'static> = Box::leak(box TyS::make_for_test(
16+
ty::Bool,
17+
TypeFlags::empty(),
18+
DebruijnIndex::from_usize(0),
19+
));
20+
}
1721

18-
&DUMMY_TYS.get_or_init(|| {
19-
let fake_type_bytes = vec![0 as u8; std::mem::size_of::<TyS<'_>>()];
20-
unsafe { std::ptr::read_unaligned::<TyS<'_>>(fake_type_bytes.as_ptr() as *const TyS<'_>) }
21-
})
22+
&DUMMY_TYS.with(|tys| *tys)
2223
}
2324

2425
struct MockBlocks<'tcx> {

0 commit comments

Comments
 (0)