Validate functions in parallel in Module::validate (#3394)
We already validate wasm functions in parallel when compiling a module, but the same parallelism wasn't available to the `Module::validate` API. This commit peforms a minor tweak to the validate-the-whole-module API to validate all functions in parallel in the same manner that module compilation does.
This commit is contained in:
@@ -8,7 +8,7 @@ use std::fs;
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasmparser::Validator;
|
use wasmparser::{Parser, ValidPayload, Validator};
|
||||||
use wasmtime_environ::{ModuleEnvironment, ModuleIndex, PrimaryMap};
|
use wasmtime_environ::{ModuleEnvironment, ModuleIndex, PrimaryMap};
|
||||||
use wasmtime_jit::{CompiledModule, CompiledModuleInfo, MmapVec, TypeTables};
|
use wasmtime_jit::{CompiledModule, CompiledModuleInfo, MmapVec, TypeTables};
|
||||||
|
|
||||||
@@ -593,7 +593,15 @@ impl Module {
|
|||||||
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()> {
|
pub fn validate(engine: &Engine, binary: &[u8]) -> Result<()> {
|
||||||
let mut validator = Validator::new();
|
let mut validator = Validator::new();
|
||||||
validator.wasm_features(engine.config().features);
|
validator.wasm_features(engine.config().features);
|
||||||
validator.validate_all(binary)?;
|
|
||||||
|
let mut functions = Vec::new();
|
||||||
|
for payload in Parser::new(0).parse_all(binary) {
|
||||||
|
if let ValidPayload::Func(a, b) = validator.payload(&payload?)? {
|
||||||
|
functions.push((a, b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.run_maybe_parallel(functions, |(mut validator, body)| validator.validate(&body))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user