diff options
author | Martin Odersky <odersky@gmail.com> | 2015-02-23 13:44:37 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:14:09 +0100 |
commit | b32244b5b5e3a1209624966fce7073d2f5594f48 (patch) | |
tree | 335cecf1a0906ebe1e18d4cd87f2264c35457504 | |
parent | 89c00f601678f58d0ddb424ffe680940f760eaeb (diff) | |
download | dotty-b32244b5b5e3a1209624966fce7073d2f5594f48.tar.gz dotty-b32244b5b5e3a1209624966fce7073d2f5594f48.tar.bz2 dotty-b32244b5b5e3a1209624966fce7073d2f5594f48.zip |
Add UUID to Tasty
Tasty files now always carry a random UUID.
4 files changed, 20 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala index e4bd95af2..42a1cc1b5 100644 --- a/src/dotty/tools/dotc/core/pickling/PickleFormat.scala +++ b/src/dotty/tools/dotc/core/pickling/PickleFormat.scala @@ -22,8 +22,9 @@ Micro-syntax: Macro-format: - File = Header majorVersion_Nat minorVersion_Nat nameTable_Length Name* Section* + File = Header majorVersion_Nat minorVersion_Nat UUID nameTable_Length Name* Section* Header = "5CA1AB1F" + UUID = Byte*16 Section = NameRef Length Bytes Length = Nat // length of rest of entry in bytes diff --git a/src/dotty/tools/dotc/core/pickling/TastyPickler.scala b/src/dotty/tools/dotc/core/pickling/TastyPickler.scala index 32cc1ae43..ee0e5a8fa 100644 --- a/src/dotty/tools/dotc/core/pickling/TastyPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TastyPickler.scala @@ -6,16 +6,20 @@ package pickling import PickleFormat._ import collection.mutable import TastyBuffer._ +import java.util.UUID class TastyPickler { private val sections = new mutable.ArrayBuffer[(TastyName.NameRef, TastyBuffer)] private val headerBuffer = { - val buf = new TastyBuffer(16) + val buf = new TastyBuffer(28) 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 } diff --git a/src/dotty/tools/dotc/core/pickling/TastyPrinter.scala b/src/dotty/tools/dotc/core/pickling/TastyPrinter.scala index 8a6ce0221..d4b4330e8 100644 --- a/src/dotty/tools/dotc/core/pickling/TastyPrinter.scala +++ b/src/dotty/tools/dotc/core/pickling/TastyPrinter.scala @@ -10,7 +10,7 @@ import TastyUnpickler._ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) { val unpickler = new TastyUnpickler(bytes) - import unpickler.{tastyName, unpickled} + import unpickler.{tastyName, unpickle} def nameToString(name: TastyName): String = name match { case Simple(name) => name.toString @@ -33,7 +33,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) { println("Names:") printNames() println("Trees:") - unpickled(new TreeUnpickler) + unpickle(new TreeUnpickler) } class TreeUnpickler extends SectionUnpickler[Unit]("ASTs") { diff --git a/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala b/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala index f2d075446..596b7542d 100644 --- a/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala +++ b/src/dotty/tools/dotc/core/pickling/TastyUnpickler.scala @@ -5,6 +5,7 @@ package pickling import scala.collection.mutable import PickleFormat._ import Names.{Name, termName} +import java.util.UUID object TastyUnpickler { class UnpickleException(msg: String) extends Exception(msg) @@ -62,17 +63,21 @@ class TastyUnpickler(reader: TastyReader) { result } - locally { + private def readHeader() = { val magic = readBytes(8) check(magic.map(_.toChar).mkString == header, "not a TASTy file") val major = readNat() val minor = readNat() - def versionMsg = + check(major == MajorVersion && minor <= MinorVersion, s"""TASTy signature has wrong version. | expected: $MajorVersion.$MinorVersion - | found : $major.$minor""".stripMargin - check(major == MajorVersion, versionMsg) - if (MajorVersion == 0) check(minor == MinorVersion, versionMsg) + | found : $major.$minor""".stripMargin) + new UUID(readUncompressedLong(), readUncompressedLong()) + } + + val uuid = readHeader() + + locally { until(readEnd()) { tastyName.add(readName()) } while (!isAtEnd) { val secName = readString() @@ -82,7 +87,7 @@ class TastyUnpickler(reader: TastyReader) { } } - def unpickled[R](sec: SectionUnpickler[R]): Option[R] = + def unpickle[R](sec: SectionUnpickler[R]): Option[R] = for (reader <- sectionReader.get(sec.name)) yield sec.unpickle(reader, tastyName) } |