Skip to content

Commit

Permalink
FIR checker: refactor ControlFlowInfos whose value is EventOccurrence…
Browse files Browse the repository at this point in the history
…sRange
  • Loading branch information
jsjeon authored and demiurg906 committed Nov 23, 2020
1 parent cf8f5b0 commit b6a4c27
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,32 @@ import org.jetbrains.kotlin.fir.resolve.dfa.cfg.*
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import java.lang.IllegalStateException

abstract class EventOccurrencesRangeInfo<E : EventOccurrencesRangeInfo<E, K>, K : Any>(
map: PersistentMap<K, EventOccurrencesRange> = persistentMapOf()
) : ControlFlowInfo<E, K, EventOccurrencesRange>(map) {

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
result = result.put(symbol, kind1 or kind2)
}
return result
}
}

class PropertyInitializationInfo(
map: PersistentMap<FirPropertySymbol, EventOccurrencesRange> = persistentMapOf()
) : ControlFlowInfo<PropertyInitializationInfo, FirPropertySymbol, EventOccurrencesRange>(map) {
) : EventOccurrencesRangeInfo<PropertyInitializationInfo, FirPropertySymbol>(map) {
companion object {
val EMPTY = PropertyInitializationInfo()
}

override val constructor: (PersistentMap<FirPropertySymbol, EventOccurrencesRange>) -> PropertyInitializationInfo =
::PropertyInitializationInfo

fun merge(other: PropertyInitializationInfo): PropertyInitializationInfo {
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 LocalPropertyCollector private constructor() : ControlFlowGraphVisitorVoid() {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,14 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() {

class LambdaInvocationInfo(
map: PersistentMap<FirBasedSymbol<*>, EventOccurrencesRange> = persistentMapOf(),
) : ControlFlowInfo<LambdaInvocationInfo, FirBasedSymbol<*>, EventOccurrencesRange>(map) {

) : EventOccurrencesRangeInfo<LambdaInvocationInfo, FirBasedSymbol<*>>(map) {
companion object {
val EMPTY = LambdaInvocationInfo()
}

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(
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6a4c27

Please sign in to comment.