Moved TestsProcessor down along the pipeline

This commit is contained in:
Igor Chevdar
2019-01-25 16:52:13 +03:00
parent 68530bf28b
commit 6bf88646cc
4 changed files with 22 additions and 29 deletions
@@ -42,10 +42,6 @@ internal class KonanLower(val context: Context, val parentPhaser: PhaseManager)
irModule.files.forEach(ExpectDeclarationsRemoving(context)::lower) irModule.files.forEach(ExpectDeclarationsRemoving(context)::lower)
} }
phaser.phase(KonanPhase.TEST_PROCESSOR) {
TestProcessor(context).process(irModule)
}
phaser.phase(KonanPhase.LOWER_BEFORE_INLINE) { phaser.phase(KonanPhase.LOWER_BEFORE_INLINE) {
irModule.files.forEach(PreInlineLowering(context)::lower) 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) { phaser.phase(KonanPhase.LOWER_INNER_CLASSES) {
InnerClassLowering(context).runOnFilePostfix(irFile) InnerClassLowering(context).runOnFilePostfix(irFile)
} }
phaser.phase(KonanPhase.TEST_PROCESSOR) {
TestProcessor(context).process(irFile)
}
phaser.phase(KonanPhase.LOWER_ENUMS) { phaser.phase(KonanPhase.LOWER_ENUMS) {
EnumClassLowering(context).run(irFile) EnumClassLowering(context).run(irFile)
} }
@@ -30,12 +30,12 @@ enum class KonanPhase(val description: String,
/* ... ... */ LOWER_INTEROP_PART1("Interop lowering, part 1", LOWER_INLINE), /* ... ... */ LOWER_INTEROP_PART1("Interop lowering, part 1", LOWER_INLINE),
/* ... ... */ LOWER_FOR_LOOPS("For loops lowering"), /* ... ... */ LOWER_FOR_LOOPS("For loops lowering"),
/* ... ... */ LOWER_ENUM_CONSTRUCTORS("Enum constructors 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_DELEGATION("Delegation lowering"),
/* ... ... */ LOWER_INITIALIZERS("Initializers lowering", LOWER_ENUM_CONSTRUCTORS), /* ... ... */ LOWER_INITIALIZERS("Initializers lowering", LOWER_ENUM_CONSTRUCTORS),
/* ... ... */ LOWER_LATEINIT("Lateinit properties lowering", LOWER_INLINE), /* ... ... */ LOWER_LATEINIT("Lateinit properties lowering", LOWER_INLINE),
/* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering", LOWER_INITIALIZERS), /* ... ... */ 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_LOCAL_FUNCTIONS("Local Function Lowering", LOWER_SHARED_VARIABLES, LOWER_CALLABLES),
/* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS), /* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS),
/* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS), /* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS),
@@ -509,11 +509,6 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
Name.identifier(className), NoLookupLocation.FROM_BACKEND Name.identifier(className), NoLookupLocation.FROM_BACKEND
) as ClassDescriptor) ) 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) val functions = (0 .. KONAN_FUNCTION_INTERFACES_MAX_PARAMETERS)
.map { symbolTable.referenceClass(builtIns.getFunction(it)) } .map { symbolTable.referenceClass(builtIns.getFunction(it)) }
@@ -532,12 +527,17 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val
val topLevelSuite = getKonanTestClass("TopLevelSuite") val topLevelSuite = getKonanTestClass("TopLevelSuite")
val testFunctionKind = getKonanTestClass("TestFunctionKind") val testFunctionKind = getKonanTestClass("TestFunctionKind")
private val testFunctionKindCache = mutableMapOf<TestProcessor.FunctionKind, IrEnumEntrySymbol>() private val testFunctionKindCache = TestProcessor.FunctionKind.values().associate {
fun getTestFunctionKind(kind: TestProcessor.FunctionKind): IrEnumEntrySymbol = testFunctionKindCache.getOrPut(kind) { val symbol = if (it.runtimeKindString.isEmpty())
symbolTable.referenceEnumEntry(testFunctionKind.descriptor.unsubstitutedMemberScope.getContributedClassifier( null
kind.runtimeKindName, NoLookupLocation.FROM_BACKEND else
) as ClassDescriptor) 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 { private fun getArrayListClassDescriptor(context: Context): ClassDescriptor {
@@ -136,18 +136,14 @@ internal class TestProcessor (val context: KonanBackendContext) {
// endregion // endregion
// region Classes for annotation collection. // region Classes for annotation collection.
internal enum class FunctionKind(annotationNameString: String, runtimeKindString: String) { internal enum class FunctionKind(annotationNameString: String, val runtimeKindString: String) {
TEST("kotlin.test.Test", "") { TEST("kotlin.test.Test", ""),
override val runtimeKindName: Name get() = throw NotImplementedError()
},
BEFORE_TEST("kotlin.test.BeforeTest", "BEFORE_TEST"), BEFORE_TEST("kotlin.test.BeforeTest", "BEFORE_TEST"),
AFTER_TEST("kotlin.test.AfterTest", "AFTER_TEST"), AFTER_TEST("kotlin.test.AfterTest", "AFTER_TEST"),
BEFORE_CLASS("kotlin.test.BeforeClass", "BEFORE_CLASS"), BEFORE_CLASS("kotlin.test.BeforeClass", "BEFORE_CLASS"),
AFTER_CLASS("kotlin.test.AfterClass", "AFTER_CLASS"); AFTER_CLASS("kotlin.test.AfterClass", "AFTER_CLASS");
val annotationFqName = FqName(annotationNameString) val annotationFqName = FqName(annotationNameString)
open val runtimeKindName = Name.identifier(runtimeKindString)
companion object { companion object {
val INSTANCE_KINDS = listOf(TEST, BEFORE_TEST, AFTER_TEST) val INSTANCE_KINDS = listOf(TEST, BEFORE_TEST, AFTER_TEST)
@@ -604,11 +600,9 @@ internal class TestProcessor (val context: KonanBackendContext) {
} }
// endregion // endregion
fun process(irModuleFragment: IrModuleFragment) { fun process(irFile: IrFile) {
irModuleFragment.files.forEach { val annotationCollector = AnnotationCollector(irFile)
val annotationCollector = AnnotationCollector(it) irFile.acceptChildrenVoid(annotationCollector)
it.acceptChildrenVoid(annotationCollector) createTestSuites(irFile, annotationCollector)
createTestSuites(it, annotationCollector)
}
} }
} }