Move RulesDiff construction from reactor to coderules runtime.

This commit is contained in:
Grigorii Kirgizov 2019-07-09 16:09:48 +03:00 committed by Fedor Isakov
parent a2672ad20a
commit 5414fe7e67
6 changed files with 33 additions and 7 deletions

View File

@ -34,11 +34,11 @@ data class RulesDiff(
val oldSet = old.toHashSet()
val newSet = new.toHashSet()
val added = new.filter { !oldSet.contains(it.uniqueTag()) }
val removed = oldSet.minus(newSet.map { it.uniqueTag() })
val added: List<Rule> = new.filter { !oldSet.contains(it.uniqueTag()) }
val removed: Set<Any> = oldSet.minus(newSet.map { it.uniqueTag() })
val removedDeps = HashSet<Any>()
for (rule in new) {
for (rule in added) {
for (depRule in ruleDeps.getDependentRules(rule)) {
if (!removed.contains(depRule)) {
removedDeps.add(depRule)

View File

@ -42,7 +42,11 @@ internal class EvaluationSessionImpl private constructor (
override fun controller() = controller
private fun incrLaunch(main: Constraint, profiler: Profiler?, token: SessionToken?, ispec: IncrementalProgramSpec) : FeedbackStatus {
private fun launch(
main: Constraint, profiler: Profiler?,
token: SessionToken?, rulesDiff: RulesDiff, ispec: IncrementalProgramSpec
) : FeedbackStatus {
val ruleIndex = RuleIndex(program().handlers())
val dispatcher = Dispatcher(ruleIndex)
@ -64,7 +68,6 @@ internal class EvaluationSessionImpl private constructor (
ruleIndex, ispec, trace, profiler
)
val rulesDiff = RulesDiff.findDiff(tkn.ruleTags, ruleIndex)
this.controller = ControllerImpl(supervisor, state, ispec, trace, profiler)
return controller.incrLaunch(main, rulesDiff)
}
@ -80,6 +83,8 @@ internal class EvaluationSessionImpl private constructor (
var token: SessionToken? = null
var rulesDiff: RulesDiff = RulesDiff.emptyDiff()
override fun withTrace(computingTracer: EvaluationTrace): EvaluationSession.Config {
this.evaluationTrace = computingTracer
return this
@ -93,6 +98,12 @@ internal class EvaluationSessionImpl private constructor (
this.token = token
return this
}
override fun withRulesDiff(rulesDiff: RulesDiff): EvaluationSession.Config {
this.rulesDiff = rulesDiff
return this
}
override fun withIncrSpec(ispec: IncrementalProgramSpec): EvaluationSession.Config {
this.ispec = ispec
return this
@ -117,7 +128,7 @@ internal class EvaluationSessionImpl private constructor (
var failure: Feedback? = null
try {
val main = parameters[ParameterKey.of("main", Constraint::class.java)] as Constraint
val status = session.incrLaunch(main, profiler, token, ispec)
val status = session.launch(main, profiler, token, rulesDiff, ispec)
if (status is FAILED) {
failure = status.failure
}

View File

@ -71,12 +71,12 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp
private data class MatchCandidate(val rule: Rule, val occChunk: MatchJournal.OccChunk)
fun invalidateDependentRules(ruleIds: Set<Any>) {
val it = this.iterator()
while (it.hasNext()) {
val chunk = it.next()
if (chunk is MatchJournal.MatchChunk && ruleIds.contains(chunk.match.rule().uniqueTag())) {
trace.invalidate(chunk.match)
it.remove()
}
}

View File

@ -17,6 +17,7 @@
package jetbrains.mps.logic.reactor.evaluation;
import jetbrains.mps.logic.reactor.core.RulesDiff;
import jetbrains.mps.logic.reactor.program.IncrementalProgramSpec;
import jetbrains.mps.logic.reactor.program.Program;
@ -97,6 +98,8 @@ public abstract class EvaluationSession {
public Config withSessionToken(SessionToken token) { return this; }
public Config withRulesDiff(RulesDiff rulesDiff) { return this; }
public Config withIncrSpec(IncrementalProgramSpec ispec) { return this; }
public abstract EvaluationResult start(Supervisor supervisor);

View File

@ -16,6 +16,7 @@
package jetbrains.mps.logic.reactor.program;
import java.util.ArrayList;
/**
* A collection of handlers that constitute a constraint rules program.
@ -29,4 +30,13 @@ public abstract class Program {
public abstract Iterable<RulesList> handlers();
public Iterable<Rule> rules() {
ArrayList<Rule> allRules = new ArrayList<Rule>();
for (RulesList rulesList : handlers()) {
for (Rule rule : rulesList.rules()) {
allRules.add(rule);
}
}
return allRules;
};
}

View File

@ -1,6 +1,7 @@
import jetbrains.mps.logic.reactor.program.IncrementalProgramSpec
import jetbrains.mps.logic.reactor.core.Occurrence
import jetbrains.mps.logic.reactor.core.ReactorLifecycle
import jetbrains.mps.logic.reactor.core.RulesDiff
import jetbrains.mps.logic.reactor.core.internal.MatchJournal
import jetbrains.mps.logic.reactor.evaluation.SessionToken
import jetbrains.mps.logic.reactor.evaluation.EvaluationResult
@ -66,6 +67,7 @@ class TestIncrementalProgram {
.withParameter(EvaluationSession.ParameterKey.of("main", Constraint::class.java), MockConstraint(ConstraintSymbol("main", 0)))
.withIncrSpec(incrSpec)
.withSessionToken(sessionToken)
.withRulesDiff(RulesDiff.findDiff(sessionToken.ruleTags, this.rules))
.start(MockSupervisor())
result.feedback()?.let { if (it.isFailure) throw it.failureCause() }
resultHandler(result)