package querty
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=572518804039bfafdf114a6c6f859250
sha512=0d839b2cba35a5489c5d1bc778d1bcd32d0d932ce9eb76bbbcdf365a96069691ca9cb0997cb73c3add99f621dca637eb4c49835661bdac0f8db8f421a4b4adc1
doc/querty/Querty/Make/index.html
Module Querty.MakeSource
Make (K) builds an engine for the query keys K.
Parameters
Signature
Errors
type derived_key = | D : ('a, derived) K.t -> derived_key(*A derived query key with its value type hidden, so keys of different value types can be listed together in
*)Cycle.
type error = | MissingInput : ('a, input) K.t -> error| Cycle : derived_key list -> error(*A derived query (directly or through others) fetched itself. Carries a path of derived queries that led to the cycle.
The path starts with the query whose fetch closed the cycle and then shows the queries that led to it.
Eg.
*)A <- C <- B <- A
Reasons a run can fail.
Database
Mutable state of the engine: input values, cached derived values with their recorded dependencies, and the current revision. Keep one db and reuse it across runs; that is what makes later runs incremental. Not safe to share between domains.
A fresh database with no inputs set and nothing cached.
rules q computes the value of derived query q. Querty calls it only when q is not cached, or when something q used last time has changed. Rules must be deterministic and get all their inputs through read and fetch: anything else they look at (files, globals, clocks) is invisible to Querty, and changes to it will not trigger a recomputation.
set_input db key v sets input key to v.
If key already has a value equal to v (by QueryKey.values_equal) this does nothing. Otherwise the change is recorded, and the next fetch of each derived query that depends on key will recompute it.
Call it between runs, or from the top-level function passed to run. Do not call it from inside a rule.
remove_input db key removes input key from db. If key is already absent then the function does nothing.
read_input db key returns the current value of input with key. Returns None if it was not set.
Running
run db f runs f (), in which queries may be used, and returns its result.
On error, values computed before the error stay cached, the db remains usable, and a later run (e.g. after setting the missing input) picks up where this one left off.
Exceptions raised by f or rules propagate out of run unchanged.
run_accumulated db key root returns the values of key accumulated by root and by every derived query it fetched, either directly or not.
Same as accumulated but doesn't need to be run inside run.
Querying
All querying functions need to be run inside run. It will raise Effect.Unhandled otherwise.
read key returns the current value of input key. When called from a rule, records key as a dependency of that rule.
Aborts the current run with MissingInput if key was never set.
Must be called inside run; raises Effect.Unhandled otherwise.
accumulate key value accumulates value for the currently running key. It can be used for diagnostics or other auxilarry emitted by derived query.
To read the accumulated values use accumulated.
Must be called inside run; raises Effect.Unhandled otherwise.
accumulated key root returns the values of key accumulated by root and by every derived query it fetched, either directly or not.
Values are in execution order.
When called from a rule, the rule is recomputed whenever the result may have changed, even if no query's value did.
Must be called inside run; raises Effect.Unhandled otherwise.