Skip to content

Commit 44009a6

Browse files
committed
Simplify & update InstantiateModel
Martin had tweaked my i14218 fix to make it more conservative: in the (NN, UU) case (i.e. no inferred bounds, only a UU upper bound declared) for covariant type parameters, revert back to minimising to Nothing rather than maximising to the declared bound.
1 parent 5f06343 commit 44009a6

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

compiler/test/dotty/tools/dotc/typer/InstantiateModel.scala

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@ package typer
44

55
// Modelling the decision in IsFullyDefined
66
object InstantiateModel:
7-
enum LB { case NN; case LL; case L1 }; import LB.*
8-
enum UB { case AA; case UU; case U1 }; import UB.*
9-
enum Var { case V; case NotV }; import Var.*
10-
enum MSe { case M; case NotM }; import MSe.*
11-
enum Bot { case Fail; case Ok; case Flip }; import Bot.*
12-
enum Act { case Min; case Max; case ToMax; case Skip; case False }; import Act.*
7+
enum LB { case NN; case LL; case L1 }; import LB.*
8+
enum UB { case AA; case UU; case U1 }; import UB.*
9+
enum Decision { case Min; case Max; case ToMax; case Skip; case Fail }; import Decision.*
1310

1411
// NN/AA = Nothing/Any
1512
// LL/UU = the original bounds, on the type parameter
1613
// L1/U1 = the constrained bounds, on the type variable
17-
// V = variance >= 0 ("non-contravariant")
18-
// MSe = minimisedSelected
19-
// Bot = IfBottom
2014
// ToMax = delayed maximisation, via addition to toMaximize
2115
// Skip = minimisedSelected "hold off instantiating"
22-
// False = return false
16+
// Fail = IfBottom.fail's bail option
2317

2418
// there are 9 combinations:
2519
// # | LB | UB | d | // d = direction
@@ -34,24 +28,27 @@ object InstantiateModel:
3428
// 8 | NN | UU | 0 | T <: UU
3529
// 9 | NN | AA | 0 | T
3630

37-
def decide(lb: LB, ub: UB, v: Var, bot: Bot, m: MSe): Act = (lb, ub) match
31+
def instDecision(lb: LB, ub: UB, v: Int, ifBottom: IfBottom, min: Boolean) = (lb, ub) match
3832
case (L1, AA) => Min
3933
case (L1, UU) => Min
4034
case (LL, U1) => Max
4135
case (NN, U1) => Max
4236

43-
case (L1, U1) => if m==M || v==V then Min else ToMax
44-
case (LL, UU) => if m==M || v==V then Min else ToMax
45-
case (LL, AA) => if m==M || v==V then Min else ToMax
46-
47-
case (NN, UU) => bot match
48-
case _ if m==M => Max
49-
//case Ok if v==V => Min // removed, i14218 fix
50-
case Fail if v==V => False
51-
case _ => ToMax
52-
53-
case (NN, AA) => bot match
54-
case _ if m==M => Skip
55-
case Ok if v==V => Min
56-
case Fail if v==V => False
57-
case _ => ToMax
37+
case (L1, U1) => if min then Min else pickVar(v, Min, Min, ToMax)
38+
case (LL, UU) => if min then Min else pickVar(v, Min, Min, ToMax)
39+
case (LL, AA) => if min then Min else pickVar(v, Min, Min, ToMax)
40+
41+
case (NN, UU) => ifBottom match
42+
case _ if min => Max
43+
case IfBottom.ok => pickVar(v, Min, ToMax, ToMax)
44+
case IfBottom.fail => pickVar(v, Fail, Fail, ToMax)
45+
case IfBottom.flip => ToMax
46+
47+
case (NN, AA) => ifBottom match
48+
case _ if min => Skip
49+
case IfBottom.ok => pickVar(v, Min, Min, ToMax)
50+
case IfBottom.fail => pickVar(v, Fail, Fail, ToMax)
51+
case IfBottom.flip => ToMax
52+
53+
def pickVar[A](v: Int, cov: A, inv: A, con: A) =
54+
if v > 0 then cov else if v == 0 then inv else con

0 commit comments

Comments
 (0)