Add DiagnosticsTest testData based smoke test for FIR #KT-29962 Fixed
Yet seven of these tests fail with an exception in RawFirBuilder
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0d976a4870
commit
e056882aa6
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
||||
import org.jetbrains.kotlin.fir.java.FirLibrarySession
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractFirDiagnosticsSmokeTest : BaseDiagnosticsTest() {
|
||||
override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) {
|
||||
try {
|
||||
analyzeAndCheckUnhandled(files)
|
||||
} catch (t: AssertionError) {
|
||||
throw t
|
||||
} catch (t: Throwable) {
|
||||
throw t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun createEnvironment(file: File): KotlinCoreEnvironment {
|
||||
return super.createEnvironment(file).apply {
|
||||
Extensions.getArea(this.project)
|
||||
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||
.unregisterExtension(JavaElementFinder::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private fun analyzeAndCheckUnhandled(files: List<TestFile>) {
|
||||
|
||||
val groupedByModule = files.groupBy(TestFile::module)
|
||||
|
||||
val modules = createModules(groupedByModule)
|
||||
|
||||
val sessionProvider = FirProjectSessionProvider(project)
|
||||
|
||||
//For BuiltIns, registered in sessionProvider automatically
|
||||
FirLibrarySession(builtInsModuleInfo, sessionProvider, GlobalSearchScope.EMPTY_SCOPE)
|
||||
|
||||
val configToSession = modules.mapValues { (config, info) ->
|
||||
val moduleFiles = groupedByModule.getValue(config)
|
||||
val scope = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, moduleFiles.mapNotNull { it.ktFile })
|
||||
FirJavaModuleBasedSession(info, sessionProvider, scope)
|
||||
}
|
||||
|
||||
val firFiles = mutableListOf<FirFile>()
|
||||
|
||||
for ((testModule, testFilesInModule) in groupedByModule) {
|
||||
val ktFiles = getKtFiles(testFilesInModule, true)
|
||||
|
||||
val session = configToSession.getValue(testModule)
|
||||
|
||||
|
||||
val firBuilder = RawFirBuilder(session, false)
|
||||
|
||||
ktFiles.mapTo(firFiles) {
|
||||
val firFile = firBuilder.buildFirFile(it)
|
||||
|
||||
(session.service<FirProvider>() as FirProviderImpl).recordFile(firFile)
|
||||
|
||||
firFile
|
||||
}
|
||||
}
|
||||
|
||||
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false)
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun createModules(
|
||||
groupedByModule: Map<TestModule?, List<TestFile>>
|
||||
): MutableMap<TestModule?, ModuleInfo> {
|
||||
val modules = HashMap<TestModule?, ModuleInfo>()
|
||||
|
||||
for (testModule in groupedByModule.keys) {
|
||||
val module = if (testModule == null)
|
||||
createSealedModule()
|
||||
else
|
||||
createModule(testModule.name)
|
||||
|
||||
modules[testModule] = module
|
||||
}
|
||||
|
||||
for (testModule in groupedByModule.keys) {
|
||||
if (testModule == null) continue
|
||||
|
||||
val module = modules[testModule]!!
|
||||
val dependencies = ArrayList<ModuleInfo>()
|
||||
dependencies.add(module)
|
||||
for (dependency in testModule.getDependencies()) {
|
||||
dependencies.add(modules[dependency]!!)
|
||||
}
|
||||
|
||||
|
||||
dependencies.add(builtInsModuleInfo)
|
||||
//dependencies.addAll(getAdditionalDependencies(module))
|
||||
(module as TestModuleInfo).dependencies.addAll(dependencies)
|
||||
}
|
||||
|
||||
return modules
|
||||
}
|
||||
|
||||
private val builtInsModuleInfo = BuiltInModuleInfo(Name.special("<built-ins>"))
|
||||
|
||||
protected open fun createModule(moduleName: String): TestModuleInfo {
|
||||
val nameSuffix = moduleName.substringAfterLast("-", "")
|
||||
// TODO: use platform
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val platform =
|
||||
when {
|
||||
nameSuffix.isEmpty() -> null
|
||||
nameSuffix == "common" -> MultiTargetPlatform.Common
|
||||
else -> MultiTargetPlatform.Specific(nameSuffix.toUpperCase())
|
||||
}
|
||||
return TestModuleInfo(Name.special("<$moduleName>"))
|
||||
}
|
||||
|
||||
class BuiltInModuleInfo(override val name: Name) : ModuleInfo {
|
||||
override val platform: TargetPlatform?
|
||||
get() = JvmPlatform
|
||||
|
||||
override fun dependencies(): List<ModuleInfo> {
|
||||
return listOf(this)
|
||||
}
|
||||
}
|
||||
|
||||
protected class TestModuleInfo(override val name: Name) : ModuleInfo {
|
||||
override val platform: TargetPlatform?
|
||||
get() = JvmPlatform
|
||||
|
||||
val dependencies = mutableListOf<ModuleInfo>(this)
|
||||
override fun dependencies(): List<ModuleInfo> {
|
||||
return dependencies
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun createSealedModule(): TestModuleInfo =
|
||||
createModule("test-module").apply {
|
||||
dependencies += builtInsModuleInfo
|
||||
}
|
||||
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.checkers.BaseDiagnosticsTest
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
||||
import org.jetbrains.kotlin.fir.java.FirLibrarySession
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractFirDiagnosticsSmokeTest : BaseDiagnosticsTest() {
|
||||
override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) {
|
||||
try {
|
||||
analyzeAndCheckUnhandled(files)
|
||||
} catch (t: AssertionError) {
|
||||
throw t
|
||||
} catch (t: Throwable) {
|
||||
throw t
|
||||
}
|
||||
}
|
||||
|
||||
private fun analyzeAndCheckUnhandled(files: List<TestFile>) {
|
||||
|
||||
val groupedByModule = files.groupBy(TestFile::module)
|
||||
|
||||
val modules = createModules(groupedByModule)
|
||||
|
||||
val sessionProvider = FirProjectSessionProvider(project)
|
||||
|
||||
//For BuiltIns, registered in sessionProvider automatically
|
||||
FirLibrarySession(builtInsModuleInfo, sessionProvider, GlobalSearchScope.EMPTY_SCOPE)
|
||||
|
||||
val configToSession = modules.mapValues { (config, info) ->
|
||||
val moduleFiles = groupedByModule.getValue(config)
|
||||
val scope = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, moduleFiles.mapNotNull { it.ktFile })
|
||||
FirJavaModuleBasedSession(info, sessionProvider, scope)
|
||||
}
|
||||
|
||||
val firFiles = mutableListOf<FirFile>()
|
||||
|
||||
for ((testModule, testFilesInModule) in groupedByModule) {
|
||||
val ktFiles = getKtFiles(testFilesInModule, true)
|
||||
|
||||
val session = configToSession.getValue(testModule)
|
||||
|
||||
|
||||
val firBuilder = RawFirBuilder(session, false)
|
||||
|
||||
ktFiles.mapTo(firFiles) {
|
||||
val firFile = firBuilder.buildFirFile(it)
|
||||
|
||||
(session.service<FirProvider>() as FirProviderImpl).recordFile(firFile)
|
||||
|
||||
firFile
|
||||
}
|
||||
}
|
||||
|
||||
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, gc = false)
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun createModules(
|
||||
groupedByModule: Map<TestModule?, List<TestFile>>
|
||||
): MutableMap<TestModule?, ModuleInfo> {
|
||||
val modules = HashMap<TestModule?, ModuleInfo>()
|
||||
|
||||
for (testModule in groupedByModule.keys) {
|
||||
val module = if (testModule == null)
|
||||
createSealedModule()
|
||||
else
|
||||
createModule(testModule.name)
|
||||
|
||||
modules[testModule] = module
|
||||
}
|
||||
|
||||
for (testModule in groupedByModule.keys) {
|
||||
if (testModule == null) continue
|
||||
|
||||
val module = modules[testModule]!!
|
||||
val dependencies = ArrayList<ModuleInfo>()
|
||||
dependencies.add(module)
|
||||
for (dependency in testModule.getDependencies()) {
|
||||
dependencies.add(modules[dependency]!!)
|
||||
}
|
||||
|
||||
|
||||
dependencies.add(builtInsModuleInfo)
|
||||
//dependencies.addAll(getAdditionalDependencies(module))
|
||||
(module as TestModuleInfo).dependencies.addAll(dependencies)
|
||||
}
|
||||
|
||||
return modules
|
||||
}
|
||||
|
||||
private val builtInsModuleInfo = BuiltInModuleInfo(Name.special("<built-ins>"))
|
||||
|
||||
protected open fun createModule(moduleName: String): TestModuleInfo {
|
||||
val nameSuffix = moduleName.substringAfterLast("-", "")
|
||||
// TODO: use platform
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
val platform =
|
||||
when {
|
||||
nameSuffix.isEmpty() -> null
|
||||
nameSuffix == "common" -> MultiTargetPlatform.Common
|
||||
else -> MultiTargetPlatform.Specific(nameSuffix.toUpperCase())
|
||||
}
|
||||
return TestModuleInfo(Name.special("<$moduleName>"))
|
||||
}
|
||||
|
||||
class BuiltInModuleInfo(override val name: Name) : ModuleInfo {
|
||||
override val platform: TargetPlatform?
|
||||
get() = JvmPlatform
|
||||
|
||||
override fun dependencies(): List<ModuleInfo> {
|
||||
return listOf(this)
|
||||
}
|
||||
}
|
||||
|
||||
protected class TestModuleInfo(override val name: Name) : ModuleInfo {
|
||||
override val platform: TargetPlatform?
|
||||
get() = JvmPlatform
|
||||
|
||||
val dependencies = mutableListOf<ModuleInfo>(this)
|
||||
override fun dependencies(): List<ModuleInfo> {
|
||||
return dependencies
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun createSealedModule(): TestModuleInfo =
|
||||
createModule("test-module").apply {
|
||||
dependencies += builtInsModuleInfo
|
||||
}
|
||||
|
||||
}
|
||||
+23305
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,11 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.system.measureNanoTime
|
||||
|
||||
fun doFirResolveTestBench(firFiles: List<FirFile>, transformers: List<FirTransformer<Nothing?>>) {
|
||||
fun doFirResolveTestBench(firFiles: List<FirFile>, transformers: List<FirTransformer<Nothing?>>, gc: Boolean = true) {
|
||||
|
||||
System.gc()
|
||||
if (gc) {
|
||||
System.gc()
|
||||
}
|
||||
|
||||
val timePerTransformer = mutableMapOf<KClass<*>, Long>()
|
||||
val counterPerTransformer = mutableMapOf<KClass<*>, Long>()
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.defaultConstructor.AbstractDefaultArgumentsReflectionTest
|
||||
import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest
|
||||
import org.jetbrains.kotlin.codegen.ir.*
|
||||
import org.jetbrains.kotlin.fir.AbstractFirDiagnosticsSmokeTest
|
||||
import org.jetbrains.kotlin.fir.AbstractFirResolveTestCase
|
||||
import org.jetbrains.kotlin.fir.AbstractFirResolveTestCaseWithStdlib
|
||||
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
|
||||
@@ -411,4 +412,11 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
testGroup("compiler/fir/resolve/tests", "compiler/testData") {
|
||||
|
||||
testClass<AbstractFirDiagnosticsSmokeTest> {
|
||||
model("diagnostics/tests")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user