From d91b2034b7f5f8f138486019334d28feb722b1f5 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Wed, 3 Apr 2024 07:47:19 +0800 Subject: [PATCH] Fix warnings with the stable Rust toolchain (#1099) As getting a ref `&` of `static mut` variables will become a compilation error in the Rust 2024 Edition, we use `unsafe { &*addr_of!(VM_LAYOUT) }` to work around it. See: https://github.com/mmtk/mmtk-core/issues/1098 Changed the `static mut` in mock_test_doc_avoid_resolving_allocator.rs to an ordinary local variable. Initialize the thread-local variable `WORKER_ORDINAL` with a `const` block. It avoids lazy initialization. We also bumped the `rust-version` field in Cargo.toml to 1.71.1 because the semantics of the `const` block in the `thread_local!` macro was undocumented in 1.70.0. --- Cargo.toml | 2 +- rust-toolchain | 2 +- src/policy/lockfreeimmortalspace.rs | 4 +++- src/scheduler/worker.rs | 2 +- src/util/heap/layout/vm_layout.rs | 3 ++- .../mock_test_doc_avoid_resolving_allocator.rs | 9 +++------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1f108df3f..0fc472534d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/mmtk/mmtk-core" readme = "README.md" categories = ["memory-management"] keywords = ["gc", "garbage", "collection", "garbage-collection", "allocation"] -rust-version = "1.70.0" +rust-version = "1.71.1" build = "build.rs" [lib] diff --git a/rust-toolchain b/rust-toolchain index 68bc7ff2a8..79e15fd493 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.71.1 +1.77.0 diff --git a/src/policy/lockfreeimmortalspace.rs b/src/policy/lockfreeimmortalspace.rs index e78f95e30a..9a077533ec 100644 --- a/src/policy/lockfreeimmortalspace.rs +++ b/src/policy/lockfreeimmortalspace.rs @@ -198,7 +198,9 @@ impl LockFreeImmortalSpace { // Create a VM request of fixed size let vmrequest = VMRequest::fixed_size(aligned_total_bytes); // Reserve the space - let VMRequest::Extent{ extent, top } = vmrequest else { unreachable!() }; + let VMRequest::Extent { extent, top } = vmrequest else { + unreachable!() + }; let start = args.heap.reserve(extent, top); let space = Self { diff --git a/src/scheduler/worker.rs b/src/scheduler/worker.rs index 1d850a7c1f..504b2f6b48 100644 --- a/src/scheduler/worker.rs +++ b/src/scheduler/worker.rs @@ -19,7 +19,7 @@ pub type ThreadId = usize; thread_local! { /// Current worker's ordinal - static WORKER_ORDINAL: Atomic = Atomic::new(ThreadId::MAX); + static WORKER_ORDINAL: Atomic = const { Atomic::new(ThreadId::MAX) }; } /// Get current worker ordinal. Return `None` if the current thread is not a worker. diff --git a/src/util/heap/layout/vm_layout.rs b/src/util/heap/layout/vm_layout.rs index 598dbd8376..720237e6fb 100644 --- a/src/util/heap/layout/vm_layout.rs +++ b/src/util/heap/layout/vm_layout.rs @@ -1,5 +1,6 @@ //! The module defines virutal memory layout parameters. +use std::ptr::addr_of; use std::sync::atomic::AtomicBool; use atomic::Ordering; @@ -192,5 +193,5 @@ pub fn vm_layout() -> &'static VMLayout { if cfg!(debug_assertions) { VM_LAYOUT_FETCHED.store(true, Ordering::SeqCst); } - unsafe { &VM_LAYOUT } + unsafe { &*addr_of!(VM_LAYOUT) } } diff --git a/src/vm/tests/mock_tests/mock_test_doc_avoid_resolving_allocator.rs b/src/vm/tests/mock_tests/mock_test_doc_avoid_resolving_allocator.rs index b7c50ddee0..3fb9d74140 100644 --- a/src/vm/tests/mock_tests/mock_test_doc_avoid_resolving_allocator.rs +++ b/src/vm/tests/mock_tests/mock_test_doc_avoid_resolving_allocator.rs @@ -18,7 +18,6 @@ pub fn acquire_typed_allocator() { || { let fixture = MMTKFixture::create(); let tls_opaque_pointer = VMMutatorThread(VMThread(OpaquePointer::UNINITIALIZED)); - static mut DEFAULT_ALLOCATOR_OFFSET: usize = 0; // ANCHOR: avoid_resolving_allocator // At boot time @@ -26,17 +25,15 @@ pub fn acquire_typed_allocator() { fixture.get_mmtk(), AllocationSemantics::Default, ); - unsafe { - DEFAULT_ALLOCATOR_OFFSET = - crate::plan::Mutator::::get_allocator_base_offset(selector); - } + let default_allocator_offset = + crate::plan::Mutator::::get_allocator_base_offset(selector); let mutator = memory_manager::bind_mutator(fixture.get_mmtk(), tls_opaque_pointer); // At run time: allocate with the default semantics without resolving allocator let default_allocator: &mut BumpAllocator = { let mutator_addr = Address::from_ref(&*mutator); unsafe { - (mutator_addr + DEFAULT_ALLOCATOR_OFFSET).as_mut_ref::>() + (mutator_addr + default_allocator_offset).as_mut_ref::>() } }; let addr = default_allocator.alloc(8, 8, 0);