Skip to content

Commit 55aa6a5

Browse files
authored
Use OOM-handling collections for Metadata (#12608)
* Use OOM-handling collections for `Metadata` These are created in the compiler, where we don't need to worry about OOM, but are deserialized in the "data-plane" where we do. The OOM-handling collections' `Deserialize` implementations automatically handle OOM for us here. * fix serialization unit tests
1 parent 7357e7c commit 55aa6a5

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

crates/wasmtime/src/engine/serialization.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use object::{
3535
};
3636
use serde_derive::{Deserialize, Serialize};
3737
use wasmtime_environ::obj;
38-
use wasmtime_environ::{FlagValue, ObjectKind, Tunables};
38+
use wasmtime_environ::{FlagValue, ObjectKind, Tunables, collections};
3939

4040
const VERSION: u8 = 0;
4141

@@ -180,11 +180,11 @@ pub fn detect_precompiled_file(path: impl AsRef<std::path::Path>) -> Result<Opti
180180

181181
#[derive(Serialize, Deserialize)]
182182
pub struct Metadata<'a> {
183-
target: String,
183+
target: collections::String,
184184
#[serde(borrow)]
185-
shared_flags: Vec<(&'a str, FlagValue<'a>)>,
185+
shared_flags: collections::Vec<(&'a str, FlagValue<'a>)>,
186186
#[serde(borrow)]
187-
isa_flags: Vec<(&'a str, FlagValue<'a>)>,
187+
isa_flags: collections::Vec<(&'a str, FlagValue<'a>)>,
188188
tunables: Tunables,
189189
features: u64,
190190
}
@@ -194,9 +194,9 @@ impl Metadata<'_> {
194194
pub fn new(engine: &Engine) -> Result<Metadata<'static>> {
195195
let compiler = engine.try_compiler()?;
196196
Ok(Metadata {
197-
target: compiler.triple().to_string(),
198-
shared_flags: compiler.flags(),
199-
isa_flags: compiler.isa_flags(),
197+
target: compiler.triple().to_string().into(),
198+
shared_flags: compiler.flags().into(),
199+
isa_flags: compiler.isa_flags().into(),
200200
tunables: engine.tunables().clone(),
201201
features: engine.features().bits(),
202202
})
@@ -463,7 +463,7 @@ mod test {
463463
fn test_architecture_mismatch() -> Result<()> {
464464
let engine = Engine::default();
465465
let mut metadata = Metadata::new(&engine)?;
466-
metadata.target = "unknown-generic-linux".to_string();
466+
metadata.target = "unknown-generic-linux".to_string().into();
467467

468468
match metadata.check_compatible(&engine) {
469469
Ok(_) => unreachable!(),
@@ -486,7 +486,8 @@ mod test {
486486
metadata.target = format!(
487487
"{}-generic-unknown",
488488
target_lexicon::Triple::host().architecture
489-
);
489+
)
490+
.into();
490491

491492
match metadata.check_compatible(&engine) {
492493
Ok(_) => unreachable!(),
@@ -515,7 +516,7 @@ mod test {
515516

516517
metadata
517518
.shared_flags
518-
.push(("preserve_frame_pointers", FlagValue::Bool(false)));
519+
.push(("preserve_frame_pointers", FlagValue::Bool(false)))?;
519520

520521
match metadata.check_compatible(&engine) {
521522
Ok(_) => unreachable!(),
@@ -541,7 +542,7 @@ mod test {
541542

542543
metadata
543544
.isa_flags
544-
.push(("not_a_flag", FlagValue::Bool(true)));
545+
.push(("not_a_flag", FlagValue::Bool(true)))?;
545546

546547
match metadata.check_compatible(&engine) {
547548
Ok(_) => unreachable!(),

0 commit comments

Comments
 (0)