@@ -98,14 +98,17 @@ class ConstraintSolver(infVarState: InfVarUid.State, elState: Elaborator.State,
9898 v.state.lowerBounds ::= bd
9999 v.state.upperBounds.foreach(ub => constrainImpl(bd, ub))
100100 v.state.disjsub.foreach: d =>
101- Type .disjoint(d.disjoint(v), bd.toBasic.simp.toBasic)(Set .empty)(using c = mutable.Map .empty) match
102- case N =>
103- d.remove(v)
104- if d.disjoint.isEmpty then
105- d.dss.foreach(_.commit())
106- d.cs.foreach((a, b) => constrainImpl(a, b))
107- case S (k) =>
108- k.foreach(k => DisjSub (d.disjoint ++ k, d.dss, d.cs).commit())
101+ val u = d.disjoint(v).flatMap: t =>
102+ Type .disjoint(t, bd.toBasic.simp.toBasic)(Set .empty)(using c = mutable.Map .empty)
103+ if u.isEmpty then
104+ d.remove(v)
105+ if d.disjoint.isEmpty then
106+ d.dss.foreach(_.commit())
107+ d.cs.foreach((a, b) => constrainImpl(a, b))
108+ else
109+ d.clear()
110+ u.reduce((x, y) => y.flatMap(y => x.map(_ ++ y))).foreach: k =>
111+ DisjSub (mutable.Map .from(k.groupMap(_._1)(_._2)), d.dss, d.cs).commit()
109112 case Conj (i, u, Nil ) => (conj.i, conj.u) match
110113 case (_, Union (N , Nil )) =>
111114 // raise(ErrorReport(msg"Cannot solve ${conj.i.toString()} ∧ ¬⊥" -> N :: Nil))
@@ -133,7 +136,7 @@ class ConstraintSolver(infVarState: InfVarUid.State, elState: Elaborator.State,
133136 else
134137 val cs = (ret1, ret2) :: (eff1, eff2) :: args2.zip(args1)
135138 k.reduce((x, y) => y.flatMap(y => x.map(_ ++ y))).foreach: k =>
136- DisjSub (mutable.Map .from(k), Nil , cs).commit()
139+ DisjSub (mutable.Map .from(k.groupMap(_._1)(_._2) ), Nil , cs).commit()
137140 case (Inter (S (fs: Ls [FunType ])), Union (S (FunType (args2, ret2, eff2)), Nil )) =>
138141 val f = fs.filter(_.args.length === args2.length)
139142 val args = f.map(_.args).transpose
@@ -152,7 +155,7 @@ class ConstraintSolver(infVarState: InfVarUid.State, elState: Elaborator.State,
152155 constrainImpl(b.eff, eff2)
153156 case S (k) =>
154157 val cs = (b.ret,ret2) :: (b.eff,eff2) :: s
155- k.foreach(k => DisjSub (mutable.Map .from(k), Nil , cs).commit())
158+ k.foreach(k => DisjSub (mutable.Map .from(k.groupMap(_._1)(_._2) ), Nil , cs).commit())
156159 case _ =>
157160 // raise(ErrorReport(msg"Cannot solve ${conj.i.toString()} <: ${conj.u.toString()}" -> N :: Nil))
158161 cctx.err
0 commit comments