K2: update LightTree support in modularized tests

This commit is contained in:
Ilya Chernikov
2022-12-21 11:59:03 +01:00
committed by Space Team
parent 1a373317ed
commit 47a4532ea0
3 changed files with 81 additions and 65 deletions
@@ -83,6 +83,7 @@ import org.jetbrains.kotlin.resolve.jvm.modules.JavaModuleResolver
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.utils.addToStdlib.runIf
import java.io.File
import java.util.LinkedHashSet
private const val kotlinFileExtensionWithDot = ".${KotlinFileType.EXTENSION}"
private const val javaFileExtensionWithDot = ".${JavaFileType.DEFAULT_EXTENSION}"
@@ -114,41 +115,7 @@ fun compileModulesUsingFrontendIrAndLightTree(
val moduleConfiguration = compilerConfiguration.copy().applyModuleProperties(module, buildFile).apply {
put(JVMConfigurationKeys.FRIEND_PATHS, module.getFriendPaths())
}
val platformSources = linkedSetOf<KtSourceFile>()
val commonSources = linkedSetOf<KtSourceFile>()
// !!
// TODO: the scripts checking should be part of the scripting plugin functionality, as it is implemented now in ScriptingProcessSourcesBeforeCompilingExtension
// TODO: implement in the next round of K2 scripting support
val skipScriptsInLtMode = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR) && compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)
var skipScriptsInLtModeWarning = false
compilerConfiguration.kotlinSourceRoots.forAllFiles(compilerConfiguration, projectEnvironment.project) { virtualFile, isCommon ->
val file = KtVirtualFileSourceFile(virtualFile)
when {
file.path.endsWith(javaFileExtensionWithDot) -> {}
file.path.endsWith(kotlinFileExtensionWithDot) || !skipScriptsInLtMode -> {
if (isCommon) commonSources.add(file)
else platformSources.add(file)
}
else -> {
// temporarily assume it is a script, see the TODO above
skipScriptsInLtModeWarning = true
}
}
}
if (skipScriptsInLtModeWarning) {
// TODO: remove then Scripts are supported in LT (probably different K2 extension should be written for handling the case properly)
messageCollector.report(
CompilerMessageSeverity.STRONG_WARNING,
"Scripts are not yet supported with K2 in LightTree mode, consider using K1 or disable LightTree mode with -XuseFirLT=false"
)
}
val renderDiagnosticName = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter()
val (platformSources, commonSources) = collectSources(compilerConfiguration, projectEnvironment, messageCollector)
val compilerInput = ModuleCompilerInput(
TargetId(module),
@@ -156,6 +123,9 @@ fun compileModulesUsingFrontendIrAndLightTree(
JvmPlatforms.unspecifiedJvmPlatform, platformSources,
moduleConfiguration
)
val renderDiagnosticName = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter()
val compilerEnvironment = ModuleCompilerEnvironment(projectEnvironment, diagnosticsReporter)
performanceManager?.notifyAnalysisStarted()
@@ -210,6 +180,44 @@ fun compileModulesUsingFrontendIrAndLightTree(
)
}
fun collectSources(
compilerConfiguration: CompilerConfiguration,
projectEnvironment: VfsBasedProjectEnvironment,
messageCollector: MessageCollector
): Pair<LinkedHashSet<KtSourceFile>, LinkedHashSet<KtSourceFile>> {
val platformSources = linkedSetOf<KtSourceFile>()
val commonSources = linkedSetOf<KtSourceFile>()
// TODO: the scripts checking should be part of the scripting plugin functionality, as it is implemented now in ScriptingProcessSourcesBeforeCompilingExtension
// TODO: implement in the next round of K2 scripting support (https://youtrack.jetbrains.com/issue/KT-55728)
val skipScriptsInLtMode = compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR) && compilerConfiguration.getBoolean(CommonConfigurationKeys.USE_LIGHT_TREE)
var skipScriptsInLtModeWarning = false
compilerConfiguration.kotlinSourceRoots.forAllFiles(compilerConfiguration, projectEnvironment.project) { virtualFile, isCommon ->
val file = KtVirtualFileSourceFile(virtualFile)
when {
file.path.endsWith(javaFileExtensionWithDot) -> {}
file.path.endsWith(kotlinFileExtensionWithDot) || !skipScriptsInLtMode -> {
if (isCommon) commonSources.add(file)
else platformSources.add(file)
}
else -> {
// temporarily assume it is a script, see the TODO above
skipScriptsInLtModeWarning = true
}
}
}
if (skipScriptsInLtModeWarning) {
// TODO: remove then Scripts are supported in LT (probably different K2 extension should be written for handling the case properly)
messageCollector.report(
CompilerMessageSeverity.STRONG_WARNING,
"Scripts are not yet supported with K2 in LightTree mode, consider using K1 or disable LightTree mode with -Xuse-fir-lt=false"
)
}
return Pair(platformSources, commonSources)
}
fun convertAnalyzedFirToIr(
input: ModuleCompilerInput,
analysisResults: ModuleCompilerAnalyzedOutput,