Commit graph

478 commits

Author SHA1 Message Date
Niko Matsakis
e7a8abc648 distinguish stale vs absent
The goal is to make `probe` usable for both "maybe changed since" and
reading the final value.
2021-10-30 11:38:29 -04:00
Niko Matsakis
dc5ea932ef WaitResult can just be panicked|completed now 2021-10-30 11:38:27 -04:00
Niko Matsakis
de7ac896bc put cycle participants into an arc
Because it bugs me to clone the vector.

Maybe silly, I admit, since cycle recovery
is not the hot path.

But by that same token, we now spend only 1 word
for a null pointer instead of 4 words for a (usually empty) vector.
2021-10-30 11:37:23 -04:00
Niko Matsakis
5bd2cbcb20 remove unnecessary type argument K 2021-10-30 11:37:21 -04:00
Niko Matsakis
35ddd36b49 move the stack instead of cloning
Currently, when one thread blocks on another, we clone the
stack from that task. This results in a lot of clones, but it also
means that we can't mark all the frames involved in a cycle atomically.
Instead, when we propagate information between threads, we also
propagate the participants of the cycle and so forth.

This branch *moves* the stack into the runtime while a thread
is blocked, and then moves it back out when the thread resumes.
This permits the runtime to mark all the cycle participants at once.
It also avoids cloning.
2021-10-30 11:35:04 -04:00
Niko Matsakis
e83bae717d have runtime coordinate blocking
Instead of creating a future for each edge
in the graph, we now have all dependent queries
block in the runtime and wake up whenever results
are published to see if their results are ready.

We could certainly allocate a CondVar for each dependent
query if we found that spurious wakeups were a problem.
I consider this highly unlikely in practice.
2021-10-30 11:32:56 -04:00
Niko Matsakis
3c094d2932 midpoint: make runtime take wait-result
Thi sis an intermediate step towards having the runtime
coordinate wakeups.
2021-10-30 11:31:18 -04:00
Niko Matsakis
21cb4ef9d6 move WaitResult to runtime
We are going to make it so that the runtime
coordinates delivery of the WaitResults.
2021-10-30 11:31:16 -04:00
Niko Matsakis
f5a15e55c6 rework the dep-graph API to take the lock
This will allow me to add condvar logic to it
2021-10-30 11:30:21 -04:00
Niko Matsakis
213e16f4ee remove explicit Default impl 2021-10-30 11:30:21 -04:00
Niko Matsakis
ba6165726b rename labels to query_dependents 2021-10-30 11:30:21 -04:00
Niko Matsakis
ec38398991 extract the depends_on helper function
Make `add_edge` infallible
2021-10-30 11:30:21 -04:00
Niko Matsakis
e870d02da1 make the dep-graph not generic
Being generic over the keys made code harder to read.
2021-10-30 11:30:21 -04:00
Niko Matsakis
da188fe609 extract DependencyGraph into its own module 2021-10-30 11:30:12 -04:00
Niko Matsakis
66b26f07c2 introduce Retry probe result
Instead of sending the result back, just have the waiting threads retry
reading the cache.
2021-10-30 11:27:04 -04:00
Niko Matsakis
eb1e06d61d fix typo that's always bugging me 2021-10-30 11:27:04 -04:00
Niko Matsakis
0298163211 move CycleError to the plumbing module 2021-10-30 11:27:04 -04:00
Niko Matsakis
187bd54fa9 move CycleError to plumbing 2021-10-30 11:27:01 -04:00
Niko Matsakis
42a653ca6f use computed recovery strategy
Rather than checking return value of from `Q::cycle_fallback`, we
now consult the computed recovery strategy to decide whether to
panic or to recover. We can thus assume that we will successfully
recover and don't need to check for `None` results anymore.
2021-10-30 11:19:09 -04:00
Niko Matsakis
bcffa4a836 find cycle recovery strategy for a given cycle 2021-10-30 11:10:07 -04:00
Niko Matsakis
fc826b0689 add cycle_recovery_strategy function on database 2021-10-30 11:09:24 -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
853006fccf isolate find_cycle_participants into its own fn 2021-10-30 11:09:24 -04:00
Niko Matsakis
d082270610 introduce CYCLE_STRATEGY constant for queries
This allows us to figure out whether a query can recover
from a cycle (and how) without invoking the `recover`
function.
2021-10-30 11:09:24 -04:00
Niko Matsakis
7b4ee6fc34 improve panic error message 2021-10-30 11:09:08 -04:00
Jonas Schievink
8f0b9b7f82 Fix invalidate and report_synthetic_read 2021-09-03 23:35:15 +02:00
Tim Robinson
fc6806a07c CI runs Clippy 2021-06-17 15:21:51 +01:00
bors[bot]
5c20caaab4
Merge #268
268: Expose proc macro docs via the main crate r=nikomatsakis a=1tgr

Improve visibility by placing the `database` and `query_group` proc macros at the bottom of the main docs page, instead of manually browsing to the docs for the `salsa-macros` crate.

Co-authored-by: Tim Robinson <tim.g.robinson@gmail.com>
2021-06-17 13:40:35 +00:00
Tim Robinson
de030b0a69 CI runs cargo fmt in check mode 2021-06-16 19:26:16 +01:00
Tim Robinson
c6e4b23c71 Expose proc macro docs via the main crate 2021-06-16 09:50:05 +01:00
Niko Matsakis
d178d1b765 update a few comments that mention gc 2021-06-06 06:20:23 -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
b9fc82969f Mention that salsa_event should be used instead 2021-05-27 14:23:30 +02: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
018658b450 Explain why we don't duplicate panics from other threads 2021-05-19 18:32:16 +02:00
Jonas Schievink
bb4b42acf1 Retain original import style 2021-05-18 16:08:43 +02:00
Jonas Schievink
223f87bb18 Canonicalize to US spelling of "cancelation" 2021-05-18 15:36:43 +02:00
Jonas Schievink
877d3f20d1 Remove on_propagated_panic 2021-05-18 15:20:13 +02:00
Jonas Schievink
5ac74aba04 Add a cancelation check callback to the runtime 2021-05-18 15:20:13 +02:00
Jonas Schievink
49a1184bcf Improve Canceled API 2021-05-18 14:41:45 +02:00
Jonas Schievink
197b01fa4b Implement "opinionated cancellation" 2021-05-17 18:59:28 +02:00
Jonas Schievink
08c7a6bd63 Include user-readable query keys in cycle errors 2021-05-06 19:56:05 +02:00
Jonas Schievink
dae31a9bb7 Log MemoInputs in human-readable form 2021-05-05 15:34:58 +02:00
Andrew Hickman
b275d36adf Allow using a borrowed key in DerivedQueryStorageOps::invalidate 2020-09-24 14:35:52 +03: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
Niko Matsakis
2084b99ba4
Merge pull request #240 from matklad/purge
Add purge method
2020-07-31 14:17:00 -04:00
Markus Westerlind
3a84a77ebc Remove some unnecessary changes 2020-07-24 11:23:41 +02:00
Markus Westerlind
e2ab6c8bfa feat: Allow the dynamic db to be non-static 2020-07-23 17:08:06 +02:00
Aleksey Kladov
35a420d0c0 Remove LRU distribution tests
They are ignored and in the git history anyway.
2020-07-23 11:36:38 +02:00
Markus Westerlind
ce6428fbbd Lift the static restriction on the traits 2020-07-23 11:34:20 +02:00
Aleksey Kladov
b460db700a Switch from rand to oorandom
The primary motivation here is reducing dependencies. rand has quite a
few of them, and many come from `getrandom` crate (bindings to system
APIs to get true randomness). Some of `getrandom` crates don't have
Apache 2.0 OR MIT license, and it probably doesn't make sense to make
salsa's licensing situation more complicated for feature we don't even
use.

There's a number of small&fast random crates there:

* randomize
* oorandom
* fastrand

I've picked oorandom because it was the simplest & smallest (doesn't
have a thread_local RNG, for example).
2020-07-23 11:30:23 +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
b00981935a fix doc tests 2020-07-07 09:59:57 +00:00
Niko Matsakis
b66eb81311 experiment: extract some Memo code to be independent from Q
This should enable more sharing and less monomorphization. There is
probably room for more radical restructing in this vein.
2020-07-06 00:55:01 +00: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
0e5366df5d move to QueryType.in_db(&db) instead of db.query(QueryType)
This will be more compatible once we move to having queries have an
associated `DynDb` type. It also reads nicely.
2020-07-04 14:17:11 +00:00
Niko Matsakis
7a5b515279 make DatabaseStorageTypes have supertrait of Database 2020-07-04 14:17:11 +00:00
Niko Matsakis
12f54d66f4 move query/query-mut to DatabaseQueryExt 2020-07-04 14:17:11 +00:00
Niko Matsakis
28b642e8c0 make DB ?Sized on execute_query_implementation helper 2020-07-04 14:17:11 +00:00
Niko Matsakis
d1fe9950c5 simplify salsa_event and make it dyn-safe 2020-07-04 14:17:11 +00:00
Niko Matsakis
67687376ed implement the Storage<DB> change 2020-07-04 14:17:10 +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
64f3eb96a1 remove GroupKey associated type 2020-07-04 14:16:50 +00:00
Niko Matsakis
1a07944efe remove DatabaseKey associated type 2020-07-04 14:16:50 +00:00
Niko Matsakis
799ddce157 remove unused GroupData associated type 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
5a1bf10ba6 add a query_name associated constant 2020-07-04 14:16:50 +00:00
Niko Matsakis
b4c6e69faf rewrite get_cycle_path to push to a vector 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
29b6b833d1 compute database-key-index for interned fields 2020-07-04 14:16:14 +00:00
Niko Matsakis
a45087a322 compute database-key-index for input slots 2020-07-04 14:16:14 +00:00
Niko Matsakis
ed1632d151 compute database-key-index for derived slots 2020-07-04 14:16:14 +00:00
Niko Matsakis
8664e7e43c add database-key-index type 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
Jonas Schievink
786168fc99 Simplify collect call 2020-07-03 19:30:23 +02:00
Jonas Schievink
e2569e7afc Use a boxed slice to store dependencies 2020-07-03 19:26:38 +02:00
Aleksey Kladov
9c7ac995d8 Make salsa buildable on power
rust-analyzer fails in rust-lang/rust repo on the power target,
because it doesn't have `AtomicU64`. So, lets just use `AtomicUsize`
as a revision number.

Semantically this is wrong, as we are not using revision to address
arrays, but, practically, it's a nice compromise to build on targets
without AtomicU64 and to have large revision numbers on most relevant
targets.
2020-07-03 16:27:19 +02:00
Aleksey Kladov
a6b162aba1 Replace mpsc channels with hand-written future implementation
cargo llvm-lines shows that some amount of llvm lines is spend on
`std::mpsc`. Given that this is not the most loved standard library
module, and that our usage of mpsc is extremely limited, it seems
worth-while to implement oneshot channel using parking_lot.
2020-07-02 01:17:52 +02:00
Markus Westerlind
380306930b feat: Prune unnecessary dependencies
Only AtomicCell is used from crossbeam and SmallRng from rand so we can
easily disable the default features
2020-07-01 22:42:07 +02:00
Laurențiu Nicola
cfb4e18eba Remove workaround for parking_lot#101 2020-06-27 13:59:29 +03:00
Laurențiu Nicola
2bf383861b Fix doctest 2020-06-27 12:46:24 +02:00
Laurențiu Nicola
bb1c308380 Revert "Bump parking_lot and remove workaround"
This reverts commit 025c882cbb.
2020-06-27 12:46:24 +02:00
Laurențiu Nicola
c627cda525 Bump parking_lot and remove workaround 2020-06-27 12:46:24 +02:00
Niko Matsakis
dd60d91e75 disable fragile LRU tests for now 2020-06-24 14:16:32 +00:00
Michal Terepeta
97ed750a9d Update some comments in slot.rs
Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
2020-01-13 12:10:26 +01:00
Declan Kelly
564fa155d4 Correct mutability in on demand example, fix doc links
Fix query_mut documentation link

Fix more documentation links

More doc links
2019-10-05 18:30:42 -07:00
Laurențiu Nicola
c99580ba14 implement QueryTable constructor manually 2019-10-03 19:26:20 +03:00
Niko Matsakis
b0710416d0 require &mut self for with_incremented_revision 2019-09-27 05:54:42 -04:00
Niko Matsakis
236c2eae84 require &mut self for QueryTableMut methods (breaking) 2019-09-27 05:54:10 -04:00
Niko Matsakis
1715d44555 store &mut DB in QueryTableMut 2019-09-27 05:53:16 -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
Niko Matsakis
8c133e7a4d make synthetic_write require &mut self (breaking change!)
This was an oversight before -- the current type implies that
one introduce a synthetic write (and hence a new revision) from
a `Frozen<DB>`! Not cool.
2019-09-27 05:50:16 -04:00
Niko Matsakis
b9f00726da introduce Database::salsa_runtime_mut method (breaking change!) 2019-09-27 05:49:15 -04:00
Niko Matsakis
c789219bc5 move query-storage into an Arc
This way, we can hold a reference to it without borrowing the database.
2019-09-27 05:34:33 -04:00