From fdfda89d5998b94715a2ef5d4f626c3fe896026e Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 13 Mar 2020 11:34:21 -0700 Subject: [PATCH 1/3] cranelift-module: make backend error an anyhow::Error This allows us to retain richer information from backend errors. We already have `anyhow` as a dep in several places in the wasmtime tree, and in cranelift-faerie. faerie is the only user of this variant. Existing code that puts a String into the Backend error can trivially adapt their code to emit an anyhow::Error. --- cranelift/module/Cargo.toml | 1 + cranelift/module/src/module.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cranelift/module/Cargo.toml b/cranelift/module/Cargo.toml index 765179c649..423b2fdf85 100644 --- a/cranelift/module/Cargo.toml +++ b/cranelift/module/Cargo.toml @@ -16,6 +16,7 @@ cranelift-entity = { path = "../entity", version = "0.59.0" } hashbrown = { version = "0.6", optional = true } log = { version = "0.4.6", default-features = false } thiserror = "1.0.4" +anyhow = "1.0" [features] default = ["std"] diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rs index daa83c2956..470eea17fe 100644 --- a/cranelift/module/src/module.rs +++ b/cranelift/module/src/module.rs @@ -149,7 +149,7 @@ pub enum ModuleError { Compilation(#[from] CodegenError), /// Wraps a generic error from a backend #[error("Backend error: {0}")] - Backend(String), + Backend(#[source] anyhow::Error), } /// A convenient alias for a `Result` that uses `ModuleError` as the error type. From 2b87db3f55018738402058c3111ed6a965cb49c3 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 13 Mar 2020 11:52:40 -0700 Subject: [PATCH 2/3] cranelift-faerie: upgrade to faerie 0.15.0, fix error reporting the `FaerieProduct` exposes faerie-specific types, so we can give the `faerie::ArtifactError` on those methods. `ModuleError::Backend` now expects an `anyhow::Error`, so we change a .to_string into .into() and retain better error information. --- Cargo.lock | 24 ++++++++++++++++++++---- cranelift/faerie/Cargo.toml | 2 +- cranelift/faerie/src/backend.rs | 16 ++++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b76c9ea69..f1a8cdf268 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,7 @@ dependencies = [ "anyhow", "cranelift-codegen", "cranelift-module", - "faerie", + "faerie 0.15.0", "goblin", "target-lexicon", ] @@ -499,6 +499,7 @@ dependencies = [ name = "cranelift-module" version = "0.59.0" dependencies = [ + "anyhow", "cranelift-codegen", "cranelift-entity", "hashbrown", @@ -857,6 +858,21 @@ dependencies = [ "thiserror", ] +[[package]] +name = "faerie" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfef65b0e94693295c5d2fe2506f0ee6f43465342d4b5331659936aee8b16084" +dependencies = [ + "goblin", + "indexmap", + "log", + "scroll", + "string-interner", + "target-lexicon", + "thiserror", +] + [[package]] name = "failure" version = "0.1.6" @@ -2424,7 +2440,7 @@ name = "wasmtime-cli" version = "0.12.0" dependencies = [ "anyhow", - "faerie", + "faerie 0.14.0", "file-per-thread-logger", "filecheck", "libc", @@ -2453,7 +2469,7 @@ name = "wasmtime-debug" version = "0.12.0" dependencies = [ "anyhow", - "faerie", + "faerie 0.14.0", "gimli", "more-asserts", "target-lexicon", @@ -2553,7 +2569,7 @@ name = "wasmtime-obj" version = "0.12.0" dependencies = [ "anyhow", - "faerie", + "faerie 0.14.0", "more-asserts", "wasmtime-environ", ] diff --git a/cranelift/faerie/Cargo.toml b/cranelift/faerie/Cargo.toml index dc5d80e70a..a692b3db11 100644 --- a/cranelift/faerie/Cargo.toml +++ b/cranelift/faerie/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" [dependencies] cranelift-module = { path = "../module", version = "0.59.0" } -faerie = "0.14.0" +faerie = "0.15.0" goblin = "0.1.0" anyhow = "1.0" target-lexicon = "0.10" diff --git a/cranelift/faerie/src/backend.rs b/cranelift/faerie/src/backend.rs index 2518893974..4f1c4455ef 100644 --- a/cranelift/faerie/src/backend.rs +++ b/cranelift/faerie/src/backend.rs @@ -2,7 +2,7 @@ use crate::container; use crate::traps::{FaerieTrapManifest, FaerieTrapSink}; -use anyhow::Error; +use anyhow::anyhow; use cranelift_codegen::binemit::{ Addend, CodeOffset, NullStackmapSink, NullTrapSink, Reloc, RelocSink, Stackmap, StackmapSink, }; @@ -57,9 +57,9 @@ impl FaerieBuilder { libcall_names: Box String>, ) -> ModuleResult { if !isa.flags().is_pic() { - return Err(ModuleError::Backend( - "faerie requires TargetIsa be PIC".to_owned(), - )); + return Err(ModuleError::Backend(anyhow!( + "faerie requires TargetIsa be PIC" + ))); } Ok(Self { isa, @@ -257,7 +257,7 @@ impl Backend for FaerieBackend { to, at: u64::from(offset), }) - .map_err(|e| ModuleError::Backend(e.to_string()))?; + .map_err(|e| ModuleError::Backend(e.into()))?; } for &(offset, id, addend) in data_relocs { debug_assert_eq!( @@ -271,7 +271,7 @@ impl Backend for FaerieBackend { to, at: u64::from(offset), }) - .map_err(|e| ModuleError::Backend(e.to_string()))?; + .map_err(|e| ModuleError::Backend(e.into()))?; } match *init { @@ -369,12 +369,12 @@ impl FaerieProduct { } /// Call `emit` on the faerie `Artifact`, producing bytes in memory. - pub fn emit(&self) -> Result, Error> { + pub fn emit(&self) -> Result, faerie::ArtifactError> { self.artifact.emit() } /// Call `write` on the faerie `Artifact`, writing to a file. - pub fn write(&self, sink: File) -> Result<(), Error> { + pub fn write(&self, sink: File) -> Result<(), faerie::ArtifactError> { self.artifact.write(sink) } } From 2f6172732ffb63e608ea7089a4b1207b89b0b9ca Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 13 Mar 2020 15:30:39 -0700 Subject: [PATCH 3/3] wasmtime-cli, obj, debug: upgrade to faerie 0.15 eliminating the faerie 0.14 dep --- Cargo.lock | 24 ++++-------------------- Cargo.toml | 2 +- crates/debug/Cargo.toml | 2 +- crates/debug/src/write_debuginfo.rs | 3 ++- crates/obj/Cargo.toml | 2 +- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1a8cdf268..5323dedf7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,7 @@ dependencies = [ "anyhow", "cranelift-codegen", "cranelift-module", - "faerie 0.15.0", + "faerie", "goblin", "target-lexicon", ] @@ -842,22 +842,6 @@ dependencies = [ name = "example-fib-debug-wasm" version = "0.1.0" -[[package]] -name = "faerie" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b9ed6159e4a6212c61d9c6a86bee01876b192a64accecf58d5b5ae3b667b52" -dependencies = [ - "anyhow", - "goblin", - "indexmap", - "log", - "scroll", - "string-interner", - "target-lexicon", - "thiserror", -] - [[package]] name = "faerie" version = "0.15.0" @@ -2440,7 +2424,7 @@ name = "wasmtime-cli" version = "0.12.0" dependencies = [ "anyhow", - "faerie 0.14.0", + "faerie", "file-per-thread-logger", "filecheck", "libc", @@ -2469,7 +2453,7 @@ name = "wasmtime-debug" version = "0.12.0" dependencies = [ "anyhow", - "faerie 0.14.0", + "faerie", "gimli", "more-asserts", "target-lexicon", @@ -2569,7 +2553,7 @@ name = "wasmtime-obj" version = "0.12.0" dependencies = [ "anyhow", - "faerie 0.14.0", + "faerie", "more-asserts", "wasmtime-environ", ] diff --git a/Cargo.toml b/Cargo.toml index 90b2725131..5723e05f6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ wasmtime-wast = { path = "crates/wast" } wasmtime-wasi = { path = "crates/wasi" } wasi-common = { path = "crates/wasi-common" } structopt = { version = "0.3.5", features = ["color", "suggestions"] } -faerie = "0.14.0" +faerie = "0.15.0" anyhow = "1.0.19" target-lexicon = { version = "0.10.0", default-features = false } pretty_env_logger = "0.3.0" diff --git a/crates/debug/Cargo.toml b/crates/debug/Cargo.toml index 0f02660553..618dffbe1a 100644 --- a/crates/debug/Cargo.toml +++ b/crates/debug/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] gimli = "0.20.0" wasmparser = "0.51.2" -faerie = "0.14.0" +faerie = "0.15.0" wasmtime-environ = { path = "../environ", version = "0.12.0" } target-lexicon = { version = "0.10.0", default-features = false } anyhow = "1.0" diff --git a/crates/debug/src/write_debuginfo.rs b/crates/debug/src/write_debuginfo.rs index d5cf56fe54..accdb17d40 100644 --- a/crates/debug/src/write_debuginfo.rs +++ b/crates/debug/src/write_debuginfo.rs @@ -35,7 +35,8 @@ pub fn emit_dwarf( id.name(), Decl::section(SectionKind::Debug), s.writer.take(), - ) + )?; + Ok(()) })?; sections.for_each_mut(|id, s| -> anyhow::Result<()> { for reloc in &s.relocs { diff --git a/crates/obj/Cargo.toml b/crates/obj/Cargo.toml index aa141ecbbb..7b3aa60a54 100644 --- a/crates/obj/Cargo.toml +++ b/crates/obj/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] anyhow = "1.0" wasmtime-environ = { path = "../environ", version = "0.12.0" } -faerie = "0.14.0" +faerie = "0.15.0" more-asserts = "0.2.1" [badges]