From 9c2b6bd20f95400589e4500e925b9df218446c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Kr=C3=BCger?= Date: Thu, 3 Apr 2025 17:11:25 +0100 Subject: [PATCH] RISC-V: Remove `allocate` method from `Layout` --- src/riscv/lib/src/cache_utils.rs | 5 - .../lib/src/machine_state/block_cache.rs | 4 - .../src/machine_state/csregisters/values.rs | 9 -- .../memory/buddy/branch_combinations.rs | 4 - .../src/machine_state/memory/buddy/leaf.rs | 6 -- .../src/machine_state/memory/buddy/proxy.rs | 5 - .../src/state_backend/commitment_layout.rs | 5 +- src/riscv/lib/src/state_backend/layout.rs | 95 +------------------ .../lib/src/state_backend/proof_layout.rs | 5 +- 9 files changed, 6 insertions(+), 132 deletions(-) diff --git a/src/riscv/lib/src/cache_utils.rs b/src/riscv/lib/src/cache_utils.rs index e62e3249bd6c..6398316f708b 100644 --- a/src/riscv/lib/src/cache_utils.rs +++ b/src/riscv/lib/src/cache_utils.rs @@ -12,7 +12,6 @@ use crate::state_backend::AllocatedOf; use crate::state_backend::CommitmentLayout; use crate::state_backend::FromProofResult; use crate::state_backend::Layout; -use crate::state_backend::ManagerAlloc; use crate::state_backend::ManagerBase; use crate::state_backend::ManagerSerialise; use crate::state_backend::Many; @@ -91,10 +90,6 @@ impl Layout for Sizes { type Allocated = as Layout>::Allocated; - - fn allocate(backend: &mut M) -> Self::Allocated { - Many::::allocate(backend) - } } impl CommitmentLayout diff --git a/src/riscv/lib/src/machine_state/block_cache.rs b/src/riscv/lib/src/machine_state/block_cache.rs index 1948bb6488f7..f1c4a69c9295 100644 --- a/src/riscv/lib/src/machine_state/block_cache.rs +++ b/src/riscv/lib/src/machine_state/block_cache.rs @@ -182,10 +182,6 @@ pub struct AddressCellLayout; impl state_backend::Layout for AddressCellLayout { type Allocated = Cell; - - fn allocate(backend: &mut M) -> Self::Allocated { - Cell::bind(backend.allocate_region([!0])) - } } impl state_backend::CommitmentLayout for AddressCellLayout { diff --git a/src/riscv/lib/src/machine_state/csregisters/values.rs b/src/riscv/lib/src/machine_state/csregisters/values.rs index bfa78ab2ef70..95a114a7de7e 100644 --- a/src/riscv/lib/src/machine_state/csregisters/values.rs +++ b/src/riscv/lib/src/machine_state/csregisters/values.rs @@ -177,15 +177,6 @@ impl Layout for CSRValuesLayout { AllocatedOf, AllocatedOf, >; - - fn allocate(backend: &mut M) -> Self::Allocated { - let backend = std::cell::RefCell::new(backend); - Self::Allocated::new_with( - || MStatusLayout::allocate(*backend.borrow_mut()), - || XipCellLayout::allocate(*backend.borrow_mut()), - || EffectCellLayout::::allocate(*backend.borrow_mut()), - ) - } } impl CommitmentLayout for CSRValuesLayout { diff --git a/src/riscv/lib/src/machine_state/memory/buddy/branch_combinations.rs b/src/riscv/lib/src/machine_state/memory/buddy/branch_combinations.rs index 65eaa6ecd437..e13468162894 100644 --- a/src/riscv/lib/src/machine_state/memory/buddy/branch_combinations.rs +++ b/src/riscv/lib/src/machine_state/memory/buddy/branch_combinations.rs @@ -97,10 +97,6 @@ macro_rules! combined_buddy_branch { impl Layout for [<$name Layout>] { type Allocated = [<$name Alloc>]; - fn allocate(backend: &mut M) -> Self::Allocated { - let inner = <[<$buddy1 Layout>]<[<$buddy2 Layout>]>>::allocate(backend); - [<$name Alloc>](inner) - } } impl CommitmentLayout for [<$name Layout>] { diff --git a/src/riscv/lib/src/machine_state/memory/buddy/leaf.rs b/src/riscv/lib/src/machine_state/memory/buddy/leaf.rs index 927f896ca950..45170db061e7 100644 --- a/src/riscv/lib/src/machine_state/memory/buddy/leaf.rs +++ b/src/riscv/lib/src/machine_state/memory/buddy/leaf.rs @@ -40,12 +40,6 @@ pub struct BuddyLeafLayout; impl Layout for BuddyLeafLayout { type Allocated = BuddyLeaf; - - fn allocate(backend: &mut M) -> Self::Allocated { - Self::Allocated { - set: Atom::::allocate(backend), - } - } } impl CommitmentLayout for BuddyLeafLayout { diff --git a/src/riscv/lib/src/machine_state/memory/buddy/proxy.rs b/src/riscv/lib/src/machine_state/memory/buddy/proxy.rs index 2936e1904898..e871caab9726 100644 --- a/src/riscv/lib/src/machine_state/memory/buddy/proxy.rs +++ b/src/riscv/lib/src/machine_state/memory/buddy/proxy.rs @@ -15,7 +15,6 @@ use crate::state_backend::CommitmentLayout; use crate::state_backend::FnManager; use crate::state_backend::FromProofResult; use crate::state_backend::Layout; -use crate::state_backend::ManagerAlloc; use crate::state_backend::ManagerBase; use crate::state_backend::ManagerSerialise; use crate::state_backend::PartialHashError; @@ -36,10 +35,6 @@ where (): BuddyLayoutMatch, { type Allocated = as Layout>::Allocated; - - fn allocate(backend: &mut M) -> Self::Allocated { - as Layout>::allocate(backend) - } } impl CommitmentLayout for BuddyLayoutProxy diff --git a/src/riscv/lib/src/state_backend/commitment_layout.rs b/src/riscv/lib/src/state_backend/commitment_layout.rs index 404100d6aea9..974dc6b7def9 100644 --- a/src/riscv/lib/src/state_backend/commitment_layout.rs +++ b/src/riscv/lib/src/state_backend/commitment_layout.rs @@ -16,7 +16,6 @@ use super::hash::HashWriter; use super::proof_backend::merkle::MERKLE_ARITY; use super::proof_backend::merkle::MERKLE_LEAF_SIZE; use super::proof_backend::merkle::chunks_to_writer; -use crate::default::ConstDefault; use crate::state_backend::hash::build_custom_merkle_hash; /// [`Layouts`] which may be used for commitments @@ -35,7 +34,7 @@ impl CommitmentLayout for Box { impl CommitmentLayout for Atom where - T: serde::Serialize + ConstDefault + 'static, + T: serde::Serialize + 'static, { fn state_hash(state: AllocatedOf) -> Result { Hash::blake2b_hash(state) @@ -44,7 +43,7 @@ where impl CommitmentLayout for Array where - T: serde::Serialize + Copy + ConstDefault + 'static, + T: serde::Serialize + Copy + 'static, { fn state_hash(state: AllocatedOf) -> Result { Hash::blake2b_hash(state) diff --git a/src/riscv/lib/src/state_backend/layout.rs b/src/riscv/lib/src/state_backend/layout.rs index 4d9c6b7ef857..5b4f602c900b 100644 --- a/src/riscv/lib/src/state_backend/layout.rs +++ b/src/riscv/lib/src/state_backend/layout.rs @@ -5,29 +5,18 @@ use std::marker::PhantomData; -use crate::default::ConstDefault; - /// Structural description of a state type pub trait Layout { /// Representation of the allocated regions in the state backend type Allocated; - - /// Allocate regions in the given state backend. - fn allocate(backend: &mut M) -> Self::Allocated; } impl Layout for () { type Allocated = (); - - fn allocate(_backend: &mut M) -> Self::Allocated {} } impl Layout for Box { type Allocated = Box>; - - fn allocate(backend: &mut M) -> Self::Allocated { - Box::new(T::allocate(backend)) - } } /// `L::Allocated` @@ -39,13 +28,8 @@ pub struct Atom { _pd: PhantomData, } -impl Layout for Atom { +impl Layout for Atom { type Allocated = super::Cell; - - fn allocate(backend: &mut M) -> Self::Allocated { - let region = backend.allocate_region([T::DEFAULT; 1]); - super::Cell::bind(region) - } } /// Layout for a fixed number of values @@ -54,16 +38,8 @@ pub struct Array { _pd: PhantomData, } -impl Layout for Array -where - [T; LEN]: ConstDefault, -{ +impl Layout for Array { type Allocated = super::Cells; - - fn allocate(backend: &mut M) -> Self::Allocated { - let region = backend.allocate_region(<[T; LEN]>::DEFAULT); - super::Cells::bind(region) - } } /// Layout for a fixed number of bytes, readable as types implementing [`super::elems::Elem`]. @@ -71,11 +47,6 @@ pub struct DynArray {} impl Layout for DynArray { type Allocated = super::DynCells; - - fn allocate(backend: &mut M) -> Self::Allocated { - let region = backend.allocate_dyn_region(); - super::DynCells::bind(region) - } } /// Usage: Provide a struct with each field holding a layout. @@ -134,16 +105,6 @@ macro_rules! struct_layout { ),+ >; - #[inline] - fn allocate( - backend: &mut M, - ) -> Self::Allocated { - Self::Allocated { - $($field_name: <[<$field_name:camel>] as $crate::state_backend::Layout>::allocate( - backend - )),+ - } - } } impl < @@ -246,10 +207,6 @@ where B: Layout, { type Allocated = (A::Allocated, B::Allocated); - - fn allocate(backend: &mut M) -> Self::Allocated { - (A::allocate(backend), B::allocate(backend)) - } } impl Layout for (A, B, C) @@ -259,14 +216,6 @@ where C: Layout, { type Allocated = (A::Allocated, B::Allocated, C::Allocated); - - fn allocate(backend: &mut M) -> Self::Allocated { - ( - A::allocate(backend), - B::allocate(backend), - C::allocate(backend), - ) - } } impl Layout for (A, B, C, D) @@ -282,15 +231,6 @@ where C::Allocated, D::Allocated, ); - - fn allocate(backend: &mut M) -> Self::Allocated { - ( - A::allocate(backend), - B::allocate(backend), - C::allocate(backend), - D::allocate(backend), - ) - } } impl Layout for (A, B, C, D, E) @@ -308,16 +248,6 @@ where D::Allocated, E::Allocated, ); - - fn allocate(backend: &mut M) -> Self::Allocated { - ( - A::allocate(backend), - B::allocate(backend), - C::allocate(backend), - D::allocate(backend), - E::allocate(backend), - ) - } } impl Layout for (A, B, C, D, E, F) @@ -337,17 +267,6 @@ where E::Allocated, F::Allocated, ); - - fn allocate(backend: &mut M) -> Self::Allocated { - ( - A::allocate(backend), - B::allocate(backend), - C::allocate(backend), - D::allocate(backend), - E::allocate(backend), - F::allocate(backend), - ) - } } impl Layout for [T; LEN] @@ -355,10 +274,6 @@ where T: Layout, { type Allocated = [T::Allocated; LEN]; - - fn allocate(backend: &mut M) -> Self::Allocated { - std::array::from_fn(|_| T::allocate(backend)) - } } /// This [`Layout`] is identical to [`[T; LEN]`] but it allows you to choose a very high `LEN`. @@ -369,12 +284,6 @@ where T: Layout, { type Allocated = Vec>; - - fn allocate(backend: &mut M) -> Self::Allocated { - let mut space = Vec::with_capacity(LEN); - space.resize_with(LEN, || T::allocate(backend)); - space - } } #[cfg(test)] diff --git a/src/riscv/lib/src/state_backend/proof_layout.rs b/src/riscv/lib/src/state_backend/proof_layout.rs index 17acaead2b4f..dc3513ac516d 100644 --- a/src/riscv/lib/src/state_backend/proof_layout.rs +++ b/src/riscv/lib/src/state_backend/proof_layout.rs @@ -28,7 +28,6 @@ use super::proof_backend::tree::Tree; use super::verify_backend::PartialState; use super::verify_backend::{self}; use crate::array_utils::boxed_array; -use crate::default::ConstDefault; use crate::state_backend::verify_backend::PageId; use crate::storage::binary; @@ -257,7 +256,7 @@ impl ProofLayout for Box { impl ProofLayout for Atom where - T: serde::Serialize + serde::de::DeserializeOwned + ConstDefault + 'static, + T: serde::Serialize + serde::de::DeserializeOwned + 'static, { fn to_merkle_tree(state: RefProofGenOwnedAlloc) -> Result { // The Merkle leaf must hold the serialisation of the initial state. @@ -289,7 +288,7 @@ where impl ProofLayout for Array where - T: serde::Serialize + serde::de::DeserializeOwned + ConstDefault + 'static, + T: serde::Serialize + serde::de::DeserializeOwned + 'static, { fn to_merkle_tree(state: RefProofGenOwnedAlloc) -> Result { // RV-282: Break down into multiple leaves if the size of the `Cells` -- GitLab