Revert "MPSCR-4: Upd refs to new RuleIndex on Dispatcher construction in incremental case."

This reverts commit 0dd7f8c70f.
This commit is contained in:
Fedor Isakov 2019-11-04 15:58:54 +01:00
parent 0dd7f8c70f
commit a0b2af95c9
9 changed files with 41 additions and 61 deletions

View File

@ -5067,26 +5067,22 @@
</node>
</node>
</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 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>
</node>
<node concept="liA8E" id="7smgEqgB$P1" role="2OqNvi">
<ref role="37wK5l" to="mhbf:~SNode.getReference()" resolve="getReference" />
</node>
</node>
</node>
</node>
@ -5094,14 +5090,6 @@
</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" />

View File

@ -45,7 +45,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JB SDK 11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JB JDK 11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -17,24 +17,21 @@
package jetbrains.mps.logic.reactor.core
typealias DispatchingFrontState = Map<Any, RuleMatcher>
typealias DispatchingFrontState = Map<Any, RuleMatchingProbe>
/**
* A front-end interface to [RuleMatcher].
*
* @author Fedor Isakov
*/
class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = emptyMap()) {
class Dispatcher (val ruleIndex: RuleIndex) {
private val ruletag2matcher = HashMap<Any, RuleMatcher>()
init {
ruleIndex.forEach { rule ->
val ruletag = rule.uniqueTag()
// reset references to stale RuleIndex instances
val matcher = prevState[ruletag]?.apply { setRuleLookup(ruleIndex) }
?: createRuleMatcher(ruleIndex, ruletag)
ruletag2matcher.put(ruletag, matcher);
val matcher = createRuleMatcher(ruleIndex, rule.uniqueTag())
ruletag2matcher.put(rule.uniqueTag(), matcher);
}
}
@ -43,6 +40,8 @@ class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = e
*/
fun front() = DispatchingFront()
fun frontFromState(predState: DispatchingFrontState) = DispatchingFront(predState)
inner class DispatchingFront {
private val ruletag2probe : HashMap<Any, RuleMatchingProbe>
@ -57,6 +56,14 @@ class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = e
}
}
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
@ -76,7 +83,7 @@ class Dispatcher (val ruleIndex: RuleIndex, prevState: DispatchingFrontState = e
return allMatches
}
fun state() : DispatchingFrontState = ruletag2matcher //.asMap()
fun state() : DispatchingFrontState = ruletag2probe //.asMap()
/**
* Returns a [DispatchingFront] instance that is "expanded" with matches corresponding to the

View File

@ -26,19 +26,14 @@ import jetbrains.mps.logic.reactor.program.Rule
* Abstracts a rule matching algorithm.
*
* A RuleMatcher corresponds to a single rule.
* 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.
* The method [probe] provides a factory of [RuleMatchingProbe], which is the main handler of match operations.
*
* @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)

View File

@ -47,10 +47,11 @@ 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(ruleIndex).front(),
dispatcher.front(),
MatchJournalImpl(ispec),
ruleIndex, ispec, trace, profiler
)
@ -61,7 +62,7 @@ internal class EvaluationSessionImpl private constructor (
} else {
val tkn = token as SessionTokenImpl
val state = ProcessingStateImpl(
Dispatcher(ruleIndex, tkn.getFrontState()).front(),
dispatcher.frontFromState(tkn.frontState),
MatchJournalImpl(ispec, tkn.journalView),
ruleIndex, ispec, trace, profiler
)

View File

@ -41,7 +41,7 @@ fun footprintOf(): Footprint = TIntHashSet()
fun Signature.toFootprint() = TIntHashSet(this)
internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup,
internal class ReteRuleMatcherImpl(private val ruleLookup: RuleLookup,
private val tag: Any) : RuleMatcher
{
@ -51,13 +51,7 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup,
fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'")
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
override fun probe(): ReteNetwork = ReteNetwork(head.size)
inner class ReteNetwork(val headSize: Int) : RuleMatchingProbe {

View File

@ -33,7 +33,7 @@ import kotlin.collections.ArrayList
*
* @author Fedor Isakov
*/
internal class RuleMatcherImpl(private var ruleLookup: RuleLookup,
internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
private val tag: Any) : RuleMatcher
{
@ -43,19 +43,12 @@ internal class RuleMatcherImpl(private var ruleLookup: RuleLookup,
fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'")
override fun setRuleLookup(ruleLookup: RuleLookup) { this.ruleLookup = ruleLookup }
override fun newProbe(): RuleMatchingProbe =
override fun probe(): 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>,

View File

@ -27,5 +27,5 @@ data class SessionTokenImpl(
) : SessionToken {
override fun getJournalView(): MatchJournalView = journalView
override fun getRuleTags(): Iterable<Any> = ruleTags
fun getFrontState(): DispatchingFrontState = frontState
override fun getFrontState(): DispatchingFrontState = frontState
}

View File

@ -24,4 +24,6 @@ public interface SessionToken {
MatchJournalView getJournalView();
@NotNull()
Iterable<Object> getRuleTags();
@NotNull()
Map<Object, RuleMatchingProbeState> getFrontState();
}