Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 5298634

Browse files
committed
pr review: use SecondaryMap for names
1 parent 380d0e4 commit 5298634

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lucetc/src/decls.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ impl<'a> ModuleDecls<'a> {
127127
decls
128128
.info
129129
.function_names
130-
.get(&func_index)
131-
.cloned()
130+
.get(func_index)
132131
.map(|s| format!("{}_{}", s, ix))
133132
}
134133

@@ -168,13 +167,9 @@ impl<'a> ModuleDecls<'a> {
168167
}
169168
};
170169

171-
let custom_info = custom_name_for(ix, func_index, decls);
172170
let import_info = import_name_for(func_index, decls, bindings)?;
173171
let export_info = export_name_for(func_index, decls);
174172

175-
// We don't match on `custom_info` because export and import info are needed to
176-
// determine the linkage type, and because we use different values as a fallback for
177-
// exported functions and local functions.
178173
match (import_info, export_info) {
179174
(Some(import_sym), _) => {
180175
// if a function is only an import, declare the corresponding artifact import.
@@ -192,7 +187,8 @@ impl<'a> ModuleDecls<'a> {
192187
// No import or export for this function, which means that it is local. We can
193188
// look for a name provided in the custom names section, otherwise we have to
194189
// make up a placeholder name for it using its index.
195-
let local_sym = custom_info.unwrap_or_else(|| format!("guest_func_{}", ix));
190+
let local_sym = custom_name_for(ix, func_index, decls)
191+
.unwrap_or_else(|| format!("guest_func_{}", ix));
196192
decls.declare_function(clif_module, local_sym, Linkage::Local, func_index)?;
197193
}
198194
}

lucetc/src/module.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Implements ModuleEnvironment for cranelift-wasm. Code derived from cranelift-wasm/environ/dummy.rs
22
use crate::error::{LucetcError, LucetcErrorKind};
33
use crate::pointer::NATIVE_POINTER;
4-
use cranelift_codegen::entity::{entity_impl, EntityRef, PrimaryMap};
4+
use cranelift_codegen::entity::{entity_impl, EntityRef, PrimaryMap, SecondaryMap};
55
use cranelift_codegen::ir;
66
use cranelift_codegen::isa::TargetFrontendConfig;
77
use cranelift_wasm::{
@@ -73,7 +73,7 @@ pub struct ModuleInfo<'a> {
7373
/// Function signatures: imported and local
7474
pub functions: PrimaryMap<UniqueFuncIndex, Exportable<'a, SignatureIndex>>,
7575
/// Function names.
76-
pub function_names: HashMap<UniqueFuncIndex, String>,
76+
pub function_names: SecondaryMap<UniqueFuncIndex, &'a str>,
7777
/// Provided by `declare_table`
7878
pub tables: PrimaryMap<TableIndex, Exportable<'a, Table>>,
7979
/// Provided by `declare_memory`
@@ -105,7 +105,7 @@ impl<'a> ModuleInfo<'a> {
105105
imported_memories: PrimaryMap::new(),
106106
function_mapping: PrimaryMap::new(),
107107
functions: PrimaryMap::new(),
108-
function_names: HashMap::new(),
108+
function_names: SecondaryMap::new(),
109109
tables: PrimaryMap::new(),
110110
memories: PrimaryMap::new(),
111111
globals: PrimaryMap::new(),
@@ -410,8 +410,7 @@ impl<'a> ModuleEnvironment<'a> for ModuleInfo<'a> {
410410
.function_mapping
411411
.get(func_index)
412412
.expect("function indices are valid");
413-
self.function_names
414-
.insert(unique_func_index, name.to_owned());
413+
self.function_names[unique_func_index] = name;
415414
Ok(())
416415
}
417416
}

0 commit comments

Comments
 (0)