diff --git a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/SortInferencer.java b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/SortInferencer.java
index be11fac1e91..3437967d7f1 100644
--- a/kernel/src/main/java/org/kframework/parser/inner/disambiguation/SortInferencer.java
+++ b/kernel/src/main/java/org/kframework/parser/inner/disambiguation/SortInferencer.java
@@ -1,6 +1,5 @@
package org.kframework.parser.inner.disambiguation;
-import com.google.gson.GsonBuilder;
import org.kframework.attributes.Att;
import org.kframework.attributes.Location;
import org.kframework.builtin.KLabels;
@@ -11,7 +10,6 @@
import org.kframework.definition.NonTerminal;
import org.kframework.definition.Production;
import org.kframework.kore.KLabel;
-import org.kframework.kore.KORE;
import org.kframework.kore.Sort;
import org.kframework.kore.SortHead;
import org.kframework.parser.Ambiguity;
@@ -30,6 +28,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -45,16 +44,16 @@
import static org.kframework.kore.KORE.*;
import static org.kframework.Collections.*;
-/*
+/**
* Disambiguation transformer which performs type checking and infers the sorts of variables.
*
- * The overall design is based on the algorithm described in
- * "The Simple Essence of Algebraic Subtyping: Principal Type Inference with Subtyping Made Easy" by Lionel Parreaux.
+ *
The overall design is based on the algorithm described in "The Simple Essence of Algebraic
+ * Subtyping: Principal Type Inference with Subtyping Made Easy" by Lionel Parreaux.
*
- * Specifically, we can straightforwardly treat any (non-ambiguous) term in our language as a function in the SimpleSub
+ *
Specifically, we can straightforwardly treat any (non-ambiguous) term in our language as a
+ * function in the SimpleSub
*
- * - Constants are treated as built-ins
- * - TermCons are treated as primitive functions
+ *
- Constants are treated as built-ins - TermCons are treated as primitive functions
*/
public class SortInferencer {
private final Module mod;
@@ -66,13 +65,13 @@ public class SortInferencer {
private final PrintWriter debug;
/**
- * Modes controlling how type inference inserts semantic casts x:Sort or strict casts x::Sort on
+ * Modes controlling how type inference inserts semantic (x:Sort) or strict (x::Sort) casts on
* variables in order to record their inferred types.
*/
public enum CastInsertionMode {
/**
- * Don't insert any casts. Type inference is still run and will report an error if the
- * term is ill-typed, but it never modifies the term.
+ * Don't insert any casts. Type inference is still run and will report an error if the term is
+ * ill-typed, but it never modifies the term.
*
*
* - x -> x
@@ -106,8 +105,7 @@ public enum CastInsertionMode {
private final CastInsertionMode castMode;
- public SortInferencer(
- Module mod, PrintWriter debug, CastInsertionMode castMode) {
+ public SortInferencer(Module mod, PrintWriter debug, CastInsertionMode castMode) {
this.mod = mod;
this.debug = debug;
this.castMode = castMode;
@@ -170,7 +168,7 @@ public Either, Term> apply(Term t, Sort topSort, boolean isAny
t.source().ifPresent(debug::println);
t.location().ifPresent(debug::println);
- InferenceResult res;
+ Set> monoRes;
try {
InferenceState inferState =
new InferenceState(new HashMap<>(), new HashMap<>(), new HashSet<>());
@@ -179,22 +177,20 @@ public Either, Term> apply(Term t, Sort topSort, boolean isAny
constrain(itemSort, topBoundedSort, inferState, (ProductionReference) t);
InferenceResult unsimplifiedRes =
new InferenceResult<>(topBoundedSort, inferState.varSorts());
- res = simplify(compact(unsimplifiedRes));
+ InferenceResult res = simplify(compact(unsimplifiedRes));
+ monoRes = monomorphize(res);
} catch (SortInferenceError e) {
Set errs = new HashSet<>();
errs.add(e.asInnerParseError());
return Left.apply(errs);
}
- debug.println(new GsonBuilder().setPrettyPrinting().create().toJson(res));
-
- Set