[][src]Struct wasmtime::Config

pub struct Config { /* fields omitted */ }

Global configuration options used to create an Engine and customize its behavior.

This structure exposed a builder-like interface and is primarily consumed by Engine::new()

Implementations

impl Config[src]

pub fn new() -> Config[src]

Creates a new configuration object with the default configuration specified.

pub fn debug_info(&mut self, enable: bool) -> &mut Self[src]

Configures whether DWARF debug information will be emitted during compilation.

By default this option is false.

pub fn wasm_backtrace_details(
    &mut self,
    enable: WasmBacktraceDetails
) -> &mut Self
[src]

Configures backtraces in Trap will parse debuginfo in the wasm file to have filename/line number information.

When enabled this will causes modules to retain debugging information found in wasm binaries. This debug information will be used when a trap happens to symbolicate each stack frame and attempt to print a filename/line number for each wasm frame in the stack trace.

By default this option is WasmBacktraceDetails::Environment, meaning that wasm will read WASMTIME_BACKTRACE_DETAILS to indicate whether details should be parsed.

pub fn interruptable(&mut self, enable: bool) -> &mut Self[src]

Configures whether functions and loops will be interruptable via the Store::interrupt_handle method.

For more information see the documentation on Store::interrupt_handle.

By default this option is false.

pub fn max_wasm_stack(&mut self, size: usize) -> &mut Self[src]

Configures the maximum amount of native stack space available to executing WebAssembly code.

WebAssembly code currently executes on the native call stack for its own call frames. WebAssembly, however, also has well-defined semantics on stack overflow. This is intended to be a knob which can help configure how much native stack space a wasm module is allowed to consume. Note that the number here is not super-precise, but rather wasm will take at most "pretty close to this much" stack space.

If a wasm call (or series of nested wasm calls) take more stack space than the size specified then a stack overflow trap will be raised.

By default this option is 1 MB.

pub fn wasm_threads(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly threads proposal will be enabled for compilation.

The WebAssembly threads proposal is not currently fully standardized and is undergoing development. Additionally the support in wasmtime itself is still being worked on. Support for this feature can be enabled through this method for appropriate wasm modules.

This feature gates items such as shared memories and atomic instructions. Note that enabling the threads feature will also enable the bulk memory feature.

This is false by default.

Note: Wasmtime does not implement everything for the wasm threads spec at this time, so bugs, panics, and possibly segfaults should be expected. This should not be enabled in a production setting right now.

pub fn wasm_reference_types(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly reference types proposal will be enabled for compilation.

This feature gates items such as the externref and funcref types as well as allowing a module to define multiple tables.

Note that enabling the reference types feature will also enable the bulk memory feature.

This is true by default on x86-64, and false by default on other architectures.

pub fn wasm_simd(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly SIMD proposal will be enabled for compilation.

The WebAssembly SIMD proposal is not currently fully standardized and is undergoing development. Additionally the support in wasmtime itself is still being worked on. Support for this feature can be enabled through this method for appropriate wasm modules.

This feature gates items such as the v128 type and all of its operators being in a module.

This is false by default.

Note: Wasmtime does not implement everything for the wasm simd spec at this time, so bugs, panics, and possibly segfaults should be expected. This should not be enabled in a production setting right now.

pub fn wasm_bulk_memory(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly bulk memory operations proposal will be enabled for compilation.

This feature gates items such as the memory.copy instruction, passive data/table segments, etc, being in a module.

This is true by default.

pub fn wasm_multi_value(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly multi-value proposal will be enabled for compilation.

This feature gates functions and blocks returning multiple values in a module, for example.

This is true by default.

pub fn wasm_multi_memory(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly multi-memory proposal will be enabled for compilation.

This feature gates modules having more than one linear memory declaration or import.

This is false by default.

pub fn wasm_module_linking(&mut self, enable: bool) -> &mut Self[src]

Configures whether the WebAssembly module linking proposal will be enabled for compilation.

Note that development of this feature is still underway, so enabling this is likely to be full of bugs.

This is false by default.

pub fn strategy(&mut self, strategy: Strategy) -> Result<&mut Self>[src]

Configures which compilation strategy will be used for wasm modules.

This method can be used to configure which compiler is used for wasm modules, and for more documentation consult the Strategy enumeration and its documentation.

The default value for this is Strategy::Auto.

Errors

Some compilation strategies require compile-time options of wasmtime itself to be set, but if they're not set and the strategy is specified here then an error will be returned.

pub fn profiler(&mut self, profile: ProfilingStrategy) -> Result<&mut Self>[src]

Creates a default profiler based on the profiling strategy choosen

Profiler creation calls the type's default initializer where the purpose is really just to put in place the type used for profiling.

pub fn cranelift_debug_verifier(&mut self, enable: bool) -> &mut Self[src]

Configures whether the debug verifier of Cranelift is enabled or not.

When Cranelift is used as a code generation backend this will configure it to have the enable_verifier flag which will enable a number of debug checks inside of Cranelift. This is largely only useful for the developers of wasmtime itself.

The default value for this is false

pub fn cranelift_opt_level(&mut self, level: OptLevel) -> &mut Self[src]

Configures the Cranelift code generator optimization level.

When the Cranelift code generator is used you can configure the optimization level used for generated code in a few various ways. For more information see the documentation of OptLevel.

The default value for this is OptLevel::None.

pub fn cranelift_nan_canonicalization(&mut self, enable: bool) -> &mut Self[src]

Configures whether Cranelift should perform a NaN-canonicalization pass.

When Cranelift is used as a code generation backend this will configure it to replace NaNs with a single canonical value. This is useful for users requiring entirely deterministic WebAssembly computation. This is not required by the WebAssembly spec, so it is not enabled by default.

The default value for this is false

pub unsafe fn cranelift_other_flag(
    &mut self,
    name: &str,
    value: &str
) -> Result<&mut Self>
[src]

Allows settings another Cranelift flag defined by a flag name and value. This allows fine-tuning of Cranelift settings.

Since Cranelift flags may be unstable, this method should not be considered to be stable either; other Config functions should be preferred for stability.

Note that this is marked as unsafe, because setting the wrong flag might break invariants, resulting in execution hazards.

Errors

This method can fail if the flag's name does not exist, or the value is not appropriate for the flag type.

pub fn cache_config_load(&mut self, path: impl AsRef<Path>) -> Result<&mut Self>[src]

Loads cache configuration specified at path.

This method will read the file specified by path on the filesystem and attempt to load cache configuration from it. This method can also fail due to I/O errors, misconfiguration, syntax errors, etc. For expected syntax in the configuration file see the documentation online.

By default cache configuration is not enabled or loaded.

This method is only available when the cache feature of this crate is enabled.

Errors

This method can fail due to any error that happens when loading the file pointed to by path and attempting to load the cache configuration.

pub fn cache_config_load_default(&mut self) -> Result<&mut Self>[src]

Loads cache configuration from the system default path.

This commit is the same as Config::cache_config_load except that it does not take a path argument and instead loads the default configuration present on the system. This is located, for example, on Unix at $HOME/.config/wasmtime/config.toml and is typically created with the wasmtime config new command.

By default cache configuration is not enabled or loaded.

This method is only available when the cache feature of this crate is enabled.

Errors

This method can fail due to any error that happens when loading the default system configuration. Note that it is not an error if the default config file does not exist, in which case the default settings for an enabled cache are applied.

pub fn with_host_memory(
    &mut self,
    mem_creator: Arc<dyn MemoryCreator>
) -> &mut Self
[src]

Sets a custom memory creator

pub fn static_memory_maximum_size(&mut self, max_size: u64) -> &mut Self[src]

Configures the maximum size, in bytes, where a linear memory is considered static, above which it'll be considered dynamic.

This function configures the threshold for wasm memories whether they're implemented as a dynamically relocatable chunk of memory or a statically located chunk of memory. The max_size parameter here is the size, in bytes, where if the maximum size of a linear memory is below max_size then it will be statically allocated with enough space to never have to move. If the maximum size of a linear memory is larger than max_size then wasm memory will be dynamically located and may move in memory through growth operations.

Specifying a max_size of 0 means that all memories will be dynamic and may be relocated through memory.grow. Also note that if any wasm memory's maximum size is below max_size then it will still reserve max_size bytes in the virtual memory space.

Static vs Dynamic Memory

Linear memories represent contiguous arrays of bytes, but they can also be grown through the API and wasm instructions. When memory is grown if space hasn't been preallocated then growth may involve relocating the base pointer in memory. Memories in Wasmtime are classified in two different ways:

  • static - these memories preallocate all space necessary they'll ever need, meaning that the base pointer of these memories is never moved. Static memories may take more virtual memory space because of pre-reserving space for memories.

  • dynamic - these memories are not preallocated and may move during growth operations. Dynamic memories consume less virtual memory space because they don't need to preallocate space for future growth.

Static memories can be optimized better in JIT code because once the base address is loaded in a function it's known that we never need to reload it because it never changes, memory.grow is generally a pretty fast operation because the wasm memory is never relocated, and under some conditions bounds checks can be elided on memory accesses.

Dynamic memories can't be quite as heavily optimized because the base address may need to be reloaded more often, they may require relocating lots of data on memory.grow, and dynamic memories require unconditional bounds checks on all memory accesses.

Should you use static or dynamic memory?

In general you probably don't need to change the value of this property. The defaults here are optimized for each target platform to consume a reasonable amount of physical memory while also generating speedy machine code.

One of the main reasons you may want to configure this today is if your environment can't reserve virtual memory space for each wasm linear memory. On 64-bit platforms wasm memories require a 6GB reservation by default, and system limits may prevent this in some scenarios. In this case you may wish to force memories to be allocated dynamically meaning that the virtual memory footprint of creating a wasm memory should be exactly what's used by the wasm itself.

For 32-bit memories a static memory must contain at least 4GB of reserved address space plus a guard page to elide any bounds checks at all. Smaller static memories will use similar bounds checks as dynamic memories.

Default

The default value for this property depends on the host platform. For 64-bit platforms there's lots of address space available, so the default configured here is 4GB. WebAssembly linear memories currently max out at 4GB which means that on 64-bit platforms Wasmtime by default always uses a static memory. This, coupled with a sufficiently sized guard region, should produce the fastest JIT code on 64-bit platforms, but does require a large address space reservation for each wasm memory.

For 32-bit platforms this value defaults to 1GB. This means that wasm memories whose maximum size is less than 1GB will be allocated statically, otherwise they'll be considered dynamic.

pub fn static_memory_guard_size(&mut self, guard_size: u64) -> &mut Self[src]

Configures the size, in bytes, of the guard region used at the end of a static memory's address space reservation.

All WebAssembly loads/stores are bounds-checked and generate a trap if they're out-of-bounds. Loads and stores are often very performance critical, so we want the bounds check to be as fast as possible! Accelerating these memory accesses is the motivation for a guard after a memory allocation.

Memories (both static and dynamic) can be configured with a guard at the end of them which consists of unmapped virtual memory. This unmapped memory will trigger a memory access violation (e.g. segfault) if accessed. This allows JIT code to elide bounds checks if it can prove that an access, if out of bounds, would hit the guard region. This means that having such a guard of unmapped memory can remove the need for bounds checks in JIT code.

For the difference between static and dynamic memories, see the Config::static_memory_maximum_size.

How big should the guard be?

In general, like with configuring static_memory_maximum_size, you probably don't want to change this value from the defaults. Otherwise, though, the size of the guard region affects the number of bounds checks needed for generated wasm code. More specifically, loads/stores with immediate offsets will generate bounds checks based on how big the guard page is.

For 32-bit memories a 4GB static memory is required to even start removing bounds checks. A 4GB guard size will guarantee that the module has zero bounds checks for memory accesses. A 2GB guard size will eliminate all bounds checks with an immediate offset less than 2GB. A guard size of zero means that all memory accesses will still have bounds checks.

Default

The default value for this property is 2GB on 64-bit platforms. This allows eliminating almost all bounds checks on loads/stores with an immediate offset of less than 2GB. On 32-bit platforms this defaults to 64KB.

Static vs Dynamic Guard Size

Note that for now the static memory guard size must be at least as large as the dynamic memory guard size, so configuring this property to be smaller than the dynamic memory guard size will have no effect.

pub fn dynamic_memory_guard_size(&mut self, guard_size: u64) -> &mut Self[src]

Configures the size, in bytes, of the guard region used at the end of a dynamic memory's address space reservation.

For the difference between static and dynamic memories, see the Config::static_memory_maximum_size

For more information about what a guard is, see the documentation on Config::static_memory_guard_size.

Note that the size of the guard region for dynamic memories is not super critical for performance. Making it reasonably-sized can improve generated code slightly, but for maximum performance you'll want to lean towards static memories rather than dynamic anyway.

Also note that the dynamic memory guard size must be smaller than the static memory guard size, so if a large dynamic memory guard is specified then the static memory guard size will also be automatically increased.

Default

This value defaults to 64KB.

Trait Implementations

impl Clone for Config[src]

impl Debug for Config[src]

impl Default for Config[src]

Auto Trait Implementations

impl !RefUnwindSafe for Config

impl Send for Config

impl Sync for Config

impl Unpin for Config

impl !UnwindSafe for Config

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.