From f7b6331dfc8ac3f5e3c1addd967cd8954a2224a2 Mon Sep 17 00:00:00 2001 From: Rigidity <35380458+Rigidity@users.noreply.github.com> Date: Thu, 10 Aug 2023 09:43:00 -0400 Subject: [PATCH] Remove empty tuple from SExp (#335) --- src/allocator.rs | 26 +++++++++++++------------- src/core_ops.rs | 4 ++-- src/more_ops.rs | 2 +- src/op_utils.rs | 12 ++++++------ src/run_program.rs | 4 ++-- src/serde/object_cache.rs | 6 +++--- src/serde/ser.rs | 2 +- src/serde/ser_br.rs | 2 +- src/test_ops.rs | 2 +- src/traverse_path.rs | 2 +- wasm/src/lazy_node.rs | 2 +- wheel/src/lazy_node.rs | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 71f2a89a..9e8b79fb 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -6,7 +6,7 @@ use bls12_381::{G1Affine, G1Projective, G2Affine, G2Projective}; pub type NodePtr = i32; pub enum SExp { - Atom(), + Atom, Pair(NodePtr, NodePtr), } @@ -252,7 +252,7 @@ impl Allocator { pub fn g1(&self, node: NodePtr) -> Result { let blob = match self.sexp(node) { - SExp::Atom() => self.atom(node), + SExp::Atom => self.atom(node), _ => { return err(node, "pair found, expected G1 point"); } @@ -271,7 +271,7 @@ impl Allocator { pub fn g2(&self, node: NodePtr) -> Result { let blob = match self.sexp(node) { - SExp::Atom() => self.atom(node), + SExp::Atom => self.atom(node), _ => { return err(node, "pair found, expected G2 point"); } @@ -293,7 +293,7 @@ impl Allocator { let pair = self.pair_vec[node as usize]; SExp::Pair(pair.first, pair.rest) } else { - SExp::Atom() + SExp::Atom } } @@ -305,7 +305,7 @@ impl Allocator { pub fn next(&self, n: NodePtr) -> Option<(NodePtr, NodePtr)> { match self.sexp(n) { SExp::Pair(first, rest) => Some((first, rest)), - SExp::Atom() => None, + SExp::Atom => None, } } @@ -385,7 +385,7 @@ fn test_null() { assert_eq!(a.atom(a.null()), b""); let buf = match a.sexp(a.null()) { - SExp::Atom() => a.atom(a.null()), + SExp::Atom => a.atom(a.null()), SExp::Pair(_, _) => panic!("unexpected"), }; assert_eq!(buf, b""); @@ -397,7 +397,7 @@ fn test_one() { assert_eq!(a.atom(a.one()), b"\x01"); assert_eq!( match a.sexp(a.one()) { - SExp::Atom() => a.atom(a.one()), + SExp::Atom => a.atom(a.one()), SExp::Pair(_, _) => panic!("unexpected"), }, b"\x01" @@ -411,7 +411,7 @@ fn test_allocate_atom() { assert_eq!(a.atom(atom), b"foobar"); assert_eq!( match a.sexp(atom) { - SExp::Atom() => a.atom(atom), + SExp::Atom => a.atom(atom), SExp::Pair(_, _) => panic!("unexpected"), }, b"foobar" @@ -427,7 +427,7 @@ fn test_allocate_pair() { assert_eq!( match a.sexp(pair) { - SExp::Atom() => panic!("unexpected"), + SExp::Atom => panic!("unexpected"), SExp::Pair(left, right) => (left, right), }, (atom1, atom2) @@ -436,7 +436,7 @@ fn test_allocate_pair() { let pair2 = a.new_pair(pair, pair).unwrap(); assert_eq!( match a.sexp(pair2) { - SExp::Atom() => panic!("unexpected"), + SExp::Atom => panic!("unexpected"), SExp::Pair(left, right) => (left, right), }, (pair, pair) @@ -552,21 +552,21 @@ fn test_sexp() { assert_eq!( match a.sexp(atom1) { - SExp::Atom() => 0, + SExp::Atom => 0, SExp::Pair(_, _) => 1, }, 0 ); assert_eq!( match a.sexp(atom2) { - SExp::Atom() => 0, + SExp::Atom => 0, SExp::Pair(_, _) => 1, }, 0 ); assert_eq!( match a.sexp(pair) { - SExp::Atom() => 0, + SExp::Atom => 0, SExp::Pair(_, _) => 1, }, 1 diff --git a/src/core_ops.rs b/src/core_ops.rs index aef787de..288981a7 100644 --- a/src/core_ops.rs +++ b/src/core_ops.rs @@ -56,7 +56,7 @@ pub fn op_raise(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response // as it'd potentially look the same as a throw of multiple arguments. let throw_value = if let Ok([value]) = get_args::<1>(a, input, "") { match a.sexp(value) { - SExp::Atom() => value, + SExp::Atom => value, _ => input, } } else { @@ -67,7 +67,7 @@ pub fn op_raise(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response } fn ensure_atom(a: &Allocator, n: NodePtr, op: &str) -> Result<(), EvalErr> { - if let SExp::Atom() = a.sexp(n) { + if let SExp::Atom = a.sexp(n) { Ok(()) } else { Err(EvalErr(n, format!("{op} on list"))) diff --git a/src/more_ops.rs b/src/more_ops.rs index e02cd3a4..ffea2185 100644 --- a/src/more_ops.rs +++ b/src/more_ops.rs @@ -551,7 +551,7 @@ pub fn op_concat(a: &mut Allocator, mut input: NodePtr, max_cost: Cost) -> Respo )?; match a.sexp(arg) { SExp::Pair(_, _) => return err(arg, "concat on list"), - SExp::Atom() => total_size += a.atom_len(arg), + SExp::Atom => total_size += a.atom_len(arg), }; terms.push(arg); } diff --git a/src/op_utils.rs b/src/op_utils.rs index 9962e83f..0fae2cbe 100644 --- a/src/op_utils.rs +++ b/src/op_utils.rs @@ -158,7 +158,7 @@ fn test_get_varargs() { pub fn nullp(a: &Allocator, n: NodePtr) -> bool { match a.sexp(n) { - SExp::Atom() => a.atom_len(n) == 0, + SExp::Atom => a.atom_len(n) == 0, _ => false, } } @@ -222,7 +222,7 @@ fn test_rest() { pub fn int_atom(a: &Allocator, args: NodePtr, op_name: &str) -> Result<(Number, usize), EvalErr> { match a.sexp(args) { - SExp::Atom() => Ok((a.number(args), a.atom_len(args))), + SExp::Atom => Ok((a.number(args), a.atom_len(args))), _ => err(args, &format!("{op_name} requires int args")), } } @@ -254,7 +254,7 @@ fn test_int_atom_failure() { pub fn atom_len(a: &Allocator, args: NodePtr, op_name: &str) -> Result { match a.sexp(args) { - SExp::Atom() => Ok(a.atom_len(args)), + SExp::Atom => Ok(a.atom_len(args)), _ => err(args, &format!("{op_name} requires an atom")), } } @@ -281,7 +281,7 @@ pub fn uint_atom( op_name: &str, ) -> Result { let bytes = match a.sexp(args) { - SExp::Atom() => a.atom(args), + SExp::Atom => a.atom(args), _ => { return err(args, &format!("{op_name} requires int arg")); } @@ -409,7 +409,7 @@ fn test_uint_atom_8_pair() { pub fn atom<'a>(a: &'a Allocator, n: NodePtr, op_name: &str) -> Result<&'a [u8], EvalErr> { match a.sexp(n) { - SExp::Atom() => Ok(a.atom(n)), + SExp::Atom => Ok(a.atom(n)), _ => err(n, &format!("{op_name} on list")), } } @@ -534,7 +534,7 @@ fn test_u64_from_bytes() { pub fn i32_atom(a: &Allocator, args: NodePtr, op_name: &str) -> Result { let buf = match a.sexp(args) { - SExp::Atom() => a.atom(args), + SExp::Atom => a.atom(args), _ => { return err(args, &format!("{op_name} requires int32 args")); } diff --git a/src/run_program.rs b/src/run_program.rs index b8c6f002..1c9ad831 100644 --- a/src/run_program.rs +++ b/src/run_program.rs @@ -278,7 +278,7 @@ impl<'a, D: Dialect> RunProgramContext<'a, D> { // put a bunch of ops on op_stack let (op_node, op_list) = match self.allocator.sexp(program) { // the program is just a bitfield path through the env tree - SExp::Atom() => { + SExp::Atom => { let r: Reduction = traverse_path(self.allocator, self.allocator.atom(program), env)?; self.push(r.1)?; @@ -305,7 +305,7 @@ impl<'a, D: Dialect> RunProgramContext<'a, D> { self.account_op_push(); Ok(APPLY_COST) } - SExp::Atom() => self.eval_op_atom(op_node, op_list, env), + SExp::Atom => self.eval_op_atom(op_node, op_list, env), } } diff --git a/src/serde/object_cache.rs b/src/serde/object_cache.rs index 9bcfc0ff..141c21d1 100644 --- a/src/serde/object_cache.rs +++ b/src/serde/object_cache.rs @@ -121,7 +121,7 @@ pub fn treehash( .get_from_cache(&right) .map(|right_value| hash_blobs(&[&[2], left_value, right_value])), }, - SExp::Atom() => Some(hash_blobs(&[&[1], allocator.atom(node)])), + SExp::Atom => Some(hash_blobs(&[&[1], allocator.atom(node)])), } } @@ -142,7 +142,7 @@ pub fn serialized_length( .saturating_add(*right_value) }), }, - SExp::Atom() => { + SExp::Atom => { let buf = allocator.atom(node); let lb: u64 = buf.len().try_into().unwrap_or(u64::MAX); Some(if lb == 0 || (lb == 1 && buf[0] < 128) { @@ -192,7 +192,7 @@ fn calculate_depth_simple( .get_from_cache(&right) .map(|right_value| 1 + max(*left_value, *right_value)), }, - SExp::Atom() => Some(0), + SExp::Atom => Some(0), } } diff --git a/src/serde/ser.rs b/src/serde/ser.rs index e25468d8..4c86454d 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -43,7 +43,7 @@ pub fn node_to_stream(a: &Allocator, node: NodePtr, f: &mut W) -> while let Some(v) = values.pop() { let n = a.sexp(v); match n { - SExp::Atom() => { + SExp::Atom => { write_atom(f, a.atom(v))?; } SExp::Pair(left, right) => { diff --git a/src/serde/ser_br.rs b/src/serde/ser_br.rs index 08c1ea7f..8598527a 100644 --- a/src/serde/ser_br.rs +++ b/src/serde/ser_br.rs @@ -62,7 +62,7 @@ pub fn node_to_stream_backrefs( read_op_stack.push(ReadOp::Parse); read_op_stack.push(ReadOp::Parse); } - SExp::Atom() => { + SExp::Atom => { let atom = allocator.atom(node_to_write); write_atom(f, atom)?; read_cache_lookup.push(*node_tree_hash); diff --git a/src/test_ops.rs b/src/test_ops.rs index f604154f..ad6bf454 100644 --- a/src/test_ops.rs +++ b/src/test_ops.rs @@ -178,7 +178,7 @@ pub fn node_eq(allocator: &Allocator, s1: NodePtr, s2: NodePtr) -> bool { (SExp::Pair(s1a, s1b), SExp::Pair(s2a, s2b)) => { node_eq(allocator, s1a, s2a) && node_eq(allocator, s1b, s2b) } - (SExp::Atom(), SExp::Atom()) => allocator.atom_eq(s1, s2), + (SExp::Atom, SExp::Atom) => allocator.atom_eq(s1, s2), _ => false, } } diff --git a/src/traverse_path.rs b/src/traverse_path.rs index 0f8c22c7..592a7774 100644 --- a/src/traverse_path.rs +++ b/src/traverse_path.rs @@ -54,7 +54,7 @@ pub fn traverse_path(allocator: &Allocator, node_index: &[u8], args: NodePtr) -> while byte_idx > first_bit_byte_index || bitmask < last_bitmask { let is_bit_set: bool = (node_index[byte_idx] & bitmask) != 0; match allocator.sexp(arg_list) { - SExp::Atom() => { + SExp::Atom => { return Err(EvalErr(arg_list, "path into atom".into())); } SExp::Pair(left, right) => { diff --git a/wasm/src/lazy_node.rs b/wasm/src/lazy_node.rs index 1d18174e..13444653 100644 --- a/wasm/src/lazy_node.rs +++ b/wasm/src/lazy_node.rs @@ -31,7 +31,7 @@ impl LazyNode { #[wasm_bindgen(getter)] pub fn atom(&self) -> Option> { match &self.allocator.sexp(self.node) { - SExp::Atom() => Some(self.allocator.atom(self.node).into()), + SExp::Atom => Some(self.allocator.atom(self.node).into()), _ => None, } } diff --git a/wheel/src/lazy_node.rs b/wheel/src/lazy_node.rs index 350647e9..228df325 100644 --- a/wheel/src/lazy_node.rs +++ b/wheel/src/lazy_node.rs @@ -37,7 +37,7 @@ impl LazyNode { #[getter(atom)] pub fn atom(&self, py: Python) -> Option { match &self.allocator.sexp(self.node) { - SExp::Atom() => Some(PyBytes::new(py, self.allocator.atom(self.node)).into()), + SExp::Atom => Some(PyBytes::new(py, self.allocator.atom(self.node)).into()), _ => None, } }