Remove the local field of Module (#2091)

This was added long ago at this point to assist with caching, but
caching has moved to a different level such that this wonky second level
of a `Module` isn't necessary. This commit removes the `ModuleLocal`
type to simplify accessors and generally make it easier to work with.
This commit is contained in:
Alex Crichton
2020-08-04 12:29:16 -05:00
committed by GitHub
parent c21fe0eb73
commit 3d2e0e55f2
26 changed files with 131 additions and 164 deletions

View File

@@ -72,7 +72,7 @@ fn transform_dwarf_data(
funcs: &CompiledFunctions,
) -> Result<Vec<DwarfSection>, 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)))

View File

@@ -20,10 +20,10 @@ pub fn resolve_imports(
signatures: &SignatureRegistry,
resolver: &mut dyn Resolver,
) -> Result<Imports, LinkError> {
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 \

View File

@@ -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::<Vec<_>>();
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)
);
}

View File

@@ -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

View File

@@ -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::<u128>())?;
// Preserve trampoline function unwind info.
if let Some(info) = &func.unwind_info {