-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler crashes on get the field names of case class. #16207
Comments
It works if change the code to:
|
Here's a minimization of the issue: def tple: Tuple = ("abc", "def")
val _ = tple.toList.map(_ => 1) Output exception while typing {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map of class class dotty.tools.dotc.ast.Trees$Select # -1
exception while typing {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int] of class class dotty.tools.dotc.ast.Trees$TypeApply # -1
exception while typing {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
) of class class dotty.tools.dotc.ast.Trees$Apply # -1
exception while typing {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked of class class dotty.tools.dotc.ast.Trees$Typed # -1
exception while typing case val x1: scala.collection.immutable.List[Int] @unchecked =
{
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked of class class dotty.tools.dotc.ast.Trees$ValDef # -1
exception while typing {
case val x1: scala.collection.immutable.List[Int] @unchecked =
{
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked
return[matchResult1] ()
} of class class dotty.tools.dotc.ast.Trees$Block # -1
exception while typing matchResult1[Unit]:
{
case val x1: scala.collection.immutable.List[Int] @unchecked =
{
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]
]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked
return[matchResult1] ()
} of class class dotty.tools.dotc.ast.Trees$Labeled # -1
exception while typing @SourceFile("i16207.scala") final module class i16207$package() extends Object()
{
private def writeReplace(): AnyRef =
new scala.runtime.ModuleSerializationProxy(classOf[i16207$package.type])
def tple: Tuple = Tuple2.apply[String, String]("abc", "def")
matchResult1[Unit]:
{
case val x1: scala.collection.immutable.List[Int] @unchecked =
{
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[
Tuple.Union[(Tuple_this : Product)]]
]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked
return[matchResult1] ()
}
} of class class dotty.tools.dotc.ast.Trees$TypeDef # -1
exception while typing package <empty> {
final lazy module val i16207$package: i16207$package = new i16207$package()
@SourceFile("i16207.scala") final module class i16207$package() extends Object
() {
private def writeReplace(): AnyRef =
new scala.runtime.ModuleSerializationProxy(classOf[i16207$package.type])
def tple: Tuple = Tuple2.apply[String, String]("abc", "def")
matchResult1[Unit]:
{
case val x1: scala.collection.immutable.List[Int] @unchecked =
{
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[
Tuple.Union[(Tuple_this : Product)]]
]
:
scala.collection.immutable.List[
Tuple.Union[(Tuple_this : Product)]]
)
}.map[Int](
{
def $anonfun(_$1: Tuple.Union[(?1 : Tuple)]): Int = 1
closure($anonfun)
}
):scala.collection.immutable.List[Int] @unchecked
return[matchResult1] ()
}
}
} of class class dotty.tools.dotc.ast.Trees$PackageDef # -1
java.lang.AssertionError: assertion failed: no owner from <none>/ <none> in {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.<none> while running erasure on i16207.scala
exception occurred while compiling i16207.scala
java.lang.AssertionError: assertion failed: no owner from <none>/ <none> in {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.<none> while compiling i16207.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: no owner from <none>/ <none> in {
val Tuple_this: Tuple = tple
(
Tuple_this.productIterator.toList.asInstanceOf[
scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]]]
:scala.collection.immutable.List[Tuple.Union[(Tuple_this : Product)]])
}.<none>
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.transform.Erasure$Typer.typedSelect(Erasure.scala:716)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2897)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.transform.Erasure$Typer.typedTypeApply(Erasure.scala:812)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2947)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:831)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2928)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.transform.Erasure$Typer.typedTyped(Erasure.scala:631)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2933)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2326)
at dotty.tools.dotc.transform.Erasure$Typer.typedValDef(Erasure.scala:901)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2901)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3084)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3130)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1047)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1096)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1100)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2936)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedLabeled(Typer.scala:1799)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2921)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3111)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3130)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1047)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2562)
at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1036)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2916)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2920)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2990)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3084)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3130)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1047)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2692)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2961)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2991)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:126)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3058)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3062)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3174)
at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:324)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:328)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:247)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:263)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:271)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:280)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:280)
at dotty.tools.dotc.Run.compileSources(Run.scala:195)
at dotty.tools.dotc.Run.compile(Run.scala:179)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
at dotty.tools.dotc.Driver.process(Driver.scala:195)
at dotty.tools.dotc.Driver.process(Driver.scala:163)
at dotty.tools.dotc.Driver.process(Driver.scala:175)
at dotty.tools.dotc.Driver.main(Driver.scala:205)
at dotty.tools.dotc.Main.main(Main.scala) |
Adding |
Still broken in current nightly. Note that in Kacper's minimization:
Dale and I are digging. Some thoughts/findings:
But we don't even really have a hypothesis yet as to the actual cause. Some logic error in the mechanics of how denotations change from phase to phase? |
This fails in inlining rather than erasure with Exception in thread "main" java.lang.AssertionError: assertion failed:
Found: Tuple.Union[(?1 : Tuple)] => Int
Required: (Tuple match {
case EmptyTuple => Nothing
case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y]
}) => Int I believe the inlined code is equivalent to something like : def tple = Tuple("abc", "def")
{
val Tuple_this: Tuple = tple
Tuple_this.productIterator.toList.asInstanceOf[List[Tuple.Union[Tuple_this.type]]]: List[Tuple.Union[? <: Tuple]]
}.map(_ => 1) (The type ascription with the wildcard is produced by -- [E007] Type Mismatch Error: try/i16207.scala:37:52 --------------------------
37 | Tuple_this.productIterator.toList.asInstanceOf[List[Tuple.Union[Tuple_this.type]]]: List[Tuple.Union[? <: Tuple]]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|Found: List[Tuple.Union[(Tuple_this : Tuple)]]
|Required: List[
| Tuple match {
| case EmptyTuple => Nothing
| case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y]
| }
|]
|
|Note: a match type could not be fully reduced:
|
| trying to reduce Tuple.Union[(Tuple_this : Tuple)]
| trying to reduce Tuple.Fold[(Tuple_this : Tuple), Nothing, [x, y] =>> x | y]
| failed since selector (Tuple_this : Tuple)
| does not match case EmptyTuple => Nothing
| and cannot be shown to be disjoint from it either.
| Therefore, reduction cannot advance to the remaining case
|
| case h *: t => h | Tuple.Fold[t, Nothing, [x, y] =>> x | y]
|
| longer explanation available when compiling with `-explain` It seems that the match type applied to a wildcard gets eagerly reduced, if we can avoid that then the subtyping check should succeed. Additionally, we might also want to change ApproximatingTypeMap to approximate a match type by its upper bound instead of leaving a wildcard, since it doesn't seem like that buys us anything. |
diff --git compiler/src/dotty/tools/dotc/core/TypeComparer.scala compiler/src/dotty/tools/dotc/core/TypeComparer.scala
index abe17e21c2..697fa09b3c 100644
--- compiler/src/dotty/tools/dotc/core/TypeComparer.scala
+++ compiler/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -1013,12 +1013,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def widenScrutinee(scrutinee1: Type) = scrutinee1 match
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
case tp => tp.widenSkolem
- def checkScrutinee(scrutinee1: Type): Boolean =
- isSameType(scrutinee1, tp2.scrutinee) || {
- val widenScrutinee1 = widenScrutinee(scrutinee1)
- (widenScrutinee1 ne scrutinee1) && checkScrutinee(widenScrutinee1)
- }
- checkScrutinee(tp1.scrutinee) &&
+ def checkScrutinee(scrutinee1: Type, scrutinee2: Type): Boolean =
+ isSameType(scrutinee1, scrutinee2) ||
+ isSameType(widenScrutinee(scrutinee1), widenScrutinee(scrutinee2))
+ checkScrutinee(tp1.scrutinee, tp2.scrutinee) &&
tp1.cases.corresponds(tp2.cases)(isSubType)
case _ => false
} |
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Old definitions are made tasty compatible and just delegate to the new representation. Fixes scala#12721 Fixes scala#15992 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Old definitions are made tasty compatible and just delegate to the new representation. Fixes scala#12721 Fixes scala#15992 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Old definitions are made tasty compatible and just delegate to the new representation. Fixes scala#12721 Fixes scala#15992 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
This provides a way forward to fixing the signatures of some tuple methods, and removes the inlining from the tuple methods. Optimization will be implemented later directly on these method calls, which avoids unnecessary complications due to inlining artifacts. Fixes scala#12721 Fixes scala#16207
@dwijnand @SethTisue @smarter what is the current state of this issue? Would like to continue working on it during a future Spree? @KacperFKorban's minimization still crashes as of 3.4.0-RC1-bin-20240112-c50f2ff-NIGHTLY. |
The scope is this is not for a Spree anymore. Our only backward-compatible solution is to redefine the |
Compiler version
3.2.0, 3.2.1-RC4
Minimized code
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: