Incremental computation library for MoonBit - changes ripple through the dependency graph
let db = @ripple.Database::new()
let rt = db.runtime()
// Define inputs
let source_files : @ripple.Input[String, String] = db.input()
source_files.register(rt)
// Define queries
let parse : @ripple.Query[String, Array[String]] = db.query(
fn(rt, path) {
match source_files.get(rt, path) {
Some(content) => parse_imports(content)
None => []
}
}
)
parse.register(rt)
// Set inputs and run queries
source_files.set(rt, "a.mbt", "import b") |> ignore
let result = parse.fetch(rt, "a.mbt") // ["b"]
// Change input - only affected queries recompute
source_files.set(rt, "a.mbt", "import b, c") |> ignore
let result2 = parse.fetch(rt, "a.mbt") // ["b", "c"] - recomputedfn[K : Hash, Q, V] Accumulator::clear_for_query(self : Accumulator[V], query : Query[K, Q], key : K) -> Unitfn[K : Hash, Q, V] Accumulator::get_for_cycle_query(self : Accumulator[V], query : CycleQuery[K, Q], key : K) -> Array[V]fn[K : Hash, Q, V] Accumulator::get_for_query(self : Accumulator[V], query : Query[K, Q], key : K) -> Array[V]type ActiveQueryfn ActiveQuery::add_edge(self : ActiveQuery, ingredient_index : Int, key_index : Int, changed_at : Revision, durability : Durability) -> Unittype CycleMemo[V]pub struct CycleQuery[K, V] {
ingredient_index : Int
compute : (Runtime, K) -> V
memos : HashMap[K, CycleMemo[V]]
hash_to_key : HashMap[Int, K]
strategy : CycleStrategy[K, V]
}fn[K : Hash + Eq, V] CycleQuery::maybe_changed_after(self : CycleQuery[K, V], key : K, revision : Revision) -> Boolfn[K, V] CycleQuery::new_with_fallback(ingredient_index : Int, compute : (Runtime, K) -> V, fallback : V) -> CycleQuery[K, V]fn[K, V] CycleQuery::new_with_recover(ingredient_index : Int, compute : (Runtime, K) -> V, recover : (Runtime, K) -> V) -> CycleQuery[K, V]fn[K, V] Database::cycle_query_with_fallback(self : Database, compute : (Runtime, K) -> V, fallback : V) -> CycleQuery[K, V]fn[K, V] Database::cycle_query_with_recover(self : Database, compute : (Runtime, K) -> V, recover : (Runtime, K) -> V) -> CycleQuery[K, V]impl Show for Durabilitypub struct Input[K, V] {
ingredient_index : Int
durability : Durability
values : HashMap[K, InputValue[V]]
hash_to_changed_at : HashMap[Int, Revision]
}pub struct Intern[V] {
ingredient_index : Int
durability : Durability
value_to_id : HashMap[V, InternId]
id_to_value : Array[V]
changed_at : Revision
}pub struct QueryEdge {
ingredient_index : Int
key_index : Int
changed_at : Revision
durability : Durability
} derive(Eq, Debug)type Runtimefn Runtime::record_dependency(self : Runtime, ingredient_index : Int, key_index : Int, changed_at : Revision, durability : Durability) -> Boollet max_fixpoint_iterations : IntIncremental computation library for MoonBit - changes ripple through the dependency graph