Skip to content

Commit ecbbd58

Browse files
committed
lib.miri.rs appraoch
1 parent 75816e0 commit ecbbd58

File tree

21 files changed

+573
-611
lines changed

21 files changed

+573
-611
lines changed

Diff for: library/alloc/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ compiler-builtins-c = ["compiler_builtins/c"]
3636
compiler-builtins-no-asm = ["compiler_builtins/no-asm"]
3737
compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"]
3838
compiler-builtins-weak-intrinsics = ["compiler_builtins/weak-intrinsics"]
39-
# Empty the crate so Miri can run tests
40-
miri-test = ["core/miri-test"]
4139
# Make panics and failed asserts immediately abort without formatting any message
4240
panic_immediate_abort = []

Diff for: library/alloc/src/lib.miri.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
extern crate alloc as realalloc;
3+
pub use realalloc::*;

Diff for: library/alloc/src/lib.rs

+61-26
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
not(test),
7373
not(any(test, bootstrap)),
7474
any(not(feature = "miri-test-libstd"), test, doctest),
75-
all(feature = "miri-test", not(any(test, doctest))),
76-
not(all(feature = "miri-test", not(any(test, doctest)))),
7775
no_global_oom_handling,
7876
not(no_global_oom_handling),
7977
not(no_rc),
@@ -219,28 +217,6 @@
219217
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
220218
#![feature(intra_doc_pointers)]
221219

222-
// We want to be able to `cargo miri test` this crate, but that's tricky.
223-
// We use the `miri-test` feature to indicate that we're running `cargo miri test`, and
224-
// with that feature we turn this crate into a re-export of the sysroot crate. We only do this when
225-
// building the crate that will become a dependency, not when doing the actual (doc)test build.
226-
// See `core/src/lib.rs` for more information.
227-
#[cfg(all(feature = "miri-test", not(any(test, doctest))))]
228-
extern crate alloc as realalloc;
229-
#[cfg(all(feature = "miri-test", not(any(test, doctest))))]
230-
#[stable(feature = "miri_test", since = "1.0.0")]
231-
pub use realalloc::*;
232-
233-
// Otherwise, we build the crate as usual. Everything that follows should have
234-
// `#[cfg(not(all(feature = "miri-test", not(any(test, doctest)))))]`. To avoid having to repeat the
235-
// same `cfg` so many times, we `include!("lib_.rs")` with the main crate contents, and `cfg` the
236-
// `include!`. However, some macro-related things can't be behind the `include!` so we have to
237-
// repeat the `cfg` for them.
238-
239-
// Module with internal macros used by other modules (needs to be included before other modules).
240-
#[cfg(not(all(feature = "miri-test", not(any(test, doctest)))))]
241-
#[macro_use]
242-
mod macros;
243-
244220
// Allow testing this library
245221
#[cfg(test)]
246222
#[macro_use]
@@ -250,5 +226,64 @@ extern crate test;
250226
#[cfg(test)]
251227
mod testing;
252228

253-
#[cfg(not(all(feature = "miri-test", not(any(test, doctest)))))]
254-
include!("lib_.rs");
229+
// Module with internal macros used by other modules (needs to be included before other modules).
230+
#[macro_use]
231+
mod macros;
232+
233+
mod raw_vec;
234+
235+
// Heaps provided for low-level allocation strategies
236+
237+
pub mod alloc;
238+
239+
// Primitive types using the heaps above
240+
241+
// Need to conditionally define the mod from `boxed.rs` to avoid
242+
// duplicating the lang-items when building in test cfg; but also need
243+
// to allow code to have `use boxed::Box;` declarations.
244+
#[cfg(not(test))]
245+
pub mod boxed;
246+
#[cfg(test)]
247+
mod boxed {
248+
pub use std::boxed::Box;
249+
}
250+
pub mod borrow;
251+
pub mod collections;
252+
#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
253+
pub mod ffi;
254+
pub mod fmt;
255+
#[cfg(not(no_rc))]
256+
pub mod rc;
257+
pub mod slice;
258+
pub mod str;
259+
pub mod string;
260+
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
261+
pub mod sync;
262+
#[cfg(all(not(no_global_oom_handling), not(no_rc), not(no_sync)))]
263+
pub mod task;
264+
#[cfg(test)]
265+
mod tests;
266+
pub mod vec;
267+
268+
#[doc(hidden)]
269+
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
270+
pub mod __export {
271+
pub use core::format_args;
272+
}
273+
274+
#[cfg(test)]
275+
#[allow(dead_code)] // Not used in all configurations
276+
pub(crate) mod test_helpers {
277+
/// Copied from `std::test_helpers::test_rng`, since these tests rely on the
278+
/// seed not being the same for every RNG invocation too.
279+
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
280+
use std::hash::{BuildHasher, Hash, Hasher};
281+
let mut hasher = std::hash::RandomState::new().build_hasher();
282+
std::panic::Location::caller().hash(&mut hasher);
283+
let hc64 = hasher.finish();
284+
let seed_vec =
285+
hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<crate::vec::Vec<u8>>();
286+
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
287+
rand::SeedableRng::from_seed(seed)
288+
}
289+
}

Diff for: library/alloc/src/lib_.rs

-59
This file was deleted.

Diff for: library/core/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ panic_immediate_abort = []
3434
# Make `RefCell` store additional debugging information, which is printed out when
3535
# a borrow error occurs
3636
debug_refcell = []
37-
# Empty the crate so Miri can run tests
38-
miri-test = []

Diff for: library/core/src/lib.miri.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![no_std]
2+
extern crate core as realcore;
3+
pub use realcore::*;

0 commit comments

Comments
 (0)