def replay_read
bendtorch-core@0.1.0.0 · src/storage/api.bend:421
import bendtorch-core@0.1.0.0/src/storage/api.bend as Api
import Base
import bendtorch-core@0.1.0.0/src/storage/model.bend as Model
import bendtorch-core@0.1.0.0/src/storage/refinement.bend as Refinement
import bendtorch-core@0.1.0.0/src/storage/certificates.bend as Certificates
import bendtorch-core@0.1.0.0/src/storage/main.bend as Storage
import bendtorch-core@0.1.0.0/src/storage/LAWS.bend as Laws
421def replay_read(+rest: List<&2, Laws.Op>, +d: Nat, +n: Nat, +fill: F32, +history: List<&2, Effect>, +j: U32,
422 hit: Bool, +dhit: {hit == hit_of(n, rest) : Bool},
423 -b: Model.Balanced(F32, d, arr(history, d, fill)), -f: {Storage.bounds(d, n) == True{} : Bool},
424 +fits: {Storage.bounds(d, n) == True{} : Bool}, +inside: {Nat.is_lt(U32.to_nat(j), n) == True{} : Bool},
425 valid: Valid(n, history)) ->
426 {Laws.read(Laws.replay(rest, Storage.Owned{d, n, arr(history, d, fill), b, f}), j) == Done{Laws.expected(rest, n, j, current(history, j, fill))} : Result<&2, &2, Storage.Error, F32>}:
427 match rest:
428 case Nil{}:
429 %Equal.sym(Result<&2, &2, Storage.Error, F32>, Laws.read(Storage.Owned{d, n, arr(history, d, fill), b, f}, j), Done{Refinement.second(F32, Array.get(F32, arr(history, d, fill), j))},
430 read_hit(d, n, arr(history, d, fill), b, f, fits, j, inside)) : {_ == Done{current(history, j, fill)} : Result<&2, &2, Storage.Error, F32>}
431 Equal.cong(Maybe<&2, F32>, Result<&2, &2, Storage.Error, F32>, to_result, Some{Refinement.second(F32, Array.get(F32, arr(history, d, fill), j))}, Some{current(history, j, fill)},
432 Equal.trans(Maybe<&2, F32>, Some{Refinement.second(F32, Array.get(F32, arr(history, d, fill), j))},
433 Model.observe(F32, d, arr(history, d, fill), Refinement.route(d, j)), Some{current(history, j, fill)},
434 Refinement.law_get_refines(F32, d, arr(history, d, fill), j, bal(history, d, fill)),
435 Equal.sym(Maybe<&2, F32>, Some{current(history, j, fill)}, Model.observe(F32, d, arr(history, d, fill), Refinement.route(d, j)),
436 model(history, d, n, fill, j, fits, inside, valid))))
437 case +op <> +later:
438 match op:
439 case Laws.Write{+i, +w}:
440 match hit:
441 case True{}:
442 +inside_i = Equal.sym(Bool, True{}, Nat.is_lt(U32.to_nat(i), n), dhit)
443 %Equal.sym(Storage.Storage & Result<&2, &2, Storage.Error, Unit>, Storage.set_checked(d, n, arr(history, d, fill), i, w, Nat.is_lt(U32.to_nat(i), n), {==}, b, f), (Storage.Owned{d, n, Array.set(F32, arr(history, d, fill), i, w), Certificates.set_result(F32, d, arr(history, d, fill), i, w, Array.set(F32, arr(history, d, fill), i, w), {==}, b), f}, Done{Unit{}}), set_checked_hit(d, n, arr(history, d, fill), i, w, Nat.is_lt(U32.to_nat(i), n), {==}, b, f, dhit, fits, inside_i)) :
444 {Laws.read(Laws.replay(later, Laws.owner(Result<&2, &2, Storage.Error, Unit>, _)), j) == Done{Laws.expected(later, n, j, Laws.latest(n, Laws.Write{i, w}, j, current(history, j, fill)))} : Result<&2, &2, Storage.Error, F32>}
445 %dhit : {Laws.read(Laws.replay(later, Storage.Owned{d, n, Array.set(F32, arr(history, d, fill), i, w), Certificates.set_result(F32, d, arr(history, d, fill), i, w, Array.set(F32, arr(history, d, fill), i, w), {==}, b), f}), j) ==
446 Done{Laws.expected(later, n, j, Bool.pick(F32, Bool.and(_, Nat.is_eq(U32.to_nat(i), U32.to_nat(j))), w, current(history, j, fill)))} : Result<&2, &2, Storage.Error, F32>}
447 replay_read(later, d, n, fill, Wrote{i, w} <> history, j, hit_of(n, later), {==}, Certificates.set_result(F32, d, arr(history, d, fill), i, w, Array.set(F32, arr(history, d, fill), i, w), {==}, b), f, fits, inside, (inside_i, valid))
448 case False{}:
449 %Equal.sym(Storage.Storage & Result<&2, &2, Storage.Error, Unit>, Storage.set_checked(d, n, arr(history, d, fill), i, w, Nat.is_lt(U32.to_nat(i), n), {==}, b, f), (Storage.Owned{d, n, arr(history, d, fill), b, f}, Fail{Storage.OutOfBounds{}}), set_checked_miss(d, n, arr(history, d, fill), i, w, Nat.is_lt(U32.to_nat(i), n), {==}, b, f, dhit)) :
450 {Laws.read(Laws.replay(later, Laws.owner(Result<&2, &2, Storage.Error, Unit>, _)), j) == Done{Laws.expected(later, n, j, Laws.latest(n, Laws.Write{i, w}, j, current(history, j, fill)))} : Result<&2, &2, Storage.Error, F32>}
451 %dhit : {Laws.read(Laws.replay(later, Storage.Owned{d, n, arr(history, d, fill), b, f}), j) == Done{Laws.expected(later, n, j, Bool.pick(F32, Bool.and(_, Nat.is_eq(U32.to_nat(i), U32.to_nat(j))), w, current(history, j, fill)))} : Result<&2, &2, Storage.Error, F32>}
452 replay_read(later, d, n, fill, history, j, hit_of(n, later), {==}, b, f, fits, inside, valid)
453 case Laws.Read{+i}:
454 match hit:
455 case True{}:
456 +inside_i = Equal.sym(Bool, True{}, Nat.is_lt(U32.to_nat(i), n), dhit)
457 %Equal.sym(Storage.Storage & Result<&2, &2, Storage.Error, F32>, Storage.get_checked(d, n, arr(history, d, fill), i, Nat.is_lt(U32.to_nat(i), n), {==}, b, f), (Storage.Owned{d, n, Refinement.first(F32, Array.get(F32, arr(history, d, fill), i)), Certificates.get_result(F32, d, arr(history, d, fill), i, Array.get(F32, arr(history, d, fill), i), {==}, b), f}, Done{Refinement.second(F32, Array.get(F32, arr(history, d, fill), i))}), get_checked_keep(d, n, arr(history, d, fill), i, Nat.is_lt(U32.to_nat(i), n), {==}, b, f, dhit, fits, inside_i)) :
458 {Laws.read(Laws.replay(later, Laws.owner(Result<&2, &2, Storage.Error, F32>, _)), j) == Done{Laws.expected(later, n, j, current(history, j, fill))} : Result<&2, &2, Storage.Error, F32>}
459 replay_read(later, d, n, fill, Kept{i} <> history, j, hit_of(n, later), {==}, Certificates.get_result(F32, d, arr(history, d, fill), i, Array.get(F32, arr(history, d, fill), i), {==}, b), f, fits, inside, valid)
460 case False{}:
461 %Equal.sym(Storage.Storage & Result<&2, &2, Storage.Error, F32>, Storage.get_checked(d, n, arr(history, d, fill), i, Nat.is_lt(U32.to_nat(i), n), {==}, b, f), (Storage.Owned{d, n, arr(history, d, fill), b, f}, Fail{Storage.OutOfBounds{}}), get_checked_stay(d, n, arr(history, d, fill), i, Nat.is_lt(U32.to_nat(i), n), {==}, b, f, dhit)) :
462 {Laws.read(Laws.replay(later, Laws.owner(Result<&2, &2, Storage.Error, F32>, _)), j) == Done{Laws.expected(later, n, j, current(history, j, fill))} : Result<&2, &2, Storage.Error, F32>}
463 replay_read(later, d, n, fill, history, j, hit_of(n, later), {==}, b, f, fits, inside, valid)
464 case Laws.First{}:
465 %Equal.sym(Storage.Storage & Storage.Storage, Storage.finish_clone(d, n, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b, f), (Storage.Owned{d, n, Pair.fst(Array<F32>, Array<F32>, Array.clone(F32, arr(history, d, fill))), Certificates.clone_first(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f}, Storage.Owned{d, n, Pair.snd(Array<F32>, Array<F32>, Array.clone(F32, arr(history, d, fill))), Certificates.clone_second(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f}), finish_pair(d, n, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b, f)) :
466 {Laws.read(Laws.replay(later, Laws.owner(Storage.Storage, _)), j) == Done{Laws.expected(later, n, j, current(history, j, fill))} : Result<&2, &2, Storage.Error, F32>}
467 replay_read(later, d, n, fill, Left{} <> history, j, hit_of(n, later), {==}, Certificates.clone_first(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f, fits, inside, valid)
468 case Laws.Second{}:
469 %Equal.sym(Storage.Storage & Storage.Storage, Storage.finish_clone(d, n, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b, f), (Storage.Owned{d, n, Pair.fst(Array<F32>, Array<F32>, Array.clone(F32, arr(history, d, fill))), Certificates.clone_first(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f}, Storage.Owned{d, n, Pair.snd(Array<F32>, Array<F32>, Array.clone(F32, arr(history, d, fill))), Certificates.clone_second(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f}), finish_pair(d, n, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b, f)) :
470 {Laws.read(Laws.replay(later, Laws.outcome(Storage.Storage, _)), j) == Done{Laws.expected(later, n, j, current(history, j, fill))} : Result<&2, &2, Storage.Error, F32>}
471 replay_read(later, d, n, fill, Right{} <> history, j, hit_of(n, later), {==}, Certificates.clone_second(F32, d, arr(history, d, fill), Array.clone(F32, arr(history, d, fill)), {==}, b), f, fits, inside, valid)
472 case Laws.Length{}:
473 replay_read(later, d, n, fill, history, j, hit_of(n, later), {==}, b, f, fits, inside, valid)