Skip to content

Commit

Permalink
scala-release: Adjust MiMa filters; Revert changes to tasty module
Browse files Browse the repository at this point in the history
  • Loading branch information
prolativ committed Dec 29, 2021
1 parent ea97378 commit 6c52cbc
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 27 deletions.
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/config/ScalaRelease.scala
@@ -1,7 +1,5 @@
package dotty.tools.dotc.config

import dotty.tools.tasty.TastyVersion

enum ScalaRelease(val majorVersion: Int, val minorVersion: Int) extends Ordered[ScalaRelease]:
case Release3_0 extends ScalaRelease(3, 0)
case Release3_1 extends ScalaRelease(3, 1)
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Expand Up @@ -38,8 +38,9 @@ import xsbti.AnalysisCallback
import plugins._
import java.util.concurrent.atomic.AtomicInteger
import java.nio.file.InvalidPathException
import dotty.tools.tasty.{ TastyFormat, TastyVersion }
import dotty.tools.tasty.TastyFormat
import dotty.tools.dotc.config.{ NoScalaVersion, SpecificScalaVersion, AnyScalaVersion, ScalaBuild }
import dotty.tools.dotc.core.tasty.TastyVersion

object Contexts {

Expand Down
Expand Up @@ -3,7 +3,7 @@ package dotc
package core
package classfile

import dotty.tools.tasty.{ TastyFormat, TastyReader, TastyHeaderUnpickler, TastyVersion }
import dotty.tools.tasty.{ TastyFormat, TastyReader, TastyHeaderUnpickler }

import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._
import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotations._, util.Spans._
Expand All @@ -20,6 +20,7 @@ import java.util.UUID
import scala.collection.immutable
import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
import scala.annotation.switch
import tasty.TastyVersion
import typer.Checking.checkNonCyclic
import io.{AbstractFile, PlainFile, ZipArchive}
import scala.util.control.NonFatal
Expand Down Expand Up @@ -964,12 +965,12 @@ class ClassfileParser(
|found: ${fileTastyVersion.show}
""".stripMargin)

val isTastyReadable = TastyFormat.isVersionCompatible(fileVersion = fileTastyVersion, compilerVersion = TastyVersion.compilerVersion)
val isTastyReadable = fileTastyVersion.isCompatibleWith(TastyVersion.compilerVersion)
if !isTastyReadable then
reportWrongTasty("its TASTy format cannot be read by the compiler", TastyVersion.compilerVersion)
else
val isTastyCompatible =
TastyFormat.isVersionCompatible(fileVersion = fileTastyVersion, compilerVersion = ctx.tastyVersion) ||
fileTastyVersion.isCompatibleWith(ctx.tastyVersion) ||
classRoot.symbol.showFullName.startsWith("scala.") // References to stdlib are considered safe because we check the values of @since annotations
if !isTastyCompatible then
reportWrongTasty(s"its TASTy format is not compatible with the one of the targeted Scala release (${ctx.scalaRelease.show})", ctx.tastyVersion)
Expand Down
Expand Up @@ -10,7 +10,7 @@ import classfile.ClassfileParser
import Names.SimpleName
import TreeUnpickler.UnpickleMode

import dotty.tools.tasty.{ TastyReader, TastyVersion }
import dotty.tools.tasty.TastyReader
import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection}

object DottyUnpickler {
Expand Down
@@ -1,7 +1,14 @@
package dotty.tools.tasty
package dotty.tools.dotc.core.tasty

import dotty.tools.tasty.TastyFormat

case class TastyVersion(major: Int, minor: Int, experimental: Int) {
def show = "" + major + "." + minor + "-" + experimental
def show = s"$major.$minor-$experimental"

def isCompatibleWith(that: TastyVersion): Boolean = TastyFormat.isVersionCompatible(
this.major, this.minor, this.experimental,
that.major, that.minor, that.experimental
)
}

object TastyVersion {
Expand All @@ -13,4 +20,4 @@ object TastyVersion {
TastyVersion(tastyMajor, tastyMinor, 0)
}

}
}
3 changes: 3 additions & 0 deletions project/MiMaFilters.scala
Expand Up @@ -25,5 +25,8 @@ object MiMaFilters {
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language.3.1"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$3$u002E1$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$3$u002E1$minusmigration$"),

// Private to the compiler - needed for forward binary compatibility
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.since")
)
}
14 changes: 9 additions & 5 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Expand Up @@ -338,12 +338,16 @@ object TastyFormat {
* @syntax markdown
*/
def isVersionCompatible(
fileVersion: TastyVersion,
compilerVersion: TastyVersion
fileMajor: Int,
fileMinor: Int,
fileExperimental: Int,
compilerMajor: Int,
compilerMinor: Int,
compilerExperimental: Int
): Boolean = (
fileVersion.major == compilerVersion.major &&
( fileVersion.minor == compilerVersion.minor && fileVersion.experimental == compilerVersion.experimental // full equality
|| fileVersion.minor < compilerVersion.minor && fileVersion.experimental == 0 // stable backwards compatibility
fileMajor == compilerMajor &&
( fileMinor == compilerMinor && fileExperimental == compilerExperimental // full equality
|| fileMinor < compilerMinor && fileExperimental == 0 // stable backwards compatibility
)
)

Expand Down
25 changes: 13 additions & 12 deletions tasty/src/dotty/tools/tasty/TastyHeaderUnpickler.scala
Expand Up @@ -45,8 +45,7 @@ class TastyHeaderUnpickler(reader: TastyReader) {
val fileMajor = readNat()
if (fileMajor <= 27) { // old behavior before `tasty-core` 3.0.0-M4
val fileMinor = readNat()
val fileTastyVersion = TastyVersion(fileMajor, fileMinor, 0)
val signature = signatureString(fileTastyVersion, TastyVersion.compilerVersion)
val signature = signatureString(fileMajor, fileMinor, 0)
throw new UnpickleException(signature + backIncompatAddendum + toolingAddendum)
}
else {
Expand All @@ -60,15 +59,17 @@ class TastyHeaderUnpickler(reader: TastyReader) {
new String(bytes, start.index, length)
}

val fileTastyVersion = TastyVersion(fileMajor, fileMinor, fileExperimental)

val validVersion = TastyFormat.isVersionCompatible(
fileVersion = fileTastyVersion,
compilerVersion = TastyVersion.compilerVersion
fileMajor = fileMajor,
fileMinor = fileMinor,
fileExperimental = fileExperimental,
compilerMajor = MajorVersion,
compilerMinor = MinorVersion,
compilerExperimental = ExperimentalVersion
)

check(validVersion, {
val signature = signatureString(fileTastyVersion, TastyVersion.compilerVersion)
val signature = signatureString(fileMajor, fileMinor, fileExperimental)
val producedByAddendum = s"\nThe TASTy file was produced by $toolingVersion.$toolingAddendum"
val msg = (
if (fileExperimental != 0) unstableAddendum
Expand Down Expand Up @@ -99,16 +100,16 @@ object TastyHeaderUnpickler {
""
)

private def signatureString(found: TastyVersion, expected: TastyVersion) = {
private def signatureString(fileMajor: Int, fileMinor: Int, fileExperimental: Int) = {
def showMinorVersion(min: Int, exp: Int) = {
val expStr = if (exp == 0) "" else s" [unstable release: $exp]"
s"$min$expStr"
}
val expectedMinorVersion = showMinorVersion(expected.minor, expected.experimental)
val foundMinorVersion = showMinorVersion(found.minor, found.experimental)
val minorVersion = showMinorVersion(MinorVersion, ExperimentalVersion)
val fileMinorVersion = showMinorVersion(fileMinor, fileExperimental)
s"""TASTy signature has wrong version.
| expected: {majorVersion: ${expected.major}, minorVersion: $expectedMinorVersion}
| found : {majorVersion: ${found.major}, minorVersion: $foundMinorVersion}
| expected: {majorVersion: $MajorVersion, minorVersion: $minorVersion}
| found : {majorVersion: $fileMajor, minorVersion: $fileMinorVersion}
|
|""".stripMargin
}
Expand Down

0 comments on commit 6c52cbc

Please sign in to comment.