From 83423f37be49a7466f8080a9b343fb791da559d9 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 27 Apr 2024 16:52:20 -0500 Subject: [PATCH] cl-arena: Make arena constructors const fn --- compiler/cl-arena/src/lib.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/cl-arena/src/lib.rs b/compiler/cl-arena/src/lib.rs index e8eae66..7aba181 100644 --- a/compiler/cl-arena/src/lib.rs +++ b/compiler/cl-arena/src/lib.rs @@ -2,7 +2,7 @@ //! //! An Arena Allocator is a type of allocator which provides stable locations for allocations within //! itself for the entire duration of its lifetime. -//! +//! //! [1]: https://raw.githubusercontent.com/rust-lang/rust/master/LICENSE-MIT #![feature(dropck_eyepatch, new_uninit, strict_provenance)] @@ -96,18 +96,18 @@ pub mod typed_arena { impl Default for TypedArena { fn default() -> Self { - Self { - _drops: Default::default(), - chunks: Default::default(), - head: Cell::new(ptr::null_mut()), - tail: Cell::new(ptr::null_mut()), - } + Self::new() } } impl TypedArena { - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self { + _drops: PhantomData, + chunks: RefCell::new(Vec::new()), + head: Cell::new(ptr::null_mut()), + tail: Cell::new(ptr::null_mut()), + } } #[allow(clippy::mut_from_ref)] @@ -205,17 +205,17 @@ pub mod dropless_arena { impl Default for DroplessArena { fn default() -> Self { - Self { - chunks: Default::default(), - head: Cell::new(ptr::null_mut()), - tail: Cell::new(ptr::null_mut()), - } + Self::new() } } impl DroplessArena { - pub fn new() -> Self { - Self::default() + pub const fn new() -> Self { + Self { + chunks: RefCell::new(Vec::new()), + head: Cell::new(ptr::null_mut()), + tail: Cell::new(ptr::null_mut()), + } } /// Allocates a `T` in the [DroplessArena], and returns a mutable reference to it.