@@ -14,10 +14,17 @@ object Mono extends Phase[CoreTransformed, CoreTransformed] {
14
14
case CoreTransformed (source, tree, mod, core) => {
15
15
core match {
16
16
case ModuleDecl (path, includes, declarations, externs, definitions, exports) => {
17
- val polys = findConstraints(definitions)
18
- polys.foreach(p => println(p))
17
+ val constraints = findConstraints(definitions)
18
+ println(" Constraints" )
19
+ constraints.foreach(c => println(c))
19
20
println()
20
- println(" Has cycle: " + hasCycle(polys))
21
+ if (! hasCycle(constraints)) {
22
+ val solvedConstraints = solveConstraints(constraints)
23
+ println(" Solved constraints" )
24
+ solvedConstraints.foreach(sc => println(sc))
25
+ } else {
26
+ println(" Cycle detected, skipping solveConstraints" )
27
+ }
21
28
println()
22
29
}
23
30
}
@@ -44,6 +51,24 @@ enum PolyType {
44
51
type PolyConstraints = Map [symbols.Symbol , Set [PolyType ]]
45
52
type PolyConstraintEntry = (symbols.Symbol , Set [PolyType ])
46
53
54
+ def solveConstraints (constraints : PolyConstraints ): PolyConstraints =
55
+ var solved : PolyConstraints = Map ()
56
+
57
+ def solveConstraint (sym : symbols.Symbol , types : Set [PolyType ]): Set [PolyType ] =
58
+ var polyTypes : Set [PolyType ] = Set ()
59
+ types.foreach(t => {
60
+ t match {
61
+ case PolyType .Var (symbol) => polyTypes ++= solved.getOrElse(symbol, solveConstraint(symbol, constraints.getOrElse(symbol, Set ())))
62
+ case base => polyTypes += base
63
+ }
64
+ })
65
+ solved += (sym -> polyTypes)
66
+ polyTypes
67
+
68
+ constraints.foreach(solveConstraint)
69
+
70
+ solved
71
+
47
72
def appendConstraint (map : PolyConstraints , sym : symbols.Symbol , tpe : ValueType ): PolyConstraintEntry =
48
73
val currentFlow = map.getOrElse(sym, Set ())
49
74
tpe match {
0 commit comments