Commit graph

93 commits

Author SHA1 Message Date
Niko Matsakis
c0d9070a64 refactor _mut path to not take arc
Instead of grabbing the arc, just pass back an `&mut Runtime`.

The eventual goal is to get rid of the lock on the `set` pathway
altogether, but one step at a time.
2022-01-21 13:52:43 -05:00
Niko Matsakis
82d695b9a7 extract hashing definitions into a utility module 2022-01-21 13:49:50 -05:00
bors[bot]
2709ee4d10
Merge #288 #289
288: Make with_incremented_revision take FnOnce r=nikomatsakis a=mheiber

Removes a bug vector, since this function would
panic if the closure is used more than once.

iuc, the code opted out of the compiler's checks
before via a clever `.take()`.

Another change is to take the closure by value
rather than by reference. The monomorphization
seems harmless, since `with_incremented_revision`
is only called from two places.

289: Remove ': salsa::Database' bound from two examples r=nikomatsakis a=mheiber

Two examples had a superfluous bound
': salsa::Database' that wasn't present
in the `compiler` example and doesn't seem to be needed.

The `query_group` macro adds this bound
automatically.

This change can lead to a trailing `+` in
the bounds list. I verified this is OK by
running the examples and verifying that the production
is allowed
[per the Rust Reference](https://doc.rust-lang.org/reference/trait-bounds.html)

Co-authored-by: Maxwell Elliot Heiber <mheiber@fb.com>
2022-01-21 18:35:51 +00:00
Maxwell Elliot Heiber
befa3ddef5 Make with_incremented_revision take FnOnce
The function is morally an FnOnce, since if
called multiple times the function will panic.

iuc, the code opted out of the compiler's checks
before via a clever `.take()`.

Another change is to take the closure by value
rather than by reference. The monomorphization
seems harmless, since `with_incremented_revision`
is only called from two places.
2021-12-30 10:44:35 +00:00
Niko Matsakis
fc020de9c4 s/maybe_changed_since/maybe_changed_after/ 2021-11-13 16:39:41 -05:00
Niko Matsakis
961599aa39 unwind from "block on" for panic/cancellation
We still record the same dependencies (or else the tests fail,
so +1 for test coverage).

This has the immediate advantage that we don't invoke the fallback
function twice for the repeated node in the cycle.

Also, fix a bug where revalidating cycles could lead to a
CycleParticipant error that is not caught (added a test for it).
2021-11-08 08:07:45 -05:00
Niko Matsakis
3f95c0b4a0 panic when recovering from a cycle
It turns out this is necessary, as this test reveals!
If we don't panic, you might encounter further cycles
that aren't supposed to have executed. (Prior to these changes,
this test was panicking from the second cycle.)
2021-11-01 10:10:50 -04:00
Niko Matsakis
61599cc81a report unexpected cycles using Cancelled
The `Cancelled` struct now reflects multiple potential reasons
for a query execution to be cancelled, including unexpected cycles.
It also gives information about the participants that lacked
recovery information.
2021-10-31 06:18:50 -04:00
Niko Matsakis
5bd2cbcb20 remove unnecessary type argument K 2021-10-30 11:37:21 -04:00
Niko Matsakis
187bd54fa9 move CycleError to plumbing 2021-10-30 11:27:01 -04:00
Niko Matsakis
e49088644d introduce cycle_recovery_strategy function
Find the cycle recovery strategy for a given DatabaseKey.
2021-10-30 11:09:24 -04:00
Niko Matsakis
f7dd6b3219 remove tracing garbage collection support
It is not widely used and it makes it harder to evolve Salsa.
2021-06-06 06:06:03 -04:00
Jonas Schievink
458266e1cd Move unwind_if_cancelled to Database 2021-05-25 15:34:57 +02:00
Jonas Schievink
1fb660c33e Use the more common spelling of cancell{ed,ation} 2021-05-25 15:08:23 +02:00
Jonas Schievink
197b01fa4b Implement "opinionated cancellation" 2021-05-17 18:59:28 +02:00
Niko Matsakis
2e2239a307
Merge pull request #242 from Marwes/lift_static_restriction
feat: Allow the dynamic db to be non-static
2020-09-09 10:52:50 -04:00
Markus Westerlind
ce6428fbbd Lift the static restriction on the traits 2020-07-23 11:34:20 +02:00
Aleksey Kladov
5f53837458 Add purge method
This is mostly useful for debugging, rust-analyzer uses it to measure
memory usage of tables
2020-07-22 18:41:53 +02:00
Niko Matsakis
fad97eeb6a remove the DB parameter
This had two unexpected consequences, one unfortunate, one "medium":

* All `salsa::Database` must be `'static`. This falls out from
`Q::DynDb` not having access to any lifetimes, but also the defaulting
rules for `dyn QueryGroup` that make it `dyn QueryGroup + 'static`. We
don't really support generic databases anyway yet so this isn't a big
deal, and we can add workarounds later (ideally via GATs).

* It is now statically impossible to invoke `snapshot` from a query,
and so we don't need to test that it panics. This is because the
signature of `snapshot` returns a `Snapshot<Self>` and that is not
accessible to a `dyn QueryGroup` type. Similarly, invoking
`Runtime::snapshot` directly is not possible becaues it is
crate-private. So I removed the test. This seems ok, but eventually I
would like to expose ways for queries to do parallel
execution (matklad and I had talked about a "speculation" primitive
for enabling that).

* This commit is 99% boilerplate I did with search-and-replace. I also
rolled in a few other changes I might have preferred to factor out,
most notably removing the `GetQueryTable` plumbing trait in favor of
free-methods, but it was awkward to factor them out and get all the
generics right (so much simpler in this version).
2020-07-04 14:17:11 +00:00
Niko Matsakis
d64dfa1727 make for_each_query dyn-safe 2020-07-04 14:17:11 +00:00
Niko Matsakis
c6663f3dcb return durability of modified data and remove SharedStateWriteGuard
Now the `with_incremented_revision` method signature does not
reference the database DB in any way.
2020-07-04 14:16:50 +00:00
Niko Matsakis
705a35d4b7 pass 'new revision' as an explicit argument
The goal is to eliminate the "shared state guard" argument, which
currently requires access to the database.
2020-07-04 14:16:50 +00:00
Niko Matsakis
d71a7a2751 make with_incremented_revision dyn-safe 2020-07-04 14:16:50 +00:00
Niko Matsakis
1b778760ae track and report cycles using DatabaseKeyIndex 2020-07-04 14:16:50 +00:00
Niko Matsakis
7b5ac6e717 implement ability to get readable debug output for DatabaseKeyIndex 2020-07-04 14:16:50 +00:00
Niko Matsakis
07623fb962 remove the DatabaseData and associated unsafe code 2020-07-04 14:16:50 +00:00
Niko Matsakis
f7a14f2309 use DatabaseKeyIndex instead of Dependency 2020-07-04 14:16:49 +00:00
Niko Matsakis
a45087a322 compute database-key-index for input slots 2020-07-04 14:16:14 +00:00
Niko Matsakis
206c086bac thread group index to storage initializers 2020-07-04 14:16:14 +00:00
Niko Matsakis
b0710416d0 require &mut self for with_incremented_revision 2019-09-27 05:54:42 -04:00
Niko Matsakis
0a94efeac3 emit WillChangeInputValue before new revision (breaking change!)
Otherwise we need to borrow the `db` in `with_incremented_revision`
and it's a pain.
2019-09-27 05:51:27 -04:00
Markus Westerlind
897ee5f3d2 cargo fmt 2019-08-21 10:13:08 +02:00
Markus Westerlind
0e01067d55 feat: Allow queries to avoid panics on cycles
Quickest POC I could create to get some potentially cyclic queries to
not panic and instead return a result I could act on. (gluon's module
importing need to error on cycles).

```
// Causes `db.query()` to actually return `Result<V, CycleError>`
fn query(&self, key: K, key2: K2) -> V;
```

A proper implementation of this would likely return
`Result<V, CycleError<(K, K2)>>` or maybe larger changes are needed.

cc #6
2019-08-16 20:37:54 +02:00
Niko Matsakis
ae9ab75384
Merge pull request #183 from matklad/no-clone
remove needless clone
2019-08-15 07:01:34 -04:00
Niko Matsakis
485df37e6f make durability helper panic on an undefined key 2019-07-05 06:06:29 -04:00
Niko Matsakis
d4f7e4b2b4 improve comment 2019-07-05 06:05:18 -04:00
Niko Matsakis
346ce6bc16 remove set_common helper and merge into set 2019-07-05 06:01:55 -04:00
Niko Matsakis
06ad8c7930 merge set and set_with_durability in plumbing trait 2019-07-05 06:01:17 -04:00
Niko Matsakis
8d30df0a0f log durability 2019-07-05 06:00:21 -04:00
Niko Matsakis
6252430a91
Update src/input.rs
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-07-05 05:52:36 -04:00
Aleksey Kladov
1faa9d6016 remove needless clone 2019-07-04 15:20:27 +03:00
Niko Matsakis
a0a6bac5af modify public API to set_foo_with_durability 2019-07-02 07:49:01 -04:00
Niko Matsakis
09c9bd9761 adjust public api from is_constant to durability 2019-07-02 07:49:01 -04:00
Niko Matsakis
880b29a640 move durability to its own module and make part of public API 2019-07-02 07:49:01 -04:00
Niko Matsakis
8b7808c6ae eliminate a built-in notion of constant durability 2019-07-02 07:49:01 -04:00
Niko Matsakis
c756d98fbb move revision code to its own module, introduce AtomicRevision
pure refactoring
2019-07-02 07:49:01 -04:00
Niko Matsakis
5bbd500c64 switch internally from IsConstant to Durability 2019-07-02 07:49:01 -04:00
Niko Matsakis
21a70b6eb0 use a newtype'd IsConstant for better readability
Random bool constants are just so gauche.
2019-07-02 07:49:01 -04:00
Niko Matsakis
30714022fd kill the ChangedAt struct
It didn't seem like it was buying us much.
2019-07-02 07:49:01 -04:00
Niko Matsakis
0a5b6b0451 permit constants to be modified
We now track the last revision in which constants were modified. When
we see a constant query result, we record the current revision as
well. Then later we can check if the result is "still" constant. This
lets us cut out a lot of intermediate work.
2019-07-02 07:49:01 -04:00