diff --git a/std/fixpoint/fixpoint-memo.kk b/std/fixpoint/fixpoint-memo.kk index 9041b62..dcb8180 100644 --- a/std/fixpoint/fixpoint-memo.kk +++ b/std/fixpoint/fixpoint-memo.kk @@ -20,40 +20,38 @@ fun cache(comp: () -> |e> d, ?order2: (k, k) -> pure order2, // trace("Updating " ++ resumes.length.show ++ " deps for " ++ s.show ++ " with " ++ c.c/show) resumes.list/foreach(fn(resumption) {resumption(change); ()}) Nothing -> () - val do = - with handler - fun add-result(key, change) - // trace("Adding result for " ++ s.s/show ++ " " ++ c.c/show) - match cache.lookup(key) - Just(r') -> - val (changed, r'') = join(r', change) - if changed then - cache := cache.set(key, r'') - update(key, change) - else () - Nothing -> - cache := cache.set(key, bottom.join(change).snd) + handle(comp) + fun add-result(key, change) + // trace("Adding result for " ++ s.s/show ++ " " ++ c.c/show) + match cache.lookup(key) + Just(r') -> + val (changed, r'') = join(r', change) + if changed then + cache := cache.set(key, r'') update(key, change) - fun is-cached(key) - if cache.contains(key) || deps.contains(key) then True - else - cache := cache.set(key, bottom) - deps := deps.set(key, Nil) - False - ctl depend(key) - // trace("Adding dep for " ++ s.s/show) - match deps.lookup(key) - Just(resumes) -> - val ress = Cons(fn(r) resume(r), resumes) - deps := deps.set(key, ress) - match cache.lookup(key) - Just(r) -> r.changes.foreach(fn(change) resume(change)) - ctl do-each(ss) - ss.foreach(fn(s) resume(s)) - final ctl none() - () - return(x) () - comp() + else () + Nothing -> + cache := cache.set(key, bottom.join(change).snd) + update(key, change) + fun is-cached(key) + if cache.contains(key) || deps.contains(key) then True + else + cache := cache.set(key, bottom) + deps := deps.set(key, Nil) + False + ctl depend(key) + // trace("Adding dep for " ++ s.s/show) + match deps.lookup(key) + Just(resumes) -> + val ress = Cons(fn(r) resume(r), resumes) + deps := deps.set(key, ress) + match cache.lookup(key) + Just(r) -> r.changes.foreach(fn(change) resume(change)) + ctl do-each(ss) + ss.foreach(fn(s) resume(s)) + final ctl none() + () + return(x) () cache // Inserts a memoization point at a recursive invocation diff --git a/std/fixpoint/memo-partial-order-fine-grained.kk b/std/fixpoint/memo-partial-order-fine-grained.kk index 374e9d6..f19bb88 100644 --- a/std/fixpoint/memo-partial-order-fine-grained.kk +++ b/std/fixpoint/memo-partial-order-fine-grained.kk @@ -33,33 +33,30 @@ fun cache(change-lattice: change-lattice, comp: () -> ,each ?k/show: k -> pure string, ?r/show: r -> pure string, ?c/show: c -> pure string): rbmap val Change-lattice(bottom, join, changes) = change-lattice var cache : some rbmap> := empty() - val do = - with handler - fun add-result(key, change) - // trace("Adding result for " ++ k.k/show ++ " " ++ c.c/show) - match cache.lookup(key) - Just(Cache-entry(current, deps)) -> - val (changed, new) = join(current, change) - if changed then - cache := cache.set(key, Cache-entry(new, deps)) - deps.foreach(fn(resumption) resumption(change)) - else () - Nothing -> - cache := cache.set(key, Cache-entry(join(bottom, change).snd, [])) - fun is-cached(k) - if cache.contains(k) then True - else - cache := cache.set(k, Cache-entry(bottom, [])) - False - ctl depend(key) - // trace("Adding dep for " ++ k.k/show) - match cache.lookup(key) - Just(Cache-entry(current, deps)) -> - cache := cache.set(key, Cache-entry(current, Cons(fn(change) resume(change), deps))) - changes(current).foreach(fn(change) resume(change)) - return(x) () - with nondet - comp() + handle({ nondet(comp) }) + fun add-result(key, change) + // trace("Adding result for " ++ k.k/show ++ " " ++ c.c/show) + match cache.lookup(key) + Just(Cache-entry(current, deps)) -> + val (changed, new) = join(current, change) + if changed then + cache := cache.set(key, Cache-entry(new, deps)) + deps.foreach(fn(resumption) resumption(change)) + else () + Nothing -> + cache := cache.set(key, Cache-entry(join(bottom, change).snd, [])) + fun is-cached(k) + if cache.contains(k) then True + else + cache := cache.set(k, Cache-entry(bottom, [])) + False + ctl depend(key) + // trace("Adding dep for " ++ k.k/show) + match cache.lookup(key) + Just(Cache-entry(current, deps)) -> + cache := cache.set(key, Cache-entry(current, Cons(fn(change) resume(change), deps))) + changes(current).foreach(fn(change) resume(change)) + return(x) () cache.remove-deps // Inserts a memoization point at a recursive invocation diff --git a/std/fixpoint/memo-partial-order.kk b/std/fixpoint/memo-partial-order.kk index a3f3eec..2df106b 100644 --- a/std/fixpoint/memo-partial-order.kk +++ b/std/fixpoint/memo-partial-order.kk @@ -36,33 +36,30 @@ fun cache(comp: () -> ,each|e> b, ?order2: (k, k) -> pure order2 ?join: (r, r) -> (bool, r), ?s/show: k -> string, ?r/show: r -> string): rbmap var cache : some rbmap> := empty() - val do = - with handler - fun add-result(key, change) - // trace("Adding result for " ++ s.s/show ++ " " ++ r.r/show) - match cache.lookup(key) - Just(Cache-entry(result, deps)) -> - val (changed, new) = join(result, change) - if changed then - cache := cache.set(key, Cache-entry(new, deps)) - deps.foreach(fn(resumption) resumption(change)) - else () - Nothing -> - cache := cache.set(key, Cache-entry(change, [])) - fun is-cached(key) - if cache.contains(key) then True - else - cache := cache.set(key, Cache-entry(bottom, [])) - False - ctl depend(key) - // trace("Adding dep for " ++ s.s/show) - match cache.lookup(key) - Just(Cache-entry(current, deps)) -> - cache := cache.set(key, Cache-entry(current, Cons(fn(change) resume(change), deps))) - resume(current) - return(x) () - with nondet - comp() + handle({ nondet(comp) }) + fun add-result(key, change) + // trace("Adding result for " ++ s.s/show ++ " " ++ r.r/show) + match cache.lookup(key) + Just(Cache-entry(result, deps)) -> + val (changed, new) = join(result, change) + if changed then + cache := cache.set(key, Cache-entry(new, deps)) + deps.foreach(fn(resumption) resumption(change)) + else () + Nothing -> + cache := cache.set(key, Cache-entry(change, [])) + fun is-cached(key) + if cache.contains(key) then True + else + cache := cache.set(key, Cache-entry(bottom, [])) + False + ctl depend(key) + // trace("Adding dep for " ++ s.s/show) + match cache.lookup(key) + Just(Cache-entry(current, deps)) -> + cache := cache.set(key, Cache-entry(current, Cons(fn(change) resume(change), deps))) + resume(current) + return(x) () cache.remove-deps // Inserts a memoization point at a recursive invocation