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(
|
ControllerImpl(
|
||||||
supervisor,
|
supervisor,
|
||||||
ProcessingStateImpl(Dispatcher(ruleIndex).front(), MatchJournalImpl(), ruleIndex, trace, profiler),
|
ProcessingStateImpl(
|
||||||
|
Dispatcher(ruleIndex).front(),
|
||||||
|
MatchJournalImpl(),
|
||||||
|
ruleIndex,
|
||||||
|
IncrementalProgramSpec.NonIncrSpec,
|
||||||
|
trace,
|
||||||
|
profiler
|
||||||
|
),
|
||||||
IncrementalProgramSpec.NonIncrSpec,
|
IncrementalProgramSpec.NonIncrSpec,
|
||||||
trace,
|
trace,
|
||||||
profiler
|
profiler
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ internal class EvaluationSessionImpl private constructor (
|
||||||
val dispatcher = Dispatcher(ruleIndex)
|
val dispatcher = Dispatcher(ruleIndex)
|
||||||
|
|
||||||
if (ispec is IncrementalProgramSpec.NonIncrSpec || token == null) {
|
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)
|
this.controller = ControllerImpl(supervisor, state, ispec, trace, profiler)
|
||||||
return controller.activate(main)
|
return controller.activate(main)
|
||||||
|
|
@ -62,7 +62,7 @@ internal class EvaluationSessionImpl private constructor (
|
||||||
val state = ProcessingStateImpl(
|
val state = ProcessingStateImpl(
|
||||||
dispatcher.frontFromState(token.frontState),
|
dispatcher.frontFromState(token.frontState),
|
||||||
MatchJournalImpl(ispec, token.journalView),
|
MatchJournalImpl(ispec, token.journalView),
|
||||||
ruleIndex, trace, profiler
|
ruleIndex, ispec, trace, profiler
|
||||||
)
|
)
|
||||||
|
|
||||||
val rulesDiff = RulesDiff.findDiff(token.ruleTags, ruleIndex)
|
val rulesDiff = RulesDiff.findDiff(token.ruleTags, ruleIndex)
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,6 @@ interface MatchJournal : MutableIterable<MatchJournal.Chunk> {
|
||||||
}
|
}
|
||||||
}.map { it.wrapped }
|
}.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 toString() = "(id=$id, $justifications, ${match.rule().uniqueTag()}, ${entriesLog()})"
|
||||||
|
|
||||||
override fun chunk(): Chunk = this
|
override fun chunk(): Chunk = this
|
||||||
|
|
@ -114,7 +111,7 @@ interface MatchJournal : MutableIterable<MatchJournal.Chunk> {
|
||||||
|
|
||||||
|
|
||||||
internal open class MatchJournalImpl(
|
internal open class MatchJournalImpl(
|
||||||
protected val ispec: IncrementalProgramSpec,
|
private val ispec: IncrementalProgramSpec,
|
||||||
view: MatchJournal.View? = null
|
view: MatchJournal.View? = null
|
||||||
) : MatchJournal
|
) : MatchJournal
|
||||||
{
|
{
|
||||||
|
|
@ -126,7 +123,7 @@ internal open class MatchJournalImpl(
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
hist = LinkedList()
|
hist = LinkedList()
|
||||||
nextChunkId = 0
|
nextChunkId = 0
|
||||||
val initChunk = ChunkImpl(ispec, InitRuleMatch, nextChunkId, justsOf(nextChunkId))
|
val initChunk = ChunkImpl(InitRuleMatch, nextChunkId, justsOf(nextChunkId))
|
||||||
nextChunkId++
|
nextChunkId++
|
||||||
hist.add(initChunk)
|
hist.add(initChunk)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -153,7 +150,7 @@ internal open class MatchJournalImpl(
|
||||||
if (ispec.isPrincipal(match.rule()) || !justs.isEmpty) {
|
if (ispec.isPrincipal(match.rule()) || !justs.isEmpty) {
|
||||||
|
|
||||||
justs.add(nextChunkId)
|
justs.add(nextChunkId)
|
||||||
val newChunk = ChunkImpl(ispec, match, nextChunkId, justs)
|
val newChunk = ChunkImpl(match, nextChunkId, justs)
|
||||||
pos.add(newChunk)
|
pos.add(newChunk)
|
||||||
|
|
||||||
++nextChunkId
|
++nextChunkId
|
||||||
|
|
@ -237,18 +234,11 @@ internal open class MatchJournalImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// todo: remove ispec from there
|
private class ChunkImpl(match: RuleMatch, id: Int, justifications: Justs) : MatchJournal.Chunk(match, id, justifications)
|
||||||
private class ChunkImpl(val ispec: IncrementalProgramSpec, match: RuleMatch, id: Int, justifications: Justs) : MatchJournal.Chunk(match, id, justifications)
|
|
||||||
{
|
{
|
||||||
var occurrences: MutableList<MatchJournal.Chunk.Entry> = mutableListOf()
|
var occurrences: MutableList<MatchJournal.Chunk.Entry> = mutableListOf()
|
||||||
|
|
||||||
override fun entriesLog(): List<MatchJournal.Chunk.Entry> = occurrences
|
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
|
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,
|
internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.DispatchingFront,
|
||||||
journal: MatchJournalImpl,
|
journal: MatchJournalImpl,
|
||||||
ruleIndex: RuleIndex,
|
ruleIndex: RuleIndex,
|
||||||
|
private val ispec: IncrementalProgramSpec = IncrementalProgramSpec.NonIncrSpec,
|
||||||
val trace: EvaluationTrace = EvaluationTrace.NULL,
|
val trace: EvaluationTrace = EvaluationTrace.NULL,
|
||||||
val profiler: Profiler? = null)
|
val profiler: Profiler? = null)
|
||||||
: StoreAwareJournalImpl(journal)
|
: StoreAwareJournalImpl(journal)
|
||||||
|
|
@ -68,17 +69,6 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp
|
||||||
// fixme: wtf, why idea's compiler complains???
|
// fixme: wtf, why idea's compiler complains???
|
||||||
override fun index(): MatchJournal.Index = journalIndex
|
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>) {
|
fun invalidateByRules(ruleIds: Set<Any>) {
|
||||||
val justificationRoots = mutableListOf<Int>()
|
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 MatchJournal.Chunk.principalOccurrence(): Occurrence? =
|
||||||
private fun Occurrence.isPrincipal() = this.constraint().isPrincipal()
|
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) }
|
private fun Justs.intersects(other: Iterable<Int>): Boolean = other.any { this.contains(it) }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue