Skip to content

allow tasty version to be inspected #11167

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 1 commit into from
Jan 20, 2021
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
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class CompilationTests {
// "-source", "3.1", // TODO: re-enable once we allow : @unchecked in pattern definitions. Right now, lots of narrowing pattern definitions fail.
))(libGroup)

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

val compilerSources = sources(Paths.get("compiler/src")) ++ sources(Paths.get("compiler/src-bootstrapped"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dotty.tools.tasty

import java.util.UUID

import TastyFormat.{MajorVersion, MinorVersion, header}

sealed abstract case class TastyHeader(uuid: UUID, majorVersion: Int, minorVersion: Int)

class TastyHeaderUnpickler(reader: TastyReader) {
import reader._

def this(bytes: Array[Byte]) = this(new TastyReader(bytes))

/** delegates to `readFullHeader`, extracting the UUID */
def readHeader(): UUID =
readFullHeader().uuid

/**Reads the header of a Tasty File, the returned header, `h`,
* has the following properties:
* - `h.majorVersion == TastyFormat.MajorVersion`
* - `0 <= h.minorVersion <= TastyFormat.MinorVersion`
*/
def readFullHeader(): TastyHeader = {
for (i <- 0 until header.length)
check(readByte() == header(i), "not a TASTy file")
val majorVersion = readNat()
val minorVersion = readNat()
val validVersion = (
majorVersion == MajorVersion
&& minorVersion >= 0 && minorVersion <= MinorVersion
)
check(validVersion,
s"""TASTy signature has wrong version.
| expected: $MajorVersion.$MinorVersion
| found : ${majorVersion}.${minorVersion}""".stripMargin
)
val uuid = new UUID(readUncompressedLong(), readUncompressedLong())
new TastyHeader(uuid, majorVersion, minorVersion) {}
}

def isAtEnd: Boolean = reader.isAtEnd

private def check(cond: Boolean, msg: => String): Unit = {
if (!cond) throw new UnpickleException(msg)
}
}