From ba8d00c2240ba644ec22da1750ca30eecfdfc3bf Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Mon, 20 Jan 2020 20:23:53 +0300 Subject: [PATCH] Handle incr exec of cases unhandled with introduced mem opt. Added test passes. --- .../mps/logic/reactor/core/RuleMatchingProbe.kt | 2 ++ .../reactor/core/internal/ConstraintsProcessing.kt | 2 +- .../logic/reactor/core/internal/ReteRuleMatcherImpl.kt | 10 ++++++++++ .../mps/logic/reactor/core/internal/RuleMatcherImpl.kt | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt index acc7370b..47be0db3 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatchingProbe.kt @@ -33,6 +33,8 @@ interface RuleMatchingProbe : RuleMatchingProbeState { fun matches(): Collection + fun hasOccurrences(): Boolean + fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe fun forget(ruleMatch: RuleMatchEx): RuleMatchingProbe 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 6d30adfa..11b73fa4 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 @@ -201,7 +201,7 @@ internal class ConstraintsProcessing(private var dispatchingFront: Dispatcher.Di resetStore() // clear observers val rules = ArrayList().apply { ruleIndex.forEach { add(it) } } val principalState = dispatchingFront.state().filterValues { ruleMatcher -> - ispec.isPrincipal(ruleMatcher.rule()) + ispec.isPrincipal(ruleMatcher.rule()) || ruleMatcher.probe().hasOccurrences() } return SessionTokenImpl(histView, rules, principalState, logicalState.clear()) } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt index 284da833..2ad406e7 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ReteRuleMatcherImpl.kt @@ -247,6 +247,8 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup, nodeList.add(node) } + fun occurrencesCount() = introTrail.size() + fun containsOccurrence(occ: Occurrence): Boolean { return introTrail.contains(occ.identity) } @@ -404,6 +406,10 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup, nodesIt = layers.last().iterate() } + fun hasOccurrences(): Boolean { + return layers.any { it.occurrencesCount() > 0 } + } + fun reset(): Generation { this.nodesIt = layers.last().iterate() return this @@ -510,6 +516,10 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup, return this } + override fun hasOccurrences(): Boolean { + return this.lastGeneration.hasOccurrences() + } + override fun matches(): Collection { return lastGeneration.matches } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt index 7c8134b9..fbda8311 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/RuleMatcherImpl.kt @@ -67,6 +67,8 @@ internal class RuleMatcherImpl(private var ruleLookup: RuleLookup, { override fun rule(): Rule = lookupRule() + override fun hasOccurrences(): Boolean = trunkNodes.size > 0 || leafNodes.size > 0 + override fun matches(): Collection = leafNodes .filter { node -> !consumedSignatures.contains(node.signature()) }