package querty

Build not yet checked
  1. Overview
  2. Docs
A simple build system for incremental and demand-driven computations

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.2.0.tar.gz
md5=572518804039bfafdf114a6c6f859250
sha512=0d839b2cba35a5489c5d1bc778d1bcd32d0d932ce9eb76bbbcdf365a96069691ca9cb0997cb73c3add99f621dca637eb4c49835661bdac0f8db8f421a4b4adc1

doc/querty/Querty/Make/index.html

Module Querty.MakeSource

Make (K) builds an engine for the query keys K.

Parameters

module K : QueryKey

Signature

Errors

Sourcetype derived_key =
  1. | 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.

    *)
Sourcetype error =
  1. | MissingInput : ('a, input) K.t -> error
    (*

    A rule read an input that was never given a value with set_input. Carries the first such input encountered.

    *)
  2. | 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

Sourcetype db

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.

Sourceval init : rules:('r. ('r, derived) K.t -> 'r) -> db

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.

Sourceval set_input : db -> ('a, input) K.t -> 'a -> unit

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.

Sourceval remove_input : db -> ('a, input) K.t -> unit

remove_input db key removes input key from db. If key is already absent then the function does nothing.

Sourceval read_input : db -> ('a, input) K.t -> 'a option

read_input db key returns the current value of input with key. Returns None if it was not set.

Running

Sourceval run : db -> (unit -> 'a) -> ('a, error) result

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.

Sourceval run_fetch : db -> ('a, derived) K.t -> ('a, error) result

run_fetch db q returns the value of derived query q.

Same as fetch but doesn't need to be run inside run.

Sourceval run_accumulated : db -> ('a, accum) K.t -> ('r, derived) K.t -> ('a list, error) result

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.

Sourceval fetch : ('a, derived) K.t -> 'a

fetch q returns the value of derived query q, recomputing it with the rules given to run only if needed. When called from a rule, records q as a dependency of that rule.

Aborts the current run with Cycle if q is already being computed.

Must be called inside run; raises Effect.Unhandled otherwise.

Sourceval read : ('a, input) K.t -> 'a

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.

Sourceval accumulate : ('a, accum) K.t -> 'a -> unit

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.

Sourceval accumulated : ('a, accum) K.t -> ('b, derived) K.t -> 'a list

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.