Skip to content

Type member appears in java generic signature (this breaks graal native and won't make javac happy either) #15091

Closed
@arixmkii

Description

@arixmkii

Compiler version

3.1.2

Minimized code

package io.github.arixmkii

import MyTypes.*

object Main extends MyInstances {

  def method[F[_], A](implicit F: Empty[F]): A = ???

  def main(args: Array[String]): Unit = {
    method[WrappedF[Id, *], Unit]
  }

}

object MyTypes {
  // Id effect
  type Id[A] = A

  // The most basic typeclass
  trait Empty[F[_]]

  // Empty wrapped effect type and related impl
  sealed abstract class WrappedFImpl {
    type T[F[_], A]
  }

  type WrappedF[F[_], A] = instance.T[F, A]

  val instance: WrappedFImpl = new WrappedFImpl {
    type T[F[_], A] = F[A]
  }
}

trait MyInstances {

  implicit def forWrappedF[F[_]]: Empty[WrappedF[F, *]] =
    new Empty[WrappedF[F, *]] {}
}

The full demo project (with compile and native image build for Scala 2 and 3) is here.

Output

It compiles with scalac -unchecked -deprecation -feature -language:implicitConversions -Ykind-projector, but when GraalVM native image build is called on the bytecode it results in exception:

Fatal error: java.lang.TypeNotPresentException: Type io.github.arixmkii.MyTypes$WrappedFImpl.T not present
  | => fat java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
	at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
	at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
	at java.base/sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
	at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
	at java.base/sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
	at java.base/sun.reflect.generics.repository.MethodRepository.computeReturnType(MethodRepository.java:75)
	at java.base/sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository.java:66)
	at java.base/java.lang.reflect.Method.getGenericReturnType(Method.java:295)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.registerTypesForMethod(ReflectionDataBuilder.java:483)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.processMethodMetadata(ReflectionDataBuilder.java:284)
	at com.oracle.svm.reflect.hosted.ReflectionDataBuilder.duringAnalysis(ReflectionDataBuilder.java:185)
	at com.oracle.svm.reflect.hosted.ReflectionFeature.duringAnalysis(ReflectionFeature.java:189)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:726)
	at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:74)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:726)
	at com.oracle.graal.pointsto.PointsToAnalysis.runAnalysis(PointsToAnalysis.java:751)
	at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:723)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:558)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
Caused by: java.lang.ClassNotFoundException: io.github.arixmkii.MyTypes$WrappedFImpl.T
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:467)
	at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
	... 23 more

Expectation

Native image is generated successfully as it is for the same code with Scala 2.13.8 and old kind-projector plugin.

Additional notes

It is not clear if this is something, which should be addressed in dotty, but taking into account that native image is working on the generated bytecode it may be. If this is not for dotty team, then may be the team can add comments for GraalVM developers in this issue oracle/graal#4530 to help them.

Also, it is only my assumption that this is kind projector related as I didn't manage to minimize that code below, what is shown here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions