Skip to content

Commit 8cec943

Browse files
committed
Allow separate compilation of Dotty using TASTY
Classfile parser now reads TASTY attributes or annotations and unpickles them in order to allow for separate compilation.
1 parent 7ebc9e2 commit 8cec943

File tree

6 files changed

+74
-7
lines changed

6 files changed

+74
-7
lines changed

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ class Definitions {
335335
lazy val ContravariantBetweenClass = ctx.requiredClass("dotty.annotation.internal.ContravariantBetween")
336336
lazy val ScalaSignatureAnnot = ctx.requiredClass("scala.reflect.ScalaSignature")
337337
lazy val ScalaLongSignatureAnnot = ctx.requiredClass("scala.reflect.ScalaLongSignature")
338+
lazy val TASTYSignatureAnnot = ctx.requiredClass("scala.annotation.internal.TASTYSignature")
339+
lazy val TASTYLongSignatureAnnot = ctx.requiredClass("scala.annotation.internal.TASTYLongSignature")
338340
lazy val DeprecatedAnnot = ctx.requiredClass("scala.deprecated")
339341
lazy val MigrationAnnot = ctx.requiredClass("scala.annotation.migration")
340342
lazy val AnnotationDefaultAnnot = ctx.requiredClass("dotty.annotation.internal.AnnotationDefault")

src/dotty/tools/dotc/core/pickling/ClassfileParser.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,17 @@ class ClassfileParser(
664664
i < attrs
665665
}
666666

667-
def unpickle(bytes: Array[Byte]): Boolean = {
667+
def unpickleScala(bytes: Array[Byte]): Boolean = {
668668
new UnPickler(bytes, classRoot, moduleRoot)(ctx).run()
669669
true
670670
}
671671

672+
def unpickleTASTY(bytes: Array[Byte]): Boolean = {
673+
new DottyUnpickler(bytes)
674+
.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))
675+
true
676+
}
677+
672678
def parseScalaSigBytes: Array[Byte] = {
673679
val tag = in.nextByte.toChar
674680
assert(tag == STRING_TAG, tag)
@@ -688,6 +694,11 @@ class ClassfileParser(
688694
pool.getBytes(entries.toList)
689695
}
690696

697+
if (scan(tpnme.TASTYATTR)) {
698+
val attrLen = in.nextInt
699+
return unpickleTASTY(in.nextBytes(attrLen))
700+
}
701+
691702
if (scan(tpnme.RuntimeAnnotationATTR)) {
692703
val attrLen = in.nextInt
693704
val nAnnots = in.nextChar
@@ -698,12 +709,16 @@ class ClassfileParser(
698709
var j = 0
699710
while (j < nArgs) {
700711
val argName = pool.getName(in.nextChar)
701-
if (attrClass == defn.ScalaSignatureAnnot && argName == nme.bytes)
702-
return unpickle(parseScalaSigBytes)
703-
else if (attrClass == defn.ScalaLongSignatureAnnot && argName == nme.bytes)
704-
return unpickle(parseScalaLongSigBytes)
705-
else
706-
parseAnnotArg(skip = true)
712+
if (argName == nme.bytes)
713+
if (attrClass == defn.ScalaSignatureAnnot)
714+
return unpickleScala(parseScalaSigBytes)
715+
else if (attrClass == defn.ScalaLongSignatureAnnot)
716+
return unpickleScala(parseScalaLongSigBytes)
717+
else if (attrClass == defn.TASTYSignatureAnnot)
718+
return unpickleTASTY(parseScalaSigBytes)
719+
else if (attrClass == defn.TASTYLongSignatureAnnot)
720+
return unpickleTASTY(parseScalaLongSigBytes)
721+
parseAnnotArg(skip = true)
707722
j += 1
708723
}
709724
i += 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package scala.annotation.internal;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.TYPE)
10+
public @interface TASTYLongSignature {
11+
public String[] bytes();
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package scala.annotation.internal;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.TYPE)
10+
public @interface TASTYSignature {
11+
public String bytes();
12+
}

tests/pos/sepComp/A_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sepComp
2+
3+
class A(y: Int) {
4+
5+
val x: Int = y
6+
7+
}
8+
9+
object A {
10+
11+
def apply(x: Int) = new A(22)
12+
13+
}

tests/pos/sepComp/B_2.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sepComp
2+
3+
class B extends A(22) {
4+
5+
val y: Int = this.x
6+
7+
val a = A(33)
8+
9+
println(a.x)
10+
11+
}
12+
13+

0 commit comments

Comments
 (0)