Skip to content

Commit e7e1a20

Browse files
committed
minor edits
1 parent 4e34e79 commit e7e1a20

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/queries/salsa.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
This chapter is based on the explanation given by Niko Matsakis in this
66
[video](https://www.youtube.com/watch?v=_muY4HjSqVw) about
7-
[`Salsa`](https://github.com/salsa-rs/salsa). To find out more you may
8-
want to watch [`Salsa` In More
7+
[Salsa](https://github.com/salsa-rs/salsa). To find out more you may
8+
want to watch [Salsa In More
99
Depth](https://www.youtube.com/watch?v=i_IhACacPRY), also by Niko
1010
Matsakis.
1111

12-
> As of <!-- date-check --> November 2022, although `Salsa` is inspired by (among
13-
> other things) `rustc`'s query system, it is not used directly in `rustc`. It
14-
> _is_ used in [chalk], an implementation of Rust's `trait` system, and
12+
> As of <!-- date-check --> November 2022, although Salsa is inspired by (among
13+
> other things) rustc's query system, it is not used directly in rustc. It
14+
> _is_ used in [chalk], an implementation of Rust's trait system, and
1515
> extensively in [`rust-analyzer`], the official implementation of the language
1616
> server protocol for Rust, but there are no medium or long-term concrete
1717
> plans to integrate it into the compiler.
@@ -21,46 +21,46 @@ Matsakis.
2121

2222
## What is Salsa?
2323

24-
`Salsa` is a library for incremental recomputation. This means it allows reusing
24+
Salsa is a library for incremental recomputation. This means it allows reusing
2525
computations that were already done in the past to increase the efficiency
2626
of future computations.
2727

28-
The objectives of `Salsa` are:
28+
The objectives of Salsa are:
2929
* Provide that functionality in an automatic way, so reusing old computations
3030
is done automatically by the library.
3131
* Doing so in a "sound", or "correct", way, therefore leading to the same
3232
results as if it had been done from scratch.
3333

34-
`Salsa`'s actual model is much richer, allowing many kinds of inputs and many
35-
different outputs. For example, integrating `Salsa` with an IDE could mean that
34+
Salsa's actual model is much richer, allowing many kinds of inputs and many different outputs.
35+
For example, integrating Salsa with an IDE could mean that
3636
the inputs could be manifests (`Cargo.toml`, `rust-toolchain.toml`), entire
3737
source files (`foo.rs`), snippets and so on. The outputs of such an integration
3838
could range from a binary executable, to lints, types (for example, if a user
3939
selects a certain variable and wishes to see its type), completions, etc.
4040

4141
## How does it work?
4242

43-
The first thing that `Salsa` has to do is identify the "base inputs" that
43+
The first thing that Salsa has to do is identify the "base inputs" that
4444
are not something computed but given as input.
4545

46-
Then `Salsa` has to also identify intermediate, "derived" values, which are
46+
Then Salsa has to also identify intermediate, "derived" values, which are
4747
something that the library produces, but, for each derived value there's a
4848
"pure" function that computes the derived value.
4949

5050
For example, there might be a function `ast(x: Path) -> AST`. The produced
5151
Abstract Syntax Tree (`AST`) isn't a final value, it's an intermediate value
5252
that the library would use for the computation.
5353

54-
This means that when you try to compute with the library, `Salsa` is going to
54+
This means that when you try to compute with the library, Salsa is going to
5555
compute various derived values, and eventually read the input and produce the
5656
result for the asked computation.
5757

58-
In the course of computing, `Salsa` tracks which inputs were accessed and which
58+
In the course of computing, Salsa tracks which inputs were accessed and which
5959
values are derived. This information is used to determine what's going to
6060
happen when the inputs change: are the derived values still valid?
6161

6262
This doesn't necessarily mean that each computation downstream from the input
63-
is going to be checked, which could be costly. `Salsa` only needs to check each
63+
is going to be checked, which could be costly. Salsa only needs to check each
6464
downstream computation until it finds one that isn't changed. At that point, it
6565
won't check other derived computations since they wouldn't need to change.
6666

@@ -76,7 +76,7 @@ J <- B <--+
7676

7777
When an input `I` changes, the derived value `A` could change. The derived
7878
value `B`, which does not depend on `I`, `A`, or any value derived from `A` or
79-
`I`, is not subject to change. Therefore, `Salsa` can reuse the computation done
79+
`I`, is not subject to change. Therefore, Salsa can reuse the computation done
8080
for `B` in the past, without having to compute it again.
8181

8282
The computation could also terminate early. Keeping the same graph as before,
@@ -86,18 +86,18 @@ computation. This leads to an "early termination", because there's no need to
8686
check if `C` needs to change, since both `C` direct inputs, `A` and `B`,
8787
haven't changed.
8888

89-
## Key `Salsa` concepts
89+
## Key Salsa concepts
9090

9191
### Query
9292

93-
A query is some value that `Salsa` can access in the course of computation. Each
93+
A query is some value that Salsa can access in the course of computation. Each
9494
query can have a number of keys (from 0 to many), and all queries have a
9595
result, akin to functions. `0-key` queries are called "input" queries.
9696

9797
### Database
9898

9999
The database is basically the context for the entire computation, it's meant to
100-
store `Salsa`'s internal state, all intermediate values for each query, and
100+
store Salsa's internal state, all intermediate values for each query, and
101101
anything else that the computation might need. The database must know all the
102102
queries the library is going to do before it can be built, but they don't need
103103
to be specified in the same place.
@@ -116,14 +116,14 @@ potentially invalidated.
116116

117117
A query group is a set of queries which have been defined together as a unit.
118118
The database is formed by combining query groups. Query groups are akin to
119-
"`Salsa` modules".
119+
"Salsa modules".
120120

121-
A set of queries in a query group are just a set of methods in a `trait`.
121+
A set of queries in a query group are just a set of methods in a trait.
122122

123-
To create a query group a `trait` annotated with a specific attribute
123+
To create a query group a trait annotated with a specific attribute
124124
(`#[salsa::query_group(...)]`) has to be created.
125125

126-
An argument must also be provided to said attribute as it will be used by `Salsa`
126+
An argument must also be provided to said attribute as it will be used by Salsa
127127
to create a `struct` to be used later when the database is created.
128128

129129
Example input query group:
@@ -166,7 +166,7 @@ pub trait Parser: Inputs {
166166

167167
When creating a derived query the implementation of said query must be defined
168168
outside the trait. The definition must take a database parameter as an `impl
169-
Trait` (or `dyn Trait`), where `Trait` is the query group that the definition
169+
Trait` (or `dyn Trait`), where trait is the query group that the definition
170170
belongs to, in addition to the other keys.
171171

172172
```rust,ignore

0 commit comments

Comments
 (0)