diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchHistory.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchHistory.kt index 586b56e9..cd9b94e3 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchHistory.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchHistory.kt @@ -19,8 +19,11 @@ package jetbrains.mps.logic.reactor.core.internal import gnu.trove.set.TIntSet import gnu.trove.set.hash.TIntHashSet import jetbrains.mps.logic.reactor.core.Occurrence +import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence import jetbrains.mps.logic.reactor.evaluation.RuleMatch import jetbrains.mps.logic.reactor.evaluation.StoreView +import jetbrains.mps.logic.reactor.program.ConstraintSymbol +import jetbrains.mps.logic.reactor.util.Id import java.util.* import kotlin.collections.ArrayList @@ -28,6 +31,7 @@ import kotlin.collections.ArrayList interface MatchHistory { data class View(val chunks: List, val nextChunkId: Int) + data class Chunk(val match: RuleMatch, val id: Int, val justifications: TIntSet) { data class Entry(val occ: Occurrence, val isDiscarded: Boolean = false) { override fun toString() = (if (isDiscarded) '-' else '+') + occ.toString() @@ -106,7 +110,15 @@ internal class MatchHistoryImpl(val state: ProcessingStateImpl, view: MatchHisto } // TODO: - override fun storeView(): StoreView = state.storeView() + override fun storeView(): StoreView = StoreViewImpl(allOccurrences()) + + private fun allOccurrences(): Sequence { + val set = HashSet>() + hist.flatMap { it.occurrences } .forEach { + if (it.isDiscarded) set.add(Id(it.occ)) else set.remove(Id(it.occ)) + } + return set.map { it.wrapped }.asSequence() + } override fun view() = MatchHistory.View(ArrayList(hist), nextChunkId) @@ -192,6 +204,22 @@ internal class MatchHistoryImpl(val state: ProcessingStateImpl, view: MatchHisto // fixme: does belong to here? // fun resetOrder() { order = hist.mapToIndex() } + + + private class StoreViewImpl(occurrences: Sequence) : StoreView { + + val allOccurrences = occurrences.toSet() + + val allSymbols = allOccurrences.map { co -> co.constraint().symbol() }.toSet() + + override fun constraintSymbols(): Iterable = allSymbols + + override fun allOccurrences(): Iterable = allOccurrences + + override fun occurrences(symbol: ConstraintSymbol): Iterable = + allOccurrences.filter { co -> co.constraint().symbol() == symbol }.toSet() + + } } private fun RuleMatch.headJustifications(): TIntSet { diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt index af6f71a3..03bf3f35 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt @@ -106,35 +106,4 @@ internal class ProcessingStateImpl private constructor(val trace: EvaluationTrac // forward to the top frame currentFrame().parentUpdated(logical) } - - fun storeView(): StoreView = - StoreViewImpl(allOccurrences()) - - private fun allOccurrences(): Sequence { - val dit = stateFrames.descendingIterator() - val set = HashSet>() - while (dit.hasNext()) { - val stateFrame = dit.next() - stateFrame.allActivated().forEach { set.add(Id(it)) } - stateFrame.allDeactivated().forEach { set.remove(Id(it)) } - } - return set.map { it.wrapped }.asSequence() - } - - private class StoreViewImpl(occurrences: Sequence) : StoreView { - - val allOccurrences = occurrences.toSet() - - val allSymbols = allOccurrences.map { co -> co.constraint().symbol() }.toSet() - - override fun constraintSymbols(): Iterable = allSymbols - - override fun allOccurrences(): Iterable = allOccurrences - - override fun occurrences(symbol: ConstraintSymbol): Iterable = - allOccurrences.filter { co -> co.constraint().symbol() == symbol }.toSet() - - } - - } \ No newline at end of file diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StateFrame.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StateFrame.kt index 1c861e4a..6a4d7232 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StateFrame.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StateFrame.kt @@ -45,10 +45,6 @@ internal class StateFrame private constructor(val state: ProcessingStateImpl) : private var observers: PersMap>, ConsList> = Maps.of() - private val activatedOccurrences = ArrayList(4) - - private val deactivatedOccurrences = ArrayList(4) - constructor(state: ProcessingStateImpl, dispatcher: Dispatcher) : this(state) { this.dispatchingFront = dispatcher.front() } @@ -95,12 +91,6 @@ internal class StateFrame private constructor(val state: ProcessingStateImpl) : } } - fun allActivated() : Sequence = - activatedOccurrences.asSequence() - - fun allDeactivated() : Sequence = - deactivatedOccurrences.asSequence() - /** * Called to update the state with the currently active constraint occurrence. * Calls the controller to process matches (if any) that were triggered. @@ -119,7 +109,6 @@ internal class StateFrame private constructor(val state: ProcessingStateImpl) : state.trace.reactivate(active) } - activatedOccurrences += active this.dispatchingFront = dispatchingFront.expand(active) val outStatus = dispatchingFront.matches().toList().fold(inStatus) { status, match -> @@ -167,7 +156,6 @@ internal class StateFrame private constructor(val state: ProcessingStateImpl) : match.forEachReplaced { occ -> this.dispatchingFront = dispatchingFront.contract(occ) - deactivatedOccurrences += occ occ.stored = false occ.terminate()