Commit graph

1050 commits

Author SHA1 Message Date
Niko Matsakis
06e0a04cb3 explain more about rev counter, include snippets 2022-08-18 19:37:59 -04:00
Niko Matsakis
030caa1d21
Update book/src/plumbing/jars_and_ingredients.md
Co-authored-by: Mihail Mihov <mmihov.personal@gmail.com>
2022-08-18 16:21:42 -04:00
Niko Matsakis
57834c553b
Update book/src/plumbing/jars_and_ingredients.md
Co-authored-by: Mihail Mihov <mmihov.personal@gmail.com>
2022-08-18 16:21:38 -04:00
Niko Matsakis
b6aec13b20 explain databases, runtimes, etc 2022-08-18 05:37:22 -04:00
Niko Matsakis
a1a8533cef define how routes are created 2022-08-18 05:15:12 -04:00
Niko Matsakis
5b7dff908d create chapters 2022-08-18 05:02:07 -04:00
Niko Matsakis
5b9da4a9c0 start documenting plumbing 2022-08-17 21:43:06 -04:00
bors[bot]
becaade31e
Merge #350
350: Accumulators r=nikomatsakis a=nikomatsakis

This branch fixes accumulators so they have the right *behavior* -- the implementation leaves something to be desired, though, in that you don't get very good re-use if you are using accumulators from inside tracked functions. Right now that is treated as an untracked read, so if you want to get good re-use you need a workaround like this one...

```rust
#[salsa::tracked(return_ref)]
fn accumulated_values(db: &dyn Db) -> Vec<T> {
    some_query::accumulated::<SomeAccumulator>(db)
}
```

...which would track and compare the new vs old vector and detect when they've changed.


Despite this limitation, this PR makes accumulators behave correctly with respect to the value taht gets returned and is good enough to Fix #313 in my opinion. I'll file an issue for the remaining improvements.

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-08-17 11:57:51 +00:00
Niko Matsakis
70b50a1813 fix formatting 2022-08-17 07:38:03 -04:00
Niko Matsakis
f147ee3917 demonstrate re-use workaround 2022-08-17 06:55:27 -04:00
Niko Matsakis
9df075b63c reset accumulators on new revisions, etc
Accumulators don't currently work across revisions
due to a few bugs. This commit adds 2 tests to show
the problems and reworks the implementation strategy.

We keep track of when the values in an accumulator were pushed
and reset the vector to empty when the push occurs in a new
revision.

We also ignore stale values from old revisions
(but update the revision when it is marked as validated).

Finally, we treat an accumulator as an untracked read,
which is quite conservative but correct. To get better
reuse, we would need to (a) somehow determine when different
values were pushed, e.g. by hashing or tracked the old values;
and (b) have some `DatabaseKeyIndex` we can use to identify
"the values pushed by this query".

Both of these would add overhead to accumulators and I didn'τ
feel like doing it, particularly since the main use case for
them is communicating errors and things which are not typically
used from within queries.
2022-08-17 06:47:11 -04:00
Niko Matsakis
186c915b21 make outputs use DependencyIndex
It turns out that we have some outputs (accumulators) for which
it only makes sense to have a `DependencyIndex` (they don't have
individual keys to identify).
2022-08-17 04:43:25 -04:00
Niko Matsakis
2a9f0f7140 add accumulation test
I can't seem to get it to perform incorrectly lol,
what am I missing.
2022-08-17 04:43:25 -04:00
bors[bot]
c24ab8ffc1
Merge #349
349: GC tracked structs r=nikomatsakis a=nikomatsakis

Extends the system to track when a tracked struct is no longer created in a new revision and eagerly delete data associated with it. It's not a *complete* answer for GC but it seems pretty useful. 

Fix #315 

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-08-16 21:59:48 +00:00
Niko Matsakis
f2a67ae527 update expected logs
input fields no longer generate WillCheckCancellation events
2022-08-16 17:58:51 -04:00
Niko Matsakis
f7f1bb9024 add reset for new revision for input fields 2022-08-16 17:58:00 -04:00
Niko Matsakis
7b99365620 add salsa_struct_deleted for input fields 2022-08-16 17:57:41 -04:00
Niko Matsakis
689751b243 wire up salsa struct seletion, test it
We now delete entities and data associated with them!
Neat!
2022-08-16 17:55:32 -04:00
Niko Matsakis
66ffae1bb9 generalize push to always have a &mut route
We also track whether reset is required at the ingredient level.
For tracked struct fields, we were not using `push_mut`,
and I think that was an oversight.

The plan is to do a "dependent ingredient" interlinking pass
once the database is constructed.
2022-08-16 17:55:32 -04:00
Niko Matsakis
60cdce22e9 track "dependent functions" 2022-08-16 17:55:32 -04:00
bors[bot]
a866e71266
Merge #342
342: Make input setters return old value r=nikomatsakis a=MihailMihov

Added an `InputFieldIngredient` which replaces the `FunctionIngredient` for inputs. The end goal is for the inputs to use an ingredient simpler than `FunctionIngredient` and that would allow us to return the old values when updating an input.

Co-authored-by: Mihail Mihov <mmihov.personal@gmail.com>
2022-08-16 19:26:02 +00:00
Mihail Mihov
07dd72470e Rename compare_and_swap to mutate_in_place 2022-08-14 20:24:57 +03:00
Mihail Mihov
5e79fb42e3 Add "compare and swap" test 2022-08-13 18:22:44 +03:00
Mihail Mihov
11cedfba4f Update methods in InputFieldIngredient 2022-08-13 18:19:37 +03:00
Mihail Mihov
83474bbc53 Fix maybe_changed_after's logic 2022-08-13 13:04:19 +03:00
Mihail Mihov
5fe3c08cb7 Pass the runtime to InputFieldIngredient's fetch 2022-08-13 13:04:19 +03:00
Mihail Mihov
064f26db8f Change QueryInputs to QueryEdges 2022-08-13 13:04:19 +03:00
Mihail Mihov
8e54a9bb3e Report reads in InputFieldIngredient's fetch method. 2022-08-13 13:04:19 +03:00
Mihail Mihov
9b7f7fd4ed Add comments describing InputFieldIngredient
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-08-13 13:04:19 +03:00
Mihail Mihov
11b23c942b Return old value in input setter methods 2022-08-13 13:04:19 +03:00
Mihail Mihov
ec141aceba Replace inputs' FunctionIngredients with InputFieldIngredients 2022-08-13 13:04:19 +03:00
Mihail Mihov
da43bd2ba6 Add InputFieldIngredient 2022-08-13 13:04:19 +03:00
bors[bot]
648248bd39
Merge #347
347: Track outputs and specified fields r=nikomatsakis a=nikomatsakis

This PR implements a new strategy for tracking output edges and specified fields correctly. Core ideas:

* Track the *outputs* of each query Q and not only its inputs. An output is a specified or assigned field, a created entity, or a pushed accumulator.
* When marking a query Q as validated (no need to execute) in a new revision, you mark ALL of its outputs as validated.

Fixes #338.

The PR also includes some commits that lay the groundwork for #313 and #315 (but I left those for a future PR). In particular, it includes the logic to diff outputs to find values that are no longer output by Q. This will be used to delete obsolete entities. (Originally, I was going to use this to clear outdated outputs of all kinds, but I realized that marking them as validated was a better approach.)

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-08-13 05:31:11 +00:00
Niko Matsakis
d80d5308f1 fix annoying formatting problem 2022-08-13 01:28:01 -04:00
Niko Matsakis
b8643a5f70 distinguish fields from other specified values
And make `QueryOrigin` finer grained while we are at it.
2022-08-13 01:21:45 -04:00
Niko Matsakis
e2763aba88 change approach: eagerly verify, don't remove
This approach is more compatible with our overall "pull" result,
and it also means we can get more re-use.
2022-08-13 01:21:45 -04:00
Niko Matsakis
2652f66fc9 messy commit: refactor + add mark_validated_output
I realized I can do this better:

* require that outputs are DatabaseKeyIndex, fewer unwraps,
  more clearly justified
* when we validate result of tracked fn, also validate its outputs
  (this is incompletely implemented, would ideally be separated
  into its own commit, but I'm short for time)

The last step will allow us to keep the memoized results for
assigned values and means we don't have to eagerly clear them.
If we see an "assigned value" that is not verified in the current
revision, it can simply be considered dirty.

We can still delete them when entities are deleted, but they're
less special.
2022-08-13 01:21:45 -04:00
Niko Matsakis
37e7eeb3fd delete stale output values
This fixes the behavior of `specify_tracked_fn_in_rev_1_but_not_2`,
mostly, though I realize now that it is suboptimal.
2022-08-13 01:21:45 -04:00
Niko Matsakis
a3a0f030f6 track the query that assigned the value
We will use this just for asserts, but it seems useful.
2022-08-13 01:21:45 -04:00
Niko Matsakis
af9de5686d delete some dead code, squash wanings 2022-08-13 01:21:45 -04:00
Niko Matsakis
aa88884b51 move "untracked" into the Origin enum
It's a bit of a stretch for the name, but I think the code is cleaner.
2022-08-13 01:21:45 -04:00
Niko Matsakis
0e96d4c1e7 replace edges with origin
We now track whether the value was ASSIGNED or DERIVED.
2022-08-13 01:21:45 -04:00
Niko Matsakis
a58bc82883 create remove_stale_output method on ingredients
but we are not doing anything in it, yet
2022-08-13 01:21:45 -04:00
Niko Matsakis
8accccdbce diff outputs when replacing a memoized value
We don't do anything with this info right now besides log it,
but the logs show we are reporting it at the right times
in the `specify_tracked_fn_in_rev_1_but_not_2` test
(also fix an oversight in the test where it was creating a new input
each time).
2022-08-13 01:21:45 -04:00
Niko Matsakis
c0ac7447c9 track both inputs/outputs for each query
Rename QueryInputs to QueryEdges.
Modify its fields to track both inputs and outputs.
The size of the struct doesn't actually change,
as the separator comes out of padding.
2022-08-13 01:21:45 -04:00
Niko Matsakis
604c182d7b record when specify is called by a user
Pre-declared fields do not need to be recorded,
as they are always specified.
2022-08-13 01:21:45 -04:00
Niko Matsakis
6ad632a747 generalize list of "entities created" to "outputs"
We will record each thing that gets *output* by the query.
We use a btree-set so that we can get a sorted list.
That will allow us to easily compare what is output between revisions.
We will use that to clear stale values.
2022-08-13 01:21:45 -04:00
Niko Matsakis
97e280ddd2 track outputs for the active record 2022-08-13 01:21:45 -04:00
Niko Matsakis
b65207ccbc add broken test for specify
We specify the value for the field in 1 rev but
fail to specify in the next revision. The old value
is (currently) never cleared.
2022-08-13 01:21:45 -04:00
Niko Matsakis
85ea35932c update reference chapter
I'm mostly adding this commit to see if I can trick
git into behaving better.
2022-08-13 01:21:45 -04:00