pub(crate) struct MergeExpressionsOptimizer<F: AcirField> {
resolved_blocks: HashMap<BlockId, BTreeSet<Witness>>,
modified_gates: HashMap<usize, Opcode<F>>,
deleted_gates: BTreeSet<usize>,
}
Fields§
§resolved_blocks: HashMap<BlockId, BTreeSet<Witness>>
§modified_gates: HashMap<usize, Opcode<F>>
§deleted_gates: BTreeSet<usize>
Implementations§
Source§impl<F: AcirField> MergeExpressionsOptimizer<F>
impl<F: AcirField> MergeExpressionsOptimizer<F>
pub(crate) fn new() -> Self
Sourcepub(crate) fn eliminate_intermediate_variable(
&mut self,
circuit: &Circuit<F>,
acir_opcode_positions: Vec<usize>,
) -> (Vec<Opcode<F>>, Vec<usize>)
pub(crate) fn eliminate_intermediate_variable( &mut self, circuit: &Circuit<F>, acir_opcode_positions: Vec<usize>, ) -> (Vec<Opcode<F>>, Vec<usize>)
This pass analyzes the circuit and identifies intermediate variables that are only used in two AssertZero opcodes. It then merges the opcode which produces the intermediate variable into the second one that uses it
The first pass maps witnesses to the index of the opcodes using them. Public inputs are not considered because they cannot be simplified. Witnesses used by MemoryInit opcodes are put in a separate map and marked as used by a Brillig call if the memory block is an input to the call.
The second pass looks for AssertZero opcodes having a witness which is only used by another arithmetic opcode.
In that case, the opcode with the smallest index is merged into the other one via Gaussian elimination.
For instance, if we have ‘w1’ used only by these two opcodes,
5*w2*w3
and w1
:
w2w3 + 2w2 + w1 + w3 = 0 // This opcode ‘defines’ the variable w1
2w3w4 + w1 + w4 = 0 // which is only used here
For w1 we can say: w1 = -1/2w2w3 - w2 - 1/2*w3
Then we will remove the first one and modify the second one like this: 2w3w4 + w4 - w2 - 1/2w3 - 1/2w2*w3 = 0
This transformation is relevant for Plonk-ish backends although they have a limited width because they can potentially handle expressions with large linear combinations using ‘big-add’ gates.
Pre-condition:
- This pass is only relevant for backends that can handle unlimited width
- CSAT pass should have been run prior to this one.
fn for_each_brillig_input_wit( &self, input: &BrilligInputs<F>, f: impl FnMut(Witness), )
fn for_each_brillig_output_wit( &self, output: &BrilligOutputs, f: impl FnMut(Witness), )
fn witness_inputs(&self, opcode: &Opcode<F>) -> BTreeSet<Witness>
fn merge_expression( target: &Expression<F>, expr: &Expression<F>, w: Witness, ) -> Option<Expression<F>>
Sourcefn get_opcode(&self, g: usize, circuit: &Circuit<F>) -> Option<Opcode<F>>
fn get_opcode(&self, g: usize, circuit: &Circuit<F>) -> Option<Opcode<F>>
Returns the ‘updated’ opcode at index ‘g’ in the circuit The modifications to the circuits are stored with ‘deleted_gates’ and ‘modified_gates’ These structures are used to give the ‘updated’ opcode. For instance, if the opcode has been deleted inside ‘deleted_gates’, then it returns None.
Auto Trait Implementations§
impl<F> Freeze for MergeExpressionsOptimizer<F>
impl<F> RefUnwindSafe for MergeExpressionsOptimizer<F>where
F: RefUnwindSafe,
impl<F> Send for MergeExpressionsOptimizer<F>where
F: Send,
impl<F> Sync for MergeExpressionsOptimizer<F>where
F: Sync,
impl<F> Unpin for MergeExpressionsOptimizer<F>where
F: Unpin,
impl<F> UnwindSafe for MergeExpressionsOptimizer<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
] or
a color-specific method, such as [OwoColorize::green
], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
] or
a color-specific method, such as [OwoColorize::on_yellow
], Read more