From f80371e1487ff4437c725df04518cb2bdbf7535d Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Thu, 7 Nov 2019 15:38:32 +0300 Subject: [PATCH] MPSCR-14: Correctly trace incrementally reactivated occurrences. Fixes the bug. --- .../reactor/core/internal/ControllerImpl.kt | 23 ++++++++++++++++--- .../core/internal/ProcessingStateImpl.kt | 8 +------ 2 files changed, 21 insertions(+), 10 deletions(-) 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 aa4e0d38..b7361c35 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 @@ -45,6 +45,8 @@ internal class ControllerImpl ( override fun variable(metaLogical: MetaLogical): Logical? = null }) + traceActivated(occ) + val status = state.processActivated(this, active, NORMAL()) if (status is FAILED) { throw status.failure.failureCause() @@ -91,8 +93,13 @@ internal class ControllerImpl ( solver.tell(invocation) } - override fun reactivate(occ: Occurrence): FeedbackStatus = - state.processActivated(this, occ, NORMAL()) + override fun reactivate(occ: Occurrence): FeedbackStatus { + // fixme: leave one of these, ensure impl is present on both reactor & mps levels + trace.activate(occ) + trace.reactivateIncremental(occ) + + return state.processActivated(this, occ, NORMAL()) + } override fun offerMatch(match: RuleMatchEx, inStatus: FeedbackStatus) : FeedbackStatus = profiler.profile("offerMatch") { @@ -212,10 +219,20 @@ internal class ControllerImpl ( val args = supervisor.instantiateArguments(constraint.arguments(), context.logicalContext, context) return context.eval { status -> - state.processActivated(this, constraint.occurrence(this, args, justsCopy(justs), context.logicalContext, context.ruleUniqueTag), status) + constraint.occurrence(this, args, justsCopy(justs), context.logicalContext, context.ruleUniqueTag).let { occ -> + traceActivated(occ) + state.processActivated(this, occ, status) + } } } + private fun traceActivated(occ: Occurrence) = + if (!occ.stored) + trace.activate(occ) + else + trace.reactivate(occ) + + private fun askPredicate(predicate: Predicate, context: Context) : Boolean = profiler.profile("ask_${predicate.symbol()}") { diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt index 785b3f76..877517ad 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/ProcessingStateImpl.kt @@ -65,7 +65,7 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp // processed as with reactivation through observers. // Incremental reactivation should proceed more like usual activation. this.dispatchingFront = dispatchingFront.forgetExpanded(activeOcc) - trace.reactivateIncremental(activeOcc) + return controller.reactivate(activeOcc) } @@ -216,16 +216,10 @@ internal class ProcessingStateImpl(private var dispatchingFront: Dispatcher.Disp if (!active.stored) { active.stored = true - trace.activate(active) - logActivation(active) active.revive(controller) - - } else { - trace.reactivate(active) } - profiler.profile("dispatch_${active.constraint().symbol()}") { this.dispatchingFront = dispatchingFront.expand(active)