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 org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
class PropertyInitializationInfo(
|
abstract class EventOccurrencesRangeInfo<E : EventOccurrencesRangeInfo<E, K>, K : Any>(
|
||||||
map: PersistentMap<FirPropertySymbol, EventOccurrencesRange> = persistentMapOf()
|
map: PersistentMap<K, EventOccurrencesRange> = persistentMapOf()
|
||||||
) : ControlFlowInfo<PropertyInitializationInfo, FirPropertySymbol, EventOccurrencesRange>(map) {
|
) : ControlFlowInfo<E, K, EventOccurrencesRange>(map) {
|
||||||
companion object {
|
|
||||||
val EMPTY = PropertyInitializationInfo()
|
|
||||||
}
|
|
||||||
|
|
||||||
override val constructor: (PersistentMap<FirPropertySymbol, EventOccurrencesRange>) -> PropertyInitializationInfo =
|
override fun merge(other: E): E {
|
||||||
::PropertyInitializationInfo
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
var result = this as E
|
||||||
fun merge(other: PropertyInitializationInfo): PropertyInitializationInfo {
|
|
||||||
var result = this
|
|
||||||
for (symbol in keys.union(other.keys)) {
|
for (symbol in keys.union(other.keys)) {
|
||||||
val kind1 = this[symbol] ?: EventOccurrencesRange.ZERO
|
val kind1 = this[symbol] ?: EventOccurrencesRange.ZERO
|
||||||
val kind2 = other[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() {
|
class LocalPropertyCollector private constructor() : ControlFlowGraphVisitorVoid() {
|
||||||
companion object {
|
companion object {
|
||||||
fun collect(graph: ControlFlowGraph): MutableSet<FirPropertySymbol> {
|
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>()
|
var resultMap = persistentMapOf<EdgeLabel, PropertyInitializationInfo>()
|
||||||
for (label in keys.union(other.keys)) {
|
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.
|
// 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 {
|
override fun put(key: K, value: V): S {
|
||||||
return constructor(map.put(key, value))
|
return constructor(map.put(key, value))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
abstract fun merge(other: S): S
|
||||||
|
}
|
||||||
|
|||||||
+2
-12
@@ -205,8 +205,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
|||||||
|
|
||||||
class LambdaInvocationInfo(
|
class LambdaInvocationInfo(
|
||||||
map: PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange> = persistentMapOf(),
|
map: PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange> = persistentMapOf(),
|
||||||
) : ControlFlowInfo<LambdaInvocationInfo, FirBasedSymbol<*>, EventOccurrencesRange>(map) {
|
) : EventOccurrencesRangeInfo<LambdaInvocationInfo, FirBasedSymbol<*>>(map) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val EMPTY = LambdaInvocationInfo()
|
val EMPTY = LambdaInvocationInfo()
|
||||||
}
|
}
|
||||||
@@ -214,15 +213,6 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {
|
|||||||
override val constructor: (PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange>) -> LambdaInvocationInfo =
|
override val constructor: (PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange>) -> LambdaInvocationInfo =
|
||||||
::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(
|
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>()
|
var resultMap = persistentMapOf<EdgeLabel, LambdaInvocationInfo>()
|
||||||
for (label in keys.union(other.keys)) {
|
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.
|
// 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 =
|
override val constructor: (PersistentMap<FirPropertySymbol, VariableStatus>) -> VariableStatusInfo =
|
||||||
::VariableStatusInfo
|
::VariableStatusInfo
|
||||||
|
|
||||||
fun merge(other: VariableStatusInfo): VariableStatusInfo {
|
override fun merge(other: VariableStatusInfo): VariableStatusInfo {
|
||||||
var result = this
|
var result = this
|
||||||
for (symbol in keys.union(other.keys)) {
|
for (symbol in keys.union(other.keys)) {
|
||||||
val kind1 = this[symbol] ?: VariableStatus.UNUSED
|
val kind1 = this[symbol] ?: VariableStatus.UNUSED
|
||||||
|
|||||||
Reference in New Issue
Block a user