Gross stdlib cleanup (part 1). (#1918)
This commit is contained in:
+1
-1
@@ -109,7 +109,7 @@ private val cKeywords = setOf(
|
||||
"xor_eq"
|
||||
)
|
||||
|
||||
private val cnameAnnotation = FqName("kotlin.native.internal.CName")
|
||||
private val cnameAnnotation = FqName("kotlin.native.CName")
|
||||
|
||||
private fun org.jetbrains.kotlin.types.KotlinType.isGeneric() =
|
||||
constructor.declarationDescriptor is TypeParameterDescriptor
|
||||
|
||||
+2
-2
@@ -291,8 +291,8 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
val nativePtrPlusLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("plus").single() }
|
||||
val nativePtrToLong by lazy { nativePtr.unsubstitutedMemberScope.getContributedFunctions("toLong").single() }
|
||||
val getNativeNullPtr by lazy { packageScope.getContributedFunctions("getNativeNullPtr").single() }
|
||||
val immutableBinaryBlobOf by lazy {
|
||||
builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope.getContributedFunctions("immutableBinaryBlobOf").single()
|
||||
val immutableBlobOf by lazy {
|
||||
builtIns.builtInsModule.getPackage(KonanFqNames.packageName).memberScope.getContributedFunctions("immutableBlobOf").single()
|
||||
}
|
||||
|
||||
val specialDeclarationsFactory = SpecialDeclarationsFactory(this)
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ internal val arrayTypes = setOf(
|
||||
"kotlin.FloatArray",
|
||||
"kotlin.DoubleArray",
|
||||
"kotlin.BooleanArray",
|
||||
"kotlin.native.ImmutableBinaryBlob"
|
||||
"kotlin.native.ImmutableBlob"
|
||||
)
|
||||
|
||||
|
||||
|
||||
+2
-4
@@ -200,14 +200,12 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
|
||||
it to symbolTable.referenceSimpleFunction(context.getInternalFunctions(name).single())
|
||||
}
|
||||
|
||||
val immutableBinaryBlob = symbolTable.referenceClass(
|
||||
val immutableBlob = symbolTable.referenceClass(
|
||||
builtInsPackage("kotlin", "native").getContributedClassifier(
|
||||
Name.identifier("ImmutableBinaryBlob"), NoLookupLocation.FROM_BACKEND
|
||||
Name.identifier("ImmutableBlob"), NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val immutableBinaryBlobOf = symbolTable.referenceSimpleFunction(context.immutableBinaryBlobOf)
|
||||
|
||||
val scheduleImpl = symbolTable.referenceSimpleFunction(context.interopBuiltIns.scheduleImplFunction)
|
||||
|
||||
val areEqualByValue = context.getInternalFunctions("areEqualByValue").map {
|
||||
|
||||
+3
-9
@@ -69,9 +69,6 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
if (descriptorAnnotations.hasAnnotation(publishedApiAnnotation)){
|
||||
return true
|
||||
}
|
||||
if (descriptorAnnotations.hasAnnotation(inlineExposedAnnotation)){
|
||||
return true
|
||||
}
|
||||
|
||||
if (this.isAnonymousObject)
|
||||
return false
|
||||
@@ -87,8 +84,7 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
// TODO: this code is required because accessor doesn't have a reference to property.
|
||||
if (descriptor is PropertyAccessorDescriptor) {
|
||||
val property = descriptor.correspondingProperty
|
||||
if (property.annotations.hasAnnotation(inlineExposedAnnotation) ||
|
||||
property.annotations.hasAnnotation(publishedApiAnnotation)) return true
|
||||
if (property.annotations.hasAnnotation(publishedApiAnnotation)) return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,16 +115,14 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
|
||||
private val symbolNameAnnotation = FqName("kotlin.native.SymbolName")
|
||||
|
||||
private val exportForCppRuntimeAnnotation = FqName("kotlin.native.internal.ExportForCppRuntime")
|
||||
private val cnameAnnotation = FqName("kotlin.native.CName")
|
||||
|
||||
private val cnameAnnotation = FqName("kotlin.native.internal.CName")
|
||||
private val exportForCppRuntimeAnnotation = FqName("kotlin.native.internal.ExportForCppRuntime")
|
||||
|
||||
private val exportForCompilerAnnotation = FqName("kotlin.native.internal.ExportForCompiler")
|
||||
|
||||
private val publishedApiAnnotation = FqName("kotlin.PublishedApi")
|
||||
|
||||
private val inlineExposedAnnotation = FqName("kotlin.internal.InlineExposed")
|
||||
|
||||
private fun acyclicTypeMangler(visited: MutableSet<TypeParameterDescriptor>, type: IrType): String {
|
||||
val descriptor = (type.classifierOrNull as? IrTypeParameterSymbol)?.owner
|
||||
if (descriptor != null) {
|
||||
|
||||
+2
-2
@@ -1745,10 +1745,10 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
||||
return receiver
|
||||
}
|
||||
|
||||
context.immutableBinaryBlobOf -> {
|
||||
context.immutableBlobOf -> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val arg = expression.getValueArgument(0) as IrConst<String>
|
||||
return context.llvm.staticData.createImmutableBinaryBlob(arg)
|
||||
return context.llvm.staticData.createImmutableBlob(arg)
|
||||
}
|
||||
|
||||
context.ir.symbols.initInstance.descriptor -> {
|
||||
|
||||
+5
-3
@@ -97,11 +97,13 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
staticData.kotlinStringLiteral(string)
|
||||
}
|
||||
|
||||
private val EXPORT_TYPE_INFO_FQ_NAME = FqName.fromSegments(listOf("kotlin", "native", "internal", "ExportTypeInfo"))
|
||||
|
||||
private fun exportTypeInfoIfRequired(classDesc: ClassDescriptor, typeInfoGlobal: LLVMValueRef?) {
|
||||
val annot = classDesc.descriptor.annotations.findAnnotation(FqName("kotlin.native.ExportTypeInfo"))
|
||||
val annot = classDesc.descriptor.annotations.findAnnotation(EXPORT_TYPE_INFO_FQ_NAME)
|
||||
if (annot != null) {
|
||||
val name = getStringValue(annot)!!
|
||||
// TODO: use LLVMAddAlias?
|
||||
// TODO: use LLVMAddAlias.
|
||||
val global = addGlobal(name, pointerType(runtime.typeInfoType), isExported = true)
|
||||
LLVMSetInitializer(global, typeInfoGlobal)
|
||||
}
|
||||
@@ -118,7 +120,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
"kotlin.DoubleArray" to LLVMDoubleType()!!,
|
||||
"kotlin.BooleanArray" to LLVMInt8Type()!!,
|
||||
"kotlin.String" to LLVMInt16Type()!!,
|
||||
"kotlin.native.ImmutableBinaryBlob" to LLVMInt8Type()!!
|
||||
"kotlin.native.ImmutableBlob" to LLVMInt8Type()!!
|
||||
)
|
||||
|
||||
// Keep in sync with Konan_RuntimeType.
|
||||
|
||||
+2
-2
@@ -183,7 +183,7 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
*
|
||||
* @param args data for constant creation.
|
||||
*/
|
||||
internal fun StaticData.createImmutableBinaryBlob(value: IrConst<String>): LLVMValueRef {
|
||||
internal fun StaticData.createImmutableBlob(value: IrConst<String>): LLVMValueRef {
|
||||
val args = value.value.map { Int8(it.toByte()).llvm }
|
||||
return createKotlinArray(context.ir.symbols.immutableBinaryBlob.owner, args)
|
||||
return createKotlinArray(context.ir.symbols.immutableBlob.owner, args)
|
||||
}
|
||||
+2
-2
@@ -107,7 +107,7 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
val argumentDescriptor = descriptor.valueParameters.singleOrNull {
|
||||
cur.getValueArgument(it.index) == argument
|
||||
}
|
||||
if (argumentDescriptor != null && argumentDescriptor.annotations.findAnnotation(FqName("kotlin.native.VolatileLambda")) != null) {
|
||||
if (argumentDescriptor?.annotations?.findAnnotation(VOLATILE_LAMBDA_FQ_NAME) != null) {
|
||||
return expression
|
||||
}
|
||||
break
|
||||
@@ -141,9 +141,9 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
||||
val functionReferenceConstructor: IrConstructor)
|
||||
|
||||
private val COROUTINES_FQ_NAME = FqName.fromSegments(listOf("kotlin", "coroutines", "experimental"))
|
||||
private val VOLATILE_LAMBDA_FQ_NAME = FqName.fromSegments(listOf("kotlin", "native", "internal", "VolatileLambda"))
|
||||
|
||||
private val coroutinesScope = context.irModule!!.descriptor.getPackage(COROUTINES_FQ_NAME).memberScope
|
||||
private val kotlinPackageScope = context.builtIns.builtInsPackageScope
|
||||
|
||||
private val continuationClassDescriptor = coroutinesScope
|
||||
.getContributedClassifier(Name.identifier("Continuation"), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
|
||||
/**
|
||||
* This pass runs after inlining and performs the following additional transformations over some operations:
|
||||
* - Convert immutableBinaryBlobOf() arguments to special IrConst.
|
||||
* - Convert immutableBlobOf() arguments to special IrConst.
|
||||
* - Convert `obj::class` and `Class::class` to calls.
|
||||
*/
|
||||
internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
@@ -77,7 +77,7 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
// Function inlining is changing function symbol at callsite
|
||||
// and unbound symbol replacement is happening later.
|
||||
// So we compare descriptors for now.
|
||||
if (expression.descriptor == context.immutableBinaryBlobOf) {
|
||||
if (expression.descriptor == context.immutableBlobOf) {
|
||||
// Convert arguments of the binary blob to special IrConst<String> structure, so that
|
||||
// vararg lowering will not affect it.
|
||||
val args = expression.getValueArgument(0) as? IrVararg
|
||||
@@ -105,7 +105,7 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass {
|
||||
}
|
||||
expression.putValueArgument(0, IrConstImpl<String>(
|
||||
expression.startOffset, expression.endOffset,
|
||||
context.ir.symbols.immutableBinaryBlob.typeWithoutArguments,
|
||||
context.ir.symbols.immutableBlob.typeWithoutArguments,
|
||||
IrConstKind.String, builder.toString()))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -456,7 +456,7 @@ internal object DataFlowIR {
|
||||
|
||||
private val NAME_ESCAPES = Name.identifier("Escapes")
|
||||
private val NAME_POINTS_TO = Name.identifier("PointsTo")
|
||||
private val FQ_NAME_KONAN = FqName.fromSegments(listOf("kotlin", "native"))
|
||||
private val FQ_NAME_KONAN = FqName.fromSegments(listOf("kotlin", "native", "internal"))
|
||||
|
||||
private val FQ_NAME_ESCAPES = FQ_NAME_KONAN.child(NAME_ESCAPES)
|
||||
private val FQ_NAME_POINTS_TO = FQ_NAME_KONAN.child(NAME_POINTS_TO)
|
||||
|
||||
-5
@@ -131,9 +131,6 @@ internal tailrec fun DeclarationDescriptor.isExported(): Boolean {
|
||||
if (this.annotations.hasAnnotation(publishedApiAnnotation)){
|
||||
return true
|
||||
}
|
||||
if (this.annotations.hasAnnotation(inlineExposedAnnotation)){
|
||||
return true
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isAnonymousObject(this))
|
||||
return false
|
||||
@@ -172,8 +169,6 @@ private val exportForCompilerAnnotation = FqName("kotlin.native.internal.ExportF
|
||||
|
||||
private val publishedApiAnnotation = FqName("kotlin.PublishedApi")
|
||||
|
||||
private val inlineExposedAnnotation = FqName("kotlin.internal.InlineExposed")
|
||||
|
||||
private fun acyclicTypeMangler(visited: MutableSet<TypeParameterDescriptor>, type: KotlinType): String {
|
||||
val descriptor = TypeUtils.getTypeParameterDescriptorOrNull(type)
|
||||
if (descriptor != null) {
|
||||
|
||||
@@ -1481,7 +1481,7 @@ task if_else(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
task immutable_binary_blob_in_lambda(type: RunKonanTest) {
|
||||
source = "lower/immutable_binary_blob_in_lambda.kt"
|
||||
source = "lower/immutable_blob_in_lambda.kt"
|
||||
goldValue = "123\n"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import platform.posix.printf
|
||||
|
||||
val golden = immutableBinaryBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer(0)
|
||||
val golden = immutableBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer(0)
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
printf("%s\n", golden)
|
||||
|
||||
@@ -2,8 +2,8 @@ import kotlinx.cinterop.*
|
||||
|
||||
import platform.zlib.*
|
||||
|
||||
val source = immutableBinaryBlobOf(0xF3, 0x48, 0xCD, 0xC9, 0xC9, 0x57, 0x04, 0x00).asCPointer()
|
||||
val golden = immutableBinaryBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer()
|
||||
val source = immutableBlobOf(0xF3, 0x48, 0xCD, 0xC9, 0xC9, 0x57, 0x04, 0x00).asCPointer()
|
||||
val golden = immutableBlobOf(0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x21, 0x00).asCPointer()
|
||||
|
||||
fun main(args: Array<String>) = memScoped {
|
||||
val buffer = ByteArray(32)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package lower.immutable_binary_blob_in_lambda
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() = run {
|
||||
val golden = immutableBinaryBlobOf(123)
|
||||
println(golden[0])
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package lower.immutable_blob_in_lambda
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun runTest() = run {
|
||||
val golden = immutableBlobOf(123)
|
||||
println(golden[0])
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
import kotlin.native.CName
|
||||
|
||||
// Top level functions.
|
||||
fun hello() {
|
||||
println("Hello, dynamic!")
|
||||
@@ -13,15 +15,15 @@ open class Base {
|
||||
|
||||
open fun fooParam(arg0: String, arg1: Int) = println("Base.fooParam: $arg0 $arg1")
|
||||
|
||||
@kotlin.native.internal.CName(fullName = "", shortName = "strangeName") fun странноеИмя() = 111
|
||||
@CName(fullName = "", shortName = "strangeName") fun странноеИмя() = 111
|
||||
|
||||
}
|
||||
|
||||
// Top level functions.
|
||||
@kotlin.native.internal.CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort")
|
||||
@CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort")
|
||||
fun topLevelFunction(x1: Int, x2: Int) = x1 - x2
|
||||
|
||||
@kotlin.native.internal.CName("topLevelFunctionVoidFromC")
|
||||
@CName("topLevelFunctionVoidFromC")
|
||||
fun topLevelFunctionVoid(x1: Int, pointer: COpaquePointer?) {
|
||||
assert(x1 == 42)
|
||||
assert(pointer == null)
|
||||
|
||||
@@ -5,7 +5,7 @@ import kotlin.test.*
|
||||
import kotlin.native.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val data = immutableBinaryBlobOf(0x1, 0x2, 0x3, 0x7, 0x8, 0x9, 0x80, 0xff)
|
||||
val data = immutableBlobOf(0x1, 0x2, 0x3, 0x7, 0x8, 0x9, 0x80, 0xff)
|
||||
for (b in data) {
|
||||
print("$b ")
|
||||
}
|
||||
|
||||
@@ -10,5 +10,10 @@ import kotlin.test.*
|
||||
expect(0xdef0.toInt()) { array.charAt(5).toInt() }
|
||||
expect(0x9abc.toShort()) { array.shortAt(7) }
|
||||
expect(0x1234_5678) { array.intAt(9) }
|
||||
expect(0xdef0_0000u) { array.uintAt(3) }
|
||||
expect(0xf0_00u) { array.ushortAt(4) }
|
||||
expect(0xf0u) { array.ubyteAt(5) }
|
||||
expect(0x1234_5678_9abcuL) { array.ulongAt(7) }
|
||||
|
||||
println("OK")
|
||||
}
|
||||
Reference in New Issue
Block a user