From 57b1b9e1a360d94f896a8ac43aa34a43626f631e Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Thu, 6 Aug 2020 11:00:10 +0100 Subject: [PATCH 1/3] Update after recent rust-nightly changes. There are two PRs which affect us: https://github.com/rust-lang/rust/pull/74850 https://github.com/rust-lang/rust/pull/75152 Henceforth, we should probably be keeping a close eye on and contributing to: https://github.com/rust-lang/wg-allocators/issues --- src/allocator.rs | 10 ++++------ src/gc.rs | 16 +++------------- src/lib.rs | 1 + 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 14d3941..1ba3761 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1,5 +1,5 @@ use std::{ - alloc::{AllocErr, AllocInit, AllocRef, GlobalAlloc, Layout, MemoryBlock}, + alloc::{AllocErr, AllocRef, GlobalAlloc, Layout}, ffi::c_void, ptr::NonNull, }; @@ -24,13 +24,11 @@ unsafe impl GlobalAlloc for BoehmAllocator { } unsafe impl AllocRef for BoehmGcAllocator { - fn alloc(&mut self, layout: Layout, _init: AllocInit) -> Result { + fn alloc(&mut self, layout: Layout) -> Result, AllocErr> { let ptr = unsafe { boehm::GC_malloc(layout.size()) } as *mut u8; assert!(!ptr.is_null()); - Ok(MemoryBlock { - ptr: unsafe { NonNull::new_unchecked(ptr) }, - size: layout.size(), - }) + let ptr = unsafe { NonNull::new_unchecked(ptr) }; + Ok(NonNull::slice_from_raw_parts(ptr, layout.size())) } unsafe fn dealloc(&mut self, _: NonNull, _: Layout) {} diff --git a/src/gc.rs b/src/gc.rs index a83f0a0..98cf994 100644 --- a/src/gc.rs +++ b/src/gc.rs @@ -1,5 +1,5 @@ use std::{ - alloc::{AllocInit, AllocRef, Layout}, + alloc::{AllocRef, Layout}, any::Any, ffi::c_void, fmt, @@ -146,13 +146,7 @@ struct GcBox(ManuallyDrop); impl GcBox { fn new(value: T) -> *mut GcBox { let layout = Layout::new::(); - let ptr = unsafe { - GC_ALLOCATOR - .alloc(layout, AllocInit::Uninitialized) - .unwrap() - .ptr - .as_ptr() - } as *mut GcBox; + let ptr = unsafe { GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() } as *mut GcBox; let gcbox = GcBox(ManuallyDrop::new(value)); unsafe { @@ -166,11 +160,7 @@ impl GcBox { fn new_from_layout(layout: Layout) -> NonNull>> { unsafe { - let base_ptr = GC_ALLOCATOR - .alloc(layout, AllocInit::Uninitialized) - .unwrap() - .ptr - .as_ptr() as *mut usize; + let base_ptr = GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() as *mut usize; NonNull::new_unchecked(base_ptr as *mut GcBox>) } } diff --git a/src/lib.rs b/src/lib.rs index 9f562ad..fd5fc1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ #![feature(alloc_layout_extra)] #![feature(arbitrary_self_types)] #![feature(dispatch_from_dyn)] +#![feature(nonnull_slice_from_raw_parts)] #![feature(raw_vec_internals)] #![feature(const_fn)] #![feature(coerce_unsized)] From f21cec9e3489e67ff275073a93c9d926eb7f82af Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Sun, 9 Aug 2020 09:31:17 +0100 Subject: [PATCH 2/3] Try a two-stage approach. --- .buildbot.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.buildbot.sh b/.buildbot.sh index 2a0b02d..4fdcb5c 100644 --- a/.buildbot.sh +++ b/.buildbot.sh @@ -8,9 +8,10 @@ export RUSTUP_HOME="`pwd`/.rustup" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh # Install no toolchain initially to ensure toolchain rollback. sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path - export PATH=`pwd`/.cargo/bin/:$PATH -rustup install nightly -cargo +nightly fmt --all -- --check +rustup toolchain install nightly --allow-downgrade --profile minimal cargo check + +rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy +cargo +nightly fmt --all -- --check From dc4bd84f48b984a513727d982c7dd005b963f91a Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Sun, 9 Aug 2020 09:41:23 +0100 Subject: [PATCH 3/3] Another try. --- .buildbot.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.buildbot.sh b/.buildbot.sh index 4fdcb5c..14a5a75 100644 --- a/.buildbot.sh +++ b/.buildbot.sh @@ -6,12 +6,15 @@ export CARGO_HOME="`pwd`/.cargo" export RUSTUP_HOME="`pwd`/.rustup" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh -# Install no toolchain initially to ensure toolchain rollback. -sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path +sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain nightly -y --no-modify-path export PATH=`pwd`/.cargo/bin/:$PATH rustup toolchain install nightly --allow-downgrade --profile minimal cargo check -rustup toolchain install nightly --allow-downgrade --profile minimal --component clippy +if [ `which cargo-fmt` -ne 0 ]; then + rm -rf ${RUSTUP_HOME} ${CARGO_HOME} + sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path + rustup toolchain install nightly --allow-downgrade --profile minimal +fi cargo +nightly fmt --all -- --check