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

cargo test takes too long if each crate has a dedicated salsa db #465

Open
xiyuzhai opened this issue Nov 24, 2023 · 0 comments
Open

cargo test takes too long if each crate has a dedicated salsa db #465

xiyuzhai opened this issue Nov 24, 2023 · 0 comments

Comments

@xiyuzhai
Copy link

xiyuzhai commented Nov 24, 2023

I use salsa-2022 to create my own programming language https://github.com/xiyuzhai-husky-lang/husky, and I construct a salsa db struct for almost every crate. Now that there are too many crates now, the cargo test time has increased dramatically. My last github push takes 40min to pass the checks.

For example, this is the db for testing in some late stage crate. The macro expands to a thousand lines of code.


#[salsa::db(
    CowordJar,
    husky_vfs::db::VfsJar,
    EntityPathJar,
    husky_token_data::db::TokenDataJar,
    TokenJar,
    AstJar,
    EntitySynTreeJar,
    TomlTokenJar,
    TomlAstJar,
    ManifestAstJar,
    CorgiConfigJar,
    CorgiConfigAstJar,
    // linkage
    husky_linkage::db::LinkageJar,
    ManifestJar,
    SynExprJar,
    SynDefnJar,
    SynDeclJar,
    TermPreludeJar,
    DeclarativeTermJar,
    DeclarativeSignatureJar,
    husky_declarative_ty::db::DeclarativeTypeJar,
    EtherealTermJar,
    EtherealSignatureJar,
    FluffyTermJar,
    SemaExprJar,
    husky_hir_ty::db::HirTypeJar,
    husky_hir_eager_expr::db::HirEagerExprJar,
    husky_hir_lazy_expr::db::HirLazyExprJar,
    husky_hir_expr::db::HirExprJar,
    husky_hir_decl::db::HirDeclJar,
    husky_hir_defn::db::HirDefnJar,
    RustTranspilationJar
)]
#[derive(Default)]
pub(crate) struct DB {
    storage: salsa::Storage<Self>,
}

I suggest that there is a dedicated salsa db for testing with no generics so that it needs only to be compiled once instead of being compiled for each individual crate. The Jars type could be something like

type Jars = HashMap<TypeId, Option<Box<dyn ...>>>

so that it's the same for different crates.

It can implement HasJar<SomeJar> by looking up the hashmap using the type id of SomeJar. In theory, this DB is the final object, it implements HasJar<Jar> for any Jar. It would be inefficient in release, but would save tons of compilation time for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant