diff --git a/internal_ws/ykcompile/src/arch/mod.rs b/internal_ws/ykcompile/src/arch/mod.rs index 9943184b8..b6529a5b7 100644 --- a/internal_ws/ykcompile/src/arch/mod.rs +++ b/internal_ws/ykcompile/src/arch/mod.rs @@ -4,4 +4,4 @@ compile_error!("Currently only linux x86_64 is supported."); #[cfg(all(target_arch = "x86_64", target_os = "linux"))] -pub(crate) mod x86_64; +pub(super) mod x86_64; diff --git a/internal_ws/ykcompile/src/arch/x86_64/store.rs b/internal_ws/ykcompile/src/arch/x86_64/store.rs index 9d915825c..ce0a234a5 100644 --- a/internal_ws/ykcompile/src/arch/x86_64/store.rs +++ b/internal_ws/ykcompile/src/arch/x86_64/store.rs @@ -7,7 +7,7 @@ use yktrace::sir::SIR; impl TraceCompiler { /// Store the value in `src_loc` into `dst_loc`. - pub(crate) fn store(&mut self, dst_ip: &IRPlace, src_ip: &IRPlace) { + pub(super) fn store(&mut self, dst_ip: &IRPlace, src_ip: &IRPlace) { let dst_loc = self.irplace_to_location(dst_ip); let src_loc = self.irplace_to_location(src_ip); debug_assert!(SIR.ty(&dst_ip.ty()).size() == SIR.ty(&src_ip.ty()).size()); @@ -15,7 +15,7 @@ impl TraceCompiler { } /// Stores src_loc into dst_loc. - pub(crate) fn store_raw(&mut self, dst_loc: &Location, src_loc: &Location, size: u64) { + pub(super) fn store_raw(&mut self, dst_loc: &Location, src_loc: &Location, size: u64) { // This is the one place in the compiler where we allow an explosion of cases over the // variants of `Location`. If elsewhere you find yourself matching over a pair of locations // you should try and re-work you code so it calls this. diff --git a/internal_ws/ykcompile/src/stack_builder.rs b/internal_ws/ykcompile/src/stack_builder.rs index 9e092fe0c..79d512ac7 100644 --- a/internal_ws/ykcompile/src/stack_builder.rs +++ b/internal_ws/ykcompile/src/stack_builder.rs @@ -11,7 +11,7 @@ use dynasmrt::{x64::Rq::RBP, Register}; use std::convert::{TryFrom, TryInto}; #[derive(Default, Debug)] -pub(crate) struct StackBuilder { +pub(super) struct StackBuilder { /// Keeps track of how many bytes have been allocated. stack_top: u64, } @@ -19,7 +19,7 @@ pub(crate) struct StackBuilder { impl StackBuilder { /// Allocate an object of given size and alignment on the stack, returning a `Location::Mem` /// describing the position of the allocation. The stack is assumed to grow down. - pub(crate) fn alloc(&mut self, size: u64, align: u64) -> Location { + pub(super) fn alloc(&mut self, size: u64, align: u64) -> Location { self.align(align); self.stack_top += size; Location::new_mem(RBP.code(), -i32::try_from(self.stack_top).unwrap()) @@ -32,7 +32,7 @@ impl StackBuilder { } /// Total allocated stack size in bytes. - pub(crate) fn size(&self) -> u32 { + pub(super) fn size(&self) -> u32 { self.stack_top.try_into().unwrap() } } diff --git a/internal_ws/ykpack/src/types.rs b/internal_ws/ykpack/src/types.rs index a945f7faa..f46f8fc28 100644 --- a/internal_ws/ykpack/src/types.rs +++ b/internal_ws/ykpack/src/types.rs @@ -230,7 +230,7 @@ pub struct TupleTy { } impl TupleTy { - pub fn is_unit(&self) -> bool { + fn is_unit(&self) -> bool { self.fields.offsets.is_empty() } } @@ -306,7 +306,7 @@ pub struct Body { pub blocks: Vec, pub flags: BodyFlags, pub local_decls: Vec, - pub num_args: usize, + pub(super) num_args: usize, pub layout: (usize, usize), pub offsets: Vec, } @@ -593,7 +593,7 @@ pub enum ConstantInt { impl ConstantInt { /// Returns an i64 value suitable for loading into a register. /// If the constant is signed, then it will be sign-extended. - pub fn i64_cast(&self) -> i64 { + fn i64_cast(&self) -> i64 { match self { ConstantInt::UnsignedInt(ui) => match ui { UnsignedInt::U8(i) => *i as i64, diff --git a/internal_ws/yksg/src/lib.rs b/internal_ws/yksg/src/lib.rs index 03bb9e48f..b165b8b5d 100644 --- a/internal_ws/yksg/src/lib.rs +++ b/internal_ws/yksg/src/lib.rs @@ -30,7 +30,7 @@ pub struct FrameInfo { /// Heap allocated memory for writing and reading locals of a stack frame. #[derive(Debug)] -pub struct LocalMem { +pub(crate) struct LocalMem { /// Pointer to allocated memory containing a frame's locals. locals: *mut u8, /// The offset of each Local into locals. @@ -198,6 +198,7 @@ pub struct StopgapInterpreter { impl StopgapInterpreter { /// Initialise the interpreter from a symbol name. + #[cfg(feature = "testing")] pub fn from_symbol(sym: String) -> Self { let frame = StopgapInterpreter::create_frame(&sym); StopgapInterpreter { diff --git a/internal_ws/yktrace/src/swt.rs b/internal_ws/yktrace/src/swt.rs index 6a87a8984..035ed800d 100644 --- a/internal_ws/yktrace/src/swt.rs +++ b/internal_ws/yktrace/src/swt.rs @@ -29,7 +29,7 @@ impl ThreadTracerImpl for SWTThreadTracer { } } -pub(crate) fn start_tracing() -> ThreadTracer { +pub(super) fn start_tracing() -> ThreadTracer { TRACE_BUF.with(|trace_buf| { assert!(trace_buf.is_empty()); }); diff --git a/tests/src/helpers.rs b/tests/src/helpers.rs index 129f6e8f4..26fcc561b 100644 --- a/tests/src/helpers.rs +++ b/tests/src/helpers.rs @@ -5,14 +5,14 @@ use regex::Regex; use ykshim_client::{sir_body_ret_ty, TirTrace, TypeId}; extern "C" { - pub fn add6(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) -> u64; + pub(super) fn add6(a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) -> u64; } extern "C" { - pub fn add_some(a: u64, b: u64, c: u64, d: u64, e: u64) -> u64; + pub(super) fn add_some(a: u64, b: u64, c: u64, d: u64, e: u64) -> u64; } /// Fuzzy matches the textual TIR for the trace `tt` with the pattern `ptn`. -pub fn assert_tir(ptn: &str, tt: &TirTrace) { +pub(super) fn assert_tir(ptn: &str, tt: &TirTrace) { let ptn_re = Regex::new(r"%.+?\b").unwrap(); // Names are words prefixed with `%`. let text_re = Regex::new(r"\$?.+?\b").unwrap(); // Any word optionally prefixed with `$`. let matcher = FMBuilder::new(ptn) @@ -28,7 +28,7 @@ pub fn assert_tir(ptn: &str, tt: &TirTrace) { } } -pub fn neg_assert_tir(ptn: &str, tt: &TirTrace) { +pub(super) fn neg_assert_tir(ptn: &str, tt: &TirTrace) { let ptn_re = Regex::new(r"%.+?\b").unwrap(); // Names are words prefixed with `%`. let text_re = Regex::new(r"\$?.+?\b").unwrap(); // Any word optionally prefixed with `$`. let matcher = FMBuilder::new(ptn) @@ -46,17 +46,17 @@ pub fn neg_assert_tir(ptn: &str, tt: &TirTrace) { /// Types IDs that we need for tests. #[repr(C)] -pub struct TestTypes { - pub t_u8: TypeId, - pub t_i64: TypeId, - pub t_string: TypeId, - pub t_tiny_struct: TypeId, - pub t_tiny_array: TypeId, - pub t_tiny_tuple: TypeId, +pub(super) struct TestTypes { + pub(super) t_u8: TypeId, + pub(super) t_i64: TypeId, + pub(super) t_string: TypeId, + pub(super) t_tiny_struct: TypeId, + pub(super) t_tiny_array: TypeId, + pub(super) t_tiny_tuple: TypeId, } impl TestTypes { - pub fn new() -> TestTypes { + pub(super) fn new() -> TestTypes { // We can't know the type ID of any given type, so this works by defining unmangled // functions with known return types and then looking them up by name in the SIR. #[no_mangle] diff --git a/tests/src/tracing.rs b/tests/src/tracing.rs index 3a5961586..ddd56cb2a 100644 --- a/tests/src/tracing.rs +++ b/tests/src/tracing.rs @@ -55,7 +55,7 @@ fn trace_twice() { /// Test that tracing in different threads works. #[test] -pub(crate) fn trace_concurrent() { +fn trace_concurrent() { #[cfg(tracermode = "hw")] let kind = TracingKind::HardwareTracing; #[cfg(tracermode = "sw")] diff --git a/ykrt/src/lib.rs b/ykrt/src/lib.rs index f2cefd30d..fa86bc068 100644 --- a/ykrt/src/lib.rs +++ b/ykrt/src/lib.rs @@ -3,7 +3,7 @@ #![cfg_attr(test, feature(test))] mod location; -pub mod mt; +pub(crate) mod mt; pub use self::location::Location; pub use self::mt::{MTBuilder, MT}; diff --git a/ykrt/src/location.rs b/ykrt/src/location.rs index 1a55851d8..5ac15f005 100644 --- a/ykrt/src/location.rs +++ b/ykrt/src/location.rs @@ -109,14 +109,14 @@ impl Location { } /// Return this Location's internal state. - pub(crate) fn load(&self, order: Ordering) -> State { + pub(super) fn load(&self, order: Ordering) -> State { State { x: self.state.load(order), marker: PhantomData, } } - pub(crate) fn compare_exchange_weak( + pub(super) fn compare_exchange_weak( &self, current: State, new: State, @@ -140,7 +140,7 @@ impl Location { /// Locks this `State` with `Acquire` ordering. If the location was in, or moves to, the /// Counting state this will return `Err`. - pub(crate) fn lock(&self) -> Result, ()> { + pub(super) fn lock(&self) -> Result, ()> { { let ls = self.load(Ordering::Relaxed); if ls.is_counting() { @@ -227,7 +227,7 @@ impl Location { } /// Unlocks this `State` with `Release` ordering. - pub(crate) fn unlock(&self) { + pub(super) fn unlock(&self) { let ls = self.load(Ordering::Relaxed); debug_assert!(ls.is_locked()); debug_assert!(!ls.is_counting()); @@ -271,7 +271,7 @@ impl Location { } /// Try obtaining the lock, returning the new `State` if successful. - pub(crate) fn try_lock(&self) -> Result, ()> { + pub(super) fn try_lock(&self) -> Result, ()> { let mut ls = self.load(Ordering::Relaxed); loop { if ls.is_locked() { @@ -300,20 +300,20 @@ impl Drop for Location { } #[cfg(target_pointer_width = "64")] -pub(crate) const STATE_TAG: usize = 0b111; // All of the other tag data must fit in this. +const STATE_TAG: usize = 0b111; // All of the other tag data must fit in this. #[cfg(target_pointer_width = "64")] -pub(crate) const STATE_NUM_BITS: usize = 3; +const STATE_NUM_BITS: usize = 3; -pub(crate) const STATE_IS_LOCKED: usize = 0b001; -pub(crate) const STATE_IS_PARKED: usize = 0b010; -pub(crate) const STATE_IS_COUNTING: usize = 0b100; +const STATE_IS_LOCKED: usize = 0b001; +const STATE_IS_PARKED: usize = 0b010; +const STATE_IS_COUNTING: usize = 0b100; -pub(crate) const TOKEN_NORMAL: UnparkToken = UnparkToken(0); -pub(crate) const TOKEN_HANDOFF: UnparkToken = UnparkToken(1); +const TOKEN_NORMAL: UnparkToken = UnparkToken(0); +const TOKEN_HANDOFF: UnparkToken = UnparkToken(1); #[derive(PartialEq, Eq, Debug)] -pub(crate) struct State { - pub(crate) x: usize, +pub(super) struct State { + x: usize, marker: PhantomData, } @@ -327,7 +327,7 @@ impl Clone for State { impl State { /// Return a new `State` in the counting phase with a count 0. - pub(crate) fn new() -> Self { + pub(super) fn new() -> Self { State { x: STATE_IS_COUNTING, marker: PhantomData, @@ -341,21 +341,21 @@ impl State { } } - pub(crate) fn is_locked(&self) -> bool { + pub(super) fn is_locked(&self) -> bool { self.x & STATE_IS_LOCKED != 0 } - pub(crate) fn is_parked(&self) -> bool { + pub(super) fn is_parked(&self) -> bool { self.x & STATE_IS_PARKED != 0 } /// Is the Location in the counting or a non-counting state? - pub(crate) fn is_counting(&self) -> bool { + pub(super) fn is_counting(&self) -> bool { self.x & STATE_IS_COUNTING != 0 } /// If, and only if, the Location is in the counting state, return the current count. - pub(crate) fn count(&self) -> HotThreshold { + pub(super) fn count(&self) -> HotThreshold { debug_assert!(self.is_counting()); debug_assert!(!self.is_locked()); u32::try_from(self.x >> STATE_NUM_BITS).unwrap() @@ -364,14 +364,14 @@ impl State { /// If this `State` is not counting, return its `HotLocation`. It is undefined behaviour to /// call this function if this `State` is in the counting phase and/or if this `State` is not /// locked. - pub(crate) unsafe fn hot_location(&self) -> &mut HotLocation { + pub(super) unsafe fn hot_location(&self) -> &mut HotLocation { debug_assert!(!self.is_counting()); //debug_assert!(self.is_locked()); &mut *((self.x & !STATE_TAG) as *mut _) } /// Return a version of this `State` with the locked bit set. - pub(crate) fn with_lock(&self) -> State { + pub(super) fn with_lock(&self) -> State { State { x: self.x | STATE_IS_LOCKED, marker: PhantomData, @@ -379,7 +379,7 @@ impl State { } /// Return a version of this `State` with the locked bit unset. - pub(crate) fn with_unlock(&self) -> State { + fn with_unlock(&self) -> State { State { x: self.x & !STATE_IS_LOCKED, marker: PhantomData, @@ -387,7 +387,7 @@ impl State { } /// Return a version of this `State` with the parked bit set. - pub(crate) fn with_parked(&self) -> State { + fn with_parked(&self) -> State { State { x: self.x | STATE_IS_PARKED, marker: PhantomData, @@ -395,7 +395,7 @@ impl State { } /// Return a version of this `State` with the parked bit unset. - pub(crate) fn with_unparked(&self) -> State { + fn with_unparked(&self) -> State { State { x: self.x & !STATE_IS_PARKED, marker: PhantomData, @@ -404,7 +404,7 @@ impl State { /// Return a version of this `State` with the count set to `count`. It is undefined behaviour /// to call this function if this `State` is not in the counting phase. - pub(crate) fn with_count(&self, count: HotThreshold) -> Self { + pub(super) fn with_count(&self, count: HotThreshold) -> Self { debug_assert!(self.is_counting()); debug_assert_eq!(count << STATE_NUM_BITS >> STATE_NUM_BITS, count); State { @@ -415,7 +415,7 @@ impl State { /// Set this `State`'s `HotLocation`. It is undefined behaviour for this `State` to already /// have a `HotLocation`. - pub(crate) fn with_hotlocation(&self, hl_ptr: *mut HotLocation) -> Self { + pub(super) fn with_hotlocation(&self, hl_ptr: *mut HotLocation) -> Self { debug_assert!(self.is_counting()); let hl_ptr = hl_ptr as usize; debug_assert_eq!(hl_ptr & !STATE_TAG, hl_ptr); @@ -428,11 +428,11 @@ impl State { /// An opaque struct used by `MTThreadInner` to help identify if a thread that started a trace is /// still active. -pub(crate) struct ThreadIdInner; +pub(super) struct ThreadIdInner; /// A `Location`'s non-counting states. #[derive(EnumDiscriminants)] -pub(crate) enum HotLocation { +pub(super) enum HotLocation { Compiled(Box>), Compiling(Arc>>>>), DontTrace, diff --git a/ykshim_client/src/lib.rs b/ykshim_client/src/lib.rs index 06270f778..3ad95cb45 100644 --- a/ykshim_client/src/lib.rs +++ b/ykshim_client/src/lib.rs @@ -32,10 +32,12 @@ pub type RawStopgapInterpreter = c_void; pub type LocalIndex = u32; #[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)] #[repr(C)] +#[cfg(feature = "testing")] pub struct Local(pub LocalIndex); #[derive(Debug, Clone, Copy)] #[repr(C)] -pub struct TyIndex(pub u32); +#[cfg(feature = "testing")] +pub(crate) struct TyIndex(pub(crate) u32); extern "C" { fn __ykshim_start_tracing(tracing_kind: u8) -> *mut RawThreadTracer; @@ -149,6 +151,7 @@ impl CompiledTrace { } /// Execute the trace with the given interpreter context. + #[cfg(feature = "testing")] pub unsafe fn execute(&self, ctx: &mut I) -> *mut RawStopgapInterpreter { let f = mem::transmute::<_, fn(&mut I) -> *mut RawStopgapInterpreter>(self.ptr()); #[cfg(not(debug_assertions))] diff --git a/ykshim_client/src/test_api.rs b/ykshim_client/src/test_api.rs index 451256fad..ee5bd9e99 100644 --- a/ykshim_client/src/test_api.rs +++ b/ykshim_client/src/test_api.rs @@ -14,12 +14,13 @@ type RawTraceCompiler = c_void; // Keep these types in-sync with the internal workspace. #[derive(Debug, Clone, Copy)] #[repr(C)] -pub struct CguHash(u64); +struct CguHash(u64); #[derive(Debug, Copy, Clone)] #[repr(C)] +#[cfg(feature = "testing")] pub struct TypeId { - pub cgu: CguHash, - pub idx: TyIndex, + cgu: CguHash, + idx: TyIndex, } extern "C" { @@ -49,6 +50,7 @@ extern "C" { } #[derive(Debug)] +#[cfg(feature = "testing")] pub struct TirTrace(*mut RawTirTrace); impl TirTrace { @@ -91,8 +93,8 @@ pub fn sir_body_ret_ty(sym: &str) -> TypeId { } pub struct LocalDecl { - pub ty: TypeId, - pub referenced: bool, + ty: TypeId, + referenced: bool, } impl LocalDecl {