You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/src/plumbing.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,6 @@ We refer to this as the "plumbing".
7
7
8
8
The plumbing section is broken up into chapters:
9
9
10
-
- The [jars and ingredients](./plumbing/jars_and_ingredients.md) covers how each salsa item (like a tracked function) specifies what data it needs and runtime, and how links between items work.
11
10
- The [database and runtime](./plumbing/database_and_runtime.md) covers the data structures that are used at runtime to coordinate workers, trigger cancellation, track which functions are active and what dependencies they have accrued, and so forth.
12
11
- The [query operations](./plumbing/query_ops.md) chapter describes how the major operations on function ingredients work. This text was written for an older version of salsa but the logic is the same:
13
12
- The [maybe changed after](./plumbing/maybe_changed_after.md) operation determines when a memoized value for a tracked function is out of date.
Copy file name to clipboardExpand all lines: book/src/plumbing/database_and_runtime.md
+4-10Lines changed: 4 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ A salsa database struct is declared by the user with the `#[salsa::db]` annotati
4
4
It contains all the data that the program needs to execute:
5
5
6
6
```rust,ignore
7
-
#[salsa::db(jar0...jarn)]
7
+
#[salsa::db]
8
8
struct MyDatabase {
9
9
storage: Storage<Self>,
10
10
maybe_other_fields: u32,
@@ -28,12 +28,12 @@ The `Snapshot` method returns a `Snapshot<DB>` type, which prevents these clones
28
28
The salsa `Storage` struct contains all the data that salsa itself will use and work with.
29
29
There are three key bits of data:
30
30
31
-
- The `Shared` struct, which contains the data stored across all snapshots. This is primarily the ingredients described in the [jars and ingredients chapter](./jars_and_ingredients.md), but it also contains some synchronization information (a cond var). This is used for cancellation, as described below.
31
+
- The `Shared` struct, which contains the data stored across all snapshots, such as synchronization information (a cond var). This is used for cancellation, as described below.
32
32
- The data in the `Shared` struct is only shared across threads when other threads are active. Some operations, like mutating an input, require an `&mut` handle to the `Shared` struct. This is obtained by using the `Arc::get_mut` methods; obviously this is only possible when all snapshots and threads have ceased executing, since there must be a single handle to the `Arc`.
33
-
- The `Routes` struct, which contains the information to find any particular ingredient -- this is also shared across all handles, and its construction is also described in the [jars and ingredients chapter](./jars_and_ingredients.md). The routes are separated out from the `Shared` struct because they are truly immutable at all times, and we want to be able to hold a handle to them while getting `&mut` access to the `Shared` struct.
33
+
- The `Routes` struct, which contains the information to find any particular ingredient -- this is also shared across all handles. The routes are separated out from the `Shared` struct because they are truly immutable at all times, and we want to be able to hold a handle to them while getting `&mut` access to the `Shared` struct.
34
34
- The `Runtime` struct, which is specific to a particular database instance. It contains the data for a single active thread, along with some links to shared data of its own.
35
35
36
-
## Incrementing the revision counter and getting mutable access to the jars
36
+
## Incrementing the revision counter
37
37
38
38
Salsa's general model is that there is a single "master" copy of the database and, potentially, multiple snapshots.
39
39
The snapshots are not directly owned, they are instead enclosed in a `Snapshot<DB>` type that permits only `&`-deref,
@@ -47,12 +47,6 @@ This allows us to get `&mut` access without any unsafe code and
47
47
guarantees that we have successfully managed to cancel the other worker threads
48
48
(or gotten ourselves into a deadlock).
49
49
50
-
The code to acquire `&mut` access to the database is the `jars_mut` method:
51
-
52
-
```rust
53
-
{{#include../../../src/storage.rs:jars_mut}}
54
-
```
55
-
56
50
The key initial point is that it invokes `cancel_other_workers` before proceeding:
The `maybe_changed_after` operation computes whether a query's value *may have changed***after** the given revision. In other words, `Q.maybe_change_since(R)` is true if the value of the query `Q` may have changed in the revisions `(R+1)..R_now`, where `R_now` is the current revision. Note that it doesn't make sense to ask `maybe_changed_after(R_now)`.
which defines the basic operations that all queries support. The most important are these two:
3
+
The most important basic operations that all queries support are:
10
4
11
5
*[maybe changed after](./maybe_changed_after.md): Returns true if the value of the query (for the given key) may have changed since the given revision.
12
6
*[Fetch](./fetch.md): Returns the up-to-date value for the given K (or an error in the case of an "unrecovered" cycle).
0 commit comments