From 46d37ca19c0699a862d7b8a02ad32da7d747bf91 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Thu, 26 Nov 2020 16:59:39 +0100 Subject: [PATCH 1/4] Add test case --- tests/pos/9890.scala | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/pos/9890.scala diff --git a/tests/pos/9890.scala b/tests/pos/9890.scala new file mode 100644 index 000000000000..96d6f1db33b7 --- /dev/null +++ b/tests/pos/9890.scala @@ -0,0 +1,49 @@ +object Test { + import scala.compiletime.ops.int._ + + trait x + + type Range[Min <: Int, Max <: Int] <: Tuple = Min match { + case Max => EmptyTuple + case _ => Min *: Range[Min + 1, Max] + } + + type TupleMap[Tup <: Tuple, Bound, F[_ <: Bound]] <: Tuple = Tup match { + case EmptyTuple => EmptyTuple + case h *: t => F[h] *: TupleMap[t, Bound, F] + } + type TupleDedup[Tup <: Tuple, Mask] <: Tuple = Tup match { + case EmptyTuple => EmptyTuple + case h *: t => h match { + case Mask => TupleDedup[t, Mask] + case _ => h *: TupleDedup[t, h | Mask] + } + } + + type CoordToPos[r <: Int, c <: Int] = r * 9 + c + type Cell[r <: Int, c <: Int, Board <: Tuple] = Tuple.Elem[Board, CoordToPos[r, c]] + type Col[c <: Int, Board <: Tuple] = TupleMap[Range[0, 9], Int, [r <: Int] =>> Cell[r, c, Board]] + + type ColFromPos[Pos <: Int] = Pos % 9 + + type Sudoku1 = ( + x, x, x, x, 1, x, 4, x, 6, + 8, x, 1, 6, 2, x, x, x, 9, + x, 3, x, x, x, 9, x, 2, x, + + 5, x, 9, 1, 3, x, x, 6, x, + x, 6, x, 9, x, 2, x, 4, x, + x, 2, x, x, 6, 7, 8, x, 5, + + x, 9, x, 5, x, x, x, 3, x, + 3, x, x, x, 4, 6, 9, x, 7, + 6, x, 7, x, 9, x, x, x, x, + ) + + //compiles fine + summon[Col[ColFromPos[0], Sudoku1] =:= (x, 8, x, 5, x, x, x, 3, 6)] + + summon[TupleDedup[(x, 8, x, 5, x, x, x, 3, 6), Nothing] =:= (x, 8, 5, 3, 6)] + //but this doesn't + summon[TupleDedup[Col[ColFromPos[0], Sudoku1], Nothing] =:= (x, 8, 5, 3, 6)] +} From 6a2a649a1063cddb631a2ecdc9a3f9fb27b3d201 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Mon, 30 Nov 2020 15:03:46 +0100 Subject: [PATCH 2/4] Fix #9890: Dealias before normalizing MT scrutinee --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 44152c072468..3fc8e123da95 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4490,7 +4490,7 @@ object Types { myReduced = trace(i"reduce match type $this $hashCode", typr, show = true) { def matchCases(cmp: TrackingTypeComparer): Type = - try cmp.matchCases(scrutinee.normalized, cases) + try cmp.matchCases(scrutinee.dealias.normalized, cases) catch case ex: Throwable => handleRecursive("reduce type ", i"$scrutinee match ...", ex) finally updateReductionContext(cmp.footprint) From 49e2bcd5da66d2e0b5fa8c34d71a71dbe567e487 Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Mon, 30 Nov 2020 15:18:17 +0100 Subject: [PATCH 3/4] Add YnoDeepSubtypes check See assert in monitoredIsSubtype: https://github.com/lampepfl/dotty/blob/866656c8d1408697111edf69b0db9b90ce553c5f/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L216 --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 91f5c2258ea7..32d254f936bf 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1257,7 +1257,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling val savedSuccessCount = successCount try recCount += 1 - if recCount >= Config.LogPendingSubTypesThreshold then monitored = true + if recCount >= Config.LogPendingSubTypesThreshold && !ctx.settings.YnoDeepSubtypes.value then monitored = true val result = if monitored then monitoredIsSubType else firstTry recCount -= 1 if !result then From b7c17ec3fdcd74b30454b4d0fc4116d784ff670d Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Tue, 1 Dec 2020 14:28:41 +0100 Subject: [PATCH 4/4] Update pos-test-pickling.blacklist --- compiler/test/dotc/pos-test-pickling.blacklist | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index 547a48d99b79..a6937f22087e 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -34,6 +34,7 @@ i7872.scala 6687.scala i11236.scala i11247.scala +9890.scala # Opaque type i5720.scala