From b4053ad76bfd3d63e3ddeed15d607177b2e0b9b4 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 4 Aug 2022 01:42:42 -0400 Subject: [PATCH] rename references to memoized to tracked --- book/src/reference/algorithm.md | 14 +++++++------- components/salsa-entity-macros/src/tracked_fn.rs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/book/src/reference/algorithm.md b/book/src/reference/algorithm.md index fcdce3a8..cfbce9c3 100644 --- a/book/src/reference/algorithm.md +++ b/book/src/reference/algorithm.md @@ -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_. diff --git a/components/salsa-entity-macros/src/tracked_fn.rs b/components/salsa-entity-macros/src/tracked_fn.rs index 21f70eb5..c1d97123 100644 --- a/components/salsa-entity-macros/src/tracked_fn.rs +++ b/components/salsa-entity-macros/src/tracked_fn.rs @@ -34,11 +34,11 @@ pub(crate) fn tracked( }) } -type Args = Options; +type Args = Options; -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;