[FIR] Split :compiler:fir:resolve module into three different modules
Those modules are:
- :compiler:fir:providers, which contains Fir and Symbol providers,
scopes, and different utilities used by them
- :compiler:fir:semantics, which contains different abstractions and
entities which are used in resolution and in checkers
- :compiler:fir:resolve, which contains all stuff related to resolution
and inference
There are two pros of this change:
1. It may increase gradle build, because it allows to compile :fir:resolve
and :fir:checkers modules in parallel
2. Logic of working FIR (scopes, providers, DFA logic system, etc) is
now separated from logic of resolution phases, so for example checkers,
which are depend on scopes physically will not be able to run resolve
in any way
This commit is contained in:
@@ -10,6 +10,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
api(project(":core:compiler.common"))
|
||||
api(kotlinxCollectionsImmutable())
|
||||
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,4 +26,6 @@ abstract class ConeSubstitutor : TypeSubstitutorMarker {
|
||||
|
||||
fun ConeSubstitutor.substituteOrNull(type: ConeKotlinType?): ConeKotlinType? {
|
||||
return type?.let { substituteOrNull(it) }
|
||||
}
|
||||
}
|
||||
|
||||
object NoSubstitutor : TypeSubstitutorMarker
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.util
|
||||
|
||||
class ChainedIterator<T>(delegates: Collection<Iterator<T>>) : Iterator<T> {
|
||||
private var metaIterator = delegates.iterator()
|
||||
private var currentIterator: Iterator<T>? = null
|
||||
|
||||
private fun promote() {
|
||||
if (currentIterator?.hasNext() == true) return
|
||||
while (metaIterator.hasNext()) {
|
||||
currentIterator = metaIterator.next()
|
||||
if (currentIterator!!.hasNext()) return
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
promote()
|
||||
return currentIterator?.hasNext() == true
|
||||
}
|
||||
|
||||
override fun next(): T {
|
||||
promote()
|
||||
return currentIterator?.next() ?: throw NoSuchElementException()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.util
|
||||
|
||||
private open class FrozenReversedListReadOnly<out T>(
|
||||
private val delegate: List<T>
|
||||
) : AbstractList<T>() {
|
||||
override val size: Int = delegate.size
|
||||
override fun get(index: Int): T = delegate[size - 1 - index]
|
||||
}
|
||||
|
||||
fun <T> List<T>.asReversedFrozen(): List<T> = FrozenReversedListReadOnly(this)
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.util
|
||||
|
||||
interface Multimap<K, out V, out C : Collection<V>> {
|
||||
operator fun get(key: K): C
|
||||
operator fun contains(key: K): Boolean
|
||||
val keys: Set<K>
|
||||
val values: Collection<V>
|
||||
}
|
||||
|
||||
interface MutableMultimap<K, V, C : Collection<V>> : Multimap<K, V, C> {
|
||||
fun put(key: K, value: V)
|
||||
fun putAll(key: K, values: Collection<V>) {
|
||||
values.forEach { put(key, it) }
|
||||
}
|
||||
|
||||
fun remove(key: K, value: V)
|
||||
fun removeKey(key: K)
|
||||
|
||||
fun clear()
|
||||
}
|
||||
|
||||
abstract class BaseMultimap<K, V, C : Collection<V>, MC : MutableCollection<V>> : MutableMultimap<K, V, C> {
|
||||
private val map: MutableMap<K, MC> = mutableMapOf()
|
||||
protected abstract fun createContainer(): MC
|
||||
protected abstract fun createEmptyContainer(): C
|
||||
|
||||
override fun get(key: K): C {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return map[key] as C? ?: createEmptyContainer()
|
||||
}
|
||||
|
||||
override operator fun contains(key: K): Boolean {
|
||||
return key in map
|
||||
}
|
||||
|
||||
override val keys: Set<K>
|
||||
get() = map.keys
|
||||
|
||||
override val values: Collection<V>
|
||||
get() = object : AbstractCollection<V>() {
|
||||
override val size: Int
|
||||
get() = map.values.sumOf { it.size }
|
||||
|
||||
override fun iterator(): Iterator<V> {
|
||||
return ChainedIterator(map.values.map { it.iterator() })
|
||||
}
|
||||
}
|
||||
|
||||
override fun put(key: K, value: V) {
|
||||
val container = map.getOrPut(key) { createContainer() }
|
||||
container.add(value)
|
||||
}
|
||||
|
||||
override fun remove(key: K, value: V) {
|
||||
val collection = map[key] ?: return
|
||||
collection.remove(value)
|
||||
if (collection.isEmpty()) {
|
||||
map.remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeKey(key: K) {
|
||||
map.remove(key)
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
map.clear()
|
||||
}
|
||||
}
|
||||
|
||||
class SetMultimap<K, V> : BaseMultimap<K, V, Set<V>, MutableSet<V>>() {
|
||||
override fun createContainer(): MutableSet<V> {
|
||||
return mutableSetOf()
|
||||
}
|
||||
|
||||
override fun createEmptyContainer(): Set<V> {
|
||||
return emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
class ListMultimap<K, V> : BaseMultimap<K, V, List<V>, MutableList<V>>() {
|
||||
override fun createContainer(): MutableList<V> {
|
||||
return mutableListOf()
|
||||
}
|
||||
|
||||
override fun createEmptyContainer(): List<V> {
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun <K, V> setMultimapOf(): SetMultimap<K, V> = SetMultimap()
|
||||
fun <K, V> listMultimapOf(): ListMultimap<K, V> = ListMultimap()
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.util
|
||||
|
||||
import kotlinx.collections.immutable.*
|
||||
|
||||
class PersistentMultimap<K, V> private constructor(private val map: PersistentMap<K, PersistentList<V>>) {
|
||||
|
||||
constructor() : this(persistentMapOf())
|
||||
|
||||
fun put(key: K, value: V): PersistentMultimap<K, V> {
|
||||
val collection = map[key] ?: persistentListOf()
|
||||
val newSet = collection.add(value)
|
||||
if (newSet === collection) return this
|
||||
val newMap = map.put(key, newSet)
|
||||
return PersistentMultimap(newMap)
|
||||
}
|
||||
|
||||
fun remove(key: K, value: V): PersistentMultimap<K, V> {
|
||||
val list = map.get(key) ?: return this
|
||||
val newSet = list.remove(value)
|
||||
if (list === newSet) return this
|
||||
val newMap = if (newSet.isEmpty()) {
|
||||
map.remove(key)
|
||||
} else {
|
||||
map.put(key, newSet)
|
||||
}
|
||||
return PersistentMultimap(newMap)
|
||||
}
|
||||
|
||||
operator fun get(key: K): List<V> {
|
||||
return map[key] ?: emptyList()
|
||||
}
|
||||
|
||||
val keys: ImmutableSet<K> get() = map.keys
|
||||
}
|
||||
|
||||
class PersistentSetMultimap<K, V> private constructor(private val map: PersistentMap<K, PersistentSet<V>>) {
|
||||
|
||||
constructor() : this(persistentMapOf())
|
||||
|
||||
fun put(key: K, value: V): PersistentSetMultimap<K, V> {
|
||||
val set = map[key] ?: persistentSetOf()
|
||||
val newSet = set.add(value)
|
||||
if (newSet === set) return this
|
||||
val newMap = map.put(key, newSet)
|
||||
return PersistentSetMultimap(newMap)
|
||||
}
|
||||
|
||||
fun remove(key: K, value: V): PersistentSetMultimap<K, V> {
|
||||
val set = map.get(key) ?: return this
|
||||
val newSet = set.remove(value)
|
||||
if (set === newSet) return this
|
||||
val newMap = if (newSet.isEmpty()) {
|
||||
map.remove(key)
|
||||
} else {
|
||||
map.put(key, newSet)
|
||||
}
|
||||
return PersistentSetMultimap(newMap)
|
||||
}
|
||||
|
||||
operator fun get(key: K): Set<V> {
|
||||
return map[key] ?: emptySet()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user