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

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

View File

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

View File

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