Skip to content

Commit

Permalink
Fix style check for Rust 1.80 (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
qinsoon committed Jul 26, 2024
1 parent 9a49d6a commit f9b85bc
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 58 deletions.
5 changes: 0 additions & 5 deletions .github/scripts/ci-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ export RUSTFLAGS="-D warnings -A unknown-lints"
cargo fmt -- --check
cargo fmt --manifest-path=macros/Cargo.toml -- --check

# All versions of Clippy randomly crash on Darwin. We disable Clippy tests for Darwin for now.
if [[ $(uname) == "Darwin" ]]; then
exit 0
fi

# Workaround the clippy issue on Rust 1.72: https://github.com/mmtk/mmtk-core/issues/929.
# If we are not testing with Rust 1.72, or there is no problem running the following clippy checks, we can remove this export.
CLIPPY_VERSION=$(cargo clippy --version)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/api-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
- run: cargo +nightly --version

- name: Install cargo-public-api
run: cargo install cargo-public-api
run: cargo +nightly install cargo-public-api
- name: API Diff
run: cargo public-api diff origin/${GITHUB_BASE_REF}..${{ github.event.pull_request.head.sha }} --deny=all
run: cargo +nightly public-api diff origin/${GITHUB_BASE_REF}..${{ github.event.pull_request.head.sha }} --deny=all

check-api-migration-update:
needs: check-public-api-changes
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pfm = { version = "0.1.1", optional = true }
portable-atomic = "1.4.3"
probe = "0.5"
regex = "1.7.0"
rustversion = "1.0"
spin = "0.9.5"
static_assertions = "1.1.0"
strum = "0.26.2"
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ extern crate strum_macros;
extern crate lazy_static;
#[macro_use]
extern crate log;
#[cfg(target = "x86_64-unknown-linux-gnu")]
extern crate atomic;
extern crate atomic_traits;
extern crate crossbeam;
extern crate num_cpus;
Expand Down
1 change: 1 addition & 0 deletions src/memory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ pub fn find_object_from_internal_pointer<VM: VMBinding>(
/// - only MMTk can allocate into, or
/// - only MMTk's delegated memory allocator (such as a malloc implementation) can allocate into
/// for allocation requests from MMTk.
///
/// Return false otherwise. This function never panics.
///
/// Particularly, if this function returns true, `object` cannot be an object allocated by the VM
Expand Down
10 changes: 5 additions & 5 deletions src/mmtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ impl<VM: VMBinding> MMTK<VM> {
/// requires the users to do some preparation before calling it.
///
/// - **Multi-threading**: If `fork()` is called when the process has multiple threads, it
/// will only duplicate the current thread into the child process, and the child process can
/// only call async-signal-safe functions, notably `exec()`. For VMs that that use
/// multi-process concurrency, it is imperative that when calling `fork()`, only one thread may
/// exist in the process.
/// will only duplicate the current thread into the child process, and the child process can
/// only call async-signal-safe functions, notably `exec()`. For VMs that that use
/// multi-process concurrency, it is imperative that when calling `fork()`, only one thread may
/// exist in the process.
///
/// - **File descriptors**: The child process inherits copies of the parent's set of open
/// file descriptors. This may or may not be desired depending on use cases.
/// file descriptors. This may or may not be desired depending on use cases.
///
/// This function helps VMs that use `fork()` for multi-process concurrency. It instructs all
/// GC threads to save their contexts and return from their entry-point functions. Currently,
Expand Down
4 changes: 2 additions & 2 deletions src/util/heap/blockpageresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ impl<B: Region> BlockPool<B> {

/// Iterate all the blocks in the BlockQueue
pub fn iterate_blocks(&self, f: &mut impl FnMut(B)) {
for array in &*self.head_global_freed_blocks.read() {
array.iterate_blocks(f)
if let Some(array) = &*self.head_global_freed_blocks.read() {
array.iterate_blocks(f);
}
for array in &*self.global_freed_blocks.read() {
array.iterate_blocks(f);
Expand Down
2 changes: 1 addition & 1 deletion src/util/heap/monotonepageresource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<VM: VMBinding> PageResource<VM> for MonotonePageResource<VM> {
sync.cursor, sync.sentinel, sync.current_chunk
);

if cfg!(debug = "true") {
if cfg!(debug_assertions) {
/*
* Cursor should always be zero, or somewhere in the current chunk. If we have just
* allocated exactly enough pages to exhaust the current chunk, then cursor can point
Expand Down
26 changes: 2 additions & 24 deletions src/util/malloc/library.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// Export one of the malloc libraries.

#[cfg(feature = "malloc_hoard")]
pub use self::hoard::*;
#[cfg(feature = "malloc_jemalloc")]
pub use self::jemalloc::*;
#[cfg(not(any(
feature = "malloc_jemalloc",
feature = "malloc_mimalloc",
feature = "malloc_hoard",
)))]
#[cfg(not(any(feature = "malloc_jemalloc", feature = "malloc_mimalloc",)))]
pub use self::libc_malloc::*;
#[cfg(feature = "malloc_mimalloc")]
pub use self::mimalloc::*;
Expand Down Expand Up @@ -48,24 +42,8 @@ mod mimalloc {
pub use mimalloc_sys::mi_malloc_usable_size as malloc_usable_size;
}

#[cfg(feature = "malloc_hoard")]
mod hoard {
// Normal 4K page
pub const LOG_BYTES_IN_MALLOC_PAGE: u8 = crate::util::constants::LOG_BYTES_IN_PAGE;
// ANSI C
pub use hoard_sys::{calloc, free, malloc, realloc};
// Posix
pub use hoard_sys::posix_memalign;
// GNU
pub use hoard_sys::malloc_usable_size;
}

/// If no malloc lib is specified, use the libc implementation
#[cfg(not(any(
feature = "malloc_jemalloc",
feature = "malloc_mimalloc",
feature = "malloc_hoard",
)))]
#[cfg(not(any(feature = "malloc_jemalloc", feature = "malloc_mimalloc",)))]
mod libc_malloc {
// Normal 4K page
pub const LOG_BYTES_IN_MALLOC_PAGE: u8 = crate::util::constants::LOG_BYTES_IN_PAGE;
Expand Down
4 changes: 0 additions & 4 deletions src/util/malloc/malloc_ms_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ pub fn alloc<VM: VMBinding>(size: usize, align: usize, offset: usize) -> (Addres
debug_assert!(address.is_aligned_to(align));
} else if align > 16 && offset == 0 {
address = align_alloc(size, align);
#[cfg(feature = "malloc_hoard")]
{
is_offset_malloc = true;
}
debug_assert!(
address.is_aligned_to(align),
"Address: {:x} is not aligned to the given alignment: {}",
Expand Down
2 changes: 1 addition & 1 deletion src/util/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ macro_rules! options {
///
/// Arguments:
/// * `options`: a string that is key value pairs separated by white spaces or commas, e.g. `threads=1 stress_factor=4096`,
/// or `threads=1,stress_factor=4096`
/// or `threads=1,stress_factor=4096`
pub fn set_bulk_from_command_line(&mut self, options: &str) -> bool {
for opt in options.replace(",", " ").split_ascii_whitespace() {
let kv_pair: Vec<&str> = opt.split('=').collect();
Expand Down
10 changes: 5 additions & 5 deletions src/util/rust_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ pub const fn min_of_usize(a: usize, b: usize) -> usize {
}
}

#[cfg(feature = "nightly")]
use core::intrinsics::{likely, unlikely};
#[rustversion::nightly]
pub use core::intrinsics::{likely, unlikely};

// likely() and unlikely() compiler hints in stable Rust
// [1]: https://github.com/rust-lang/hashbrown/blob/a41bd76de0a53838725b997c6085e024c47a0455/src/raw/mod.rs#L48-L70
// [2]: https://users.rust-lang.org/t/compiler-hint-for-unlikely-likely-for-if-branches/62102/3
#[cfg(not(feature = "nightly"))]
#[rustversion::not(nightly)]
#[cold]
fn cold() {}

#[cfg(not(feature = "nightly"))]
#[rustversion::not(nightly)]
pub fn likely(b: bool) -> bool {
if !b {
cold();
}
b
}
#[cfg(not(feature = "nightly"))]
#[rustversion::not(nightly)]
pub fn unlikely(b: bool) -> bool {
if b {
cold();
Expand Down
2 changes: 1 addition & 1 deletion src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! lto = true
//! ```
//! 2. Make sure that the crate type for a VM binding supports LTO. To our knowledge, `staticlib` and `cdylib` support LTO, and
//! `rlib` does *not* support LTO.
//! `rlib` does *not* support LTO.

mod active_plan;
mod collection;
Expand Down
6 changes: 0 additions & 6 deletions src/vm/tests/mock_tests/mock_test_malloc_ms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ fn test_malloc() {
assert!((address4 + 4_isize).is_aligned_to(64));

assert!(!bool1);
#[cfg(feature = "malloc_hoard")]
assert!(bool2);
#[cfg(not(feature = "malloc_hoard"))]
assert!(!bool2);
assert!(bool3);
assert!(bool4);
Expand All @@ -33,9 +30,6 @@ fn test_malloc() {
unsafe {
malloc_ms_util::free(address1.to_mut_ptr());
}
#[cfg(feature = "malloc_hoard")]
malloc_ms_util::offset_free(address2);
#[cfg(not(feature = "malloc_hoard"))]
unsafe {
malloc_ms_util::free(address2.to_mut_ptr());
}
Expand Down

0 comments on commit f9b85bc

Please sign in to comment.