From b20128a6cbcbcbcb0b8fcdc057369ce6c5146e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Cabrera?= Date: Thu, 27 Oct 2022 10:38:44 -0400 Subject: [PATCH] Expose type information in module translation (#5139) This adds a new field `types` to `ModuleTranslation`, so that consumers can have access to the module type information known after validation has finished. This change is useful when consumers want to have access to the type information in wasmparser's terms rather than in wasmtime_environ's equivalent types (e.g. `WasmFuncType`). --- crates/environ/src/module_environ.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index e8f1e8e296..a48ad952f3 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -14,7 +14,7 @@ use std::convert::{TryFrom, TryInto}; use std::path::PathBuf; use std::sync::Arc; use wasmparser::{ - CustomSectionReader, DataKind, ElementItem, ElementKind, Encoding, ExternalKind, + types::Types, CustomSectionReader, DataKind, ElementItem, ElementKind, Encoding, ExternalKind, FuncToValidate, FunctionBody, NameSectionReader, Naming, Operator, Parser, Payload, Type, TypeRef, Validator, ValidatorResources, }; @@ -90,6 +90,19 @@ pub struct ModuleTranslation<'data> { /// When we're parsing the code section this will be incremented so we know /// which function is currently being defined. code_index: u32, + + /// The type information of the current module made available at the end of the + /// validation process. + types: Option, +} + +impl<'data> ModuleTranslation<'data> { + /// Returns a reference to the type information of the current module. + pub fn get_types(&self) -> &Types { + self.types + .as_ref() + .expect("module type information to be available") + } } /// Contains function data: byte code and its offset in the module. @@ -195,7 +208,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { } Payload::End(offset) => { - self.validator.end(offset)?; + self.result.types = Some(self.validator.end(offset)?); // With the `escaped_funcs` set of functions finished // we can calculate the set of signatures that are exported as @@ -622,7 +635,7 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { "\ Support for interface types has temporarily been removed from `wasmtime`. -For more information about this temoprary you can read on the issue online: +For more information about this temporary change you can read on the issue online: https://github.com/bytecodealliance/wasmtime/issues/1271