[K2/N] Prohibit single-stage compilation with language version 2.0
Kotlin/Native compiler can compile source files directly to a native
binary (e.g. an executable or a framework). This is the so-called
"single-stage" compilation mode. It is used only in the command-line
compiler, while Kotlin Gradle plugin always produces an intermediate
klib first, and then compiles it to a native binary ("two-stage"
compilation mode).
When running Kotlin/Native compiler with '-language-version 2.0' in the
single-stage compilation mode, it in fact doesn't use the new K2
frontend. This is misleading and error-prone.
To address this problem, the commit prohibits the single-stage
compilation with '-language-version 2.0'. This affects only the
command-line compiler, and shouldn't affect compilation with Gradle.
^KT-56855
This commit is contained in:
committed by
Space Team
parent
25b6eb3114
commit
22ee170f44
+26
-5
@@ -6,9 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan.driver.phases
|
package org.jetbrains.kotlin.backend.konan.driver.phases
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||||
import org.jetbrains.kotlin.backend.konan.FrontendServices
|
import org.jetbrains.kotlin.backend.konan.*
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanCompilationException
|
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanConfig
|
|
||||||
import org.jetbrains.kotlin.backend.konan.TopDownAnalyzerFacadeForKonan
|
import org.jetbrains.kotlin.backend.konan.TopDownAnalyzerFacadeForKonan
|
||||||
import org.jetbrains.kotlin.backend.konan.driver.BasicPhaseContext
|
import org.jetbrains.kotlin.backend.konan.driver.BasicPhaseContext
|
||||||
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
|
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
|
||||||
@@ -16,9 +14,11 @@ import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine
|
|||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||||
|
|
||||||
sealed class FrontendPhaseOutput {
|
sealed class FrontendPhaseOutput {
|
||||||
object ShouldNotGenerateCode : FrontendPhaseOutput()
|
object ShouldNotGenerateCode : FrontendPhaseOutput()
|
||||||
@@ -54,9 +54,30 @@ internal val FrontendPhase = createSimpleNamedCompilerPhase(
|
|||||||
input.configuration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
|
input.configuration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val sourceFiles = input.getSourceFiles()
|
||||||
|
|
||||||
|
if (sourceFiles.isNotEmpty()) {
|
||||||
|
if (input.configuration.getBoolean(CommonConfigurationKeys.USE_FIR)) {
|
||||||
|
context.reportCompilationError(
|
||||||
|
"language version 2.0 doesn't support compiling sources " +
|
||||||
|
"(${sourceFiles.first().virtualFilePath} in particular) " +
|
||||||
|
"directly to native binaries " +
|
||||||
|
"(e.g. a ${context.config.produce.name.toLowerCaseAsciiOnly()}).\n" +
|
||||||
|
"If you are using the command-line compiler (e.g. konanc or kotlinc-native), then " +
|
||||||
|
"compile the sources to a klib first with '-p library' compiler flag, " +
|
||||||
|
"and then use '-Xinclude=<klib>' flag to compile this to a binary.\n" +
|
||||||
|
"See more details at https://youtrack.jetbrains.com/issue/KT-56855\n" +
|
||||||
|
"If you are seeing this error message when compiling with Gradle, " +
|
||||||
|
"please report this here: https://kotl.in/issue"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: we shouldn't be here in this case.
|
||||||
|
}
|
||||||
|
|
||||||
// Build AST and binding info.
|
// Build AST and binding info.
|
||||||
analyzerWithCompilerReport.analyzeAndReport(input.getSourceFiles()) {
|
analyzerWithCompilerReport.analyzeAndReport(sourceFiles) {
|
||||||
TopDownAnalyzerFacadeForKonan.analyzeFiles(input.getSourceFiles(), context)
|
TopDownAnalyzerFacadeForKonan.analyzeFiles(sourceFiles, context)
|
||||||
}
|
}
|
||||||
if (analyzerWithCompilerReport.hasErrors()) {
|
if (analyzerWithCompilerReport.hasErrors()) {
|
||||||
throw KonanCompilationException()
|
throw KonanCompilationException()
|
||||||
|
|||||||
Reference in New Issue
Block a user