diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt index e89f6b66f07..4f406f3266d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLower.kt @@ -42,10 +42,6 @@ internal class KonanLower(val context: Context, val parentPhaser: PhaseManager) irModule.files.forEach(ExpectDeclarationsRemoving(context)::lower) } - phaser.phase(KonanPhase.TEST_PROCESSOR) { - TestProcessor(context).process(irModule) - } - phaser.phase(KonanPhase.LOWER_BEFORE_INLINE) { irModule.files.forEach(PreInlineLowering(context)::lower) } @@ -117,6 +113,9 @@ internal class KonanLower(val context: Context, val parentPhaser: PhaseManager) phaser.phase(KonanPhase.LOWER_INNER_CLASSES) { InnerClassLowering(context).runOnFilePostfix(irFile) } + phaser.phase(KonanPhase.TEST_PROCESSOR) { + TestProcessor(context).process(irFile) + } phaser.phase(KonanPhase.LOWER_ENUMS) { EnumClassLowering(context).run(irFile) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt index 6a32352dac1..d26efd62271 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPhases.kt @@ -30,12 +30,12 @@ enum class KonanPhase(val description: String, /* ... ... */ LOWER_INTEROP_PART1("Interop lowering, part 1", LOWER_INLINE), /* ... ... */ LOWER_FOR_LOOPS("For loops lowering"), /* ... ... */ LOWER_ENUM_CONSTRUCTORS("Enum constructors lowering"), - /* ... ... */ LOWER_ENUMS("Enum classes lowering", LOWER_ENUM_CONSTRUCTORS), + /* ... ... */ LOWER_ENUMS("Enum classes lowering", LOWER_ENUM_CONSTRUCTORS/*TODO: make weak dependence on TEST_PROCESSOR*/), /* ... ... */ LOWER_DELEGATION("Delegation lowering"), /* ... ... */ LOWER_INITIALIZERS("Initializers lowering", LOWER_ENUM_CONSTRUCTORS), /* ... ... */ LOWER_LATEINIT("Lateinit properties lowering", LOWER_INLINE), /* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering", LOWER_INITIALIZERS), - /* ... ... */ LOWER_CALLABLES("Callable references Lowering", LOWER_DELEGATION), + /* ... ... */ LOWER_CALLABLES("Callable references Lowering", LOWER_DELEGATION/*TODO: make weak dependence on TEST_PROCESSOR*/), /* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering", LOWER_SHARED_VARIABLES, LOWER_CALLABLES), /* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS), /* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS), diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index 3c504cf3640..6177e6acfe2 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -509,11 +509,6 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val Name.identifier(className), NoLookupLocation.FROM_BACKEND ) as ClassDescriptor) - private fun getFunction(name: Name, receiverType: KotlinType, predicate: (FunctionDescriptor) -> Boolean) = - symbolTable.referenceFunction(receiverType.memberScope - .getContributedFunctions(name, NoLookupLocation.FROM_BACKEND).single(predicate) - ) - val functions = (0 .. KONAN_FUNCTION_INTERFACES_MAX_PARAMETERS) .map { symbolTable.referenceClass(builtIns.getFunction(it)) } @@ -532,12 +527,17 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val val topLevelSuite = getKonanTestClass("TopLevelSuite") val testFunctionKind = getKonanTestClass("TestFunctionKind") - private val testFunctionKindCache = mutableMapOf() - fun getTestFunctionKind(kind: TestProcessor.FunctionKind): IrEnumEntrySymbol = testFunctionKindCache.getOrPut(kind) { - symbolTable.referenceEnumEntry(testFunctionKind.descriptor.unsubstitutedMemberScope.getContributedClassifier( - kind.runtimeKindName, NoLookupLocation.FROM_BACKEND - ) as ClassDescriptor) + private val testFunctionKindCache = TestProcessor.FunctionKind.values().associate { + val symbol = if (it.runtimeKindString.isEmpty()) + null + else + symbolTable.referenceEnumEntry(testFunctionKind.descriptor.unsubstitutedMemberScope.getContributedClassifier( + Name.identifier(it.runtimeKindString), NoLookupLocation.FROM_BACKEND + ) as ClassDescriptor) + it to symbol } + + fun getTestFunctionKind(kind: TestProcessor.FunctionKind) = testFunctionKindCache[kind]!! } private fun getArrayListClassDescriptor(context: Context): ClassDescriptor { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index fb195c7462b..77aa1fef287 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -136,18 +136,14 @@ internal class TestProcessor (val context: KonanBackendContext) { // endregion // region Classes for annotation collection. - internal enum class FunctionKind(annotationNameString: String, runtimeKindString: String) { - TEST("kotlin.test.Test", "") { - override val runtimeKindName: Name get() = throw NotImplementedError() - }, - + internal enum class FunctionKind(annotationNameString: String, val runtimeKindString: String) { + TEST("kotlin.test.Test", ""), BEFORE_TEST("kotlin.test.BeforeTest", "BEFORE_TEST"), AFTER_TEST("kotlin.test.AfterTest", "AFTER_TEST"), BEFORE_CLASS("kotlin.test.BeforeClass", "BEFORE_CLASS"), AFTER_CLASS("kotlin.test.AfterClass", "AFTER_CLASS"); val annotationFqName = FqName(annotationNameString) - open val runtimeKindName = Name.identifier(runtimeKindString) companion object { val INSTANCE_KINDS = listOf(TEST, BEFORE_TEST, AFTER_TEST) @@ -604,11 +600,9 @@ internal class TestProcessor (val context: KonanBackendContext) { } // endregion - fun process(irModuleFragment: IrModuleFragment) { - irModuleFragment.files.forEach { - val annotationCollector = AnnotationCollector(it) - it.acceptChildrenVoid(annotationCollector) - createTestSuites(it, annotationCollector) - } + fun process(irFile: IrFile) { + val annotationCollector = AnnotationCollector(irFile) + irFile.acceptChildrenVoid(annotationCollector) + createTestSuites(irFile, annotationCollector) } -} +} \ No newline at end of file