Move platform specific symbols to KonanSymbols
(cherry picked from commit 40df6da2d78420497c6c2cd3a229ab00fb0d8f36)
This commit is contained in:
committed by
Vasily Levchenko
parent
d33e8c78d1
commit
d9c04eaaf5
+14
-44
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
@@ -26,40 +27,23 @@ abstract class Ir<out T: CommonBackendContext>(val context: T, val irModule: IrM
|
|||||||
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Symbols<out T: CommonBackendContext>(val context: T, private val symbolTable: SymbolTable) {
|
abstract class Symbols<out T: CommonBackendContext>(val context: T, private val symbolTable: SymbolTable) {
|
||||||
|
|
||||||
private val builtIns
|
private val builtIns
|
||||||
get() = context.builtIns
|
get() = context.builtIns
|
||||||
|
|
||||||
private fun builtInsPackage(vararg packageNameSegments: String) =
|
protected fun builtInsPackage(vararg packageNameSegments: String) =
|
||||||
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||||
|
|
||||||
val refClass = symbolTable.referenceClass(context.getInternalClass("Ref"))
|
val refClass = symbolTable.referenceClass(context.getInternalClass("Ref"))
|
||||||
|
|
||||||
val areEqualByValue = context.getInternalFunctions("areEqualByValue").map {
|
abstract val areEqual: IrFunctionSymbol
|
||||||
symbolTable.referenceSimpleFunction(it)
|
abstract val ThrowNullPointerException: IrFunctionSymbol
|
||||||
}
|
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
||||||
|
abstract val ThrowTypeCastException: IrFunctionSymbol
|
||||||
|
abstract val ThrowUninitializedPropertyAccessException: IrFunctionSymbol
|
||||||
|
|
||||||
val areEqual = symbolTable.referenceSimpleFunction(context.getInternalFunctions("areEqual").single())
|
abstract val stringBuilder: IrClassSymbol
|
||||||
|
|
||||||
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 iterator = symbolTable.referenceClass(
|
val iterator = symbolTable.referenceClass(
|
||||||
builtInsPackage("kotlin", "collections").getContributedClassifier(
|
builtInsPackage("kotlin", "collections").getContributedClassifier(
|
||||||
@@ -82,11 +66,6 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
val progressionClasses = listOf(charProgression, intProgression, longProgression)
|
val progressionClasses = listOf(charProgression, intProgression, longProgression)
|
||||||
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
||||||
|
|
||||||
val checkProgressionStep = context.getInternalFunctions("checkProgressionStep")
|
|
||||||
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
|
||||||
val getProgressionLast = context.getInternalFunctions("getProgressionLast")
|
|
||||||
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
|
||||||
|
|
||||||
val defaultConstructorMarker = symbolTable.referenceClass(context.getInternalClass("DefaultConstructorMarker"))
|
val defaultConstructorMarker = symbolTable.referenceClass(context.getInternalClass("DefaultConstructorMarker"))
|
||||||
|
|
||||||
val any = symbolTable.referenceClass(builtIns.any)
|
val any = symbolTable.referenceClass(builtIns.any)
|
||||||
@@ -124,7 +103,7 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
|
|
||||||
val arrays = PrimitiveType.values().map { primitiveArrayClass(it) } + array
|
val arrays = PrimitiveType.values().map { primitiveArrayClass(it) } + array
|
||||||
|
|
||||||
private fun arrayExtensionFun(type: KotlinType, name: String): IrSimpleFunctionSymbol {
|
protected fun arrayExtensionFun(type: KotlinType, name: String): IrSimpleFunctionSymbol {
|
||||||
val descriptor = builtInsPackage("kotlin")
|
val descriptor = builtInsPackage("kotlin")
|
||||||
.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND)
|
.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND)
|
||||||
.singleOrNull { it.valueParameters.isEmpty()
|
.singleOrNull { it.valueParameters.isEmpty()
|
||||||
@@ -134,7 +113,7 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val arrayTypes = arrayOf(
|
protected val arrayTypes = arrayOf(
|
||||||
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.BYTE),
|
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.BYTE),
|
||||||
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.CHAR),
|
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.CHAR),
|
||||||
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.SHORT),
|
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.SHORT),
|
||||||
@@ -145,8 +124,6 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.BOOLEAN),
|
builtIns.getPrimitiveArrayKotlinType(PrimitiveType.BOOLEAN),
|
||||||
builtIns.array.defaultType
|
builtIns.array.defaultType
|
||||||
)
|
)
|
||||||
val arrayContentToString = arrayTypes.associateBy({ it }, { arrayExtensionFun(it, "contentToString") })
|
|
||||||
val arrayContentHashCode = arrayTypes.associateBy({ it }, { arrayExtensionFun(it, "contentHashCode") })
|
|
||||||
|
|
||||||
val copyRangeTo = arrays.map { symbol ->
|
val copyRangeTo = arrays.map { symbol ->
|
||||||
val packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME)
|
val packageViewDescriptor = builtIns.builtInsModule.getPackage(KotlinBuiltIns.COLLECTIONS_PACKAGE_FQ_NAME)
|
||||||
@@ -174,14 +151,9 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
val valuesForEnum = symbolTable.referenceSimpleFunction(
|
abstract val valuesForEnum: IrFunctionSymbol
|
||||||
context.getInternalFunctions("valuesForEnum").single())
|
abstract val valueOfForEnum: IrFunctionSymbol
|
||||||
|
abstract val getContinuation: IrFunctionSymbol
|
||||||
val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
|
||||||
context.getInternalFunctions("valueOfForEnum").single())
|
|
||||||
|
|
||||||
val getContinuation = symbolTable.referenceSimpleFunction(
|
|
||||||
context.getInternalFunctions("getContinuation").single())
|
|
||||||
|
|
||||||
val coroutineImpl = symbolTable.referenceClass(context.getInternalClass("CoroutineImpl"))
|
val coroutineImpl = symbolTable.referenceClass(context.getInternalClass("CoroutineImpl"))
|
||||||
|
|
||||||
@@ -199,8 +171,6 @@ open class Symbols<out T: CommonBackendContext>(val context: T, private val symb
|
|||||||
val kMutableProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl)
|
val kMutableProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl)
|
||||||
val kMutableProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl)
|
val kMutableProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl)
|
||||||
val kMutableProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl)
|
val kMutableProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl)
|
||||||
val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl)
|
|
||||||
val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl)
|
|
||||||
|
|
||||||
fun getFunction(name: Name, receiverType: KotlinType, vararg argTypes: KotlinType) =
|
fun getFunction(name: Name, receiverType: KotlinType, vararg argTypes: KotlinType) =
|
||||||
symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
||||||
|
|||||||
+69
@@ -21,9 +21,13 @@ import org.jetbrains.kotlin.backend.common.ir.Ir
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
import org.jetbrains.kotlin.backend.konan.ValueType
|
import org.jetbrains.kotlin.backend.konan.ValueType
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
// This is what Context collects about IR.
|
// This is what Context collects about IR.
|
||||||
@@ -65,4 +69,69 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable): Sym
|
|||||||
|
|
||||||
|
|
||||||
val scheduleImpl = symbolTable.referenceSimpleFunction(context.interopBuiltIns.scheduleImplFunction)
|
val scheduleImpl = symbolTable.referenceSimpleFunction(context.interopBuiltIns.scheduleImplFunction)
|
||||||
|
|
||||||
|
val areEqualByValue = context.getInternalFunctions("areEqualByValue").map {
|
||||||
|
symbolTable.referenceSimpleFunction(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val areEqual = symbolTable.referenceSimpleFunction(context.getInternalFunctions("areEqual").single())
|
||||||
|
|
||||||
|
override val ThrowNullPointerException = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("ThrowNullPointerException").single())
|
||||||
|
|
||||||
|
override val ThrowNoWhenBranchMatchedException = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("ThrowNoWhenBranchMatchedException").single())
|
||||||
|
|
||||||
|
override val ThrowTypeCastException = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("ThrowTypeCastException").single())
|
||||||
|
|
||||||
|
override val ThrowUninitializedPropertyAccessException = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("ThrowUninitializedPropertyAccessException").single()
|
||||||
|
)
|
||||||
|
|
||||||
|
override val stringBuilder = symbolTable.referenceClass(
|
||||||
|
builtInsPackage("kotlin", "text").getContributedClassifier(
|
||||||
|
Name.identifier("StringBuilder"), NoLookupLocation.FROM_BACKEND
|
||||||
|
) as ClassDescriptor
|
||||||
|
)
|
||||||
|
|
||||||
|
val checkProgressionStep = context.getInternalFunctions("checkProgressionStep")
|
||||||
|
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
||||||
|
val getProgressionLast = context.getInternalFunctions("getProgressionLast")
|
||||||
|
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
||||||
|
|
||||||
|
val arrayContentToString = arrayTypes.associateBy({ it }, { arrayExtensionFun(it, "contentToString") })
|
||||||
|
val arrayContentHashCode = arrayTypes.associateBy({ it }, { arrayExtensionFun(it, "contentHashCode") })
|
||||||
|
|
||||||
|
override 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 valuesForEnum = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("valuesForEnum").single())
|
||||||
|
|
||||||
|
val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("valueOfForEnum").single())
|
||||||
|
|
||||||
|
val getContinuation = symbolTable.referenceSimpleFunction(
|
||||||
|
context.getInternalFunctions("getContinuation").single())
|
||||||
|
|
||||||
|
override val coroutineImpl = symbolTable.referenceClass(context.getInternalClass("CoroutineImpl"))
|
||||||
|
|
||||||
|
override val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
||||||
|
builtInsPackage("kotlin", "coroutines", "experimental", "intrinsics")
|
||||||
|
.getContributedVariables(Name.identifier("COROUTINE_SUSPENDED"), NoLookupLocation.FROM_BACKEND)
|
||||||
|
.single().getter!!
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl)
|
||||||
|
val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl)
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.backend.common.lower.irBlock
|
|||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
import org.jetbrains.kotlin.backend.jvm.descriptors.initialize
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||||
import org.jetbrains.kotlin.backend.common.ir.createArrayOfExpression
|
import org.jetbrains.kotlin.backend.common.ir.createArrayOfExpression
|
||||||
|
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
@@ -49,7 +50,7 @@ import org.jetbrains.kotlin.types.SimpleType
|
|||||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||||
import org.jetbrains.kotlin.types.replace
|
import org.jetbrains.kotlin.types.replace
|
||||||
|
|
||||||
internal class PropertyDelegationLowering(val context: CommonBackendContext) : FileLoweringPass {
|
internal class PropertyDelegationLowering(val context: KonanBackendContext) : FileLoweringPass {
|
||||||
private val reflectionTypes = context.reflectionTypes
|
private val reflectionTypes = context.reflectionTypes
|
||||||
private var tempIndex = 0
|
private var tempIndex = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user