[FE] Completely replace FunctionClassKind with FunctionalTypeKind

FunctionalTypeKind can be used in FE 1.0 too, so there is no need to
  keep both classes. Also, removal of FunctionClassKind simplifies work
  with FunctionalTypeKind in common code, like Analysis Api
This commit is contained in:
Dmitriy Novozhilov
2023-01-20 14:54:33 +02:00
committed by Space Team
parent 87a9103cc6
commit 67aa80562d
38 changed files with 242 additions and 262 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
import org.jetbrains.kotlin.fir.types.*
open class ConeTypeRenderer {
@@ -14,7 +15,7 @@ open class ConeTypeRenderer {
open fun renderAsPossibleFunctionType(
type: ConeKotlinType,
functionalClassKindExtractor: (ConeKotlinType) -> ConeFunctionalTypeKind?,
functionalClassKindExtractor: (ConeKotlinType) -> FunctionalTypeKind?,
renderType: ConeTypeProjection.() -> Unit = { render() }
) {
val kind = functionalClassKindExtractor(type)
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.fir.types.ConeFunctionalTypeKind
import org.jetbrains.kotlin.builtins.functions.FunctionalTypeKind
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
@@ -19,7 +19,7 @@ class ConeTypeRendererForDebugging() : ConeTypeRenderer() {
override fun renderAsPossibleFunctionType(
type: ConeKotlinType,
functionalClassKindExtractor: (ConeKotlinType) -> ConeFunctionalTypeKind?,
functionalClassKindExtractor: (ConeKotlinType) -> FunctionalTypeKind?,
renderType: ConeTypeProjection.() -> Unit
) {
builder.append("R|")
@@ -1,141 +0,0 @@
/*
* Copyright 2010-2023 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.types
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
/**
* [ConeFunctionalTypeKind] describes a family of various similar functional types (like kotlin.FunctionN)
* All types in the same family have corresponding shape of classId: [packageFqName].[classNamePrefix]N,
* where `N` is an arity of function
*
* Functional type kind may be either reflect type or non-reflect type
* Each non-reflect kind should have corresponding reflect kind and vice-versa (like `kotlin.FunctionN` and `kotlin.reflection.KFunctionN`)
*
* Classes for such functional types are synthetic and generated by compiler itself
* [annotationOnInvokeClassId] is a classId of annotation, which will be added to `invoke` function of generated
* functional interface. This argument is mandatory for non-standard functional kinds
*
* Assume we have `some.CustomFunctionN` and `some.KCustomFunctionN` families with [annotationOnInvokeClassId] = /some.Anno
* Classes for those kinds will look like this:
*
* interface CustomFunctionN<P1, P2, ..., PN, R> : kotlin.Function<R> {
* @some.Anno
* operator fun invoke(p1: P1, p2: P2, ..., pN: PN): R
* }
*
* interface KCustomFunctionN<P1, P2, ..., PN, R> : kotlin.reflect.KFunction<R>, some.CustomFunctionN<P1, P2, ..., PN, R> {
* @some.Anno
* override operator fun invoke(p1: P1, p2: P2, ..., pN: PN): R
* }
*
* Note that if you provide some new functional type kind it's your responsibility to handle all references to it in backend
* with [IrGenerationExtension] implementation
*/
abstract class ConeFunctionalTypeKind internal constructor(
val packageFqName: FqName,
val classNamePrefix: String,
val isReflectType: Boolean,
val annotationOnInvokeClassId: ClassId?
) {
/*
* This constructor is needed to enforce not nullable [annotationOnInvokeClassId] for
* functional kinds provided by compiler plugins
*/
constructor(
packageFqName: FqName,
classNamePrefix: String,
annotationOnInvokeClassId: ClassId,
isReflectType: Boolean
) : this(packageFqName, classNamePrefix, isReflectType, annotationOnInvokeClassId)
/*
* Specifies how corresponding type will be rendered
* E.g. if `prefixForTypeRender = @Some` and type is `some.CustomFunction2<Int, String, Double>`,
* then type will be rendered as `@Some (Int, String) -> Double`
*/
open val prefixForTypeRender: String?
get() = null
/**
* @return corresponding non-reflect kind for reflect kind
* @return [this] if [isReflectType] is false
*
* Should be overridden for reflect kinds
*/
open fun nonReflectKind(): ConeFunctionalTypeKind {
return if (isReflectType) error("Should be overridden explicitly") else this
}
/**
* @return corresponding reflect kind for non-reflect kind
* @return [this] if [isReflectType] is true
*
* Should be overridden for non reflect kinds
*/
open fun reflectKind(): ConeFunctionalTypeKind {
return if (isReflectType) this else error("Should be overridden explicitly")
}
fun numberedClassName(arity: Int): Name = Name.identifier("$classNamePrefix$arity")
override fun toString(): String {
return "$packageFqName.${classNamePrefix}N"
}
// ------------------------------------------- Builtin functional kinds -------------------------------------------
object Function : ConeFunctionalTypeKind(
StandardNames.BUILT_INS_PACKAGE_FQ_NAME,
"Function",
isReflectType = false,
annotationOnInvokeClassId = null
) {
override fun reflectKind(): ConeFunctionalTypeKind = KFunction
}
object SuspendFunction : ConeFunctionalTypeKind(
StandardNames.COROUTINES_PACKAGE_FQ_NAME,
"SuspendFunction",
isReflectType = false,
annotationOnInvokeClassId = null
) {
override val prefixForTypeRender: String
get() = "suspend"
override fun reflectKind(): ConeFunctionalTypeKind = KSuspendFunction
}
object KFunction : ConeFunctionalTypeKind(
StandardNames.KOTLIN_REFLECT_FQ_NAME,
"KFunction",
isReflectType = true,
annotationOnInvokeClassId = null
) {
override fun nonReflectKind(): ConeFunctionalTypeKind = Function
}
object KSuspendFunction : ConeFunctionalTypeKind(
StandardNames.KOTLIN_REFLECT_FQ_NAME,
"KSuspendFunction",
isReflectType = true,
annotationOnInvokeClassId = null
) {
override fun nonReflectKind(): ConeFunctionalTypeKind = SuspendFunction
}
}
val ConeFunctionalTypeKind.isBuiltin: Boolean
get() = when (this) {
ConeFunctionalTypeKind.Function,
ConeFunctionalTypeKind.KFunction,
ConeFunctionalTypeKind.SuspendFunction,
ConeFunctionalTypeKind.KSuspendFunction -> true
else -> false
}