Extract common interfaces from native ir (#618)
* Move objects out of inner classes * Extracted CommonBackendContext, common Ir and Symbols * Switch some lowers to CommonBackendContext * Move IrUtils to common package * Move 'atMostOne' utils to common package * Move DumpIrTreeWithDescriptorsVisitor to common package
This commit is contained in:
committed by
SvyatoslavScherbina
parent
74ffc479bb
commit
9af223fb00
+105
@@ -0,0 +1,105 @@
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
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.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 {
|
||||
|
||||
val ir: Ir<CommonBackendContext>
|
||||
|
||||
//TODO move to builtins
|
||||
fun getInternalClass(name: String): ClassDescriptor
|
||||
|
||||
//TODO move to builtins
|
||||
fun getInternalFunctions(name: String): List<FunctionDescriptor>
|
||||
|
||||
val reflectionTypes: ReflectionTypes
|
||||
|
||||
fun log(message: () -> String)
|
||||
|
||||
val compilerConfiguration: CompilerConfiguration
|
||||
}
|
||||
|
||||
class ReflectionTypes(module: ModuleDescriptor, internalPackage: FqName) {
|
||||
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
||||
|
||||
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 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)
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.ir.IrReturnableBlockImpl
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
+4
-4
@@ -23,19 +23,19 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
fun validateIrFile(context: BackendContext, irFile: IrFile) {
|
||||
fun validateIrFile(context: CommonBackendContext, irFile: IrFile) {
|
||||
val visitor = IrValidator(context, false)
|
||||
irFile.acceptVoid(visitor)
|
||||
}
|
||||
|
||||
fun validateIrModule(context: BackendContext, irModule: IrModuleFragment) {
|
||||
fun validateIrModule(context: CommonBackendContext, irModule: IrModuleFragment) {
|
||||
val visitor = IrValidator(context, true) // TODO: consider taking the boolean from settings.
|
||||
irModule.acceptVoid(visitor)
|
||||
|
||||
// TODO: also check that all referenced symbol targets are reachable.
|
||||
}
|
||||
|
||||
private fun BackendContext.reportIrValidationError(message: String, irFile: IrFile, irElement: IrElement) {
|
||||
private fun CommonBackendContext.reportIrValidationError(message: String, irFile: IrFile, irElement: IrElement) {
|
||||
try {
|
||||
this.reportWarning("[IR VALIDATION] $message", irFile, irElement)
|
||||
} catch (e: Throwable) {
|
||||
@@ -45,7 +45,7 @@ private fun BackendContext.reportIrValidationError(message: String, irFile: IrFi
|
||||
// TODO: throw an exception after fixing bugs leading to invalid IR.
|
||||
}
|
||||
|
||||
private class IrValidator(val context: BackendContext, performHeavyValidations: Boolean) : IrElementVisitorVoid {
|
||||
private class IrValidator(val context: CommonBackendContext, performHeavyValidations: Boolean) : IrElementVisitorVoid {
|
||||
|
||||
val builtIns = context.builtIns
|
||||
lateinit var currentFile: IrFile
|
||||
|
||||
+18
-15
@@ -16,30 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.util.getCompilerMessageLocation
|
||||
|
||||
// TODO: declare as a member of BackendContext
|
||||
val BackendContext.compilerConfiguration: CompilerConfiguration
|
||||
get() = when (this) {
|
||||
is KonanBackendContext -> this.config.configuration
|
||||
is JvmBackendContext -> this.state.configuration
|
||||
else -> TODO(this.toString())
|
||||
}
|
||||
val CommonBackendContext.messageCollector: MessageCollector
|
||||
get() = compilerConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
val BackendContext.messageCollector: MessageCollector
|
||||
get() = this.compilerConfiguration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
|
||||
fun BackendContext.reportWarning(message: String, irFile: IrFile, irElement: IrElement) {
|
||||
fun CommonBackendContext.reportWarning(message: String, irFile: IrFile, irElement: IrElement) {
|
||||
val location = irElement.getCompilerMessageLocation(irFile)
|
||||
this.messageCollector.report(CompilerMessageSeverity.WARNING, message, location)
|
||||
messageCollector.report(CompilerMessageSeverity.WARNING, message, location)
|
||||
}
|
||||
|
||||
fun <E> MutableList<E>.push(element: E) = this.add(element)
|
||||
@@ -48,3 +37,17 @@ fun <E> MutableList<E>.pop() = this.removeAt(size - 1)
|
||||
|
||||
fun <E> MutableList<E>.peek(): E? = if (size == 0) null else this[size - 1]
|
||||
|
||||
fun <T> Collection<T>.atMostOne(): T? {
|
||||
return when (this.size) {
|
||||
0 -> null
|
||||
1 -> this.iterator().next()
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Iterable<T>.atMostOne(predicate: (T) -> Boolean): T? = this.filter(predicate).atMostOne()
|
||||
|
||||
fun <T: Any> T.onlyIf(condition: T.()->Boolean, then: (T)->Unit): T {
|
||||
if (this.condition()) then(this)
|
||||
return this
|
||||
}
|
||||
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.generators.SymbolTable
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
// This is what Context collects about IR.
|
||||
abstract class Ir<out T: CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
|
||||
|
||||
val defaultParameterDeclarationsCache = mutableMapOf<FunctionDescriptor, IrFunction>()
|
||||
|
||||
abstract val symbols: Symbols<T>
|
||||
}
|
||||
|
||||
open class Symbols<out T: CommonBackendContext>(val context: T, private val symbolTable: SymbolTable) {
|
||||
|
||||
private val builtIns
|
||||
get() = context.builtIns
|
||||
|
||||
private fun builtInsPackage(vararg packageNameSegments: String) =
|
||||
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||
|
||||
val refClass = symbolTable.referenceClass(context.getInternalClass("Ref"))
|
||||
|
||||
val areEqualByValue = context.getInternalFunctions("areEqualByValue").map {
|
||||
symbolTable.referenceSimpleFunction(it)
|
||||
}
|
||||
|
||||
val areEqual = symbolTable.referenceSimpleFunction(context.getInternalFunctions("areEqual").single())
|
||||
|
||||
val ThrowNullPointerException = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("ThrowNullPointerException").single())
|
||||
|
||||
val ThrowNoWhenBranchMatchedException = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("ThrowNoWhenBranchMatchedException").single())
|
||||
|
||||
val ThrowTypeCastException = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("ThrowTypeCastException").single())
|
||||
|
||||
val ThrowUninitializedPropertyAccessException = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("ThrowUninitializedPropertyAccessException").single()
|
||||
)
|
||||
|
||||
val stringBuilder = symbolTable.referenceClass(
|
||||
builtInsPackage("kotlin", "text").getContributedClassifier(
|
||||
Name.identifier("StringBuilder"), NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val defaultArgumentMarker = symbolTable.referenceClass(context.getInternalClass("DefaultArgumentMarker"))
|
||||
|
||||
val any = symbolTable.referenceClass(builtIns.any)
|
||||
val unit = symbolTable.referenceClass(builtIns.unit)
|
||||
|
||||
val byte = symbolTable.referenceClass(builtIns.byte)
|
||||
val short = symbolTable.referenceClass(builtIns.short)
|
||||
val int = symbolTable.referenceClass(builtIns.int)
|
||||
val long = symbolTable.referenceClass(builtIns.long)
|
||||
|
||||
val integerClasses = listOf(byte, short, int, long)
|
||||
|
||||
val arrayOf = symbolTable.referenceSimpleFunction(
|
||||
builtInsPackage("kotlin").getContributedFunctions(
|
||||
Name.identifier("arrayOf"), NoLookupLocation.FROM_BACKEND
|
||||
).single()
|
||||
)
|
||||
|
||||
val array = symbolTable.referenceClass(builtIns.array)
|
||||
|
||||
private fun primitiveArrayClass(type: PrimitiveType) =
|
||||
symbolTable.referenceClass(builtIns.getPrimitiveArrayClassDescriptor(type))
|
||||
|
||||
val byteArray = primitiveArrayClass(PrimitiveType.BYTE)
|
||||
val charArray = primitiveArrayClass(PrimitiveType.CHAR)
|
||||
val shortArray = primitiveArrayClass(PrimitiveType.SHORT)
|
||||
val intArray = primitiveArrayClass(PrimitiveType.INT)
|
||||
val longArray = primitiveArrayClass(PrimitiveType.LONG)
|
||||
val floatArray = primitiveArrayClass(PrimitiveType.FLOAT)
|
||||
val doubleArray = primitiveArrayClass(PrimitiveType.DOUBLE)
|
||||
val booleanArray = primitiveArrayClass(PrimitiveType.BOOLEAN)
|
||||
|
||||
val arrays = PrimitiveType.values().map { primitiveArrayClass(it) } + array
|
||||
|
||||
val copyRangeTo = arrays.map { symbol ->
|
||||
val packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME)
|
||||
val functionDescriptor = packageViewDescriptor.memberScope
|
||||
.getContributedFunctions(Name.identifier("copyRangeTo"), NoLookupLocation.FROM_BACKEND)
|
||||
.first {
|
||||
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor
|
||||
}
|
||||
symbol.descriptor to symbolTable.referenceSimpleFunction(functionDescriptor)
|
||||
}.toMap()
|
||||
|
||||
val intAnd = symbolTable.referenceFunction(
|
||||
builtIns.intType.memberScope
|
||||
.getContributedFunctions(OperatorNameConventions.AND, NoLookupLocation.FROM_BACKEND)
|
||||
.single()
|
||||
)
|
||||
|
||||
val intPlusInt = symbolTable.referenceFunction(
|
||||
builtIns.intType.memberScope
|
||||
.getContributedFunctions(OperatorNameConventions.PLUS, NoLookupLocation.FROM_BACKEND)
|
||||
.single {
|
||||
it.valueParameters.single().type == builtIns.intType
|
||||
}
|
||||
)
|
||||
|
||||
val valuesForEnum = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("valuesForEnum").single())
|
||||
|
||||
val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("valueOfForEnum").single())
|
||||
|
||||
val getContinuation = symbolTable.referenceSimpleFunction(
|
||||
context.getInternalFunctions("getContinuation").single())
|
||||
|
||||
val coroutineImpl = symbolTable.referenceClass(context.getInternalClass("CoroutineImpl"))
|
||||
|
||||
val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
||||
builtInsPackage("kotlin", "coroutines", "experimental", "intrinsics")
|
||||
.getContributedVariables(Name.identifier("COROUTINE_SUSPENDED"), NoLookupLocation.FROM_BACKEND)
|
||||
.single().getter!!
|
||||
)
|
||||
|
||||
val kFunctionImpl = symbolTable.referenceClass(context.getInternalClass("KFunctionImpl"))
|
||||
|
||||
val kProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty0Impl)
|
||||
val kProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty1Impl)
|
||||
val kProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty2Impl)
|
||||
val kMutableProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl)
|
||||
val kMutableProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl)
|
||||
val kMutableProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl)
|
||||
val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl)
|
||||
val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl)
|
||||
|
||||
}
|
||||
+4
-3
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
@@ -116,7 +117,7 @@ internal fun IrClass.addSimpleDelegatingConstructor(superConstructorSymbol: IrCo
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Context.createArrayOfExpression(arrayElementType: KotlinType,
|
||||
internal fun CommonBackendContext.createArrayOfExpression(arrayElementType: KotlinType,
|
||||
arrayElements: List<IrExpression>,
|
||||
startOffset: Int, endOffset: Int): IrExpression {
|
||||
|
||||
+7
-6
@@ -39,6 +39,13 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.util.*
|
||||
|
||||
class LocalDeclarationsLowering(val context: BackendContext) : DeclarationContainerLoweringPass {
|
||||
|
||||
private object DECLARATION_ORIGIN_FIELD_FOR_CAPTURED_VALUE :
|
||||
IrDeclarationOriginImpl("FIELD_FOR_CAPTURED_VALUE") {}
|
||||
|
||||
private object STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE :
|
||||
IrStatementOriginImpl("INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE") {}
|
||||
|
||||
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||
if (irDeclarationContainer is IrDeclaration &&
|
||||
irDeclarationContainer.descriptor.parents.any { it is CallableDescriptor }) {
|
||||
@@ -338,12 +345,6 @@ class LocalDeclarationsLowering(val context: BackendContext) : DeclarationContai
|
||||
irDeclaration.transformChildrenVoid(FunctionBodiesRewriter(localContext))
|
||||
}
|
||||
|
||||
private object DECLARATION_ORIGIN_FIELD_FOR_CAPTURED_VALUE :
|
||||
IrDeclarationOriginImpl("FIELD_FOR_CAPTURED_VALUE") {}
|
||||
|
||||
private object STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE :
|
||||
IrStatementOriginImpl("INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE") {}
|
||||
|
||||
private fun rewriteClassMembers(irClass: IrClass, localClassContext: LocalClassContext) {
|
||||
irClass.transformChildrenVoid(FunctionBodiesRewriter(localClassContext))
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.common.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
|
||||
+12
-89
@@ -18,13 +18,14 @@ package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import llvm.LLVMDumpModule
|
||||
import llvm.LLVMModuleRef
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
||||
import org.jetbrains.kotlin.backend.common.ReflectionTypes
|
||||
import org.jetbrains.kotlin.backend.common.validateIrModule
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.DumpIrTreeWithDescriptorsVisitor
|
||||
import org.jetbrains.kotlin.backend.konan.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.konan.library.LinkData
|
||||
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanIr
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryWriter
|
||||
import org.jetbrains.kotlin.backend.konan.library.LinkData
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -32,31 +33,23 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.SourceManager
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor
|
||||
import org.jetbrains.kotlin.ir.util.endOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.ir.util.startOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||
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.lang.System.out
|
||||
import java.util.*
|
||||
import kotlin.LazyThreadSafetyMode.PUBLICATION
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
internal class SpecialDeclarationsFactory(val context: Context) {
|
||||
private val enumSpecialDeclarationsFactory by lazy { EnumSpecialDeclarationsFactory(context) }
|
||||
@@ -159,83 +152,13 @@ internal class SpecialDeclarationsFactory(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ReflectionTypes(module: ModuleDescriptor) {
|
||||
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
||||
val KONAN_INTERNAL_FQ_NAME = FqName("konan.internal")
|
||||
|
||||
private val kotlinReflectScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||
}
|
||||
|
||||
private val konanInternalScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
module.getPackage(KONAN_INTERNAL_FQ_NAME).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 kProperty0Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kProperty1Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kProperty2Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kMutableProperty0Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kMutableProperty1Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kMutableProperty2Impl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kLocalDelegatedPropertyImpl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
val kLocalDelegatedMutablePropertyImpl: ClassDescriptor by ClassLookup(konanInternalScope)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
lateinit var moduleDescriptor: ModuleDescriptor
|
||||
|
||||
override val builtIns: KonanBuiltIns by lazy(PUBLICATION) { moduleDescriptor.builtIns as KonanBuiltIns }
|
||||
|
||||
val specialDeclarationsFactory = SpecialDeclarationsFactory(this)
|
||||
val reflectionTypes: ReflectionTypes by lazy(PUBLICATION) { ReflectionTypes(moduleDescriptor) }
|
||||
override val reflectionTypes: ReflectionTypes by lazy(PUBLICATION) { ReflectionTypes(moduleDescriptor, FqName("konan.internal")) }
|
||||
private val vtableBuilders = mutableMapOf<ClassDescriptor, ClassVtablesBuilder>()
|
||||
|
||||
fun getVtableBuilder(classDescriptor: ClassDescriptor) = vtableBuilders.getOrPut(classDescriptor) {
|
||||
@@ -259,10 +182,10 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
}
|
||||
field = module!!
|
||||
|
||||
ir = Ir(this, module)
|
||||
ir = KonanIr(this, module)
|
||||
}
|
||||
|
||||
override lateinit var ir: Ir
|
||||
override lateinit var ir: KonanIr
|
||||
|
||||
override val irBuiltIns
|
||||
get() = ir.irModule.irBuiltins
|
||||
@@ -427,7 +350,7 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
return config.configuration.getBoolean(KonanConfigKeys.DEBUG)
|
||||
}
|
||||
|
||||
fun log(message: () -> String) {
|
||||
override fun log(message: () -> String) {
|
||||
if (phase?.verbose ?: false) {
|
||||
println(message())
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createSimpleDelegatingConstructorDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createSimpleDelegatingConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.Lifetime
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.RuntimeAware
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.isObjectType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
|
||||
+19
-4
@@ -16,18 +16,33 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.KonanSharedVariablesManager
|
||||
import org.jetbrains.kotlin.backend.konan.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.konanInternal
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanIr
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract internal class KonanBackendContext(val config: KonanConfig) : BackendContext {
|
||||
abstract internal class KonanBackendContext(val config: KonanConfig) : CommonBackendContext {
|
||||
abstract override val builtIns: KonanBuiltIns
|
||||
|
||||
abstract val ir: Ir
|
||||
abstract override val ir: KonanIr
|
||||
|
||||
override val sharedVariablesManager by lazy {
|
||||
// Creating lazily because builtIns module seems to be incomplete during `link` test;
|
||||
// TODO: investigate this.
|
||||
KonanSharedVariablesManager(this)
|
||||
}
|
||||
|
||||
override fun getInternalClass(name: String): ClassDescriptor =
|
||||
builtIns.konanInternal.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
|
||||
override fun getInternalFunctions(name: String): List<FunctionDescriptor> =
|
||||
builtIns.konanInternal.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).toList()
|
||||
|
||||
override val compilerConfiguration: CompilerConfiguration
|
||||
get() = config.configuration
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.backend.common.messageCollector
|
||||
import org.jetbrains.kotlin.backend.common.validateIrModule
|
||||
import org.jetbrains.kotlin.backend.konan.ir.DeserializerDriver
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ModuleIndex
|
||||
import org.jetbrains.kotlin.backend.konan.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.emitLLVM
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.KonanSerializationUtil
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.markBackingFields
|
||||
@@ -85,7 +85,7 @@ public fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEn
|
||||
val generatorContext = translator.createGeneratorContext(context.moduleDescriptor, bindingContext)
|
||||
context.psi2IrGeneratorContext = generatorContext
|
||||
|
||||
val symbols = Symbols(context, generatorContext.symbolTable)
|
||||
val symbols = KonanSymbols(context, generatorContext.symbolTable)
|
||||
|
||||
val module = translator.generateModuleFragment(generatorContext, environment.getSourceFiles())
|
||||
|
||||
|
||||
+2
-2
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.messageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.util.getCompilerMessageLocation
|
||||
|
||||
internal fun BackendContext.reportCompilationError(message: String, irFile: IrFile, irElement: IrElement): Nothing {
|
||||
internal fun CommonBackendContext.reportCompilationError(message: String, irFile: IrFile, irElement: IrElement): Nothing {
|
||||
val location = irElement.getCompilerMessageLocation(irFile)
|
||||
this.messageCollector.report(CompilerMessageSeverity.ERROR, message, location)
|
||||
throw KonanCompilationException()
|
||||
|
||||
-21
@@ -116,27 +116,6 @@ private val konanInternalPackageName = FqName.fromSegments(listOf("konan", "inte
|
||||
internal val KonanBuiltIns.konanInternal: MemberScope
|
||||
get() = this.builtInsModule.getPackage(konanInternalPackageName).memberScope
|
||||
|
||||
/**
|
||||
* @return built-in class `konan.internal.$name` or
|
||||
* `null` if no such class is available (e.g. when compiling `link` test without stdlib).
|
||||
*
|
||||
* TODO: remove this workaround after removing compilation without stdlib.
|
||||
*/
|
||||
internal fun KonanBuiltIns.getKonanInternalClassOrNull(name: String): ClassDescriptor? {
|
||||
val classifier = konanInternal.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND)
|
||||
return classifier as? ClassDescriptor
|
||||
}
|
||||
|
||||
/**
|
||||
* @return built-in class `konan.internal.$name`
|
||||
*/
|
||||
internal fun KonanBuiltIns.getKonanInternalClass(name: String): ClassDescriptor =
|
||||
getKonanInternalClassOrNull(name) ?: TODO(name)
|
||||
|
||||
internal fun KonanBuiltIns.getKonanInternalFunctions(name: String): List<FunctionDescriptor> {
|
||||
return konanInternal.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).toList()
|
||||
}
|
||||
|
||||
internal val KotlinType.isFunctionOrKFunctionType: Boolean
|
||||
get() {
|
||||
val kind = constructor.declarationDescriptor?.getFunctionalClassKind()
|
||||
|
||||
+22
-154
@@ -16,184 +16,52 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.ValueType
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalClass
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalFunctions
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.konanInternal
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.generators.SymbolTable
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
// This is what Context collects about IR.
|
||||
internal class Ir(val context: Context, val irModule: IrModuleFragment) {
|
||||
val propertiesWithBackingFields = mutableSetOf<PropertyDescriptor>()
|
||||
internal class KonanIr(context: Context, irModule: IrModuleFragment): Ir<Context>(context, irModule) {
|
||||
|
||||
val defaultParameterDeclarationsCache = mutableMapOf<FunctionDescriptor, IrFunction>()
|
||||
val propertiesWithBackingFields = mutableSetOf<PropertyDescriptor>()
|
||||
|
||||
val originalModuleIndex = ModuleIndex(irModule)
|
||||
|
||||
lateinit var moduleIndexForCodegen: ModuleIndex
|
||||
|
||||
lateinit var symbols: Symbols
|
||||
override var symbols: KonanSymbols by Delegates.notNull()
|
||||
}
|
||||
|
||||
internal class Symbols(val context: Context, val symbolTable: SymbolTable) {
|
||||
|
||||
val builtIns: KonanBuiltIns get() = context.builtIns
|
||||
|
||||
private fun builtInsPackage(vararg packageNameSegments: String) =
|
||||
builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||
|
||||
val refClass = symbolTable.referenceClass(builtIns.getKonanInternalClass("Ref"))
|
||||
|
||||
val areEqualByValue = builtIns.getKonanInternalFunctions("areEqualByValue").map {
|
||||
symbolTable.referenceSimpleFunction(it)
|
||||
}
|
||||
|
||||
val areEqual = symbolTable.referenceSimpleFunction(builtIns.getKonanInternalFunctions("areEqual").single())
|
||||
|
||||
val ThrowNullPointerException = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("ThrowNullPointerException").single())
|
||||
|
||||
val ThrowNoWhenBranchMatchedException = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("ThrowNoWhenBranchMatchedException").single())
|
||||
|
||||
val ThrowTypeCastException = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("ThrowTypeCastException").single())
|
||||
|
||||
val ThrowUninitializedPropertyAccessException = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("ThrowUninitializedPropertyAccessException").single()
|
||||
)
|
||||
|
||||
val stringBuilder = symbolTable.referenceClass(
|
||||
builtInsPackage("kotlin", "text").getContributedClassifier(
|
||||
Name.identifier("StringBuilder"), NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val defaultArgumentMarker = symbolTable.referenceClass(
|
||||
builtIns.konanInternal.getContributedClassifier(
|
||||
Name.identifier("DefaultArgumentMarker"), NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val any = symbolTable.referenceClass(builtIns.any)
|
||||
val unit = symbolTable.referenceClass(builtIns.unit)
|
||||
|
||||
val byte = symbolTable.referenceClass(builtIns.byte)
|
||||
val short = symbolTable.referenceClass(builtIns.short)
|
||||
val int = symbolTable.referenceClass(builtIns.int)
|
||||
val long = symbolTable.referenceClass(builtIns.long)
|
||||
|
||||
val integerClasses = listOf(byte, short, int, long)
|
||||
|
||||
val arrayOf = symbolTable.referenceSimpleFunction(
|
||||
builtInsPackage("kotlin").getContributedFunctions(
|
||||
Name.identifier("arrayOf"), NoLookupLocation.FROM_BACKEND
|
||||
).single()
|
||||
)
|
||||
|
||||
val array = symbolTable.referenceClass(builtIns.array)
|
||||
|
||||
private fun primitiveArrayClass(type: PrimitiveType) =
|
||||
symbolTable.referenceClass(builtIns.getPrimitiveArrayClassDescriptor(type))
|
||||
|
||||
val byteArray = primitiveArrayClass(PrimitiveType.BYTE)
|
||||
val charArray = primitiveArrayClass(PrimitiveType.CHAR)
|
||||
val shortArray = primitiveArrayClass(PrimitiveType.SHORT)
|
||||
val intArray = primitiveArrayClass(PrimitiveType.INT)
|
||||
val longArray = primitiveArrayClass(PrimitiveType.LONG)
|
||||
val floatArray = primitiveArrayClass(PrimitiveType.FLOAT)
|
||||
val doubleArray = primitiveArrayClass(PrimitiveType.DOUBLE)
|
||||
val booleanArray = primitiveArrayClass(PrimitiveType.BOOLEAN)
|
||||
|
||||
val arrays = PrimitiveType.values().map { primitiveArrayClass(it) } + array
|
||||
|
||||
val copyRangeTo = arrays.map { symbol ->
|
||||
val packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME)
|
||||
val functionDescriptor = packageViewDescriptor.memberScope
|
||||
.getContributedFunctions(Name.identifier("copyRangeTo"), NoLookupLocation.FROM_BACKEND)
|
||||
.first {
|
||||
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == symbol.descriptor
|
||||
}
|
||||
symbol.descriptor to symbolTable.referenceSimpleFunction(functionDescriptor)
|
||||
}.toMap()
|
||||
|
||||
val intAnd = symbolTable.referenceFunction(
|
||||
builtIns.intType.memberScope
|
||||
.getContributedFunctions(OperatorNameConventions.AND, NoLookupLocation.FROM_BACKEND)
|
||||
.single()
|
||||
)
|
||||
|
||||
val intPlusInt = symbolTable.referenceFunction(
|
||||
builtIns.intType.memberScope
|
||||
.getContributedFunctions(OperatorNameConventions.PLUS, NoLookupLocation.FROM_BACKEND)
|
||||
.single {
|
||||
it.valueParameters.single().type == builtIns.intType
|
||||
}
|
||||
)
|
||||
|
||||
val boxFunctions = ValueType.values().associate {
|
||||
val boxFunctionName = "box${it.classFqName.shortName()}"
|
||||
it to symbolTable.referenceSimpleFunction(context.builtIns.getKonanInternalFunctions(boxFunctionName).single())
|
||||
}
|
||||
|
||||
val boxClasses = ValueType.values().associate {
|
||||
it to symbolTable.referenceClass(context.builtIns.getKonanInternalClass("${it.classFqName.shortName()}Box"))
|
||||
}
|
||||
|
||||
val unboxFunctions = ValueType.values().mapNotNull {
|
||||
val unboxFunctionName = "unbox${it.classFqName.shortName()}"
|
||||
context.builtIns.getKonanInternalFunctions(unboxFunctionName).atMostOne()?.let { descriptor ->
|
||||
it to symbolTable.referenceSimpleFunction(descriptor)
|
||||
}
|
||||
}.toMap()
|
||||
internal class KonanSymbols(context: Context, val symbolTable: SymbolTable): Symbols<Context>(context, symbolTable) {
|
||||
|
||||
val interopNativePointedGetRawPointer =
|
||||
symbolTable.referenceSimpleFunction(context.interopBuiltIns.nativePointedGetRawPointer)
|
||||
|
||||
val interopCPointerGetRawValue = symbolTable.referenceSimpleFunction(context.interopBuiltIns.cPointerGetRawValue)
|
||||
|
||||
val getNativeNullPtr = symbolTable.referenceSimpleFunction(builtIns.getNativeNullPtr)
|
||||
val getNativeNullPtr = symbolTable.referenceSimpleFunction(context.builtIns.getNativeNullPtr)
|
||||
|
||||
val valuesForEnum = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("valuesForEnum").single())
|
||||
val boxFunctions = ValueType.values().associate {
|
||||
val boxFunctionName = "box${it.classFqName.shortName()}"
|
||||
it to symbolTable.referenceSimpleFunction(context.getInternalFunctions(boxFunctionName).single())
|
||||
}
|
||||
|
||||
val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
||||
builtIns.getKonanInternalFunctions("valueOfForEnum").single())
|
||||
val boxClasses = ValueType.values().associate {
|
||||
it to symbolTable.referenceClass(context.getInternalClass("${it.classFqName.shortName()}Box"))
|
||||
}
|
||||
|
||||
val getContinuation = symbolTable.referenceSimpleFunction(
|
||||
context.builtIns.getKonanInternalFunctions("getContinuation").single())
|
||||
val unboxFunctions = ValueType.values().mapNotNull {
|
||||
val unboxFunctionName = "unbox${it.classFqName.shortName()}"
|
||||
context.getInternalFunctions(unboxFunctionName).atMostOne()?.let { descriptor ->
|
||||
it to symbolTable.referenceSimpleFunction(descriptor)
|
||||
}
|
||||
}.toMap()
|
||||
|
||||
val coroutineImpl = symbolTable.referenceClass(context.builtIns.getKonanInternalClass("CoroutineImpl"))
|
||||
|
||||
val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
||||
builtInsPackage("kotlin", "coroutines", "experimental", "intrinsics")
|
||||
.getContributedVariables(Name.identifier("COROUTINE_SUSPENDED"), NoLookupLocation.FROM_BACKEND)
|
||||
.single().getter!!
|
||||
)
|
||||
|
||||
val kFunctionImpl = symbolTable.referenceClass(context.builtIns.getKonanInternalClass("KFunctionImpl"))
|
||||
|
||||
val kProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty0Impl)
|
||||
val kProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty1Impl)
|
||||
val kProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty2Impl)
|
||||
val kMutableProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl)
|
||||
val kMutableProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl)
|
||||
val kMutableProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl)
|
||||
val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl)
|
||||
val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl)
|
||||
|
||||
}
|
||||
+2
-2
@@ -20,6 +20,7 @@ import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.isSuspend
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
||||
import org.jetbrains.kotlin.backend.konan.CompilerOutputKind
|
||||
@@ -28,7 +29,6 @@ import org.jetbrains.kotlin.backend.konan.library.LinkData
|
||||
import org.jetbrains.kotlin.backend.konan.PhaseManager
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.backend.konan.TargetManager
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryWriter
|
||||
import org.jetbrains.kotlin.backend.konan.library.SplitLibraryWriter
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
@@ -1712,7 +1712,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private val coroutineImplDescriptor = context.builtIns.getKonanInternalClass("CoroutineImpl")
|
||||
private val coroutineImplDescriptor = context.getInternalClass("CoroutineImpl")
|
||||
private val doResumeFunctionDescriptor = coroutineImplDescriptor.unsubstitutedMemberScope
|
||||
.getContributedFunctions(Name.identifier("doResume"), NoLookupLocation.FROM_BACKEND).single()
|
||||
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.backend.common.AbstractValueUsageTransformer
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.isSuspend
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalClass
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.target
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -228,7 +227,7 @@ private class AutoboxingTransformer(val context: Context) : AbstractValueUsageTr
|
||||
get() = this.classFqName.shortName()
|
||||
|
||||
private fun getBoxType(valueType: ValueType) =
|
||||
context.builtIns.getKonanInternalClass("${valueType.shortName}Box").defaultType
|
||||
context.getInternalClass("${valueType.shortName}Box").defaultType
|
||||
|
||||
private fun IrExpression.box(valueType: ValueType): IrExpression {
|
||||
val boxFunction = symbols.boxFunctions[valueType]!!
|
||||
|
||||
+1
-1
@@ -17,10 +17,10 @@
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys.Companion.ENABLE_ASSERTIONS
|
||||
import org.jetbrains.kotlin.backend.konan.isValueType
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
|
||||
+15
-11
@@ -19,19 +19,26 @@ package org.jetbrains.kotlin.backend.konan.lower
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.explicitParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.getFunction
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.replace
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isFunctionOrKFunctionType
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createFakeOverrideDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createFakeOverrideDescriptor
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.functionName
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
@@ -44,18 +51,18 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
internal class CallableReferenceLowering(val context: Context): FileLoweringPass {
|
||||
|
||||
private object DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL : IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL")
|
||||
|
||||
private var functionReferenceCount = 0
|
||||
|
||||
override fun lower(irFile: IrFile) {
|
||||
@@ -94,10 +101,9 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
val functionReferenceConstructor: IrConstructor)
|
||||
|
||||
private val COROUTINES_FQ_NAME = FqName.fromSegments(listOf("kotlin", "coroutines", "experimental"))
|
||||
private val KOTLIN_FQ_NAME = FqName("kotlin")
|
||||
|
||||
private val coroutinesScope = context.irModule!!.descriptor.getPackage(COROUTINES_FQ_NAME).memberScope
|
||||
private val kotlinPackageScope = context.irModule!!.descriptor.getPackage(KOTLIN_FQ_NAME).memberScope
|
||||
private val kotlinPackageScope = context.builtIns.builtInsPackageScope
|
||||
|
||||
private val continuationClassDescriptor = coroutinesScope
|
||||
.getContributedClassifier(Name.identifier("Continuation"), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
@@ -374,7 +380,5 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
return propertyBuilder.ir.backingField!!.symbol
|
||||
}
|
||||
|
||||
private object DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL :
|
||||
IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL")
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -17,12 +17,13 @@
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.irBlockBody
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
@@ -51,7 +52,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
class DefaultArgumentStubGenerator internal constructor(val context: Context): DeclarationContainerLoweringPass {
|
||||
class DefaultArgumentStubGenerator internal constructor(val context: CommonBackendContext): DeclarationContainerLoweringPass {
|
||||
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||
irDeclarationContainer.declarations.transformFlat { memberDeclaration ->
|
||||
if (memberDeclaration is IrFunction)
|
||||
@@ -339,7 +340,7 @@ class DefaultParameterInjector internal constructor(val context: Context): BodyL
|
||||
private val CallableMemberDescriptor.needsDefaultArgumentsLowering
|
||||
get() = valueParameters.any { it.hasDefaultValue() } && !(this is FunctionDescriptor && isInline)
|
||||
|
||||
private fun FunctionDescriptor.generateDefaultsFunction(context: Context): IrFunction {
|
||||
private fun FunctionDescriptor.generateDefaultsFunction(context: CommonBackendContext): IrFunction {
|
||||
return context.ir.defaultParameterDeclarationsCache.getOrPut(this) {
|
||||
val descriptor = when (this) {
|
||||
is ClassConstructorDescriptor ->
|
||||
|
||||
+12
-11
@@ -16,40 +16,41 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createArrayOfExpression
|
||||
import org.jetbrains.kotlin.backend.common.ir.createArrayOfExpression
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrLocalDelegatedProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.functions
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.replace
|
||||
|
||||
internal class PropertyDelegationLowering(val context: Context) : FileLoweringPass {
|
||||
internal class PropertyDelegationLowering(val context: CommonBackendContext) : FileLoweringPass {
|
||||
private val reflectionTypes = context.reflectionTypes
|
||||
private val kotlinPackage = context.irModule!!.descriptor.getPackage(FqName("kotlin"))
|
||||
private val genericArrayType = kotlinPackage.memberScope.getContributedClassifier(Name.identifier("Array"), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
private var tempIndex = 0
|
||||
|
||||
private fun getKPropertyImplConstructor(receiverTypes: List<KotlinType>,
|
||||
@@ -108,7 +109,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
||||
val kPropertiesField = IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION,
|
||||
createKPropertiesFieldDescriptor(irFile.packageFragmentDescriptor,
|
||||
genericArrayType.replace(kPropertyImplType)
|
||||
context.builtIns.array.replace(kPropertyImplType)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
+4
-4
@@ -24,10 +24,10 @@ import org.jetbrains.kotlin.backend.jvm.descriptors.createValueParameter
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.DECLARATION_ORIGIN_ENUM
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createArrayOfExpression
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createFakeOverrideDescriptor
|
||||
import org.jetbrains.kotlin.backend.konan.ir.addSimpleDelegatingConstructor
|
||||
import org.jetbrains.kotlin.backend.konan.ir.createSimpleDelegatingConstructorDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createArrayOfExpression
|
||||
import org.jetbrains.kotlin.backend.common.ir.createFakeOverrideDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.addSimpleDelegatingConstructor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createSimpleDelegatingConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
|
||||
+11
-9
@@ -17,9 +17,12 @@
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -37,7 +40,12 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.hasPrimaryConstructor
|
||||
|
||||
internal class InitializersLowering(val context: Context) : ClassLoweringPass {
|
||||
internal class InitializersLowering(val context: CommonBackendContext) : ClassLoweringPass {
|
||||
|
||||
object STATEMENT_ORIGIN_ANONYMOUS_INITIALIZER : IrStatementOriginImpl("ANONYMOUS_INITIALIZER")
|
||||
|
||||
object DECLARATION_ORIGIN_ANONYMOUS_INITIALIZER : IrDeclarationOriginImpl("ANONYMOUS_INITIALIZER")
|
||||
|
||||
override fun lower(irClass: IrClass) {
|
||||
InitializersTransformer(irClass).lowerInitializers()
|
||||
}
|
||||
@@ -51,12 +59,6 @@ internal class InitializersLowering(val context: Context) : ClassLoweringPass {
|
||||
lowerConstructors(initializerMethodSymbol)
|
||||
}
|
||||
|
||||
object STATEMENT_ORIGIN_ANONYMOUS_INITIALIZER :
|
||||
IrStatementOriginImpl("ANONYMOUS_INITIALIZER")
|
||||
|
||||
object DECLARATION_ORIGIN_ANONYMOUS_INITIALIZER :
|
||||
IrDeclarationOriginImpl("ANONYMOUS_INITIALIZER")
|
||||
|
||||
private fun collectAndRemoveInitializers() {
|
||||
// Do with one traversal in order to preserve initializers order.
|
||||
irClass.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.isValueType
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal class LateinitLowering(val context: Context): FileLoweringPass {
|
||||
internal class LateinitLowering(val context: CommonBackendContext): FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildrenVoid(object: IrElementTransformerVoid() {
|
||||
override fun visitProperty(declaration: IrProperty): IrStatement {
|
||||
|
||||
+3
-3
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
/**
|
||||
* This lowering pass replaces [IrStringConcatenation]s with StringBuilder appends.
|
||||
*/
|
||||
internal class StringConcatenationLowering(val context: Context) : FileLoweringPass {
|
||||
internal class StringConcatenationLowering(val context: CommonBackendContext) : FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) {
|
||||
irFile.transformChildrenVoid(StringConcatenationTransformer(this))
|
||||
}
|
||||
|
||||
+22
-16
@@ -16,42 +16,53 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.explicitParameters
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.explicitParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.getFunction
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.replace
|
||||
import org.jetbrains.kotlin.backend.common.ir.createFakeOverrideDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createOverriddenDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalFunctions
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetVariableImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
|
||||
internal class SuspendFunctionsLowering(val context: Context): DeclarationContainerLoweringPass {
|
||||
|
||||
private object STATEMENT_ORIGIN_COROUTINE_IMPL : IrStatementOriginImpl("COROUTINE_IMPL")
|
||||
private object DECLARATION_ORIGIN_COROUTINE_IMPL : IrDeclarationOriginImpl("COROUTINE_IMPL")
|
||||
|
||||
private val builtCoroutines = mutableMapOf<FunctionDescriptor, BuiltCoroutine>()
|
||||
private val suspendLambdas = mutableMapOf<FunctionDescriptor, IrFunctionReference>()
|
||||
|
||||
@@ -202,7 +213,7 @@ internal class SuspendFunctionsLowering(val context: Context): DeclarationContai
|
||||
|
||||
private val symbols = context.ir.symbols
|
||||
private val getContinuationSymbol = symbols.getContinuation
|
||||
private val returnIfSuspendedDescriptor = context.builtIns.getKonanInternalFunctions("returnIfSuspended").single()
|
||||
private val returnIfSuspendedDescriptor = context.getInternalFunctions("returnIfSuspended").single()
|
||||
|
||||
private fun removeReturnIfSuspendedCall(irFunction: IrFunction) {
|
||||
irFunction.transformChildrenVoid(object: IrElementTransformerVoid() {
|
||||
@@ -1075,9 +1086,6 @@ internal class SuspendFunctionsLowering(val context: Context): DeclarationContai
|
||||
private val IrExpression.isSuspendCall: Boolean
|
||||
get() = this is IrCall && this.descriptor.isSuspend
|
||||
|
||||
private object STATEMENT_ORIGIN_COROUTINE_IMPL :
|
||||
IrStatementOriginImpl("COROUTINE_IMPL")
|
||||
|
||||
private fun IrElement.isSpecialBlock()
|
||||
= this is IrBlock && this.origin == STATEMENT_ORIGIN_COROUTINE_IMPL
|
||||
|
||||
@@ -1116,8 +1124,6 @@ internal class SuspendFunctionsLowering(val context: Context): DeclarationContai
|
||||
get() = this is IrCall && this.descriptor.original == returnIfSuspendedDescriptor
|
||||
}
|
||||
|
||||
private object DECLARATION_ORIGIN_COROUTINE_IMPL :
|
||||
IrDeclarationOriginImpl("COROUTINE_IMPL")
|
||||
|
||||
private fun IrBuilderWithScope.irVar(descriptor: VariableDescriptor, initializer: IrExpression?) =
|
||||
IrVariableImpl(startOffset, endOffset, DECLARATION_ORIGIN_COROUTINE_IMPL, descriptor, initializer)
|
||||
|
||||
+6
-4
@@ -16,9 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.FunctionLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.common.lower.at
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -39,7 +41,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
/**
|
||||
* This lowering pass lowers some [IrTypeOperatorCall]s.
|
||||
*/
|
||||
internal class TypeOperatorLowering(val context: Context) : FunctionLoweringPass {
|
||||
internal class TypeOperatorLowering(val context: CommonBackendContext) : FunctionLoweringPass {
|
||||
override fun lower(irFunction: IrFunction) {
|
||||
val transformer = TypeOperatorTransformer(context, irFunction.symbol)
|
||||
irFunction.transformChildrenVoid(transformer)
|
||||
@@ -47,7 +49,7 @@ internal class TypeOperatorLowering(val context: Context) : FunctionLoweringPass
|
||||
}
|
||||
|
||||
|
||||
private class TypeOperatorTransformer(val context: Context, val function: IrFunctionSymbol) : IrElementTransformerVoid() {
|
||||
private class TypeOperatorTransformer(val context: CommonBackendContext, val function: IrFunctionSymbol) : IrElementTransformerVoid() {
|
||||
|
||||
private val builder = context.createIrBuilder(function)
|
||||
|
||||
|
||||
+3
-3
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedString
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
|
||||
class VarargInjectionLowering internal constructor(val context: Context): DeclarationContainerLoweringPass {
|
||||
class VarargInjectionLowering internal constructor(val context: CommonBackendContext): DeclarationContainerLoweringPass {
|
||||
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||
irDeclarationContainer.declarations.forEach{
|
||||
when (it) {
|
||||
|
||||
+1
-1
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.onlyIf
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.needsSerializedIr
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.IrAwareExtension
|
||||
import org.jetbrains.kotlin.backend.konan.util.onlyIf
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.builtins.transformSuspendFunctionToRuntimeFunctionType
|
||||
|
||||
-2
@@ -17,9 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalClass
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.backend.common.DeepCopyIrTreeWithDescriptors
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.deserializedPropertyIfAccessor
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isDeserializableCallable
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2stringWhole
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2stringWhole
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.base64Decode
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.base64Encode
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
+2
-12
@@ -16,25 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2stringWhole
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.EmptyDescriptorVisitorVoid
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.*
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.base64Encode
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.base64Decode
|
||||
import org.jetbrains.kotlin.backend.konan.PhaseManager
|
||||
import org.jetbrains.kotlin.backend.konan.KonanPhase
|
||||
import org.jetbrains.kotlin.serialization.MutableTypeTable
|
||||
import org.jetbrains.kotlin.serialization.KonanLinkData
|
||||
|
||||
internal class DeserializerDriver(val context: Context) {
|
||||
|
||||
@@ -48,7 +38,7 @@ internal class DeserializerDriver(val context: Context) {
|
||||
try {
|
||||
deserializedIr = IrDeserializer(context, descriptor).decodeDeclaration()
|
||||
context.log{"${deserializedIr!!.descriptor}"}
|
||||
context.log{ir2stringWhole(deserializedIr!!)}
|
||||
context.log{ ir2stringWhole(deserializedIr!!) }
|
||||
context.log{"IR deserialization SUCCESS:\t$descriptor"}
|
||||
} catch(e: Throwable) {
|
||||
context.log{"IR deserialization FAILURE:\t$descriptor"}
|
||||
|
||||
-15
@@ -36,21 +36,6 @@ fun nTabs(amount: Int): String {
|
||||
return String.format("%1$-${(amount+1)*4}s", "")
|
||||
}
|
||||
|
||||
fun <T> Collection<T>.atMostOne(): T? {
|
||||
return when (this.size) {
|
||||
0 -> null
|
||||
1 -> this.iterator().next()
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Iterable<T>.atMostOne(predicate: (T) -> Boolean): T? = this.filter(predicate).atMostOne()
|
||||
|
||||
fun <T: Any> T.onlyIf(condition: T.()->Boolean, then: (T)->Unit): T {
|
||||
if (this.condition()) then(this)
|
||||
return this
|
||||
}
|
||||
|
||||
fun String.suffixIfNot(suffix: String) =
|
||||
if (this.endsWith(suffix)) this else "$this$suffix"
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
|
||||
Reference in New Issue
Block a user