From 357560f11ffba3d82cddd927cc32bbca68b3cff7 Mon Sep 17 00:00:00 2001 From: Fedor Isakov Date: Tue, 8 Mar 2022 15:36:35 +0100 Subject: [PATCH] Drop unused obsolete stuff --- .../reactor/core/internal/ComparatorExt.kt | 25 ----- .../reactor/core/internal/JournalIterator.kt | 10 +- .../reactor/core/internal/MatchJournal.kt | 77 +--------------- .../reactor/core/internal/MatchJournalImpl.kt | 91 +------------------ .../reactor/program/IncrementalSpec.java | 14 ++- 5 files changed, 15 insertions(+), 202 deletions(-) delete mode 100644 reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ComparatorExt.kt diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ComparatorExt.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ComparatorExt.kt deleted file mode 100644 index dfd7fc6e..00000000 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ComparatorExt.kt +++ /dev/null @@ -1,25 +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 - -interface ComparatorExt: Comparator { - infix fun T.before(other: T): Boolean = compare(this, other) < 0 - infix fun T.beforeOrEq(other: T): Boolean = compare(this, other) <= 0 - - infix fun T.after(other: T): Boolean = compare(this, other) > 0 - infix fun T.afterOrEq(other: T): Boolean = compare(this, other) >= 0 -} \ No newline at end of file diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/JournalIterator.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/JournalIterator.kt index f91fae13..f70e8efc 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/JournalIterator.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/JournalIterator.kt @@ -26,22 +26,14 @@ interface ChunkReader { infix fun at(pos: MatchJournal.Pos) = current === pos.chunk infix fun at(chunk: MatchJournal.Chunk) = current === chunk - - infix fun atNext(pos: MatchJournal.Pos) = next === pos.chunk - infix fun atNext(chunk: MatchJournal.Chunk) = next === chunk } interface JournalIterator: ChunkReader, Iterator -interface RemovingJournalIterator: JournalIterator { - fun removeNext() -} - -interface MutableJournalIterator: RemovingJournalIterator { +interface MutableJournalIterator: JournalIterator { fun add(chunk: MatchJournal.Chunk) } - internal infix fun JournalIterator.assertAt(pos: MatchJournal.Pos) { if (!(this at pos)) throw IllegalStateException("Position wasn't found in journal: $pos") } 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 97c3e69f..05a6ef8f 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 @@ -62,21 +62,12 @@ interface MatchJournal : EvidenceSource { */ fun currentPos(): Pos - /** - * Indicates whether journal's pos points to its end. - */ - fun isFront(): Boolean - - - /** - * Returns read-only [JournalIterator] that allows to remove future [Chunk]s. - */ - fun iterator(): JournalIterator - /** * Returns internal [JournalIterator] that allows to remove future [Chunk]s. */ - val cursor: RemovingJournalIterator + @Deprecated("Obsolete TBR") + val cursor: JournalIterator + get() = TODO() /** * Same as [resetCursor], moves [cursor] before [initialChunk]. @@ -118,62 +109,8 @@ interface MatchJournal : EvidenceSource { */ fun storeView(): StoreView - /** - * Returns [Index] for current state of [MatchJournal]. - */ - fun index(): Index - fun basisRuleTags(chunk: Chunk): List - - /** - * Simplifies some search operations on [MatchJournal]. - * Also serves as a comparator for positions: later in journal means greater. - */ - interface Index : ComparatorExt { - - /** - * Returns [Comparator] for [Chunk]s based on their [Pos] in this [Index]. - */ - val chunkComparator: Comparator get - - /** - * Returns [true] for indexed [Chunk]s. - * [Index] is a snapshot of [MatchJournal], - * so new additions to journal aren't indexed. - */ - fun isKnown(chunk: Chunk): Boolean - - /** - * Same as [isKnown], but for [Occurrence]. - * Returns [true] for indexed [Occurrence]s. - */ - fun isKnown(occ: Occurrence): Boolean = activatingChunkOf(occ) != null - - /** - * Returns [Chunk] corresponding to [occ] activation. - * Returns null for non-principal occurrences & those not from indexed session. - */ - fun activatingChunkOf(occ: Occurrence): OccChunk? - - /** - * Returns [Pos] at which provided [RuleMatch] was triggered. - * Returns null for non-principal rules & those not from indexed session. - */ - fun activationPos(match: RuleMatchEx): OccChunk? - - /** - * Returns [MatchChunk] corresponding to [RuleMatch] where [occ] was activated. - * Returns null for non-principal occurrences & those not from indexed session. - */ - fun matchChunkOf(occChunk: OccChunk): MatchChunk? - - /** - * Length of the indexed [MatchJournal] - */ - val size: Int - } - - + /** * Immutable snapshot of [MatchJournal]. */ @@ -228,12 +165,6 @@ interface MatchJournal : EvidenceSource { */ interface MatchChunk : Chunk { - /** - * Returns true if this [Chunk] depends on changes to specified rule. - * Relevant for rules with origin. Doesn't include rule from [match]. - */ - fun dependsOnRule(utag: Any): Boolean - /** * [RuleMatch] which defines this [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 1250d5fa..536d3da9 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 @@ -40,14 +40,10 @@ internal open class MatchJournalImpl( } private class MatchChunkImpl(override val evidence: Evidence, override val match: RuleMatch) : ChunkImpl(), MatchChunk { - override fun dependsOnRule(utag: Any): Boolean = rulesWithOrigin.contains(utag) - override fun justifications(): Justifications = justifications private val justifications = match.collectJustifications(evidence) - val rulesWithOrigin = HashSet(4) - override fun toString() = "(id=$evidence, ${justifications()}, ${match.rule().uniqueTag().toString()}, $entries)" } @@ -76,7 +72,6 @@ internal open class MatchJournalImpl( // invariant: never empty private val ancestorChunksStack: MutableList - private var evidenceSeed: Evidence = 0 final override val nullEvidence: Evidence = CornerChunk.evidence @@ -105,12 +100,6 @@ internal open class MatchJournalImpl( constructor(view: MatchJournal.View? = null) : this(IncrementalSpec.DefaultSpec, view) - - override fun iterator(): JournalIterator = JournalIteratorImpl(hist.listIterator()) - - override val cursor: RemovingJournalIterator get() = __cursor - - override fun logMatch(match: RuleMatch): MatchChunk? { val added: MatchChunk? @@ -166,12 +155,6 @@ internal open class MatchJournalImpl( child.justifyByAll(moreJustified) } } - - match.rule().let { - if (it.isWeakPrincipal) { - (parent as MatchChunkImpl).rulesWithOrigin.add(it.uniqueTag()) - } - } } override fun logActivation(occ: Occurrence): OccChunk? { @@ -195,9 +178,6 @@ internal open class MatchJournalImpl( override fun currentPos(): MatchJournal.Pos = __cursor.current.toPos() - override fun isFront(): Boolean = __cursor.atEnd() - - override fun reset(pastPos: MatchJournal.Pos) { reset(pastPos, true) replay(pastPos) @@ -242,8 +222,6 @@ internal open class MatchJournalImpl( override fun storeView(): StoreView = StoreViewImpl(allOccurrences()) - override fun index(): MatchJournal.Index = IndexImpl(hist) - override fun basisRuleTags(chunk: Chunk): List { val ptags = mutableListOf() chunk.justifications().forEach { jn -> @@ -347,12 +325,6 @@ internal open class MatchJournalImpl( indexChunk(chunk) } - override fun removeNext() { - it.next() - it.remove() - updateNext() - } - /** * Walk in journal in direct order ([from] -> [current]) * while applying [action] to each visited [Chunk] @@ -414,68 +386,7 @@ internal open class MatchJournalImpl( val last: E get() = if (l is LinkedList) l.last else l.last() } - - private class IndexImpl(chunks: List): MatchJournal.Index - { - private val chunkOrder = HashMap, Int>() - private val occChunks = HashMap() - private val parentMatches = HashMap() - - init { - var index: Int = chunks.size - val orphansYet = hashSetOf() - chunks.reversed().forEach { chunk -> - if (!(chunk is CornerChunk)) { - chunkOrder[Id(chunk)] = --index - } - - when (chunk) { - is OccChunk -> { - occChunks[chunk.occ.identity] = chunk - - orphansYet.add(chunk) - } - is MatchChunk -> orphansYet.removeIf{ orphan -> - // first met justifying MatchChunk is parent - if (orphan.justifiedBy(chunk)) { - parentMatches[orphan] = chunk - true - } else false - } - } - } - } - - override val size: Int = chunks.size - - override fun isKnown(chunk: Chunk): Boolean = chunkOrder.containsKey(Id(chunk)) - - override fun activatingChunkOf(occ: Occurrence) = occChunks[occ.identity] - - override fun activationPos(match: RuleMatchEx): OccChunk? = - // The latest matched occurrence from match's head is (by definition) - // the occurrence which activated this match. - match.allHeads() - .mapNotNull(this::activatingChunkOf) - .maxBy { orderOf(it)!! } // compare positions: find latest - - override fun matchChunkOf(occChunk: OccChunk): MatchChunk? = parentMatches[occChunk] - - override val chunkComparator: Comparator get() = compareBy(this::orderOfThrow) - - override fun compare(lhs: Pos, rhs: Pos): Int = - compareBy{ orderOfThrow(it.chunk) } - .thenComparingInt { it.entriesCount } - .compare(lhs, rhs) - - private fun orderOf(chunk: Chunk): Int? = chunkOrder[Id(chunk)] - - private fun orderOfThrow(chunk: Chunk): Int = when (val ord = orderOf(chunk)) { - null -> throw IllegalStateException("Chunk (${chunk.evidence}) must be known by journal index!") - else -> ord - } - } - + /** * Mock RuleMatch for use only in initial Chunk */ 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 570c84b6..744e58ec 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/program/IncrementalSpec.java @@ -22,15 +22,19 @@ public interface IncrementalSpec { boolean isPrincipal(Constraint ctr); boolean isPrincipal(Rule rule); - boolean isWeakPrincipal(Rule rule); + + @Deprecated(forRemoval = true) + default boolean isWeakPrincipal(Rule rule) {return false; } @NotNull - Enabled ability(); + @Deprecated(forRemoval = true) + default Enabled ability() { throw new UnsupportedOperationException(); } @NotNull - IncrLevel incrLevel(); + @Deprecated(forRemoval = true) + default IncrLevel incrLevel() { throw new UnsupportedOperationException(); } @NotNull - AssertLevel assertLevel(); - + @Deprecated(forRemoval = true) + default AssertLevel assertLevel() { throw new UnsupportedOperationException(); } enum IncrLevel { Preamble, Full;