Deprecate RulesDiff, introduce replacement methods in Program.

This commit is contained in:
Fedor Isakov 2020-12-06 18:04:16 +01:00
parent d637bed114
commit da9814a18d
4 changed files with 28 additions and 7 deletions

View File

@ -19,6 +19,7 @@ package jetbrains.mps.logic.reactor.core
import jetbrains.mps.logic.reactor.program.Rule
@Deprecated("superfluous")
class RulesDiff(
preserved: Iterable<Rule>,
val added: Iterable<Rule>,

View File

@ -147,7 +147,7 @@ internal class EvaluationSessionImpl private constructor (
val processing = ConstraintsProcessing(front, journal, logicalState, incrementality, trace, profiler)
val processingStrategy = IncrementalProcessing(
incrementality, journal, program.incrementalDiff(), processing.getStateCleaner(), ruleIndex, trace
incrementality, journal, program.newRules(), program.droppedRules(), processing.getStateCleaner(), ruleIndex, trace
)
processing.setStrategy(processingStrategy)
@ -187,7 +187,7 @@ internal class EvaluationSessionImpl private constructor (
val processing = ConstraintsProcessing(front, journal, logicalState, incrementality, trace, profiler)
val processingStrategy = PreambleProcessing(
incrementality, journal, program.incrementalDiff(), ruleIndex, trace
incrementality, journal, program.newRules(), ruleIndex, trace
)
processing.setStrategy(processingStrategy)

View File

@ -20,6 +20,7 @@ import jetbrains.mps.logic.reactor.core.*
import jetbrains.mps.logic.reactor.evaluation.EvaluationTrace
import jetbrains.mps.logic.reactor.program.Constraint
import jetbrains.mps.logic.reactor.program.IncrementalSpec
import jetbrains.mps.logic.reactor.program.Rule
/**
* Facade interface for incremental processing.
@ -91,7 +92,8 @@ internal class NonIncrementalProcessing: ProcessingStrategy {
internal class IncrementalProcessing(
override val ispec: IncrementalSpec,
val journal: MatchJournal,
rulesDiff: RulesDiff,
newRules: Iterable<Rule>,
droppedRules: Iterable<Any>,
stateCleaner: ConstraintsProcessing.ProgramStateCleaner,
ruleIndex: RuleIndex,
trace: EvaluationTrace
@ -101,8 +103,8 @@ internal class IncrementalProcessing(
private val ruleOrdering = RuleOrdering(ruleIndex)
private val continuator = ContinueOccurrencesStage(ispec, journalIndex)
private val invalidator = InvalidationStage(ispec, rulesDiff.removed, continuator, stateCleaner, trace)
private val adder = AdditionStage(ispec, rulesDiff.added, continuator, ruleOrdering, ruleIndex, trace)
private val invalidator = InvalidationStage(ispec, droppedRules.toSet(), continuator, stateCleaner, trace)
private val adder = AdditionStage(ispec, newRules, continuator, ruleOrdering, ruleIndex, trace)
private val postponer = PostponeMatchesStage(ispec, journal, journalIndex, ruleOrdering)
@ -180,7 +182,7 @@ internal class IncrementalProcessing(
internal class PreambleProcessing(
override val ispec: IncrementalSpec,
val journal: MatchJournal,
rulesDiff: RulesDiff,
newRules: Iterable<Rule>,
ruleIndex: RuleIndex,
trace: EvaluationTrace
): ProcessingStrategy, IncrSpecHolder {
@ -189,7 +191,7 @@ internal class PreambleProcessing(
private val ruleOrdering = RuleOrdering(ruleIndex)
private val continuator = ContinueOccurrencesStage(ispec, journalIndex)
private val adder = AdditionStage(ispec, rulesDiff.added, continuator, ruleOrdering, ruleIndex, trace)
private val adder = AdditionStage(ispec, newRules, continuator, ruleOrdering, ruleIndex, trace)
override fun invalidatedFeedback(): FeedbackKeySet = emptySet()

View File

@ -16,6 +16,7 @@
package jetbrains.mps.logic.reactor.program;
import javaslang.collection.List;
import javaslang.collection.Stream;
import jetbrains.mps.logic.reactor.core.RulesDiff;
@ -36,8 +37,10 @@ public abstract class Program {
public abstract PreambleInfo preambleInfo();
@Deprecated
public Program withRulesDiff(RulesDiff diff) { return this; };
@Deprecated
public RulesDiff incrementalDiff() { return RulesDiff.emptyDiff(); };
public Iterable<Rule> rules() {
@ -49,4 +52,19 @@ public abstract class Program {
}
return allRules;
};
/**
* Returns rules that have been created since the last evaluation of this program.
*/
public Iterable<Rule> newRules () {
return incrementalDiff().getAdded();
}
/**
* Returns objects that identify rules removed from the previous invocation.
*/
public Iterable<Object> droppedRules() {
return incrementalDiff().getRemoved();
}
}