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 69baf96d..e1db567c 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 @@ -40,11 +40,9 @@ internal class ConstraintsProcessing( private var dispatchingFront: Dispatcher.DispatchingFront, journal: MatchJournalImpl, val logicalState: LogicalState, - override val ispec: IncrementalSpec = IncrementalSpec.DefaultSpec, val trace: EvaluationTrace = EvaluationTrace.NULL, val profiler: Profiler? = null ) : MatchJournal by journal, - LogicalStateObservable by LogicalState(), - IncrSpecHolder + LogicalStateObservable by LogicalState() { fun getFrontState(): DispatchingFrontState = dispatchingFront.state() @@ -159,7 +157,6 @@ internal class ConstraintsProcessing( * Encapsulates logic for deriving [Evidence] and [Justifications] for a new [Occurrence]. */ inner class JustifiedOccurrenceCreator( - private val savedEvidence: Evidence = evidence(), private val savedJustifications: Justifications = justifications() ) { fun Constraint.occurrence( @@ -170,14 +167,8 @@ internal class ConstraintsProcessing( ): Occurrence { // By default share justifications (as a small optimization) - var evidence = savedEvidence - var justifications = savedJustifications - - // For principal occurrences create new - if (ispec.isPrincipal(this)) { - evidence = nextEvidence() - justifications = justsCopy(savedJustifications).apply { add(evidence) } - } + val evidence = nextEvidence() + val justifications = justsCopy(savedJustifications).apply { add(evidence) } return Occurrence( observable, this, logicalContext, arguments, 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 739fcfbe..f18a1fe8 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 @@ -32,9 +32,8 @@ import jetbrains.mps.logic.reactor.util.profile internal class ControllerImpl ( val supervisor: Supervisor, val processing: ConstraintsProcessing, - override val ispec: IncrementalSpec = IncrementalSpec.DefaultSpec, val trace: EvaluationTrace = EvaluationTrace.NULL, - val profiler: Profiler? = null) : Controller, IncrSpecHolder + val profiler: Profiler? = null) : Controller { init { @@ -149,13 +148,11 @@ internal class ControllerImpl ( } val savedPos = processing.currentPos() - var newParent: MatchJournal.MatchChunk = parent + val newParent: MatchJournal.MatchChunk = savedPos.chunk as MatchJournal.MatchChunk + + // This match corresponds to the last added chunk + assert( (savedPos.chunk as? MatchJournal.MatchChunk)?.match === match ) - if (match.isPrincipal) { - // This match corresponds to the last added chunk - assert( (savedPos.chunk as? MatchJournal.MatchChunk)?.match === match ) - newParent = savedPos.chunk as MatchJournal.MatchChunk - } // fixme: fails in lambdacalc because of reactivated occurrences // (parents ain't tracked correctly in this case) // assert(newParent === processing.parentChunk()) @@ -381,11 +378,9 @@ fun createController( Dispatcher(ruleIndex).front(), MatchJournalImpl(), logicalState, - IncrementalSpec.DefaultSpec, trace, profiler ), - IncrementalSpec.DefaultSpec, 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 8847eb81..2d340422 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 @@ -32,7 +32,6 @@ internal typealias OccurrenceStore = Collection internal fun emptyStore(): OccurrenceStore = emptyList() - /** * Handles creation of the first and following sessions, * properly ending sessions and getting their results. @@ -77,7 +76,6 @@ internal data class SessionParts( internal class EvaluationSessionImpl private constructor ( - val incrementality: IncrementalSpec, val program: Program, val supervisor: Supervisor, val trace: EvaluationTrace, @@ -105,13 +103,13 @@ internal class EvaluationSessionImpl private constructor ( ?.also { it.updateIndexFromRules(program.rules()) } ?: RuleIndex(program.rules()) - val journal = MatchJournalImpl(incrementality, trace) + val journal = MatchJournalImpl(trace) val logicalState = LogicalState() val dispatchingFront = Dispatcher(ruleIndex).front() - val processing = ConstraintsProcessing(dispatchingFront, journal, logicalState, incrementality, trace, profiler) + val processing = ConstraintsProcessing(dispatchingFront, journal, logicalState, trace, profiler) - val controller = ControllerImpl(supervisor, processing, incrementality, trace, profiler) + val controller = ControllerImpl(supervisor, processing, trace, profiler) return SessionParts(ruleIndex, journal, logicalState, controller, processing, PrincipalObserverDispatcher.EMPTY) } @@ -137,8 +135,6 @@ internal class EvaluationSessionImpl private constructor ( var evaluationTrace: EvaluationTrace = EvaluationTrace.NULL - var ispec: IncrementalSpec = IncrementalSpec.DefaultSpec - var token: SessionToken? = null override fun withTrace(computingTracer: EvaluationTrace): EvaluationSession.Config { @@ -152,7 +148,6 @@ internal class EvaluationSessionImpl private constructor ( } override fun withIncrSpec(ispec: IncrementalSpec): EvaluationSession.Config { - this.ispec = ispec return this } @@ -170,7 +165,7 @@ internal class EvaluationSessionImpl private constructor ( as MutableMap? val profiler = durations?.let { Profiler() } - session = EvaluationSessionImpl(ispec, program, supervisor, evaluationTrace, profiler, parameters) + session = EvaluationSessionImpl(program, supervisor, evaluationTrace, profiler, parameters) Backend.ourBackend.ourSession.set(session) try { val main = parameters[ParameterKey.of("main", Constraint::class.java)] as Constraint diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/IncrSpecHolder.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/IncrSpecHolder.kt deleted file mode 100644 index 501177dd..00000000 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/IncrSpecHolder.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014-2020 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.Occurrence -import jetbrains.mps.logic.reactor.evaluation.RuleMatch -import jetbrains.mps.logic.reactor.program.IncrementalContractViolationException -import jetbrains.mps.logic.reactor.program.IncrementalSpec -import jetbrains.mps.logic.reactor.program.Rule - -@Deprecated("obsolete class") -interface IncrSpecHolder { - val ispec: IncrementalSpec - - val Occurrence.isPrincipal get() = ispec.isPrincipal(this.constraint()) - - val RuleMatch.isPrincipal get() = ispec.isPrincipal(this.rule()) - -// val Rule.isPrincipal get() = ispec.isPrincipal(this) - - val RuleMatch.isWeakPrincipal get() = ispec.isWeakPrincipal(this.rule()) - - val Rule.isWeakPrincipal get() = ispec.isWeakPrincipal(this) - -} 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 bfb050fe..8dc355b9 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 @@ -30,9 +30,7 @@ interface MatchJournal : EvidenceSource { // for tests companion object { - fun fromView( - ispec: IncrementalSpec = IncrementalSpec.DefaultSpec - ): MatchJournal = MatchJournalImpl(ispec, EvaluationTrace.NULL) + fun forTest(): MatchJournal = MatchJournalImpl(EvaluationTrace.NULL) } /** 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 b821e9c1..681cd491 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 @@ -31,9 +31,8 @@ import java.util.* internal open class MatchJournalImpl( - override val ispec: IncrementalSpec, val trace: EvaluationTrace = EvaluationTrace.NULL -) : MatchJournal, IncrSpecHolder { +) : MatchJournal { private abstract class ChunkImpl : Chunk { var entries: MutableList = mutableListOf() @@ -94,21 +93,12 @@ internal open class MatchJournalImpl( assert(initialChunk.match is InitRuleMatch) } - constructor(trace: EvaluationTrace = EvaluationTrace.NULL) : this(IncrementalSpec.DefaultSpec, trace) - override fun logMatch(match: RuleMatch) { - if (match.isPrincipal) { - val nextChunk = MatchChunkImpl(nextEvidence(), match) - __cursor.addChunk(nextChunk) - resetParentChunk(nextChunk) - pushParentChunk(nextChunk) - } else { - val dummy: Justified = MatchChunkImpl(nullEvidence, match) // collects justifications - resetParentChunk(dummy) - // If a non-principal match has any principal - // occurrences in head -- they must be tracked - collectJustificationsFrom(match) - } + val nextChunk = MatchChunkImpl(nextEvidence(), match) + __cursor.addChunk(nextChunk) + resetParentChunk(nextChunk) + pushParentChunk(nextChunk) + // Log discarded occurrences (match as RuleMatchImpl).forEachReplaced { occ -> __cursor.addEntryToCurrent(Chunk.Entry(occ, true)) @@ -138,7 +128,7 @@ internal open class MatchJournalImpl( val moreJustified = match.allHeads().filter { // Filter to avoid justifying parent by its child! - it.isPrincipal && !it.justifiedBy(parent) + !it.justifiedBy(parent) }.toList() if (moreJustified.isNotEmpty()) { @@ -150,9 +140,7 @@ internal open class MatchJournalImpl( override fun logActivation(occ: Occurrence) { resetParentChunk(occ) - if (occ.isPrincipal) { - __cursor.addChunk(OccChunkImpl(occ)) - } + __cursor.addChunk(OccChunkImpl(occ)) __cursor.addEntryToCurrent(Chunk.Entry(occ)) } diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationSession.java b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationSession.java index d06294a7..be061a6a 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationSession.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/evaluation/EvaluationSession.java @@ -80,6 +80,7 @@ public abstract class EvaluationSession { public Config withSessionToken(SessionToken token) { return this; } + @Deprecated(forRemoval = true) public Config withIncrSpec(IncrementalSpec ispec) { return this; } public abstract EvaluationResult start(Supervisor supervisor); diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java b/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java index 744e58ec..1c4b0b70 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java @@ -18,6 +18,7 @@ package jetbrains.mps.logic.reactor.program; import org.jetbrains.annotations.NotNull; +@Deprecated(forRemoval = true) public interface IncrementalSpec { boolean isPrincipal(Constraint ctr); diff --git a/reactor/Test/test/TestStoreAwareJournal.kt b/reactor/Test/test/TestStoreAwareJournal.kt index d9f33997..a35fd424 100644 --- a/reactor/Test/test/TestStoreAwareJournal.kt +++ b/reactor/Test/test/TestStoreAwareJournal.kt @@ -1,12 +1,10 @@ import jetbrains.mps.logic.reactor.core.* import jetbrains.mps.logic.reactor.core.internal.* import jetbrains.mps.logic.reactor.program.Constraint -import jetbrains.mps.logic.reactor.program.ConstraintSymbol import jetbrains.mps.logic.reactor.program.IncrementalSpec import jetbrains.mps.logic.reactor.program.Rule import org.junit.Test import org.junit.Assert.* -import org.junit.Ignore /* * Copyright 2014-2019 JetBrains s.r.o. @@ -27,16 +25,9 @@ import org.junit.Ignore class TestStoreAwareJournal { - private object LegacyMockIncrProgSpec : IncrementalSpec.StubSpec() { - override fun isPrincipal(ctr: Constraint): Boolean = ctr.isPrincipal - override fun isPrincipal(rule: Rule): Boolean = rule.all().any { it is Constraint && it.isPrincipal } - override fun ability(): IncrementalSpec.Enabled = IncrementalSpec.Enabled.Yes - } - private class JournalDispatcherHelper( dispatcher: Dispatcher, - ispec: IncrementalSpec = LegacyMockIncrProgSpec, - val hist: MatchJournal = MatchJournal.fromView(ispec) + val hist: MatchJournal = MatchJournal.forTest() ) { val initialJournalSize = hist.view().chunks.size @@ -153,7 +144,7 @@ class TestStoreAwareJournal { with(hist) { - view().chunks.size shouldBe 4 + initialJournalSize + view().chunks.size shouldBe 5 + initialJournalSize storeView().allOccurrences().count() shouldBe 1 // only "qux" // reset to the very beginning @@ -215,7 +206,8 @@ class TestStoreAwareJournal { logFirstMatch() logExpand("bazz") // matched on rule with heads without justifications, should remain in the same chunk - hist.currentPos().chunk shouldBeSame curChunk + // NB! the above no longer holds as the "principal" stuff has been phased out +// hist.currentPos().chunk shouldBeSame curChunk // last production from rule2 @@ -223,10 +215,10 @@ class TestStoreAwareJournal { // rule4 - hist.view().chunks.size shouldBe 3 + initialJournalSize + hist.view().chunks.size shouldBe 7 + initialJournalSize logFirstMatch() // match on the principal constraint must add the chunk - hist.view().chunks.size shouldBe 4 + initialJournalSize + hist.view().chunks.size shouldBe 8 + initialJournalSize val oldState = hist.view() @@ -235,7 +227,7 @@ class TestStoreAwareJournal { logExpandJustified("last") - hist.view().chunks.size shouldBe 5 + initialJournalSize + hist.view().chunks.size shouldBe 9 + initialJournalSize assertNotEquals(oldStore, hist.storeView().allOccurrences())