Remove unnecessary copy of ReflectionTypes
ReflectionTypes was copied from org.jetbrains.kotlin.builtins to
kotlin-native in
https://github.com/JetBrains/kotlin-native/commit/776f4c4b7, and then
was incorrectly copied back in 27365dc4be. This class is in fact only
needed in kotlin-native, where it was moved and simplified in
https://github.com/JetBrains/kotlin-native/commit/c3e921d53
This commit is contained in:
+5
-85
@@ -1,28 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. 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.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
interface CommonBackendContext : BackendContext {
|
||||
|
||||
override val ir: Ir<CommonBackendContext>
|
||||
|
||||
//TODO move to builtins
|
||||
@@ -33,77 +23,7 @@ interface CommonBackendContext : BackendContext {
|
||||
//TODO move to builtins
|
||||
fun getInternalFunctions(name: String): List<FunctionDescriptor>
|
||||
|
||||
val reflectionTypes: ReflectionTypes
|
||||
|
||||
fun log(message: () -> String)
|
||||
|
||||
fun report(element: IrElement?, irFile: IrFile?, message: String, isError: Boolean)
|
||||
}
|
||||
|
||||
class ReflectionTypes(module: ModuleDescriptor, internalPackage: FqName) {
|
||||
|
||||
private val kotlinReflectScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||
}
|
||||
|
||||
private val internalScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
module.getPackage(internalPackage).memberScope
|
||||
}
|
||||
|
||||
private fun find(memberScope: MemberScope, className: String): ClassDescriptor {
|
||||
val name = Name.identifier(className)
|
||||
return memberScope.getContributedClassifier(name, NoLookupLocation.FROM_REFLECTION) as ClassDescriptor
|
||||
}
|
||||
|
||||
private class ClassLookup(val memberScope: MemberScope) {
|
||||
operator fun getValue(types: ReflectionTypes, property: KProperty<*>): ClassDescriptor {
|
||||
return types.find(memberScope, property.name.capitalize())
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFunctionTypeArgumentProjections(
|
||||
receiverType: KotlinType?,
|
||||
parameterTypes: List<KotlinType>,
|
||||
returnType: KotlinType
|
||||
): List<TypeProjection> {
|
||||
val arguments = ArrayList<TypeProjection>(parameterTypes.size + (if (receiverType != null) 1 else 0) + 1)
|
||||
|
||||
arguments.addIfNotNull(receiverType?.asTypeProjection())
|
||||
|
||||
parameterTypes.mapTo(arguments, KotlinType::asTypeProjection)
|
||||
|
||||
arguments.add(returnType.asTypeProjection())
|
||||
|
||||
return arguments
|
||||
}
|
||||
|
||||
fun getKFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KFunction$n")
|
||||
|
||||
val kClass: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kProperty0: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kProperty1: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kProperty2: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kMutableProperty0: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kMutableProperty1: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kMutableProperty2: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
||||
val kFunctionImpl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kProperty0Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kProperty1Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kProperty2Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kMutableProperty0Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kMutableProperty1Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kMutableProperty2Impl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kLocalDelegatedPropertyImpl: ClassDescriptor by ClassLookup(internalScope)
|
||||
val kLocalDelegatedMutablePropertyImpl: ClassDescriptor by ClassLookup(internalScope)
|
||||
|
||||
fun getKFunctionType(
|
||||
annotations: Annotations,
|
||||
receiverType: KotlinType?,
|
||||
parameterTypes: List<KotlinType>,
|
||||
returnType: KotlinType
|
||||
): KotlinType {
|
||||
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
|
||||
val classDescriptor = getKFunction(arguments.size - 1 /* return type */)
|
||||
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.ReflectionTypes
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.KnownPackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
@@ -78,10 +77,6 @@ class JsIrBackendContext(
|
||||
override val sharedVariablesManager =
|
||||
JsSharedVariablesManager(irBuiltIns, implicitDeclarationFile)
|
||||
override val declarationFactory = JsDeclarationFactory()
|
||||
override val reflectionTypes: ReflectionTypes by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
// TODO
|
||||
ReflectionTypes(module, REFLECT_PACKAGE_FQNAME)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val KOTLIN_PACKAGE_FQN = FqName.fromSegments(listOf("kotlin"))
|
||||
@@ -149,10 +144,6 @@ class JsIrBackendContext(
|
||||
|
||||
val functions = (0..22).map { symbolTable.referenceClass(builtIns.getFunction(it)) }
|
||||
|
||||
val kFunctions by lazy {
|
||||
(0..22).map { symbolTable.referenceClass(reflectionTypes.getKFunction(it)) }
|
||||
}
|
||||
|
||||
val primitiveCompanionObjects = PrimitiveType.NUMBER_TYPES
|
||||
.asSequence()
|
||||
.filter { it.name != "LONG" && it.name != "CHAR" } // skip due to they have own explicit companions
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.ReflectionTypes
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
@@ -26,6 +27,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
|
||||
class JvmBackendContext(
|
||||
val state: GenerationState,
|
||||
@@ -37,9 +39,8 @@ class JvmBackendContext(
|
||||
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(psiSourceManager, builtIns, state, symbolTable)
|
||||
override val sharedVariablesManager = JvmSharedVariablesManager(builtIns, irBuiltIns)
|
||||
|
||||
override val reflectionTypes: ReflectionTypes by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
ReflectionTypes(state.module, FqName("kotlin.reflect.jvm.internal"))
|
||||
}
|
||||
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
||||
internal val reflectionTypes = ReflectionTypes(state.module, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, state.module))
|
||||
|
||||
override val ir = JvmIr(irModuleFragment, symbolTable)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user