mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-14 17:18:20 +00:00
A generic framework for on-demand, incrementalized computation. Inspired by adapton, glimmer, and rustc's query system.
d4a94fbf07
440: Change the constructor of `salsa::Id` to const fn r=XFFXFF a=Y-Nak This change is motivated to allow interned structs to have default const instances and prefill them in db initialization. A specific example is managing symbols as a salsa interned struct in a compiler implementation. By declaring keywords as `const` symbols, we can handle keywords without going through their internal representation as rustc does (ref: [rustc_span::symbol](https://github.com/rust-lang/rust/blob/master/compiler/rustc_span/src/symbol.rs)). Conceptually, it'd look like the one below. ```rust #[salsa::interned] pub struct Symbol { data: String, } const SELF_SYM: Symbol = Symbol(salsa::Id::from_u32(1)) ... /// This function is called in db initialization. fn prefill(db: &dyn HirDb) { Symbol::new(db, "self".to_string()); ... } ``` Co-authored-by: Yoshitomo Nakanishi <yurayura.rounin.3@gmail.com> |
||
---|---|---|
.github/workflows | ||
book | ||
components | ||
examples | ||
examples-2022 | ||
salsa-2022-tests | ||
src | ||
tests | ||
.dir-locals.el | ||
.gitignore | ||
bors.toml | ||
Cargo.toml | ||
FAQ.md | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md | ||
RELEASES.md | ||
rustfmt.toml |
salsa
A generic framework for on-demand, incrementalized computation.
Obligatory warning
Very much a WORK IN PROGRESS at this point. Ready for experimental use but expect frequent breaking changes.
Credits
This system is heavily inspired by adapton, glimmer, and rustc's query system. So credit goes to Eduard-Mihai Burtescu, Matthew Hammer, Yehuda Katz, and Michael Woerister.
Key idea
The key idea of salsa
is that you define your program as a set of
queries. Every query is used like function K -> V
that maps from
some key of type K
to a value of type V
. Queries come in two basic
varieties:
- Inputs: the base inputs to your system. You can change these whenever you like.
- Functions: pure functions (no side effects) that transform your inputs into other values. The results of queries are memoized to avoid recomputing them a lot. When you make changes to the inputs, we'll figure out (fairly intelligently) when we can re-use these memoized values and when we have to recompute them.
Want to learn more?
To learn more about Salsa, try one of the following:
- read the heavily commented
hello_world
example; - check out the Salsa book;
- watch one of our videos.
Getting in touch
The bulk of the discussion happens in the issues and pull requests, but we have a zulip chat as well.