Struct RangeOptimizer

Source
pub(crate) struct RangeOptimizer<'a, F: AcirField> {
    infos: BTreeMap<Witness, RangeInfo>,
    brillig_side_effects: &'a BTreeMap<BrilligFunctionId, bool>,
    circuit: Circuit<F>,
}

Fields§

§infos: BTreeMap<Witness, RangeInfo>

Maps witnesses to their bit size switch points.

§brillig_side_effects: &'a BTreeMap<BrilligFunctionId, bool>

The next potential side effect for each opcode.

§circuit: Circuit<F>

Implementations§

Source§

impl<'a, F: AcirField> RangeOptimizer<'a, F>

Source

pub(crate) fn new( circuit: Circuit<F>, brillig_side_effects: &'a BTreeMap<BrilligFunctionId, bool>, ) -> Self

Creates a new RangeOptimizer by collecting all known range constraints from Circuit.

Source

fn collect_ranges(circuit: &Circuit<F>) -> BTreeMap<Witness, RangeInfo>

Collect range information about witnesses.

Source

pub(crate) fn replace_redundant_ranges( self, order_list: Vec<usize>, ) -> (Circuit<F>, Vec<usize>)

Returns a Circuit where each Witness is only range constrained a minimal number of times that still allows us to avoid executing any new side effects due to their removal.

The idea is to keep only the RANGE opcodes that have strictly smaller bit-size requirements than before, i.e the ones that are at a ‘switch point’. Furthermore, we only keep the switch points that are last before a ‘side-effect’ opcode (i.e a Brillig call). As a result, we simply do a backward pass on the opcodes, so that the last Brillig call is known before reaching a RANGE opcode.

Auto Trait Implementations§

§

impl<'a, F> Freeze for RangeOptimizer<'a, F>

§

impl<'a, F> RefUnwindSafe for RangeOptimizer<'a, F>
where F: RefUnwindSafe,

§

impl<'a, F> Send for RangeOptimizer<'a, F>
where F: Send,

§

impl<'a, F> Sync for RangeOptimizer<'a, F>
where F: Sync,

§

impl<'a, F> Unpin for RangeOptimizer<'a, F>
where F: Unpin,

§

impl<'a, F> UnwindSafe for RangeOptimizer<'a, F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more