Skip to content

Commit 9c21d7a

Browse files
authored
Merge pull request #10135 from dotty-staging/fix-jdk14-2
Fix #10131: load enum types more lazily
2 parents 757739c + 9dc145d commit 9c21d7a

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

.github/workflows/ci.yaml

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ on:
44
push:
55
paths-ignore:
66
# Do not run everything on changes only in docs
7-
- 'scala3doc/**'
7+
- 'scala3doc/**'
88
- 'scala3doc-testcases/**'
99
pull_request:
1010
paths-ignore:
1111
# Do not run everything on changes only in docs
12-
- 'scala3doc/**'
12+
- 'scala3doc/**'
1313
- 'scala3doc-testcases/**'
1414
schedule:
1515
- cron: '0 3 * * *' # Every day at 3 AM
@@ -20,13 +20,13 @@ env:
2020
jobs:
2121
test:
2222
runs-on: [self-hosted, Linux]
23-
container: lampepfl/dotty:2020-04-24
23+
container: lampepfl/dotty:2020-09-08
2424
if: "!(github.event_name == 'push' &&
2525
startsWith(github.event.ref, 'refs/tags/sbt-dotty-'))"
2626

2727
steps:
2828
- name: Set JDK 11 as default
29-
run: echo "/usr/lib/jvm/java-11-openjdk-amd64/bin" >> $GITHUB_PATH
29+
run: echo "/usr/lib/jvm/java-14-openjdk-amd64/bin" >> $GITHUB_PATH
3030

3131
- name: Checkout cleanup script
3232
uses: actions/checkout@v2
@@ -65,13 +65,13 @@ jobs:
6565
6666
test_bootstrapped:
6767
runs-on: [self-hosted, Linux]
68-
container: lampepfl/dotty:2020-04-24
68+
container: lampepfl/dotty:2020-09-08
6969
if: "!(github.event_name == 'push' &&
7070
startsWith(github.event.ref, 'refs/tags/sbt-dotty-'))"
7171

7272
steps:
7373
- name: Set JDK 11 as default
74-
run: echo "/usr/lib/jvm/java-11-openjdk-amd64/bin" >> $GITHUB_PATH
74+
run: echo "/usr/lib/jvm/java-14-openjdk-amd64/bin" >> $GITHUB_PATH
7575

7676
- name: Checkout cleanup script
7777
uses: actions/checkout@v2
@@ -143,7 +143,7 @@ jobs:
143143

144144
community_build:
145145
runs-on: [self-hosted, Linux]
146-
container: lampepfl/dotty:2020-04-24
146+
container: lampepfl/dotty:2020-09-08
147147

148148
steps:
149149
- name: Checkout cleanup script
@@ -184,7 +184,7 @@ jobs:
184184
185185
test_sbt:
186186
runs-on: [self-hosted, Linux]
187-
container: lampepfl/dotty:2020-04-24
187+
container: lampepfl/dotty:2020-09-08
188188
if: (
189189
github.event_name == 'push' &&
190190
startsWith(github.event.ref, 'refs/tags/')
@@ -227,7 +227,7 @@ jobs:
227227

228228
test_java8:
229229
runs-on: [self-hosted, Linux]
230-
container: lampepfl/dotty:2020-04-24
230+
container: lampepfl/dotty:2020-09-08
231231
if: "(
232232
github.event_name == 'push' &&
233233
startsWith(github.event.ref, 'refs/tags/') &&
@@ -274,7 +274,7 @@ jobs:
274274

275275
publish_nightly:
276276
runs-on: [self-hosted, Linux]
277-
container: lampepfl/dotty:2020-04-24
277+
container: lampepfl/dotty:2020-09-08
278278
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
279279
if: github.event_name == 'schedule'
280280
env:
@@ -321,7 +321,7 @@ jobs:
321321
322322
nightly_documentation:
323323
runs-on: [self-hosted, Linux]
324-
container: lampepfl/dotty:2020-04-24
324+
container: lampepfl/dotty:2020-09-08
325325
needs: [publish_nightly]
326326
if: github.event_name == 'schedule'
327327
env:
@@ -375,7 +375,7 @@ jobs:
375375

376376
publish_release:
377377
runs-on: [self-hosted, Linux]
378-
container: lampepfl/dotty:2020-04-24
378+
container: lampepfl/dotty:2020-09-08
379379
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
380380
if: github.event_name == 'push' &&
381381
startsWith(github.event.ref, 'refs/tags/') &&
@@ -470,7 +470,7 @@ jobs:
470470

471471
release_documentation:
472472
runs-on: [self-hosted, Linux]
473-
container: lampepfl/dotty:2020-04-24
473+
container: lampepfl/dotty:2020-09-08
474474
needs: [publish_release]
475475
if: github.event_name == 'push' &&
476476
startsWith(github.event.ref, 'refs/tags/') &&
@@ -527,7 +527,7 @@ jobs:
527527

528528
publish_sbt_release:
529529
runs-on: [self-hosted, Linux]
530-
container: lampepfl/dotty:2020-04-24
530+
container: lampepfl/dotty:2020-09-08
531531
needs: [community_build, test_sbt]
532532
if: github.event_name == 'push' &&
533533
startsWith(github.event.ref, 'refs/tags/sbt-dotty-')

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+30-17
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,24 @@ class ClassfileParser(
518518
}
519519
// sigToType
520520

521-
def parseAnnotArg(skip: Boolean = false)(using ctx: Context, in: DataReader): Option[untpd.Tree] = {
521+
class EnumTag(sig: String, name: NameOrString) {
522+
def toTree(using ctx: Context): untpd.Tree = {
523+
val enumClassTp = sigToType(sig)
524+
val enumModuleClass = enumClassTp.classSymbol.companionModule
525+
val tmref = TermRef(enumModuleClass.termRef, name.name)
526+
untpd.TypedSplice(ref(tmref))
527+
}
528+
}
529+
530+
def parseAnnotArg(skip: Boolean = false)(using ctx: Context, in: DataReader): Option[untpd.Tree | EnumTag] = {
522531

523532
// If we encounter an empty array literal, we need the type of the corresponding
524533
// parameter to properly type it, but that would require forcing the annotation
525534
// early. To avoid this we store annotation arguments as untyped trees
526-
import untpd._
527535

528536
// ... but constants need to actually be typed with a ConstantType, so we
529537
// can't rely on type inference, and type them early.
530-
def lit(c: Constant): Tree = TypedSplice(ast.tpd.Literal(c))
538+
def lit(c: Constant): untpd.Tree = untpd.TypedSplice(tpd.Literal(c))
531539

532540
val tag = in.nextByte.toChar
533541
val index = in.nextChar
@@ -545,34 +553,36 @@ class ClassfileParser(
545553
case CLASS_TAG =>
546554
if (skip) None else Some(lit(Constant(pool.getType(index))))
547555
case ENUM_TAG =>
548-
val enumClassTp = pool.getType(index)
556+
val sig = pool.getExternalName(index).value
549557
val enumCaseName = pool.getName(in.nextChar)
550-
if (skip)
551-
None
552-
else {
553-
val enumModuleClass = enumClassTp.classSymbol.companionModule
554-
Some(Select(ref(enumModuleClass), enumCaseName.name))
555-
}
558+
if (skip) None else Some(EnumTag(sig, enumCaseName))
556559
case ARRAY_TAG =>
557-
val arr = new ArrayBuffer[Tree]()
560+
val arr = new ArrayBuffer[untpd.Tree]()
558561
var hasError = false
559562
for (i <- 0 until index)
560563
parseAnnotArg(skip) match {
561-
case Some(c) => arr += c
564+
case Some(c: untpd.Tree) => arr += c
565+
case Some(tag: EnumTag) => arr += tag.toTree
562566
case None => hasError = true
563567
}
564568
if (hasError) None
565569
else if (skip) None
566570
else {
567571
val elems = arr.toList
568-
Some(untpd.JavaSeqLiteral(elems, TypeTree()))
572+
Some(untpd.JavaSeqLiteral(elems, untpd.TypeTree()))
569573
}
570574
case ANNOTATION_TAG =>
571575
parseAnnotation(index, skip).map(_.untpdTree)
572576
}
573577
}
574578

575-
class ClassfileAnnotation(annotType: Type, args: List[untpd.Tree]) extends LazyAnnotation {
579+
class ClassfileAnnotation(annotType: Type, lazyArgs: List[(NameOrString, untpd.Tree | EnumTag)]) extends LazyAnnotation {
580+
private def args(using Context): List[untpd.Tree] =
581+
lazyArgs.map {
582+
case (name, tree: untpd.Tree) => untpd.NamedArg(name.name, tree).withSpan(NoSpan)
583+
case (name, tag: EnumTag) => untpd.NamedArg(name.name, tag.toTree).withSpan(NoSpan)
584+
}
585+
576586
protected var mySym: Symbol | (Context ?=> Symbol) =
577587
(using ctx: Context) => annotType.classSymbol
578588

@@ -598,13 +608,16 @@ class ClassfileParser(
598608
case _ =>
599609

600610
val nargs = in.nextChar
601-
val argbuf = new ListBuffer[untpd.Tree]
611+
val argbuf = new ListBuffer[(NameOrString, untpd.Tree | EnumTag)]
602612
var hasError = false
603613
for (i <- 0 until nargs) {
604614
val name = pool.getName(in.nextChar)
605615
parseAnnotArg(skip) match {
606-
case Some(arg) => argbuf += untpd.NamedArg(name.name, arg)
607-
case None => hasError = !skip
616+
case Some(arg) =>
617+
argbuf += name -> arg
618+
619+
case None =>
620+
hasError = !skip
608621
}
609622
}
610623
if (hasError || skip) None

0 commit comments

Comments
 (0)