Commit graph

822 commits

Author SHA1 Message Date
Niko Matsakis
75ee3edd2e introduce Cycle type and use in recovery, errors
The Cycle type gives more structured information and ensures
deterministic ordering of participants within any particular
execution.
2021-10-31 07:21:07 -04:00
Niko Matsakis
3caf965533 limit visibility of CycleError 2021-10-31 06:41:05 -04:00
Niko Matsakis
ea6eedd9a3 test cycles with mixed recovery 2021-10-31 06:35:55 -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
4a1dffe7bc cleanup: move cycle recovery into try_block_on
This is just a refactoring.
2021-10-31 05:39:15 -04:00
Niko Matsakis
f659e1d2dd docs: improve diagram, split gen. code and runtime 2021-10-31 04:30:11 -04:00
Niko Matsakis
5fe48246a9 take take take, that's all you do 2021-10-31 04:14:55 -04:00
Niko Matsakis
d8a792ce60 use RefCell::take 2021-10-31 04:13:42 -04:00
Niko Matsakis
cb00077ebc silence clippy warnings
cargo clippy --fix ftw
2021-10-30 17:20:32 -04:00
Niko Matsakis
a53b1c53f1 put queries on the stack when validating 2021-10-30 11:46:37 -04:00
Niko Matsakis
b0eaa59139 make execute_query take active_query argument 2021-10-30 11:46:37 -04:00
Niko Matsakis
0af2a9fba7 add helper for pushing queries
This permits us to separate pushing on the query stack
from executing the query.
2021-10-30 11:46:30 -04:00
Niko Matsakis
54277d4ad1 remove silly duration parameter 2021-10-30 11:45:18 -04:00
Niko Matsakis
293e103c09 make "maybe changed since" share code with read
It is still *slightly* different from `read`.
This seems to have fixed various bugs.
2021-10-30 11:45:12 -04:00
Niko Matsakis
5adb3c9ab3 add debug methods that carry db 2021-10-30 11:39:50 -04:00
Niko Matsakis
d0c74935c9 break out a helper for executing queries
we're going to use it from maybe_changed_since soon
2021-10-30 11:38:29 -04:00
Niko Matsakis
91ed93a4d4 distinguish no-value from not computed at all
In the case of no-value, we track the revision where
the value was last changed, which will be useful for
maybe-changed-since.
2021-10-30 11:38:29 -04:00
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
0630fb1139 track caller to give better line numbers on test errors 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
2d7a84b4f4 silence lint 2021-10-30 11:27:04 -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
79f8acc3aa improve parallel cycle tests
Before we could not observe the case where:

* thread A is blocked on B
* cycle detected in thread B
* some participants are on thread A and have to be marked

(In particular, I commented out some code that seemed necessary and
didn't see any tests fail)
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
7b9c383eb0 improve parallel cycle tests
They now use signals to guarantee we are testing the code paths
we want to be testing.
2021-10-30 11:15:08 -04:00
Niko Matsakis
b4a04531a9 document what we are testing, rename variables 2021-10-30 11:10:10 -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
Niko Matsakis
40139abc24 enable debug logging in the cycles tests 2021-10-30 11:09:08 -04:00
Niko Matsakis
b72b251240 add should-panic annotations to cycle tests that fail 2021-10-30 11:09:08 -04:00
Aleksey Kladov
0f3bc72ec0 Add tests for "dynamic" cycles
If I am not in an error, all current tests uses "static" cycles -- a
cycle always present. Let's spice that up by adding conditional cycles:
cycles that appear only for specific impls
2021-10-30 11:09:05 -04:00