Skip to content

Commit

Permalink
Merge pull request #1048 from sbillig/diag-refactor
Browse files Browse the repository at this point in the history
Diagnostic refactor
  • Loading branch information
sbillig authored Jan 27, 2025
2 parents 93f181d + cc94a4a commit f704df1
Show file tree
Hide file tree
Showing 53 changed files with 2,535 additions and 2,561 deletions.
24 changes: 16 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions crates/driver/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use common::{
InputDb, InputFile, InputIngot,
};
use hir::{
analysis_pass::AnalysisPassManager,
diagnostics::DiagnosticVoucher,
hir_def::TopLevelMod,
lower::{map_file_to_mod, module_tree},
HirDb, LowerHirDb, ParsingPass, SpannedHirDb,
HirDb, LowerHirDb, SpannedHirDb,
};
use hir_analysis::{
analysis_pass::{AnalysisPassManager, ParsingPass},
diagnostics::{DiagnosticVoucher, SpannedHirAnalysisDb},
name_resolution::{DefConflictAnalysisPass, ImportAnalysisPass, PathAnalysisPass},
ty::{
AdtDefAnalysisPass, BodyAnalysisPass, FuncAnalysisPass, ImplAnalysisPass,
Expand All @@ -36,7 +36,7 @@ static LIBRARY: Dir = include_dir!("$CARGO_MANIFEST_DIR/../../library");

#[salsa::db]
pub trait DriverDb:
salsa::Database + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
salsa::Database + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb + SpannedHirAnalysisDb
{
fn as_driver_db(&self) -> &dyn DriverDb;
}
Expand All @@ -53,7 +53,8 @@ impl_db_traits!(
LowerHirDb,
SpannedHirDb,
HirAnalysisDb,
DriverDb
SpannedHirAnalysisDb,
DriverDb,
);

impl DriverDataBase {
Expand Down
8 changes: 4 additions & 4 deletions crates/driver/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ use common::{
InputDb, InputFile,
};
use cs::{diagnostic as cs_diag, files as cs_files};
use hir::{diagnostics::DiagnosticVoucher, SpannedHirDb};
use hir_analysis::diagnostics::{DiagnosticVoucher, SpannedHirAnalysisDb};

use crate::DriverDb;

pub trait ToCsDiag {
fn to_cs(&self, db: &dyn SpannedInputDb) -> cs_diag::Diagnostic<InputFile>;
}

pub trait SpannedInputDb: SpannedHirDb + InputDb {}
impl<T> SpannedInputDb for T where T: SpannedHirDb + InputDb {}
pub trait SpannedInputDb: SpannedHirAnalysisDb + InputDb {}
impl<T> SpannedInputDb for T where T: SpannedHirAnalysisDb + InputDb {}

impl<T> ToCsDiag for T
where
T: for<'db> DiagnosticVoucher<'db>,
{
fn to_cs(&self, db: &dyn SpannedInputDb) -> cs_diag::Diagnostic<InputFile> {
let complete = self.to_complete(db.as_spanned_hir_db());
let complete = self.to_complete(db.as_spanned_hir_analysis_db());

let severity = convert_severity(complete.severity);
let code = Some(complete.error_code.to_string());
Expand Down
1 change: 1 addition & 0 deletions crates/hir-analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ num-bigint.workspace = true
rustc-hash.workspace = true
salsa.workspace = true
smallvec.workspace = true
smallvec2 = { package = "smallvec", version = "2.0.0-alpha.10" }

common.workspace = true
test-utils.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{
diagnostics::DiagnosticVoucher,
use crate::diagnostics::DiagnosticVoucher;
use hir::{
hir_def::{ModuleTree, TopLevelMod},
lower::parse_file_impl,
HirDb, ParseErrorAccumulator,
};

/// All analysis passes that run analysis on the HIR top level module
Expand Down Expand Up @@ -50,3 +52,26 @@ impl<'db> AnalysisPassManager<'db> {
diags
}
}

#[derive(Clone, Copy)]
pub struct ParsingPass<'db> {
db: &'db dyn HirDb,
}

impl<'db> ParsingPass<'db> {
pub fn new(db: &'db dyn HirDb) -> Self {
Self { db }
}
}

impl<'db> ModuleAnalysisPass<'db> for ParsingPass<'db> {
fn run_on_module(
&mut self,
top_mod: TopLevelMod<'db>,
) -> Vec<Box<dyn DiagnosticVoucher<'db> + 'db>> {
parse_file_impl::accumulated::<ParseErrorAccumulator>(self.db, top_mod)
.into_iter()
.map(|d| Box::new(d.0) as _)
.collect::<Vec<_>>()
}
}
Loading

0 comments on commit f704df1

Please # to comment.