A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Enable reflecting most `Config` values through `Engine` (#13671)
Alex Crichtonabcde9b59f4e
diff --git a/.github/workflows/main.yml b/.github/workflows/main.ymlindex 1444c433c0..95fef6981c 100644--- a/.github/workflows/main.yml+++ b/.github/workflows/main.yml@@ -452,6 +452,14 @@ jobs:-p wasmtime-wizer --no-default-features --features component-model-p wasmtime-wizer --no-default-features --features rayon-p wasmtime-wizer --no-default-features --all-features++ - name: wasmtime-cli-flags+ checks: |+ -p wasmtime-cli-flags --no-default-features+ -p wasmtime-cli-flags --no-default-features --features serde+ -p wasmtime-cli-flags --no-default-features --features clap+ -p wasmtime-cli-flags --no-default-features --features toml+ -p wasmtime-cli-flags --no-default-features --all-featuresruns-on: ubuntu-lateststeps:- uses: actions/checkout@v6diff --git a/Cargo.toml b/Cargo.tomlindex 8f895c38b7..86ea424a02 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -45,7 +45,7 @@ doc = false[dependencies]wasmtime = { workspace = true, features = ['std'] }wasmtime-cache = { workspace = true, optional = true }-wasmtime-cli-flags = { workspace = true }+wasmtime-cli-flags = { workspace = true, features = ['clap', 'toml'] }wasmtime-cranelift = { workspace = true, optional = true }wasmtime-environ = { workspace = true }wasmtime-explorer = { workspace = true, optional = true }diff --git a/crates/bench-api/Cargo.toml b/crates/bench-api/Cargo.tomlindex 3a48198681..2509958c2d 100644--- a/crates/bench-api/Cargo.toml+++ b/crates/bench-api/Cargo.toml@@ -25,6 +25,7 @@ wasmtime = { workspace = true, default-features = true, features = ["winch", "puwasmtime-cli-flags = { workspace = true, default-features = true, features = ["cranelift","gc",+ "clap",] }wasmtime-wasi = { workspace = true, features = ['p1', 'p2'] }wasmtime-wasi-nn = { workspace = true, optional = true }diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.tomlindex 6a22e005f1..4187b908bb 100644--- a/crates/cli-flags/Cargo.toml+++ b/crates/cli-flags/Cargo.toml@@ -13,16 +13,29 @@ rust-version.workspace = trueworkspace = true[dependencies]-clap = { workspace = true }+clap = { workspace = true, optional = true }file-per-thread-logger = { workspace = true, optional = true }tracing-subscriber = { workspace = true, optional = true }rayon = { version = "1.5.0", optional = true }wasmtime = { workspace = true }-serde = { workspace = true }-serde_derive = { workspace = true }-toml = { workspace = true }+serde = { workspace = true, optional = true }+serde_derive = { workspace = true, optional = true }+toml = { workspace = true, optional = true }[features]+# ----------------------------------------+# Features specific to this crate itself++# Enable `clap` derives to parse arguments+clap = ["dep:clap"]+# Enable `Serialize`/`Deserialize` derives to parse arguments+serde = ["dep:serde", "dep:serde_derive", "serde/std"]+# Enable loading configuration files serialized with TOML.+toml = ["dep:toml", "serde"]++# ----------------------------------------+# Forwarding features to the `wasmtime` crate, and additionally being able to+# configure various options gated behind these features.async = ["wasmtime/async"]pooling-allocator = ["wasmtime/pooling-allocator"]component-model = ["wasmtime/component-model"]diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rsindex e9e427c0bb..35c309b60a 100644--- a/crates/cli-flags/src/lib.rs+++ b/crates/cli-flags/src/lib.rs@@ -1,15 +1,19 @@-//! Contains the common Wasmtime command line interface (CLI) flags.+//! A utility crate for managing Wasmtime configuration options in a+//! serializable format.+//!+//! This crate primarily provides a [`CommonOptions`] structure which can be+//! parsed from CLI flags via [`clap`] or with [`serde::Deserialize`]. This+//! structure can additionally be created from a [`wasmtime::Engine`] to+//! serialize some of the significant configuration options affecting an engine.+//!+//! This is intended to be a shared way for embedders to configure Wasmtime with+//! serializable configuration. The source of truth for Wasmtime's configuration+//! is the [`Config`] type but this additionally serves as a means of creating+//! that type.-use clap::Parser;-use serde::Deserialize;use std::num::NonZeroUsize;-use std::{- fmt, fs,- num::NonZeroU32,- path::{Path, PathBuf},- time::Duration,-};-use wasmtime::{Config, Result, WasmBacktraceDetails, bail, error::Context as _};+use std::{fmt, num::NonZeroU32, path::PathBuf, time::Duration};+use wasmtime::{Config, Engine, Result, WasmBacktraceDetails, WasmFeatures, bail};pub mod opt;@@ -43,17 +47,17 @@ fn init_file_per_thread_logger(prefix: &'static str) {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct OptimizeOptions {/// Optimization level of generated code (0-2, s; default: 2)#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub opt_level: Option<wasmtime::OptLevel>,/// Register allocator algorithm choice.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub regalloc_algorithm: Option<wasmtime::RegallocAlgorithm>,/// Do not allow Wasm linear memories to move in the host process's@@ -110,7 +114,8 @@ wasmtime_option_group! {/// Enable memory protection keys for the pooling allocator; this can/// optimize the size of memory slots.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub pooling_memory_protection_keys: Option<wasmtime::Enabled>,/// Sets an upper limit on how many memory protection keys (MPK) Wasmtime@@ -211,7 +216,8 @@ wasmtime_option_group! {/// Whether or not `PAGEMAP_SCAN` ioctls are used to reset linear/// memory.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub pooling_pagemap_scan: Option<wasmtime::Enabled>,/// XXX: For internal fuzzing and debugging use only!@@ -225,15 +231,14 @@ wasmtime_option_group! {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct CodegenOptions {/// Either `cranelift` or `winch`.////// Currently only `cranelift` and `winch` are supported, but not all/// builds of Wasmtime have both built in.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub compiler: Option<wasmtime::Strategy>,/// Which garbage collector to use: `drc`, `null`, or `copying`.///@@ -247,7 +252,8 @@ wasmtime_option_group! {/// Note that not all builds of Wasmtime will have support for garbage/// collection included.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub collector: Option<wasmtime::Collector>,/// Enable Cranelift's internal debug verifier (expensive)pub cranelift_debug_verifier: Option<bool>,@@ -263,7 +269,8 @@ wasmtime_option_group! {/// Whether to perform function inlining during compilation.#[serde(default)]- #[serde(deserialize_with = "crate::opt::cli_parse_wrapper")]+ #[serde(deserialize_with = "crate::opt::deserialize_cli_parse_wrapper")]+ #[serde(serialize_with = "crate::opt::serialize_cli_parse_wrapper")]pub inlining: Option<wasmtime::Inlining>,/// Whether or not trap metadata is present for wasm internal assertions@@ -286,8 +293,6 @@ wasmtime_option_group! {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct DebugOptions {/// Enable generation of DWARF debug information in compiled code.pub debug_info: Option<bool>,@@ -329,8 +334,6 @@ wasmtime_option_group! {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct WasmOptions {/// Enable canonicalization of all NaN values.pub nan_canonicalization: Option<bool>,@@ -478,8 +481,6 @@ wasmtime_option_group! {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct WasiOptions {/// Enable support for WASI CLI APIs, including filesystems, sockets, clocks, and random.pub cli: Option<bool>,@@ -580,8 +581,6 @@ wasmtime_option_group! {}wasmtime_option_group! {- #[derive(PartialEq, Clone, Deserialize)]- #[serde(rename_all = "kebab-case", deny_unknown_fields)]pub struct RecordOptions {/// Filename for the recorded execution trace (or empty string to skip writing a file).pub path: Option<String>,@@ -611,8 +610,13 @@ pub struct KeyValuePair {}/// Common options for commands that translate WebAssembly modules-#[derive(Parser, Clone, Deserialize)]-#[serde(deny_unknown_fields)]+#[derive(Clone)]+#[cfg_attr(feature = "clap", derive(clap::Parser))]+#[cfg_attr(+ feature = "serde",+ derive(serde_derive::Deserialize, serde_derive::Serialize)+)]+#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]pub struct CommonOptions {// These options groups are used to parse `-O` and such options but aren't// the raw form consumed by the CLI. Instead they're pushed into the `pub`@@ -623,29 +627,44 @@ pub struct CommonOptions {// now./// Optimization and tuning related options for wasm performance, `-O help` to/// see all.- #[arg(short = 'O', long = "optimize", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'O', long = "optimize", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]opts_raw: Vec<opt::CommaSeparated<Optimize>>,/// Codegen-related configuration options, `-C help` to see all.- #[arg(short = 'C', long = "codegen", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'C', long = "codegen", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]codegen_raw: Vec<opt::CommaSeparated<Codegen>>,/// Debug-related configuration options, `-D help` to see all.- #[arg(short = 'D', long = "debug", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'D', long = "debug", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]debug_raw: Vec<opt::CommaSeparated<Debug>>,/// Options for configuring semantic execution of WebAssembly, `-W help` to see/// all.- #[arg(short = 'W', long = "wasm", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'W', long = "wasm", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]wasm_raw: Vec<opt::CommaSeparated<Wasm>>,/// Options for configuring WASI and its proposals, `-S help` to see all.- #[arg(short = 'S', long = "wasi", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'S', long = "wasi", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]wasi_raw: Vec<opt::CommaSeparated<Wasi>>,/// Options to enable and configure execution recording, `-R help` to see all.@@ -656,43 +675,46 @@ pub struct CommonOptions {////// Note: Minimal configuration options for deterministic Wasm semantics will be/// enforced during recording by default (NaN canonicalization, deterministic relaxed SIMD).- #[arg(short = 'R', long = "record", value_name = "KEY[=VAL[,..]]")]- #[serde(skip)]+ #[cfg_attr(+ feature = "clap",+ arg(short = 'R', long = "record", value_name = "KEY[=VAL[,..]]")+ )]+ #[cfg_attr(feature = "serde", serde(skip))]record_raw: Vec<opt::CommaSeparated<Record>>,// These fields are filled in by the `configure` method below via the// options parsed from the CLI above. This is what the CLI should use.- #[arg(skip)]- #[serde(skip)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(skip))]configured: bool,- #[arg(skip)]- #[serde(rename = "optimize", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(rename = "optimize", default))]pub opts: OptimizeOptions,- #[arg(skip)]- #[serde(rename = "codegen", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(default))]pub codegen: CodegenOptions,- #[arg(skip)]- #[serde(rename = "debug", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(default))]pub debug: DebugOptions,- #[arg(skip)]- #[serde(rename = "wasm", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(default))]pub wasm: WasmOptions,- #[arg(skip)]- #[serde(rename = "wasi", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(default))]pub wasi: WasiOptions,- #[arg(skip)]- #[serde(rename = "record", default)]+ #[cfg_attr(feature = "clap", arg(skip))]+ #[cfg_attr(feature = "serde", serde(default))]pub record: RecordOptions,/// The target triple; default is the host triple- #[arg(long, value_name = "TARGET")]- #[serde(skip)]+ #[cfg_attr(feature = "clap", arg(long, value_name = "TARGET"))]+ #[cfg_attr(feature = "serde", serde(skip))]pub target: Option<String>,/// Use the specified TOML configuration file.@@ -701,8 +723,8 @@ pub struct CommonOptions {////// Additional options specified on the command line will take precedent over options loaded from/// this TOML file.- #[arg(long = "config", value_name = "FILE")]- #[serde(skip)]+ #[cfg_attr(feature = "clap", arg(long = "config", value_name = "FILE"))]+ #[cfg_attr(feature = "serde", serde(skip))]pub config: Option<PathBuf>,}@@ -755,13 +777,23 @@ impl CommonOptions {}self.configured = true;if let Some(toml_config_path) = &self.config {- let toml_options = CommonOptions::from_file(toml_config_path)?;- self.opts = toml_options.opts;- self.codegen = toml_options.codegen;- self.debug = toml_options.debug;- self.wasm = toml_options.wasm;- self.wasi = toml_options.wasi;- self.record = toml_options.record;+ #[cfg(feature = "toml")]+ {+ let toml_options = CommonOptions::from_file(toml_config_path)?;+ self.opts = toml_options.opts;+ self.codegen = toml_options.codegen;+ self.debug = toml_options.debug;+ self.wasm = toml_options.wasm;+ self.wasi = toml_options.wasi;+ self.record = toml_options.record;+ }+ #[cfg(not(feature = "toml"))]+ {+ bail!(+ "support for loading a configuration file from \+ {toml_config_path:?} disabled at compile time"+ );+ }}self.opts.configure_with(&self.opts_raw);self.codegen.configure_with(&self.codegen_raw);@@ -882,7 +914,7 @@ impl CommonOptions {if self.codegen.cache != Some(false) {use wasmtime::Cache;let cache = match &self.codegen.cache_config {- Some(path) => Cache::from_file(Some(Path::new(path)))?,+ Some(path) => Cache::from_file(Some(std::path::Path::new(path)))?,None => Cache::from_file(None)?,};config.cache(Some(cache));@@ -1260,13 +1292,230 @@ impl CommonOptions {Ok(())}- pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {+ #[cfg(feature = "toml")]+ pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self> {+ use wasmtime::error::Context;+let path_ref = path.as_ref();- let file_contents = fs::read_to_string(path_ref)+ let file_contents = std::fs::read_to_string(path_ref).with_context(|| format!("failed to read config file: {path_ref:?}"))?;toml::from_str::<CommonOptions>(&file_contents).with_context(|| format!("failed to parse TOML config file {path_ref:?}"))}++ /// Creates an instance of [`CommonOptions`] by reflecting on the+ /// configuration present in the provided [`Engine`].+ ///+ /// This will extract all configuration values that can be set by this+ /// [`CommonOptions`] into a [`Config`] into the returned structure to the+ /// best of its ability. Not all configuration options present on [`Engine`]+ /// can be reflected back into [`CommonOptions`], and not all options on+ /// [`CommonOptions`] can be set on an [`Engine`]. This means that this+ /// is a lossy operation that doesn't fully capture 100% of the+ /// configuration of [`Engine`]. That being said, however, it can capture+ /// almost all of the configuration related to codegen and major other+ /// configuration options.+ pub fn from_engine(engine: &Engine) -> Self {+ let features = engine.get_wasm_features();+ let pooling = engine.get_pooling_config();+ CommonOptions {+ target: engine.get_target(),+ opts: OptimizeOptions {+ memory_may_move: Some(engine.get_memory_may_move()),+ memory_reservation: Some(engine.get_memory_reservation()),+ memory_reservation_for_growth: Some(engine.get_memory_reservation_for_growth()),+ memory_guard_size: Some(engine.get_memory_guard_size()),+ gc_heap_may_move: Some(engine.get_gc_heap_may_move()),+ gc_heap_reservation: Some(engine.get_gc_heap_reservation()),+ gc_heap_reservation_for_growth: Some(engine.get_gc_heap_reservation_for_growth()),+ gc_heap_guard_size: Some(engine.get_gc_heap_guard_size()),+ guard_before_linear_memory: Some(engine.get_guard_before_linear_memory()),+ table_lazy_init: Some(engine.get_table_lazy_init()),+ memory_init_cow: Some(engine.get_memory_init_cow()),+ memory_guaranteed_dense_image_size: Some(+ engine.get_memory_guaranteed_dense_image_size(),+ ),+ signals_based_traps: Some(engine.get_signals_based_traps()),+ gc_zeal_alloc_counter: engine.get_gc_zeal_alloc_counter(),+ opt_level: engine.get_cranelift_opt_level(),+ regalloc_algorithm: engine.get_cranelift_regalloc_algorithm(),+ pooling_allocator: Some(pooling.is_some()),+ pooling_decommit_batch_size: pooling.map(|c| c.get_decommit_batch_size()),+ pooling_memory_keep_resident: pooling.map(|c| c.get_memory_keep_resident()),+ pooling_table_keep_resident: pooling.map(|c| c.get_table_keep_resident()),+ pooling_max_unused_warm_slots: pooling.map(|c| c.get_max_unused_warm_slots()),+ pooling_pagemap_scan: pooling.map(|c| c.get_pagemap_scan()),+ pooling_total_core_instances: pooling.map(|c| c.get_total_core_instances()),+ pooling_total_component_instances: pooling+ .map(|c| c.get_total_component_instances()),+ pooling_total_memories: pooling.map(|c| c.get_total_memories()),+ pooling_total_tables: pooling.map(|c| c.get_total_tables()),+ pooling_max_memory_size: pooling.map(|c| c.get_max_memory_size()),+ pooling_table_elements: pooling.map(|c| c.get_table_elements()),+ pooling_max_core_instance_size: pooling.map(|c| c.get_max_core_instance_size()),+ pooling_max_component_instance_size: pooling+ .map(|c| c.get_max_component_instance_size()),+ pooling_max_core_instances_per_component: pooling+ .map(|c| c.get_max_core_instances_per_component()),+ pooling_max_memories_per_component: pooling+ .map(|c| c.get_max_memories_per_component()),+ pooling_max_tables_per_component: pooling.map(|c| c.get_max_tables_per_component()),+ pooling_max_tables_per_module: pooling.map(|c| c.get_max_tables_per_module()),+ pooling_max_memories_per_module: pooling.map(|c| c.get_max_memories_per_module()),+ pooling_async_stack_keep_resident: pooling+ .map(|c| c.get_async_stack_keep_resident()),+ pooling_total_stacks: pooling.map(|c| c.get_total_stacks()),+ pooling_total_gc_heaps: pooling.map(|c| c.get_total_gc_heaps()),+ pooling_memory_protection_keys: pooling.map(|c| c.get_memory_protection_keys()),+ pooling_max_memory_protection_keys: pooling+ .map(|c| c.get_max_memory_protection_keys()),+ // Deprecated aliases for the above options; intentionally left+ // unset in favor of their replacements.+ dynamic_memory_guard_size: None,+ static_memory_guard_size: None,+ static_memory_forced: None,+ static_memory_maximum_size: None,+ dynamic_memory_reserved_for_growth: None,+ },+ codegen: CodegenOptions {+ compiler: engine.get_strategy(),+ collector: engine.get_collector(),+ cranelift_debug_verifier: engine.get_cranelift_debug_verifier(),+ inlining: Some(engine.get_compiler_inlining()),+ native_unwind_info: engine.get_native_unwind_info(),+ parallel_compilation: Some(engine.get_parallel_compilation()),+ metadata_for_internal_asserts: Some(engine.get_metadata_for_internal_asserts()),+ metadata_for_gc_heap_corruption: Some(engine.get_metadata_for_gc_heap_corruption()),+ cranelift: engine+ .get_cranelift_flags_set()+ .map(|(k, v)| (k.to_string(), Some(v.to_string())))+ .chain(+ engine+ .get_cranelift_flags_enabled()+ .map(|k| (k.to_string(), None)),+ )+ .collect(),++ // not easily extractable from `Engine` since that supports+ // arbitrary code-defined caches.+ cache: None,+ cache_config: None,+ },+ debug: DebugOptions {+ address_map: Some(engine.get_generate_address_map()),+ debug_info: Some(engine.get_debug_info()),+ guest_debug: Some(engine.get_guest_debug()),+ symbols: Some(engine.get_debug_symbols()),+ max_backtrace: Some(engine.get_wasm_backtrace_max_frames()),++ // Can't infer a path to emit a core dump to from engine+ // configuration.+ coredump: None,+ // debugger configuration not part of engine config+ debugger: None,+ arg: Vec::new(),+ inherit_stderr: None,+ inherit_stdout: None,+ inherit_stdin: None,+ // logging not part of engine config+ log_to_files: None,+ logging: None,+ },+ wasm: WasmOptions {+ async_stack_size: Some(engine.get_async_stack_size()),+ async_stack_zeroing: Some(engine.get_async_stack_zeroing()),+ branch_hinting: Some(engine.get_wasm_branch_hinting()),+ bulk_memory: Some(features.contains(WasmFeatures::BULK_MEMORY)),+ component_model: Some(features.contains(WasmFeatures::COMPONENT_MODEL)),+ component_model_async: Some(features.contains(WasmFeatures::CM_ASYNC)),+ component_model_async_stackful: Some(+ features.contains(WasmFeatures::CM_ASYNC_STACKFUL),+ ),+ component_model_error_context: Some(+ features.contains(WasmFeatures::CM_ERROR_CONTEXT),+ ),+ component_model_gc: Some(features.contains(WasmFeatures::CM_GC)),+ component_model_fixed_length_lists: Some(+ features.contains(WasmFeatures::CM_FIXED_LENGTH_LISTS),+ ),+ component_model_implements: Some(features.contains(WasmFeatures::CM_IMPLEMENTS)),+ component_model_map: Some(features.contains(WasmFeatures::CM_MAP)),+ component_model_more_async_builtins: Some(+ features.contains(WasmFeatures::CM_MORE_ASYNC_BUILTINS),+ ),+ component_model_threading: Some(features.contains(WasmFeatures::CM_THREADING)),+ custom_page_sizes: Some(features.contains(WasmFeatures::CUSTOM_PAGE_SIZES)),+ exceptions: Some(features.contains(WasmFeatures::EXCEPTIONS)),+ extended_const: Some(features.contains(WasmFeatures::EXTENDED_CONST)),+ function_references: Some(features.contains(WasmFeatures::FUNCTION_REFERENCES)),+ gc: Some(features.contains(WasmFeatures::GC)),+ gc_support: Some(features.contains(WasmFeatures::GC_TYPES)),+ memory64: Some(features.contains(WasmFeatures::MEMORY64)),+ multi_memory: Some(features.contains(WasmFeatures::MULTI_MEMORY)),+ multi_value: Some(features.contains(WasmFeatures::MULTI_VALUE)),+ reference_types: Some(features.contains(WasmFeatures::REFERENCE_TYPES)),+ relaxed_simd: Some(features.contains(WasmFeatures::RELAXED_SIMD)),+ shared_everything_threads: Some(+ features.contains(WasmFeatures::SHARED_EVERYTHING_THREADS),+ ),+ simd: Some(features.contains(WasmFeatures::SIMD)),+ stack_switching: Some(features.contains(WasmFeatures::STACK_SWITCHING)),+ tail_call: Some(features.contains(WasmFeatures::TAIL_CALL)),+ threads: Some(features.contains(WasmFeatures::THREADS)),+ wide_arithmetic: Some(features.contains(WasmFeatures::WIDE_ARITHMETIC)),+ concurrency_support: Some(engine.get_concurrency_support()),+ epoch_interruption: Some(engine.get_epoch_interruption()),+ fuel: if engine.get_consume_fuel() {+ Some(1)+ } else {+ None+ },+ max_wasm_stack: Some(engine.get_max_wasm_stack()),+ nan_canonicalization: engine.get_cranelift_nan_canonicalization(),+ relaxed_simd_deterministic: Some(engine.get_relaxed_simd_deterministic()),+ shared_memory: Some(engine.get_shared_memory()),++ // This is covered by individual `WasmFeatures::*` flags above.+ all_proposals: None,+ // These aren't set in `Config` any more, they're just+ // historical+ max_instances: None,+ max_memories: None,+ max_memory_size: None,+ max_table_elements: None,+ max_tables: None,+ // not part of engine config, specific to `run` command+ timeout: None,+ trap_on_grow_failure: None,+ unknown_exports_allow: None,+ unknown_imports_default: None,+ unknown_imports_trap: None,+ wmemcheck: None,+ },++ // Not currently reflected in `Engine`.+ record: RecordOptions::default(),++ // WASI options aren't reflected in an `Engine`.+ wasi: Default::default(),++ // CLI flags are represented above, they have default values here.+ configured: true,+ codegen_raw: Default::default(),+ debug_raw: Default::default(),+ opts_raw: Default::default(),+ record_raw: Default::default(),+ wasi_raw: Default::default(),+ wasm_raw: Default::default(),++ // No external configuration file, it's all above.+ config: None,+ //+ // Note that an exhaustive listing is explicitly used to avoid+ // forgetting to configure a field. Please don't add `..something`+ // here at the end.+ }+ }}#[cfg(test)]diff --git a/crates/cli-flags/src/opt.rs b/crates/cli-flags/src/opt.rsindex a7c8cbed3f..1691435622 100644--- a/crates/cli-flags/src/opt.rs+++ b/crates/cli-flags/src/opt.rs@@ -6,14 +6,17 @@//! option parsing is contained exclusively within this module.use crate::{KeyValuePair, WasiNnGraph};+#[cfg(feature = "clap")]use clap::builder::{StringValueParser, TypedValueParser, ValueParserFactory};+#[cfg(feature = "clap")]use clap::error::{Error, ErrorKind};+#[cfg(feature = "serde")]use serde::de::{self, Visitor};+use std::fmt;use std::num::NonZeroU32;use std::path::PathBuf;use std::str::FromStr;use std::time::Duration;-use std::{fmt, marker};use wasmtime::{Result, bail, format_err};/// Characters which can be safely ignored while parsing numeric options to wasmtime@@ -43,16 +46,18 @@ macro_rules! wasmtime_option_group {...}) => {- #[derive(Default, Debug)]+ #[derive(Default, Debug, PartialEq, Clone)]+ #[cfg_attr(feature = "serde", derive(serde_derive::Deserialize, serde_derive::Serialize))]+ #[cfg_attr(feature = "serde", serde(rename_all = "kebab-case", deny_unknown_fields))]$(#[$attr])*pub struct $opts {$(- $(#[serde($serde_attr)])*+ $(#[cfg_attr(feature = "serde", serde($serde_attr))])*$(#[doc($doc_attr)])?pub $opt: $container<$payload>,)+$(- $(#[serde($serde_attr2)])*+ $(#[cfg_attr(feature = "serde", serde($serde_attr2))])*pub $prefixed: Vec<(String, Option<String>)>,)?}@@ -158,6 +163,7 @@ macro_rules! wasmtime_option_group {#[derive(Clone, Debug, PartialEq)]pub struct CommaSeparated<T>(pub Vec<T>);+#[cfg(feature = "clap")]impl<T> ValueParserFactory for CommaSeparated<T>whereT: WasmtimeOption,@@ -165,13 +171,15 @@ wheretype Parser = CommaSeparatedParser<T>;fn value_parser() -> CommaSeparatedParser<T> {- CommaSeparatedParser(marker::PhantomData)+ CommaSeparatedParser(std::marker::PhantomData)}}#[derive(Clone)]-pub struct CommaSeparatedParser<T>(marker::PhantomData<T>);+#[cfg(feature = "clap")]+pub struct CommaSeparatedParser<T>(std::marker::PhantomData<T>);+#[cfg(feature = "clap")]impl<T> TypedValueParser for CommaSeparatedParser<T>whereT: WasmtimeOption,@@ -312,6 +320,7 @@ pub enum OptName {}impl OptName {+ #[cfg(feature = "clap")]fn display_string(&self) -> String {match self {OptName::Name(s) => s.replace('_', "-"),@@ -682,8 +691,10 @@ impl<T> OptionContainer<T> for Vec<T> {// for parsing toml values the same way we parse command line values.//// Used for wasmtime::Strategy, wasmtime::Collector, wasmtime::OptLevel, wasmtime::RegallocAlgorithm+#[cfg(feature = "serde")]struct ToStringVisitor {}+#[cfg(feature = "serde")]impl<'de> Visitor<'de> for ToStringVisitor {type Value = String;@@ -714,7 +725,10 @@ impl<'de> Visitor<'de> for ToStringVisitor {}// Deserializer that uses the `WasmtimeOptionValue::parse` to parse toml values-pub(crate) fn cli_parse_wrapper<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>+#[cfg(feature = "serde")]+pub(crate) fn deserialize_cli_parse_wrapper<'de, D, T>(+ deserializer: D,+) -> Result<Option<T>, D::Error>whereT: WasmtimeOptionValue,D: serde::Deserializer<'de>,@@ -727,6 +741,18 @@ where.map_err(serde::de::Error::custom)}+#[cfg(feature = "serde")]+pub(crate) fn serialize_cli_parse_wrapper<S, T>(val: &Option<T>, ser: S) -> Result<S::Ok, S::Error>+where+ T: WasmtimeOptionValue,+ S: serde::Serializer,+{+ match val {+ Some(val) => ser.serialize_some(&fmt::from_fn(|f| val.display(f)).to_string()),+ None => ser.serialize_none(),+ }+}+#[cfg(test)]mod tests {use super::WasmtimeOptionValue;diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rsindex 9c4166960e..9b0bca8e25 100644--- a/crates/wasmtime/src/config.rs+++ b/crates/wasmtime/src/config.rs@@ -1,3 +1,4 @@+use crate::Engine;use crate::prelude::*;use alloc::sync::Arc;use bitflags::Flags;@@ -7,6 +8,8 @@ use core::str::FromStr;#[cfg(any(feature = "cranelift", feature = "winch"))]use std::path::Path;pub use wasmparser::WasmFeatures;+#[cfg(any(feature = "cranelift", feature = "winch"))]+use wasmtime_environ::FlagValue;use wasmtime_environ::{ConfigTunables, OperatorCost, OperatorCostStrategy, TripleExt, Tunables};#[cfg(feature = "runtime")]@@ -134,14 +137,14 @@ pub enum RRConfig {None,}-/// Global configuration options used to create an [`Engine`](crate::Engine)+/// 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()`](crate::Engine::new).+/// [`Engine::new()`].////// The validation of `Config` is deferred until the engine is being built, thus-/// a problematic config may cause `Engine::new` to fail.+/// a problematic config may cause [`Engine::new`] to fail.////// # Defaults///@@ -182,9 +185,7 @@ pub struct Config {pub(crate) wasm_backtrace_details_env_used: bool,pub(crate) wasm_backtrace_max_frames: Option<NonZeroUsize>,pub(crate) native_unwind_info: Option<bool>,- #[cfg(any(feature = "async", feature = "stack-switching"))]pub(crate) async_stack_size: usize,- #[cfg(feature = "async")]pub(crate) async_stack_zeroing: bool,#[cfg(feature = "async")]pub(crate) stack_creator: Option<Arc<dyn RuntimeFiberStackCreator>>,@@ -207,14 +208,21 @@ pub struct Config {#[derive(Debug, Clone)]struct CompilerConfig {strategy: Option<Strategy>,- settings: crate::hash_map::HashMap<String, String>,- flags: crate::hash_set::HashSet<String>,+ settings: crate::hash_map::HashMap<String, (String, UserSpecified)>,+ flags: crate::hash_map::HashMap<String, UserSpecified>,#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]cache_store: Option<Arc<dyn CacheStore>>,clif_dir: Option<std::path::PathBuf>,wmemcheck: bool,}+#[cfg(any(feature = "cranelift", feature = "winch"))]+#[derive(Debug, Clone)]+enum UserSpecified {+ Yes,+ No,+}+#[cfg(any(feature = "cranelift", feature = "winch"))]impl CompilerConfig {fn new() -> Self {@@ -238,12 +246,13 @@ impl CompilerConfig {/// value, or false if the setting was explicitly set to something/// else previously.fn ensure_setting_unset_or_given(&mut self, k: &str, v: &str) -> bool {- if let Some(value) = self.settings.get(k) {+ if let Some((value, _)) = self.settings.get(k) {if value != v {return false;}} else {- self.settings.insert(k.to_string(), v.to_string());+ self.settings+ .insert(k.to_string(), (v.to_string(), UserSpecified::No));}true}@@ -289,9 +298,7 @@ impl Config {native_unwind_info: None,enabled_features: WasmFeatures::empty(),disabled_features: WasmFeatures::empty(),- #[cfg(any(feature = "async", feature = "stack-switching"))]async_stack_size: 2 << 20,- #[cfg(feature = "async")]async_stack_zeroing: false,#[cfg(feature = "async")]stack_creator: None,@@ -332,7 +339,7 @@ impl Config {/// Configure whether Wasm compilation is enabled.////// Disabling Wasm compilation will allow you to load and run- /// [pre-compiled][crate::Engine::precompile_module] Wasm programs, but not+ /// [pre-compiled][Engine::precompile_module] Wasm programs, but not/// to compile and run new Wasm programs that have not already been/// pre-compiled.///@@ -353,7 +360,7 @@ impl Config {////// The static approach is better in most cases, however dynamically calling/// `enable_compiler(false)` is useful whenever you create multiple- /// `Engine`s in the same process, some of which must be able to compile+ /// [`Engine`]s in the same process, some of which must be able to compile/// Wasm and some of which should never do so. Tests are a common example of/// such a situation, especially when there are multiple Rust binaries in/// the same cargo workspace, and cargo's feature resolution enables the@@ -375,15 +382,14 @@ impl Config {/// Configures the target platform of this [`Config`].////// This method is used to configure the output of compilation in an- /// [`Engine`](crate::Engine). This can be used, for example, to+ /// [`Engine`]. This can be used, for example, to/// cross-compile from one platform to another. By default, the host target/// triple is used meaning compiled code is suitable to run on the host.////// Note that the [`Module`](crate::Module) type can only be created if the/// target configured here matches the host. Otherwise if a cross-compile is/// being performed where the host doesn't match the target then- /// [`Engine::precompile_module`](crate::Engine::precompile_module) must be- /// used instead.+ /// [`Engine::precompile_module`] must be used instead.////// Target-specific flags (such as CPU features) will not be inferred by/// default for the target when one is provided here. This means that this@@ -667,8 +673,8 @@ impl Config {/// Epoch-based interruption is that mechanism. There is a global/// "epoch", which is a counter that divides time into arbitrary/// periods (or epochs). This counter lives on the- /// [`Engine`](crate::Engine) and can be incremented by calling- /// [`Engine::increment_epoch`](crate::Engine::increment_epoch).+ /// [`Engine`] and can be incremented by calling+ /// [`Engine::increment_epoch`]./// Epoch-based instrumentation works by setting a "deadline/// epoch". The compiled code knows the deadline, and at certain/// points, checks the current epoch against that deadline. It@@ -752,7 +758,6 @@ impl Config {////// # See Also///- /// - [`Engine::increment_epoch`](crate::Engine::increment_epoch)/// - [`Store::set_epoch_deadline`](crate::Store::set_epoch_deadline)/// - [`Store::epoch_deadline_trap`](crate::Store::epoch_deadline_trap)/// - [`Store::epoch_deadline_callback`](crate::Store::epoch_deadline_callback)@@ -824,7 +829,7 @@ impl Config {////// # Errors///- /// The `Engine::new` method will fail if the `size` specified here is+ /// The [`Engine::new`] method will fail if the `size` specified here is/// either 0 or larger than the [`Config::async_stack_size`] configuration.pub fn max_wasm_stack(&mut self, size: usize) -> &mut Self {self.max_wasm_stack = size;@@ -845,9 +850,8 @@ impl Config {////// # Errors///- /// The `Engine::new` method will fail if the value for this option is+ /// The [`Engine::new`] method will fail if the value for this option is/// smaller than the [`Config::max_wasm_stack`] option.- #[cfg(any(feature = "async", feature = "stack-switching"))]pub fn async_stack_size(&mut self, size: usize) -> &mut Self {self.async_stack_size = size;self@@ -880,7 +884,6 @@ impl Config {/// This option defaults to `false`.////// [`call_async`]: crate::TypedFunc::call_async- #[cfg(feature = "async")]pub fn async_stack_zeroing(&mut self, enable: bool) -> &mut Self {self.async_stack_zeroing = enable;self@@ -896,7 +899,7 @@ impl Config {////// Feature validation is deferred until an engine is being built, thus by/// enabling features here a caller may cause- /// [`Engine::new`](crate::Engine::new) to fail later, if the feature+ /// [`Engine::new`] to fail later, if the feature/// configuration isn't supported.pub fn wasm_features(&mut self, flag: WasmFeatures, enable: bool) -> &mut Self {self.enabled_features.set(flag, enable);@@ -1012,7 +1015,7 @@ impl Config {/// # Errors////// The validation of this feature are deferred until the engine is being built,- /// and thus may cause `Engine::new` fail if the `bulk_memory` feature is disabled.+ /// and thus may cause [`Engine::new`] fail if the `bulk_memory` feature is disabled.////// [proposal]: https://github.com/webassembly/reference-types#[cfg(feature = "gc")]@@ -1152,7 +1155,7 @@ impl Config {/// # Errors////// Disabling this feature without disabling `reference_types` will cause- /// `Engine::new` to fail.+ /// [`Engine::new`] to fail.////// [proposal]: https://github.com/webassembly/bulk-memory-operationspub fn wasm_bulk_memory(&mut self, enable: bool) -> &mut Self {@@ -1423,7 +1426,7 @@ impl Config {/// # Errors////// The validation of this field is deferred until the engine is being built, and thus may- /// cause `Engine::new` fail if the required feature is disabled, or the platform is not+ /// cause [`Engine::new`] fail if the required feature is disabled, or the platform is not/// supported.pub fn profiler(&mut self, profile: ProfilingStrategy) -> &mut Self {self.profiling_strategy = profile;@@ -1445,9 +1448,10 @@ impl Config {#[cfg(any(feature = "cranelift", feature = "winch"))]pub fn cranelift_debug_verifier(&mut self, enable: bool) -> &mut Self {let val = if enable { "true" } else { "false" };- self.compiler_config_mut()- .settings- .insert("enable_verifier".to_string(), val.to_string());+ self.compiler_config_mut().settings.insert(+ "enable_verifier".to_string(),+ (val.to_string(), UserSpecified::No),+ );self}@@ -1482,9 +1486,10 @@ impl Config {OptLevel::Speed => "speed",OptLevel::SpeedAndSize => "speed_and_size",};- self.compiler_config_mut()- .settings- .insert("opt_level".to_string(), val.to_string());+ self.compiler_config_mut().settings.insert(+ "opt_level".to_string(),+ (val.to_string(), UserSpecified::No),+ );self}@@ -1507,9 +1512,10 @@ impl Config {RegallocAlgorithm::Backtracking => "backtracking",RegallocAlgorithm::SinglePass => "single_pass",};- self.compiler_config_mut()- .settings- .insert("regalloc_algorithm".to_string(), val.to_string());+ self.compiler_config_mut().settings.insert(+ "regalloc_algorithm".to_string(),+ (val.to_string(), UserSpecified::No),+ );self}@@ -1533,9 +1539,10 @@ impl Config {#[cfg(any(feature = "cranelift", feature = "winch"))]pub fn cranelift_nan_canonicalization(&mut self, enable: bool) -> &mut Self {let val = if enable { "true" } else { "false" };- self.compiler_config_mut()- .settings- .insert("enable_nan_canonicalization".to_string(), val.to_string());+ self.compiler_config_mut().settings.insert(+ "enable_nan_canonicalization".to_string(),+ (val.to_string(), UserSpecified::No),+ );self}@@ -1553,7 +1560,7 @@ impl Config {/// # Errors////// The validation of the flags are deferred until the engine is being built, and thus may- /// cause `Engine::new` fail if the flag's name does not exist, or the value is not appropriate+ /// cause [`Engine::new`] fail if the flag's name does not exist, or the value is not appropriate/// for the flag type.////// # Panics@@ -1561,7 +1568,9 @@ impl Config {/// Panics if this configuration's compiler was [disabled][Config::enable_compiler].#[cfg(any(feature = "cranelift", feature = "winch"))]pub unsafe fn cranelift_flag_enable(&mut self, flag: &str) -> &mut Self {- self.compiler_config_mut().flags.insert(flag.to_string());+ self.compiler_config_mut()+ .flags+ .insert(flag.to_string(), UserSpecified::Yes);self}@@ -1579,7 +1588,7 @@ impl Config {/// # Errors////// The validation of the flags are deferred until the engine is being built, and thus may- /// cause `Engine::new` fail if the flag's name does not exist, or incompatible with other+ /// cause [`Engine::new`] fail if the flag's name does not exist, or incompatible with other/// settings.////// For example, feature `wasm_backtrace` will set `unwind_info` to `true`, but if it's@@ -1592,7 +1601,7 @@ impl Config {pub unsafe fn cranelift_flag_set(&mut self, name: &str, value: &str) -> &mut Self {self.compiler_config_mut().settings- .insert(name.to_string(), value.to_string());+ .insert(name.to_string(), (value.to_string(), UserSpecified::Yes));self}@@ -2305,7 +2314,7 @@ impl Config {/// This may result in faster execution at runtime, but adds additional/// compilation time. Inlining may also enlarge the size of compiled/// artifacts (for example, the size of the result of- /// [`Engine::precompile_component`](crate::Engine::precompile_component)).+ /// [`Engine::precompile_component`]).////// Inlining is not supported by all of Wasmtime's compilation strategies;/// currently, it only Cranelift supports it. This setting will be ignored@@ -2553,7 +2562,6 @@ impl Config {panic!("should have returned an error by now")}- #[cfg(any(feature = "async", feature = "stack-switching"))]if self.max_wasm_stack > self.async_stack_size {bail!("max_wasm_stack size cannot exceed the async_stack_size");}@@ -2763,20 +2771,14 @@ impl Config {&self,tunables: &Tunables,) -> Result<Box<dyn InstanceAllocator + Send + Sync>> {- #[cfg(feature = "async")]- let (stack_size, stack_zeroing) = (self.async_stack_size, self.async_stack_zeroing);-- #[cfg(not(feature = "async"))]- let (stack_size, stack_zeroing) = (0, false);-let _ = tunables;match &self.allocation_strategy {InstanceAllocationStrategy::OnDemand => {let mut _allocator = try_new::<Box<_>>(OnDemandInstanceAllocator::new(self.mem_creator.clone(),- stack_size,- stack_zeroing,+ self.async_stack_size,+ self.async_stack_zeroing,))?;#[cfg(feature = "async")]if let Some(stack_creator) = &self.stack_creator {@@ -2786,9 +2788,13 @@ impl Config {}#[cfg(feature = "pooling-allocator")]InstanceAllocationStrategy::Pooling(config) => {- let mut config = config.config;- config.stack_size = stack_size;- config.async_stack_zeroing = stack_zeroing;+ let mut config = config.clone();+ let _ = &mut config;+ #[cfg(feature = "async")]+ {+ config.stack_size = self.async_stack_size;+ config.async_stack_zeroing = self.async_stack_zeroing;+ }let allocator = try_new::<Box<_>>(crate::runtime::vm::PoolingInstanceAllocator::new(&config, tunables)?,)?;@@ -2891,9 +2897,10 @@ impl Config {// If probestack is enabled for a target, Wasmtime will always use the// inline strategy which doesn't require us to define a `__probestack`// function or similar.- self.compiler_config_mut()- .settings- .insert("probestack_strategy".into(), "inline".into());+ self.compiler_config_mut().settings.insert(+ "probestack_strategy".into(),+ ("inline".into(), UserSpecified::No),+ );// We enable stack probing by default on all targets.// This is required on Windows because of the way Windows@@ -2902,13 +2909,13 @@ impl Config {// sizes.self.compiler_config_mut().flags- .insert("enable_probestack".into());+ .insert("enable_probestack".into(), UserSpecified::No);// The current wasm multivalue implementation depends on this.// FIXME(#9510) handle this in wasmtime-cranelift instead.self.compiler_config_mut().flags- .insert("enable_multi_ret_implicit_sret".into());+ .insert("enable_multi_ret_implicit_sret".into(), UserSpecified::No);if let Some(unwind_requested) = self.native_unwind_info {if !self@@ -2933,9 +2940,10 @@ impl Config {// We require frame pointers for correct stack walking, which is safety// critical in the presence of reference types, and otherwise it is just// really bad developer experience to get wrong.- self.compiler_config_mut()- .settings- .insert("preserve_frame_pointers".into(), "true".into());+ self.compiler_config_mut().settings.insert(+ "preserve_frame_pointers".into(),+ ("true".into(), UserSpecified::No),+ );if !tunables.signals_based_traps {let mut ok = self@@ -2985,10 +2993,10 @@ impl Config {// Apply compiler settings and flagscompiler.set_tunables(tunables.clone())?;- for (k, v) in self.compiler_config_mut().settings.iter() {+ for (k, (v, _)) in self.compiler_config_mut().settings.iter() {compiler.set(k, v)?;}- for flag in self.compiler_config_mut().flags.iter() {+ for (flag, _) in self.compiler_config_mut().flags.iter() {compiler.enable(flag)?;}*tunables = compiler.tunables().cloned().unwrap();@@ -3300,7 +3308,7 @@ impl Config {}}#[cfg(any(feature = "cranelift", feature = "winch"))]- if let Some(v) = self+ if let Some((v, _)) = self.compiler_config.as_ref().and_then(|c| c.settings.get("enable_nan_canonicalization"))@@ -3769,7 +3777,7 @@ pub enum Enabled {/// Another disadvantage of the pooling allocator is that it may keep memory/// alive when nothing is using it. A previously used slot for an instance might/// have paged-in memory that will not get paged out until the-/// [`Engine`](crate::Engine) owning the pooling allocator is dropped. While+/// [`Engine`] owning the pooling allocator is dropped. While/// suitable for some applications this behavior may not be suitable for all/// applications.///@@ -3783,13 +3791,167 @@ pub enum Enabled {/// [`mprotect`]: https://man7.org/linux/man-pages/man2/mprotect.2.html/// [`mmap`]: https://man7.org/linux/man-pages/man2/mmap.2.html/// [`munmap`]: https://man7.org/linux/man-pages/man2/munmap.2.html-#[cfg(feature = "pooling-allocator")]-#[derive(Debug, Clone, Default)]+#[derive(Debug, Clone)]pub struct PoolingAllocationConfig {- config: crate::runtime::vm::PoolingInstanceAllocatorConfig,+ /// See `PoolingAllocatorConfig::max_unused_warm_slots` in `wasmtime`+ pub(crate) max_unused_warm_slots: u32,+ /// The target number of decommits to do per batch. This is not precise, as+ /// we can queue up decommits at times when we aren't prepared to+ /// immediately flush them, and so we may go over this target size+ /// occasionally.+ pub(crate) decommit_batch_size: usize,+ /// The size, in bytes, of async stacks to allocate (not including the guard+ /// page).+ #[cfg_attr(+ not(all(feature = "async", feature = "pooling-allocator")),+ expect(dead_code, reason = "easier to cfg")+ )]+ pub(crate) stack_size: usize,+ /// The limits to apply to instances allocated within this allocator.+ pub(crate) limits: InstanceLimits,+ /// Whether or not async stacks are zeroed after use.+ #[cfg_attr(+ not(all(feature = "async", feature = "pooling-allocator")),+ expect(dead_code, reason = "easier to cfg")+ )]+ pub(crate) async_stack_zeroing: bool,+ /// If async stack zeroing is enabled and the host platform is Linux this is+ /// how much memory to zero out with `memset`.+ ///+ /// The rest of memory will be zeroed out with `madvise`.+ pub(crate) async_stack_keep_resident: usize,+ /// How much linear memory, in bytes, to keep resident after resetting for+ /// use with the next instance. This much memory will be `memset` to zero+ /// when a linear memory is deallocated.+ ///+ /// Memory exceeding this amount in the wasm linear memory will be released+ /// with `madvise` back to the kernel.+ ///+ /// Only applicable on Linux.+ pub(crate) linear_memory_keep_resident: usize,+ /// Same as `linear_memory_keep_resident` but for tables.+ pub(crate) table_keep_resident: usize,+ /// Whether to enable memory protection keys.+ pub(crate) memory_protection_keys: Enabled,+ /// How many memory protection keys to allocate.+ pub(crate) max_memory_protection_keys: usize,+ /// Whether to enable PAGEMAP_SCAN on Linux.+ pub(crate) pagemap_scan: Enabled,+}++impl Default for PoolingAllocationConfig {+ fn default() -> Self {+ Self {+ max_unused_warm_slots: 100,+ decommit_batch_size: 1,+ stack_size: 2 << 20,+ limits: InstanceLimits::default(),+ async_stack_zeroing: false,+ async_stack_keep_resident: 0,+ linear_memory_keep_resident: 0,+ table_keep_resident: 0,+ memory_protection_keys: Enabled::No,+ max_memory_protection_keys: 16,+ pagemap_scan: Enabled::No,+ }+ }+}++/// Instance-related limit configuration for pooling.+///+/// More docs on this can be found at `wasmtime::PoolingAllocationConfig`.+#[derive(Debug, Copy, Clone)]+pub(crate) struct InstanceLimits {+ /// The maximum number of component instances that may be allocated+ /// concurrently.+ pub(crate) total_component_instances: u32,++ /// The maximum size of a component's `VMComponentContext`, including+ /// the aggregate size of all its inner core modules' `VMContext` sizes.+ pub(crate) component_instance_size: usize,++ /// The maximum number of core module instances that may be allocated+ /// concurrently.+ pub(crate) total_core_instances: u32,++ /// The maximum number of core module instances that a single component may+ /// transitively contain.+ pub(crate) max_core_instances_per_component: u32,++ /// The maximum number of Wasm linear memories that a component may+ /// transitively contain.+ pub(crate) max_memories_per_component: u32,++ /// The maximum number of tables that a component may transitively contain.+ pub(crate) max_tables_per_component: u32,++ /// The total number of linear memories in the pool, across all instances.+ pub(crate) total_memories: u32,++ /// The total number of tables in the pool, across all instances.+ pub(crate) total_tables: u32,++ /// The total number of async stacks in the pool, across all instances.+ pub(crate) total_stacks: u32,++ /// Maximum size of a core instance's `VMContext`.+ pub(crate) core_instance_size: usize,++ /// Maximum number of tables per instance.+ pub(crate) max_tables_per_module: u32,++ /// Maximum number of word-size elements per table.+ ///+ /// Note that tables for element types such as continuations+ /// that use more than one word of storage may store fewer+ /// elements.+ pub(crate) table_elements: usize,++ /// Maximum number of linear memories per instance.+ pub(crate) max_memories_per_module: u32,++ /// Maximum byte size of a linear memory, must be smaller than+ /// `memory_reservation` in `Tunables`.+ pub(crate) max_memory_size: usize,++ /// The total number of GC heaps in the pool, across all instances.+ pub(crate) total_gc_heaps: u32,+}++impl Default for InstanceLimits {+ fn default() -> Self {+ let total = if cfg!(target_pointer_width = "32") {+ 100+ } else {+ 1000+ };+ // See doc comments for `wasmtime::PoolingAllocationConfig` for these+ // default values+ Self {+ total_component_instances: total,+ component_instance_size: 1 << 20, // 1 MiB+ total_core_instances: total,+ max_core_instances_per_component: u32::MAX,+ max_memories_per_component: u32::MAX,+ max_tables_per_component: u32::MAX,+ total_memories: total,+ total_tables: total,+ total_stacks: total,+ core_instance_size: 1 << 20, // 1 MiB+ max_tables_per_module: 1,+ // NB: in #8504 it was seen that a C# module in debug module can+ // have 10k+ elements.+ table_elements: 20_000,+ max_memories_per_module: 1,+ #[cfg(target_pointer_width = "64")]+ max_memory_size: 1 << 32, // 4G,+ #[cfg(target_pointer_width = "32")]+ max_memory_size: 10 << 20, // 10 MiB+ total_gc_heaps: total,+ }+ }}-#[cfg(feature = "pooling-allocator")]impl PoolingAllocationConfig {/// Returns a new configuration builder with all default settings/// configured.@@ -3849,7 +4011,7 @@ impl PoolingAllocationConfig {////// The default value for this option is `100`.pub fn max_unused_warm_slots(&mut self, max: u32) -> &mut Self {- self.config.max_unused_warm_slots = max;+ self.max_unused_warm_slots = max;self}@@ -3863,7 +4025,7 @@ impl PoolingAllocationConfig {////// Defaults to `1`.pub fn decommit_batch_size(&mut self, batch_size: usize) -> &mut Self {- self.config.decommit_batch_size = batch_size;+ self.decommit_batch_size = batch_size;self}@@ -3878,9 +4040,8 @@ impl PoolingAllocationConfig {////// Note that when using this option the memory with async stacks will/// never be decommitted.- #[cfg(feature = "async")]pub fn async_stack_keep_resident(&mut self, size: usize) -> &mut Self {- self.config.async_stack_keep_resident = size;+ self.async_stack_keep_resident = size;self}@@ -3896,7 +4057,7 @@ impl PoolingAllocationConfig {/// which can, in some configurations, reduce the number of page faults/// taken when a slot is reused.pub fn linear_memory_keep_resident(&mut self, size: usize) -> &mut Self {- self.config.linear_memory_keep_resident = size;+ self.linear_memory_keep_resident = size;self}@@ -3910,7 +4071,7 @@ impl PoolingAllocationConfig {/// [`PoolingAllocationConfig::linear_memory_keep_resident`] except that it/// is applicable to tables instead.pub fn table_keep_resident(&mut self, size: usize) -> &mut Self {- self.config.table_keep_resident = size;+ self.table_keep_resident = size;self}@@ -3928,7 +4089,7 @@ impl PoolingAllocationConfig {/// where `max_component_instance_size` is rounded up to the size and alignment/// of the internal representation of the metadata.pub fn total_component_instances(&mut self, count: u32) -> &mut Self {- self.config.limits.total_component_instances = count;+ self.limits.total_component_instances = count;self}@@ -3971,7 +4132,7 @@ impl PoolingAllocationConfig {/// where `max_component_instance_size` is rounded up to the size and alignment/// of the internal representation of the metadata.pub fn max_component_instance_size(&mut self, size: usize) -> &mut Self {- self.config.limits.component_instance_size = size;+ self.limits.component_instance_size = size;self}@@ -3987,7 +4148,7 @@ impl PoolingAllocationConfig {/// If a component will instantiate more core instances than `count`, then/// the component will fail to instantiate.pub fn max_core_instances_per_component(&mut self, count: u32) -> &mut Self {- self.config.limits.max_core_instances_per_component = count;+ self.limits.max_core_instances_per_component = count;self}@@ -4003,7 +4164,7 @@ impl PoolingAllocationConfig {/// If a component transitively contains more linear memories than `count`,/// then the component will fail to instantiate.pub fn max_memories_per_component(&mut self, count: u32) -> &mut Self {- self.config.limits.max_memories_per_component = count;+ self.limits.max_memories_per_component = count;self}@@ -4019,7 +4180,7 @@ impl PoolingAllocationConfig {/// If a component will transitively contains more tables than `count`, then/// the component will fail to instantiate.pub fn max_tables_per_component(&mut self, count: u32) -> &mut Self {- self.config.limits.max_tables_per_component = count;+ self.limits.max_tables_per_component = count;self}@@ -4042,7 +4203,7 @@ impl PoolingAllocationConfig {/// TiB. That might seem like a lot, but each linear memory will *reserve* 6/// GiB of space by default.pub fn total_memories(&mut self, count: u32) -> &mut Self {- self.config.limits.total_memories = count;+ self.limits.total_memories = count;self}@@ -4056,7 +4217,7 @@ impl PoolingAllocationConfig {/// supported by an instance (see `table_elements` to control the size of/// each table).pub fn total_tables(&mut self, count: u32) -> &mut Self {- self.config.limits.total_tables = count;+ self.limits.total_tables = count;self}@@ -4067,7 +4228,7 @@ impl PoolingAllocationConfig {/// pooling instance allocator.#[cfg(feature = "async")]pub fn total_stacks(&mut self, count: u32) -> &mut Self {- self.config.limits.total_stacks = count;+ self.limits.total_stacks = count;self}@@ -4085,7 +4246,7 @@ impl PoolingAllocationConfig {/// where `max_core_instance_size` is rounded up to the size and alignment of/// the internal representation of the metadata.pub fn total_core_instances(&mut self, count: u32) -> &mut Self {- self.config.limits.total_core_instances = count;+ self.limits.total_core_instances = count;self}@@ -4120,7 +4281,7 @@ impl PoolingAllocationConfig {/// where `max_core_instance_size` is rounded up to the size and alignment of/// the internal representation of the metadata.pub fn max_core_instance_size(&mut self, size: usize) -> &mut Self {- self.config.limits.core_instance_size = size;+ self.limits.core_instance_size = size;self}@@ -4133,7 +4294,7 @@ impl PoolingAllocationConfig {/// sizeof(VMTableDefinition)` for each instance regardless of how many/// tables are defined by an instance's module.pub fn max_tables_per_module(&mut self, tables: u32) -> &mut Self {- self.config.limits.max_tables_per_module = tables;+ self.limits.max_tables_per_module = tables;self}@@ -4152,7 +4313,7 @@ impl PoolingAllocationConfig {/// Therefore, the space reserved for each instance is `tables */// table_elements * sizeof::<*const ()>`.pub fn table_elements(&mut self, elements: usize) -> &mut Self {- self.config.limits.table_elements = elements;+ self.limits.table_elements = elements;self}@@ -4166,7 +4327,7 @@ impl PoolingAllocationConfig {/// sizeof(VMMemoryDefinition)` for each core instance regardless of how/// many memories are defined by the core instance's module.pub fn max_memories_per_module(&mut self, memories: u32) -> &mut Self {- self.config.limits.max_memories_per_module = memories;+ self.limits.max_memories_per_module = memories;self}@@ -4194,7 +4355,7 @@ impl PoolingAllocationConfig {/// by the [`Config::memory_reservation`] setting and this method's/// configuration cannot exceed [`Config::memory_reservation`].pub fn max_memory_size(&mut self, bytes: usize) -> &mut Self {- self.config.limits.max_memory_size = bytes;+ self.limits.max_memory_size = bytes;self}@@ -4233,7 +4394,7 @@ impl PoolingAllocationConfig {/// misconfigured.#[cfg(feature = "memory-protection-keys")]pub fn memory_protection_keys(&mut self, enable: Enabled) -> &mut Self {- self.config.memory_protection_keys = enable;+ self.memory_protection_keys = enable;self}@@ -4251,7 +4412,7 @@ impl PoolingAllocationConfig {/// other engines.#[cfg(feature = "memory-protection-keys")]pub fn max_memory_protection_keys(&mut self, max: usize) -> &mut Self {- self.config.max_memory_protection_keys = max;+ self.max_memory_protection_keys = max;self}@@ -4276,7 +4437,7 @@ impl PoolingAllocationConfig {/// store.#[cfg(feature = "gc")]pub fn total_gc_heaps(&mut self, count: u32) -> &mut Self {- self.config.limits.total_gc_heaps = count;+ self.limits.total_gc_heaps = count;self}@@ -4309,14 +4470,153 @@ impl PoolingAllocationConfig {////// [ioctl]: https://www.man7.org/linux/man-pages/man2/PAGEMAP_SCAN.2const.htmlpub fn pagemap_scan(&mut self, enable: Enabled) -> &mut Self {- self.config.pagemap_scan = enable;+ self.pagemap_scan = enable;self}- /// Tests whether [`Self::pagemap_scan`] is available or not on the host- /// system.- pub fn is_pagemap_scan_available() -> bool {- crate::runtime::vm::PoolingInstanceAllocatorConfig::is_pagemap_scan_available()+ /// Returns the configured+ /// [`PoolingAllocationConfig::decommit_batch_size`], if enabled.+ pub fn get_decommit_batch_size(&self) -> usize {+ self.decommit_batch_size+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_unused_warm_slots`], if enabled.+ pub fn get_max_unused_warm_slots(&self) -> u32 {+ self.max_unused_warm_slots+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::linear_memory_keep_resident`], if+ /// enabled.+ pub fn get_memory_keep_resident(&self) -> usize {+ self.linear_memory_keep_resident+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::table_keep_resident`], if enabled.+ pub fn get_table_keep_resident(&self) -> usize {+ self.table_keep_resident+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::async_stack_keep_resident`], if+ /// enabled.+ pub fn get_async_stack_keep_resident(&self) -> usize {+ self.async_stack_keep_resident+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::memory_protection_keys`], if enabled.+ pub fn get_memory_protection_keys(&self) -> Enabled {+ self.memory_protection_keys+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_memory_protection_keys`], if+ /// enabled.+ pub fn get_max_memory_protection_keys(&self) -> usize {+ self.max_memory_protection_keys+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::pagemap_scan`], if enabled.+ pub fn get_pagemap_scan(&self) -> Enabled {+ self.pagemap_scan+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_core_instances`], if enabled.+ pub fn get_total_core_instances(&self) -> u32 {+ self.limits.total_core_instances+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_component_instances`], if+ /// enabled.+ pub fn get_total_component_instances(&self) -> u32 {+ self.limits.total_component_instances+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_memories`], if enabled.+ pub fn get_total_memories(&self) -> u32 {+ self.limits.total_memories+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_tables`], if enabled.+ pub fn get_total_tables(&self) -> u32 {+ self.limits.total_tables+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_stacks`], if enabled.+ pub fn get_total_stacks(&self) -> u32 {+ self.limits.total_stacks+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::total_gc_heaps`], if enabled.+ pub fn get_total_gc_heaps(&self) -> u32 {+ self.limits.total_gc_heaps+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_memory_size`], if enabled.+ pub fn get_max_memory_size(&self) -> usize {+ self.limits.max_memory_size+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::table_elements`], if enabled.+ pub fn get_table_elements(&self) -> usize {+ self.limits.table_elements+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_core_instance_size`], if enabled.+ pub fn get_max_core_instance_size(&self) -> usize {+ self.limits.core_instance_size+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_component_instance_size`], if+ /// enabled.+ pub fn get_max_component_instance_size(&self) -> usize {+ self.limits.component_instance_size+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_core_instances_per_component`], if+ /// enabled.+ pub fn get_max_core_instances_per_component(&self) -> u32 {+ self.limits.max_core_instances_per_component+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_memories_per_component`], if+ /// enabled.+ pub fn get_max_memories_per_component(&self) -> u32 {+ self.limits.max_memories_per_component+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_tables_per_component`], if enabled.+ pub fn get_max_tables_per_component(&self) -> u32 {+ self.limits.max_tables_per_component+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_tables_per_module`], if enabled.+ pub fn get_max_tables_per_module(&self) -> u32 {+ self.limits.max_tables_per_module+ }++ /// Returns the configured+ /// [`PoolingAllocationConfig::max_memories_per_module`], if enabled.+ pub fn get_max_memories_per_module(&self) -> u32 {+ self.limits.max_memories_per_module}}@@ -4406,3 +4706,346 @@ fn detect_host_feature(feature: &str) -> Option<bool> {return None;}}++// What follows in this impl block is intended to be a somewhat-mechanical+// mostly-complete set of getters for relevant configuration options on+// `Config`. The `Config` type does not reflect a complete configuration so+// default values cannot be directly read from it. An `Engine`, however,+// represents a concrete and complete configuration with all default values+// fully specified. The purpose of these getters are then to perform a dual+// function of reflecting what was explicitly configured above as well as+// defaults that Wasmtime sets.+//+// The current pattern is:+//+// * All methods are `get_<config_name>`+// * Return values return `T` instead of `Option<T>` where possible unless the+// state for `T` is completely missing.+//+// This impl is primarily in service of+// `wasmtime_cli_flags::CommonOptions::from_engine` at this time, and CLI flags+// are not as comprehensive as `Config` options, but it's expected that the set+// will settle/grow over time.+impl Engine {+ /// Returns the configured [`Config::memory_may_move`] value.+ pub fn get_memory_may_move(&self) -> bool {+ self.tunables().memory_may_move+ }++ /// Returns the configured [`Config::memory_reservation`] value.+ pub fn get_memory_reservation(&self) -> u64 {+ self.tunables().memory_reservation+ }++ /// Returns the configured [`Config::memory_reservation_for_growth`] value.+ pub fn get_memory_reservation_for_growth(&self) -> u64 {+ self.tunables().memory_reservation_for_growth+ }++ /// Returns the configured [`Config::memory_guard_size`] value.+ pub fn get_memory_guard_size(&self) -> u64 {+ self.tunables().memory_guard_size+ }++ /// Returns the configured [`Config::gc_heap_may_move`] value.+ pub fn get_gc_heap_may_move(&self) -> bool {+ self.tunables().gc_heap_may_move+ }++ /// Returns the configured [`Config::gc_heap_reservation`] value.+ pub fn get_gc_heap_reservation(&self) -> u64 {+ self.tunables().gc_heap_reservation+ }++ /// Returns the configured [`Config::gc_heap_reservation_for_growth`] value.+ pub fn get_gc_heap_reservation_for_growth(&self) -> u64 {+ self.tunables().gc_heap_reservation_for_growth+ }++ /// Returns the configured [`Config::gc_heap_guard_size`] value.+ pub fn get_gc_heap_guard_size(&self) -> u64 {+ self.tunables().gc_heap_guard_size+ }++ /// Returns the configured [`Config::guard_before_linear_memory`] value.+ pub fn get_guard_before_linear_memory(&self) -> bool {+ self.tunables().guard_before_linear_memory+ }++ /// Returns the configured [`Config::table_lazy_init`] value.+ pub fn get_table_lazy_init(&self) -> bool {+ self.tunables().table_lazy_init+ }++ /// Returns the configured [`Config::memory_init_cow`] value.+ pub fn get_memory_init_cow(&self) -> bool {+ self.tunables().memory_init_cow+ }++ /// Returns the configured [`Config::memory_guaranteed_dense_image_size`] value.+ pub fn get_memory_guaranteed_dense_image_size(&self) -> u64 {+ self.config().memory_guaranteed_dense_image_size+ }++ /// Returns the configured [`Config::signals_based_traps`] value.+ pub fn get_signals_based_traps(&self) -> bool {+ self.tunables().signals_based_traps+ }++ /// Returns the configured [`Config::gc_zeal_alloc_counter`] value.+ pub fn get_gc_zeal_alloc_counter(&self) -> Option<core::num::NonZeroU32> {+ self.tunables().gc_zeal_alloc_counter+ }++ /// Returns the configured [`Config::cranelift_opt_level`] value.+ pub fn get_cranelift_opt_level(&self) -> Option<OptLevel> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ let flags = compiler.flags();+ let (_, FlagValue::Enum(opt)) = flags.iter().find(|(f, _)| *f == "opt_level")? else {+ return None;+ };+ return match &opt[..] {+ "none" => Some(OptLevel::None),+ "speed" => Some(OptLevel::Speed),+ "speed_and_size" => Some(OptLevel::SpeedAndSize),+ _ => None,+ };+ }+ None+ }++ /// Returns the configured [`Config::cranelift_regalloc_algorithm`] value.+ pub fn get_cranelift_regalloc_algorithm(&self) -> Option<RegallocAlgorithm> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ let flags = compiler.flags();+ let (_, FlagValue::Enum(opt)) =+ flags.iter().find(|(f, _)| *f == "regalloc_algorithm")?+ else {+ return None;+ };+ return match &opt[..] {+ "backtracking" => Some(RegallocAlgorithm::Backtracking),+ "single_pass" => Some(RegallocAlgorithm::SinglePass),+ _ => None,+ };+ }+ None+ }++ /// Returns the configured [`Config::strategy`] value.+ pub fn get_strategy(&self) -> Option<Strategy> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ return self.config().compiler_config.as_ref()?.strategy;+ #[cfg(not(any(feature = "cranelift", feature = "winch")))]+ return None;+ }++ /// Returns the configured [`Config::collector`] value.+ pub fn get_collector(&self) -> Option<Collector> {+ #[cfg(feature = "gc")]+ return Some(self.config().collector);+ #[cfg(not(feature = "gc"))]+ return None;+ }++ /// Returns the configured [`Config::cranelift_debug_verifier`] value.+ pub fn get_cranelift_debug_verifier(&self) -> Option<bool> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ let flags = compiler.flags();+ let (_, FlagValue::Bool(b)) = flags.iter().find(|(f, _)| *f == "enable_verifier")?+ else {+ return None;+ };+ return Some(*b);+ }+ None+ }++ /// Returns the configured [`Config::compiler_inlining`] value.+ pub fn get_compiler_inlining(&self) -> Inlining {+ self.tunables().inlining+ }++ /// Returns the configured [`Config::native_unwind_info`] value.+ pub fn get_native_unwind_info(&self) -> Option<bool> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ let flags = compiler.flags();+ let (_, FlagValue::Bool(b)) = flags.iter().find(|(f, _)| *f == "unwind_info")? else {+ return None;+ };+ return Some(*b);+ }+ None+ }++ /// Returns the configured [`Config::parallel_compilation`] value.+ pub fn get_parallel_compilation(&self) -> bool {+ self.config().parallel_compilation+ }++ /// Returns the configured [`Config::metadata_for_internal_asserts`] value.+ pub fn get_metadata_for_internal_asserts(&self) -> bool {+ self.tunables().metadata_for_internal_asserts+ }++ /// Returns the configured [`Config::metadata_for_gc_heap_corruption`] value.+ pub fn get_metadata_for_gc_heap_corruption(&self) -> bool {+ self.tunables().metadata_for_gc_heap_corruption+ }++ /// Returns the runtime pooling allocator configuration, if the pooling+ /// allocator is in use.+ pub fn get_pooling_config(&self) -> Option<&PoolingAllocationConfig> {+ #[cfg(feature = "pooling-allocator")]+ {+ Some(self.allocator().as_pooling()?.config())+ }+ #[cfg(not(feature = "pooling-allocator"))]+ {+ None+ }+ }++ /// Returns the configured wasm proposals enabled in this engine.+ pub fn get_wasm_features(&self) -> WasmFeatures {+ self.features()+ }++ /// Returns the configured [`Config::async_stack_size`] value.+ pub fn get_async_stack_size(&self) -> usize {+ self.config().async_stack_size+ }++ /// Returns the configured [`Config::async_stack_zeroing`] value.+ pub fn get_async_stack_zeroing(&self) -> bool {+ self.config().async_stack_zeroing+ }++ /// Returns the configured [`Config::wasm_branch_hinting`] value.+ pub fn get_wasm_branch_hinting(&self) -> bool {+ self.tunables().branch_hinting+ }++ /// Returns the configured [`Config::concurrency_support`] value.+ pub fn get_concurrency_support(&self) -> bool {+ self.tunables().concurrency_support+ }++ /// Returns the configured [`Config::epoch_interruption`] value.+ pub fn get_epoch_interruption(&self) -> bool {+ self.tunables().epoch_interruption+ }++ /// Returns the configured [`Config::consume_fuel`] value.+ pub fn get_consume_fuel(&self) -> bool {+ self.tunables().consume_fuel+ }++ /// Returns the configured [`Config::max_wasm_stack`] value.+ pub fn get_max_wasm_stack(&self) -> usize {+ self.config().max_wasm_stack+ }++ /// Returns the configured [`Config::cranelift_nan_canonicalization`] value.+ pub fn get_cranelift_nan_canonicalization(&self) -> Option<bool> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ let flags = compiler.flags();+ let (_, FlagValue::Bool(b)) = flags+ .iter()+ .find(|(f, _)| *f == "enable_nan_canonicalization")?+ else {+ return None;+ };+ return Some(*b);+ }+ None+ }++ /// Returns the configured [`Config::relaxed_simd_deterministic`] value.+ pub fn get_relaxed_simd_deterministic(&self) -> bool {+ self.tunables().relaxed_simd_deterministic+ }++ /// Returns the configured [`Config::shared_memory`] value.+ pub fn get_shared_memory(&self) -> bool {+ self.config().shared_memory+ }++ /// Returns the configured [`Config::generate_address_map`] value.+ pub fn get_generate_address_map(&self) -> bool {+ self.tunables().generate_address_map+ }++ /// Returns the configured [`Config::debug_info`] value.+ pub fn get_debug_info(&self) -> bool {+ self.tunables().debug_native+ }++ /// Returns the configured [`Config::guest_debug`] value.+ pub fn get_guest_debug(&self) -> bool {+ self.tunables().debug_guest+ }++ /// Returns the configured [`Config::debug_symbols`] value.+ pub fn get_debug_symbols(&self) -> bool {+ self.tunables().debug_symbols+ }++ /// Returns the configured [`Config::wasm_backtrace_max_frames`] value.+ pub fn get_wasm_backtrace_max_frames(&self) -> usize {+ self.config()+ .wasm_backtrace_max_frames+ .map(|f| f.get())+ .unwrap_or(0)+ }++ /// Returns the configured [`Config::target`] value.+ pub fn get_target(&self) -> Option<String> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(compiler) = self.compiler() {+ return Some(compiler.triple().to_string());+ }+ None+ }++ /// Returns the enabled flags via [`Config::cranelift_flag_enable`].+ pub fn get_cranelift_flags_enabled(&self) -> impl Iterator<Item = &str> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(config) = &self.config().compiler_config {+ return config+ .flags+ .iter()+ .filter_map(|(k, v)| match v {+ UserSpecified::Yes => Some(k.as_str()),+ UserSpecified::No => None,+ })+ .collect::<Vec<_>>()+ .into_iter();+ }++ Vec::new().into_iter()+ }++ /// Returns the enabled flags via [`Config::cranelift_flag_set`].+ pub fn get_cranelift_flags_set(&self) -> impl Iterator<Item = (&str, &str)> {+ #[cfg(any(feature = "cranelift", feature = "winch"))]+ if let Some(config) = &self.config().compiler_config {+ return config+ .settings+ .iter()+ .filter_map(|(k, (v, s))| match s {+ UserSpecified::Yes => Some((k.as_str(), v.as_str())),+ UserSpecified::No => None,+ })+ .collect::<Vec<_>>()+ .into_iter();+ }++ Vec::new().into_iter()+ }+}diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rsindex 2039498158..a3e1bf7fae 100644--- a/crates/wasmtime/src/engine.rs+++ b/crates/wasmtime/src/engine.rs@@ -1,5 +1,3 @@-use crate::Config;-use crate::RRConfig;use crate::prelude::*;#[cfg(feature = "runtime")]pub use crate::runtime::code_memory::CustomCodeMemory;@@ -7,6 +5,7 @@ pub use crate::runtime::code_memory::CustomCodeMemory;use crate::runtime::type_registry::TypeRegistry;#[cfg(feature = "runtime")]use crate::runtime::vm::{GcRuntime, ModuleRuntimeInfo};+use crate::{Config, RRConfig};use alloc::sync::Arc;use core::ptr::NonNull;#[cfg(target_has_atomic = "64")]diff --git a/crates/wasmtime/src/runtime/vm.rs b/crates/wasmtime/src/runtime/vm.rsindex 7b9bac6be4..e97b4259ad 100644--- a/crates/wasmtime/src/runtime/vm.rs+++ b/crates/wasmtime/src/runtime/vm.rs@@ -106,8 +106,7 @@ pub use crate::runtime::vm::instance::{};#[cfg(feature = "pooling-allocator")]pub use crate::runtime::vm::instance::{- InstanceLimits, PoolConcurrencyLimitError, PoolingAllocatorMetrics, PoolingInstanceAllocator,- PoolingInstanceAllocatorConfig,+ PoolConcurrencyLimitError, PoolingAllocatorMetrics, PoolingInstanceAllocator,};pub use crate::runtime::vm::interpreter::*;pub use crate::runtime::vm::memory::{diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator.rs b/crates/wasmtime/src/runtime/vm/instance/allocator.rsindex 9c1f01c2da..c94853cb38 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator.rs@@ -29,8 +29,7 @@ pub use self::on_demand::OnDemandInstanceAllocator;mod pooling;#[cfg(feature = "pooling-allocator")]pub use self::pooling::{- InstanceLimits, PoolConcurrencyLimitError, PoolingAllocatorMetrics, PoolingInstanceAllocator,- PoolingInstanceAllocatorConfig,+ PoolConcurrencyLimitError, PoolingAllocatorMetrics, PoolingInstanceAllocator,};/// Represents a request for a new runtime instance.diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rsindex 2700d22637..ef350f978b 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs@@ -43,11 +43,13 @@ cfg_if::cfg_if! {use self::decommit_queue::DecommitQueue;use self::memory_pool::MemoryPool;+pub use self::metrics::PoolingAllocatorMetrics;use self::table_pool::TablePool;use super::{InstanceAllocationRequest, InstanceAllocator, MemoryAllocationIndex, TableAllocationIndex,};use crate::Enabled;+use crate::config::PoolingAllocationConfig;use crate::prelude::*;use crate::runtime::vm::{CompiledModuleId, Memory, Table,@@ -69,8 +71,6 @@ use wasmtime_environ::{DefinedMemoryIndex, DefinedTableIndex, HostPtr, MemoryKind, Module, Tunables, VMOffsets,};-pub use self::metrics::PoolingAllocatorMetrics;-#[cfg(feature = "gc")]use super::GcHeapAllocationIndex;#[cfg(feature = "gc")]@@ -93,168 +93,9 @@ fn round_up_to_pow2(n: usize, to: usize) -> usize {(n + to - 1) & !(to - 1)}-/// Instance-related limit configuration for pooling.-///-/// More docs on this can be found at `wasmtime::PoolingAllocationConfig`.-#[derive(Debug, Copy, Clone)]-pub struct InstanceLimits {- /// The maximum number of component instances that may be allocated- /// concurrently.- pub total_component_instances: u32,-- /// The maximum size of a component's `VMComponentContext`, including- /// the aggregate size of all its inner core modules' `VMContext` sizes.- pub component_instance_size: usize,-- /// The maximum number of core module instances that may be allocated- /// concurrently.- pub total_core_instances: u32,-- /// The maximum number of core module instances that a single component may- /// transitively contain.- pub max_core_instances_per_component: u32,-- /// The maximum number of Wasm linear memories that a component may- /// transitively contain.- pub max_memories_per_component: u32,-- /// The maximum number of tables that a component may transitively contain.- pub max_tables_per_component: u32,-- /// The total number of linear memories in the pool, across all instances.- pub total_memories: u32,-- /// The total number of tables in the pool, across all instances.- pub total_tables: u32,-- /// The total number of async stacks in the pool, across all instances.- #[cfg(feature = "async")]- pub total_stacks: u32,-- /// Maximum size of a core instance's `VMContext`.- pub core_instance_size: usize,-- /// Maximum number of tables per instance.- pub max_tables_per_module: u32,-- /// Maximum number of word-size elements per table.- ///- /// Note that tables for element types such as continuations- /// that use more than one word of storage may store fewer- /// elements.- pub table_elements: usize,-- /// Maximum number of linear memories per instance.- pub max_memories_per_module: u32,-- /// Maximum byte size of a linear memory, must be smaller than- /// `memory_reservation` in `Tunables`.- pub max_memory_size: usize,-- /// The total number of GC heaps in the pool, across all instances.- #[cfg(feature = "gc")]- pub total_gc_heaps: u32,-}--impl Default for InstanceLimits {- fn default() -> Self {- let total = if cfg!(target_pointer_width = "32") {- 100- } else {- 1000- };- // See doc comments for `wasmtime::PoolingAllocationConfig` for these- // default values- Self {- total_component_instances: total,- component_instance_size: 1 << 20, // 1 MiB- total_core_instances: total,- max_core_instances_per_component: u32::MAX,- max_memories_per_component: u32::MAX,- max_tables_per_component: u32::MAX,- total_memories: total,- total_tables: total,- #[cfg(feature = "async")]- total_stacks: total,- core_instance_size: 1 << 20, // 1 MiB- max_tables_per_module: 1,- // NB: in #8504 it was seen that a C# module in debug module can- // have 10k+ elements.- table_elements: 20_000,- max_memories_per_module: 1,- #[cfg(target_pointer_width = "64")]- max_memory_size: 1 << 32, // 4G,- #[cfg(target_pointer_width = "32")]- max_memory_size: 10 << 20, // 10 MiB- #[cfg(feature = "gc")]- total_gc_heaps: total,- }- }-}--/// Configuration options for the pooling instance allocator supplied at-/// construction.-#[derive(Copy, Clone, Debug)]-pub struct PoolingInstanceAllocatorConfig {- /// See `PoolingAllocatorConfig::max_unused_warm_slots` in `wasmtime`- pub max_unused_warm_slots: u32,- /// The target number of decommits to do per batch. This is not precise, as- /// we can queue up decommits at times when we aren't prepared to- /// immediately flush them, and so we may go over this target size- /// occasionally.- pub decommit_batch_size: usize,- /// The size, in bytes, of async stacks to allocate (not including the guard- /// page).- pub stack_size: usize,- /// The limits to apply to instances allocated within this allocator.- pub limits: InstanceLimits,- /// Whether or not async stacks are zeroed after use.- pub async_stack_zeroing: bool,- /// If async stack zeroing is enabled and the host platform is Linux this is- /// how much memory to zero out with `memset`.- ///- /// The rest of memory will be zeroed out with `madvise`.- #[cfg(feature = "async")]- pub async_stack_keep_resident: usize,- /// How much linear memory, in bytes, to keep resident after resetting for- /// use with the next instance. This much memory will be `memset` to zero- /// when a linear memory is deallocated.- ///- /// Memory exceeding this amount in the wasm linear memory will be released- /// with `madvise` back to the kernel.- ///- /// Only applicable on Linux.- pub linear_memory_keep_resident: usize,- /// Same as `linear_memory_keep_resident` but for tables.- pub table_keep_resident: usize,- /// Whether to enable memory protection keys.- pub memory_protection_keys: Enabled,- /// How many memory protection keys to allocate.- pub max_memory_protection_keys: usize,- /// Whether to enable PAGEMAP_SCAN on Linux.- pub pagemap_scan: Enabled,-}--impl Default for PoolingInstanceAllocatorConfig {- fn default() -> PoolingInstanceAllocatorConfig {- PoolingInstanceAllocatorConfig {- max_unused_warm_slots: 100,- decommit_batch_size: 1,- stack_size: 2 << 20,- limits: InstanceLimits::default(),- async_stack_zeroing: false,- #[cfg(feature = "async")]- async_stack_keep_resident: 0,- linear_memory_keep_resident: 0,- table_keep_resident: 0,- memory_protection_keys: Enabled::No,- max_memory_protection_keys: 16,- pagemap_scan: Enabled::No,- }- }-}--impl PoolingInstanceAllocatorConfig {+impl PoolingAllocationConfig {+ /// Tests whether [`Self::pagemap_scan`] is available or not on the host+ /// system.pub fn is_pagemap_scan_available() -> bool {PageMap::new().is_some()}@@ -297,9 +138,6 @@ impl PoolConcurrencyLimitError {/// terminates correctly.#[derive(Debug)]pub struct PoolingInstanceAllocator {- decommit_batch_size: usize,- limits: InstanceLimits,-// The number of live core module and component instances at any given// time. Note that this can temporarily go over the configured limit. This// doesn't mean we have actually overshot, but that we attempted to allocate@@ -329,6 +167,7 @@ pub struct PoolingInstanceAllocator {live_stacks: AtomicUsize,pagemap: Option<PageMap>,+ config: PoolingAllocationConfig,}impl Drop for PoolingInstanceAllocator {@@ -371,10 +210,8 @@ impl Drop for PoolingInstanceAllocator {impl PoolingInstanceAllocator {/// Creates a new pooling instance allocator with the given strategy and limits.- pub fn new(config: &PoolingInstanceAllocatorConfig, tunables: &Tunables) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig, tunables: &Tunables) -> Result<Self> {Ok(Self {- decommit_batch_size: config.decommit_batch_size,- limits: config.limits,live_component_instances: AtomicU64::new(0),live_core_instances: AtomicU64::new(0),decommit_queue: Mutex::new(DecommitQueue::default()),@@ -404,11 +241,15 @@ impl PoolingInstanceAllocator {})?),Enabled::No => None,},+ config: config.clone(),})}fn core_instance_size(&self) -> usize {- round_up_to_pow2(self.limits.core_instance_size, mem::align_of::<Instance>())+ round_up_to_pow2(+ self.config.limits.core_instance_size,+ mem::align_of::<Instance>(),+ )}fn validate_table_plans(&self, module: &Module) -> Result<()> {@@ -484,7 +325,7 @@ impl PoolingInstanceAllocator {) -> Result<()> {let vmcomponentctx_size = usize::try_from(offsets.size_of_vmctx()).unwrap();let total_instance_size = core_instances_aggregate_size.saturating_add(vmcomponentctx_size);- if total_instance_size <= self.limits.component_instance_size {+ if total_instance_size <= self.config.limits.component_instance_size {return Ok(());}@@ -495,7 +336,7 @@ impl PoolingInstanceAllocator {and aggregated core instance runtime space which exceeds the configured maximum of {} bytes. \`VMComponentContext` used {vmcomponentctx_size} bytes, `core module instances` used \{core_instances_aggregate_size} bytes.",- self.limits.component_instance_size+ self.config.limits.component_instance_size)}@@ -537,7 +378,7 @@ impl PoolingInstanceAllocator {// We enqueued at least our batch size of regions for decommit, so// flush the local queue immediately. Don't bother inspecting (or// locking!) the shared queue.- n if n >= self.decommit_batch_size => {+ n if n >= self.config.decommit_batch_size => {local_queue.flush(self);}@@ -545,18 +386,22 @@ impl PoolingInstanceAllocator {// batch size, so we don't want to flush it yet, then merge the// local queue into the shared queue.n => {- debug_assert!(n < self.decommit_batch_size);+ debug_assert!(n < self.config.decommit_batch_size);let mut shared_queue = self.decommit_queue.lock().unwrap();shared_queue.append(&mut local_queue);// And if the shared queue now has at least as many regions// enqueued for decommit as our batch size, then we can flush// it.- if shared_queue.raw_len() >= self.decommit_batch_size {+ if shared_queue.raw_len() >= self.config.decommit_batch_size {self.flush_decommit_queue(shared_queue);}}}}++ pub fn config(&self) -> &PoolingAllocationConfig {+ &self.config+ }}unsafe impl InstanceAllocator for PoolingInstanceAllocator {@@ -601,28 +446,28 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {}if num_core_instances- > usize::try_from(self.limits.max_core_instances_per_component).unwrap()+ > usize::try_from(self.config.limits.max_core_instances_per_component).unwrap(){bail!("The component transitively contains {num_core_instances} core module instances, \which exceeds the configured maximum of {} in the pooling allocator",- self.limits.max_core_instances_per_component+ self.config.limits.max_core_instances_per_component);}- if num_memories > usize::try_from(self.limits.max_memories_per_component).unwrap() {+ if num_memories > usize::try_from(self.config.limits.max_memories_per_component).unwrap() {bail!("The component transitively contains {num_memories} Wasm linear memories, which \exceeds the configured maximum of {} in the pooling allocator",- self.limits.max_memories_per_component+ self.config.limits.max_memories_per_component);}- if num_tables > usize::try_from(self.limits.max_tables_per_component).unwrap() {+ if num_tables > usize::try_from(self.config.limits.max_tables_per_component).unwrap() {bail!("The component transitively contains {num_tables} tables, which exceeds the \configured maximum of {} in the pooling allocator",- self.limits.max_tables_per_component+ self.config.limits.max_tables_per_component);}@@ -650,10 +495,10 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {#[cfg(feature = "component-model")]fn increment_component_instance_count(&self) -> Result<()> {let old_count = self.live_component_instances.fetch_add(1, Ordering::AcqRel);- if old_count >= u64::from(self.limits.total_component_instances) {+ if old_count >= u64::from(self.config.limits.total_component_instances) {self.decrement_component_instance_count();return Err(PoolConcurrencyLimitError::new(- usize::try_from(self.limits.total_component_instances).unwrap(),+ usize::try_from(self.config.limits.total_component_instances).unwrap(),"component instances",).into());@@ -668,10 +513,10 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {fn increment_core_instance_count(&self) -> Result<()> {let old_count = self.live_core_instances.fetch_add(1, Ordering::AcqRel);- if old_count >= u64::from(self.limits.total_core_instances) {+ if old_count >= u64::from(self.config.limits.total_core_instances) {self.decrement_core_instance_count();return Err(PoolConcurrencyLimitError::new(- usize::try_from(self.limits.total_core_instances).unwrap(),+ usize::try_from(self.config.limits.total_core_instances).unwrap(),"core instances",).into());@@ -915,16 +760,17 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {#[cfg(target_pointer_width = "64")]mod test {use super::*;+ use crate::config::InstanceLimits;#[test]fn test_pooling_allocator_with_memory_pages_exceeded() {- let config = PoolingInstanceAllocatorConfig {+ let config = PoolingAllocationConfig {limits: InstanceLimits {total_memories: 1,max_memory_size: 0x100010000,..Default::default()},- ..PoolingInstanceAllocatorConfig::default()+ ..PoolingAllocationConfig::default()};assert_eq!(PoolingInstanceAllocator::new(@@ -950,7 +796,7 @@ mod test {))]#[test]fn test_stack_zeroed() -> Result<()> {- let config = PoolingInstanceAllocatorConfig {+ let config = PoolingAllocationConfig {max_unused_warm_slots: 0,limits: InstanceLimits {total_stacks: 1,@@ -960,7 +806,7 @@ mod test {},stack_size: 128,async_stack_zeroing: true,- ..PoolingInstanceAllocatorConfig::default()+ ..PoolingAllocationConfig::default()};let allocator = PoolingInstanceAllocator::new(&config, &Tunables::default_host())?;@@ -990,7 +836,7 @@ mod test {))]#[test]fn test_stack_unzeroed() -> Result<()> {- let config = PoolingInstanceAllocatorConfig {+ let config = PoolingAllocationConfig {max_unused_warm_slots: 0,limits: InstanceLimits {total_stacks: 1,@@ -1000,7 +846,7 @@ mod test {},stack_size: 128,async_stack_zeroing: false,- ..PoolingInstanceAllocatorConfig::default()+ ..PoolingAllocationConfig::default()};let allocator = PoolingInstanceAllocator::new(&config, &Tunables::default_host())?;diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rsindex 0de2c479a5..2a5e47e7f7 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/gc_heap_pool.rs@@ -1,6 +1,7 @@use super::index_allocator::{SimpleIndexAllocator, SlotId};use super::{GcHeapAllocationIndex, PoolConcurrencyLimitError};-use crate::runtime::vm::{GcHeap, GcRuntime, PoolingInstanceAllocatorConfig, Result};+use crate::config::PoolingAllocationConfig;+use crate::runtime::vm::{GcHeap, GcRuntime, Result};use crate::vm::MemoryAllocationIndex;use crate::{Engine, prelude::*};use std::sync::Mutex;@@ -58,7 +59,7 @@ impl std::fmt::Debug for GcHeapPool {impl GcHeapPool {/// Create a new `GcHeapPool` with the given configuration.- pub fn new(config: &PoolingInstanceAllocatorConfig, tunables: &Tunables) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig, tunables: &Tunables) -> Result<Self> {// When using the pooling allocator, GC heaps and linear memories share// the same underlying memory pool, so they must be configured the same.debug_assert_eq!(diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/generic_stack_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/generic_stack_pool.rsindex af883d48b1..0a990d7308 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/generic_stack_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/generic_stack_pool.rs@@ -4,8 +4,8 @@)]use crate::PoolConcurrencyLimitError;+use crate::config::PoolingAllocationConfig;use crate::prelude::*;-use crate::runtime::vm::PoolingInstanceAllocatorConfig;use std::sync::atomic::{AtomicU64, Ordering};/// A generic implementation of a stack pool.@@ -33,7 +33,7 @@ impl StackPool {false}- pub fn new(config: &PoolingInstanceAllocatorConfig) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig) -> Result<Self> {Ok(StackPool {stack_size: config.stack_size,stack_zeroing: config.async_stack_zeroing,diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rsindex aaa26ef5f5..305f032992 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs@@ -54,10 +54,12 @@ use super::{MemoryAllocationIndex,index_allocator::{MemoryInModule, ModuleAffinityIndexAllocator, SlotId},};+use crate::config::InstanceLimits;+use crate::config::PoolingAllocationConfig;use crate::prelude::*;use crate::runtime::vm::{- CompiledModuleId, InstanceAllocationRequest, InstanceLimits, Memory, MemoryBase,- MemoryImageSlot, Mmap, MmapOffset, PoolingInstanceAllocatorConfig, mmap::AlignedLength,+ CompiledModuleId, InstanceAllocationRequest, Memory, MemoryBase, MemoryImageSlot, Mmap,+ MmapOffset, mmap::AlignedLength,};use crate::{Enabled,@@ -173,7 +175,7 @@ enum ImageSlot {impl MemoryPool {/// Create a new `MemoryPool`.- pub fn new(config: &PoolingInstanceAllocatorConfig, tunables: &Tunables) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig, tunables: &Tunables) -> Result<Self> {if u64::try_from(config.limits.max_memory_size).unwrap() > tunables.memory_reservation {bail!("maximum memory size of {:#x} bytes exceeds the configured \@@ -894,7 +896,7 @@ mod tests {#[test]fn test_memory_pool() -> Result<()> {let pool = MemoryPool::new(- &PoolingInstanceAllocatorConfig {+ &PoolingAllocationConfig {limits: InstanceLimits {total_memories: 5,max_tables_per_module: 0,@@ -939,9 +941,9 @@ mod tests {}// Force the use of MPK.- let config = PoolingInstanceAllocatorConfig {+ let config = PoolingAllocationConfig {memory_protection_keys: Enabled::Yes,- ..PoolingInstanceAllocatorConfig::default()+ ..PoolingAllocationConfig::default()};let pool = MemoryPool::new(&config, &Tunables::default_host()).unwrap();assert!(pool.stripes.len() >= 2);diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rsindex 46e1da9d96..1d10026ee9 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs@@ -2,10 +2,10 @@ use super::{TableAllocationIndex,index_allocator::{SimpleIndexAllocator, SlotId},};+use crate::config::PoolingAllocationConfig;use crate::runtime::vm::sys::vm::{PageMap, commit_pages, reset_with_pagemap};use crate::runtime::vm::{- InstanceAllocationRequest, Mmap, PoolingInstanceAllocatorConfig, SendSyncPtr, Table,- mmap::AlignedLength,+ InstanceAllocationRequest, Mmap, SendSyncPtr, Table, mmap::AlignedLength,};use crate::{prelude::*, vm::HostAlignedByteCount};use std::ptr::NonNull;@@ -28,7 +28,7 @@ pub struct TablePool {impl TablePool {/// Create a new `TablePool`.- pub fn new(config: &PoolingInstanceAllocatorConfig) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig) -> Result<Self> {let table_size = HostAlignedByteCount::new_rounded_up(crate::runtime::vm::table::NOMINAL_MAX_TABLE_ELEM_SIZE.checked_mul(config.limits.table_elements)@@ -260,11 +260,11 @@ impl TablePool {#[cfg(test)]mod tests {use super::*;- use crate::runtime::vm::InstanceLimits;+ use crate::config::InstanceLimits;#[test]fn test_table_pool() -> Result<()> {- let pool = TablePool::new(&PoolingInstanceAllocatorConfig {+ let pool = TablePool::new(&PoolingAllocationConfig {limits: InstanceLimits {total_tables: 7,table_elements: 100,@@ -298,7 +298,7 @@ mod tests {#[test]fn test_table_pool_continuations_capacity() -> Result<()> {let mkpool = |table_elements: usize| -> Result<TablePool> {- TablePool::new(&PoolingInstanceAllocatorConfig {+ TablePool::new(&PoolingAllocationConfig {limits: InstanceLimits {table_elements,total_tables: 7,diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rsindex 13e788e179..fa1718f26e 100644--- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs+++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs@@ -1,10 +1,9 @@#![cfg_attr(asan, allow(dead_code))]use super::index_allocator::{SimpleIndexAllocator, SlotId};+use crate::config::PoolingAllocationConfig;use crate::prelude::*;-use crate::runtime::vm::{- HostAlignedByteCount, Mmap, PoolingInstanceAllocatorConfig, mmap::AlignedLength,-};+use crate::runtime::vm::{HostAlignedByteCount, Mmap, mmap::AlignedLength};/// Represents a pool of execution stacks (used for the async fiber implementation).///@@ -33,7 +32,7 @@ impl StackPool {true}- pub fn new(config: &PoolingInstanceAllocatorConfig) -> Result<Self> {+ pub fn new(config: &PoolingAllocationConfig) -> Result<Self> {use rustix::mm::{MprotectFlags, mprotect};let page_size = HostAlignedByteCount::host_page_size();@@ -262,18 +261,18 @@ impl StackPool {#[cfg(all(test, unix, feature = "async", not(miri), not(asan)))]mod tests {use super::*;- use crate::runtime::vm::InstanceLimits;+ use crate::config::InstanceLimits;#[test]fn test_stack_pool() -> Result<()> {- let config = PoolingInstanceAllocatorConfig {+ let config = PoolingAllocationConfig {limits: InstanceLimits {total_stacks: 10,..Default::default()},stack_size: 1,async_stack_zeroing: true,- ..PoolingInstanceAllocatorConfig::default()+ ..PoolingAllocationConfig::default()};let pool = StackPool::new(&config)?;