Rename some API interfaces to better reflect the intent.

This commit is contained in:
Fedor Isakov 2019-05-02 14:41:57 +02:00
parent e270655a7f
commit 59b6fb09fe
16 changed files with 58 additions and 72 deletions

View File

@ -19,7 +19,6 @@ package jetbrains.mps.logic.reactor.core
import com.github.andrewoma.dexx.collection.Maps
import jetbrains.mps.logic.reactor.core.internal.RuleMatchImpl
import com.github.andrewoma.dexx.collection.Map as PersMap
import jetbrains.mps.logic.reactor.evaluation.MatchRule
/**
* A front-end interface to [RuleMatcher].

View File

@ -16,7 +16,7 @@
package jetbrains.mps.logic.reactor.core
import jetbrains.mps.logic.reactor.evaluation.MatchRule
import jetbrains.mps.logic.reactor.evaluation.RuleMatch
import jetbrains.mps.logic.reactor.util.IdWrapper
@ -24,7 +24,7 @@ import jetbrains.mps.logic.reactor.util.IdWrapper
* @author Fedor Isakov
*/
interface RuleMatchEx : MatchRule {
interface RuleMatchEx : RuleMatch {
/**
* Returns an array of matched constraint occurrences wrapped in [IdWrapper].

View File

@ -16,7 +16,6 @@
package jetbrains.mps.logic.reactor.core
import jetbrains.mps.logic.reactor.evaluation.MatchRule
import jetbrains.mps.logic.reactor.program.Rule
import java.util.BitSet

View File

@ -263,12 +263,12 @@ internal class ControllerImpl (
override fun <V : Any> variable(metaLogical: MetaLogical<V>): Logical<V>? = null
}
private fun MatchRule.patternPredicates() =
private fun RuleMatch.patternPredicates() =
(rule().headKept() + rule().headReplaced()).zip(matchHeadKept() + matchHeadReplaced()).flatMap {
it.first.patternPredicates(it.second.arguments())
}.toList()
private fun MatchRule.allStored() = (matchHeadKept() + matchHeadReplaced()).all { co -> (co as Occurrence).stored }
private fun RuleMatch.allStored() = (matchHeadKept() + matchHeadReplaced()).all { co -> (co as Occurrence).stored }
}

View File

@ -17,11 +17,11 @@
package jetbrains.mps.logic.reactor.core.internal
import jetbrains.mps.logic.reactor.core.LogicalObserver
import jetbrains.mps.logic.reactor.logical.JoinableLogical
import jetbrains.mps.logic.reactor.logical.MutableLogical
import jetbrains.mps.logic.reactor.logical.MetaLogical
import java.util.ArrayList
internal class LogicalImpl<T> : JoinableLogical<T> {
internal class LogicalImpl<T> : MutableLogical<T> {
companion object {
var lastIdx = 0
@ -79,7 +79,7 @@ internal class LogicalImpl<T> : JoinableLogical<T> {
override fun metaLogical(): MetaLogical<T> = metaLogical
override fun findRoot(): JoinableLogical<T> = find()
override fun findRoot(): MutableLogical<T> = find()
override fun setValue(newValue: T) {
if (_value !== newValue) {
@ -88,7 +88,7 @@ internal class LogicalImpl<T> : JoinableLogical<T> {
}
}
override fun union(other: JoinableLogical<T>, reconciler: JoinableLogical.ValueReconciler<T>) {
override fun union(other: MutableLogical<T>, reconciler: MutableLogical.ValueReconciler<T>) {
val thisRepr = this.find()
val otherRepr = (other as LogicalImpl<T>).find()
@ -143,7 +143,7 @@ internal class LogicalImpl<T> : JoinableLogical<T> {
}
}
override fun union(other: JoinableLogical<T>) {
override fun union(other: MutableLogical<T>) {
union(other, { a, b -> if (a != b) throw IllegalStateException("$a does not equal to $b")})
}
@ -166,13 +166,13 @@ internal class LogicalImpl<T> : JoinableLogical<T> {
notifyParentUpdated()
}
private fun mergeValueObservers(mergeFrom: JoinableLogical<T>) {
private fun mergeValueObservers(mergeFrom: MutableLogical<T>) {
val other = mergeFrom as LogicalImpl<T>
valueObservers.addAll(other.valueObservers)
other.valueObservers.clear()
}
private fun mergeParentObservers(mergeFrom: JoinableLogical<T>) {
private fun mergeParentObservers(mergeFrom: MutableLogical<T>) {
val other = mergeFrom as LogicalImpl<T>
parentObservers.addAll(other.parentObservers)
other.parentObservers.clear()
@ -203,11 +203,11 @@ class DefaultMetaLogical<V> (val name: String) : MetaLogical<V>(name, Object::cl
// Used from tests
fun <V> anonLogical(value: V): JoinableLogical<V> = LogicalImpl<V>(value)
fun <V> anonLogical(value: V): MutableLogical<V> = LogicalImpl<V>(value)
fun <V> namedLogical(name: String): JoinableLogical<V> = LogicalImpl<V>(name)
fun <V> namedLogical(name: String): MutableLogical<V> = LogicalImpl<V>(name)
fun <V> MetaLogical<V>.logical(): JoinableLogical<V> = LogicalImpl<V>(this)
fun <V> MetaLogical<V>.logical(): MutableLogical<V> = LogicalImpl<V>(this)
fun <V> MetaLogical<V>.logical(value: V): JoinableLogical<V> = LogicalImpl<V>(name(), value)
fun <V> MetaLogical<V>.logical(value: V): MutableLogical<V> = LogicalImpl<V>(name(), value)

View File

@ -18,7 +18,6 @@ package jetbrains.mps.logic.reactor.core.internal
import jetbrains.mps.logic.reactor.core.*
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
import jetbrains.mps.logic.reactor.evaluation.MatchRule
import jetbrains.mps.logic.reactor.logical.MetaLogical
import jetbrains.mps.logic.reactor.program.Rule
import jetbrains.mps.logic.reactor.util.allSetBits

View File

@ -20,7 +20,6 @@ import jetbrains.mps.logic.reactor.core.Occurrence
import jetbrains.mps.logic.reactor.core.RuleMatchEx
import jetbrains.mps.logic.reactor.core.Subst
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
import jetbrains.mps.logic.reactor.evaluation.MatchRule
import jetbrains.mps.logic.reactor.logical.Logical
import jetbrains.mps.logic.reactor.logical.LogicalContext
import jetbrains.mps.logic.reactor.logical.LogicalOwner

View File

@ -44,7 +44,7 @@ public class EvaluationFailure extends EvaluationFeedback {
}
/**
* // FIXME need a smarter way to supercede previously reported failure with a more specific one
* // TODO need a smarter way to supercede previously reported failure with a more specific one
* Constructs a more specific failure given a generic one.
*/
public EvaluationFailure(EvaluationFailure reason, String message) {

View File

@ -38,19 +38,19 @@ public interface EvaluationTrace {
public void discard(ConstraintOccurrence occurrence) {
}
public void trying(MatchRule matchRule) {
public void trying(RuleMatch matchRule) {
}
public void reject(MatchRule matchRule) {
public void reject(RuleMatch matchRule) {
}
public void trigger(MatchRule matchRule) {
public void trigger(RuleMatch matchRule) {
}
public void retry(MatchRule matchRule) {
public void retry(RuleMatch matchRule) {
}
public void finish(MatchRule matchRule) {
public void finish(RuleMatch matchRule) {
}
public void tell(PredicateInvocation invocation) {
@ -72,15 +72,15 @@ public interface EvaluationTrace {
void discard(ConstraintOccurrence occurrence);
void trying(MatchRule matchRule);
void trying(RuleMatch matchRule);
void reject(MatchRule matchRule);
void reject(RuleMatch matchRule);
void trigger(MatchRule matchRule);
void trigger(RuleMatch matchRule);
void retry(MatchRule matchRule);
void retry(RuleMatch matchRule);
void finish(MatchRule matchRule);
void finish(RuleMatch matchRule);
void tell(PredicateInvocation invocation);

View File

@ -35,10 +35,5 @@ public interface PredicateInvocation {
LogicalContext logicalContext();
default InvocationContext invocationContext() {
// FIXME delete the implementation after all code has been migrated
// keep compatibitily with existing code
throw new UnsupportedOperationException();
};
InvocationContext invocationContext();
}

View File

@ -23,11 +23,9 @@ import jetbrains.mps.logic.reactor.program.Rule;
/**
* A binding of a rule and the constraint occurrences that matched its head.
*
* // FIXME rename to RuleMatch
*
* @author Fedor Isakov
*/
public interface MatchRule {
public interface RuleMatch {
Rule rule();

View File

@ -39,8 +39,6 @@ public interface Logical<T> {
* Returns the value associated with this logical instance.
* Can be null.
* Only the logical instance that is a representative can have value that is not null.
* <p>
* FIXME: must return the representative's value
*/
T value();

View File

@ -18,32 +18,31 @@ package jetbrains.mps.logic.reactor.logical;
/**
* // FIXME to be renamed to MutableLogical
* A logical variable that can be joined with another variable to produce a union.
*
* @param <T> the value type
*
* @author Fedor Isakov
*/
public interface JoinableLogical<T> extends Logical<T> {
public interface MutableLogical<T> extends Logical<T> {
/**
* Covariant override.
*/
JoinableLogical<T> findRoot();
MutableLogical<T> findRoot();
/**
* Unions two equivalence classes of logicals.
* Both the receiver and the {@code other} parameter are expected to be representatives.
* The one with the highest rank becomes the representative for the new class.
*/
void union(JoinableLogical<T> other, JoinableLogical.ValueReconciler<T> reconciler);
void union(MutableLogical<T> other, MutableLogical.ValueReconciler<T> reconciler);
/**
* Calls {@link JoinableLogical#union(JoinableLogical <T>, JoinableLogical.ValueReconciler<T>) } with the default value reconciler.
* Calls {@link MutableLogical#union(MutableLogical <T>, MutableLogical.ValueReconciler<T>) } with the default value reconciler.
* The default reconciler throws {@link java.lang.IllegalArgumentException } if the two values are not equal.
*/
void union(JoinableLogical<T> other);
void union(MutableLogical<T> other);
/**
* Should only be called on a representative.

View File

@ -5,7 +5,7 @@ import jetbrains.mps.logic.reactor.evaluation.*
import jetbrains.mps.logic.reactor.logical.Logical
import jetbrains.mps.logic.reactor.logical.LogicalContext
import jetbrains.mps.logic.reactor.logical.MetaLogical
import jetbrains.mps.logic.reactor.logical.JoinableLogical
import jetbrains.mps.logic.reactor.logical.MutableLogical
import jetbrains.mps.logic.reactor.program.Predicate
import jetbrains.mps.logic.reactor.program.PredicateSymbol
@ -26,11 +26,11 @@ class EqualsSolver : Solver {
}
private fun _ask(left: Any?, right: Any?): Boolean {
return if (left is JoinableLogical<*> && right is JoinableLogical<*>) {
return if (left is MutableLogical<*> && right is MutableLogical<*>) {
ask_logical_logical(left, right)
} else if (left is JoinableLogical<*>) {
} else if (left is MutableLogical<*>) {
ask_logical_value(left, right)
} else if (right is JoinableLogical<*>) {
} else if (right is MutableLogical<*>) {
ask_value_logical(left, right)
} else {
ask_value_value(left, right)
@ -42,27 +42,27 @@ class EqualsSolver : Solver {
}
private fun _tell(left: Any?, right: Any?) {
if (left is JoinableLogical<*> && right is JoinableLogical<*>) {
tell_logical_logical(left as JoinableLogical<Any>, right as JoinableLogical<Any>)
} else if (left is JoinableLogical<*>) {
tell_logical_value(left as JoinableLogical<Any>, right)
} else if (right is JoinableLogical<*>) {
tell_value_logical(left, right as JoinableLogical<Any>)
if (left is MutableLogical<*> && right is MutableLogical<*>) {
tell_logical_logical(left as MutableLogical<Any>, right as MutableLogical<Any>)
} else if (left is MutableLogical<*>) {
tell_logical_value(left as MutableLogical<Any>, right)
} else if (right is MutableLogical<*>) {
tell_value_logical(left, right as MutableLogical<Any>)
} else {
tell_value_value(left, right)
}
}
fun ask_logical_logical(left: JoinableLogical<*>, right: JoinableLogical<*>): Boolean {
fun ask_logical_logical(left: MutableLogical<*>, right: MutableLogical<*>): Boolean {
if (left.findRoot() == right.findRoot()) return true
return left.isBound && right.isBound && left.findRoot().value() == right.findRoot().value()
}
fun ask_logical_value(left: JoinableLogical<*>, right: Any?): Boolean {
fun ask_logical_value(left: MutableLogical<*>, right: Any?): Boolean {
return left.isBound && left.findRoot().value() == right
}
fun ask_value_logical(left: Any?, right: JoinableLogical<*>): Boolean {
fun ask_value_logical(left: Any?, right: MutableLogical<*>): Boolean {
return right.isBound && right.findRoot().value() == left
}
@ -70,7 +70,7 @@ class EqualsSolver : Solver {
return left == right
}
fun <T> tell_logical_logical(left: JoinableLogical<T>, right: JoinableLogical<T>) {
fun <T> tell_logical_logical(left: MutableLogical<T>, right: MutableLogical<T>) {
if (left == right) return
val leftRepr = left.findRoot()
@ -81,7 +81,7 @@ class EqualsSolver : Solver {
leftRepr.union(rightRepr, { a, b -> tell_value_value(a, b)})
}
fun <T> tell_logical_value(left: JoinableLogical<T>, right: T?) {
fun <T> tell_logical_value(left: MutableLogical<T>, right: T?) {
if (left.isBound) {
check(left.findRoot().value() == right)
}
@ -90,7 +90,7 @@ class EqualsSolver : Solver {
}
}
fun <T> tell_value_logical(left: T?, right: JoinableLogical<T>) {
fun <T> tell_value_logical(left: T?, right: MutableLogical<T>) {
if (right.isBound) {
check(right.findRoot().value() == left)
}

View File

@ -1,7 +1,7 @@
import jetbrains.mps.logic.reactor.core.LogicalObserver
import jetbrains.mps.logic.reactor.core.internal.anonLogical
import jetbrains.mps.logic.reactor.core.internal.namedLogical
import jetbrains.mps.logic.reactor.logical.JoinableLogical
import jetbrains.mps.logic.reactor.logical.MutableLogical
import jetbrains.mps.logic.reactor.logical.Logical
import jetbrains.mps.logic.reactor.logical.MetaLogical
import java.util.*
@ -36,7 +36,7 @@ fun <T : Any> Logical<T>.get(): T = findRoot().value()
fun <T : Any> Logical<T>.getNullable(): T? = findRoot().value()
fun <T : Any> Logical<T>.set(t: T) {
if (this is JoinableLogical<T>)
if (this is MutableLogical<T>)
findRoot().setValue(t)
else
throw IllegalStateException("unexpected receiver $this")

View File

@ -17,7 +17,7 @@
package jetbrains.mps.unification.test;
import jetbrains.mps.logic.reactor.core.internal.LogicalImplKt;
import jetbrains.mps.logic.reactor.logical.JoinableLogical;
import jetbrains.mps.logic.reactor.logical.MutableLogical;
import jetbrains.mps.logic.reactor.logical.MetaLogical;
import jetbrains.mps.unification.Substitution;
import jetbrains.mps.unification.Term;
@ -573,9 +573,9 @@ public class SolverTests {
MetaLogical<Term> X = new MetaLogical<>("X", Term.class);
MetaLogical<Term> Y = new MetaLogical<>("Y", Term.class);
MetaLogical<Term> Z = new MetaLogical<>("Z", Term.class);
JoinableLogical<Term> xLogical = LogicalImplKt.logical(X);
JoinableLogical<Term> yLogical = LogicalImplKt.logical(Y);
JoinableLogical<Term> zLogical = LogicalImplKt.logical(Z);
MutableLogical<Term> xLogical = LogicalImplKt.logical(X);
MutableLogical<Term> yLogical = LogicalImplKt.logical(Y);
MutableLogical<Term> zLogical = LogicalImplKt.logical(Z);
Term left = term("foo", term("bar", logicalVar(yLogical)), logicalVar(zLogical));
Term right = term("foo", term("bar", logicalVar(xLogical)), logicalVar(zLogical));
@ -593,9 +593,9 @@ public class SolverTests {
MetaLogical<Term> X = new MetaLogical<>("X", Term.class);
MetaLogical<Term> Y = new MetaLogical<>("Y", Term.class);
MetaLogical<Term> Z = new MetaLogical<>("Z", Term.class);
JoinableLogical<Term> xLogical = LogicalImplKt.logical(X);
JoinableLogical<Term> yLogical = LogicalImplKt.logical(Y);
JoinableLogical<Term> zLogical = LogicalImplKt.logical(Z);
MutableLogical<Term> xLogical = LogicalImplKt.logical(X);
MutableLogical<Term> yLogical = LogicalImplKt.logical(Y);
MutableLogical<Term> zLogical = LogicalImplKt.logical(Z);
Term left = logicalVar(yLogical);
Term right = term("foo", term("bar", logicalVar(xLogical)), logicalVar(zLogical));