Skip to content

Commit

Permalink
Simplify & clarify TASTy isVersionCompatible
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 17, 2021
1 parent 38b983c commit d15206b
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,29 +327,12 @@ object TastyFormat {
* with an unstable TASTy version.
*
* We follow the given algorithm:
*
* ```
* if file.major != compiler.major then
* return incompatible
* if compiler.experimental == 0 then
* if file.experimental != 0 then
* return incompatible
* if file.minor > compiler.minor then
* return incompatible
* else
* return compatible
* else invariant[compiler.experimental != 0]
* if file.experimental == compiler.experimental then
* if file.minor == compiler.minor then
* return compatible (all fields equal)
* else
* return incompatible
* else if file.experimental == 0,
* if file.minor < compiler.minor then
* return compatible (an experimental version can read a previous released version)
* else
* return incompatible (an experimental version cannot read its own minor version or any later version)
* else invariant[file.experimental is non-0 and different than compiler.experimental]
* return incompatible
* (fileMajor, fileMinor, fileExperimental) match
* case (`compilerMajor`, `compilerMinor`, `compilerExperimental`) => true // full equality
* case (`compilerMajor`, minor, 0) if minor < compilerMinor => true // stable backwards compatibility
* case _ => false
* ```
* @syntax markdown
*/
Expand All @@ -361,18 +344,9 @@ object TastyFormat {
compilerMinor: Int,
compilerExperimental: Int
): Boolean = (
fileMajor == compilerMajor && (
if (fileExperimental == compilerExperimental) {
if (compilerExperimental == 0) {
fileMinor <= compilerMinor
}
else {
fileMinor == compilerMinor
}
}
else {
fileExperimental == 0 && fileMinor < compilerMinor
}
fileMajor == compilerMajor &&
( fileMinor == compilerMinor && fileExperimental == compilerExperimental // full equality
|| fileMinor < compilerMinor && fileExperimental == 0 // stable backwards compatibility
)
)

Expand Down

0 comments on commit d15206b

Please sign in to comment.