diff --git a/Cargo.lock b/Cargo.lock index 6bfa8af1e..960028af5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -217,7 +217,7 @@ checksum = "523363cbe1df49b68215efdf500b103ac3b0fb4836aed6d15689a076eadb8fff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1129,7 +1129,7 @@ checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1505,7 +1505,7 @@ checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] @@ -1728,7 +1728,7 @@ checksum = "beb382a4d9f53bd5c0be86b10d8179c3f8a14c30bf774ff77096ed6581e35981" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.90", ] [[package]] diff --git a/ceno_host/src/lib.rs b/ceno_host/src/lib.rs index c64bce07d..ac90f7d1d 100644 --- a/ceno_host/src/lib.rs +++ b/ceno_host/src/lib.rs @@ -8,6 +8,14 @@ use rkyv::{ util::AlignedVec, }; +// We want to get access to the default value of `AlignedVec::ALIGNMENT`, and using it directly like this +// pub const RKVY_ALIGNMENT: usize = rkyv::util::AlignedVec::ALIGNMENT; +// doesn't work: +pub const RKYV_ALIGNMENT: usize = { + type AlignedVec = rkyv::util::AlignedVec; + AlignedVec::ALIGNMENT +}; + #[derive(Default)] pub struct CenoStdin { pub items: Vec, @@ -26,32 +34,30 @@ impl CenoStdin { } pub fn finalise(&self) -> Vec { - // TODO: perhaps don't hardcode 16 here. - // It's from rkyv's format, so we can probably take it from there somehow? - // TODO: clean this up. - let initial_offset = (size_of::() * self.items.len()).next_multiple_of(16); - // println!("offset: {}", initial_offset); + let initial_offset = (size_of::() * self.items.len()).next_multiple_of(RKYV_ALIGNMENT); let offsets: Vec = self .items .iter() .scan(initial_offset, |acc, bytes| { let output = (*acc + bytes.len()) as u32; - // print!("len: {}\t", bytes.len()); - *acc += bytes.len().next_multiple_of(16); - // println!("acc: {}", *acc); + *acc += bytes.len().next_multiple_of(RKYV_ALIGNMENT); Some(output) }) .collect(); let offsets_u8: Vec = offsets.iter().copied().flat_map(u32::to_le_bytes).collect(); let mut buf: AlignedVec = AlignedVec::new(); buf.extend_from_slice(&offsets_u8); - // println!("buf.len() after offsets: {}", buf.len()); - buf.extend_from_slice(&vec![0; buf.len().next_multiple_of(16) - buf.len()]); - // println!("buf.len() after offset padding: {}", buf.len()); + buf.extend_from_slice(&vec![ + 0; + buf.len().next_multiple_of(RKYV_ALIGNMENT) - buf.len() + ]); for (offset, item) in izip!(offsets, &self.items) { buf.extend_from_slice(item); - buf.extend_from_slice(&vec![0; buf.len().next_multiple_of(16) - buf.len()]); - assert_eq!(buf.len(), offset.next_multiple_of(16) as usize); + buf.extend_from_slice(&vec![ + 0; + buf.len().next_multiple_of(RKYV_ALIGNMENT) - buf.len() + ]); + assert_eq!(buf.len(), offset.next_multiple_of(RKYV_ALIGNMENT) as usize); } let (prefix, hints, postfix): (_, &[u32], _) = unsafe { buf.align_to() }; assert_eq!(prefix, &[]);