Skip to content

Commit e7eb6dc

Browse files
committed
Add cache for TASTy bytes
1 parent a259fb9 commit e7eb6dc

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ class JavaPlatform extends Platform {
7878
new ClassfileLoader(bin)
7979

8080
def newTastyLoader(bin: AbstractFile)(using Context): SymbolLoader =
81-
new TastyLoader(bin)
81+
new TastyLoader(bin, ctx.cacheStore.tastyBytes)
8282
}

compiler/src/dotty/tools/dotc/core/CacheStores.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ object CacheStores:
1818
def files: Cache[TermName, AbstractFile]
1919
def sources: Cache[AbstractFile, SourceFile]
2020
def classBytes: Cache[AbstractFile, Array[Byte]]
21+
def tastyBytes: Cache[AbstractFile, Array[Byte]]
2122

2223
override def toString: String =
2324
s"""CacheStore(
2425
| classPaths = $classPaths,
2526
| files = $files,
2627
| sources = $sources
2728
| classBytes = $classBytes
29+
| tastyBytes = $tastyBytes
2830
|)""".stripMargin
2931

3032
/** Default, per-run cache store implementation. */
@@ -50,8 +52,8 @@ object CacheStores:
5052
*/
5153
val sources = NoopCache()
5254

53-
/** By default, we do not cache class bytes across runs. */
55+
/** By default, we do not cache class bytes. */
5456
val classBytes = NoopCache()
5557

56-
/** By default, we do not cache tasty loaders. */
57-
val tastyLoaders = NoopCache()
58+
/** By default, we do not cache tasty bytes. */
59+
val tastyBytes = NoopCache()

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import NameOps.*
1717
import StdNames.*
1818
import classfile.{ClassfileParser, ClassfileTastyUUIDParser}
1919
import Decorators.*
20+
import Caches.Cache
2021

2122
import util.Stats
2223
import reporting.trace
@@ -471,10 +472,11 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
471472
classfileParser.run()
472473
}
473474

474-
class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
475-
val isBestEffortTasty = tastyFile.hasBetastyExtension
475+
class TastyLoader(val tastyFile: AbstractFile, tastyBytesCache: Cache[AbstractFile, Array[Byte]]) extends SymbolLoader {
476+
private val isBestEffortTasty = tastyFile.hasBetastyExtension
476477

477-
lazy val tastyBytes = tastyFile.toByteArray
478+
private lazy val tastyBytes: Array[Byte] =
479+
tastyBytesCache(tastyFile, tastyFile.toByteArray)
478480

479481
private lazy val unpickler: tasty.DottyUnpickler =
480482
handleUnpicklingExceptions:

compiler/test/dotty/tools/TestCacheStore.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ object TestCacheStore extends CacheStore:
2727

2828
/** Cache class bytes across runs, except for classes in the `out` directory.
2929
*
30-
* Classes in the `out` directory are generated during tests, so we do not
31-
* want to cache them.
30+
* Files in the `out` directory are generated during tests, so we do not want
31+
* to cache them.
3232
*/
3333
val classBytes = FilteringCache(SynchronizedMapCache(), !_.canonicalPath.startsWith(outDir))
34+
35+
/** Cache tasty bytes across runs, except for those in the `out` directory. */
36+
val tastyBytes = FilteringCache(SynchronizedMapCache(), !_.canonicalPath.startsWith(outDir))

0 commit comments

Comments
 (0)