[K2] Use file name as one of parameters to extract evaluated const

It is not enough to store evaluated constants only by
<startOffset, endOffset> pair. We need to consider case there constant
can be located in different files with the same offset but with
different values.

#KT-57928 Fixed
#KT-57929 Fixed
This commit is contained in:
Ivan Kylchik
2023-04-11 12:56:59 +02:00
committed by Space Team
parent 8cc8e54a9f
commit c00c7ffbe0
13 changed files with 123 additions and 100 deletions
@@ -8,8 +8,9 @@ package org.jetbrains.kotlin.constant
import java.util.concurrent.ConcurrentHashMap
abstract class EvaluatedConstTracker {
abstract fun save(start: Int, end: Int, constant: ConstantValue<*>)
abstract fun load(start: Int, end: Int): ConstantValue<*>?
abstract fun save(start: Int, end: Int, file: String, constant: ConstantValue<*>)
abstract fun load(start: Int, end: Int, file: String): ConstantValue<*>?
abstract fun load(file: String): Map<Pair<Int, Int>, ConstantValue<*>>?
companion object {
/**
@@ -24,14 +25,20 @@ abstract class EvaluatedConstTracker {
}
private class DefaultEvaluatedConstTracker : EvaluatedConstTracker() {
private val storage = ConcurrentHashMap<Pair<Int, Int>, ConstantValue<*>>()
private val storage = ConcurrentHashMap<String, ConcurrentHashMap<Pair<Int, Int>, ConstantValue<*>>>()
override fun save(start: Int, end: Int, constant: ConstantValue<*>) {
storage[start to end] = constant
override fun save(start: Int, end: Int, file: String, constant: ConstantValue<*>) {
storage
.getOrPut(file) { ConcurrentHashMap() }
.let { it[start to end] = constant }
}
override fun load(start: Int, end: Int): ConstantValue<*>? {
return storage[start to end]
override fun load(start: Int, end: Int, file: String): ConstantValue<*>? {
return storage[file]?.get(start to end)
}
override fun load(file: String): Map<Pair<Int, Int>, ConstantValue<*>>? {
return storage[file]
}
}