Skip to content
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

assertion failed: unresolved symbols while pickling quote with type bounds #14708

Closed
xuwei-k opened this issue Mar 18, 2022 · 4 comments · Fixed by #18133
Closed

assertion failed: unresolved symbols while pickling quote with type bounds #14708

xuwei-k opened this issue Mar 18, 2022 · 4 comments · Fixed by #18133
Assignees
Labels
Milestone

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Mar 18, 2022

Compiler version

  • 3.1.2-RC2
  • 3.1.1
  • 3.1.3-RC1-bin-20220317-17e46ad-NIGHTLY

Minimized code

import scala.quoted.*

object Main {
  def foo(a: Expr[Any])(using Quotes) = {
    a match {
      case '{ ($x: Set[t]).toSet } =>
      case _ =>
    }
  }
}

workaround(?)

import scala.quoted.*

object Main {
  def foo(a: Expr[Any])(using Quotes) = {
    a match {
      case '{
              type t1
              type t2 >: `t1`
              ($x: Set[`t1`]).toSet[`t2`]
            } =>
      case _ =>
    }
  }
}

Output (click arrow to expand)

[error] java.lang.AssertionError: assertion failed: unresolved symbols: value t$given1 (line 5) #14166 when pickling /Users/kenji/set-expr-match/Main.scala
[error] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[error] dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:777)
[error] dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:69)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.transform.Pickler.run$$anonfun$1(Pickler.scala:106)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.transform.Pickler.run(Pickler.scala:106)
[error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:308)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:309)
[error] dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:111)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:261)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:272)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:289)
[error] dotty.tools.dotc.Run.compileSources(Run.scala:222)
[error] dotty.tools.dotc.Run.compile(Run.scala:206)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:39)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:169)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:750)

@xuwei-k xuwei-k added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 18, 2022
@nicolasstucki
Copy link
Contributor

At first glance of the stacktrace, it seems this is happening in the Pickler phase before the changes in the later phases of #12540.
The Typer, in QuotesAndSplices might be generating type reference that the pickler does not know how to handle.

@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 18, 2022
@odersky
Copy link
Contributor

odersky commented Mar 19, 2022

The unresolved symbol gets created in typedQuoteTypeVar.
Looking at the code after Typer, something seems to be off:

[[syntax trees at end of                     typer]] // i14708.scala
package <empty>#1677 {
  import scala#25.quoted#422.*
  final lazy module val Main#2822: Main#2823 = new Main#2823()
  final module class Main#2823() extends Object() { this: Main#2822.type =>
    def foo#6754(a#6786: quoted#422.Expr#4925[Any#456])(using 
      x$2#7232: quoted#422.Quotes#4937
    ): Unit#155 = 
      {
        a#6786 match 
          {
            case 
              x$2#7232.asInstanceOf#2632[
                scala#25.quoted#422.runtime#4949.QuoteMatching#7251
              ].ExprMatch#7287.unapply#15094[Tuple1#302[t#14796 @ _], 
                (scala#25.quoted#422.Type#4943[t#14796], 
                  scala#25.quoted#422.Expr#4925[Set[t#14796]]
                )
              ](
                Tuple2#135.unapply#13801[scala#25.quoted#422.Type#4943[t#14796]
                  , 
                scala#25.quoted#422.Expr#4925[Set[t#14796]]](
                  given t$given1#14935 @ _
                , x#14936 @ _:scala#25.quoted#422.Expr#4925[Set#6796[t#14796]])
              )(
                '{
                  {
                    @patternType type t#14202
                    scala#25.quoted#422.runtime#4949.Patterns#7249.
                      patternHole#14206
                    [Set[t#14202]].toSet#14580[t$given1#14221.Underlying#14218]
                  }
                }.apply#14273(x$2#7232)
              )
             => 
              ()
            case _ => 
              ()
          }
      }
  }

Here, we do bind a t$given1 in the pattern of ExprMatch.unapply, but then we use it in the implicit argument to the same unapply. The second usage does not have a corresponding binding. Is this a case
of an illegal recursion between pattern and argument?

@nicolasstucki
Copy link
Contributor

After type checking we have

...
       '{
                  {
                    @patternType type t
                    scala.quoted.runtime.Patterns.patternHole[Set[t]].toSet[t$given1.Underlying]
                  }
                }.apply(x$2)
...

but we should have

       '{
                  {
                    @patternType type t
                    scala.quoted.runtime.Patterns.patternHole[Set[t]].toSet[t]
                  }
                }.apply(x$2)

This must be a bug in QuotesAndSplices.scala. Probably in splitQuotePattern.

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 10, 2023

Simpler workaround

-      case '{ ($x: Set[t]).toSet } =>
+      case '{ type t; ($x: Set[`t`]).toSet } =>

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 10, 2023
```scala
case '{ type u; f($x: t, $y: t, $z: u) }
```
is desugared to
```scala
case '{ type t; type u; f($x: `t`, $y: `t`, $z: `u`) }
```

Fixes scala#14708
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 10, 2023
```scala
case '{ type u; ($x: t, $y: t, $z: u) }
```
is desugared to
```scala
case '{ type t; type u; ($x: `t`, $y: `t`, $z: `u`) }
```

Fixes scala#14708
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 12, 2023
```scala
case '{ type u; ($x: t, $y: t, $z: u) }
```
is desugared to
```scala
case '{ type t; type u; ($x: `t`, $y: `t`, $z: `u`) }
```

Fixes scala#14708
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 12, 2023
```scala
case '{ type u; ($x: t, $y: t, $z: u) }
```
is desugared to
```scala
case '{ type t; type u; ($x: `t`, $y: `t`, $z: `u`) }
```

Fixes scala#14708
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 13, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 13, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 19, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 20, 2023
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment