Skip to content

Commit 95023d3

Browse files
committed
Handle recursive functions when solving
1 parent a0e5ab9 commit 95023d3

File tree

1 file changed

+7
-3
lines changed
  • effekt/shared/src/main/scala/effekt/core

1 file changed

+7
-3
lines changed

effekt/shared/src/main/scala/effekt/core/Mono.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,14 @@ def solveConstraints(constraints: Constraints): Solution =
113113
val groupedConstraints = constraints.groupBy(c => c.upper)
114114
val vecConstraints = groupedConstraints.map((sym, constraints) => (sym -> constraints.map(c => c.lower)))
115115

116+
while (true) {
117+
val previousSolved = solved
116118
vecConstraints.foreach((sym, tas) =>
117119
val sol = solveConstraints(sym).map(bs => bs.toVector)
118-
solved += (sym -> sol)
119-
)
120+
solved += (sym -> sol)
121+
)
122+
if (previousSolved == solved) return solved
123+
}
120124

121125
def solveConstraints(funId: FunctionId): Set[List[TypeArg.Base]] =
122126
val filteredConstraints = vecConstraints(funId)
@@ -127,7 +131,7 @@ def solveConstraints(constraints: Constraints): Solution =
127131
b.foreach({
128132
case TypeArg.Base(tpe) => l = productAppend(l, List(TypeArg.Base(tpe)))
129133
case TypeArg.Var(funId, pos) =>
130-
val funSolved = solved.getOrElse(funId, solveConstraints(funId))
134+
val funSolved = solved.getOrElse(funId, Set.empty)
131135
val posArgs = funSolved.map(v => v(pos))
132136
l = posArgs.zipWithIndex.map((base, ind) => listFromIndex(ind) :+ base).toList
133137
})

0 commit comments

Comments
 (0)