Update support for the module linking proposal

This commit updates the various tooling used by wasmtime which has new
updates to the module linking proposal. This is done primarily to sync
with WebAssembly/module-linking#26. The main change implemented here is
that wasmtime now supports creating instances from a set of values, nott
just from instantiating a module. Additionally subtyping handling of
modules with respect to imports is now properly handled by desugaring
two-level imports to imports of instances.

A number of small refactorings are included here as well, but most of
them are in accordance with the changes to `wasmparser` and the updated
binary format for module linking.
This commit is contained in:
Alex Crichton
2021-01-12 10:44:11 -08:00
parent 705af0ac41
commit 703762c49e
45 changed files with 1041 additions and 747 deletions

View File

@@ -4,8 +4,8 @@ use crate::environ::{ModuleEnvironment, WasmResult};
use crate::sections_translator::{
parse_alias_section, parse_data_section, parse_element_section, parse_event_section,
parse_export_section, parse_function_section, parse_global_section, parse_import_section,
parse_instance_section, parse_memory_section, parse_module_section, parse_name_section,
parse_start_section, parse_table_section, parse_type_section,
parse_instance_section, parse_memory_section, parse_name_section, parse_start_section,
parse_table_section, parse_type_section,
};
use crate::state::ModuleTranslationState;
use cranelift_codegen::timing;
@@ -22,23 +22,16 @@ pub fn translate_module<'data>(
let mut module_translation_state = ModuleTranslationState::new();
let mut validator = Validator::new();
validator.wasm_features(environ.wasm_features());
let mut stack = Vec::new();
let mut modules = 1;
let mut cur_module = 0;
for payload in Parser::new(0).parse_all(data) {
match payload? {
Payload::Version { num, range } => {
validator.version(num, &range)?;
environ.module_start(cur_module);
environ.module_start();
}
Payload::End => {
validator.end()?;
environ.module_end(cur_module);
if let Some((other, other_index)) = stack.pop() {
validator = other;
cur_module = other_index;
}
environ.module_end();
}
Payload::TypeSection(types) => {
@@ -111,10 +104,6 @@ pub fn translate_module<'data>(
environ.reserve_passive_data(count)?;
}
Payload::ModuleSection(s) => {
validator.module_section(&s)?;
parse_module_section(s, environ)?;
}
Payload::InstanceSection(s) => {
validator.instance_section(&s)?;
parse_instance_section(s, environ)?;
@@ -123,20 +112,17 @@ pub fn translate_module<'data>(
validator.alias_section(&s)?;
parse_alias_section(s, environ)?;
}
Payload::ModuleCodeSectionStart {
Payload::ModuleSectionStart {
count,
range,
size: _,
} => {
validator.module_code_section_start(count, &range)?;
validator.module_section_start(count, &range)?;
environ.reserve_modules(count);
}
Payload::ModuleCodeSectionEntry { .. } => {
let subvalidator = validator.module_code_section_entry();
stack.push((validator, cur_module));
validator = subvalidator;
cur_module = modules;
modules += 1;
Payload::ModuleSectionEntry { .. } => {
validator.module_section_entry();
}
Payload::CustomSection {