@@ -39,38 +39,37 @@ object Mono extends Phase[CoreTransformed, CoreTransformed] {
39
39
// so we can generate the required monomorphic functions
40
40
41
41
enum PolyType {
42
- case Base (val tpe : symbols. Symbol )
43
- case Var (val sym : symbols. Symbol )
42
+ case Base (val tpe : Id )
43
+ case Var (val sym : Id )
44
44
45
- def toSymbol : symbols. Symbol = this match {
45
+ def toSymbol : Id = this match {
46
46
case Base (tpe) => tpe
47
47
case Var (sym) => sym
48
48
}
49
49
}
50
50
51
- type PolyConstraints = Map [symbols. Symbol , Set [PolyType ]]
52
- type PolyConstraintEntry = (symbols. Symbol , Set [PolyType ])
51
+ type PolyConstraints = Map [Id , Set [PolyType ]]
52
+ type PolyConstraintEntry = (Id , Set [PolyType ])
53
53
54
54
def solveConstraints (constraints : PolyConstraints ): PolyConstraints =
55
55
var solved : PolyConstraints = Map ()
56
56
57
- def solveConstraint (sym : symbols. Symbol , types : Set [PolyType ]): Set [PolyType ] =
57
+ def solveConstraint (sym : Id , types : Set [PolyType ]): Set [PolyType ] =
58
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
- })
59
+ types.foreach {
60
+ case PolyType .Var (symbol) => polyTypes ++= solved.getOrElse(symbol, solveConstraint(symbol, constraints.getOrElse(symbol, Set ())))
61
+ case base => polyTypes += base
62
+ }
65
63
solved += (sym -> polyTypes)
66
64
polyTypes
67
65
68
66
constraints.foreach(solveConstraint)
69
67
70
68
solved
71
69
72
- def appendConstraint (map : PolyConstraints , sym : symbols. Symbol , tpe : ValueType ): PolyConstraintEntry =
70
+ def appendConstraint (map : PolyConstraints , sym : Id , tpe : ValueType ): PolyConstraintEntry =
73
71
val currentFlow = map.getOrElse(sym, Set ())
72
+ println(" Append: " + tpe + " , " + sym)
74
73
tpe match {
75
74
// Ignore self cycling types A -> A
76
75
case ValueType .Data (name, targs) if name != sym => (sym -> (currentFlow + PolyType .Base (name)))
@@ -122,15 +121,15 @@ def findConstraints(definitions: List[Toplevel]): PolyConstraints =
122
121
case _ =>
123
122
}
124
123
case _ =>
125
- case _ =>
124
+ case _ =>
126
125
}
127
126
typeFlow
128
127
129
128
def hasCycle (constraints : PolyConstraints ): Boolean =
130
- var visited : Set [symbols. Symbol ] = Set ()
131
- var recStack : Set [symbols. Symbol ] = Set ()
129
+ var visited : Set [Id ] = Set ()
130
+ var recStack : Set [Id ] = Set ()
132
131
133
- def hasCycleHelper (vertex : symbols. Symbol ): Boolean =
132
+ def hasCycleHelper (vertex : Id ): Boolean =
134
133
if (recStack.contains(vertex)) return true
135
134
if (visited.contains(vertex)) return false
136
135
0 commit comments