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 c35f47a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 40 deletions.
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/config/ScalaRelease.scala
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
28 changes: 15 additions & 13 deletions tasty/test/dotty/tools/tasty/TastyVersionFormatTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package dotty.tools.tasty
import org.junit.Assert._
import org.junit.{Test, Ignore}

import dotty.tools.tasty.TastyVersion

import TastyFormat._
import TastyBuffer._

Expand All @@ -13,10 +11,10 @@ class TastyVersionFormatTest {
import TastyVersionFormatTest._

/** aliases `TastyVersion.apply` */
def compiler(major: Int, minor: Int, experimental: Experimental) = tastyVersion(major, minor, experimental)
def compiler(major: Int, minor: Int, experimental: Experimental) = TastyVersion(major, minor, experimental)

/** aliases `TastyVersion.apply` */
def file(major: Int, minor: Int, experimental: Experimental) = tastyVersion(major, minor, experimental)
def file(major: Int, minor: Int, experimental: Experimental) = TastyVersion(major, minor, experimental)

@Test def accept_ExperimentalReadEQExperimental_EQMinor: Unit = {
assert(file(28,1,Exp(1)) <:< compiler(28,1,Exp(1))) // same minor, same experimental
Expand Down Expand Up @@ -71,18 +69,22 @@ object TastyVersionFormatTest {
val Final: Experimental = 0
def Exp(i: Int): Experimental = i.ensuring(_ > 0)

implicit class TastyVersionOps(fileVersion: TastyVersion) {
def <:<(compilerVersion: TastyVersion): Boolean = TastyFormat.isVersionCompatible(fileVersion, compilerVersion)

/**if `file unrelated compiler` then tasty file must be rejected.*/
def unrelatedTo(compilerVersion: TastyVersion): Boolean = !(fileVersion <:< compilerVersion)
}

def tastyVersion(major: Int, minor: Int, experimental: Experimental) = {
case class TastyVersion(major: Int, minor: Int, experimental: Experimental) { file =>
assert(major >= 0)
assert(minor >= 0)
assert(experimental >= 0)
TastyVersion(major, minor, experimental)

def <:<(compiler: TastyVersion): Boolean = TastyFormat.isVersionCompatible(
fileMajor = file.major,
fileMinor = file.minor,
fileExperimental = file.experimental,
compilerMajor = compiler.major,
compilerMinor = compiler.minor,
compilerExperimental = compiler.experimental
)

/**if `file unrelated compiler` then tasty file must be rejected.*/
def unrelatedTo(compiler: TastyVersion): Boolean = !(file <:< compiler)
}

}

0 comments on commit c35f47a

Please sign in to comment.