MPSCR-4: Upd refs to new RuleIndex on Dispatcher construction in incremental case.
Slightly extend RuleMatcher interface. Store RuleMatcher instances instead of RuleMatcherProbe in SessionToken.
This commit is contained in:
parent
320a19af93
commit
0dd7f8c70f
|
|
@ -5067,21 +5067,25 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node concept="3clFbF" id="7smgEqgBwSC" role="3cqZAp">
|
||||
<node concept="1oi1Uc" id="7smgEqgBuPa" role="3clFbG">
|
||||
<node concept="1oi5UN" id="7smgEqgBuPf" role="1oi0x0">
|
||||
<node concept="1oi5Wm" id="7smgEqgByek" role="1ojpOf">
|
||||
<property role="TrG5h" value="id" />
|
||||
<node concept="1oi5XN" id="7smgEqgByyN" role="1oi5zu">
|
||||
<node concept="22Ky0T" id="7smgEqgByGW" role="lGtFl">
|
||||
<node concept="2OqwBi" id="7smgEqgB$6j" role="22Ky0K">
|
||||
<node concept="2JrnkZ" id="7smgEqgBzOR" role="2Oq$k0">
|
||||
<node concept="37vLTw" id="7smgEqgByNR" role="2JrQYb">
|
||||
<ref role="3cqZAo" node="7smgEqgBveJ" resolve="node" />
|
||||
<node concept="1X3_iC" id="3FGJ5nvoycw" role="lGtFl">
|
||||
<property role="3V$3am" value="statement" />
|
||||
<property role="3V$3ak" value="f3061a53-9226-4cc5-a443-f952ceaf5816/1068580123136/1068581517665" />
|
||||
<node concept="3clFbF" id="7smgEqgBwSC" role="8Wnug">
|
||||
<node concept="1oi1Uc" id="7smgEqgBuPa" role="3clFbG">
|
||||
<node concept="1oi5UN" id="7smgEqgBuPf" role="1oi0x0">
|
||||
<node concept="1oi5Wm" id="7smgEqgByek" role="1ojpOf">
|
||||
<property role="TrG5h" value="id" />
|
||||
<node concept="1oi5XN" id="7smgEqgByyN" role="1oi5zu">
|
||||
<node concept="22Ky0T" id="7smgEqgByGW" role="lGtFl">
|
||||
<node concept="2OqwBi" id="7smgEqgB$6j" role="22Ky0K">
|
||||
<node concept="2JrnkZ" id="7smgEqgBzOR" role="2Oq$k0">
|
||||
<node concept="37vLTw" id="7smgEqgByNR" role="2JrQYb">
|
||||
<ref role="3cqZAo" node="7smgEqgBveJ" resolve="node" />
|
||||
</node>
|
||||
</node>
|
||||
<node concept="liA8E" id="7smgEqgB$P1" role="2OqNvi">
|
||||
<ref role="37wK5l" to="mhbf:~SNode.getReference()" resolve="getReference" />
|
||||
</node>
|
||||
</node>
|
||||
<node concept="liA8E" id="7smgEqgB$P1" role="2OqNvi">
|
||||
<ref role="37wK5l" to="mhbf:~SNode.getReference()" resolve="getReference" />
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -5090,6 +5094,14 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node concept="3clFbF" id="4a1_91oCN_D" role="3cqZAp">
|
||||
<node concept="2OqwBi" id="4a1_91oCNJo" role="3clFbG">
|
||||
<node concept="37vLTw" id="4a1_91oCN_B" role="2Oq$k0">
|
||||
<ref role="3cqZAo" node="7smgEqgBveJ" resolve="node" />
|
||||
</node>
|
||||
<node concept="iZEcu" id="4a1_91oCNQr" role="2OqNvi" />
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node concept="raruj" id="34$A1MfwU_v" role="lGtFl" />
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JB JDK 11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JB SDK 11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -17,21 +17,24 @@
|
|||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
|
||||
typealias DispatchingFrontState = Map<Any, RuleMatchingProbe>
|
||||
typealias DispatchingFrontState = Map<Any, RuleMatcher>
|
||||
|
||||
/**
|
||||
* A front-end interface to [RuleMatcher].
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
class Dispatcher (val ruleIndex: RuleIndex) {
|
||||
class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = emptyMap()) {
|
||||
|
||||
private val ruletag2matcher = HashMap<Any, RuleMatcher>()
|
||||
|
||||
init {
|
||||
ruleIndex.forEach { rule ->
|
||||
val matcher = createRuleMatcher(ruleIndex, rule.uniqueTag())
|
||||
ruletag2matcher.put(rule.uniqueTag(), matcher);
|
||||
val ruletag = rule.uniqueTag()
|
||||
// reset references to stale RuleIndex instances
|
||||
val matcher = prevState[ruletag]?.apply { setRuleLookup(ruleIndex) }
|
||||
?: createRuleMatcher(ruleIndex, ruletag)
|
||||
ruletag2matcher.put(ruletag, matcher);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,8 +43,6 @@ class Dispatcher (val ruleIndex: RuleIndex) {
|
|||
*/
|
||||
fun front() = DispatchingFront()
|
||||
|
||||
fun frontFromState(predState: DispatchingFrontState) = DispatchingFront(predState)
|
||||
|
||||
inner class DispatchingFront {
|
||||
|
||||
private val ruletag2probe : HashMap<Any, RuleMatchingProbe>
|
||||
|
|
@ -56,14 +57,6 @@ class Dispatcher (val ruleIndex: RuleIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
constructor(predState: DispatchingFrontState) {
|
||||
this.ruletag2probe = hashMapOf()
|
||||
this.matching = null
|
||||
ruletag2matcher.entries.forEach { e ->
|
||||
ruletag2probe[e.key] = predState[e.key] ?: e.value.probe()
|
||||
}
|
||||
}
|
||||
|
||||
private constructor(pred: DispatchingFront, matching: Iterable<RuleMatchingProbe>? = null) {
|
||||
this.ruletag2probe = pred.ruletag2probe
|
||||
this.matching = matching
|
||||
|
|
@ -83,7 +76,7 @@ class Dispatcher (val ruleIndex: RuleIndex) {
|
|||
return allMatches
|
||||
}
|
||||
|
||||
fun state() : DispatchingFrontState = ruletag2probe //.asMap()
|
||||
fun state() : DispatchingFrontState = ruletag2matcher //.asMap()
|
||||
|
||||
/**
|
||||
* Returns a [DispatchingFront] instance that is "expanded" with matches corresponding to the
|
||||
|
|
|
|||
|
|
@ -26,14 +26,19 @@ import jetbrains.mps.logic.reactor.program.Rule
|
|||
* Abstracts a rule matching algorithm.
|
||||
*
|
||||
* A RuleMatcher corresponds to a single rule.
|
||||
* The method [probe] provides a factory of [RuleMatchingProbe], which is the main handler of match operations.
|
||||
* The method [newProbe] provides a factory of [RuleMatchingProbe], which is the main handler of match operations.
|
||||
* The method [probe] provides access to a last created instance of [RuleMatchingProbe] or creates a first one.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
interface RuleMatcher {
|
||||
|
||||
fun newProbe(): RuleMatchingProbe
|
||||
|
||||
fun probe(): RuleMatchingProbe
|
||||
|
||||
fun setRuleLookup(ruleLookup: RuleLookup): Unit
|
||||
|
||||
}
|
||||
|
||||
fun createRuleMatcher(lookup: RuleLookup, tag: Any): RuleMatcher = ReteRuleMatcherImpl(lookup, tag)
|
||||
|
|
|
|||
|
|
@ -47,11 +47,10 @@ internal class EvaluationSessionImpl private constructor (
|
|||
) : FeedbackStatus {
|
||||
|
||||
val ruleIndex = RuleIndex(program.handlers())
|
||||
val dispatcher = Dispatcher(ruleIndex)
|
||||
|
||||
if (ispec is IncrementalProgramSpec.NonIncrSpec || token == null) {
|
||||
val state = ProcessingStateImpl(
|
||||
dispatcher.front(),
|
||||
Dispatcher(ruleIndex).front(),
|
||||
MatchJournalImpl(ispec),
|
||||
ruleIndex, ispec, trace, profiler
|
||||
)
|
||||
|
|
@ -62,7 +61,7 @@ internal class EvaluationSessionImpl private constructor (
|
|||
} else {
|
||||
val tkn = token as SessionTokenImpl
|
||||
val state = ProcessingStateImpl(
|
||||
dispatcher.frontFromState(tkn.frontState),
|
||||
Dispatcher(ruleIndex, tkn.getFrontState()).front(),
|
||||
MatchJournalImpl(ispec, tkn.journalView),
|
||||
ruleIndex, ispec, trace, profiler
|
||||
)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ fun footprintOf(): Footprint = TIntHashSet()
|
|||
|
||||
fun Signature.toFootprint() = TIntHashSet(this)
|
||||
|
||||
internal class ReteRuleMatcherImpl(private val ruleLookup: RuleLookup,
|
||||
internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup,
|
||||
private val tag: Any) : RuleMatcher
|
||||
{
|
||||
|
||||
|
|
@ -51,7 +51,13 @@ internal class ReteRuleMatcherImpl(private val ruleLookup: RuleLookup,
|
|||
|
||||
fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'")
|
||||
|
||||
override fun probe(): ReteNetwork = ReteNetwork(head.size)
|
||||
override fun setRuleLookup(ruleLookup: RuleLookup) { this.ruleLookup = ruleLookup }
|
||||
|
||||
override fun newProbe(): RuleMatchingProbe = ReteNetwork(head.size).also { probe = it }
|
||||
|
||||
override fun probe(): RuleMatchingProbe = probe ?: newProbe()
|
||||
|
||||
private var probe: RuleMatchingProbe? = null
|
||||
|
||||
inner class ReteNetwork(val headSize: Int) : RuleMatchingProbe {
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import kotlin.collections.ArrayList
|
|||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
|
||||
internal class RuleMatcherImpl(private var ruleLookup: RuleLookup,
|
||||
private val tag: Any) : RuleMatcher
|
||||
{
|
||||
|
||||
|
|
@ -43,12 +43,19 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
|
|||
|
||||
fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'")
|
||||
|
||||
override fun probe(): RuleMatchingProbe =
|
||||
override fun setRuleLookup(ruleLookup: RuleLookup) { this.ruleLookup = ruleLookup }
|
||||
|
||||
override fun newProbe(): RuleMatchingProbe =
|
||||
RuleMatchFront(emptyList(),
|
||||
emptyList(),
|
||||
Sets.of(IntArray(head.size).toSignature()),
|
||||
Sets.of(),
|
||||
Sets.of())
|
||||
.also { probe = it }
|
||||
|
||||
override fun probe(): RuleMatchingProbe = probe ?: newProbe()
|
||||
|
||||
private var probe: RuleMatchingProbe? = null
|
||||
|
||||
inner class RuleMatchFront(private val trunkNodes: List<MatchNode>,
|
||||
private val leafNodes: List<MatchNode>,
|
||||
|
|
|
|||
|
|
@ -27,5 +27,5 @@ data class SessionTokenImpl(
|
|||
) : SessionToken {
|
||||
override fun getJournalView(): MatchJournalView = journalView
|
||||
override fun getRuleTags(): Iterable<Any> = ruleTags
|
||||
override fun getFrontState(): DispatchingFrontState = frontState
|
||||
fun getFrontState(): DispatchingFrontState = frontState
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,4 @@ public interface SessionToken {
|
|||
MatchJournalView getJournalView();
|
||||
@NotNull()
|
||||
Iterable<Object> getRuleTags();
|
||||
@NotNull()
|
||||
Map<Object, RuleMatchingProbeState> getFrontState();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue