Skip to content

Fixes&Changes to TASTY inspired by Linker #1003

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
merged 9 commits into from
Jan 4, 2016
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools
package dotc

import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.tasty.{TastyBuffer, TastyPickler}
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TastyBuffer, TastyPickler}
import util.SourceFile
import ast.{tpd, untpd}
import dotty.tools.dotc.core.Symbols._
Expand All @@ -23,4 +23,6 @@ class CompilationUnit(val source: SourceFile) {
* Subsequent phases can add new sections.
*/
var picklers: Map[ClassSymbol, TastyPickler] = Map()

var unpicklers: Map[ClassSymbol, TastyUnpickler] = Map()
}
1 change: 1 addition & 0 deletions src/dotty/tools/dotc/FromTasty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ object FromTasty extends Driver {
val (List(unpickled), source) = unpickler.body(readPositions = true)
val unit1 = new CompilationUnit(source)
unit1.tpdTree = unpickled
unit1.unpicklers += (clsd.classSymbol -> unpickler.unpickler)
force.traverse(unit1.tpdTree)
unit1
case _ =>
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object SymDenotations {
ownerIfExists: Symbol,
final val name: Name,
initFlags: FlagSet,
initInfo: Type,
final val initInfo: Type,
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {

//assert(symbol.id != 4940, name)
Expand Down
8 changes: 8 additions & 0 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,14 @@ object Types {
case _ => Nil
}

/** The parameter names of a PolyType or MethodType, Empty list for others */
final def paramNamess(implicit ctx: Context): List[List[TermName]] = this match {
case mt: MethodType => mt.paramNames :: mt.resultType.paramNamess
case pt: PolyType => pt.resultType.paramNamess
case _ => Nil
}


/** The parameter types in the first parameter section of a PolyType or MethodType, Empty list for others */
final def firstParamTypes(implicit ctx: Context): List[Type] = this match {
case mt: MethodType => mt.paramTypes
Expand Down
33 changes: 17 additions & 16 deletions src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tasty
import Contexts._, SymDenotations._
import dotty.tools.dotc.ast.tpd
import TastyUnpickler._, TastyBuffer._
import dotty.tools.dotc.core.tasty.DottyUnpickler.{SourceFileUnpickler, TreeSectionUnpickler, PositionsSectionUnpickler}
import util.Positions._
import util.{SourceFile, NoSource}
import PositionUnpickler._
Expand All @@ -15,6 +16,21 @@ object DottyUnpickler {

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

class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new SourceFile(tastyName(reader.readNameRef()).toString, Seq())
}

class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new TreeUnpickler(reader, tastyName)
}

class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new PositionUnpickler(reader).unpickle()
}
}

/** A class for unpickling Tasty trees and symbols.
Expand All @@ -23,7 +39,7 @@ object DottyUnpickler {
class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded {
import tpd._

private val unpickler = new TastyUnpickler(bytes)
val unpickler = new TastyUnpickler(bytes)
private val treeUnpickler = unpickler.unpickle(new TreeSectionUnpickler).get

/** Enter all toplevel classes and objects into their scopes
Expand All @@ -42,19 +58,4 @@ class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded {
treeUnpickler.usePositions(totalRange, positions)
(treeUnpickler.unpickle(), source)
}

private class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new SourceFile(tastyName(reader.readNameRef()).toString, Seq())
}

private class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new TreeUnpickler(reader, tastyName)
}

private class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") {
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
new PositionUnpickler(reader).unpickle()
}
}
5 changes: 4 additions & 1 deletion src/dotty/tools/dotc/core/tasty/TastyPickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import ast.tpd
class TastyPickler {

private val sections = new mutable.ArrayBuffer[(TastyName.NameRef, TastyBuffer)]
val uuid = UUID.randomUUID()

private val headerBuffer = {
val buf = new TastyBuffer(24)
for (ch <- header) buf.writeByte(ch.toByte)
buf.writeNat(MajorVersion)
buf.writeNat(MinorVersion)
val uuid = UUID.randomUUID()
buf.writeUncompressedLong(uuid.getMostSignificantBits)
buf.writeUncompressedLong(uuid.getLeastSignificantBits)
buf
Expand All @@ -31,6 +31,7 @@ class TastyPickler {
sections += ((nameBuffer.nameIndex(name), buf))

def assembleParts(): Array[Byte] = {
treePkl.compactify()
def lengthWithLength(buf: TastyBuffer) = {
buf.assemble()
buf.length + natSize(buf.length)
Expand Down Expand Up @@ -67,4 +68,6 @@ class TastyPickler {
* so one can reliably use this function only dirrectly after `pickler`
*/
var addrOfSym: Symbol => Option[Addr] = (_ => None)

val treePkl = new TreePickler(this)
}
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TastyReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =

/** Read an uncompressed Long stored in 8 bytes in big endian format */
def readUncompressedLong(): Long = {
var x = 0
var x: Long = 0
for (i <- 0 to 7)
x = (x << 8) | (readByte() & 0xff)
x
Expand Down
Loading