From 68cde5be6c77b2da57aea975950e5c481b0b220d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 12 May 2016 22:18:57 -0400 Subject: [PATCH] DemandMatcher: overlap not ruled out! Remove it. --- js/src/demand-matcher.js | 9 +++++++++ racket/syndicate/demand-matcher.rkt | 28 ++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/js/src/demand-matcher.js b/js/src/demand-matcher.js index c6cdd55..900c285 100644 --- a/js/src/demand-matcher.js +++ b/js/src/demand-matcher.js @@ -107,6 +107,15 @@ DemandMatcher.prototype.handlePatch = function (p) { var addedSupply = this.extractKeys(p.added, self.supplyProjections, sN, 'supply'); var removedSupply = this.extractKeys(p.removed, self.supplyProjections, sN, 'supply'); + // Though the added and removed sets of patches are always disjoint, + // *after projection* this may not hold. Cancel out any overlaps. + var demandOverlap = addedDemand.intersect(removedDemand); + var supplyOverlap = addedSupply.intersect(removedSupply); + addedDemand = addedDemand.subtract(demandOverlap); + removedDemand = removedDemand.subtract(demandOverlap); + addedSupply = addedSupply.subtract(supplyOverlap); + removedSupply = removedSupply.subtract(supplyOverlap); + self.currentSupply = self.currentSupply.union(addedSupply); self.currentDemand = self.currentDemand.subtract(removedDemand); diff --git a/racket/syndicate/demand-matcher.rkt b/racket/syndicate/demand-matcher.rkt index 2f212c5..71dee26 100644 --- a/racket/syndicate/demand-matcher.rkt +++ b/racket/syndicate/demand-matcher.rkt @@ -51,6 +51,15 @@ (set) (set))) +(define (ensure-non-wild s kind spec direction t) + (when (not s) + (error 'demand-matcher + "Wildcard ~a of ~v ~a:\n~a" + kind + spec + direction + (trie->pretty-string t)))) + ;; DemandMatcher (Constreeof Action) Patch -> (Transition DemandMatcher) ;; Given a Patch from the environment, projects it into supply and ;; demand increase and decrease sets. Calls ChangeHandlers in response @@ -69,12 +78,19 @@ (define-values (added-supply removed-supply) (patch-project/set #:take supply-arity p supply-spec)) - (when (not added-demand) (error 'demand-matcher "Wildcard demand of ~v:\n~a" - demand-spec - (trie->pretty-string (patch-added p)))) - (when (not added-supply) (error 'demand-matcher "Wildcard supply of ~v:\n~a" - supply-spec - (trie->pretty-string (patch-added p)))) + (ensure-non-wild added-demand 'demand demand-spec 'added (patch-added p)) + (ensure-non-wild added-supply 'supply supply-spec 'added (patch-added p)) + (ensure-non-wild removed-demand 'demand demand-spec 'removed (patch-removed p)) + (ensure-non-wild removed-supply 'supply supply-spec 'removed (patch-removed p)) + + ;; Though the added and removed sets of patches are always disjoint, + ;; *after projection* this may not hold. Cancel out any overlaps. + (let ((overlap (set-intersect added-demand removed-demand))) + (set! added-demand (set-subtract added-demand overlap)) + (set! removed-demand (set-subtract removed-demand overlap))) + (let ((overlap (set-intersect added-supply removed-supply))) + (set! added-supply (set-subtract added-supply overlap)) + (set! removed-supply (set-subtract removed-supply overlap))) (set! supply (set-union supply added-supply)) (set! demand (set-subtract demand removed-demand))