Provide as eval result tags of invalidated rules. for MPSCR-82

Relevant for Incremental strategy.
Allows to more precisely track invalidated types of nodes.
Type of node is invalidated if rules with this origin
were invalidated during incremental processing.
This commit is contained in:
Grigorii Kirgizov 2020-11-24 11:43:44 +03:00
parent b4c441a41e
commit 88067571d0
4 changed files with 43 additions and 18 deletions

View File

@ -129,7 +129,7 @@ internal class EvaluationSessionImpl private constructor (
val status = run(main)
controller.shutDown()
val newToken = endSession(session)
return EvaluationResultImpl(newToken, status, strategy.invalidatedFeedback())
return EvaluationResultImpl(newToken, status, strategy.invalidatedFeedback(), strategy.invalidatedRules())
}
private fun SessionParts.run(main: Constraint): FeedbackStatus = strategy.run(processing, controller, main)
@ -329,12 +329,14 @@ internal class EvaluationSessionImpl private constructor (
private class EvaluationResultImpl(
val token: SessionToken,
val status: FeedbackStatus,
val invalidFeedbackKeys: FeedbackKeySet
val invalidFeedbackKeys: FeedbackKeySet,
val invalidRules: Collection<Any>
): EvaluationResult {
override fun token() = token
override fun storeView(): StoreView = token.journalView.storeView
override fun feedback(): EvaluationFeedback? = if (status is FAILED) status.failure else null
override fun invalidFeedbackKeys(): Collection<Any> = invalidFeedbackKeys
override fun invalidRules(): Collection<Any> = invalidRules
}

View File

@ -55,7 +55,12 @@ internal class InvalidationStage(
private val invalidFeedbackKeys: MutableSet<Any> = mutableSetOf<Any>()
fun invalidatedFeedback(): FeedbackKeySet = HashSet<Any>(invalidFeedbackKeys)
private val invalidRuleIdsAll: MutableList<Any> = mutableListOf<Any>()
fun invalidatedFeedback(): FeedbackKeySet = invalidFeedbackKeys.toHashSet()
fun invalidatedRules(): List<Any> = invalidRuleIdsAll.toList()
fun receive(invalid: Iterable<Justified>) { invalidJustifications.addAll(invalid) }
@ -89,28 +94,31 @@ internal class InvalidationStage(
val validOccs: Sequence<Occurrence>
if (chunk is MatchJournal.MatchChunk) {
trace.invalidate(chunk.match)
with (chunk.match) {
trace.invalidate(this)
invalidFeedbackKeys.add(chunk.match.feedbackKey)
stateCleaner.erase(chunk.match as RuleMatchEx)
invalidFeedbackKeys.add(feedbackKey)
invalidRuleIdsAll.add(rule().uniqueTag())
// Valid head occurrences could match more rules
// without this match, so need to reactivate them.
// E.g. occurrences discarded in this match on
// previous run but revived here can match more rules.
validOccs = chunk.match.allHeads().filter { occ ->
!occ.justifiedByAny(invalidJustifications)
stateCleaner.erase(this as RuleMatchEx)
// Valid head occurrences could match more rules
// without this match, so need to reactivate them.
// E.g. occurrences discarded in this match on
// previous run but revived here can match more rules.
validOccs = allHeads().filter { occ ->
!occ.justifiedByAny(invalidJustifications)
}
// By definition of Chunk and principal rule,
// all occurrences from the head are principal.
assert(allHeads().all { it.isPrincipal })
}
// By definition of Chunk and principal rule,
// all occurrences from the head are principal.
assert(chunk.match.allHeads().all { it.isPrincipal })
} else validOccs = emptySequence()
return validOccs.asIterable()
}
private fun MatchJournal.MatchChunk.dependsOnAny(utags: Iterable<Any>): Boolean =
utags.contains(this.ruleUniqueTag) || utags.any { utag -> dependsOnRule(utag) }
utags.contains(ruleUniqueTag) || utags.any(::dependsOnRule)
}

View File

@ -34,6 +34,11 @@ internal interface ProcessingStrategy {
*/
fun invalidatedFeedback(): FeedbackKeySet
/**
* Unique tags of principal rules which matches where invalidated.
*/
fun invalidatedRules(): List<Any>
/**
* Entry point for processing session.
*/
@ -59,6 +64,8 @@ internal class NonIncrementalProcessing: ProcessingStrategy {
override fun invalidatedFeedback(): FeedbackKeySet = emptySet()
override fun invalidatedRules(): List<Any> = emptyList()
/**
* Simply redirects evaluation to [Controller].
*/
@ -108,7 +115,11 @@ internal class IncrementalProcessing(
private val postponer = PostponeMatchesStage(ispec, journal, journalIndex, ruleOrdering)
override fun invalidatedFeedback(): FeedbackKeySet = invalidator.invalidatedFeedback()
override fun invalidatedFeedback(): FeedbackKeySet =
invalidator.invalidatedFeedback()
override fun invalidatedRules(): List<Any> =
invalidator.invalidatedRules()
override fun processMatch(match: RuleMatchEx) =
continueReplacedHeadsImpl(match)
@ -196,6 +207,8 @@ internal class PreambleProcessing(
override fun invalidatedFeedback(): FeedbackKeySet = emptySet()
override fun invalidatedRules(): List<Any> = emptyList()
override fun processMatch(match: RuleMatchEx) = Unit
override fun processOccurrenceMatches(active: Occurrence, matches: List<RuleMatchEx>) = matches

View File

@ -31,4 +31,6 @@ public interface EvaluationResult {
public Collection<Object> invalidFeedbackKeys();
public Collection<Object> invalidRules();
}