pub struct OptimizationOptions {
    pub reader: ReaderOptions,
    pub writer: WriterOptions,
    pub inlining: InliningOptions,
    pub passopts: PassOptions,
    pub passes: Passes,
    pub features: Features,
    pub converge: bool,
}
Expand description

Optimization options and optimization builder.

This type declares all supported Binaryen options. It can be modified directly or by its builder-pattern methods.

Call OptimizationOptions::run to perform the optimizations.

Fields§

§reader: ReaderOptions

Options for reading the unoptimized wasm module.

§writer: WriterOptions

Options for writing the optimized wasm module.

§inlining: InliningOptions

Options related to inlining.

§passopts: PassOptions

Options that affect how optimization passes behave.

§passes: Passes

The set of optimization passes to apply.

§features: Features

The set of wasm-features.

§converge: bool

Run passes to convergence, continuing while binary size decreases.

Implementations§

source§

impl OptimizationOptions

Constructors.

source

pub fn new_optimize_for_size() -> Self

Optimize for size.

This corresponds to the -Os argument to wasm-opt, and also the -O argument to wasm-opt.

It applies

source

pub fn new_optimize_for_size_aggressively() -> Self

Optimize for size, but even more.

It applies

This corresponds to the -Oz argument to wasm-opt.

source

pub fn new_opt_level_0() -> Self

Do not optimize.

It applies

It adds no default passes.

This corresponds to the -O0 argument to wasm-opt, and also to calling wasm-opt with no -O* optional at all.

source

pub fn new_opt_level_1() -> Self

Apply basic optimizations.

Useful for fast iteration.

It applies

This corresponds to the -O1 argument to wasm-opt.

source

pub fn new_opt_level_2() -> Self

Apply most optimizations.

This level of optimization is appropriate for most applications. Higher optimization levels will not necessarily yield better performance, but will take longer to optimize.

It applies

This corresponds to the -O2 argument to wasm-opt.

source

pub fn new_opt_level_3() -> Self

Apply slower optimizations.

Spends potentially a lot of time on optimizations.

It applies

This corresponds to the -O3 argument to wasm-opt.

source

pub fn new_opt_level_4() -> Self

Apply the most aggressive optimizations.

Flattens the IR, which can take a lot of time and memory, but may be useful on nested / complex / less-optimized input.

It applies

This corresponds to the -O4 argument to wasm-opt.

source§

impl OptimizationOptions

Builder methods.

source

pub fn reader_file_type(&mut self, value: FileType) -> &mut Self

source

pub fn writer_file_type(&mut self, value: FileType) -> &mut Self

source

pub fn set_converge(&mut self) -> &mut Self

source

pub fn always_inline_max_size(&mut self, value: u32) -> &mut Self

source

pub fn one_caller_inline_max_size(&mut self, value: u32) -> &mut Self

source

pub fn flexible_inline_max_size(&mut self, value: u32) -> &mut Self

source

pub fn allow_functions_with_loops(&mut self, value: bool) -> &mut Self

source

pub fn partial_inlining_ifs(&mut self, value: u32) -> &mut Self

source

pub fn validate(&mut self, value: bool) -> &mut Self

source

pub fn validate_globally(&mut self, value: bool) -> &mut Self

source

pub fn optimize_level(&mut self, value: OptimizeLevel) -> &mut Self

source

pub fn shrink_level(&mut self, value: ShrinkLevel) -> &mut Self

source

pub fn traps_never_happen(&mut self, value: bool) -> &mut Self

source

pub fn low_memory_unused(&mut self, value: bool) -> &mut Self

source

pub fn fast_math(&mut self, value: bool) -> &mut Self

source

pub fn zero_filled_memory(&mut self, value: bool) -> &mut Self

source

pub fn debug_info(&mut self, value: bool) -> &mut Self

source

pub fn set_pass_arg(&mut self, key: &str, value: &str) -> &mut Self

Adds a pass argument to PassOptions::arguments.

source

pub fn add_default_passes(&mut self, value: bool) -> &mut Self

source

pub fn add_pass(&mut self, value: Pass) -> &mut Self

Adds a pass to Passes::more_passes.

source

pub fn mvp_features_only(&mut self) -> &mut Self

Sets the baseline feature set to FeatureBaseline::MvpOnly.

source

pub fn all_features(&mut self) -> &mut Self

Sets the baseline feature set to FeatureBaseline::All.

source

pub fn enable_feature(&mut self, feature: Feature) -> &mut Self

Enables a feature.

This adds the feature to Features::enabled, and is equivalent to the --enable-{feature} command line arguments.

source

pub fn disable_feature(&mut self, feature: Feature) -> &mut Self

Disables a feature.

This adds the feature to Features::disabled, and is equivalent to the --disable-{feature} command line arguments.

source§

impl OptimizationOptions

Execution.

source

pub fn run( &self, infile: impl AsRef<Path>, outfile: impl AsRef<Path> ) -> Result<(), OptimizationError>

Run the Binaryen wasm optimizer.

This loads a module from a file, runs optimization passes, and writes the module back to a file.

To supply sourcemaps for the input module, and preserve them for the output module, use OptimizationOptions::run_with_sourcemaps.

§Errors

Returns error on I/O failure, or if the input fails to parse. If PassOptions::validate is true, it returns an error if the input module fails to validate, or if the optimized module fails to validate.

The Rust API does not support reading a module on stdin, as the CLI does. If infile is empty or “-”, OptimizationError::InvalidStdinPath is returned.

source

pub fn run_with_sourcemaps( &self, infile: impl AsRef<Path>, infile_sourcemap: Option<impl AsRef<Path>>, outfile: impl AsRef<Path>, outfile_sourcemap: Option<impl AsRef<Path>>, sourcemap_url: Option<impl AsRef<str>> ) -> Result<(), OptimizationError>

Run the Binaryen wasm optimizer.

This loads a module from a file, runs optimization passes, and writes the module back to a file.

The sourcemap arguments are optional, and only have effect when reading or writing binary wasm files. When using text wat files the respective sourcemap argument is ignored.

§Errors

Returns error on I/O failure, or if the input fails to parse. If PassOptions::validate is true, it returns an error if the input module fails to validate, or if the optimized module fails to validate.

The Rust API does not support reading a module on stdin, as the CLI does. If infile is empty or “-”, OptimizationError::InvalidStdinPath is returned.

Trait Implementations§

source§

impl Clone for OptimizationOptions

source§

fn clone(&self) -> OptimizationOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for OptimizationOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.