|
| 1 | +package dotty.tools |
| 2 | +package dotc |
| 3 | +package typer |
| 4 | + |
| 5 | +// Modelling the decision in IsFullyDefined |
| 6 | +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.* |
| 13 | + |
| 14 | + // NN/AA = Nothing/Any |
| 15 | + // LL/UU = the original bounds, on the type parameter |
| 16 | + // L1/U1 = the constrained bounds, on the type variable |
| 17 | + // V = variance >= 0 ("non-contravariant") |
| 18 | + // MSe = minimisedSelected |
| 19 | + // Bot = IfBottom |
| 20 | + // ToMax = delayed maximisation, via addition to toMaximize |
| 21 | + // Skip = minimisedSelected "hold off instantiating" |
| 22 | + // False = return false |
| 23 | + |
| 24 | + // there are 9 combinations: |
| 25 | + // # | LB | UB | d | // d = direction |
| 26 | + // --+----+----+---+ |
| 27 | + // 1 | L1 | AA | - | L1 <: T |
| 28 | + // 2 | L1 | UU | - | L1 <: T <: UU |
| 29 | + // 3 | LL | U1 | + | LL <: T <: U1 |
| 30 | + // 4 | NN | U1 | + | T <: U1 |
| 31 | + // 5 | L1 | U1 | 0 | L1 <: T <: U1 |
| 32 | + // 6 | LL | UU | 0 | LL <: T <: UU |
| 33 | + // 7 | LL | AA | 0 | LL <: T |
| 34 | + // 8 | NN | UU | 0 | T <: UU |
| 35 | + // 9 | NN | AA | 0 | T |
| 36 | + |
| 37 | + def decide(lb: LB, ub: UB, v: Var, bot: Bot, m: MSe): Act = (lb, ub) match |
| 38 | + case (L1, AA) => Min |
| 39 | + case (L1, UU) => Min |
| 40 | + case (LL, U1) => Max |
| 41 | + case (NN, U1) => Max |
| 42 | + |
| 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 |
0 commit comments