Skip to content

Commit 013c823

Browse files
committed
Merge pull request #1003 from dotty-staging/linker/tasty
Fixes&Changes to TASTY inspired by Linker
2 parents 4bca332 + ef73669 commit 013c823

File tree

10 files changed

+339
-296
lines changed

10 files changed

+339
-296
lines changed

src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33

44
import dotty.tools.dotc.core.Types.Type
5-
import dotty.tools.dotc.core.tasty.{TastyBuffer, TastyPickler}
5+
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TastyBuffer, TastyPickler}
66
import util.SourceFile
77
import ast.{tpd, untpd}
88
import dotty.tools.dotc.core.Symbols._
@@ -23,4 +23,6 @@ class CompilationUnit(val source: SourceFile) {
2323
* Subsequent phases can add new sections.
2424
*/
2525
var picklers: Map[ClassSymbol, TastyPickler] = Map()
26+
27+
var unpicklers: Map[ClassSymbol, TastyUnpickler] = Map()
2628
}

src/dotty/tools/dotc/FromTasty.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ object FromTasty extends Driver {
8686
val (List(unpickled), source) = unpickler.body(readPositions = true)
8787
val unit1 = new CompilationUnit(source)
8888
unit1.tpdTree = unpickled
89+
unit1.unpicklers += (clsd.classSymbol -> unpickler.unpickler)
8990
force.traverse(unit1.tpdTree)
9091
unit1
9192
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object SymDenotations {
6969
ownerIfExists: Symbol,
7070
final val name: Name,
7171
initFlags: FlagSet,
72-
initInfo: Type,
72+
final val initInfo: Type,
7373
initPrivateWithin: Symbol = NoSymbol) extends SingleDenotation(symbol) {
7474

7575
//assert(symbol.id != 4940, name)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,14 @@ object Types {
10111011
case _ => Nil
10121012
}
10131013

1014+
/** The parameter names of a PolyType or MethodType, Empty list for others */
1015+
final def paramNamess(implicit ctx: Context): List[List[TermName]] = this match {
1016+
case mt: MethodType => mt.paramNames :: mt.resultType.paramNamess
1017+
case pt: PolyType => pt.resultType.paramNamess
1018+
case _ => Nil
1019+
}
1020+
1021+
10141022
/** The parameter types in the first parameter section of a PolyType or MethodType, Empty list for others */
10151023
final def firstParamTypes(implicit ctx: Context): List[Type] = this match {
10161024
case mt: MethodType => mt.paramTypes

src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package tasty
66
import Contexts._, SymDenotations._
77
import dotty.tools.dotc.ast.tpd
88
import TastyUnpickler._, TastyBuffer._
9+
import dotty.tools.dotc.core.tasty.DottyUnpickler.{SourceFileUnpickler, TreeSectionUnpickler, PositionsSectionUnpickler}
910
import util.Positions._
1011
import util.{SourceFile, NoSource}
1112
import PositionUnpickler._
@@ -15,6 +16,21 @@ object DottyUnpickler {
1516

1617
/** Exception thrown if classfile is corrupted */
1718
class BadSignature(msg: String) extends RuntimeException(msg)
19+
20+
class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") {
21+
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
22+
new SourceFile(tastyName(reader.readNameRef()).toString, Seq())
23+
}
24+
25+
class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") {
26+
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
27+
new TreeUnpickler(reader, tastyName)
28+
}
29+
30+
class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") {
31+
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
32+
new PositionUnpickler(reader).unpickle()
33+
}
1834
}
1935

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

26-
private val unpickler = new TastyUnpickler(bytes)
42+
val unpickler = new TastyUnpickler(bytes)
2743
private val treeUnpickler = unpickler.unpickle(new TreeSectionUnpickler).get
2844

2945
/** Enter all toplevel classes and objects into their scopes
@@ -42,19 +58,4 @@ class DottyUnpickler(bytes: Array[Byte]) extends ClassfileParser.Embedded {
4258
treeUnpickler.usePositions(totalRange, positions)
4359
(treeUnpickler.unpickle(), source)
4460
}
45-
46-
private class SourceFileUnpickler extends SectionUnpickler[SourceFile]("Sourcefile") {
47-
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
48-
new SourceFile(tastyName(reader.readNameRef()).toString, Seq())
49-
}
50-
51-
private class TreeSectionUnpickler extends SectionUnpickler[TreeUnpickler]("ASTs") {
52-
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
53-
new TreeUnpickler(reader, tastyName)
54-
}
55-
56-
private class PositionsSectionUnpickler extends SectionUnpickler[(Position, AddrToPosition)]("Positions") {
57-
def unpickle(reader: TastyReader, tastyName: TastyName.Table) =
58-
new PositionUnpickler(reader).unpickle()
59-
}
6061
}

src/dotty/tools/dotc/core/tasty/TastyPickler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import ast.tpd
1313
class TastyPickler {
1414

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

1718
private val headerBuffer = {
1819
val buf = new TastyBuffer(24)
1920
for (ch <- header) buf.writeByte(ch.toByte)
2021
buf.writeNat(MajorVersion)
2122
buf.writeNat(MinorVersion)
22-
val uuid = UUID.randomUUID()
2323
buf.writeUncompressedLong(uuid.getMostSignificantBits)
2424
buf.writeUncompressedLong(uuid.getLeastSignificantBits)
2525
buf
@@ -31,6 +31,7 @@ class TastyPickler {
3131
sections += ((nameBuffer.nameIndex(name), buf))
3232

3333
def assembleParts(): Array[Byte] = {
34+
treePkl.compactify()
3435
def lengthWithLength(buf: TastyBuffer) = {
3536
buf.assemble()
3637
buf.length + natSize(buf.length)
@@ -67,4 +68,6 @@ class TastyPickler {
6768
* so one can reliably use this function only dirrectly after `pickler`
6869
*/
6970
var addrOfSym: Symbol => Option[Addr] = (_ => None)
71+
72+
val treePkl = new TreePickler(this)
7073
}

src/dotty/tools/dotc/core/tasty/TastyReader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TastyReader(val bytes: Array[Byte], start: Int, end: Int, val base: Int =
9999

100100
/** Read an uncompressed Long stored in 8 bytes in big endian format */
101101
def readUncompressedLong(): Long = {
102-
var x = 0
102+
var x: Long = 0
103103
for (i <- 0 to 7)
104104
x = (x << 8) | (readByte() & 0xff)
105105
x

0 commit comments

Comments
 (0)