Skip to content

Match error in backend using Java defined annotation with default parameters #2704

Closed
@olafurpg

Description

@olafurpg

While trying to compile the compiler-benchmark with Dotty I hit on a match error in the backend

[error] Error while emitting ColdDotcBenchmark.scala
[error] Block(List(ValDef(warmups$1,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$2)), ValDef(jvm$1,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$3)), ValDef(jvmArgs$1,TypeTree[RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(TypeRef(NoPrefix,lang)),String), 0))],Apply(Apply(TypeApply(Select(Ident(Array),apply),List(TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))])),List(SeqLiteral(List(Literal(Constant(-XX:CICompilerCount=2))),TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))]))),List(Apply(TypeApply(Select(Ident(ClassTag),apply),List(TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))])),List(Literal(Constant(TypeRef(ThisType(TypeRef(NoPrefix,lang)),String)))))))), ValDef(jvmArgsPrepend$1,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$5))),Apply(Select(New(TypeTree[TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),org)/withSig(Signature(List(),)),openjdk)/withSig(Signature(List(),)),jmh)/withSig(Signature(List(),)),annotations)/withSig(Signature(List(),)),Fork)]),<init>),List(Literal(Constant(16)), Select(This(Ident(ColdDotcBenchmark)),warmups$1), Select(This(Ident(ColdDotcBenchmark)),jvm$1), Select(This(Ident(ColdDotcBenchmark)),jvmArgs$1), Select(This(Ident(ColdDotcBenchmark)),jvmArgsPrepend$1), Select(Ident(Fork),$lessinit$greater$default$6)))) (of class dotty.tools.dotc.ast.Trees$Block)
scala.MatchError: Block(List(ValDef(warmups$3,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$2)), ValDef(jvm$3,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$3)), ValDef(jvmArgs$3,TypeTree[RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Array), scala$Array$$T, TypeAlias(TypeRef(ThisType(TypeRef(NoPrefix,lang)),String), 0))],Apply(Apply(TypeApply(Select(Ident(Array),apply),List(TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))])),List(SeqLiteral(List(Literal(Constant(-XX:CICompilerCount=2))),TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))]))),List(Apply(TypeApply(Select(Ident(ClassTag),apply),List(TypeTree[TypeVar(ParamRef(scala$Array$apply$$T) -> TypeRef(ThisType(TypeRef(NoPrefix,lang)),String))])),List(Literal(Constant(TypeRef(ThisType(TypeRef(NoPrefix,lang)),String)))))))), ValDef(jvmArgsPrepend$3,TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing)],Select(Ident(Fork),$lessinit$greater$default$5))),Apply(Select(New(TypeTree[TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),org)/withSig(Signature(List(),)),openjdk)/withSig(Signature(List(),)),jmh)/withSig(Signature(List(),)),annotations)/withSig(Signature(List(),)),Fork)]),<init>),List(Literal(Constant(16)), Select(This(Ident(ColdScalacBenchmark)),warmups$3), Select(This(Ident(ColdScalacBenchmark)),jvm$3), Select(This(Ident(ColdScalacBenchmark)),jvmArgs$3), Select(This(Ident(ColdScalacBenchmark)),jvmArgsPrepend$3), Select(Ident(Fork),$lessinit$greater$default$6)))) (of class dotty.tools.dotc.ast.Trees$Block)
    at dotty.tools.backend.jvm.DottyBackendInterface.assocsFromApply(DottyBackendInterface.scala:530)
    at dotty.tools.backend.jvm.DottyBackendInterface$$anon$10.assocs(DottyBackendInterface.scala:521)
    at dotty.tools.backend.jvm.DottyBackendInterface.emitAnnotations$$anonfun$6(DottyBackendInterface.scala:306)

With -Xprint:all

[info] result of /Users/ollie/dev/compiler-benchmark/compilation/src/main/scala/dotty/tools/dotc/ColdDotcBenchmark.scala after genBCode:
[info]
[info] package dotty.tools.dotc {
[info]   @scala.annotation.internal.SourceFile(
[info]     "/Users/ollie/dev/compiler-benchmark/compilation/src/main/scala/dotty/tools/dotc/ColdDotcBenchmark.scala"
[info]   ) @{
[info]     <accessor> val warmups$1: Nothing =
[info]       org.openjdk.jmh.annotations.Fork.$lessinit$greater$default$2
[info]     <accessor> val jvm$1: Nothing =
[info]       org.openjdk.jmh.annotations.Fork.$lessinit$greater$default$3
[info]     <accessor> val jvmArgs$1: Array{scala$Array$$T = String} =
[info]       Array.apply[String^](["-XX:CICompilerCount=2" : String^])(
[info]         scala.reflect.ClassTag.apply[String^](classOf[class String])
[info]       )
[info]     <accessor> val jvmArgsPrepend$1: Nothing =
[info]       org.openjdk.jmh.annotations.Fork.$lessinit$greater$default$5
[info]     new org.openjdk.jmh.annotations.Fork(16,
[info]       dotty.tools.dotc.ColdDotcBenchmark.this.warmups$1
[info]     , dotty.tools.dotc.ColdDotcBenchmark.this.jvm$1,
[info]       dotty.tools.dotc.ColdDotcBenchmark.this.jvmArgs$1
[info]     , dotty.tools.dotc.ColdDotcBenchmark.this.jvmArgsPrepend$1,
[info]       org.openjdk.jmh.annotations.Fork.$lessinit$greater$default$6
[info]     )
[info]   } @org.openjdk.jmh.annotations.OutputTimeUnit(MILLISECONDS) @
[info]     org.openjdk.jmh.annotations.BenchmarkMode
[info]   (
[info]     Array.apply[org.openjdk.jmh.annotations.Mode^](
[info]       [SingleShotTime : org.openjdk.jmh.annotations.Mode^]
[info]     )(
[info]       scala.reflect.ClassTag.apply[org.openjdk.jmh.annotations.Mode^](
[info]         classOf[class Mode]
[info]       )
[info]     )
[info]   ) @org.openjdk.jmh.annotations.State(Benchmark) class ColdDotcBenchmark
[info]      extends
[info]    base.BaseDotcBenchmark {
[info]     def <init>(): Unit =
[info]       {
[info]         super()
[info]         ()
[info]       }
[info]     @org.openjdk.jmh.annotations.Benchmark() override def compile(): Unit =
[info]       super.compile()
[info]   }
[info] }
[info]

The source file where the error happens ColdDotcBenchmark.scala: https://github.com/lampepfl/compiler-benchmark/blob/82392bc30df11946cb489d45afc2698e3b48bced/compilation/src/main/scala/dotty/tools/dotc/ColdDotcBenchmark.scala#L10-L18

The @Fork annotations is defined in Java from the JMH project, https://github.com/jacek-lewandowski/jmh-jl/blob/fc92780b525f6376b2433518b3dc90a5f511feef/jmh-core/src/main/java/org/openjdk/jmh/annotations/Fork.java#L44

I made several attempts to minimize the error with Fork.java and a tiny Foo.scala but didn't manage to reproduce. To reproduce in the environment I hit the error:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions