Skip to content

Commit 4dc6fab

Browse files
authored
Merge pull request #12438 from dotty-staging/backport/final-tasty-version
[backport] Tasty: set experimental to zero
2 parents b0cfb0d + 7863e97 commit 4dc6fab

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,27 @@ object TastyFormat {
301301
* is able to read final TASTy documents if the file's
302302
* `MinorVersion` is strictly less than the current value.
303303
*/
304-
final val ExperimentalVersion: Int = 3
304+
final val ExperimentalVersion: Int = 0
305305

306306
/**This method implements a binary relation (`<:<`) between two TASTy versions.
307+
*
307308
* We label the lhs `file` and rhs `compiler`.
308309
* if `file <:< compiler` then the TASTy file is valid to be read.
309310
*
310-
* TASTy versions have a partial order,
311-
* for example `a <:< b` and `b <:< a` are both false if `a` and `b` have different major versions.
311+
* A TASTy version, e.g. `v := 28.0-3` is composed of three fields:
312+
* - v.major == 28
313+
* - v.minor == 0
314+
* - v.experimental == 3
315+
*
316+
* TASTy versions have a partial order, for example,
317+
* `a <:< b` and `b <:< a` are both false if
318+
* - `a` and `b` have different `major` fields.
319+
* - `a` and `b` have different `experimental` fields, both non-zero.
320+
*
321+
* A zero value for an `experimental` field is considered
322+
* to be a stable TASTy version, and has higher precedence
323+
* than a TASTy version with the same `major`/`minor` fields
324+
* but a non-zero `experimental` field.
312325
*
313326
* We follow the given algorithm:
314327
* ```

tasty/test/dotty/tools/tasty/TastyVersionFormatTest.scala

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,69 @@ class TastyVersionFormatTest {
1111
import TastyVersionFormatTest._
1212

1313
/** aliases `TastyVersion.apply` */
14-
def compiler(major: Int, minor: Int, experimental: Int) = TastyVersion(major, minor, experimental)
14+
def compiler(major: Int, minor: Int, experimental: Experimental) = TastyVersion(major, minor, experimental)
1515

1616
/** aliases `TastyVersion.apply` */
17-
def file(major: Int, minor: Int, experimental: Int) = TastyVersion(major, minor, experimental)
17+
def file(major: Int, minor: Int, experimental: Experimental) = TastyVersion(major, minor, experimental)
1818

1919
@Test def accept_ExperimentalReadEQExperimental_EQMinor: Unit = {
20-
assert(file(28,1,1) <:< compiler(28,1,1)) // same minor, same experimental
20+
assert(file(28,1,Exp(1)) <:< compiler(28,1,Exp(1))) // same minor, same experimental
2121
}
2222

2323
@Test def accept_ExperimentalReadFinal_LTMinor: Unit = {
24-
assert(file(28,0,0) <:< compiler(28,1,1)) // preceding minor
24+
assert(file(28,0,Final) <:< compiler(28,1,Exp(1))) // preceding minor
2525
}
2626

2727
@Test def accept_FinalReadFinal_LTEqualMinor: Unit = {
28-
assert(file(28,0,0) <:< compiler(28,1,0)) // preceding minor
29-
assert(file(28,0,0) <:< compiler(28,0,0)) // same minor
28+
assert(file(28,0,Final) <:< compiler(28,1,Final)) // preceding minor
29+
assert(file(28,0,Final) <:< compiler(28,0,Final)) // same minor
3030
}
3131

3232
/** these cases are unrelated because a final compiler can only read final tasty of <= minor version */
3333
@Test def reject_FinalReadFinal_GTMinor: Unit = {
34-
assert(file(28,2,0) unrelatedTo compiler(28,1,0)) // succeeding minor
34+
assert(file(28,2,Final) unrelatedTo compiler(28,1,Final)) // succeeding minor
3535
}
3636

3737
/** these cases are unrelated because a final compiler can not read experimental tasty */
3838
@Test def reject_FinalReadExperimental: Unit = {
39-
assert(file(28,0,1) unrelatedTo compiler(28,1,0)) // preceding minor
40-
assert(file(28,1,1) unrelatedTo compiler(28,1,0)) // same minor
41-
assert(file(28,2,1) unrelatedTo compiler(28,1,0)) // succeeding minor
39+
assert(file(28,0,Exp(1)) unrelatedTo compiler(28,1,Final)) // preceding minor
40+
assert(file(28,1,Exp(1)) unrelatedTo compiler(28,1,Final)) // same minor
41+
assert(file(28,2,Exp(1)) unrelatedTo compiler(28,1,Final)) // succeeding minor
4242
}
4343

4444
/** These cases are unrelated because an experimental compiler can only read final tasty of < minor version */
4545
@Test def reject_ExperimentalReadFinal_GTEqualMinor: Unit = {
46-
assert(file(28,2,0) unrelatedTo compiler(28,1,1)) // succeeding minor
47-
assert(file(28,1,0) unrelatedTo compiler(28,1,1)) // equal minor
46+
assert(file(28,2,Final) unrelatedTo compiler(28,1,Exp(1))) // succeeding minor
47+
assert(file(28,1,Final) unrelatedTo compiler(28,1,Exp(1))) // equal minor
4848
}
4949

5050
/**These cases are unrelated because both compiler and file are experimental,
5151
* and with unequal experimental part.
5252
*/
5353
@Test def reject_ExperimentalReadNEExperimental: Unit = {
54-
assert(file(28,1,2) unrelatedTo compiler(28,1,1)) // same minor version, succeeding experimental
55-
assert(file(28,1,1) unrelatedTo compiler(28,1,2)) // same minor version, preceding experimental
54+
assert(file(28,1,Exp(2)) unrelatedTo compiler(28,1,Exp(1))) // same minor version, succeeding experimental
55+
assert(file(28,1,Exp(1)) unrelatedTo compiler(28,1,Exp(2))) // same minor version, preceding experimental
5656
}
5757

5858
/** these cases are unrelated because the major version must be identical */
5959
@Test def reject_NEMajor: Unit = {
60-
assert(file(27,0,0) unrelatedTo compiler(28,0,0)) // less than
61-
assert(file(29,0,0) unrelatedTo compiler(28,0,0)) // greater than
60+
assert(file(27,0,Final) unrelatedTo compiler(28,0,Final)) // less than
61+
assert(file(29,0,Final) unrelatedTo compiler(28,0,Final)) // greater than
6262
}
6363

6464
}
6565

6666
object TastyVersionFormatTest {
6767

68-
case class TastyVersion(major: Int, minor: Int, experimental: Int) { file =>
68+
type Experimental = Int
69+
val Final: Experimental = 0
70+
def Exp(i: Int): Experimental = i.ensuring(_ > 0)
71+
72+
case class TastyVersion(major: Int, minor: Int, experimental: Experimental) { file =>
73+
assert(major >= 0)
74+
assert(minor >= 0)
75+
assert(experimental >= 0)
76+
6977
def <:<(compiler: TastyVersion): Boolean = TastyFormat.isVersionCompatible(
7078
fileMajor = file.major,
7179
fileMinor = file.minor,

0 commit comments

Comments
 (0)