-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attributes section to TASTy and use it for Stdlib TASTy (#18599)
The `Attributes` section contains a list `Attribute` tags. 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 `SCALA2STANDARDLIBRARYattr` attribute to the TASTy file. We mark all unpickled classes from those TASTy files with `Scala2x | Scala2Tasty`. Attributes will also be used to mark files that were compiled with explicit nulls using the `EXPLICITNULLSattr` attribute.
- Loading branch information
Showing
12 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dotty.tools.dotc.core.tasty | ||
|
||
import dotty.tools.dotc.ast.{tpd, untpd} | ||
|
||
import dotty.tools.tasty.TastyBuffer | ||
import dotty.tools.tasty.TastyFormat, TastyFormat.AttributesSection | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
object AttributePickler: | ||
|
||
def pickleAttributes( | ||
attributes: Attributes, | ||
pickler: TastyPickler, | ||
buf: TastyBuffer | ||
): Unit = | ||
if attributes.scala2StandardLibrary || attributes.explicitNulls then // or any other attribute is set | ||
pickler.newSection(AttributesSection, buf) | ||
// Pickle attributes | ||
if attributes.scala2StandardLibrary then buf.writeNat(TastyFormat.SCALA2STANDARDLIBRARYattr) | ||
if attributes.explicitNulls then buf.writeNat(TastyFormat.EXPLICITNULLSattr) | ||
end if | ||
|
||
end pickleAttributes | ||
|
||
end AttributePickler |
33 changes: 33 additions & 0 deletions
33
compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dotty.tools.dotc | ||
package core.tasty | ||
|
||
import scala.language.unsafeNulls | ||
|
||
import dotty.tools.tasty.{TastyFormat, TastyReader, TastyBuffer} | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
class AttributeUnpickler(reader: TastyReader): | ||
import reader._ | ||
|
||
lazy val attributeTags: List[Int] = | ||
val listBuilder = List.newBuilder[Int] | ||
while !isAtEnd do listBuilder += readNat() | ||
listBuilder.result() | ||
|
||
lazy val attributes: Attributes = { | ||
var scala2StandardLibrary = false | ||
var explicitNulls = false | ||
for attributeTag <- attributeTags do | ||
attributeTag match | ||
case TastyFormat.SCALA2STANDARDLIBRARYattr => scala2StandardLibrary = true | ||
case TastyFormat.EXPLICITNULLSattr => explicitNulls = true | ||
case attribute => | ||
assert(false, "Unexpected attribute value: " + attribute) | ||
Attributes( | ||
scala2StandardLibrary, | ||
explicitNulls, | ||
) | ||
} | ||
|
||
end AttributeUnpickler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dotty.tools.dotc.core.tasty | ||
|
||
class Attributes( | ||
val scala2StandardLibrary: Boolean, | ||
val explicitNulls: Boolean, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters