From 693cfbb15d95daaa03d827e6880feb24fe03ae70 Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Mon, 29 Jun 2020 18:23:25 +0300 Subject: [PATCH] Fix incorrect Dispatcher state clear on incremental invalidation Some constraints could be missed: those which are activated and discarded in the same Chunk. Dispatcher weren't cleared from them and stale matches could remain in its state. Through these matches their invalidated heads could get into incremental execution queue which led to assert violation in MatchJournalImpl.reset --- .../reactor/core/internal/ConstraintsProcessing.kt | 2 +- .../mps/logic/reactor/core/internal/ExecutionQueue.kt | 10 +++++----- .../mps/logic/reactor/core/internal/MatchJournal.kt | 6 ------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt index 42ded52a..23d4f17f 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt @@ -96,7 +96,7 @@ internal class ConstraintsProcessing(private var dispatchingFront: Dispatcher.Di // Remove chunk from the journal it.remove() // 'Undo' all activated in this chunk occurrences - chunk.activated().forEach { + chunk.activatedLog().forEach { dispatchingFront = dispatchingFront.forget(it) } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt index a379865a..e58039d2 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ExecutionQueue.kt @@ -74,7 +74,6 @@ internal class ExecutionQueue( // If the occurrence is still in the store after replay (i.e. if it's valid to activate it) if (execPos.activeOcc.stored) { - // fixme: parentChunk can also be tracked status = processing.activateContinue(controller, execPos.activeOcc, processing.parentChunk()) // Leave journal processing as it was at the point of failure if (!status.operational) return status @@ -107,12 +106,13 @@ internal class ExecutionQueue( // if it is a future match if (pos != null && journalIndex.compare(lastIncrementalRootPos, pos) < 0) { + // TODO: Remove extra logic with 'postponedMatches' + // when following Dispatcher contract is specified/checked: + // Dispatcher returns unconsumed matches relevant for offered + // activation on future calls to Dispatcher.matches(). + // With this there's no need to store them here. // val idOcc = Id(occChunk.occ) // postponedMatches[idOcc] = (postponedMatches[idOcc] ?: emptyList()) + listOf(m) - // TODO: Seems, Dispatcher will again return these unconsumed - // future matches on this offered activation, - // so there's no need to store them. - // Remove extra logic with 'postponedMatches'. offer(pos, occChunk) } else { currentMatches.add(m) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt index 6a05af93..1c570ed7 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt @@ -176,12 +176,6 @@ interface MatchJournal : MutableIterable, EvidenceSource { */ fun discardedLog(): List = entries().filter { it.discarded }.map { it.occ } - /** - * Returns the resulting collection of activated occurrences - * without discarded (only in this chunk!) occurrences. - */ - fun activated(): List = entries().allOccurrences() - fun toPos(): Pos = Pos(this, entries().size) }