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

Runtime staging cannot handle compiling functions with a second non-primitive argument #19176

Closed
christophkoch opened this issue Dec 3, 2023 · 2 comments
Assignees
Labels

Comments

@christophkoch
Copy link

christophkoch commented Dec 3, 2023

Compiler version

3.3.1

Minimized code

import scala.quoted.*
given staging.Compiler = staging.Compiler.make(Predef.getClass.getClassLoader)

class A
val f: (A, Int) => Int = staging.run { '{ (q: A, x: Int) => x } }

@main def run = f

Output (click arrow to expand)

[info] running run

exception while retyping def $anonfun(q: A, x: Int): Int =
{
x
} of class DefDef # -1

An unhandled exception was thrown in the compiler.
Please file a crash report here:
https://github.com/lampepfl/dotty/issues/new/choose

 while compiling: <quoted.Expr>
    during phase: erasure
            mode: Mode(ImplicitsEnabled,ReadPositions)
 library version: version 2.13.10
compiler version: version 3.3.1
        settings: -classpath /Users/ckoch/.sbt/boot/scala-2.12.17/org.scala-sbt/sbt/1.8.0/test-interface-1.0.jar:/Users/ckoch/.sbt/boot/scala-2.12.17/org.scala-sbt/sbt/1.8.0/util-interface-1.8.0.jar:/Users/ckoch/.sbt/boot/scala-2.12.17/org.scala-sbt/sbt/1.8.0/compiler-interface-1.8.0.jar:/Users/ckoch/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar:/Users/ckoch/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar -d <quote compilation output>

            tree: apply
   tree position: :<unknown>
       tree type: (Generated$Code$From$Quoted.this.apply : (): Object)
          symbol: method apply in class Generated$Code$From$Quoted

symbol definition: def apply(): Object (a Symbol)
symbol package:
symbol owners: in class Generated$Code$From$Quoted
call site: method apply in class Generated$Code$From$Quoted in module class

== Source file context for tree position ==

Exception in thread "sbt-bg-threads-1" java.lang.ExceptionInInitializerError
at run.main(Bug2.scala:7)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at sbt.Run.invokeMain(Run.scala:143)
at sbt.Run.execute$1(Run.scala:93)
at sbt.Run.$anonfun$runWithLoader$5(Run.scala:120)
at sbt.Run$.executeSuccess(Run.scala:186)
at sbt.Run.runWithLoader(Run.scala:120)
at sbt.Defaults$.$anonfun$bgRunTask$6(Defaults.scala:1980)
at sbt.Defaults$.$anonfun$termWrapper$2(Defaults.scala:1919)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.util.Try$.apply(Try.scala:213)
at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:366)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: dotty.tools.FatalError: cannot resolve reference to type ( : .type).A
the classfile defining the type might be missing from the classpath
or the self type of ( : .type) might not contain all transitive dependencies
at dotty.tools.FatalError$.apply(FatalError.scala:3)
at dotty.tools.dotc.core.TypeErasure.checkedSuperType(TypeErasure.scala:717)
at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:602)
at dotty.tools.dotc.core.TypeErasure.paramErasure$1(TypeErasure.scala:650)
at dotty.tools.dotc.core.TypeErasure.$anonfun$1(TypeErasure.scala:658)
at scala.collection.immutable.List.mapConserve(List.scala:472)
at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:658)
at dotty.tools.dotc.core.TypeErasure.eraseInfo(TypeErasure.scala:773)
at dotty.tools.dotc.core.TypeErasure$.transformInfo(TypeErasure.scala:244)
at dotty.tools.dotc.transform.Erasure.transform(Erasure.scala:97)
at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:826)
at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:872)
at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2361)
at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2324)
at dotty.tools.dotc.ast.Trees$DenotingTree.denot(Trees.scala:256)
at dotty.tools.dotc.ast.Trees$Tree.symbol(Trees.scala:145)
at dotty.tools.dotc.typer.ReTyper.retrieveSym(ReTyper.scala:119)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3014)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1052)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1159)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1163)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3056)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:2047)
at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:897)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3070)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3181)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
at dotty.tools.dotc.typer.Typer.$anonfun$57(Typer.scala:2486)
at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:243)
at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2486)
at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:953)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3024)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1052)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1041)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3036)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3040)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3111)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3210)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3256)
at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1052)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3081)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3112)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:146)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3184)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3188)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3300)
at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
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:262)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
at dotty.tools.dotc.Run.compileUnits(Run.scala:200)
at scala.quoted.staging.QuoteCompiler$ExprRun.compileExpr(QuoteCompiler.scala:118)
at scala.quoted.staging.QuoteDriver.run(QuoteDriver.scala:43)
at scala.quoted.staging.Compiler$$anon$1.run(Compiler.scala:38)
at scala.quoted.staging.package$.run(staging.scala:19)
at Bug2$package$.(Bug2.scala:5)
... 18 more

@christophkoch christophkoch added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 3, 2023
@hamzaremmal hamzaremmal 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 Dec 3, 2023
@christophkoch christophkoch changed the title Runtime staging cannont handle compiling functions with a second non-primitive argument Runtime staging cannot handle compiling functions with a second non-primitive argument Dec 3, 2023
@nicolasstucki
Copy link
Contributor

This has the same issue and solution as #19170 (comment)

@jchyb
Copy link
Contributor

jchyb commented Apr 26, 2024

Closed by #20137. Ensuring that the correct class loader was passed might be near-impossible, but we have improved the reporting here so that it's handled as a thrown exception rather than printing on stdout and we also include a hint on what may be wrong with the classloader in the exception message.

@jchyb jchyb closed this as completed Apr 26, 2024
WojciechMazur pushed a commit that referenced this issue Jun 27, 2024
This addresses part of #19211, #19170, and #19176

[Cherry-picked 693a80a]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants