Apply suggestions from code review

Co-Authored-By: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
Aleksey Kladov 2019-09-24 12:08:13 +03:00 committed by GitHub
parent a798f1d918
commit 3616014391
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

View file

@ -1,19 +1,19 @@
# Common patterns
## On Demnd (Lazy) Inputs
## On Demand (Lazy) Inputs
Salsa input quries work best if you can easily provide all of the inputs upfront.
However sometimes the set of inputs is not known beforehand.
A typical example is reading files from disk.
While it is possible to eagarly scan a particular directory and create an in-memory file tree in a salsa input query, a more straight forward approach is to read the files lazily.
While it is possible to eagerly scan a particular directory and create an in-memory file tree in a salsa input query, a more straight-forward approach is to read the files lazily.
That is, when someone requests the text of a file for the first time:
1. Read the file from disk and cache it.
2. Setup a file-system watcher for this path.
3. Innvalidate the cached file once the watcher sends a change notification.
3. Invalidate the cached file once the watcher sends a change notification.
This is possible to achive in salsa, using a derived query and `report_synthetic_read` and `invalidate` queries.
This is possible to achieve in salsa, using a derived query and `report_synthetic_read` and `invalidate` queries.
The setup looks roughtly like this:
```rust,ignore

View file

@ -559,7 +559,7 @@ where
/// This causes salsa to re-execute the query function on the next access to
/// the query, even if all dependencies are up to date.
///
/// This is most commonly used for queries with zero inputs.
/// This is most commonly used for invaliding on-demand inputs; see the [Salsa Book](https://salsa-rs.github.io/salsa/) for more information.
pub fn invalidate(&self, key: &Q::Key)
where
Q::Storage: plumbing::DerivedQueryStorageOps<DB, Q>,

View file

@ -396,10 +396,9 @@ where
.report_untracked_read(self.current_revision());
}
/// Fores the durability of the current query to at most `durability`.
/// Acts as though the current query had read an input with the given durability; this will force the current query's durability to be at most `durability`.
///
/// This is mostly useful to lower durability level of derived queries with
/// zero inputs.
/// This is mostly useful to control the durability level for on-demand inputs, as described in [the salsa book](https://salsa-rs.github.io/salsa/).
pub fn report_synthetic_read(&self, durability: Durability) {
self.local_state
.report_synthetic_read(durability);