diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt index f70a99d2..0dc47ed2 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ConstraintsProcessing.kt @@ -42,11 +42,10 @@ internal class ConstraintsProcessing( val logicalState: LogicalState, override val ispec: IncrementalSpec = IncrementalSpec.DefaultSpec, val trace: EvaluationTrace = EvaluationTrace.NULL, - val profiler: Profiler? = null - - // fixme: can get rid of inheritance from journal, use composition instead -) : StoreAwareJournalImpl(journal, logicalState), IncrSpecHolder { - + val profiler: Profiler? = null ) : MatchJournal by journal, + LogicalStateObservable by LogicalState(), + IncrSpecHolder +{ fun getFrontState(): DispatchingFrontState = dispatchingFront.state() fun engage(controller: Controller) { 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 bd73a054..bfc93baa 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 @@ -28,6 +28,14 @@ typealias ChunkIndex = TIntObjectHashMap interface MatchJournal : EvidenceSource { + // for tests + companion object { + fun fromView( + ispec: IncrementalSpec = IncrementalSpec.DefaultSpec, + view: MatchJournal.View? = null + ): MatchJournal = MatchJournalImpl(ispec, EvaluationTrace.NULL, view) + } + /** * Add new [Chunk] for matches of principal rules. * Log occurrences discarded by match in current [Chunk]. diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournalImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournalImpl.kt index bd943fbe..b13266c2 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournalImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/MatchJournalImpl.kt @@ -19,6 +19,7 @@ package jetbrains.mps.logic.reactor.core.internal import jetbrains.mps.logic.reactor.core.* import jetbrains.mps.logic.reactor.core.internal.MatchJournal.* import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence +import jetbrains.mps.logic.reactor.evaluation.EvaluationTrace import jetbrains.mps.logic.reactor.evaluation.RuleMatch import jetbrains.mps.logic.reactor.evaluation.StoreView import jetbrains.mps.logic.reactor.logical.Logical @@ -31,6 +32,7 @@ import java.util.* internal open class MatchJournalImpl( override val ispec: IncrementalSpec, + val trace: EvaluationTrace = EvaluationTrace.NULL, view: MatchJournal.View? = null ) : MatchJournal, IncrSpecHolder { @@ -98,7 +100,8 @@ internal open class MatchJournalImpl( assert(initialChunk.match is InitRuleMatch) } - constructor(view: MatchJournal.View? = null) : this(IncrementalSpec.DefaultSpec, view) + constructor(trace: EvaluationTrace = EvaluationTrace.NULL, + view: MatchJournal.View? = null) : this(IncrementalSpec.DefaultSpec, trace, view) override fun logMatch(match: RuleMatch): MatchChunk? { val added: MatchChunk? diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt deleted file mode 100644 index 0f06d877..00000000 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014-2019 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.mps.logic.reactor.core.internal - -import jetbrains.mps.logic.reactor.core.LogicalStateObservable -import jetbrains.mps.logic.reactor.program.IncrementalSpec -import java.lang.IllegalArgumentException - - -/** - * [MatchJournal] which also maintains observers in [LogicalStateObservable] in sync with its current position. - */ -interface StoreAwareJournal : MatchJournal, LogicalStateObservable { - - // for tests - companion object { - fun fromView( - ispec: IncrementalSpec = IncrementalSpec.DefaultSpec, - view: MatchJournal.View? = null - ): StoreAwareJournal = StoreAwareJournalImpl(MatchJournalImpl(ispec, view)) - } -} - - -internal open class StoreAwareJournalImpl(private val journal: MatchJournal, - private val logicalState: LogicalState = LogicalState()) - : MatchJournal by journal, StoreAwareJournal, LogicalStateObservable by logicalState -{ - - private class FramePos( - chunk: MatchJournal.Chunk, - entriesCount: Int = 0 - ) : MatchJournal.Pos(chunk, entriesCount) - - override fun currentPos(): MatchJournal.Pos = - FramePos(journal.currentPos().chunk, journal.currentPos().entriesCount) - - // Throw away recently added chunks and reset store accordingly - // NB: not checking that chunks are actually recently added, from this exec session - override fun reset(pastPos: MatchJournal.Pos) { - if (pastPos is FramePos) { - journal.reset(pastPos) - } else { - throw IllegalArgumentException() - } - } -} \ No newline at end of file diff --git a/reactor/Test/test/TestStoreAwareJournal.kt b/reactor/Test/test/TestStoreAwareJournal.kt index 114b2470..d9f33997 100644 --- a/reactor/Test/test/TestStoreAwareJournal.kt +++ b/reactor/Test/test/TestStoreAwareJournal.kt @@ -36,7 +36,7 @@ class TestStoreAwareJournal { private class JournalDispatcherHelper( dispatcher: Dispatcher, ispec: IncrementalSpec = LegacyMockIncrProgSpec, - val hist: StoreAwareJournal = StoreAwareJournal.fromView(ispec) + val hist: MatchJournal = MatchJournal.fromView(ispec) ) { val initialJournalSize = hist.view().chunks.size