Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tyvar refinement #1034

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ resolver = "2"
[profile.dev.package.solc]
opt-level = 3

[workspace.dependencies]
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "7ca9695" }

[profile.dev]
# Set to 0 to make the build faster and debugging more difficult.
debug = 1
3 changes: 2 additions & 1 deletion crates/common2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = "Provides HIR definition and lowering for Fe lang."
semver = "1.0.17"
camino = "1.1.4"
smol_str = "0.1.24"
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
salsa.workspace = true
indexmap = "2.2"
parser = { path = "../parser2", package = "fe-parser2" }
paste = "1.0.15"
2 changes: 1 addition & 1 deletion crates/common2/src/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
ops::{Deref, DerefMut},
};

use salsa::update::Update;
use salsa::Update;

#[derive(Debug, Clone)]
pub struct IndexMap<K, V, S = RandomState>(indexmap::IndexMap<K, V, S>);
Expand Down
1 change: 1 addition & 0 deletions crates/common2/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use camino::Utf8PathBuf;
use salsa::Setter;
use smol_str::SmolStr;

use crate::{indexmap::IndexSet, InputDb};
Expand Down
34 changes: 26 additions & 8 deletions crates/common2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
pub mod diagnostics;
pub mod indexmap;
pub mod input;

pub use input::{InputFile, InputIngot};

#[salsa::jar(db = InputDb)]
pub struct Jar(InputIngot, InputFile);
#[salsa::db]
pub trait InputDb: salsa::Database {
fn as_input_db(&self) -> &dyn InputDb;
}

#[doc(hidden)]
pub use paste::paste;

#[macro_export]
macro_rules! impl_db_traits {
($db_type:ty, $($trait_name:ident),+ $(,)?) => {
#[salsa::db]
impl salsa::Database for $db_type {
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
}

pub trait InputDb: salsa::DbWithJar<Jar> {
fn as_input_db(&self) -> &dyn InputDb {
<Self as salsa::DbWithJar<Jar>>::as_jar_db::<'_>(self)
}
$(
$crate::paste! {
#[salsa::db]
impl $trait_name for $db_type {
fn [<as_ $trait_name:snake>](&self) -> &dyn $trait_name {
self
}
}
}
)+
};
}
impl<DB> InputDb for DB where DB: ?Sized + salsa::DbWithJar<Jar> {}
2 changes: 1 addition & 1 deletion crates/driver2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Provides Fe driver"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
salsa.workspace = true
codespan-reporting = "0.11"

hir = { path = "../hir", package = "fe-hir" }
Expand Down
37 changes: 15 additions & 22 deletions crates/driver2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use codespan_reporting::term::{
};
use common::{
diagnostics::CompleteDiagnostic,
impl_db_traits,
indexmap::IndexSet,
input::{IngotKind, Version},
InputDb, InputFile, InputIngot,
Expand All @@ -28,31 +29,27 @@ use hir_analysis::{

use crate::diagnostics::ToCsDiag;

#[salsa::jar(db = DriverDb)]
pub struct Jar(diagnostics::file_line_starts);

#[salsa::db]
pub trait DriverDb:
salsa::DbWithJar<Jar> + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
{
}

impl<DB> DriverDb for DB where
DB: salsa::DbWithJar<Jar> + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
salsa::Database + HirAnalysisDb + HirDb + LowerHirDb + SpannedHirDb + InputDb
{
fn as_driver_db(&self) -> &dyn DriverDb;
}

#[derive(Default)]
#[salsa::db(
common::Jar,
hir::Jar,
hir::LowerJar,
hir::SpannedJar,
hir_analysis::Jar,
Jar
)]
#[derive(Default, Clone)]
#[salsa::db]
pub struct DriverDataBase {
storage: salsa::Storage<Self>,
}
impl_db_traits!(
DriverDataBase,
InputDb,
HirDb,
LowerHirDb,
SpannedHirDb,
HirAnalysisDb,
DriverDb
);

impl DriverDataBase {
// TODO: An temporary implementation for ui testing.
Expand Down Expand Up @@ -98,10 +95,6 @@ impl DriverDataBase {
}
}

impl salsa::Database for DriverDataBase {
fn salsa_event(&self, _: salsa::Event) {}
}

pub struct DiagnosticsCollection<'db>(Vec<Box<dyn DiagnosticVoucher<'db> + 'db>>);
impl<'db> DiagnosticsCollection<'db> {
pub fn emit(&self, db: &'db DriverDataBase) {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/ethereum/fe"
description = "Provides HIR semantic analysis for Fe lang"

[dependencies]
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
salsa.workspace = true
smallvec = "1.10"
rustc-hash = "1.1.0"
either = "1.8"
Expand Down
80 changes: 3 additions & 77 deletions crates/hir-analysis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,83 +1,9 @@
use hir::{span::DynLazySpan, HirDb};

#[salsa::jar(db = HirAnalysisDb)]
pub struct Jar(
name_resolution::resolve_imports,
name_resolution::traits_in_scope::available_traits_in_scope_impl,
name_resolution::traits_in_scope::TraitScope<'_>,
name_resolution::EarlyNameQueryId<'_>,
name_resolution::resolve_query,
// Type system.
ty::ty_def::TyId<'_>,
ty::ty_def::ty_kind,
ty::ty_def::pretty_print_ty,
ty::ty_def::decompose_ty_app,
ty::ty_def::ty_flags,
// Adt types.
ty::adt_def::AdtDef<'_>,
ty::adt_def::AdtRefId<'_>,
ty::adt_def::lower_adt,
// Func type.
ty::func_def::FuncDef<'_>,
ty::func_def::lower_func,
// Const types.
ty::const_ty::ConstTyId<'_>,
ty::const_ty::evaluate_const_ty,
// Type lowering.
ty::ty_lower::lower_hir_ty,
ty::ty_lower::lower_type_alias,
ty::ty_lower::collect_generic_params,
ty::ty_lower::GenericParamOwnerId<'_>,
ty::ty_lower::GenericParamTypeSet<'_>,
ty::ty_lower::evaluate_params_precursor,
// Trait lowering.
ty::trait_lower::lower_trait,
ty::trait_lower::lower_trait_ref,
ty::trait_lower::collect_trait_impls,
ty::trait_lower::lower_impl_trait,
ty::trait_lower::collect_implementor_methods,
// Method collection.
ty::method_table::collect_methods,
ty::method_table::probe_method,
// Item Definition analysis.
ty::def_analysis::check_recursive_adt,
ty::def_analysis::analyze_adt,
ty::def_analysis::analyze_type_alias,
ty::def_analysis::analyze_trait,
ty::def_analysis::analyze_impl,
ty::def_analysis::analyze_impl_trait,
ty::def_analysis::analyze_func,
// Trait system.
ty::trait_def::TraitDef<'_>,
ty::trait_def::TraitInstId<'_>,
ty::trait_def::Implementor<'_>,
ty::trait_def::ingot_trait_env,
ty::trait_def::impls_for_trait,
ty::trait_def::impls_for_ty,
// Trait constraints
ty::trait_resolution::constraint::collect_super_traits,
ty::trait_resolution::constraint::collect_trait_constraints,
ty::trait_resolution::constraint::collect_adt_constraints,
ty::trait_resolution::constraint::collect_implementor_constraints,
ty::trait_resolution::constraint::collect_impl_block_constraints,
ty::trait_resolution::constraint::collect_func_def_constraints,
ty::trait_resolution::constraint::collect_func_def_constraints_impl,
ty::trait_resolution::constraint::ty_constraints,
ty::trait_resolution::PredicateListId<'_>,
ty::trait_resolution::is_goal_satisfiable,
ty::trait_resolution::check_ty_wf,
ty::trait_resolution::check_trait_inst_wf,
ty::trait_resolution::ty_depth_impl,
// Type checking.
ty::ty_check::check_func_body,
);

pub trait HirAnalysisDb: salsa::DbWithJar<Jar> + HirDb {
fn as_hir_analysis_db(&self) -> &dyn HirAnalysisDb {
<Self as salsa::DbWithJar<Jar>>::as_jar_db::<'_>(self)
}
#[salsa::db]
pub trait HirAnalysisDb: salsa::Database + HirDb {
fn as_hir_analysis_db(&self) -> &dyn HirAnalysisDb;
}
impl<DB> HirAnalysisDb for DB where DB: ?Sized + salsa::DbWithJar<Jar> + HirDb {}

pub mod name_resolution;
pub mod ty;
Expand Down
Loading
Loading