@@ -24,7 +24,7 @@ sealed abstract case class TastyHeader(
24
24
majorVersion : Int ,
25
25
minorVersion : Int ,
26
26
experimentalVersion : Int ,
27
- compilerVersion : String
27
+ compilerVersion : String // String could lead to a lot of duplication
28
28
)
29
29
30
30
class TastyHeaderUnpickler (reader : TastyReader ) {
@@ -46,8 +46,6 @@ class TastyHeaderUnpickler(reader: TastyReader) {
46
46
47
47
def expectedMinor = showMinorVersion(MinorVersion , ExperimentalVersion )
48
48
49
- def myScalaV = " <???.???.???>"
50
-
51
49
def myAddendum = {
52
50
if (ExperimentalVersion > 0 )
53
51
" \n Note that you are currently using an unstable compiler version."
@@ -57,88 +55,78 @@ class TastyHeaderUnpickler(reader: TastyReader) {
57
55
58
56
for (i <- 0 until header.length)
59
57
check(readByte() == header(i), " not a TASTy file" )
60
- val majorVersion = readNat()
61
- if (majorVersion <= 27 ) { // old behavior before Scala 3.0.0-M4
62
- val minorVersion = readNat()
58
+ val fileMajor = readNat()
59
+ if (fileMajor <= 27 ) { // old behavior before Scala 3.0.0-M4
60
+ val fileMinor = readNat()
63
61
throw new UnpickleException (
64
62
s """ TASTy signature is from a backwards incompatible release.
65
63
| expected: {majorVersion: $MajorVersion, minorVersion: $expectedMinor}
66
- | found : {majorVersion: $majorVersion , minorVersion: $minorVersion }
64
+ | found : {majorVersion: $fileMajor , minorVersion: $fileMinor }
67
65
|
68
- |Please recompile this TASTy with at least Scala $myScalaV . $myAddendum""" .stripMargin
66
+ |Please recompile this TASTy with a later Scala version . $myAddendum""" .stripMargin
69
67
)
70
68
}
71
69
else {
72
- check(majorVersion <= MajorVersion , // layout of header may have changed in future release
70
+ check(fileMajor <= MajorVersion , // layout of header may have changed in future release
73
71
s """ TASTy signature is from a future release of Scala with unknown TASTy format.
74
72
| expected: {majorVersion: $MajorVersion, minorVersion: $expectedMinor}
75
- | found : {majorVersion: $majorVersion , ...}
73
+ | found : {majorVersion: $fileMajor , ...}
76
74
|
77
- |Please use TASTy compiled by Scala $myScalaV . $myAddendum""" .stripMargin)
78
- val minorVersion = readNat()
79
- val experimentalVersion = readNat()
75
+ |Please use TASTy compiled an earlier Scala version . $myAddendum""" .stripMargin)
76
+ val fileMinor = readNat()
77
+ val fileExperimental = readNat()
80
78
val compilerVersion = {
81
79
val length = readNat()
82
80
val start = currentAddr
83
81
val end = start + length
84
82
goto(end)
85
- new String (bytes, start.index, length)
83
+ new String (bytes, start.index, length) // NOTE: new string object here (should probably cache as it leaks)
86
84
}
87
- // |=============|==============|========|
88
- // | Our Version | Read Version | Valid |
89
- // |=============|==============|========|
90
- // | 28. | 27. | false |
91
- // | 28. | 29. | false |
92
- // | 28.0 | 28.1 | false |
93
- // | 28.1 | 28.0 | true |
94
- // | 28.0 @ 0 | 28.0 @ 0 | true |
95
- // | 28.0 @ 0 | 28.0 @ 1 | false | // implementation could have changed between 0 and 1
96
- // | 28.0 @ 1 | 28.0 @ 0 | false | // implementation could have changed between 1 and 0
97
- // | 28.0 @ 1 | 28.0 @ 2 | false | // implementation could have changed between 1 and 2
98
- // | 28.0 @ 2 | 28.0 @ 1 | false | // implementation could have changed between 2 and 1
99
- // |=============|==============|========|
100
-
101
- // Example series:
102
- // Scala 3.0.0-M4 - 28.0 @ 1
103
- // Scala 3.0.0-RC1 - 28.0 @ 1
104
- // Scala 3.0.0 - 28.0 @ 0 // reset experimental to 0 for final version
105
- // Scala 3.0.1 - 28.0 @ 0
106
- // Scala 3.0.2 - 28.0 @ 0
107
- // Scala 3.1.0-RC1 - 28.1 @ 1 // we intend to break forward compat, bump both minor and experimental
108
- // Scala 3.1.0-RC2 - 28.1 @ 2 // we try another change, bump only experimental, should (`28.1 @ 1` be able to read `28.1 @ 2`?)
109
- // Scala 3.1.0 - 28.1 @ 0 // reset experimental to 0 for final version
110
85
111
- val validVersion = (
112
- majorVersion == MajorVersion
113
- && minorVersion <= MinorVersion
114
- && ! (minorVersion == MinorVersion && ExperimentalVersion != experimentalVersion) // experimentals are forks
86
+ val validVersion = ( // inlined from `dotty.tools.tasty.TastyVersionFormatTest.TastyVersion.<:<`
87
+ fileMajor == MajorVersion && (
88
+ if (fileExperimental == ExperimentalVersion ) {
89
+ if (ExperimentalVersion == 0 ) {
90
+ fileMinor <= MinorVersion
91
+ }
92
+ else {
93
+ fileMinor == MinorVersion
94
+ }
95
+ }
96
+ else {
97
+ fileExperimental == 0 && fileMinor < MinorVersion
98
+ }
99
+ )
115
100
)
116
101
check(validVersion, {
117
- val foundMinor = showMinorVersion(minorVersion, experimentalVersion )
102
+ val foundMinor = showMinorVersion(fileMinor, fileExperimental )
118
103
val foundAddendum = {
119
- if (experimentalVersion > 0 )
104
+ if (fileExperimental > 0 )
120
105
" \n Note that this TASTy file was produced by an unstable compiler version."
121
106
else
122
107
" "
123
108
}
124
- if (majorVersion < MajorVersion ) {
109
+ if (fileMajor < MajorVersion ) {
125
110
s """ TASTy signature is from a backwards incompatible release.
126
111
| expected: {majorVersion: $MajorVersion, minorVersion: $expectedMinor}
127
- | found : {majorVersion: $majorVersion , minorVersion: $foundMinor}
112
+ | found : {majorVersion: $fileMajor , minorVersion: $foundMinor}
128
113
|
129
- |Please recompile this TASTy with at least Scala $myScalaV. $myAddendum$foundAddendum""" .stripMargin
114
+ |Please recompile this TASTy with a later Scala version.
115
+ |The TASTy file was compiled by $compilerVersion. $myAddendum$foundAddendum""" .stripMargin
130
116
}
131
117
else {
118
+ // TODO ajust message based on experimental vs forward incompat
132
119
s """ TASTy signature is from a forwards incompatible release.
133
120
| expected: {majorVersion: $MajorVersion, minorVersion: $expectedMinor}
134
- | found : {majorVersion: $majorVersion , minorVersion: $foundMinor}
121
+ | found : {majorVersion: $fileMajor , minorVersion: $foundMinor}
135
122
|
136
- |To read this TASTy file, please upgrade your Scala version to at least $compilerVersion. $myAddendum$foundAddendum""" .stripMargin
123
+ |To read this TASTy file, please upgrade your Scala version.
124
+ |The TASTy file was compiled by $compilerVersion. $myAddendum$foundAddendum""" .stripMargin
137
125
}
138
126
}
139
127
)
140
128
val uuid = new UUID (readUncompressedLong(), readUncompressedLong())
141
- new TastyHeader (uuid, majorVersion, minorVersion, experimentalVersion , compilerVersion) {}
129
+ new TastyHeader (uuid, fileMajor, fileMinor, fileExperimental , compilerVersion) {}
142
130
}
143
131
}
144
132
0 commit comments