Enable the SIMD proposal by default (#3601)

* Enable the SIMD proposal by default

This commit updates Wasmtime to enable the SIMD proposal for WebAssembly
by default. Support has been implemented for quite some time and
recently fuzzing has been running for multiple weeks without incident,
so it seems like it might be time to go ahead and enable this!

* Refactor CLI feature specification

Don't store a `bool` but rather an `Option<bool>` so we can inherit the
defaults from Wasmtime rather than having to keep the defaults in-sync.
This commit is contained in:
Alex Crichton
2021-12-14 16:57:52 -06:00
committed by GitHub
parent 8ac4d872db
commit 2cdbf32a06
2 changed files with 95 additions and 87 deletions

View File

@@ -138,6 +138,7 @@ impl Config {
ret.wasm_reference_types(true); ret.wasm_reference_types(true);
ret.wasm_multi_value(true); ret.wasm_multi_value(true);
ret.wasm_bulk_memory(true); ret.wasm_bulk_memory(true);
ret.wasm_simd(true);
ret.wasm_backtrace_details(WasmBacktraceDetails::Environment); ret.wasm_backtrace_details(WasmBacktraceDetails::Environment);
ret ret
} }
@@ -433,23 +434,15 @@ impl Config {
/// Configures whether the WebAssembly SIMD proposal will be /// Configures whether the WebAssembly SIMD proposal will be
/// enabled for compilation. /// enabled for compilation.
/// ///
/// The [WebAssembly SIMD proposal][proposal] is not currently /// The [WebAssembly SIMD proposal][proposal]. This feature gates items such
/// fully standardized and is undergoing development. Additionally the /// as the `v128` type and all of its operators being in a module. Note that
/// support in wasmtime itself is still being worked on. Support for this /// this does not enable the [relaxed simd proposal] as that is not
/// feature can be enabled through this method for appropriate wasm /// implemented in Wasmtime at this time.
/// modules.
/// ///
/// This feature gates items such as the `v128` type and all of its /// This is `true` by default.
/// operators being in a module.
///
/// This is `false` by default.
///
/// > **Note**: Wasmtime does not implement everything for the wasm simd
/// > spec at this time, so bugs, panics, and possibly segfaults should be
/// > expected. This should not be enabled in a production setting right
/// > now.
/// ///
/// [proposal]: https://github.com/webassembly/simd /// [proposal]: https://github.com/webassembly/simd
/// [relaxed simd proposal]: https://github.com/WebAssembly/relaxed-simd
pub fn wasm_simd(&mut self, enable: bool) -> &mut Self { pub fn wasm_simd(&mut self, enable: bool) -> &mut Self {
self.features.simd = enable; self.features.simd = enable;
#[cfg(compiler)] #[cfg(compiler)]

View File

@@ -164,7 +164,7 @@ struct CommonOptions {
/// Enables or disables WebAssembly features /// Enables or disables WebAssembly features
#[structopt(long, value_name = "FEATURE,FEATURE,...", parse(try_from_str = parse_wasm_features))] #[structopt(long, value_name = "FEATURE,FEATURE,...", parse(try_from_str = parse_wasm_features))]
wasm_features: Option<wasmparser::WasmFeatures>, wasm_features: Option<WasmFeatures>,
/// Enables or disables WASI modules /// Enables or disables WASI modules
#[structopt(long, value_name = "MODULE,MODULE,...", parse(try_from_str = parse_wasi_modules))] #[structopt(long, value_name = "MODULE,MODULE,...", parse(try_from_str = parse_wasi_modules))]
@@ -305,17 +305,41 @@ impl CommonOptions {
} }
fn enable_wasm_features(&self, config: &mut Config) { fn enable_wasm_features(&self, config: &mut Config) {
let features = self.wasm_features.unwrap_or_default(); let WasmFeatures {
simd,
bulk_memory,
reference_types,
multi_value,
threads,
multi_memory,
memory64,
module_linking,
} = self.wasm_features.unwrap_or_default();
config if let Some(enable) = simd {
.wasm_simd(features.simd) config.wasm_simd(enable);
.wasm_bulk_memory(features.bulk_memory) }
.wasm_reference_types(features.reference_types) if let Some(enable) = bulk_memory {
.wasm_multi_value(features.multi_value) config.wasm_bulk_memory(enable);
.wasm_threads(features.threads) }
.wasm_multi_memory(features.multi_memory) if let Some(enable) = reference_types {
.wasm_memory64(features.memory64) config.wasm_reference_types(enable);
.wasm_module_linking(features.module_linking); }
if let Some(enable) = multi_value {
config.wasm_multi_value(enable);
}
if let Some(enable) = threads {
config.wasm_threads(enable);
}
if let Some(enable) = multi_memory {
config.wasm_multi_memory(enable);
}
if let Some(enable) = memory64 {
config.wasm_memory64(enable);
}
if let Some(enable) = module_linking {
config.wasm_module_linking(enable);
}
} }
fn opt_level(&self) -> wasmtime::OptLevel { fn opt_level(&self) -> wasmtime::OptLevel {
@@ -339,7 +363,19 @@ fn parse_opt_level(opt_level: &str) -> Result<wasmtime::OptLevel> {
} }
} }
fn parse_wasm_features(features: &str) -> Result<wasmparser::WasmFeatures> { #[derive(Default, Clone, Copy)]
struct WasmFeatures {
reference_types: Option<bool>,
multi_value: Option<bool>,
bulk_memory: Option<bool>,
simd: Option<bool>,
module_linking: Option<bool>,
threads: Option<bool>,
multi_memory: Option<bool>,
memory64: Option<bool>,
}
fn parse_wasm_features(features: &str) -> Result<WasmFeatures> {
let features = features.trim(); let features = features.trim();
let mut all = None; let mut all = None;
@@ -377,18 +413,15 @@ fn parse_wasm_features(features: &str) -> Result<wasmparser::WasmFeatures> {
} }
} }
Ok(wasmparser::WasmFeatures { Ok(WasmFeatures {
reference_types: all.unwrap_or(values["reference-types"].unwrap_or(true)), reference_types: all.or(values["reference-types"]),
multi_value: all.unwrap_or(values["multi-value"].unwrap_or(true)), multi_value: all.or(values["multi-value"]),
bulk_memory: all.unwrap_or(values["bulk-memory"].unwrap_or(true)), bulk_memory: all.or(values["bulk-memory"]),
module_linking: all.unwrap_or(values["module-linking"].unwrap_or(false)), module_linking: all.or(values["module-linking"]),
simd: all.unwrap_or(values["simd"].unwrap_or(false)), simd: all.or(values["simd"]),
threads: all.unwrap_or(values["threads"].unwrap_or(false)), threads: all.or(values["threads"]),
tail_call: false, multi_memory: all.or(values["multi-memory"]),
deterministic_only: false, memory64: all.or(values["memory64"]),
multi_memory: all.unwrap_or(values["multi-memory"].unwrap_or(false)),
exceptions: false,
memory64: all.unwrap_or(values["memory64"].unwrap_or(false)),
}) })
} }
@@ -483,31 +516,25 @@ mod test {
fn test_all_features() -> Result<()> { fn test_all_features() -> Result<()> {
let options = CommonOptions::from_iter_safe(vec!["foo", "--wasm-features=all"])?; let options = CommonOptions::from_iter_safe(vec!["foo", "--wasm-features=all"])?;
let wasmparser::WasmFeatures { let WasmFeatures {
reference_types, reference_types,
multi_value, multi_value,
bulk_memory, bulk_memory,
module_linking, module_linking,
simd, simd,
threads, threads,
tail_call,
deterministic_only,
multi_memory, multi_memory,
exceptions,
memory64, memory64,
} = options.wasm_features.unwrap(); } = options.wasm_features.unwrap();
assert!(reference_types); assert_eq!(reference_types, Some(true));
assert!(multi_value); assert_eq!(multi_value, Some(true));
assert!(bulk_memory); assert_eq!(bulk_memory, Some(true));
assert!(module_linking); assert_eq!(module_linking, Some(true));
assert!(simd); assert_eq!(simd, Some(true));
assert!(threads); assert_eq!(threads, Some(true));
assert!(!tail_call); // Not supported assert_eq!(multi_memory, Some(true));
assert!(!deterministic_only); // Not supported assert_eq!(memory64, Some(true));
assert!(multi_memory);
assert!(!exceptions); // Not supported
assert!(memory64);
Ok(()) Ok(())
} }
@@ -516,31 +543,25 @@ mod test {
fn test_no_features() -> Result<()> { fn test_no_features() -> Result<()> {
let options = CommonOptions::from_iter_safe(vec!["foo", "--wasm-features=-all"])?; let options = CommonOptions::from_iter_safe(vec!["foo", "--wasm-features=-all"])?;
let wasmparser::WasmFeatures { let WasmFeatures {
reference_types, reference_types,
multi_value, multi_value,
bulk_memory, bulk_memory,
module_linking, module_linking,
simd, simd,
threads, threads,
tail_call,
deterministic_only,
multi_memory, multi_memory,
exceptions,
memory64, memory64,
} = options.wasm_features.unwrap(); } = options.wasm_features.unwrap();
assert!(!reference_types); assert_eq!(reference_types, Some(false));
assert!(!multi_value); assert_eq!(multi_value, Some(false));
assert!(!bulk_memory); assert_eq!(bulk_memory, Some(false));
assert!(!module_linking); assert_eq!(module_linking, Some(false));
assert!(!simd); assert_eq!(simd, Some(false));
assert!(!threads); assert_eq!(threads, Some(false));
assert!(!tail_call); assert_eq!(multi_memory, Some(false));
assert!(!deterministic_only); assert_eq!(memory64, Some(false));
assert!(!multi_memory);
assert!(!exceptions);
assert!(!memory64);
Ok(()) Ok(())
} }
@@ -552,31 +573,25 @@ mod test {
"--wasm-features=-reference-types,simd,multi-memory,memory64", "--wasm-features=-reference-types,simd,multi-memory,memory64",
])?; ])?;
let wasmparser::WasmFeatures { let WasmFeatures {
reference_types, reference_types,
multi_value, multi_value,
bulk_memory, bulk_memory,
module_linking, module_linking,
simd, simd,
threads, threads,
tail_call,
deterministic_only,
multi_memory, multi_memory,
exceptions,
memory64, memory64,
} = options.wasm_features.unwrap(); } = options.wasm_features.unwrap();
assert!(!reference_types); assert_eq!(reference_types, Some(false));
assert!(multi_value); assert_eq!(multi_value, None);
assert!(bulk_memory); assert_eq!(bulk_memory, None);
assert!(!module_linking); assert_eq!(module_linking, None);
assert!(simd); assert_eq!(simd, Some(true));
assert!(!threads); assert_eq!(threads, None);
assert!(!tail_call); // Not supported assert_eq!(multi_memory, Some(true));
assert!(!deterministic_only); // Not supported assert_eq!(memory64, Some(true));
assert!(multi_memory);
assert!(!exceptions); // Not supported
assert!(memory64);
Ok(()) Ok(())
} }
@@ -588,18 +603,18 @@ mod test {
let options = let options =
CommonOptions::from_iter_safe(vec!["foo", concat!("--wasm-features=", $flag)])?; CommonOptions::from_iter_safe(vec!["foo", concat!("--wasm-features=", $flag)])?;
let wasmparser::WasmFeatures { $name, .. } = options.wasm_features.unwrap(); let WasmFeatures { $name, .. } = options.wasm_features.unwrap();
assert!($name); assert_eq!($name, Some(true));
let options = CommonOptions::from_iter_safe(vec![ let options = CommonOptions::from_iter_safe(vec![
"foo", "foo",
concat!("--wasm-features=-", $flag), concat!("--wasm-features=-", $flag),
])?; ])?;
let wasmparser::WasmFeatures { $name, .. } = options.wasm_features.unwrap(); let WasmFeatures { $name, .. } = options.wasm_features.unwrap();
assert!(!$name); assert_eq!($name, Some(false));
Ok(()) Ok(())
} }