From bfc78a01b55638692c369992d3ba982d61e33e5e Mon Sep 17 00:00:00 2001 From: Gabriel Barreto Date: Wed, 3 Jan 2024 14:54:08 -0300 Subject: [PATCH] Utility macros --- src/cli/repl/meta_cmd.rs | 3 +- src/cli/zstore.rs | 35 ++++---- src/coprocessor/gadgets.rs | 25 +++--- src/lem/eval.rs | 7 +- src/lem/interpreter.rs | 17 ++-- src/lem/store.rs | 132 ++++++++++++------------------ src/lem/tests/nivc_steps.rs | 9 +- src/proof/tests/nova_tests_lem.rs | 7 +- 8 files changed, 113 insertions(+), 122 deletions(-) diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index 53c75afc57..e1f99dfcb6 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -19,6 +19,7 @@ use crate::{ eval::evaluate_with_env_and_cont, multiframe::MultiFrame, pointers::{Ptr, RawPtr, ZPtr}, + store::expect_ptrs, Tag, }, package::{Package, SymbolRef}, @@ -945,7 +946,7 @@ impl MetaCmd { io[0].fmt_to_string(&repl.store, &repl.state.borrow()) ) }; - let [pre_verify, post_verify] = &repl.store.expect_2_ptrs(*idx); + let [pre_verify, post_verify] = &expect_ptrs!(repl.store, 2, *idx); if pre_verify.is_nil() { bail!("Pre-verification predicate rejected the input") diff --git a/src/cli/zstore.rs b/src/cli/zstore.rs index 07351f4767..99bf11932e 100644 --- a/src/cli/zstore.rs +++ b/src/cli/zstore.rs @@ -6,7 +6,7 @@ use crate::{ field::{FWrap, LurkField}, lem::{ pointers::{Ptr, RawPtr, ZPtr}, - store::Store, + store::{expect_ptrs, intern_ptrs_hydrated, Store}, }, }; @@ -53,7 +53,7 @@ impl ZDag { unreachable!() } RawPtr::Hash4(idx) => { - let [a, b] = store.expect_2_ptrs(*idx); + let [a, b] = expect_ptrs!(store, 2, *idx); let a = self.populate_with(&a, store, cache); let b = self.populate_with(&b, store, cache); let z_ptr = ZPtr::from_parts( @@ -69,7 +69,7 @@ impl ZDag { z_ptr } RawPtr::Hash6(idx) => { - let [a, b, c] = store.expect_3_ptrs(*idx); + let [a, b, c] = expect_ptrs!(store, 3, *idx); let a = self.populate_with(&a, store, cache); let b = self.populate_with(&b, store, cache); let c = self.populate_with(&c, store, cache); @@ -88,7 +88,7 @@ impl ZDag { z_ptr } RawPtr::Hash8(idx) => { - let [a, b, c, d] = store.expect_4_ptrs(*idx); + let [a, b, c, d] = expect_ptrs!(store, 4, *idx); let a = self.populate_with(&a, store, cache); let b = self.populate_with(&b, store, cache); let c = self.populate_with(&c, store, cache); @@ -137,20 +137,20 @@ impl ZDag { Some(ZPtrType::Tuple2(z1, z2)) => { let ptr1 = self.populate_store(z1, store, cache)?; let ptr2 = self.populate_store(z2, store, cache)?; - store.intern_2_ptrs_hydrated(*z_ptr.tag(), ptr1, ptr2, *z_ptr) + intern_ptrs_hydrated!(store, *z_ptr.tag(), *z_ptr, ptr1, ptr2) } Some(ZPtrType::Tuple3(z1, z2, z3)) => { let ptr1 = self.populate_store(z1, store, cache)?; let ptr2 = self.populate_store(z2, store, cache)?; let ptr3 = self.populate_store(z3, store, cache)?; - store.intern_3_ptrs_hydrated(*z_ptr.tag(), ptr1, ptr2, ptr3, *z_ptr) + intern_ptrs_hydrated!(store, *z_ptr.tag(), *z_ptr, ptr1, ptr2, ptr3) } Some(ZPtrType::Tuple4(z1, z2, z3, z4)) => { let ptr1 = self.populate_store(z1, store, cache)?; let ptr2 = self.populate_store(z2, store, cache)?; let ptr3 = self.populate_store(z3, store, cache)?; let ptr4 = self.populate_store(z4, store, cache)?; - store.intern_4_ptrs_hydrated(*z_ptr.tag(), ptr1, ptr2, ptr3, ptr4, *z_ptr) + intern_ptrs_hydrated!(store, *z_ptr.tag(), *z_ptr, ptr1, ptr2, ptr3, ptr4) } }; cache.insert(*z_ptr, ptr); @@ -281,7 +281,11 @@ mod tests { use crate::{ field::LurkField, - lem::{pointers::Ptr, store::Store, Tag}, + lem::{ + pointers::Ptr, + store::{intern_ptrs, Store}, + Tag, + }, tag::{ContTag, ExprTag, Op1, Op2}, }; @@ -302,23 +306,26 @@ mod tests { } else { match rnd % 4 { 0 => store.intern_atom(tag, Fp::from_u64(rnd)), - 1 => store.intern_2_ptrs( + 1 => intern_ptrs!( + store, tag, rng_interner(rng, max_depth - 1, store), - rng_interner(rng, max_depth - 1, store), + rng_interner(rng, max_depth - 1, store) ), - 2 => store.intern_3_ptrs( + 2 => intern_ptrs!( + store, tag, rng_interner(rng, max_depth - 1, store), rng_interner(rng, max_depth - 1, store), - rng_interner(rng, max_depth - 1, store), + rng_interner(rng, max_depth - 1, store) ), - 3 => store.intern_4_ptrs( + 3 => intern_ptrs!( + store, tag, rng_interner(rng, max_depth - 1, store), rng_interner(rng, max_depth - 1, store), rng_interner(rng, max_depth - 1, store), - rng_interner(rng, max_depth - 1, store), + rng_interner(rng, max_depth - 1, store) ), _ => unreachable!(), } diff --git a/src/coprocessor/gadgets.rs b/src/coprocessor/gadgets.rs index 371a078b03..e983da74ce 100644 --- a/src/coprocessor/gadgets.rs +++ b/src/coprocessor/gadgets.rs @@ -12,7 +12,7 @@ use crate::{ lem::{ circuit::GlobalAllocator, pointers::{Ptr, ZPtr}, - store::Store, + store::{expect_ptrs, Store}, }, tag::{ExprTag, Tag}, }; @@ -178,7 +178,7 @@ pub(crate) fn deconstruct_tuple2>( ) -> Result<(AllocatedPtr, AllocatedPtr), SynthesisError> { let (a, b) = if not_dummy.get_value() == Some(true) { let idx = get_ptr(tuple, store)?.get_index2().expect("invalid Ptr"); - let [a, b] = &store.expect_2_ptrs(idx); + let [a, b] = &expect_ptrs!(store, 2, idx); (store.hash_ptr(a), store.hash_ptr(b)) } else { (ZPtr::dummy(), ZPtr::dummy()) @@ -221,7 +221,7 @@ pub(crate) fn deconstruct_tuple3>( ) -> Result<(AllocatedPtr, AllocatedPtr, AllocatedPtr), SynthesisError> { let (a, b, c) = if not_dummy.get_value() == Some(true) { let idx = get_ptr(tuple, store)?.get_index3().expect("invalid Ptr"); - let [a, b, c] = &store.expect_3_ptrs(idx); + let [a, b, c] = &expect_ptrs!(store, 3, idx); (store.hash_ptr(a), store.hash_ptr(b), store.hash_ptr(c)) } else { (ZPtr::dummy(), ZPtr::dummy(), ZPtr::dummy()) @@ -275,7 +275,7 @@ pub(crate) fn deconstruct_tuple4>( > { let (a, b, c, d) = if not_dummy.get_value() == Some(true) { let idx = get_ptr(tuple, store)?.get_index4().expect("invalid Ptr"); - let [a, b, c, d] = &store.expect_4_ptrs(idx); + let [a, b, c, d] = &expect_ptrs!(store, 4, idx); ( store.hash_ptr(a), store.hash_ptr(b), @@ -538,7 +538,10 @@ mod test { deconstruct_tuple4, }, field::LurkField, - lem::{circuit::GlobalAllocator, store::Store}, + lem::{ + circuit::GlobalAllocator, + store::{intern_ptrs, Store}, + }, }; use super::{a_ptr_as_z_ptr, chain_car_cdr, construct_list, deconstruct_tuple2}; @@ -561,7 +564,7 @@ mod test { &a_nil, ) .unwrap(); - let nil2_ptr = store.intern_2_ptrs(*nil_tag, nil, nil); + let nil2_ptr = intern_ptrs!(store, *nil_tag, nil, nil); let z_nil2_ptr = store.hash_ptr(&nil2_ptr); assert_eq!(a_ptr_as_z_ptr(&nil2), Some(z_nil2_ptr)); @@ -575,7 +578,7 @@ mod test { &a_nil, ) .unwrap(); - let nil3_ptr = store.intern_3_ptrs(*nil_tag, nil, nil, nil); + let nil3_ptr = intern_ptrs!(store, *nil_tag, nil, nil, nil); let z_nil3_ptr = store.hash_ptr(&nil3_ptr); assert_eq!(a_ptr_as_z_ptr(&nil3), Some(z_nil3_ptr)); @@ -590,7 +593,7 @@ mod test { &a_nil, ) .unwrap(); - let nil4_ptr = store.intern_4_ptrs(*nil_tag, nil, nil, nil, nil); + let nil4_ptr = intern_ptrs!(store, *nil_tag, nil, nil, nil, nil); let z_nil4_ptr = store.hash_ptr(&nil4_ptr); assert_eq!(a_ptr_as_z_ptr(&nil4), Some(z_nil4_ptr)); } @@ -624,7 +627,7 @@ mod test { let nil_tag = *nil.tag(); let not_dummy = Boolean::Constant(true); - let tuple2 = store.intern_2_ptrs(nil_tag, nil, nil); + let tuple2 = intern_ptrs!(store, nil_tag, nil, nil); let z_tuple2 = store.hash_ptr(&tuple2); let a_tuple2 = AllocatedPtr::alloc_infallible(&mut cs.namespace(|| "tuple2"), || z_tuple2); let (a, b) = deconstruct_tuple2( @@ -637,7 +640,7 @@ mod test { assert_eq!(a_ptr_as_z_ptr(&a), Some(z_nil)); assert_eq!(a_ptr_as_z_ptr(&b), Some(z_nil)); - let tuple3 = store.intern_3_ptrs(nil_tag, nil, nil, nil); + let tuple3 = intern_ptrs!(store, nil_tag, nil, nil, nil); let z_tuple3 = store.hash_ptr(&tuple3); let a_tuple3 = AllocatedPtr::alloc_infallible(&mut cs.namespace(|| "tuple3"), || z_tuple3); let (a, b, c) = deconstruct_tuple3( @@ -651,7 +654,7 @@ mod test { assert_eq!(a_ptr_as_z_ptr(&b), Some(z_nil)); assert_eq!(a_ptr_as_z_ptr(&c), Some(z_nil)); - let tuple4 = store.intern_4_ptrs(nil_tag, nil, nil, nil, nil); + let tuple4 = intern_ptrs!(store, nil_tag, nil, nil, nil, nil); let z_tuple4 = store.hash_ptr(&tuple4); let a_tuple4 = AllocatedPtr::alloc_infallible(&mut cs.namespace(|| "tuple4"), || z_tuple4); let (a, b, c, d) = deconstruct_tuple4( diff --git a/src/lem/eval.rs b/src/lem/eval.rs index 9ad14daca6..e15afee04a 100644 --- a/src/lem/eval.rs +++ b/src/lem/eval.rs @@ -22,7 +22,7 @@ use crate::{ use super::{ interpreter::{Frame, Hints}, pointers::{Ptr, RawPtr}, - store::Store, + store::{fetch_ptrs, Store}, Ctrl, Func, Op, Tag, Var, }; @@ -42,9 +42,8 @@ fn get_pc>( ) -> usize { match expr.parts() { (Tag::Expr(Cproc), RawPtr::Hash4(idx)) => { - let [cproc, _] = &store - .fetch_2_ptrs(*idx) - .expect("Coprocessor expression is not interned"); + let [cproc, _] = + &fetch_ptrs!(store, 2, *idx).expect("Coprocessor expression is not interned"); let cproc_sym = store .fetch_symbol(cproc) .expect("Coprocessor expression is not interned"); diff --git a/src/lem/interpreter.rs b/src/lem/interpreter.rs index aa01851be4..1a9fdcfc13 100644 --- a/src/lem/interpreter.rs +++ b/src/lem/interpreter.rs @@ -4,7 +4,7 @@ use super::{ path::Path, pointers::{Ptr, RawPtr}, slot::{SlotData, Val}, - store::Store, + store::{fetch_ptrs, intern_ptrs, Store}, var_map::VarMap, Block, Ctrl, Func, Op, Tag, Var, }; @@ -341,7 +341,7 @@ impl Block { } Op::Cons2(img, tag, preimg) => { let preimg_ptrs = bindings.get_many_ptr(preimg)?; - let tgt_ptr = store.intern_2_ptrs(*tag, preimg_ptrs[0], preimg_ptrs[1]); + let tgt_ptr = intern_ptrs!(store, *tag, preimg_ptrs[0], preimg_ptrs[1]); bindings.insert_ptr(img.clone(), tgt_ptr); let vals = preimg_ptrs.into_iter().map(Val::Pointer).collect(); hints.hash4.push(Some(SlotData { vals })); @@ -349,19 +349,20 @@ impl Block { Op::Cons3(img, tag, preimg) => { let preimg_ptrs = bindings.get_many_ptr(preimg)?; let tgt_ptr = - store.intern_3_ptrs(*tag, preimg_ptrs[0], preimg_ptrs[1], preimg_ptrs[2]); + intern_ptrs!(store, *tag, preimg_ptrs[0], preimg_ptrs[1], preimg_ptrs[2]); bindings.insert_ptr(img.clone(), tgt_ptr); let vals = preimg_ptrs.into_iter().map(Val::Pointer).collect(); hints.hash6.push(Some(SlotData { vals })); } Op::Cons4(img, tag, preimg) => { let preimg_ptrs = bindings.get_many_ptr(preimg)?; - let tgt_ptr = store.intern_4_ptrs( + let tgt_ptr = intern_ptrs!( + store, *tag, preimg_ptrs[0], preimg_ptrs[1], preimg_ptrs[2], - preimg_ptrs[3], + preimg_ptrs[3] ); bindings.insert_ptr(img.clone(), tgt_ptr); let vals = preimg_ptrs.into_iter().map(Val::Pointer).collect(); @@ -372,7 +373,7 @@ impl Block { let Some(idx) = img_ptr.get_index2() else { bail!("{img} isn't a Tree2 pointer"); }; - let Some(preimg_ptrs) = store.fetch_2_ptrs(idx) else { + let Some(preimg_ptrs) = fetch_ptrs!(store, 2, idx) else { bail!("Couldn't fetch {img}'s children") }; for (var, ptr) in preimg.iter().zip(preimg_ptrs.iter()) { @@ -386,7 +387,7 @@ impl Block { let Some(idx) = img_ptr.get_index3() else { bail!("{img} isn't a Tree3 pointer"); }; - let Some(preimg_ptrs) = store.fetch_3_ptrs(idx) else { + let Some(preimg_ptrs) = fetch_ptrs!(store, 3, idx) else { bail!("Couldn't fetch {img}'s children") }; for (var, ptr) in preimg.iter().zip(preimg_ptrs.iter()) { @@ -400,7 +401,7 @@ impl Block { let Some(idx) = img_ptr.get_index4() else { bail!("{img} isn't a Tree4 pointer"); }; - let Some(preimg_ptrs) = store.fetch_4_ptrs(idx) else { + let Some(preimg_ptrs) = fetch_ptrs!(store, 4, idx) else { bail!("Couldn't fetch {img}'s children") }; for (var, ptr) in preimg.iter().zip(preimg_ptrs.iter()) { diff --git a/src/lem/store.rs b/src/lem/store.rs index 37c0471d74..e27b887f08 100644 --- a/src/lem/store.rs +++ b/src/lem/store.rs @@ -104,6 +104,44 @@ impl Default for Store { } } +// These are utility macros for store methods on `Ptr`s, especially because +// they contain two const generic variables (more on this later) +macro_rules! count { + () => (0); + ( $_x:tt $($xs:tt)* ) => (1 + crate::lem::store::count!($($xs)*)); +} +pub(crate) use count; + +macro_rules! intern_ptrs { + ($store:expr, $tag:expr, $($ptrs:expr),*) => {{ + const N: usize = crate::lem::store::count!($($ptrs)*); + ($store).intern_ptrs::<{2*N}, N>($tag, [$($ptrs),*]) + }} +} +pub(crate) use intern_ptrs; + +macro_rules! intern_ptrs_hydrated { + ($store:expr, $tag:expr, $z:expr, $($ptrs:expr),*) => {{ + const N: usize = crate::lem::store::count!($($ptrs)*); + ($store).intern_ptrs_hydrated::<{2*N}, N>($tag, [$($ptrs),*], $z) + }} +} +pub(crate) use intern_ptrs_hydrated; + +macro_rules! fetch_ptrs { + ($store:expr, $n:expr, $idx:expr) => {{ + ($store).fetch_ptrs::<{ 2 * $n }, $n>($idx) + }}; +} +pub(crate) use fetch_ptrs; + +macro_rules! expect_ptrs { + ($store:expr, $n:expr, $idx:expr) => {{ + ($store).expect_ptrs::<{ 2 * $n }, $n>($idx) + }}; +} +pub(crate) use expect_ptrs; + impl Store { /// Cost of poseidon hash with arity 3, including the input #[inline] @@ -157,7 +195,7 @@ impl Store { /// Since the `generic_const_exprs` feature is still unstable, we cannot substitute `N * 2` /// for generic const `P` and remove it completely, so we must keep it and do a dynamic assertion /// that it equals `N * 2`. This is not very ergonomic though, since we must add turbofishes - /// like `::<6, 3>` instead of the simpler `::<3>`. Could we maybe create a macro for these functions? + /// like `::<6, 3>` instead of the simpler `::<3>`. #[inline] pub fn ptrs_to_raw_ptrs(&self, ptrs: &[Ptr; P]) -> [RawPtr; N] { assert_eq!(P * 2, N); @@ -257,10 +295,10 @@ impl Store { &self, tag: Tag, ptrs: [Ptr; P], - z: FWrap, + z: ZPtr, ) -> Ptr { let raw_ptrs = self.ptrs_to_raw_ptrs::(&ptrs); - let payload = self.intern_raw_ptrs_hydrated::(raw_ptrs, z); + let payload = self.intern_raw_ptrs_hydrated::(raw_ptrs, FWrap(*z.value())); Ptr::new(tag, payload) } @@ -311,64 +349,6 @@ impl Store { .expect("Index missing from store") } - // TODO eventually deprecate these functions - #[inline] - pub fn intern_2_ptrs(&self, tag: Tag, a: Ptr, b: Ptr) -> Ptr { - self.intern_ptrs::<4, 2>(tag, [a, b]) - } - #[inline] - pub fn intern_3_ptrs(&self, tag: Tag, a: Ptr, b: Ptr, c: Ptr) -> Ptr { - self.intern_ptrs::<6, 3>(tag, [a, b, c]) - } - #[inline] - pub fn intern_4_ptrs(&self, tag: Tag, a: Ptr, b: Ptr, c: Ptr, d: Ptr) -> Ptr { - self.intern_ptrs::<8, 4>(tag, [a, b, c, d]) - } - #[inline] - pub fn intern_2_ptrs_hydrated(&self, tag: Tag, a: Ptr, b: Ptr, z: ZPtr) -> Ptr { - self.intern_ptrs_hydrated::<4, 2>(tag, [a, b], FWrap(*z.value())) - } - #[inline] - pub fn intern_3_ptrs_hydrated(&self, tag: Tag, a: Ptr, b: Ptr, c: Ptr, z: ZPtr) -> Ptr { - self.intern_ptrs_hydrated::<6, 3>(tag, [a, b, c], FWrap(*z.value())) - } - #[inline] - pub fn intern_4_ptrs_hydrated( - &self, - tag: Tag, - a: Ptr, - b: Ptr, - c: Ptr, - d: Ptr, - z: ZPtr, - ) -> Ptr { - self.intern_ptrs_hydrated::<8, 4>(tag, [a, b, c, d], FWrap(*z.value())) - } - #[inline] - pub fn fetch_2_ptrs(&self, idx: usize) -> Option<[Ptr; 2]> { - self.fetch_ptrs::<4, 2>(idx) - } - #[inline] - pub fn fetch_3_ptrs(&self, idx: usize) -> Option<[Ptr; 3]> { - self.fetch_ptrs::<6, 3>(idx) - } - #[inline] - pub fn fetch_4_ptrs(&self, idx: usize) -> Option<[Ptr; 4]> { - self.fetch_ptrs::<8, 4>(idx) - } - #[inline] - pub fn expect_2_ptrs(&self, idx: usize) -> [Ptr; 2] { - self.fetch_2_ptrs(idx).expect("Index missing from store") - } - #[inline] - pub fn expect_3_ptrs(&self, idx: usize) -> [Ptr; 3] { - self.fetch_3_ptrs(idx).expect("Index missing from store") - } - #[inline] - pub fn expect_4_ptrs(&self, idx: usize) -> [Ptr; 4] { - self.fetch_4_ptrs(idx).expect("Index missing from store") - } - #[inline] pub fn tag(&self, tag: Tag) -> RawPtr { self.intern_raw_atom(tag.to_field()) @@ -446,8 +426,7 @@ impl Store { } else { let empty_str = Ptr::new(Tag::Expr(Str), self.raw_zero()); let ptr = s.chars().rev().fold(empty_str, |acc, c| { - let ptrs = [self.char(c), acc]; - self.intern_ptrs::<4, 2>(Tag::Expr(Str), ptrs) + intern_ptrs!(self, Tag::Expr(Str), self.char(c), acc) }); self.string_ptr_cache.insert(s.to_string(), Box::new(ptr)); self.ptr_string_cache.insert(ptr, s.to_string()); @@ -496,8 +475,7 @@ impl Store { pub fn intern_symbol_path(&self, path: &[String]) -> Ptr { let zero_sym = Ptr::new(Tag::Expr(Sym), self.raw_zero()); path.iter().fold(zero_sym, |acc, s| { - let ptrs = [self.intern_string(s), acc]; - self.intern_ptrs::<4, 2>(Tag::Expr(Sym), ptrs) + intern_ptrs!(self, Tag::Expr(Sym), self.intern_string(s), acc) }) } @@ -673,14 +651,12 @@ impl Store { #[inline] pub fn cons(&self, car: Ptr, cdr: Ptr) -> Ptr { - let ptrs = [car, cdr]; - self.intern_ptrs::<4, 2>(Tag::Expr(Cons), ptrs) + intern_ptrs!(self, Tag::Expr(Cons), car, cdr) } #[inline] pub fn intern_fun(&self, arg: Ptr, body: Ptr, env: Ptr) -> Ptr { - let ptrs = [arg, body, env, self.dummy()]; - self.intern_ptrs::<8, 4>(Tag::Expr(Fun), ptrs) + intern_ptrs!(self, Tag::Expr(Fun), arg, body, env, self.dummy()) } #[inline] @@ -1120,7 +1096,7 @@ impl Ptr { Fun => match self.raw().get_hash8() { None => "".into(), Some(idx) => { - if let Some([vars, body, _, _]) = store.fetch_ptrs::<8, 4>(idx) { + if let Some([vars, body, _, _]) = fetch_ptrs!(store, 4, idx) { match vars.tag() { Tag::Expr(Nil) => { format!("", body.fmt_to_string(store, state)) @@ -1142,7 +1118,7 @@ impl Ptr { Thunk => match self.raw().get_hash4() { None => "".into(), Some(idx) => { - if let Some([val, cont]) = store.fetch_ptrs::<4, 2>(idx) { + if let Some([val, cont]) = fetch_ptrs!(store, 2, idx) { format!( "Thunk{{ value: {} => cont: {} }}", val.fmt_to_string(store, state), @@ -1167,7 +1143,7 @@ impl Ptr { Cproc => match self.raw().get_hash4() { None => "".into(), Some(idx) => { - if let Some([cproc_name, args]) = store.fetch_ptrs::<4, 2>(idx) { + if let Some([cproc_name, args]) = fetch_ptrs!(store, 2, idx) { format!( "", cproc_name.fmt_to_string(store, state), @@ -1229,7 +1205,7 @@ impl Ptr { match self.raw().get_hash8() { None => format!(""), Some(idx) => { - if let Some([a, cont, _, _]) = store.fetch_ptrs::<8, 4>(idx) { + if let Some([a, cont, _, _]) = fetch_ptrs!(store, 4, idx) { format!( "{name}{{ {field}: {}, continuation: {} }}", a.fmt_to_string(store, state), @@ -1252,7 +1228,7 @@ impl Ptr { match self.raw().get_hash8() { None => format!(""), Some(idx) => { - if let Some([a, b, cont, _]) = store.fetch_ptrs::<8, 4>(idx) { + if let Some([a, b, cont, _]) = fetch_ptrs!(store, 4, idx) { let (fa, fb) = fields; format!( "{name}{{ {fa}: {}, {fb}: {}, continuation: {} }}", @@ -1277,7 +1253,7 @@ impl Ptr { match self.raw().get_hash8() { None => format!(""), Some(idx) => { - if let Some([a, b, c, cont]) = store.fetch_ptrs::<8, 4>(idx) { + if let Some([a, b, c, cont]) = fetch_ptrs!(store, 4, idx) { let (fa, fb, fc) = fields; format!( "{name}{{ {fa}: {}, {fb}: {}, {fc}: {}, continuation: {} }}", @@ -1394,17 +1370,17 @@ mod tests { &store.poseidon_cache.hash3(&[zero; 3]) ); - let ptr2 = store.intern_2_ptrs(zero_tag, foo, foo); + let ptr2 = intern_ptrs!(store, zero_tag, foo, foo); let z_ptr2 = store.hash_ptr(&ptr2); assert_eq!(z_ptr2.tag(), &zero_tag); assert_eq!(z_ptr2.value(), &store.poseidon_cache.hash4(&[zero; 4])); - let ptr3 = store.intern_3_ptrs(zero_tag, foo, foo, foo); + let ptr3 = intern_ptrs!(store, zero_tag, foo, foo, foo); let z_ptr3 = store.hash_ptr(&ptr3); assert_eq!(z_ptr3.tag(), &zero_tag); assert_eq!(z_ptr3.value(), &store.poseidon_cache.hash6(&[zero; 6])); - let ptr4 = store.intern_4_ptrs(zero_tag, foo, foo, foo, foo); + let ptr4 = intern_ptrs!(store, zero_tag, foo, foo, foo, foo); let z_ptr4 = store.hash_ptr(&ptr4); assert_eq!(z_ptr4.tag(), &zero_tag); assert_eq!(z_ptr4.value(), &store.poseidon_cache.hash8(&[zero; 8])); diff --git a/src/lem/tests/nivc_steps.rs b/src/lem/tests/nivc_steps.rs index fe741e0d57..c1843d96c1 100644 --- a/src/lem/tests/nivc_steps.rs +++ b/src/lem/tests/nivc_steps.rs @@ -5,7 +5,7 @@ use crate::{ eval::lang::Lang, lem::{ eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, - store::Store, + store::{expect_ptrs, intern_ptrs, Store}, Tag, }, state::user_sym, @@ -78,12 +78,13 @@ fn test_nivc_steps() { let expr = cproc_input.pop().unwrap(); let idx = expr.get_index2().unwrap(); - let [_, args] = store.expect_2_ptrs(idx); + let [_, args] = expect_ptrs!(store, 2, idx); let new_name = user_sym("cproc-dumb-not"); - let new_expr = store.intern_2_ptrs( + let new_expr = intern_ptrs!( + store, Tag::Expr(ExprTag::Cproc), store.intern_symbol(&new_name), - args, + args ); // `cproc` can't reduce the altered cproc input (with the wrong name) diff --git a/src/proof/tests/nova_tests_lem.rs b/src/proof/tests/nova_tests_lem.rs index 8867f589fd..b0ed617390 100644 --- a/src/proof/tests/nova_tests_lem.rs +++ b/src/proof/tests/nova_tests_lem.rs @@ -4,7 +4,10 @@ use std::{cell::RefCell, rc::Rc, sync::Arc}; use crate::{ eval::lang::{Coproc, Lang}, - lem::{store::Store, Tag}, + lem::{ + store::{intern_ptrs, Store}, + Tag, + }, num::Num, proof::nova::C1LEM, state::user_sym, @@ -3786,7 +3789,7 @@ fn test_prove_call_literal_fun() { let empty_env = s.intern_nil(); let args = s.list(vec![s.intern_user_symbol("x")]); let body = s.read_with_default_state("(+ x 1)").unwrap(); - let fun = s.intern_4_ptrs(Tag::Expr(ExprTag::Fun), args, body, empty_env, s.dummy()); + let fun = intern_ptrs!(s, Tag::Expr(ExprTag::Fun), args, body, empty_env, s.dummy()); let input = s.num_u64(9); let expr = s.list(vec![fun, input]); let res = s.num_u64(10);