Drop unused obsolete stuff

This commit is contained in:
Fedor Isakov 2022-03-08 15:36:35 +01:00
parent 945088f72e
commit 357560f11f
5 changed files with 15 additions and 202 deletions

View File

@ -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<T>: Comparator<T> {
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
}

View File

@ -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<MatchJournal.Chunk>
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")
}

View File

@ -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<Any>
/**
* Simplifies some search operations on [MatchJournal].
* Also serves as a comparator for positions: later in journal means greater.
*/
interface Index : ComparatorExt<Pos> {
/**
* Returns [Comparator] for [Chunk]s based on their [Pos] in this [Index].
*/
val chunkComparator: Comparator<Chunk> 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]
*/

View File

@ -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<Any>(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<MatchChunk>
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<Any> {
val ptags = mutableListOf<Any>()
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<E>) l.last else l.last()
}
private class IndexImpl(chunks: List<Chunk>): MatchJournal.Index
{
private val chunkOrder = HashMap<Id<Chunk>, Int>()
private val occChunks = HashMap<Int, OccChunk>()
private val parentMatches = HashMap<OccChunk, MatchChunk>()
init {
var index: Int = chunks.size
val orphansYet = hashSetOf<OccChunk>()
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<Chunk> get() = compareBy<Chunk>(this::orderOfThrow)
override fun compare(lhs: Pos, rhs: Pos): Int =
compareBy<Pos>{ 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
*/

View File

@ -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;