From d222e958775c04fd8d31197231457545a51f9f81 Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Tue, 13 Jul 2021 12:09:17 +0300 Subject: [PATCH] [K/N] Remove unused old buggy intrinsic --- .../backend/konan/KonanLoweringPhases.kt | 7 --- .../kotlin/backend/konan/ToplevelPhases.kt | 2 - .../jetbrains/kotlin/backend/konan/ir/Ir.kt | 2 - .../backend/konan/llvm/IntrinsicGenerator.kt | 17 ------- .../backend/konan/llvm/StaticObjects.kt | 22 -------- .../lower/CompileTimeEvaluateLowering.kt | 50 ------------------- .../kotlin/native/internal/IntrinsicType.kt | 1 - .../kotlin/native/internal/RuntimeUtils.kt | 9 ---- 8 files changed, 110 deletions(-) delete mode 100644 kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CompileTimeEvaluateLowering.kt diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt index 62ffd6249ec..e0bf3acf994 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt @@ -363,13 +363,6 @@ internal val varargPhase = makeKonanFileLoweringPhase( prerequisite = setOf(functionReferencePhase, defaultParameterExtentPhase, interopPhase, functionsWithoutBoundCheck) ) -internal val compileTimeEvaluatePhase = makeKonanFileLoweringPhase( - ::CompileTimeEvaluateLowering, - name = "CompileTimeEvaluate", - description = "Compile time evaluation lowering", - prerequisite = setOf(varargPhase) -) - internal val coroutinesPhase = makeKonanFileLoweringPhase( ::NativeSuspendFunctionsLowering, name = "Coroutines", diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index dde62f9f145..719d0c944b9 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -290,7 +290,6 @@ internal val allLoweringsPhase = NamedCompilerPhase( enumUsagePhase, interopPhase, varargPhase, - compileTimeEvaluatePhase, kotlinNothingValueExceptionPhase, coroutinesPhase, typeOperatorPhase, @@ -510,7 +509,6 @@ internal fun PhaseConfig.disableUnless(phase: AnyNamedPhase, condition: Boolean) internal fun PhaseConfig.konanPhasesConfig(config: KonanConfig) { with(config.configuration) { - disable(compileTimeEvaluatePhase) disable(localEscapeAnalysisPhase) // Don't serialize anything to a final executable. diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index 1d53348b77a..7e28f713436 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -483,8 +483,6 @@ internal class KonanSymbols( val listOf = irBuiltIns.findFunctions(Name.identifier("listOf"), "kotlin", "collections") .single { it.descriptor.valueParameters.size == 1 && it.descriptor.valueParameters[0].isVararg } - val listOfInternal = internalFunction("listOfInternal") - val threadLocal = symbolTable.referenceClass( context.builtIns.builtInsModule.findClassAcrossModuleDependencies( ClassId.topLevel(KonanFqNames.threadLocal))!!) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt index 03d34812b25..c6684a249df 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt @@ -63,7 +63,6 @@ internal enum class IntrinsicType { // Other GET_CLASS_TYPE_INFO, CREATE_UNINITIALIZED_INSTANCE, - LIST_OF_INTERNAL, IDENTITY, IMMUTABLE_BLOB, INIT_INSTANCE, @@ -253,7 +252,6 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv IntrinsicType.INTEROP_NATIVE_PTR_TO_LONG -> emitNativePtrToLong(callSite, args) IntrinsicType.INTEROP_NATIVE_PTR_PLUS_LONG -> emitNativePtrPlusLong(args) IntrinsicType.INTEROP_GET_NATIVE_NULL_PTR -> emitGetNativeNullPtr() - IntrinsicType.LIST_OF_INTERNAL -> emitListOfInternal(callSite, args) IntrinsicType.IDENTITY -> emitIdentity(args) IntrinsicType.GET_CONTINUATION -> emitGetContinuation() IntrinsicType.INTEROP_MEMORY_COPY -> emitMemoryCopy(callSite, args) @@ -310,21 +308,6 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv private fun FunctionGenerationContext.emitIsExperimentalMM(): LLVMValueRef = Int1(context.memoryModel == MemoryModel.EXPERIMENTAL).llvm - private fun FunctionGenerationContext.emitListOfInternal(callSite: IrCall, args: List): LLVMValueRef { - val varargExpression = callSite.getValueArgument(0) as IrVararg - val vararg = args.single() - - val length = varargExpression.elements.size - // TODO: store length in `vararg` itself when more abstract types will be used for values. - - val array = constPointer(vararg) - // Note: dirty hack here: `vararg` has type `Array`, but `createConstArrayList` expects `Array`; - // however `vararg` is immutable, and in current implementation it has type `Array`, - // so let's ignore this mismatch currently for simplicity. - - return context.llvm.staticData.createConstArrayList(array, length).llvm - } - private fun FunctionGenerationContext.emitGetNativeNullPtr(): LLVMValueRef = kNullInt8Ptr diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticObjects.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticObjects.kt index 28a956c29d8..c6f2bdb2bfa 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticObjects.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticObjects.kt @@ -75,28 +75,6 @@ internal fun StaticData.createConstKotlinObject(type: IrClass, vararg fields: Co internal fun StaticData.createInitializer(type: IrClass, vararg fields: ConstValue): ConstValue = Struct(objHeader(type.typeInfoPtr), *fields) -/** - * Creates static instance of `kotlin.collections.ArrayList` with given values of fields. - * - * @param array value for `array: Array` field. - * @param length value for `length: Int` field. - */ -internal fun StaticData.createConstArrayList(array: ConstPointer, length: Int): ConstPointer { - val arrayListClass = context.ir.symbols.arrayList.owner - - val arrayListFields = mapOf( - "array" to array, - "offset" to Int32(0), - "length" to Int32(length), - "backing" to NullPointer(kObjHeader)) - - // Now sort these values according to the order of fields returned by getFields() - // to match the sorting order of the real ArrayList(). - val sorted = context.getLayoutBuilder(arrayListClass).fields.map { arrayListFields[it.name]!! } - - return createConstKotlinObject(arrayListClass, *sorted.toTypedArray()) -} - internal fun StaticData.createUniqueInstance( kind: UniqueKind, bodyType: LLVMTypeRef, typeInfo: ConstPointer): ConstPointer { assert (getStructElements(bodyType).size == 1) // ObjHeader only. diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CompileTimeEvaluateLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CompileTimeEvaluateLowering.kt deleted file mode 100644 index a4648eb2f1e..00000000000 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CompileTimeEvaluateLowering.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package org.jetbrains.kotlin.backend.konan.lower - -import org.jetbrains.kotlin.backend.common.FileLoweringPass -import org.jetbrains.kotlin.backend.common.lower.IrBuildingTransformer -import org.jetbrains.kotlin.backend.common.lower.at -import org.jetbrains.kotlin.backend.konan.Context -import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.types.isString -import org.jetbrains.kotlin.ir.util.fqNameForIrSerialization -import org.jetbrains.kotlin.ir.util.irCall -import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid - -internal class CompileTimeEvaluateLowering(val context: Context): FileLoweringPass { - - override fun lower(irFile: IrFile) { - irFile.transformChildrenVoid(object: IrBuildingTransformer(context) { - override fun visitCall(expression: IrCall): IrExpression { - expression.transformChildrenVoid(this) - - val callee = expression.symbol.owner - // TODO - if (callee.fqNameForIrSerialization.asString() != "kotlin.collections.listOf" || callee.valueParameters.size != 1) - return expression - val elementsArr = expression.getValueArgument(0) as? IrVararg - ?: return expression - - // The function is kotlin.collections.listOf(vararg args: T). - // TODO: refer functions more reliably. - - if (elementsArr.elements.any { it is IrSpreadElement } - || !elementsArr.elements.all { it is IrConst<*> && it.type.isString() }) - return expression - - - builder.at(expression) - - val typeArgument = expression.getTypeArgument(0)!! - return builder.irCall(context.ir.symbols.listOfInternal.owner, listOf(typeArgument)).apply { - putValueArgument(0, elementsArr) - } - } - }) - } -} \ No newline at end of file diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/IntrinsicType.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/IntrinsicType.kt index 116a80bd41f..4fc12f916ae 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/IntrinsicType.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/IntrinsicType.kt @@ -50,7 +50,6 @@ class IntrinsicType { const val INTEROP_READ_BITS = "INTEROP_READ_BITS" const val INTEROP_WRITE_BITS = "INTEROP_WRITE_BITS" const val CREATE_UNINITIALIZED_INSTANCE = "CREATE_UNINITIALIZED_INSTANCE" - const val LIST_OF_INTERNAL = "LIST_OF_INTERNAL" const val IDENTITY = "IDENTITY" const val IMMUTABLE_BLOB = "IMMUTABLE_BLOB" const val INIT_INSTANCE = "INIT_INSTANCE" diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt index fa808818aca..558b479be8b 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt @@ -231,12 +231,3 @@ internal fun KonanObjectToUtf8Array(value: Any?): ByteArray { } return string.encodeToByteArray() } - -@TypedIntrinsic(IntrinsicType.LIST_OF_INTERNAL) -@PublishedApi -internal fun listOfInternal(vararg elements: T): List { - val result = ArrayList(elements.size) - for (i in 0 until elements.size) - result.add(elements[i]) - return result -}