Modify EvaluationResult to also return the set of tags of all invalidated rules (MPSCR-32)

This commit is contained in:
Grigorii Kirgizov 2020-01-23 16:30:01 +03:00
parent 1334c7c7a1
commit e55e67bc08
4 changed files with 41 additions and 25 deletions

View File

@ -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<Any>) {
fun invalidateRuleMatches(ruleIds: Set<Any>): Set<Any> {
val justificationRoots = mutableListOf<Int>()
val allInvalidatedIds = mutableSetOf<Any>()
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 =

View File

@ -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<FeedbackStatus, Set<Any>> {
val invalidatedRuleTags =
profiler.profile<Set<Any>>("invalidation") {
processing.invalidateRuleMatches(rulesDiff.removed)
}
profiler.profile("adding_matches") {
processing.addRuleMatches(rulesDiff.added)
}
return profiler.profile<FeedbackStatus>("reexecution") {
processing.launchQueue(this)
}
val status =
profiler.profile<FeedbackStatus>("reexecution") {
processing.launchQueue(this)
}
return status to invalidatedRuleTags
}
fun activate(constraint: Constraint) : FeedbackStatus {

View File

@ -42,7 +42,11 @@ internal class EvaluationSessionImpl private constructor (
private fun launch(
main: Constraint, profiler: Profiler?,
token: SessionToken?, rulesDiff: RulesDiff, ispec: IncrementalProgramSpec
) : Pair<FeedbackStatus, SessionToken> {
) : EvaluationResult {
val newToken: SessionToken
val status: FeedbackStatus
val invalidatedTags: Set<Any>
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<Any> = 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 {

View File

@ -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<Object> invalidatedTags();
}