Skip to content

Commit 645d7f5

Browse files
committed
Use Scala2x flags for unpickled Scala 2 stdlib TASTy
Also introduce `Scala2Tasty` flag to differentiate between Scala 2 symbols that come from class files and Scala 2 symbols that come from TASTy. At this point, the only Scala 2 TASTy is the one from the standard library. To know that a TASTy contains the definitions of the standard library, we add the `Scala2StandardLibrary` attribute to the TASTy file. We mark all unpickled classes from those TASTy files with `Scala2x | Scala2Tasty`.
1 parent 9481cf9 commit 645d7f5

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ object Flags {
308308
*/
309309
val (_, StableRealizable @ _, _) = newFlags(24, "<stable>")
310310

311-
/** A case parameter accessor */
312-
val (_, CaseAccessor @ _, _) = newFlags(25, "<caseaccessor>")
311+
/** A case parameter accessor / an unpickled Scala 2 TASTy (only for Scala 2 stdlib) */
312+
val (_, CaseAccessor @ _, Scala2Tasty @ _) = newFlags(25, "<caseaccessor>", "<scala-2-tasty>")
313313

314314
/** A Scala 2x super accessor / an unpickled Scala 2.x class */
315315
val (SuperParamAliasOrScala2x @ _, SuperParamAlias @ _, Scala2x @ _) = newFlags(26, "<super-param-alias>", "<scala-2.x>")

compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package core.tasty
33

44
import scala.language.unsafeNulls
55

6-
import dotty.tools.tasty.{TastyReader, TastyBuffer}
6+
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer}
77

88
import java.nio.charset.StandardCharsets
99

@@ -23,4 +23,6 @@ class AttributeUnpickler(reader: TastyReader):
2323
attributesBuilder.result()
2424
}
2525

26+
def scala2Stdlib: Boolean = attributes.contains(TastyFormat.Scala2StandardLibraryAttribute)
27+
2628
end AttributeUnpickler

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class TreeUnpickler(reader: TastyReader,
9999
/** Was unpickled class compiled with capture checks? */
100100
private var withCaptureChecks: Boolean = false
101101

102+
private val unpicklingScala2Lib =
103+
attributeUnpicklerOpt.exists(_.scala2Stdlib)
104+
102105
private def registerSym(addr: Addr, sym: Symbol) =
103106
symAtAddr(addr) = sym
104107

@@ -610,7 +613,8 @@ class TreeUnpickler(reader: TastyReader,
610613
val rhsStart = currentAddr
611614
val rhsIsEmpty = nothingButMods(end)
612615
if (!rhsIsEmpty) skipTree()
613-
val (givenFlags, annotFns, privateWithin) = readModifiers(end)
616+
val (givenFlags0, annotFns, privateWithin) = readModifiers(end)
617+
val givenFlags = if isClass && unpicklingScala2Lib then givenFlags0 | Scala2x | Scala2Tasty else givenFlags0
614618
pickling.println(i"creating symbol $name at $start with flags ${givenFlags.flagsString}, isAbsType = $isAbsType, $ttag")
615619
val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty)
616620
def adjustIfModule(completer: LazyType) =

compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
7777

7878
// Create extension methods, except if the class comes from Scala 2
7979
// because it adds extension methods before pickling.
80-
if (!(valueClass.is(Scala2x)))
80+
if !valueClass.is(Scala2x, butNot = Scala2Tasty) then
8181
for (decl <- valueClass.classInfo.decls)
8282
if isMethodWithExtension(decl) then
8383
enterInModuleClass(createExtensionMethod(decl, moduleClassSym.symbol))

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import reporting.{ThrowingReporter, Profile, Message}
1616
import collection.mutable
1717
import util.concurrent.{Executor, Future}
1818
import compiletime.uninitialized
19+
import dotty.tools.tasty.TastyFormat.Scala2StandardLibraryAttribute
1920

2021
object Pickler {
2122
val name: String = "pickler"
@@ -108,7 +109,9 @@ class Pickler extends Phase {
108109
pickler, treePkl.buf.addrOfTree, treePkl.docString, tree,
109110
scratch.commentBuffer)
110111

111-
val attributes = Nil // TODO add attributes here
112+
val attributes =
113+
if ctx.settings.Yscala2Stdlib.value then List(Scala2StandardLibraryAttribute)
114+
else Nil
112115
AttributePickler.pickleAttributes(attributes, pickler, scratch.attributeBuffer)
113116

114117
val pickled = pickler.assembleParts()

stdlib-bootstrapped-tasty-tests/src/Main.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object HelloWorld:
1717
testScala2ObjectParents()
1818
testScala2CaseClassUnderscoreMembers()
1919
testScalaNumberUnderlying()
20+
testArrayOps()
2021
scala.collection.mutable.UnrolledBufferTest.test()
2122
}
2223

@@ -68,3 +69,9 @@ object HelloWorld:
6869
val _: Object = MyNumber2(BigInt(1)).underlying
6970
val _: Object = (MyNumber2(BigInt(1)): ScalaNumber).underlying
7071
}
72+
73+
def testArrayOps() = {
74+
new collection.ArrayOps[String](Array[String]("foo")).exists(x => true)
75+
}
76+
77+
end HelloWorld

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ object TastyFormat {
366366
final val CommentsSection = "Comments"
367367
final val AttributesSection = "Attributes"
368368

369+
final val Scala2StandardLibraryAttribute = "Scala2StandardLibrary"
370+
369371
/** Tags used to serialize names, should update [[TastyFormat$.nameTagToString]] if a new constant is added */
370372
class NameTags {
371373
final val UTF8 = 1 // A simple name in UTF8 encoding.

0 commit comments

Comments
 (0)