Skip to content

Commit 896a59f

Browse files
committed
allow tasty version to be inspected
1 parent cc8ffb1 commit 896a59f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class CompilationTests {
247247
// "-source", "3.1", // TODO: re-enable once we allow : @unchecked in pattern definitions. Right now, lots of narrowing pattern definitions fail.
248248
))(libGroup)
249249

250-
val tastyCoreSources = sources(Paths.get("tasty/src"))
250+
val tastyCoreSources = sources(Paths.get("tasty/src")) ++ sources(Paths.get("tasty/src-bootstrapped"))
251251
val tastyCore = compileList("tastyCore", tastyCoreSources, opt)(tastyCoreGroup)
252252

253253
val compilerSources = sources(Paths.get("compiler/src")) ++ sources(Paths.get("compiler/src-bootstrapped"))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dotty.tools.tasty
2+
3+
import java.util.UUID
4+
5+
import TastyFormat.{MajorVersion, MinorVersion, header}
6+
7+
sealed abstract case class TastyHeader(uuid: UUID, majorVersion: Int, minorVersion: Int)
8+
9+
class TastyHeaderUnpickler(reader: TastyReader) {
10+
import reader._
11+
12+
def this(bytes: Array[Byte]) = this(new TastyReader(bytes))
13+
14+
/** delegates to `readFullHeader`, extracting the UUID */
15+
def readHeader(): UUID =
16+
readFullHeader().uuid
17+
18+
/**Reads the header of a Tasty File, the returned header, `h`,
19+
* has the following properties:
20+
* - `h.majorVersion == TastyFormat.MajorVersion`
21+
* - `0 <= h.minorVersion <= TastyFormat.MinorVersion`
22+
*/
23+
def readFullHeader(): TastyHeader = {
24+
for (i <- 0 until header.length)
25+
check(readByte() == header(i), "not a TASTy file")
26+
val majorVersion = readNat()
27+
val minorVersion = readNat()
28+
val validVersion = (
29+
majorVersion == MajorVersion
30+
&& minorVersion >= 0 && minorVersion <= MinorVersion
31+
)
32+
check(validVersion,
33+
s"""TASTy signature has wrong version.
34+
| expected: $MajorVersion.$MinorVersion
35+
| found : ${majorVersion}.${minorVersion}""".stripMargin
36+
)
37+
val uuid = new UUID(readUncompressedLong(), readUncompressedLong())
38+
new TastyHeader(uuid, majorVersion, minorVersion) {}
39+
}
40+
41+
def isAtEnd: Boolean = reader.isAtEnd
42+
43+
private def check(cond: Boolean, msg: => String): Unit = {
44+
if (!cond) throw new UnpickleException(msg)
45+
}
46+
}

0 commit comments

Comments
 (0)