From fe40d6b804f2312e379787fae8a6df329c37e04b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 21 Oct 2018 13:32:06 +0100 Subject: [PATCH] Present-to-absent check is necessary in assertion removal handler --- ijs/src/skeleton.js | 13 ++++++++----- imperative/HOWITWORKS.md | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ijs/src/skeleton.js b/ijs/src/skeleton.js index 32e4460..344bf45 100644 --- a/ijs/src/skeleton.js +++ b/ijs/src/skeleton.js @@ -204,11 +204,14 @@ function add_to_handler(h, vs) { function del_from_cont(c, v) { c.cachedAssertions = c.cachedAssertions.remove(v); } function del_from_leaf(l, v) { l.cachedAssertions = l.cachedAssertions.remove(v); } function del_from_handler(h, vs) { - h.cachedCaptures = Bag.change(h.cachedCaptures, vs, -1).bag; - h.callbacks.forEach((cb) => { - cb(EVENT_REMOVED, vs); - return true; - }); + let net; + ({bag: h.cachedCaptures, net: net} = Bag.change(h.cachedCaptures, vs, -1)); + if (net === Bag.PRESENT_TO_ABSENT) { + h.callbacks.forEach((cb) => { + cb(EVENT_REMOVED, vs); + return true; + }); + } } Index.prototype.adjustAssertion = function(outerValue, delta) { diff --git a/imperative/HOWITWORKS.md b/imperative/HOWITWORKS.md index 898df22..7ad4761 100644 --- a/imperative/HOWITWORKS.md +++ b/imperative/HOWITWORKS.md @@ -444,8 +444,9 @@ check followed by zero or more (move, check) pairs. del_leaf (leafcache, _) v = leafcache -= v del_handler (bag, f_table) vs = bag[vs] -= 1 - for f in f_table - f "-" vs + if vs not in bag then + for f in f_table + f "-" vs **Definition.** The procedures `addAssertion` and `removeAssertion` install and remove an assertion `v` into the given index,