From 1eeec7b698e0ef82914d6824a3e6f0cfe6b59276 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 1 Dec 2022 11:04:36 -0800 Subject: [PATCH] cranelift-wasm: Remove `ModuleTranslationState` (#5365) * cranelift-wasm: Remove `ModuleTranslationState` We were putting data into it, but never reading data out of it. Can be removed. * cranelift-wasm: move `funct_state.rs` sub module to `state.rs` Since it is the only submodule of `state` it can just be the whole `state` module. --- cranelift/wasm/src/lib.rs | 3 +- cranelift/wasm/src/module_translator.rs | 8 ++--- cranelift/wasm/src/sections_translator.rs | 7 ----- .../src/{state/func_state.rs => state.rs} | 3 -- cranelift/wasm/src/state/mod.rs | 14 --------- cranelift/wasm/src/state/module_state.rs | 31 ------------------- 6 files changed, 4 insertions(+), 62 deletions(-) rename cranelift/wasm/src/{state/func_state.rs => state.rs} (99%) delete mode 100644 cranelift/wasm/src/state/mod.rs delete mode 100644 cranelift/wasm/src/state/module_state.rs diff --git a/cranelift/wasm/src/lib.rs b/cranelift/wasm/src/lib.rs index 1121598629..b8388848b5 100644 --- a/cranelift/wasm/src/lib.rs +++ b/cranelift/wasm/src/lib.rs @@ -61,8 +61,7 @@ pub use crate::environ::{ }; pub use crate::func_translator::FuncTranslator; pub use crate::module_translator::translate_module; -pub use crate::state::func_state::FuncTranslationState; -pub use crate::state::module_state::ModuleTranslationState; +pub use crate::state::FuncTranslationState; pub use crate::translation_utils::*; pub use cranelift_frontend::FunctionBuilder; pub use wasmtime_types::*; diff --git a/cranelift/wasm/src/module_translator.rs b/cranelift/wasm/src/module_translator.rs index 97a5d171b9..356c738e5f 100644 --- a/cranelift/wasm/src/module_translator.rs +++ b/cranelift/wasm/src/module_translator.rs @@ -6,7 +6,6 @@ use crate::sections_translator::{ parse_global_section, parse_import_section, parse_memory_section, parse_name_section, parse_start_section, parse_table_section, parse_tag_section, parse_type_section, }; -use crate::state::ModuleTranslationState; use crate::WasmResult; use cranelift_codegen::timing; use std::prelude::v1::*; @@ -17,9 +16,8 @@ use wasmparser::{NameSectionReader, Parser, Payload, Validator}; pub fn translate_module<'data>( data: &'data [u8], environ: &mut dyn ModuleEnvironment<'data>, -) -> WasmResult { +) -> WasmResult<()> { let _tt = timing::wasm_translate_module(); - let mut module_translation_state = ModuleTranslationState::new(); let mut validator = Validator::new_with_features(environ.wasm_features()); for payload in Parser::new(0).parse_all(data) { @@ -37,7 +35,7 @@ pub fn translate_module<'data>( Payload::TypeSection(types) => { validator.type_section(&types)?; - parse_type_section(types, &mut module_translation_state, environ)?; + parse_type_section(types, environ)?; } Payload::ImportSection(imports) => { @@ -127,5 +125,5 @@ pub fn translate_module<'data>( } } - Ok(module_translation_state) + Ok(()) } diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index 78424eaeef..3030054d0b 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -8,7 +8,6 @@ //! is handled, according to the semantics of WebAssembly, to only specific expressions that are //! interpreted on the fly. use crate::environ::ModuleEnvironment; -use crate::state::ModuleTranslationState; use crate::wasm_unsupported; use crate::{ DataIndex, ElemIndex, FuncIndex, Global, GlobalIndex, GlobalInit, Memory, MemoryIndex, Table, @@ -64,21 +63,15 @@ fn global(ty: GlobalType, initializer: GlobalInit) -> WasmResult { /// Parses the Type section of the wasm module. pub fn parse_type_section<'a>( types: TypeSectionReader<'a>, - module_translation_state: &mut ModuleTranslationState, environ: &mut dyn ModuleEnvironment<'a>, ) -> WasmResult<()> { let count = types.get_count(); - module_translation_state.wasm_types.reserve(count as usize); environ.reserve_types(count)?; for entry in types { match entry? { Type::Func(wasm_func_ty) => { environ.declare_type_func(wasm_func_ty.clone().try_into()?)?; - module_translation_state.wasm_types.push(( - wasm_func_ty.params().to_vec().into(), - wasm_func_ty.results().to_vec().into(), - )); } } } diff --git a/cranelift/wasm/src/state/func_state.rs b/cranelift/wasm/src/state.rs similarity index 99% rename from cranelift/wasm/src/state/func_state.rs rename to cranelift/wasm/src/state.rs index bcb97098cb..03051ed630 100644 --- a/cranelift/wasm/src/state/func_state.rs +++ b/cranelift/wasm/src/state.rs @@ -1,8 +1,5 @@ //! WebAssembly module and function translation state. //! -//! The `ModuleTranslationState` struct defined in this module is used to keep track of data about -//! the whole WebAssembly module, such as the decoded type signatures. -//! //! The `FuncTranslationState` struct defined in this module is used to keep track of the WebAssembly //! value and control stacks during the translation of a single function. diff --git a/cranelift/wasm/src/state/mod.rs b/cranelift/wasm/src/state/mod.rs deleted file mode 100644 index 730dc8beb5..0000000000 --- a/cranelift/wasm/src/state/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! WebAssembly module and function translation state. -//! -//! The `ModuleTranslationState` struct defined in this module is used to keep track of data about -//! the whole WebAssembly module, such as the decoded type signatures. -//! -//! The `FuncTranslationState` struct defined in this module is used to keep track of the WebAssembly -//! value and control stacks during the translation of a single function. - -pub(crate) mod func_state; -pub(crate) mod module_state; - -// Re-export for convenience. -pub(crate) use func_state::*; -pub(crate) use module_state::*; diff --git a/cranelift/wasm/src/state/module_state.rs b/cranelift/wasm/src/state/module_state.rs deleted file mode 100644 index db22d82794..0000000000 --- a/cranelift/wasm/src/state/module_state.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::SignatureIndex; -use cranelift_entity::PrimaryMap; -use std::boxed::Box; - -/// Map of signatures to a function's parameter and return types. -pub(crate) type WasmTypes = - PrimaryMap, Box<[wasmparser::ValType]>)>; - -/// Contains information decoded from the Wasm module that must be referenced -/// during each Wasm function's translation. -/// -/// This is only for data that is maintained by `cranelift-wasm` itself, as -/// opposed to being maintained by the embedder. Data that is maintained by the -/// embedder is represented with `ModuleEnvironment`. -#[derive(Debug)] -pub struct ModuleTranslationState { - /// A map containing a Wasm module's original, raw signatures. - /// - /// This is used for translating multi-value Wasm blocks inside functions, - /// which are encoded to refer to their type signature via index. - pub(crate) wasm_types: WasmTypes, -} - -impl ModuleTranslationState { - /// Creates a new empty ModuleTranslationState. - pub fn new() -> Self { - Self { - wasm_types: PrimaryMap::new(), - } - } -}