diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt index 2affcc3a..7f54d051 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ControllerImpl.kt @@ -309,7 +309,14 @@ fun createController( ControllerImpl( supervisor, - ProcessingStateImpl(Dispatcher(ruleIndex).front(), MatchJournalImpl(), ruleIndex, trace, profiler), + ProcessingStateImpl( + Dispatcher(ruleIndex).front(), + MatchJournalImpl(), + ruleIndex, + IncrementalProgramSpec.NonIncrSpec, + trace, + profiler + ), IncrementalProgramSpec.NonIncrSpec, trace, profiler diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt index ebe32615..953e822e 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/EvaluationSessionImpl.kt @@ -53,7 +53,7 @@ internal class EvaluationSessionImpl private constructor ( val dispatcher = Dispatcher(ruleIndex) if (ispec is IncrementalProgramSpec.NonIncrSpec || token == null) { - val state = ProcessingStateImpl(dispatcher.front(), MatchJournalImpl(ispec), ruleIndex, trace, profiler) + val state = ProcessingStateImpl(dispatcher.front(), MatchJournalImpl(ispec), ruleIndex, ispec, trace, profiler) this.controller = ControllerImpl(supervisor, state, ispec, trace, profiler) return controller.activate(main) @@ -62,7 +62,7 @@ internal class EvaluationSessionImpl private constructor ( val state = ProcessingStateImpl( dispatcher.frontFromState(token.frontState), MatchJournalImpl(ispec, token.journalView), - ruleIndex, trace, profiler + ruleIndex, ispec, trace, profiler ) val rulesDiff = RulesDiff.findDiff(token.ruleTags, ruleIndex) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt index 5f634eb2..18fa9665 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournal.kt @@ -73,9 +73,6 @@ interface MatchJournal : MutableIterable { } }.map { it.wrapped } - abstract fun findOccurrence(ctr: Constraint): Occurrence? - abstract fun principalOccurrence(): Occurrence? - override fun toString() = "(id=$id, $justifications, ${match.rule().uniqueTag()}, ${entriesLog()})" override fun chunk(): Chunk = this @@ -114,7 +111,7 @@ interface MatchJournal : MutableIterable { internal open class MatchJournalImpl( - protected val ispec: IncrementalProgramSpec, + private val ispec: IncrementalProgramSpec, view: MatchJournal.View? = null ) : MatchJournal { @@ -126,7 +123,7 @@ internal open class MatchJournalImpl( if (view == null) { hist = LinkedList() nextChunkId = 0 - val initChunk = ChunkImpl(ispec, InitRuleMatch, nextChunkId, justsOf(nextChunkId)) + val initChunk = ChunkImpl(InitRuleMatch, nextChunkId, justsOf(nextChunkId)) nextChunkId++ hist.add(initChunk) } else { @@ -153,7 +150,7 @@ internal open class MatchJournalImpl( if (ispec.isPrincipal(match.rule()) || !justs.isEmpty) { justs.add(nextChunkId) - val newChunk = ChunkImpl(ispec, match, nextChunkId, justs) + val newChunk = ChunkImpl(match, nextChunkId, justs) pos.add(newChunk) ++nextChunkId @@ -237,18 +234,11 @@ internal open class MatchJournalImpl( } - // todo: remove ispec from there - private class ChunkImpl(val ispec: IncrementalProgramSpec, match: RuleMatch, id: Int, justifications: Justs) : MatchJournal.Chunk(match, id, justifications) + private class ChunkImpl(match: RuleMatch, id: Int, justifications: Justs) : MatchJournal.Chunk(match, id, justifications) { var occurrences: MutableList = mutableListOf() override fun entriesLog(): List = occurrences - - override fun findOccurrence(ctr: Constraint): Occurrence? = - activatedLog().find { it.constraint.symbol() == ctr.symbol() } - - override fun principalOccurrence(): Occurrence? = - activatedLog().find { ispec.isPrincipal(it.constraint) } } class IndexImpl(ispec: IncrementalProgramSpec, chunks: Iterable): MatchJournal.Index 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 1347720d..2de3a1b2 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 @@ -44,6 +44,7 @@ import java.util.* internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.DispatchingFront, journal: MatchJournalImpl, ruleIndex: RuleIndex, + private val ispec: IncrementalProgramSpec = IncrementalProgramSpec.NonIncrSpec, val trace: EvaluationTrace = EvaluationTrace.NULL, val profiler: Profiler? = null) : StoreAwareJournalImpl(journal) @@ -68,17 +69,6 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp // fixme: wtf, why idea's compiler complains??? override fun index(): MatchJournal.Index = journalIndex - // only for tests - fun pushActivateFirstOccOf(ctr: Constraint): Boolean { - val pos = currentPos() - val occ = pos.chunk().findOccurrence(ctr) - if (occ != null) { - execQueue.offer(ExecPos(pos, occ)) - return true - } - return false - } - fun invalidateByRules(ruleIds: Set) { val justificationRoots = mutableListOf() @@ -358,8 +348,10 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp } - // TODO: provide ispec to ProcessingStateImpl and use it - private fun Occurrence.isPrincipal() = this.constraint().isPrincipal() + private fun MatchJournal.Chunk.principalOccurrence(): Occurrence? = + activatedLog().find { ispec.isPrincipal(it.constraint) } + + private fun Occurrence.isPrincipal() = ispec.isPrincipal(this.constraint()) private fun Justs.intersects(other: Iterable): Boolean = other.any { this.contains(it) }