rename references to memoized to tracked

This commit is contained in:
Niko Matsakis 2022-08-04 01:42:42 -04:00
parent 91a18114bc
commit b4053ad76b
2 changed files with 10 additions and 10 deletions

View file

@ -8,18 +8,18 @@ The salsa database always tracks a single **revision**. Each time you set an inp
### Basic rule: when inputs change, re-execute!
When you invoke a memoized function, in addition to storing the value that was returned, we also track what _other_ memoized functions it depends on, and the revisions when their value last changed. When you invoke the function again, if the database is in a new revision, then we check whether any of the inputs to this function have changed in that new revision. If not, we can just return our cached value. But if the inputs _have_ changed (or may have changed), we will re-execute the function to find the most up-to-date answer.
When you invoke a tracked function, in addition to storing the value that was returned, we also track what _other_ tracked functions it depends on, and the revisions when their value last changed. When you invoke the function again, if the database is in a new revision, then we check whether any of the inputs to this function have changed in that new revision. If not, we can just return our cached value. But if the inputs _have_ changed (or may have changed), we will re-execute the function to find the most up-to-date answer.
Here is a simple example, where the `parse_module` function invokes the `module_text` function:
```rust
#[salsa::memoized]
#[salsa::tracked]
fn parse_module(db: &dyn Db, module: Module) -> Ast {
let module_text: &String = module_text(db, module);
Ast::parse_text(module_text)
}
#[salsa::memoized(ref)]
#[salsa::tracked(ref)]
fn module_text(db: &dyn Db, module: Module) -> String {
panic!("text for module `{module:?}` not set")
}
@ -47,10 +47,10 @@ parse_module(db, module); // executes again!
### Backdating: sometimes we can be smarter
Often, though, memoized functions don't depend directly on the inputs. Instead, they'll depend on some _processed_ version. For example, perhaps we have a `type_check` function that reads the AST:
Often, though, tracked functions don't depend directly on the inputs. Instead, they'll depend on some other tracked function. For example, perhaps we have a `type_check` function that reads the AST:
```rust
#[salsa::memoized]
#[salsa::tracked]
fn type_check(db: &dyn Db, module: Module) {
let ast = parse_module(db, module);
...
@ -64,7 +64,7 @@ If the module text is changed, we saw that we have to re-execute `parse_module`,
## Durability: an optimization
As an optimization, salsa includes the concept of **durability**. When you set the value of a memoized function, you can also set it with a given _durability_:
As an optimization, salsa includes the concept of **durability**. When you set the value of a tracked function, you can also set it with a given _durability_:
```rust
module_text::set_with_durability(
@ -75,6 +75,6 @@ module_text::set_with_durability(
);
```
For each durability, we track the revision in which _some input_ with that durability changed. If a memoized function depends (transitively) only on high durability inputs, and you change a low durability input, then we can very easily determine that the memoized function result is still valid, avoiding the need to traverse the input edges one by one.
For each durability, we track the revision in which _some input_ with that durability changed. If a tracked function depends (transitively) only on high durability inputs, and you change a low durability input, then we can very easily determine that the tracked function result is still valid, avoiding the need to traverse the input edges one by one.
An example: if compiling a Rust program, you might mark the inputs from crates.io as _high durability_ inputs, since they are unlikely to change. The current workspace could be marked as _low durability_.

View file

@ -34,11 +34,11 @@ pub(crate) fn tracked(
})
}
type Args = Options<Memoized>;
type Args = Options<TrackedFn>;
struct Memoized;
struct TrackedFn;
impl crate::options::AllowedOptions for Memoized {
impl crate::options::AllowedOptions for TrackedFn {
const RETURN_REF: bool = true;
const NO_EQ: bool = true;