Update "Jars and Ingredients" to reflect the in-place init changes

This commit is contained in:
DropDemBits 2023-06-18 00:13:54 -04:00
parent 5b8412656c
commit f1a141a6c0
No known key found for this signature in database
GPG key ID: D550F8DFBB392533
2 changed files with 5 additions and 5 deletions

View file

@ -195,16 +195,16 @@ The `Default` implementation for `Storage<DB>` does the work:
First, it creates an empty `Routes` instance.
Then it invokes the `DB::create_jars` method.
The implementation of this method is defined by the `#[salsa::db]` macro; it simply invokes the `Jar::create_jar` method on each of the jars:
The implementation of this method is defined by the `#[salsa::db]` macro; it invokes `salsa::plumbing::create_jars_inplace` to allocate memory for the jars, and then invokes the `Jar::init_jar` method on each of the jars to initialize them:
```rust,ignore
{{#include ../../../components/salsa-2022-macros/src/db.rs:create_jars}}
```
This implementation for `create_jar` is geneated by the `#[salsa::jar]` macro, and simply walks over the representative type for each salsa item and asks *it* to create its ingredients
This implementation for `init_jar` is generated by the `#[salsa::jar]` macro, and simply walks over the representative type for each salsa item and asks *it* to create its ingredients
```rust,ignore
{{#include ../../../components/salsa-2022-macros/src/jar.rs:create_jar}}
{{#include ../../../components/salsa-2022-macros/src/jar.rs:init_jar}}
```
The code to create the ingredients for any particular item is generated by their associated macros (e.g., `#[salsa::tracked]`, `#[salsa::input]`), but it always follows a particular structure.

View file

@ -108,7 +108,7 @@ pub(crate) fn jar_impl(
.zip(0..)
.map(|(f, i)| syn::LitInt::new(&format!("{}", i), f.ty.span()))
.collect();
// ANCHOR: create_jar
// ANCHOR: init_jar
quote! {
unsafe impl<'salsa_db> salsa::jar::Jar<'salsa_db> for #jar_struct {
type DynDb = dyn #jar_trait + 'salsa_db;
@ -126,7 +126,7 @@ pub(crate) fn jar_impl(
}
}
}
// ANCHOR_END: create_jar
// ANCHOR_END: init_jar
}
pub(crate) fn jar_struct(input: &ItemStruct) -> ItemStruct {