Skip to content

Commit

Permalink
Cache stable TASTyVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 22, 2023
1 parent e152b56 commit 71266bf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tasty/src/dotty/tools/tasty/TastyVersion.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dotty.tools.tasty

case class TastyVersion(major: Int, minor: Int, experimental: Int) {
import scala.collection.mutable

case class TastyVersion private(major: Int, minor: Int, experimental: Int) {
def isExperimental: Boolean = experimental > 0

def nextStable: TastyVersion = copy(experimental = 0)
Expand All @@ -21,4 +23,12 @@ case class TastyVersion(major: Int, minor: Int, experimental: Int) {
val extra = Option.when(experimental > 0)(this)
s"stable TASTy from ${min.show} to ${max.show}${extra.fold("")(e => s", or exactly ${e.show}")}"
}
}
}

object TastyVersion {
/** All TASTy versions in stable releases */
private val cache: mutable.Map[(Int, Int, Int), TastyVersion] = mutable.Map.empty

def apply(major: Int, minor: Int, experimental: Int): TastyVersion =
cache.getOrElseUpdate((major, minor, experimental), new TastyVersion(major, minor, experimental))
}

0 comments on commit 71266bf

Please sign in to comment.