Skip to content

Commit

Permalink
Cache stable TASTyVersion
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Stucki <[email protected]>
Co-authored-by: Jamie Thompson <[email protected]>
  • Loading branch information
nicolasstucki and bishabosha committed Nov 23, 2023
1 parent e152b56 commit 97d8171
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 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.annotation.internal.sharable

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,17 @@ 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 {

@sharable
private val cache: java.util.concurrent.ConcurrentHashMap[TastyVersion, TastyVersion] =
new java.util.concurrent.ConcurrentHashMap()

def apply(major: Int, minor: Int, experimental: Int): TastyVersion = {
val version = new TastyVersion(major, minor, experimental)
val cachedVersion = cache.putIfAbsent(version, version)
if (cachedVersion == null) version else cachedVersion
}
}

0 comments on commit 97d8171

Please sign in to comment.