From e55e67bc08e6e18eb021492265eef2dd80c72554 Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Thu, 23 Jan 2020 16:30:01 +0300 Subject: [PATCH] Modify EvaluationResult to also return the set of tags of all invalidated rules (MPSCR-32) --- .../core/internal/ConstraintsProcessing.kt | 6 ++- .../reactor/core/internal/ControllerImpl.kt | 17 ++++---- .../core/internal/EvaluationSessionImpl.kt | 39 +++++++++++-------- .../reactor/evaluation/EvaluationResult.java | 4 ++ 4 files changed, 41 insertions(+), 25 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 11b73fa4..b1260919 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 @@ -76,8 +76,9 @@ internal class ConstraintsProcessing(private var dispatchingFront: Dispatcher.Di * - reactivating occurrences that led to invalidated matches * - pruning invalidated occurrences and matches from Dispatcher's state */ - fun invalidateRuleMatches(ruleIds: Set) { + fun invalidateRuleMatches(ruleIds: Set): Set { val justificationRoots = mutableListOf() + val allInvalidatedIds = mutableSetOf() val it = this.iterator() var prevChunk = it.next() // skip initial chunk @@ -101,10 +102,10 @@ internal class ConstraintsProcessing(private var dispatchingFront: Dispatcher.Di if (chunk is MatchJournal.MatchChunk) { trace.invalidate(chunk.match) + allInvalidatedIds.add(chunk.match.rule().uniqueTag()) // Seems, it's not strictly necessary, because some of its head occurrences are anyway invalidated forever // and storing this invalid consumed match can make no harm, except some memory overhead. - // fixme: move Chunk's interface to RuleMatchEx instead of RuleMatch dispatchingFront = dispatchingFront.forget(chunk.match as RuleMatchEx) // Need to 'cancel' discarding. @@ -127,6 +128,7 @@ internal class ConstraintsProcessing(private var dispatchingFront: Dispatcher.Di prevChunk = chunk } + return allInvalidatedIds } private fun canMatch(rule: Rule, occ: Occurrence): Boolean = diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt index 0d1d29e9..2f831a95 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt @@ -54,16 +54,19 @@ internal class ControllerImpl ( return storeView() } - fun incrLaunch(constraint: Constraint, rulesDiff: RulesDiff): FeedbackStatus { - profiler.profile("invalidation") { - processing.invalidateRuleMatches(rulesDiff.removed) - } + fun incrLaunch(constraint: Constraint, rulesDiff: RulesDiff): Pair> { + val invalidatedRuleTags = + profiler.profile>("invalidation") { + processing.invalidateRuleMatches(rulesDiff.removed) + } profiler.profile("adding_matches") { processing.addRuleMatches(rulesDiff.added) } - return profiler.profile("reexecution") { - processing.launchQueue(this) - } + val status = + profiler.profile("reexecution") { + processing.launchQueue(this) + } + return status to invalidatedRuleTags } fun activate(constraint: Constraint) : FeedbackStatus { diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt index b6bf9f22..002684c2 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt @@ -42,7 +42,11 @@ internal class EvaluationSessionImpl private constructor ( private fun launch( main: Constraint, profiler: Profiler?, token: SessionToken?, rulesDiff: RulesDiff, ispec: IncrementalProgramSpec - ) : Pair { + ) : EvaluationResult { + + val newToken: SessionToken + val status: FeedbackStatus + val invalidatedTags: Set val ruleIndex = RuleIndex(program.rulesLists()) @@ -54,24 +58,36 @@ internal class EvaluationSessionImpl private constructor ( MatchJournalImpl(ispec), ruleIndex, logicalState, ispec, trace, profiler ) - val controller = ControllerImpl(supervisor, processing, ispec, trace, profiler) logicalState.init(controller) - return controller.activate(main) to processing.endSession() + + status = controller.activate(main) + newToken = processing.endSession() + invalidatedTags = emptySet() } else { val tkn = token as SessionTokenImpl val logicalState = tkn.logicalState - + val processing = ConstraintsProcessing( Dispatcher(ruleIndex, tkn.getFrontState()).front(), MatchJournalImpl(ispec, tkn.journalView), ruleIndex, logicalState, ispec, trace, profiler ) - val controller = ControllerImpl(supervisor, processing, ispec, trace, profiler) logicalState.init(controller) - return controller.incrLaunch(main, rulesDiff) to processing.endSession() + + val status2tags = controller.incrLaunch(main, rulesDiff) + newToken = processing.endSession() + status = status2tags.first + invalidatedTags = status2tags.second + } + + return object : EvaluationResult { + override fun token(): SessionToken = newToken + override fun storeView(): StoreView = newToken.journalView.storeView + override fun feedback(): EvaluationFeedback? = if (status is FAILED) status.failure else null + override fun invalidatedTags(): Collection = invalidatedTags } } @@ -122,16 +138,7 @@ internal class EvaluationSessionImpl private constructor ( Backend.ourBackend.ourSession.set(session) try { val main = parameters[ParameterKey.of("main", Constraint::class.java)] as Constraint - val (status, token) = session.launch(main, profiler, token, program.incrementalDiff(), ispec) - - return object : EvaluationResult { - - override fun token(): SessionToken = token - - override fun storeView(): StoreView = token.journalView.storeView - - override fun feedback(): EvaluationFeedback? = if (status is FAILED) status.failure else null - } + return session.launch(main, profiler, token, program.incrementalDiff(), ispec) } finally { try { diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationResult.java b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationResult.java index 1a70c74e..b2d5cafa 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationResult.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationResult.java @@ -16,6 +16,8 @@ package jetbrains.mps.logic.reactor.evaluation; +import java.util.Collection; + /** * @author Fedor Isakov */ @@ -27,4 +29,6 @@ public interface EvaluationResult { public EvaluationFeedback feedback(); + public Collection invalidatedTags(); + }