-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MonoItems and Instance to stable_mir
Also add a few methods to instantiate instances and get an instance definition. We're still missing support to actually monomorphize the instance body.
- Loading branch information
Showing
7 changed files
with
401 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! When things go wrong, we need some error handling. | ||
//! There are a few different types of errors in StableMIR: | ||
//! | ||
//! - [CompilerError]: This represents errors that can be raised when invoking the compiler. | ||
//! - [Error]: Generic error that represents the reason why a request that could not be fulfilled. | ||
|
||
use std::fmt::{Debug, Display, Formatter}; | ||
use std::{error, fmt}; | ||
|
||
/// An error type used to represent an error that has already been reported by the compiler. | ||
#[derive(Clone, Copy, PartialEq, Eq)] | ||
pub enum CompilerError<T> { | ||
/// Internal compiler error (I.e.: Compiler crashed). | ||
ICE, | ||
/// Compilation failed. | ||
CompilationFailed, | ||
/// Compilation was interrupted. | ||
Interrupted(T), | ||
/// Compilation skipped. This happens when users invoke rustc to retrieve information such as | ||
/// --version. | ||
Skipped, | ||
} | ||
|
||
/// A generic error to represent an API request that cannot be fulfilled. | ||
#[derive(Debug)] | ||
pub struct Error(String); | ||
|
||
impl Error { | ||
pub(crate) fn new(msg: String) -> Self { | ||
Self(msg) | ||
} | ||
} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
Display::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl<T> Display for CompilerError<T> | ||
where | ||
T: Display, | ||
{ | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
CompilerError::ICE => write!(f, "Internal Compiler Error"), | ||
CompilerError::CompilationFailed => write!(f, "Compilation Failed"), | ||
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason}"), | ||
CompilerError::Skipped => write!(f, "Compilation Skipped"), | ||
} | ||
} | ||
} | ||
|
||
impl<T> Debug for CompilerError<T> | ||
where | ||
T: Debug, | ||
{ | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
match self { | ||
CompilerError::ICE => write!(f, "Internal Compiler Error"), | ||
CompilerError::CompilationFailed => write!(f, "Compilation Failed"), | ||
CompilerError::Interrupted(reason) => write!(f, "Compilation Interrupted: {reason:?}"), | ||
CompilerError::Skipped => write!(f, "Compilation Skipped"), | ||
} | ||
} | ||
} | ||
|
||
impl error::Error for Error {} | ||
impl<T> error::Error for CompilerError<T> where T: Display + Debug {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod body; | ||
pub mod mono; | ||
|
||
pub use body::*; |
Oops, something went wrong.