From 49a0f113a4f42651ed5cc8f6c1d8e41dd0eab1b1 Mon Sep 17 00:00:00 2001 From: Robin Hundt <24554122+robinhundt@users.noreply.github.com> Date: Sat, 24 Feb 2024 20:17:29 +0100 Subject: [PATCH] Added todo --- crates/seec/src/circuit/base_circuit.rs | 81 +++++++++++++------------ 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/crates/seec/src/circuit/base_circuit.rs b/crates/seec/src/circuit/base_circuit.rs index 23e5217..2a3aecf 100644 --- a/crates/seec/src/circuit/base_circuit.rs +++ b/crates/seec/src/circuit/base_circuit.rs @@ -59,19 +59,19 @@ pub enum BaseGate { } #[derive( - Debug, - Default, - Copy, - Clone, - Ord, - PartialOrd, - PartialEq, - Eq, - Hash, - Serialize, - Deserialize, - Pod, - Zeroable, +Debug, +Default, +Copy, +Clone, +Ord, +PartialOrd, +PartialEq, +Eq, +Hash, +Serialize, +Deserialize, +Pod, +Zeroable, )] #[repr(transparent)] pub struct GateId(pub(crate) Idx); @@ -145,7 +145,7 @@ impl BaseCircuit { pub fn parent_gates( &self, id: impl Into>, - ) -> impl Iterator> + '_ { + ) -> impl Iterator> + '_ { self.graph .neighbors_directed(id.into().into(), Direction::Incoming) .map(GateId::from) @@ -176,13 +176,13 @@ impl BaseCircuit { &self.graph } - pub fn interactive_iter(&self) -> impl Iterator)> + '_ { + pub fn interactive_iter(&self) -> impl Iterator)> + '_ { self.layer_iter() .visit_sc_inputs() .flat_map(|layer| layer.into_interactive_iter()) } - pub fn iter(&self) -> impl Iterator)> + '_ { + pub fn iter(&self) -> impl Iterator)> + '_ { self.layer_iter() .visit_sc_inputs() .flat_map(|layer| layer.into_iter()) @@ -190,7 +190,7 @@ impl BaseCircuit { } impl BaseCircuit { - #[tracing::instrument(level="trace", skip(self), fields(%from, %to))] + #[tracing::instrument(level = "trace", skip(self), fields(% from, % to))] pub fn add_wire(&mut self, from: GateId, to: GateId) { self.graph.add_edge(from.into(), to.into(), ()); trace!("Added wire"); @@ -213,7 +213,7 @@ impl BaseCircuit { pub fn add_sub_circuit( &mut self, circuit: &Self, - inputs: impl IntoIterator>, + inputs: impl IntoIterator>, ) -> Vec> { assert!(!circuit.is_main, "Can't add main circuit as sub circuit"); assert!( @@ -304,9 +304,9 @@ pub enum Load { } impl BaseCircuit -where - Share: Clone, - G: Gate + From> + for<'a> From<&'a bristol::Gate>, + where + Share: Clone, + G: Gate + From> + for<'a> From<&'a bristol::Gate>, { #[tracing::instrument(skip(bristol))] pub fn from_bristol(bristol: bristol::Circuit, load: Load) -> Result { @@ -407,7 +407,7 @@ impl Debug for BaseCircuit { impl BaseGate { pub(crate) fn evaluate_sc_input_simd( &self, - inputs: impl Iterator::Share>, + inputs: impl Iterator::Share>, ) -> <::Share as Share>::SimdShare { let Self::SubCircuitInput(_) = self else { panic!("Called evaluate_sc_input_simd on wrong gate {self:?}"); @@ -449,7 +449,7 @@ impl Gate for BaseGate { fn evaluate_non_interactive( &self, party_id: usize, - mut inputs: impl Iterator, + mut inputs: impl Iterator, ) -> Self::Share { match self { Self::Constant(constant) => { @@ -480,7 +480,7 @@ impl Gate for BaseGate { fn evaluate_non_interactive_simd<'e>( &self, _party_id: usize, - mut inputs: impl Iterator::SimdShare>, + mut inputs: impl Iterator::SimdShare>, ) -> ::SimdShare { match self { BaseGate::Output(_) @@ -512,6 +512,7 @@ pub struct BaseLayerIter<'a, G, Idx: GateIdx, W> { visited: as Visitable>::Map, added_to_next: as Visitable>::Map, // only used for SIMD circuits + // TODO remove entries from hashmap when count recheas 0 inputs_left_to_provide: HashMap, u32>, // (non_interactive, interactive) last_layer_size: (usize, usize), @@ -598,7 +599,7 @@ pub struct CircuitLayer { pub(crate) interactive_ids: Vec>, /// SIMD Gates that can be freed after this layer pub(crate) freeable_gates: Vec>, // TODO add output gates here so that the CircuitLayerIter::next doesn't need to iterate - // over all potential outs + // over all potential outs } impl CircuitLayer { @@ -636,27 +637,27 @@ impl CircuitLayer { } impl CircuitLayer { - pub(crate) fn iter_ids(&self) -> impl Iterator> + '_ { + pub(crate) fn iter_ids(&self) -> impl Iterator> + '_ { self.non_interactive_ids .iter() .chain(&self.interactive_ids) .cloned() } - pub(crate) fn into_interactive_iter(self) -> impl Iterator)> + Clone { + pub(crate) fn into_interactive_iter(self) -> impl Iterator)> + Clone { self.interactive_gates.into_iter().zip(self.interactive_ids) } #[allow(unused)] pub(crate) fn into_non_interactive_iter( self, - ) -> impl Iterator)> + Clone { + ) -> impl Iterator)> + Clone { self.non_interactive_gates .into_iter() .zip(self.non_interactive_ids) } - pub(crate) fn interactive_iter(&self) -> impl Iterator)> + Clone + '_ { + pub(crate) fn interactive_iter(&self) -> impl Iterator)> + Clone + '_ { self.interactive_gates .clone() .into_iter() @@ -665,7 +666,7 @@ impl CircuitLayer { pub(crate) fn non_interactive_iter( &self, - ) -> impl Iterator)> + Clone + '_ { + ) -> impl Iterator)> + Clone + '_ { self.non_interactive_gates .clone() .into_iter() @@ -674,7 +675,7 @@ impl CircuitLayer { } impl CircuitLayer { - pub(crate) fn into_iter(self) -> impl Iterator)> + Clone { + pub(crate) fn into_iter(self) -> impl Iterator)> + Clone { let ni = self .non_interactive_gates .into_iter() @@ -686,7 +687,7 @@ impl CircuitLayer { pub(crate) fn into_sc_iter( self, sc_id: CircuitId, - ) -> impl Iterator)> + Clone { + ) -> impl Iterator)> + Clone { self.into_iter() .map(move |(g, gate_id)| (g, SubCircuitGate::new(sc_id, gate_id))) } @@ -801,8 +802,8 @@ impl GateId { } impl From> for GateId -where - Idx: GateIdx, + where + Idx: GateIdx, { fn from(idx: NodeIndex) -> Self { Self( @@ -821,8 +822,8 @@ impl From> for NodeIndex { } impl From for GateId -where - Idx: TryFrom, + where + Idx: TryFrom, { fn from(val: u16) -> Self { GateId( @@ -834,8 +835,8 @@ where } impl From for GateId -where - Idx: TryFrom, + where + Idx: TryFrom, { fn from(val: u32) -> Self { GateId( @@ -847,8 +848,8 @@ where } impl From for GateId -where - Idx: TryFrom, + where + Idx: TryFrom, { fn from(val: usize) -> Self { GateId(