Skip to content

Commit

Permalink
feat(sol-driver): use into_eyre_diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed May 29, 2024
1 parent 3995e40 commit 1da37ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 11 additions & 0 deletions sol-diagnostic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ pub struct Diagnostics(Arc<sol_eyre::Report>);
/// A result type that uses [`Diagnostic`] as the error type.
pub type Result<T, E = Diagnostic> = std::result::Result<T, E>;

/// A trait for types that can be converted into a [`Diagnostic`].
pub trait IntoEyreDiagnostic<T> {
fn into_eyre_diagnostic(self) -> sol_eyre::Result<T>;
}

impl<T> IntoEyreDiagnostic<T> for Result<T, Diagnostic> {
fn into_eyre_diagnostic(self) -> sol_eyre::Result<T> {
self.map_err(|diagnostic| *diagnostic.0)
}
}

/// A trait for types that can be unwrapped or report an error. By reporting
/// an error, it means that the error is added to the diagnostic accumulator.
pub trait UnwrapOrReport<T: Default> {
Expand Down
9 changes: 5 additions & 4 deletions sol-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{

use dashmap::{DashMap, DashSet};
use salsa::DebugWithDb;
use sol_diagnostic::IntoEyreDiagnostic;
use sol_hir::{
lowering::HirLowering,
package::{HasManifest, Package},
Expand Down Expand Up @@ -66,22 +67,22 @@ impl HirLowering for RootDb {
/// Bridges the [`RootDb`] with the [`sol_thir::ThirLowering`] trait.
impl ThirLowering for RootDb {
fn thir_eval(&self, env: sol_thir::shared::Env, term: Term) -> sol_thir::value::Value {
sol_thir_lowering::thir_eval(self, env, term)
sol_thir_lowering::thir_eval(self, env, term).into_eyre_diagnostic()
}

fn thir_quote(&self, lvl: sol_thir::debruijin::Level, value: sol_thir::value::Value) -> Term {
sol_thir_lowering::thir_quote(self, lvl, value)
sol_thir_lowering::thir_quote(self, lvl, value).into_eyre_diagnostic()
}
}

/// Bridges the [`RootDb`] with the [`sol_thir::ThirTyping`] trait.
impl ThirTyping for RootDb {
fn thir_infer(&self, ctx: sol_thir::shared::Context, expr: Expr) -> ElaboratedTerm {
sol_thir_lowering::infer::thir_infer(self, ctx, expr)
sol_thir_lowering::infer::thir_infer(self, ctx, expr).into_eyre_diagnostic()
}

fn thir_check(&self, ctx: sol_thir::shared::Context, expr: Expr, type_repr: Type) -> Term {
sol_thir_lowering::check::thir_check(self, ctx, expr, type_repr)
sol_thir_lowering::check::thir_check(self, ctx, expr, type_repr).into_eyre_diagnostic()
}
}

Expand Down

0 comments on commit 1da37ba

Please sign in to comment.