diff --git a/crates/environ/src/cranelift.rs b/crates/environ/src/cranelift.rs index 6dbb1ec1fc..4a936581b9 100644 --- a/crates/environ/src/cranelift.rs +++ b/crates/environ/src/cranelift.rs @@ -302,17 +302,17 @@ impl Compiler for Cranelift { input: &FunctionBodyData<'_>, isa: &dyn isa::TargetIsa, ) -> Result { - let local = &translation.module.local; + let module = &translation.module; let tunables = &translation.tunables; - let func_index = local.func_index(func_index); + let func_index = module.func_index(func_index); let mut context = Context::new(); context.func.name = get_func_name(func_index); - context.func.signature = local.native_func_signature(func_index).clone(); + context.func.signature = module.native_func_signature(func_index).clone(); if tunables.debug_info { context.func.collect_debug_info(); } - let mut func_env = FuncEnvironment::new(isa.frontend_config(), local, tunables); + let mut func_env = FuncEnvironment::new(isa.frontend_config(), module, tunables); // We use these as constant offsets below in // `stack_limit_from_arguments`, so assert their values here. This diff --git a/crates/environ/src/func_environ.rs b/crates/environ/src/func_environ.rs index e2a4be7530..aeaf5f6e79 100644 --- a/crates/environ/src/func_environ.rs +++ b/crates/environ/src/func_environ.rs @@ -1,6 +1,6 @@ -use crate::module::{MemoryPlan, MemoryStyle, ModuleLocal, TableStyle}; +use crate::module::{MemoryPlan, MemoryStyle, TableStyle}; use crate::vmoffsets::VMOffsets; -use crate::{Tunables, INTERRUPTED, WASM_PAGE_SIZE}; +use crate::{Module, Tunables, INTERRUPTED, WASM_PAGE_SIZE}; use cranelift_codegen::cursor::FuncCursor; use cranelift_codegen::ir; use cranelift_codegen::ir::condcodes::*; @@ -203,7 +203,7 @@ pub struct FuncEnvironment<'module_environment> { target_config: TargetFrontendConfig, /// The module-level environment which this function-level environment belongs to. - module: &'module_environment ModuleLocal, + module: &'module_environment Module, /// The Cranelift global holding the vmctx address. vmctx: Option, @@ -220,7 +220,7 @@ pub struct FuncEnvironment<'module_environment> { impl<'module_environment> FuncEnvironment<'module_environment> { pub fn new( target_config: TargetFrontendConfig, - module: &'module_environment ModuleLocal, + module: &'module_environment Module, tunables: &'module_environment Tunables, ) -> Self { let builtin_function_signatures = BuiltinFunctionSignatures::new( diff --git a/crates/environ/src/lib.rs b/crates/environ/src/lib.rs index a8d3926d27..a0148ff7fe 100644 --- a/crates/environ/src/lib.rs +++ b/crates/environ/src/lib.rs @@ -49,7 +49,7 @@ pub use crate::func_environ::BuiltinFunctionIndex; #[cfg(feature = "lightbeam")] pub use crate::lightbeam::Lightbeam; pub use crate::module::{ - EntityIndex, MemoryPlan, MemoryStyle, Module, ModuleLocal, TableElements, TablePlan, TableStyle, + EntityIndex, MemoryPlan, MemoryStyle, Module, TableElements, TablePlan, TableStyle, }; pub use crate::module_environ::*; pub use crate::tunables::Tunables; diff --git a/crates/environ/src/lightbeam.rs b/crates/environ/src/lightbeam.rs index cea6e3cb1d..caaba4b024 100644 --- a/crates/environ/src/lightbeam.rs +++ b/crates/environ/src/lightbeam.rs @@ -22,11 +22,11 @@ impl Compiler for Lightbeam { if translation.tunables.debug_info { return Err(CompileError::DebugInfoNotSupported); } - let func_index = translation.module.local.func_index(i); + let func_index = translation.module.func_index(i); let env = FuncEnvironment::new( isa.frontend_config(), - &translation.module.local, + &translation.module, &translation.tunables, ); let mut codegen_session: CodeGenSession<_> = CodeGenSession::new( diff --git a/crates/environ/src/module.rs b/crates/environ/src/module.rs index 07444bf94c..1353bab5a9 100644 --- a/crates/environ/src/module.rs +++ b/crates/environ/src/module.rs @@ -146,12 +146,6 @@ pub struct Module { /// The name of this wasm module, often found in the wasm file. pub name: Option, - /// Local information about a module which is the bare minimum necessary to - /// translate a function body. This is derived as `Hash` whereas this module - /// isn't, since it contains too much information needed to translate a - /// function. - pub local: ModuleLocal, - /// All import records, in the order they are declared in the module. pub imports: Vec<(String, String, EntityIndex)>, @@ -173,16 +167,7 @@ pub struct Module { /// WebAssembly table initializers. pub func_names: HashMap, -} -/// Local information known about a wasm module, the bare minimum necessary to -/// translate function bodies. -/// -/// This is stored within a `Module` and it implements `Hash`, unlike `Module`, -/// and is used as part of the cache key when we load compiled modules from the -/// global cache. -#[derive(Debug, Clone, Hash, Serialize, Deserialize)] -pub struct ModuleLocal { /// Unprocessed signatures exactly as provided by `declare_signature()`. pub signatures: PrimaryMap, @@ -224,17 +209,15 @@ impl Module { passive_elements: HashMap::new(), passive_data: HashMap::new(), func_names: HashMap::new(), - local: ModuleLocal { - num_imported_funcs: 0, - num_imported_tables: 0, - num_imported_memories: 0, - num_imported_globals: 0, - signatures: PrimaryMap::new(), - functions: PrimaryMap::new(), - table_plans: PrimaryMap::new(), - memory_plans: PrimaryMap::new(), - globals: PrimaryMap::new(), - }, + num_imported_funcs: 0, + num_imported_tables: 0, + num_imported_memories: 0, + num_imported_globals: 0, + signatures: PrimaryMap::new(), + functions: PrimaryMap::new(), + table_plans: PrimaryMap::new(), + memory_plans: PrimaryMap::new(), + globals: PrimaryMap::new(), } } @@ -247,9 +230,7 @@ impl Module { static NEXT_ID: AtomicUsize = AtomicUsize::new(0); NEXT_ID.fetch_add(1, SeqCst) } -} -impl ModuleLocal { /// Convert a `DefinedFuncIndex` into a `FuncIndex`. pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex { FuncIndex::new(self.num_imported_funcs + defined_func.index()) diff --git a/crates/environ/src/module_environ.rs b/crates/environ/src/module_environ.rs index 65fa3d3bd4..19db0bdaf3 100644 --- a/crates/environ/src/module_environ.rs +++ b/crates/environ/src/module_environ.rs @@ -195,7 +195,6 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data fn reserve_signatures(&mut self, num: u32) -> WasmResult<()> { self.result .module - .local .signatures .reserve_exact(usize::try_from(num).unwrap()); Ok(()) @@ -204,7 +203,7 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data fn declare_signature(&mut self, wasm: WasmFuncType, sig: ir::Signature) -> WasmResult<()> { let sig = translate_signature(sig, self.pointer_type()); // TODO: Deduplicate signatures. - self.result.module.local.signatures.push((wasm, sig)); + self.result.module.signatures.push((wasm, sig)); Ok(()) } @@ -223,17 +222,17 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data field: &str, ) -> WasmResult<()> { debug_assert_eq!( - self.result.module.local.functions.len(), - self.result.module.local.num_imported_funcs, + self.result.module.functions.len(), + self.result.module.num_imported_funcs, "Imported functions must be declared first" ); - let func_index = self.result.module.local.functions.push(sig_index); + let func_index = self.result.module.functions.push(sig_index); self.result.module.imports.push(( module.to_owned(), field.to_owned(), EntityIndex::Function(func_index), )); - self.result.module.local.num_imported_funcs += 1; + self.result.module.num_imported_funcs += 1; if let Some(info) = &mut self.result.debuginfo { info.wasm_file.imported_func_count += 1; } @@ -242,18 +241,18 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data fn declare_table_import(&mut self, table: Table, module: &str, field: &str) -> WasmResult<()> { debug_assert_eq!( - self.result.module.local.table_plans.len(), - self.result.module.local.num_imported_tables, + self.result.module.table_plans.len(), + self.result.module.num_imported_tables, "Imported tables must be declared first" ); let plan = TablePlan::for_table(table, &self.result.tunables); - let table_index = self.result.module.local.table_plans.push(plan); + let table_index = self.result.module.table_plans.push(plan); self.result.module.imports.push(( module.to_owned(), field.to_owned(), EntityIndex::Table(table_index), )); - self.result.module.local.num_imported_tables += 1; + self.result.module.num_imported_tables += 1; Ok(()) } @@ -264,21 +263,21 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data field: &str, ) -> WasmResult<()> { debug_assert_eq!( - self.result.module.local.memory_plans.len(), - self.result.module.local.num_imported_memories, + self.result.module.memory_plans.len(), + self.result.module.num_imported_memories, "Imported memories must be declared first" ); if memory.shared { return Err(WasmError::Unsupported("shared memories".to_owned())); } let plan = MemoryPlan::for_memory(memory, &self.result.tunables); - let memory_index = self.result.module.local.memory_plans.push(plan); + let memory_index = self.result.module.memory_plans.push(plan); self.result.module.imports.push(( module.to_owned(), field.to_owned(), EntityIndex::Memory(memory_index), )); - self.result.module.local.num_imported_memories += 1; + self.result.module.num_imported_memories += 1; Ok(()) } @@ -289,24 +288,23 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data field: &str, ) -> WasmResult<()> { debug_assert_eq!( - self.result.module.local.globals.len(), - self.result.module.local.num_imported_globals, + self.result.module.globals.len(), + self.result.module.num_imported_globals, "Imported globals must be declared first" ); - let global_index = self.result.module.local.globals.push(global); + let global_index = self.result.module.globals.push(global); self.result.module.imports.push(( module.to_owned(), field.to_owned(), EntityIndex::Global(global_index), )); - self.result.module.local.num_imported_globals += 1; + self.result.module.num_imported_globals += 1; Ok(()) } fn reserve_func_types(&mut self, num: u32) -> WasmResult<()> { self.result .module - .local .functions .reserve_exact(usize::try_from(num).unwrap()); self.result @@ -316,14 +314,13 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data } fn declare_func_type(&mut self, sig_index: SignatureIndex) -> WasmResult<()> { - self.result.module.local.functions.push(sig_index); + self.result.module.functions.push(sig_index); Ok(()) } fn reserve_tables(&mut self, num: u32) -> WasmResult<()> { self.result .module - .local .table_plans .reserve_exact(usize::try_from(num).unwrap()); Ok(()) @@ -331,14 +328,13 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data fn declare_table(&mut self, table: Table) -> WasmResult<()> { let plan = TablePlan::for_table(table, &self.result.tunables); - self.result.module.local.table_plans.push(plan); + self.result.module.table_plans.push(plan); Ok(()) } fn reserve_memories(&mut self, num: u32) -> WasmResult<()> { self.result .module - .local .memory_plans .reserve_exact(usize::try_from(num).unwrap()); Ok(()) @@ -349,21 +345,20 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data return Err(WasmError::Unsupported("shared memories".to_owned())); } let plan = MemoryPlan::for_memory(memory, &self.result.tunables); - self.result.module.local.memory_plans.push(plan); + self.result.module.memory_plans.push(plan); Ok(()) } fn reserve_globals(&mut self, num: u32) -> WasmResult<()> { self.result .module - .local .globals .reserve_exact(usize::try_from(num).unwrap()); Ok(()) } fn declare_global(&mut self, global: Global) -> WasmResult<()> { - self.result.module.local.globals.push(global); + self.result.module.globals.push(global); Ok(()) } @@ -456,10 +451,10 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data module_offset: body_offset, }); if let Some(info) = &mut self.result.debuginfo { - let func_index = self.code_index + self.result.module.local.num_imported_funcs as u32; + let func_index = self.code_index + self.result.module.num_imported_funcs as u32; let func_index = FuncIndex::from_u32(func_index); - let sig_index = self.result.module.local.functions[func_index]; - let sig = &self.result.module.local.signatures[sig_index]; + let sig_index = self.result.module.functions[func_index]; + let sig = &self.result.module.signatures[sig_index]; let mut locals = Vec::new(); let body = wasmparser::FunctionBody::new(body_offset, body_bytes); for pair in body.get_locals_reader()? { diff --git a/crates/environ/src/vmoffsets.rs b/crates/environ/src/vmoffsets.rs index 6efa591457..aa5e00d0ac 100644 --- a/crates/environ/src/vmoffsets.rs +++ b/crates/environ/src/vmoffsets.rs @@ -19,7 +19,7 @@ // builtins: VMBuiltinFunctionsArray, // } -use crate::module::ModuleLocal; +use crate::module::Module; use crate::BuiltinFunctionIndex; use cranelift_codegen::ir; use cranelift_wasm::{ @@ -75,7 +75,7 @@ pub struct VMOffsets { impl VMOffsets { /// Return a new `VMOffsets` instance, for a given pointer size. - pub fn new(pointer_size: u8, module: &ModuleLocal) -> Self { + pub fn new(pointer_size: u8, module: &Module) -> Self { Self { pointer_size, num_signature_ids: cast_to_u32(module.signatures.len()), diff --git a/crates/jit/src/compiler.rs b/crates/jit/src/compiler.rs index 052af5262e..349135b33e 100644 --- a/crates/jit/src/compiler.rs +++ b/crates/jit/src/compiler.rs @@ -72,7 +72,7 @@ fn transform_dwarf_data( funcs: &CompiledFunctions, ) -> Result, SetupError> { let target_config = isa.frontend_config(); - let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local); + let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); let memory_offset = if ofs.num_imported_memories > 0 { ModuleMemoryOffset::Imported(ofs.vmctx_vmmemory_import(MemoryIndex::new(0))) diff --git a/crates/jit/src/imports.rs b/crates/jit/src/imports.rs index a6ba165fca..3c00ce4aeb 100644 --- a/crates/jit/src/imports.rs +++ b/crates/jit/src/imports.rs @@ -20,10 +20,10 @@ pub fn resolve_imports( signatures: &SignatureRegistry, resolver: &mut dyn Resolver, ) -> Result { - let mut function_imports = PrimaryMap::with_capacity(module.local.num_imported_funcs); - let mut table_imports = PrimaryMap::with_capacity(module.local.num_imported_tables); - let mut memory_imports = PrimaryMap::with_capacity(module.local.num_imported_memories); - let mut global_imports = PrimaryMap::with_capacity(module.local.num_imported_globals); + let mut function_imports = PrimaryMap::with_capacity(module.num_imported_funcs); + let mut table_imports = PrimaryMap::with_capacity(module.num_imported_tables); + let mut memory_imports = PrimaryMap::with_capacity(module.num_imported_memories); + let mut global_imports = PrimaryMap::with_capacity(module.num_imported_globals); for (import_idx, (module_name, field_name, import)) in module.imports.iter().enumerate() { let import_idx = import_idx.try_into().unwrap(); @@ -31,7 +31,7 @@ pub fn resolve_imports( match (import, &export) { (EntityIndex::Function(func_index), Some(Export::Function(f))) => { - let import_signature = module.local.native_func_signature(*func_index); + let import_signature = module.native_func_signature(*func_index); let signature = signatures .lookup_native(unsafe { f.anyfunc.as_ref().type_index }) .unwrap(); @@ -63,7 +63,7 @@ pub fn resolve_imports( } (EntityIndex::Table(table_index), Some(Export::Table(t))) => { - let import_table = &module.local.table_plans[*table_index]; + let import_table = &module.table_plans[*table_index]; if !is_table_compatible(&t.table, import_table) { return Err(LinkError(format!( "{}/{}: incompatible import type: exported table incompatible with \ @@ -90,7 +90,7 @@ pub fn resolve_imports( } (EntityIndex::Memory(memory_index), Some(Export::Memory(m))) => { - let import_memory = &module.local.memory_plans[*memory_index]; + let import_memory = &module.memory_plans[*memory_index]; if !is_memory_compatible(&m.memory, import_memory) { return Err(LinkError(format!( "{}/{}: incompatible import type: exported memory incompatible with \ @@ -131,7 +131,7 @@ pub fn resolve_imports( } (EntityIndex::Global(global_index), Some(Export::Global(g))) => { - let imported_global = module.local.globals[*global_index]; + let imported_global = module.globals[*global_index]; if !is_global_compatible(&g.global, &imported_global) { return Err(LinkError(format!( "{}/{}: incompatible import type: exported global incompatible with \ diff --git a/crates/jit/src/instantiate.rs b/crates/jit/src/instantiate.rs index bbc202500b..ee1bffdebe 100644 --- a/crates/jit/src/instantiate.rs +++ b/crates/jit/src/instantiate.rs @@ -256,7 +256,6 @@ impl CompiledModule { // Compute indices into the shared signature table. let signatures = { self.module - .local .signatures .values() .map(|(wasm_sig, native)| { @@ -387,7 +386,7 @@ fn create_dbg_image( .values() .map(|allocated: &*mut [VMFunctionBody]| (*allocated) as *const u8) .collect::>(); - create_gdbjit_image(obj, code_range, module.local.num_imported_funcs, &funcs) + create_gdbjit_image(obj, code_range, module.num_imported_funcs, &funcs) .map_err(SetupError::DebugInfo) } @@ -417,7 +416,7 @@ fn build_code_memory( let fat_ptr: *mut [VMFunctionBody] = fat_ptr; assert_eq!( Some(finished_functions.push(fat_ptr)), - module.local.defined_func_index(i) + module.defined_func_index(i) ); } diff --git a/crates/jit/src/link.rs b/crates/jit/src/link.rs index 71284e8755..13cb254793 100644 --- a/crates/jit/src/link.rs +++ b/crates/jit/src/link.rs @@ -49,7 +49,7 @@ fn apply_reloc( match sym.name() { Some(name) => { if let Some(index) = try_parse_func_name(name) { - match module.local.defined_func_index(index) { + match module.defined_func_index(index) { Some(f) => { let fatptr: *const [VMFunctionBody] = finished_functions[f]; fatptr as *const VMFunctionBody as usize diff --git a/crates/jit/src/object.rs b/crates/jit/src/object.rs index 18891c7528..8c8bdd179e 100644 --- a/crates/jit/src/object.rs +++ b/crates/jit/src/object.rs @@ -39,13 +39,13 @@ pub(crate) fn build_object( unwind_info.extend(funcs.iter().filter_map(|(index, func)| { func.unwind_info .as_ref() - .map(|info| ObjectUnwindInfo::Func(module.local.func_index(index), info.clone())) + .map(|info| ObjectUnwindInfo::Func(module.func_index(index), info.clone())) })); - let mut trampolines = PrimaryMap::with_capacity(module.local.signatures.len()); + let mut trampolines = PrimaryMap::with_capacity(module.signatures.len()); let mut cx = FunctionBuilderContext::new(); // Build trampolines for every signature. - for (i, (_, native_sig)) in module.local.signatures.iter() { + for (i, (_, native_sig)) in module.signatures.iter() { let func = build_trampoline(isa, &mut cx, native_sig, std::mem::size_of::())?; // Preserve trampoline function unwind info. if let Some(info) = &func.unwind_info { diff --git a/crates/obj/src/builder.rs b/crates/obj/src/builder.rs index 5ad11fc36c..e9f823b00c 100644 --- a/crates/obj/src/builder.rs +++ b/crates/obj/src/builder.rs @@ -46,7 +46,7 @@ fn to_object_relocations<'a>( RelocationTarget::UserFunc(index) => (funcs[index], 0), RelocationTarget::LibCall(call) => (libcalls[&call], 0), RelocationTarget::JumpTable(f, jt) => { - let df = module.local.defined_func_index(f).unwrap(); + let df = module.defined_func_index(f).unwrap(); let offset = *compiled_funcs .get(df) .and_then(|f| f.jt_offsets.get(jt)) @@ -314,7 +314,7 @@ impl<'a> ObjectBuilder<'a> { // Create symbols for imports -- needed during linking. let mut func_symbols = PrimaryMap::with_capacity(self.compilation.len()); - for index in 0..module.local.num_imported_funcs { + for index in 0..module.num_imported_funcs { let symbol_id = obj.add_symbol(Symbol { name: utils::func_symbol_name(FuncIndex::new(index)) .as_bytes() @@ -351,7 +351,7 @@ impl<'a> ObjectBuilder<'a> { // Create symbols and section data for the compiled functions. for (index, func) in self.compilation.iter() { - let name = utils::func_symbol_name(module.local.func_index(index)) + let name = utils::func_symbol_name(module.func_index(index)) .as_bytes() .to_vec(); let symbol_id = append_func(name, func); @@ -383,7 +383,7 @@ impl<'a> ObjectBuilder<'a> { // Write all functions relocations. for (index, func) in self.compilation.into_iter() { - let func_index = module.local.func_index(index); + let func_index = module.func_index(index); let (_, off) = obj .symbol_section_and_offset(func_symbols[func_index]) .unwrap(); @@ -419,7 +419,7 @@ impl<'a> ObjectBuilder<'a> { for reloc in relocs { let target_symbol = match reloc.target { DwarfSectionRelocTarget::Func(index) => { - func_symbols[module.local.func_index(DefinedFuncIndex::new(index))] + func_symbols[module.func_index(DefinedFuncIndex::new(index))] } DwarfSectionRelocTarget::Section(name) => { obj.section_symbol(*dwarf_sections_ids.get(name).unwrap()) diff --git a/crates/obj/src/context.rs b/crates/obj/src/context.rs index d46ecf253e..e306f6f36b 100644 --- a/crates/obj/src/context.rs +++ b/crates/obj/src/context.rs @@ -18,14 +18,14 @@ pub fn layout_vmcontext( module: &Module, target_config: &TargetFrontendConfig, ) -> (Box<[u8]>, Box<[TableRelocation]>) { - let ofs = VMOffsets::new(target_config.pointer_bytes(), &module.local); + let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); let out_len = ofs.size_of_vmctx() as usize; let mut out = vec![0; out_len]; // Assign unique indices to unique signatures. let mut signature_registry = HashMap::new(); let mut signature_registry_len = signature_registry.len(); - for (index, sig) in module.local.signatures.iter() { + for (index, sig) in module.signatures.iter() { let offset = ofs.vmctx_vmshared_signature_id(index) as usize; let target_index = match signature_registry.entry(sig) { Entry::Occupied(o) => *o.get(), @@ -42,10 +42,10 @@ pub fn layout_vmcontext( } } - let num_tables_imports = module.local.num_imported_tables; - let mut table_relocs = Vec::with_capacity(module.local.table_plans.len() - num_tables_imports); - for (index, table) in module.local.table_plans.iter().skip(num_tables_imports) { - let def_index = module.local.defined_table_index(index).unwrap(); + let num_tables_imports = module.num_imported_tables; + let mut table_relocs = Vec::with_capacity(module.table_plans.len() - num_tables_imports); + for (index, table) in module.table_plans.iter().skip(num_tables_imports) { + let def_index = module.defined_table_index(index).unwrap(); let offset = ofs.vmctx_vmtable_definition(def_index) as usize; let current_elements = table.table.minimum; unsafe { @@ -66,9 +66,9 @@ pub fn layout_vmcontext( }); } - let num_globals_imports = module.local.num_imported_globals; - for (index, global) in module.local.globals.iter().skip(num_globals_imports) { - let def_index = module.local.defined_global_index(index).unwrap(); + let num_globals_imports = module.num_imported_globals; + for (index, global) in module.globals.iter().skip(num_globals_imports) { + let def_index = module.defined_global_index(index).unwrap(); let offset = ofs.vmctx_vmglobal_definition(def_index) as usize; let to = unsafe { out.as_mut_ptr().add(offset) }; match global.initializer { diff --git a/crates/obj/src/module.rs b/crates/obj/src/module.rs index 4137d4a641..2adf1aa393 100644 --- a/crates/obj/src/module.rs +++ b/crates/obj/src/module.rs @@ -66,7 +66,7 @@ pub fn emit_module( declare_data_segment(&mut obj, initializer, i)?; } - for i in 0..module.local.table_plans.len() { + for i in 0..module.table_plans.len() { declare_table(&mut obj, i)?; } @@ -74,7 +74,7 @@ pub fn emit_module( emit_data_segment(&mut obj, initializer, i)?; } - for i in 0..module.local.table_plans.len() { + for i in 0..module.table_plans.len() { emit_table(&mut obj, i)?; } diff --git a/crates/profiling/src/lib.rs b/crates/profiling/src/lib.rs index fcbce63af7..a0e2a36ea5 100644 --- a/crates/profiling/src/lib.rs +++ b/crates/profiling/src/lib.rs @@ -72,7 +72,7 @@ impl ProfilingAgent for NullProfilerAgent { #[allow(dead_code)] fn debug_name(module: &Module, index: DefinedFuncIndex) -> String { - let index = module.local.func_index(index); + let index = module.func_index(index); match module.func_names.get(&index) { Some(s) => s.clone(), None => format!("wasm::wasm-function[{}]", index.index()), diff --git a/crates/runtime/src/debug_builtins.rs b/crates/runtime/src/debug_builtins.rs index 3a6cfc8b81..8d685651b8 100644 --- a/crates/runtime/src/debug_builtins.rs +++ b/crates/runtime/src/debug_builtins.rs @@ -16,7 +16,7 @@ pub unsafe extern "C" fn resolve_vmctx_memory_ptr(p: *const u32) -> *const u8 { ); let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0); assert!( - VMCTX_AND_MEMORY.1 < handle.module().local.memory_plans.len(), + VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(), "memory index for debugger is out of bounds" ); let index = MemoryIndex::new(VMCTX_AND_MEMORY.1); diff --git a/crates/runtime/src/instance.rs b/crates/runtime/src/instance.rs index ad6092ba74..eac1954c79 100644 --- a/crates/runtime/src/instance.rs +++ b/crates/runtime/src/instance.rs @@ -176,7 +176,7 @@ impl Instance { /// Get a locally defined or imported memory. pub(crate) fn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition { - if let Some(defined_index) = self.module.local.defined_memory_index(index) { + if let Some(defined_index) = self.module.defined_memory_index(index) { self.memory(defined_index) } else { let import = self.imported_memory(index); @@ -234,7 +234,7 @@ impl Instance { &self, index: GlobalIndex, ) -> *mut VMGlobalDefinition { - if let Some(index) = self.module.local.defined_global_index(index) { + if let Some(index) = self.module.defined_global_index(index) { self.global_ptr(index) } else { self.imported_global(index).from @@ -297,7 +297,7 @@ impl Instance { } EntityIndex::Table(index) => { let (definition, vmctx) = - if let Some(def_index) = self.module.local.defined_table_index(*index) { + if let Some(def_index) = self.module.defined_table_index(*index) { (self.table_ptr(def_index), self.vmctx_ptr()) } else { let import = self.imported_table(*index); @@ -306,13 +306,13 @@ impl Instance { ExportTable { definition, vmctx, - table: self.module.local.table_plans[*index].clone(), + table: self.module.table_plans[*index].clone(), } .into() } EntityIndex::Memory(index) => { let (definition, vmctx) = - if let Some(def_index) = self.module.local.defined_memory_index(*index) { + if let Some(def_index) = self.module.defined_memory_index(*index) { (self.memory_ptr(def_index), self.vmctx_ptr()) } else { let import = self.imported_memory(*index); @@ -321,19 +321,18 @@ impl Instance { ExportMemory { definition, vmctx, - memory: self.module.local.memory_plans[*index].clone(), + memory: self.module.memory_plans[*index].clone(), } .into() } EntityIndex::Global(index) => ExportGlobal { - definition: if let Some(def_index) = self.module.local.defined_global_index(*index) - { + definition: if let Some(def_index) = self.module.defined_global_index(*index) { self.global_ptr(def_index) } else { self.imported_global(*index).from }, vmctx: self.vmctx_ptr(), - global: self.module.local.globals[*index], + global: self.module.globals[*index], } .into(), } @@ -771,7 +770,7 @@ impl Instance { /// Get a table by index regardless of whether it is locally-defined or an /// imported, foreign table. pub(crate) fn get_table(&self, table_index: TableIndex) -> &Table { - if let Some(defined_table_index) = self.module.local.defined_table_index(table_index) { + if let Some(defined_table_index) = self.module.defined_table_index(table_index) { self.get_defined_table(defined_table_index) } else { self.get_foreign_table(table_index) @@ -796,7 +795,7 @@ impl Instance { &self, index: TableIndex, ) -> (DefinedTableIndex, &Instance) { - if let Some(defined_table_index) = self.module.local.defined_table_index(index) { + if let Some(defined_table_index) = self.module.defined_table_index(index) { (defined_table_index, self) } else { let import = self.imported_table(index); @@ -867,7 +866,7 @@ impl InstanceHandle { let vmctx_globals = create_globals(&module); - let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module.local); + let offsets = VMOffsets::new(mem::size_of::<*const u8>() as u8, &module); let passive_data = RefCell::new(module.passive_data.clone()); @@ -946,11 +945,11 @@ impl InstanceHandle { *instance.externref_activations_table() = externref_activations_table; *instance.stack_map_registry() = stack_map_registry; - for (index, sig) in instance.module.local.functions.iter() { + for (index, sig) in instance.module.functions.iter() { let type_index = instance.signature_id(*sig); let (func_ptr, vmctx) = - if let Some(def_index) = instance.module.local.defined_func_index(index) { + if let Some(def_index) = instance.module.defined_func_index(index) { ( NonNull::new(instance.finished_functions[def_index] as *mut _).unwrap(), instance.vmctx_ptr(), @@ -1202,7 +1201,7 @@ fn get_memory_init_start(init: &DataInitializer<'_>, instance: &Instance) -> usi if let Some(base) = init.location.base { let val = unsafe { - if let Some(def_index) = instance.module.local.defined_global_index(base) { + if let Some(def_index) = instance.module.defined_global_index(base) { *instance.global(def_index).as_u32() } else { *(*instance.imported_global(base).from).as_u32() @@ -1221,7 +1220,6 @@ unsafe fn get_memory_slice<'instance>( ) -> &'instance mut [u8] { let memory = if let Some(defined_memory_index) = instance .module - .local .defined_memory_index(init.location.memory_index) { instance.memory(defined_memory_index) @@ -1256,10 +1254,10 @@ fn check_memory_init_bounds( /// Allocate memory for just the tables of the current module. fn create_tables(module: &Module) -> BoxedSlice { - let num_imports = module.local.num_imported_tables; + let num_imports = module.num_imported_tables; let mut tables: PrimaryMap = - PrimaryMap::with_capacity(module.local.table_plans.len() - num_imports); - for table in &module.local.table_plans.values().as_slice()[num_imports..] { + PrimaryMap::with_capacity(module.table_plans.len() - num_imports); + for table in &module.table_plans.values().as_slice()[num_imports..] { tables.push(Table::new(table)); } tables.into_boxed_slice() @@ -1271,7 +1269,7 @@ fn get_table_init_start(init: &TableElements, instance: &Instance) -> usize { if let Some(base) = init.base { let val = unsafe { - if let Some(def_index) = instance.module.local.defined_global_index(base) { + if let Some(def_index) = instance.module.defined_global_index(base) { *instance.global(def_index).as_u32() } else { *(*instance.imported_global(base).from).as_u32() @@ -1354,10 +1352,10 @@ fn create_memories( module: &Module, mem_creator: &dyn RuntimeMemoryCreator, ) -> Result>, InstantiationError> { - let num_imports = module.local.num_imported_memories; + let num_imports = module.num_imported_memories; let mut memories: PrimaryMap = - PrimaryMap::with_capacity(module.local.memory_plans.len() - num_imports); - for plan in &module.local.memory_plans.values().as_slice()[num_imports..] { + PrimaryMap::with_capacity(module.memory_plans.len() - num_imports); + for plan in &module.memory_plans.values().as_slice()[num_imports..] { memories.push( mem_creator .new_memory(plan) @@ -1399,10 +1397,10 @@ fn initialize_memories( /// Allocate memory for just the globals of the current module, /// with initializers applied. fn create_globals(module: &Module) -> BoxedSlice { - let num_imports = module.local.num_imported_globals; - let mut vmctx_globals = PrimaryMap::with_capacity(module.local.globals.len() - num_imports); + let num_imports = module.num_imported_globals; + let mut vmctx_globals = PrimaryMap::with_capacity(module.globals.len() - num_imports); - for _ in &module.local.globals.values().as_slice()[num_imports..] { + for _ in &module.globals.values().as_slice()[num_imports..] { vmctx_globals.push(VMGlobalDefinition::new()); } @@ -1411,9 +1409,9 @@ fn create_globals(module: &Module) -> BoxedSlice *(*to).as_f64_bits_mut() = x, GlobalInit::V128Const(x) => *(*to).as_u128_bits_mut() = x.0, GlobalInit::GetGlobal(x) => { - let from = if let Some(def_x) = module.local.defined_global_index(x) { + let from = if let Some(def_x) = module.defined_global_index(x) { instance.global(def_x) } else { *instance.imported_global(x).from diff --git a/crates/runtime/src/vmcontext.rs b/crates/runtime/src/vmcontext.rs index b3c1aea614..c3cf249487 100644 --- a/crates/runtime/src/vmcontext.rs +++ b/crates/runtime/src/vmcontext.rs @@ -30,7 +30,7 @@ mod test_vmfunction_import { #[test] fn check_vmfunction_import_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmfunction_import()) @@ -86,7 +86,7 @@ mod test_vmtable_import { #[test] fn check_vmtable_import_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmtable_import()) @@ -124,7 +124,7 @@ mod test_vmmemory_import { #[test] fn check_vmmemory_import_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmmemory_import()) @@ -159,7 +159,7 @@ mod test_vmglobal_import { #[test] fn check_vmglobal_import_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmglobal_import()) @@ -194,7 +194,7 @@ mod test_vmmemory_definition { #[test] fn check_vmmemory_definition_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmmemory_definition()) @@ -238,7 +238,7 @@ mod test_vmtable_definition { #[test] fn check_vmtable_definition_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmtable_definition()) @@ -285,7 +285,7 @@ mod test_vmglobal_definition { #[test] fn check_vmglobal_definition_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmglobal_definition()) @@ -295,7 +295,7 @@ mod test_vmglobal_definition { #[test] fn check_vmglobal_begins_aligned() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!(offsets.vmctx_globals_begin() % 16, 0); } @@ -471,7 +471,7 @@ mod test_vmshared_signature_index { #[test] fn check_vmshared_signature_index() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmshared_signature_index()) @@ -525,7 +525,7 @@ mod test_vmcaller_checked_anyfunc { #[test] fn check_vmcaller_checked_anyfunc_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmcaller_checked_anyfunc()) @@ -629,7 +629,7 @@ mod test_vm_invoke_argument { #[test] fn check_vmglobal_definition_offsets() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( size_of::(), usize::from(offsets.size_of_vmglobal_definition()) @@ -682,7 +682,7 @@ mod test_vminterrupts { #[test] fn check_vminterrupts_interrupted_offset() { let module = Module::new(); - let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module.local); + let offsets = VMOffsets::new(size_of::<*mut u8>() as u8, &module); assert_eq!( offset_of!(VMInterrupts, stack_limit), usize::from(offsets.vminterrupts_stack_limit()) diff --git a/crates/wasmtime/src/frame_info.rs b/crates/wasmtime/src/frame_info.rs index 27d80904bb..1cc81a0653 100644 --- a/crates/wasmtime/src/frame_info.rs +++ b/crates/wasmtime/src/frame_info.rs @@ -162,7 +162,7 @@ pub fn register(module: &CompiledModule) -> Option max = cmp::max(max, end); let func = FunctionInfo { start, - index: module.module().local.func_index(i), + index: module.module().func_index(i), traps: traps.to_vec(), instr_map: address_map.clone(), }; diff --git a/crates/wasmtime/src/trampoline/create_handle.rs b/crates/wasmtime/src/trampoline/create_handle.rs index b2a4b219e3..b8fde1622b 100644 --- a/crates/wasmtime/src/trampoline/create_handle.rs +++ b/crates/wasmtime/src/trampoline/create_handle.rs @@ -31,7 +31,6 @@ pub(crate) fn create_handle( // Compute indices into the shared signature table. let signatures = module - .local .signatures .values() .map(|(wasm, native)| store.register_signature(wasm.clone(), native.clone())) diff --git a/crates/wasmtime/src/trampoline/func.rs b/crates/wasmtime/src/trampoline/func.rs index 03f76bf569..350236a3ff 100644 --- a/crates/wasmtime/src/trampoline/func.rs +++ b/crates/wasmtime/src/trampoline/func.rs @@ -229,10 +229,9 @@ pub fn create_handle_with_function( // First up we manufacture a trampoline which has the ABI specified by `ft` // and calls into `stub_fn`... let sig_id = module - .local .signatures .push((ft.to_wasm_func_type(), sig.clone())); - let func_id = module.local.functions.push(sig_id); + let func_id = module.functions.push(sig_id); module .exports .insert("trampoline".to_string(), EntityIndex::Function(func_id)); @@ -289,10 +288,9 @@ pub unsafe fn create_handle_with_raw_function( let mut trampolines = HashMap::new(); let sig_id = module - .local .signatures .push((ft.to_wasm_func_type(), sig.clone())); - let func_id = module.local.functions.push(sig_id); + let func_id = module.functions.push(sig_id); module .exports .insert("trampoline".to_string(), EntityIndex::Function(func_id)); diff --git a/crates/wasmtime/src/trampoline/global.rs b/crates/wasmtime/src/trampoline/global.rs index 6a98cdf656..7093e65164 100644 --- a/crates/wasmtime/src/trampoline/global.rs +++ b/crates/wasmtime/src/trampoline/global.rs @@ -37,11 +37,10 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result Result Result EntityType<'module> { ) -> EntityType<'module> { match entity_index { EntityIndex::Function(func_index) => { - let sig = module.local.wasm_func_type(*func_index); + let sig = module.wasm_func_type(*func_index); EntityType::Function(&sig) } EntityIndex::Table(table_index) => { - EntityType::Table(&module.local.table_plans[*table_index].table) + EntityType::Table(&module.table_plans[*table_index].table) } EntityIndex::Memory(memory_index) => { - EntityType::Memory(&module.local.memory_plans[*memory_index].memory) - } - EntityIndex::Global(global_index) => { - EntityType::Global(&module.local.globals[*global_index]) + EntityType::Memory(&module.memory_plans[*memory_index].memory) } + EntityIndex::Global(global_index) => EntityType::Global(&module.globals[*global_index]), } }