minor: remove usages of Constraint.isPrincipal in ProcessingStateImpl, use IncrementalProgramSpec instead
This commit is contained in:
parent
ae20c334b4
commit
0bfe9e8a47
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -73,9 +73,6 @@ interface MatchJournal : MutableIterable<MatchJournal.Chunk> {
|
|||
}
|
||||
}.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<MatchJournal.Chunk> {
|
|||
|
||||
|
||||
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<MatchJournal.Chunk.Entry> = mutableListOf()
|
||||
|
||||
override fun entriesLog(): List<MatchJournal.Chunk.Entry> = 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.Chunk>): MatchJournal.Index
|
||||
|
|
|
|||
|
|
@ -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<Any>) {
|
||||
val justificationRoots = mutableListOf<Int>()
|
||||
|
||||
|
|
@ -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<Int>): Boolean = other.any { this.contains(it) }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue