From b6be6f389e3ed36408081b21e2505c8415714eaa Mon Sep 17 00:00:00 2001 From: Alex Koshelev Date: Mon, 4 Mar 2024 10:56:05 -0800 Subject: [PATCH 1/2] Change boolean debug representation The default one is too verbose. Before: ``` (StdArray([BA32(BitArray { addr: 0x12b842774, head: 000, bits: 32 } [1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])]), StdArray([BA32(BitArray { addr: 0x12b842778, head: 000, bits: 32 } [0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0])])) ``` after ``` (StdArray([BA32([1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1])]), StdArray([BA32([0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0])])) ``` --- ipa-core/src/ff/boolean_array.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ipa-core/src/ff/boolean_array.rs b/ipa-core/src/ff/boolean_array.rs index 78265ca27..2dbbf0b9f 100644 --- a/ipa-core/src/ff/boolean_array.rs +++ b/ipa-core/src/ff/boolean_array.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Formatter}; + use bitvec::{ prelude::{BitArr, Lsb0}, slice::Iter, @@ -254,9 +256,15 @@ macro_rules! boolean_array_impl { type Store = BitArr!(for $bits, in u8, Lsb0); /// A Boolean array with $bits bits. - #[derive(Clone, Copy, PartialEq, Eq, Debug)] + #[derive(Clone, Copy, PartialEq, Eq)] pub struct $name(pub(super) Store); + impl Debug for $name { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}({})", stringify!($name), self.0) + } + } + impl $name { #[cfg(all(test, unit_test))] const STORE_LEN: usize = bitvec::mem::elts::($bits); From e30d1fbf345ccd6fc283c12e5edb517a1ecfd118 Mon Sep 17 00:00:00 2001 From: Alex Koshelev Date: Tue, 5 Mar 2024 21:03:14 -0800 Subject: [PATCH 2/2] Add a test and fix a bug It is always about not having the tests --- ipa-core/src/ff/boolean_array.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ipa-core/src/ff/boolean_array.rs b/ipa-core/src/ff/boolean_array.rs index 2dbbf0b9f..4137d0eeb 100644 --- a/ipa-core/src/ff/boolean_array.rs +++ b/ipa-core/src/ff/boolean_array.rs @@ -261,7 +261,8 @@ macro_rules! boolean_array_impl { impl Debug for $name { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}({})", stringify!($name), self.0) + f.write_str(stringify!($name))?; + self.0.data.fmt(f) } } @@ -705,6 +706,13 @@ macro_rules! boolean_array_impl { "Failed to deserialize a valid value: {ba:?}" ); } + + #[test] + fn debug() { + let expected = format!("{}{:?}", stringify!($name), $name::ZERO.0.data); + let actual = format!("{:?}", $name::ZERO); + assert_eq!(expected, actual); + } } }