Skip to content

Commit 4a85c83

Browse files
committed
Tasty: set experimental to zero
1 parent 2004dc2 commit 4a85c83

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

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

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

305305
/**This method implements a binary relation (`<:<`) between two TASTy versions.
306+
*
306307
* We label the lhs `file` and rhs `compiler`.
307308
* if `file <:< compiler` then the TASTy file is valid to be read.
308309
*
309-
* TASTy versions have a partial order,
310-
* for example `a <:< b` and `b <:< a` are both false if `a` and `b` have different major versions.
310+
* A TASTy version, e.g. `v := 28.0-3` is composed of three fields:
311+
* - v.major == 28
312+
* - v.minor == 0
313+
* - v.experimental == 3
314+
*
315+
* TASTy versions have a partial order, for example,
316+
* `a <:< b` and `b <:< a` are both false if
317+
* - `a` and `b` have different `major` fields.
318+
* - `a` and `b` have the same `major` & `minor` fields,
319+
* but 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.
311325
*
312326
* We follow the given algorithm:
313327
* ```

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)