diff --git a/crates/cranelift-shared/src/lib.rs b/crates/cranelift-shared/src/lib.rs index b508e04a79e6..1b72ef884d3f 100644 --- a/crates/cranelift-shared/src/lib.rs +++ b/crates/cranelift-shared/src/lib.rs @@ -3,7 +3,6 @@ use cranelift_codegen::{ ir::{self, ExternalName, UserExternalNameRef}, settings, FinalizedMachReloc, FinalizedRelocTarget, MachTrap, }; -use std::collections::BTreeMap; use wasmtime_environ::{FlagValue, FuncIndex, Trap, TrapInformation}; pub mod isa_builder; @@ -37,16 +36,16 @@ pub enum RelocationTarget { /// Converts cranelift_codegen settings to the wasmtime_environ equivalent. pub fn clif_flags_to_wasmtime( flags: impl IntoIterator, -) -> BTreeMap { +) -> Vec<(&'static str, FlagValue<'static>)> { flags .into_iter() - .map(|val| (val.name.to_string(), to_flag_value(&val))) + .map(|val| (val.name, to_flag_value(&val))) .collect() } -fn to_flag_value(v: &settings::Value) -> FlagValue { +fn to_flag_value(v: &settings::Value) -> FlagValue<'static> { match v.kind() { - settings::SettingKind::Enum => FlagValue::Enum(v.as_enum().unwrap().into()), + settings::SettingKind::Enum => FlagValue::Enum(v.as_enum().unwrap()), settings::SettingKind::Num => FlagValue::Num(v.as_num().unwrap()), settings::SettingKind::Bool => FlagValue::Bool(v.as_bool().unwrap()), settings::SettingKind::Preset => unreachable!(), diff --git a/crates/cranelift/src/compiler.rs b/crates/cranelift/src/compiler.rs index b9457f8ad70e..7a0f038daddf 100644 --- a/crates/cranelift/src/compiler.rs +++ b/crates/cranelift/src/compiler.rs @@ -23,7 +23,6 @@ use object::write::{Object, StandardSegment, SymbolId}; use object::{RelocationEncoding, RelocationKind, SectionKind}; use std::any::Any; use std::cmp; -use std::collections::BTreeMap; use std::collections::HashMap; use std::convert::TryFrom; use std::mem; @@ -522,11 +521,11 @@ impl wasmtime_environ::Compiler for Compiler { self.isa.triple() } - fn flags(&self) -> BTreeMap { + fn flags(&self) -> Vec<(&'static str, FlagValue<'static>)> { wasmtime_cranelift_shared::clif_flags_to_wasmtime(self.isa.flags().iter()) } - fn isa_flags(&self) -> BTreeMap { + fn isa_flags(&self) -> Vec<(&'static str, FlagValue<'static>)> { wasmtime_cranelift_shared::clif_flags_to_wasmtime(self.isa.isa_flags()) } diff --git a/crates/environ/src/compilation.rs b/crates/environ/src/compilation.rs index eede6d3bff4a..3cee62b856ad 100644 --- a/crates/environ/src/compilation.rs +++ b/crates/environ/src/compilation.rs @@ -12,7 +12,6 @@ use object::{Architecture, BinaryFormat, FileFlags}; use serde_derive::{Deserialize, Serialize}; use std::any::Any; use std::borrow::Cow; -use std::collections::BTreeMap; use std::fmt; use std::path; use std::sync::Arc; @@ -348,10 +347,10 @@ pub trait Compiler: Send + Sync { } /// Returns a list of configured settings for this compiler. - fn flags(&self) -> BTreeMap; + fn flags(&self) -> Vec<(&'static str, FlagValue<'static>)>; /// Same as [`Compiler::flags`], but ISA-specific (a cranelift-ism) - fn isa_flags(&self) -> BTreeMap; + fn isa_flags(&self) -> Vec<(&'static str, FlagValue<'static>)>; /// Get a flag indicating whether branch protection is enabled. fn is_branch_protection_enabled(&self) -> bool; @@ -383,16 +382,16 @@ pub trait Compiler: Send + Sync { /// Value of a configured setting for a [`Compiler`] #[derive(Serialize, Deserialize, Hash, Eq, PartialEq, Debug)] -pub enum FlagValue { +pub enum FlagValue<'a> { /// Name of the value that has been configured for this setting. - Enum(Cow<'static, str>), + Enum(&'a str), /// The numerical value of the configured settings. Num(u8), /// Whether the setting is on or off. Bool(bool), } -impl fmt::Display for FlagValue { +impl fmt::Display for FlagValue<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::Enum(v) => v.fmt(f), diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rs index 86cc6cb8e373..bdae74d74ffc 100644 --- a/crates/wasmtime/src/engine/serialization.rs +++ b/crates/wasmtime/src/engine/serialization.rs @@ -26,7 +26,6 @@ use anyhow::{anyhow, bail, Context, Result}; use object::write::{Object, StandardSegment}; use object::{File, FileFlags, Object as _, ObjectSection, SectionKind}; use serde_derive::{Deserialize, Serialize}; -use std::collections::BTreeMap; use std::str::FromStr; use wasmtime_environ::obj; use wasmtime_environ::{FlagValue, ObjectKind, Tunables}; @@ -142,7 +141,7 @@ pub fn check_compatible(engine: &Engine, mmap: &MmapVec, expected: ObjectKind) - } ModuleVersionStrategy::None => { /* ignore the version info, accept all */ } } - bincode::deserialize::(data)?.check_compatible(engine) + bincode::deserialize::>(data)?.check_compatible(engine) } fn detect_precompiled<'data, R: object::ReadRef<'data>>( @@ -174,10 +173,12 @@ pub fn detect_precompiled_file(path: impl AsRef) -> Result { target: String, - shared_flags: BTreeMap, - isa_flags: BTreeMap, + #[serde(borrow)] + shared_flags: Vec<(&'a str, FlagValue<'a>)>, + #[serde(borrow)] + isa_flags: Vec<(&'a str, FlagValue<'a>)>, tunables: Tunables, features: WasmFeatures, } @@ -200,9 +201,9 @@ struct WasmFeatures { function_references: bool, } -impl Metadata { +impl Metadata<'_> { #[cfg(any(feature = "cranelift", feature = "winch"))] - fn new(engine: &Engine) -> Metadata { + fn new(engine: &Engine) -> Metadata<'static> { let wasmparser::WasmFeatures { reference_types, multi_value, @@ -533,10 +534,9 @@ mod test { let engine = Engine::default(); let mut metadata = Metadata::new(&engine); - metadata.shared_flags.insert( - "preserve_frame_pointers".to_string(), - FlagValue::Bool(false), - ); + metadata + .shared_flags + .push(("preserve_frame_pointers", FlagValue::Bool(false))); match metadata.check_compatible(&engine) { Ok(_) => unreachable!(), @@ -559,7 +559,7 @@ Caused by: metadata .isa_flags - .insert("not_a_flag".to_string(), FlagValue::Bool(true)); + .push(("not_a_flag", FlagValue::Bool(true))); match metadata.check_compatible(&engine) { Ok(_) => unreachable!(), diff --git a/crates/winch/src/compiler.rs b/crates/winch/src/compiler.rs index fe2c45236e04..89e4a775d3c3 100644 --- a/crates/winch/src/compiler.rs +++ b/crates/winch/src/compiler.rs @@ -210,11 +210,11 @@ impl wasmtime_environ::Compiler for Compiler { self.isa.triple() } - fn flags(&self) -> std::collections::BTreeMap { + fn flags(&self) -> Vec<(&'static str, wasmtime_environ::FlagValue<'static>)> { wasmtime_cranelift_shared::clif_flags_to_wasmtime(self.isa.flags().iter()) } - fn isa_flags(&self) -> std::collections::BTreeMap { + fn isa_flags(&self) -> Vec<(&'static str, wasmtime_environ::FlagValue<'static>)> { wasmtime_cranelift_shared::clif_flags_to_wasmtime(self.isa.isa_flags()) } diff --git a/src/commands/settings.rs b/src/commands/settings.rs index b51475d90554..058909f8d381 100644 --- a/src/commands/settings.rs +++ b/src/commands/settings.rs @@ -45,7 +45,7 @@ struct Settings { bools: Vec, presets: Vec, - inferred: Option>, + inferred: Option>, } impl Settings {