Remove thiserror dependency from cranelift_codegen
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -535,7 +535,6 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
"souper-ir",
|
"souper-ir",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"thiserror",
|
|
||||||
"wast 35.0.2",
|
"wast 35.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ serde = { version = "1.0.94", features = ["derive"], optional = true }
|
|||||||
bincode = { version = "1.2.1", optional = true }
|
bincode = { version = "1.2.1", optional = true }
|
||||||
gimli = { version = "0.23.0", default-features = false, features = ["write"], optional = true }
|
gimli = { version = "0.23.0", default-features = false, features = ["write"], optional = true }
|
||||||
smallvec = { version = "1.6.1" }
|
smallvec = { version = "1.6.1" }
|
||||||
thiserror = "1.0.4"
|
|
||||||
peepmatic = { path = "../peepmatic", optional = true, version = "0.73.0" }
|
peepmatic = { path = "../peepmatic", optional = true, version = "0.73.0" }
|
||||||
peepmatic-traits = { path = "../peepmatic/crates/traits", optional = true, version = "0.73.0" }
|
peepmatic-traits = { path = "../peepmatic/crates/traits", optional = true, version = "0.73.0" }
|
||||||
peepmatic-runtime = { path = "../peepmatic/crates/runtime", optional = true, version = "0.73.0" }
|
peepmatic-runtime = { path = "../peepmatic/crates/runtime", optional = true, version = "0.73.0" }
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use crate::ir::{types, ConstantData, Type};
|
|||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::fmt::{self, Display, Formatter};
|
use core::fmt::{self, Display, Formatter};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// Represent a data value. Where [Value] is an SSA reference, [DataValue] is the type + value
|
/// Represent a data value. Where [Value] is an SSA reference, [DataValue] is the type + value
|
||||||
/// that would be referred to by a [Value].
|
/// that would be referred to by a [Value].
|
||||||
@@ -97,15 +96,36 @@ impl DataValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Record failures to cast [DataValue].
|
/// Record failures to cast [DataValue].
|
||||||
#[derive(Error, Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub enum DataValueCastFailure {
|
pub enum DataValueCastFailure {
|
||||||
#[error("unable to cast data value of type {0} to type {1}")]
|
|
||||||
TryInto(Type, Type),
|
TryInto(Type, Type),
|
||||||
#[error("unable to cast i64({0}) to a data value of type {1}")]
|
|
||||||
FromInteger(i64, Type),
|
FromInteger(i64, Type),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for DataValueCastFailure {}
|
||||||
|
|
||||||
|
impl Display for DataValueCastFailure {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
DataValueCastFailure::TryInto(from, to) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"unable to cast data value of type {} to type {}",
|
||||||
|
from, to
|
||||||
|
)
|
||||||
|
}
|
||||||
|
DataValueCastFailure::FromInteger(val, to) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"unable to cast i64({}) to a data value of type {}",
|
||||||
|
val, to
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper for creating conversion implementations for [DataValue].
|
/// Helper for creating conversion implementations for [DataValue].
|
||||||
macro_rules! build_conversion_impl {
|
macro_rules! build_conversion_impl {
|
||||||
( $rust_ty:ty, $data_value_ty:ident, $cranelift_ty:ident ) => {
|
( $rust_ty:ty, $data_value_ty:ident, $cranelift_ty:ident ) => {
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ use core::fmt;
|
|||||||
use core::fmt::{Debug, Formatter};
|
use core::fmt::{Debug, Formatter};
|
||||||
use core::hash::Hasher;
|
use core::hash::Hasher;
|
||||||
use target_lexicon::{triple, Architecture, OperatingSystem, PointerWidth, Triple};
|
use target_lexicon::{triple, Architecture, OperatingSystem, PointerWidth, Triple};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[cfg(feature = "riscv")]
|
#[cfg(feature = "riscv")]
|
||||||
mod riscv;
|
mod riscv;
|
||||||
@@ -178,17 +177,28 @@ pub fn lookup_by_name(name: &str) -> Result<Builder, LookupError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Describes reason for target lookup failure
|
/// Describes reason for target lookup failure
|
||||||
#[derive(Error, PartialEq, Eq, Copy, Clone, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
pub enum LookupError {
|
pub enum LookupError {
|
||||||
/// Support for this target was disabled in the current build.
|
/// Support for this target was disabled in the current build.
|
||||||
#[error("Support for this target is disabled")]
|
|
||||||
SupportDisabled,
|
SupportDisabled,
|
||||||
|
|
||||||
/// Support for this target has not yet been implemented.
|
/// Support for this target has not yet been implemented.
|
||||||
#[error("Support for this target has not been implemented yet")]
|
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for LookupError {}
|
||||||
|
|
||||||
|
impl fmt::Display for LookupError {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
LookupError::SupportDisabled => write!(f, "Support for this target is disabled"),
|
||||||
|
LookupError::Unsupported => {
|
||||||
|
write!(f, "Support for this target has not been implemented yet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Builder for a `TargetIsa`.
|
/// Builder for a `TargetIsa`.
|
||||||
/// Modify the ISA-specific settings before creating the `TargetIsa` trait object with `finish`.
|
/// Modify the ISA-specific settings before creating the `TargetIsa` trait object with `finish`.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use crate::isa::unwind::UnwindInst;
|
|||||||
use crate::result::{CodegenError, CodegenResult};
|
use crate::result::{CodegenError, CodegenResult};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use gimli::write::{Address, FrameDescriptionEntry};
|
use gimli::write::{Address, FrameDescriptionEntry};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[cfg(feature = "enable-serde")]
|
#[cfg(feature = "enable-serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -15,16 +14,30 @@ type Register = u16;
|
|||||||
|
|
||||||
/// Enumerate the errors possible in mapping Cranelift registers to their DWARF equivalent.
|
/// Enumerate the errors possible in mapping Cranelift registers to their DWARF equivalent.
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
#[derive(Error, Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum RegisterMappingError {
|
pub enum RegisterMappingError {
|
||||||
#[error("unable to find bank for register info")]
|
|
||||||
MissingBank,
|
MissingBank,
|
||||||
#[error("register mapping is currently only implemented for x86_64")]
|
|
||||||
UnsupportedArchitecture,
|
UnsupportedArchitecture,
|
||||||
#[error("unsupported register bank: {0}")]
|
|
||||||
UnsupportedRegisterBank(&'static str),
|
UnsupportedRegisterBank(&'static str),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for RegisterMappingError {}
|
||||||
|
|
||||||
|
impl std::fmt::Display for RegisterMappingError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
RegisterMappingError::MissingBank => write!(f, "unable to find bank for register info"),
|
||||||
|
RegisterMappingError::UnsupportedArchitecture => write!(
|
||||||
|
f,
|
||||||
|
"register mapping is currently only implemented for x86_64"
|
||||||
|
),
|
||||||
|
RegisterMappingError::UnsupportedRegisterBank(bank) => {
|
||||||
|
write!(f, "unsupported register bank: {}", bank)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This mirrors gimli's CallFrameInstruction, but is serializable
|
// This mirrors gimli's CallFrameInstruction, but is serializable
|
||||||
// This excludes CfaExpression, Expression, ValExpression due to
|
// This excludes CfaExpression, Expression, ValExpression due to
|
||||||
// https://github.com/gimli-rs/gimli/issues/513.
|
// https://github.com/gimli-rs/gimli/issues/513.
|
||||||
|
|||||||
@@ -2,19 +2,17 @@
|
|||||||
|
|
||||||
use crate::verifier::VerifierErrors;
|
use crate::verifier::VerifierErrors;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// A compilation error.
|
/// A compilation error.
|
||||||
///
|
///
|
||||||
/// When Cranelift fails to compile a function, it will return one of these error codes.
|
/// When Cranelift fails to compile a function, it will return one of these error codes.
|
||||||
#[derive(Error, Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum CodegenError {
|
pub enum CodegenError {
|
||||||
/// A list of IR verifier errors.
|
/// A list of IR verifier errors.
|
||||||
///
|
///
|
||||||
/// This always represents a bug, either in the code that generated IR for Cranelift, or a bug
|
/// This always represents a bug, either in the code that generated IR for Cranelift, or a bug
|
||||||
/// in Cranelift itself.
|
/// in Cranelift itself.
|
||||||
#[error("Verifier errors")]
|
Verifier(VerifierErrors),
|
||||||
Verifier(#[from] VerifierErrors),
|
|
||||||
|
|
||||||
/// An implementation limit was exceeded.
|
/// An implementation limit was exceeded.
|
||||||
///
|
///
|
||||||
@@ -22,27 +20,55 @@ pub enum CodegenError {
|
|||||||
/// limits][limits] that cause compilation to fail when they are exceeded.
|
/// limits][limits] that cause compilation to fail when they are exceeded.
|
||||||
///
|
///
|
||||||
/// [limits]: https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/docs/ir.md#implementation-limits
|
/// [limits]: https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/docs/ir.md#implementation-limits
|
||||||
#[error("Implementation limit exceeded")]
|
|
||||||
ImplLimitExceeded,
|
ImplLimitExceeded,
|
||||||
|
|
||||||
/// The code size for the function is too large.
|
/// The code size for the function is too large.
|
||||||
///
|
///
|
||||||
/// Different target ISAs may impose a limit on the size of a compiled function. If that limit
|
/// Different target ISAs may impose a limit on the size of a compiled function. If that limit
|
||||||
/// is exceeded, compilation fails.
|
/// is exceeded, compilation fails.
|
||||||
#[error("Code for function is too large")]
|
|
||||||
CodeTooLarge,
|
CodeTooLarge,
|
||||||
|
|
||||||
/// Something is not supported by the code generator. This might be an indication that a
|
/// Something is not supported by the code generator. This might be an indication that a
|
||||||
/// feature is used without explicitly enabling it, or that something is temporarily
|
/// feature is used without explicitly enabling it, or that something is temporarily
|
||||||
/// unsupported by a given target backend.
|
/// unsupported by a given target backend.
|
||||||
#[error("Unsupported feature: {0}")]
|
|
||||||
Unsupported(String),
|
Unsupported(String),
|
||||||
|
|
||||||
/// A failure to map Cranelift register representation to a DWARF register representation.
|
/// A failure to map Cranelift register representation to a DWARF register representation.
|
||||||
#[cfg(feature = "unwind")]
|
#[cfg(feature = "unwind")]
|
||||||
#[error("Register mapping error")]
|
|
||||||
RegisterMappingError(crate::isa::unwind::systemv::RegisterMappingError),
|
RegisterMappingError(crate::isa::unwind::systemv::RegisterMappingError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A convenient alias for a `Result` that uses `CodegenError` as the error type.
|
/// A convenient alias for a `Result` that uses `CodegenError` as the error type.
|
||||||
pub type CodegenResult<T> = Result<T, CodegenError>;
|
pub type CodegenResult<T> = Result<T, CodegenError>;
|
||||||
|
|
||||||
|
impl std::error::Error for CodegenError {
|
||||||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
match self {
|
||||||
|
CodegenError::Verifier(source) => Some(source),
|
||||||
|
CodegenError::ImplLimitExceeded { .. }
|
||||||
|
| CodegenError::CodeTooLarge { .. }
|
||||||
|
| CodegenError::Unsupported { .. } => None,
|
||||||
|
#[cfg(feature = "unwind")]
|
||||||
|
CodegenError::RegisterMappingError { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for CodegenError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
CodegenError::Verifier(_) => write!(f, "Verifier errors"),
|
||||||
|
CodegenError::ImplLimitExceeded => write!(f, "Implementation limit exceeded"),
|
||||||
|
CodegenError::CodeTooLarge => write!(f, "Code for function is too large"),
|
||||||
|
CodegenError::Unsupported(feature) => write!(f, "Unsupported feature: {}", feature),
|
||||||
|
#[cfg(feature = "unwind")]
|
||||||
|
CodegenError::RegisterMappingError(_0) => write!(f, "Register mapping error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<VerifierErrors> for CodegenError {
|
||||||
|
fn from(source: VerifierErrors) -> Self {
|
||||||
|
CodegenError::Verifier { 0: source }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ use alloc::boxed::Box;
|
|||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::str;
|
use core::str;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// A string-based configurator for settings groups.
|
/// A string-based configurator for settings groups.
|
||||||
///
|
///
|
||||||
@@ -261,21 +260,34 @@ impl Configurable for Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An error produced when changing a setting.
|
/// An error produced when changing a setting.
|
||||||
#[derive(Error, Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum SetError {
|
pub enum SetError {
|
||||||
/// No setting by this name exists.
|
/// No setting by this name exists.
|
||||||
#[error("No existing setting named '{0}'")]
|
|
||||||
BadName(String),
|
BadName(String),
|
||||||
|
|
||||||
/// Type mismatch for setting (e.g., setting an enum setting as a bool).
|
/// Type mismatch for setting (e.g., setting an enum setting as a bool).
|
||||||
#[error("Trying to set a setting with the wrong type")]
|
|
||||||
BadType,
|
BadType,
|
||||||
|
|
||||||
/// This is not a valid value for this setting.
|
/// This is not a valid value for this setting.
|
||||||
#[error("Unexpected value for a setting, expected {0}")]
|
|
||||||
BadValue(String),
|
BadValue(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for SetError {}
|
||||||
|
|
||||||
|
impl fmt::Display for SetError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
SetError::BadName(name) => write!(f, "No existing setting named '{}'", name),
|
||||||
|
SetError::BadType => {
|
||||||
|
write!(f, "Trying to set a setting with the wrong type")
|
||||||
|
}
|
||||||
|
SetError::BadValue(value) => {
|
||||||
|
write!(f, "Unexpected value for a setting, expected {}", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A result returned when changing a setting.
|
/// A result returned when changing a setting.
|
||||||
pub type SetResult<T> = Result<T, SetError>;
|
pub type SetResult<T> = Result<T, SetError>;
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ use alloc::vec::Vec;
|
|||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::fmt::{self, Display, Formatter, Write};
|
use core::fmt::{self, Display, Formatter, Write};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
pub use self::cssa::verify_cssa;
|
pub use self::cssa::verify_cssa;
|
||||||
pub use self::liveness::verify_liveness;
|
pub use self::liveness::verify_liveness;
|
||||||
@@ -92,8 +91,7 @@ mod liveness;
|
|||||||
mod locations;
|
mod locations;
|
||||||
|
|
||||||
/// A verifier error.
|
/// A verifier error.
|
||||||
#[derive(Error, Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
#[error("{}{}: {}", .location, format_context(.context), .message)]
|
|
||||||
pub struct VerifierError {
|
pub struct VerifierError {
|
||||||
/// The entity causing the verifier error.
|
/// The entity causing the verifier error.
|
||||||
pub location: AnyEntity,
|
pub location: AnyEntity,
|
||||||
@@ -104,11 +102,14 @@ pub struct VerifierError {
|
|||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for formatting Verifier::Error context.
|
impl std::error::Error for VerifierError {}
|
||||||
fn format_context(context: &Option<String>) -> String {
|
|
||||||
match context {
|
impl Display for VerifierError {
|
||||||
None => "".to_string(),
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
Some(c) => format!(" ({})", c),
|
match &self.context {
|
||||||
|
None => write!(f, "{}: {}", self.location, self.message),
|
||||||
|
Some(context) => write!(f, "{} ({}): {}", self.location, context, self.message),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,9 +176,11 @@ pub type VerifierStepResult<T> = Result<T, ()>;
|
|||||||
pub type VerifierResult<T> = Result<T, VerifierErrors>;
|
pub type VerifierResult<T> = Result<T, VerifierErrors>;
|
||||||
|
|
||||||
/// List of verifier errors.
|
/// List of verifier errors.
|
||||||
#[derive(Error, Debug, Default, PartialEq, Eq, Clone)]
|
#[derive(Debug, Default, PartialEq, Eq, Clone)]
|
||||||
pub struct VerifierErrors(pub Vec<VerifierError>);
|
pub struct VerifierErrors(pub Vec<VerifierError>);
|
||||||
|
|
||||||
|
impl std::error::Error for VerifierErrors {}
|
||||||
|
|
||||||
impl VerifierErrors {
|
impl VerifierErrors {
|
||||||
/// Return a new `VerifierErrors` struct.
|
/// Return a new `VerifierErrors` struct.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
Reference in New Issue
Block a user