Provide proper function index and name in the FrameInfo (#824)

* fix function index

* Add function name to JITFunctionTag

* Add ModuleSyncString.
This commit is contained in:
Yury Delendik
2020-01-16 12:36:51 -06:00
committed by GitHub
parent adcc047f4a
commit b2bfb98f1f
8 changed files with 63 additions and 12 deletions

View File

@@ -54,7 +54,7 @@ pub use crate::func_environ::BuiltinFunctionIndex;
#[cfg(feature = "lightbeam")]
pub use crate::lightbeam::Lightbeam;
pub use crate::module::{
Export, MemoryPlan, MemoryStyle, Module, TableElements, TablePlan, TableStyle,
Export, MemoryPlan, MemoryStyle, Module, ModuleSyncString, TableElements, TablePlan, TableStyle,
};
pub use crate::module_environ::{
translate_signature, DataInitializer, DataInitializerLocation, FunctionBodyData,

View File

@@ -3,7 +3,7 @@
use crate::module_environ::FunctionBodyData;
use crate::tunables::Tunables;
use cranelift_codegen::ir;
use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_entity::{EntityRef, PrimaryMap, SecondaryMap};
use cranelift_wasm::{
DefinedFuncIndex, DefinedGlobalIndex, DefinedMemoryIndex, DefinedTableIndex, FuncIndex, Global,
GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
@@ -11,6 +11,7 @@ use cranelift_wasm::{
use indexmap::IndexMap;
use more_asserts::assert_ge;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
/// A WebAssembly table initializer.
#[derive(Clone, Debug, Hash)]
@@ -128,6 +129,28 @@ impl TablePlan {
}
}
/// Allows module strings to be cached as reused across
/// multiple threads. Useful for debug/trace information.
#[derive(Debug, Clone)]
pub struct ModuleSyncString(Option<Arc<String>>);
impl ModuleSyncString {
/// Gets optional string reference.
pub fn get(&self) -> Option<&str> {
self.0.as_deref().map(|s| s.as_str())
}
/// Constructs the string.
pub fn new(s: Option<&str>) -> Self {
ModuleSyncString(s.map(|s| Arc::new(s.to_string())))
}
}
impl Default for ModuleSyncString {
fn default() -> Self {
ModuleSyncString(None)
}
}
/// A translated WebAssembly module, excluding the function bodies and
/// memory initializers.
// WARNING: when modifying, make sure that `hash_for_cache` is still valid!
@@ -171,7 +194,10 @@ pub struct Module {
pub table_elements: Vec<TableElements>,
/// Module name.
pub name: Option<String>,
pub name: ModuleSyncString,
/// Function names.
pub func_names: SecondaryMap<FuncIndex, ModuleSyncString>,
}
impl Module {
@@ -190,7 +216,8 @@ impl Module {
exports: IndexMap::new(),
start_func: None,
table_elements: Vec::new(),
name: None,
name: Default::default(),
func_names: SecondaryMap::new(),
}
}

View File

@@ -1,5 +1,5 @@
use crate::func_environ::FuncEnvironment;
use crate::module::{Export, MemoryPlan, Module, TableElements, TablePlan};
use crate::module::{Export, MemoryPlan, Module, ModuleSyncString, TableElements, TablePlan};
use crate::tunables::Tunables;
use cranelift_codegen::ir;
use cranelift_codegen::ir::{AbiParam, ArgumentPurpose};
@@ -369,6 +369,11 @@ impl<'data> cranelift_wasm::ModuleEnvironment<'data> for ModuleEnvironment<'data
});
Ok(())
}
fn declare_func_name(&mut self, func_index: FuncIndex, name: &'data str) -> WasmResult<()> {
self.result.module.func_names[func_index] = ModuleSyncString::new(Some(name));
Ok(())
}
}
/// Add environment-specific function parameters.