Skip to content

Commit d91b203

Browse files
authored
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: #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.
1 parent dd84218 commit d91b203

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/mmtk/mmtk-core"
1010
readme = "README.md"
1111
categories = ["memory-management"]
1212
keywords = ["gc", "garbage", "collection", "garbage-collection", "allocation"]
13-
rust-version = "1.70.0"
13+
rust-version = "1.71.1"
1414
build = "build.rs"
1515

1616
[lib]

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.71.1
1+
1.77.0

src/policy/lockfreeimmortalspace.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ impl<VM: VMBinding> LockFreeImmortalSpace<VM> {
198198
// Create a VM request of fixed size
199199
let vmrequest = VMRequest::fixed_size(aligned_total_bytes);
200200
// Reserve the space
201-
let VMRequest::Extent{ extent, top } = vmrequest else { unreachable!() };
201+
let VMRequest::Extent { extent, top } = vmrequest else {
202+
unreachable!()
203+
};
202204
let start = args.heap.reserve(extent, top);
203205

204206
let space = Self {

src/scheduler/worker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub type ThreadId = usize;
1919

2020
thread_local! {
2121
/// Current worker's ordinal
22-
static WORKER_ORDINAL: Atomic<ThreadId> = Atomic::new(ThreadId::MAX);
22+
static WORKER_ORDINAL: Atomic<ThreadId> = const { Atomic::new(ThreadId::MAX) };
2323
}
2424

2525
/// Get current worker ordinal. Return `None` if the current thread is not a worker.

src/util/heap/layout/vm_layout.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The module defines virutal memory layout parameters.
22
3+
use std::ptr::addr_of;
34
use std::sync::atomic::AtomicBool;
45

56
use atomic::Ordering;
@@ -192,5 +193,5 @@ pub fn vm_layout() -> &'static VMLayout {
192193
if cfg!(debug_assertions) {
193194
VM_LAYOUT_FETCHED.store(true, Ordering::SeqCst);
194195
}
195-
unsafe { &VM_LAYOUT }
196+
unsafe { &*addr_of!(VM_LAYOUT) }
196197
}

src/vm/tests/mock_tests/mock_test_doc_avoid_resolving_allocator.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,22 @@ pub fn acquire_typed_allocator() {
1818
|| {
1919
let fixture = MMTKFixture::create();
2020
let tls_opaque_pointer = VMMutatorThread(VMThread(OpaquePointer::UNINITIALIZED));
21-
static mut DEFAULT_ALLOCATOR_OFFSET: usize = 0;
2221

2322
// ANCHOR: avoid_resolving_allocator
2423
// At boot time
2524
let selector = memory_manager::get_allocator_mapping(
2625
fixture.get_mmtk(),
2726
AllocationSemantics::Default,
2827
);
29-
unsafe {
30-
DEFAULT_ALLOCATOR_OFFSET =
31-
crate::plan::Mutator::<MockVM>::get_allocator_base_offset(selector);
32-
}
28+
let default_allocator_offset =
29+
crate::plan::Mutator::<MockVM>::get_allocator_base_offset(selector);
3330
let mutator = memory_manager::bind_mutator(fixture.get_mmtk(), tls_opaque_pointer);
3431

3532
// At run time: allocate with the default semantics without resolving allocator
3633
let default_allocator: &mut BumpAllocator<MockVM> = {
3734
let mutator_addr = Address::from_ref(&*mutator);
3835
unsafe {
39-
(mutator_addr + DEFAULT_ALLOCATOR_OFFSET).as_mut_ref::<BumpAllocator<MockVM>>()
36+
(mutator_addr + default_allocator_offset).as_mut_ref::<BumpAllocator<MockVM>>()
4037
}
4138
};
4239
let addr = default_allocator.alloc(8, 8, 0);

0 commit comments

Comments
 (0)