Skip to content

Make standard section names part of TastyFormat #10431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import dotty.tools.dotc.core.Contexts._

import dotty.tools.tasty.TastyBuffer
import TastyBuffer.{Addr, NoAddr}
import dotty.tools.tasty.TastyFormat.CommentsSection

import java.nio.charset.StandardCharsets

class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]):
private val buf = new TastyBuffer(5000)
pickler.newSection("Comments", buf)
pickler.newSection(CommentsSection, buf)

def pickleComment(root: tpd.Tree): Unit = traverse(root)

Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import Names.SimpleName
import TreeUnpickler.UnpickleMode

import dotty.tools.tasty.TastyReader
import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection}

object DottyUnpickler {

/** Exception thrown if classfile is corrupted */
class BadSignature(msg: String) extends RuntimeException(msg)

class TreeSectionUnpickler(posUnpickler: Option[PositionUnpickler], commentUnpickler: Option[CommentUnpickler])
extends SectionUnpickler[TreeUnpickler](TreePickler.sectionName) {
extends SectionUnpickler[TreeUnpickler](ASTsSection) {
def unpickle(reader: TastyReader, nameAtRef: NameTable): TreeUnpickler =
new TreeUnpickler(reader, nameAtRef, posUnpickler, commentUnpickler)
}

class PositionsSectionUnpickler extends SectionUnpickler[PositionUnpickler]("Positions") {
class PositionsSectionUnpickler extends SectionUnpickler[PositionUnpickler](PositionsSection) {
def unpickle(reader: TastyReader, nameAtRef: NameTable): PositionUnpickler =
new PositionUnpickler(reader, nameAtRef)
}

class CommentsSectionUnpickler extends SectionUnpickler[CommentUnpickler]("Comments") {
class CommentsSectionUnpickler extends SectionUnpickler[CommentUnpickler](CommentsSection) {
def unpickle(reader: TastyReader, nameAtRef: NameTable): CommentUnpickler =
new CommentUnpickler(reader)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotc
package core
package tasty

import dotty.tools.tasty.TastyFormat.SOURCE
import dotty.tools.tasty.TastyFormat.{SOURCE, PositionsSection}
import dotty.tools.tasty.TastyBuffer
import TastyBuffer._

Expand All @@ -23,7 +23,7 @@ class PositionPickler(

import ast.tpd._
val buf: TastyBuffer = new TastyBuffer(5000)
pickler.newSection("Positions", buf)
pickler.newSection(PositionsSection, buf)

private val pickledIndices = new mutable.BitSet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import StdNames.nme
import TastyUnpickler._
import util.Spans.offsetToInt
import printing.Highlighting._
import dotty.tools.tasty.TastyFormat.ASTsSection

/** Reads the package and class name of the class contained in this TASTy */
class TastyClassName(bytes: Array[Byte]) {
Expand All @@ -21,7 +22,7 @@ class TastyClassName(bytes: Array[Byte]) {
/** Returns a tuple with the package and class names */
def readName(): Option[(TermName, TermName)] = unpickle(new TreeSectionUnpickler)

class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](TreePickler.sectionName) {
class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](ASTsSection) {
import dotty.tools.tasty.TastyFormat._
def unpickle(reader: TastyReader, tastyName: NameTable): (TermName, TermName) = {
import reader._
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Names.Name
import TastyUnpickler._
import util.Spans.offsetToInt
import printing.Highlighting._
import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection}

object TastyPrinter:
def show(bytes: Array[Byte])(using Context): String =
Expand Down Expand Up @@ -57,7 +58,7 @@ class TastyPrinter(bytes: Array[Byte]) {
sb.result
}

class TreeSectionUnpickler extends SectionUnpickler[String](TreePickler.sectionName) {
class TreeSectionUnpickler extends SectionUnpickler[String](ASTsSection) {
import dotty.tools.tasty.TastyFormat._

private val sb: StringBuilder = new StringBuilder
Expand Down Expand Up @@ -133,7 +134,7 @@ class TastyPrinter(bytes: Array[Byte]) {
}
}

class PositionSectionUnpickler extends SectionUnpickler[String]("Positions") {
class PositionSectionUnpickler extends SectionUnpickler[String](PositionsSection) {

private val sb: StringBuilder = new StringBuilder

Expand All @@ -150,7 +151,7 @@ class TastyPrinter(bytes: Array[Byte]) {
}
}

class CommentSectionUnpickler extends SectionUnpickler[String]("Comments") {
class CommentSectionUnpickler extends SectionUnpickler[String](CommentsSection) {

private val sb: StringBuilder = new StringBuilder

Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import printing.Texts._
import util.SourceFile
import annotation.constructorOnly
import collection.mutable
import dotty.tools.tasty.TastyFormat.ASTsSection

object TreePickler {

val sectionName = "ASTs"

case class Hole(isTermHole: Boolean, idx: Int, args: List[tpd.Tree])(implicit @constructorOnly src: SourceFile) extends tpd.Tree {
override def isTerm: Boolean = isTermHole
override def isType: Boolean = !isTermHole
Expand All @@ -36,7 +35,7 @@ object TreePickler {

class TreePickler(pickler: TastyPickler) {
val buf: TreeBuffer = new TreeBuffer
pickler.newSection(TreePickler.sectionName, buf)
pickler.newSection(ASTsSection, buf)
import TreePickler._
import buf._
import pickler.nameBuffer.nameIndex
Expand Down
8 changes: 6 additions & 2 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Note: Tree tags are grouped into 5 categories that determine what follows, and t
Category 4 (tags 110-127): tag Nat AST
Category 5 (tags 128-255): tag Length <payload>

Standard Section: "Positions" Assoc*
Standard-Section: "Positions" Assoc*

Assoc = Header offset_Delta? offset_Delta? point_Delta?
| SOURCE nameref_Int
Expand All @@ -244,7 +244,7 @@ Standard Section: "Positions" Assoc*

All elements of a position section are serialized as Ints

Standard Section: "Comments" Comment*
Standard-Section: "Comments" Comment*

Comment = Length Bytes LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates.

Expand All @@ -257,6 +257,10 @@ object TastyFormat {
val MajorVersion: Int = 25
val MinorVersion: Int = 0

final val ASTsSection = "ASTs"
final val PositionsSection = "Positions"
final val CommentsSection = "Comments"

/** Tags used to serialize names, should update [[nameTagToString]] if a new constant is added */
class NameTags {
final val UTF8 = 1 // A simple name in UTF8 encoding.
Expand Down