[IC] Refactor IC maps to reuse code and ensure consistency

The key changes include:
  - Top interface: `PersistentStorage`
  - Implementation:
      + `LazyStorage`
      + `InMemoryStorage`
  - Extended functionality:
      + `BasicMap`
      + `PersistentStorageAdapter`

 The remaining changes are small cleanups to adapt to the above key
 changes.

 Test: Existing tests (refactoring change)
 Bug: N/A (code cleanup)
This commit is contained in:
Hung Nguyen
2023-08-25 20:12:52 +01:00
committed by Space Cloud
parent e8630fd63f
commit 4e89dcf031
26 changed files with 730 additions and 581 deletions
@@ -6,14 +6,13 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.build.report.DoNothingBuildReporter
import org.jetbrains.kotlin.incremental.storage.InMemoryStorageWrapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.jetbrains.kotlin.incremental.storage.InMemoryStorageInterface
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.io.TempDir
import java.io.Closeable
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
@@ -27,23 +26,21 @@ private class CacheMock(private val throwsException: Boolean = false) : Closeabl
}
}
private class InMemoryStorageWrapperMock : InMemoryStorageWrapper<Any, Any> {
private class InMemoryStorageWrapperMock : InMemoryStorageInterface<Any, Any> {
var reset = false
override fun resetInMemoryChanges() {
override fun applyChanges() {}
override fun clearChanges() {
reset = true
}
override val keys: Collection<Any> = emptyList()
override val storageFile = File("")
override fun clean() {}
override fun flush(memoryCachesOnly: Boolean) {}
override val keys: Set<Any> = emptySet()
override fun close() {}
override fun append(key: Any, value: Any) {}
override fun remove(key: Any) {}
override fun set(key: Any, value: Any) {}
@@ -15,7 +15,7 @@ import java.io.Closeable
import java.nio.file.Files
import java.nio.file.Path
class InMemoryStorageWrapperTest {
class InMemoryStorageTest {
@TempDir
private lateinit var workingDir: Path
@@ -83,7 +83,7 @@ class InMemoryStorageWrapperTest {
assertEquals(setOf(5), it[key5])
}
withLookupMapInTransaction(storageRoot, useInMemoryWrapper = true, successful = true) {
it.clean()
it.clear()
it.append(key1, setOf(4))
}
withLookupMapInTransaction(storageRoot, useInMemoryWrapper = false, successful = true) {
@@ -108,7 +108,7 @@ class InMemoryStorageWrapperTest {
val savedState = workingDir.resolve("backup")
storageRoot.toFile().copyRecursively(savedState.toFile())
withLookupMapInTransaction(storageRoot, useInMemoryWrapper = true, successful = false) {
it.clean()
it.clear()
it.append(key1, setOf(3))
it.remove(key2)
it[key3] = setOf(5)
@@ -131,7 +131,6 @@ class InMemoryStorageWrapperTest {
icContext.transaction.runWithin { transaction ->
val lookupMap = LookupMap(storageFile, icContext)
transaction.cachesManager = Closeable {
lookupMap.flush(false)
lookupMap.close()
}
dataProvider(lookupMap)