diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index e558f8209..1f3521735 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -43,7 +43,7 @@ struct ShortNames {} impl SymbolRegistry for ShortNames { fn symbol_to_name(&self, symbol: Symbol) -> String { match symbol { - Symbol::Metadata(prefix) => format!("M{}", prefix), + Symbol::Metadata => "M".to_string(), Symbol::LocalFunction(index) => format!("f{}", index.index()), Symbol::Section(index) => format!("s{}", index.index()), Symbol::FunctionCallTrampoline(index) => format!("t{}", index.index()), @@ -57,7 +57,7 @@ impl SymbolRegistry for ShortNames { } let (ty, idx) = name.split_at(1); if ty.starts_with('M') { - return Some(Symbol::Metadata(idx.to_string())); + return Some(Symbol::Metadata); } let idx = idx.parse::().ok()?; diff --git a/lib/types/src/compilation/symbols.rs b/lib/types/src/compilation/symbols.rs index 800171c08..f3175fae3 100644 --- a/lib/types/src/compilation/symbols.rs +++ b/lib/types/src/compilation/symbols.rs @@ -17,10 +17,11 @@ use serde::{Deserialize, Serialize}; RkyvSerialize, RkyvDeserialize, Archive, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, )] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] +#[archive(as = "Self")] pub enum Symbol { /// A metadata section, indexed by a unique prefix /// (usually the wasm file SHA256 hash) - Metadata(String), + Metadata, /// A function defined in the wasm. LocalFunction(LocalFunctionIndex), @@ -147,8 +148,8 @@ impl ModuleMetadata { impl SymbolRegistry for ModuleMetadataSymbolRegistry { fn symbol_to_name(&self, symbol: Symbol) -> String { match symbol { - Symbol::Metadata(prefix) => { - format!("WASMER_METADATA_{}", prefix) + Symbol::Metadata => { + format!("WASMER_METADATA_{}", self.prefix) } Symbol::LocalFunction(index) => { format!("wasmer_function_{}_{}", self.prefix, index.index()) @@ -172,8 +173,8 @@ impl SymbolRegistry for ModuleMetadataSymbolRegistry { } fn name_to_symbol(&self, name: &str) -> Option { - if let Some(prefix) = name.strip_prefix("WASMER_METADATA_") { - Some(Symbol::Metadata(prefix.to_string())) + if name == format!("WASMER_METADATA_{}", self.prefix) { + Some(Symbol::Metadata) } else if let Some(index) = name.strip_prefix(&format!("wasmer_function_{}_", self.prefix)) { index