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

@@ -162,7 +162,7 @@ pub fn register(module: &CompiledModule) -> Option<GlobalFrameInfoRegistration>
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(),
};

View File

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

View File

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

View File

@@ -37,11 +37,10 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
// our global with a `ref.func` to grab that imported function.
let shared_sig_index = f.sig_index();
let local_sig_index = module
.local
.signatures
.push(store.lookup_wasm_and_native_signatures(shared_sig_index));
let func_index = module.local.functions.push(local_sig_index);
module.local.num_imported_funcs = 1;
let func_index = module.functions.push(local_sig_index);
module.num_imported_funcs = 1;
module
.imports
.push(("".into(), "".into(), EntityIndex::Function(func_index)));
@@ -59,7 +58,7 @@ pub fn create_global(store: &Store, gt: &GlobalType, val: Val) -> Result<StoreIn
},
};
let global_id = module.local.globals.push(global);
let global_id = module.globals.push(global);
module
.exports
.insert("global".to_string(), EntityIndex::Global(global_id));

View File

@@ -24,7 +24,7 @@ pub fn create_handle_with_memory(
let memory_plan =
wasmtime_environ::MemoryPlan::for_memory(memory, &store.engine().config().tunables);
let memory_id = module.local.memory_plans.push(memory_plan);
let memory_id = module.memory_plans.push(memory_plan);
module
.exports
.insert("memory".to_string(), EntityIndex::Memory(memory_id));

View File

@@ -22,7 +22,7 @@ pub fn create_handle_with_table(store: &Store, table: &TableType) -> Result<Stor
let tunable = Default::default();
let table_plan = wasmtime_environ::TablePlan::for_table(table, &tunable);
let table_id = module.local.table_plans.push(table_plan);
let table_id = module.table_plans.push(table_plan);
module
.exports
.insert("table".to_string(), EntityIndex::Table(table_id));

View File

@@ -432,18 +432,16 @@ impl<'module> 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]),
}
}