FIR checker: refactor ControlFlowInfos whose value is EventOccurrencesRange
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
cf8f5b0912
commit
b6a4c279a4
@@ -13,18 +13,13 @@ import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class PropertyInitializationInfo(
|
||||
map: PersistentMap<FirPropertySymbol, EventOccurrencesRange> = persistentMapOf()
|
||||
) : ControlFlowInfo<PropertyInitializationInfo, FirPropertySymbol, EventOccurrencesRange>(map) {
|
||||
companion object {
|
||||
val EMPTY = PropertyInitializationInfo()
|
||||
}
|
||||
abstract class EventOccurrencesRangeInfo<E : EventOccurrencesRangeInfo<E, K>, K : Any>(
|
||||
map: PersistentMap<K, EventOccurrencesRange> = persistentMapOf()
|
||||
) : ControlFlowInfo<E, K, EventOccurrencesRange>(map) {
|
||||
|
||||
override val constructor: (PersistentMap<FirPropertySymbol, EventOccurrencesRange>) -> PropertyInitializationInfo =
|
||||
::PropertyInitializationInfo
|
||||
|
||||
fun merge(other: PropertyInitializationInfo): PropertyInitializationInfo {
|
||||
var result = this
|
||||
override fun merge(other: E): E {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
var result = this as E
|
||||
for (symbol in keys.union(other.keys)) {
|
||||
val kind1 = this[symbol] ?: EventOccurrencesRange.ZERO
|
||||
val kind2 = other[symbol] ?: EventOccurrencesRange.ZERO
|
||||
@@ -34,6 +29,18 @@ class PropertyInitializationInfo(
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyInitializationInfo(
|
||||
map: PersistentMap<FirPropertySymbol, EventOccurrencesRange> = persistentMapOf()
|
||||
) : EventOccurrencesRangeInfo<PropertyInitializationInfo, FirPropertySymbol>(map) {
|
||||
companion object {
|
||||
val EMPTY = PropertyInitializationInfo()
|
||||
}
|
||||
|
||||
override val constructor: (PersistentMap<FirPropertySymbol, EventOccurrencesRange>) -> PropertyInitializationInfo =
|
||||
::PropertyInitializationInfo
|
||||
|
||||
}
|
||||
|
||||
class LocalPropertyCollector private constructor() : ControlFlowGraphVisitorVoid() {
|
||||
companion object {
|
||||
fun collect(graph: ControlFlowGraph): MutableSet<FirPropertySymbol> {
|
||||
@@ -105,7 +112,7 @@ class PathAwarePropertyInitializationInfo(
|
||||
}
|
||||
}
|
||||
|
||||
fun merge(other: PathAwarePropertyInitializationInfo): PathAwarePropertyInitializationInfo {
|
||||
override fun merge(other: PathAwarePropertyInitializationInfo): PathAwarePropertyInitializationInfo {
|
||||
var resultMap = persistentMapOf<EdgeLabel, PropertyInitializationInfo>()
|
||||
for (label in keys.union(other.keys)) {
|
||||
// disjoint merging to preserve paths. i.e., merge the property initialization info if and only if both have the key.
|
||||
|
||||
@@ -28,4 +28,6 @@ abstract class ControlFlowInfo<S : ControlFlowInfo<S, K, V>, K : Any, V : Any> p
|
||||
override fun put(key: K, value: V): S {
|
||||
return constructor(map.put(key, value))
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun merge(other: S): S
|
||||
}
|
||||
|
||||
+2
-12
@@ -205,8 +205,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
|
||||
class LambdaInvocationInfo(
|
||||
map: PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange> = persistentMapOf(),
|
||||
) : ControlFlowInfo<LambdaInvocationInfo, FirBasedSymbol<*>, EventOccurrencesRange>(map) {
|
||||
|
||||
) : EventOccurrencesRangeInfo<LambdaInvocationInfo, FirBasedSymbol<*>>(map) {
|
||||
companion object {
|
||||
val EMPTY = LambdaInvocationInfo()
|
||||
}
|
||||
@@ -214,15 +213,6 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
override val constructor: (PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange>) -> LambdaInvocationInfo =
|
||||
::LambdaInvocationInfo
|
||||
|
||||
fun merge(other: LambdaInvocationInfo): LambdaInvocationInfo {
|
||||
var result = this
|
||||
for (symbol in keys.union(other.keys)) {
|
||||
val kind1 = this[symbol] ?: EventOccurrencesRange.ZERO
|
||||
val kind2 = other[symbol] ?: EventOccurrencesRange.ZERO
|
||||
result = result.put(symbol, kind1 or kind2)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
class PathAwareLambdaInvocationInfo(
|
||||
@@ -278,7 +268,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
||||
}
|
||||
}
|
||||
|
||||
fun merge(other: PathAwareLambdaInvocationInfo): PathAwareLambdaInvocationInfo {
|
||||
override fun merge(other: PathAwareLambdaInvocationInfo): PathAwareLambdaInvocationInfo {
|
||||
var resultMap = persistentMapOf<EdgeLabel, LambdaInvocationInfo>()
|
||||
for (label in keys.union(other.keys)) {
|
||||
// disjoint merging to preserve paths. i.e., merge the property initialization info if and only if both have the key.
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ object UnusedChecker : FirControlFlowChecker() {
|
||||
override val constructor: (PersistentMap<FirPropertySymbol, VariableStatus>) -> VariableStatusInfo =
|
||||
::VariableStatusInfo
|
||||
|
||||
fun merge(other: VariableStatusInfo): VariableStatusInfo {
|
||||
override fun merge(other: VariableStatusInfo): VariableStatusInfo {
|
||||
var result = this
|
||||
for (symbol in keys.union(other.keys)) {
|
||||
val kind1 = this[symbol] ?: VariableStatus.UNUSED
|
||||
|
||||
Reference in New Issue
Block a user