Fix FIR bootstrap in version 2.0
This commit is contained in:
@@ -172,14 +172,18 @@ fun Project.configureKotlinCompilationOptions() {
|
|||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs += jvmCompilerArgs
|
freeCompilerArgs += jvmCompilerArgs
|
||||||
|
|
||||||
if (useJvmFir && project.path !in projectsWithDisabledFirBootstrap) {
|
if (useJvmFir) {
|
||||||
freeCompilerArgs += "-Xuse-k2"
|
if (project.path !in projectsWithDisabledFirBootstrap) {
|
||||||
freeCompilerArgs += "-Xabi-stability=stable"
|
freeCompilerArgs += "-Xuse-k2"
|
||||||
if (useFirLT) {
|
freeCompilerArgs += "-Xabi-stability=stable"
|
||||||
freeCompilerArgs += "-Xuse-fir-lt"
|
if (useFirLT) {
|
||||||
}
|
freeCompilerArgs += "-Xuse-fir-lt"
|
||||||
if (useFirIC) {
|
}
|
||||||
freeCompilerArgs += "-Xuse-fir-ic"
|
if (useFirIC) {
|
||||||
|
freeCompilerArgs += "-Xuse-fir-ic"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
freeCompilerArgs += "-Xskip-prerelease-check"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (renderDiagnosticNames) {
|
if (renderDiagnosticNames) {
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ class ModuleMapping private constructor(
|
|||||||
debugName: String,
|
debugName: String,
|
||||||
skipMetadataVersionCheck: Boolean,
|
skipMetadataVersionCheck: Boolean,
|
||||||
isJvmPackageNameSupported: Boolean,
|
isJvmPackageNameSupported: Boolean,
|
||||||
metadataVersionFromLanguageVersion: JvmMetadataVersion,
|
metadataVersionFromLanguageVersion: JvmMetadataVersion = JvmMetadataVersion.INSTANCE,
|
||||||
reportIncompatibleVersionError: (JvmMetadataVersion) -> Unit,
|
reportIncompatibleVersionError: (JvmMetadataVersion) -> Unit,
|
||||||
): ModuleMapping {
|
): ModuleMapping {
|
||||||
if (bytes == null) {
|
if (bytes == null) {
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ ext.configureFrontendIr = { Project project ->
|
|||||||
if (project.kotlinBuildProperties.useFirForLibraries) {
|
if (project.kotlinBuildProperties.useFirForLibraries) {
|
||||||
freeCompilerArgs += "-Xuse-k2"
|
freeCompilerArgs += "-Xuse-k2"
|
||||||
allWarningsAsErrors = false
|
allWarningsAsErrors = false
|
||||||
|
} else if (project.kotlinBuildProperties.useFir) {
|
||||||
|
freeCompilerArgs += "-Xskip-prerelease-check"
|
||||||
}
|
}
|
||||||
if (project.properties.renderDiagnosticNames) {
|
if (project.properties.renderDiagnosticNames) {
|
||||||
freeCompilerArgs += "-Xrender-internal-diagnostic-names"
|
freeCompilerArgs += "-Xrender-internal-diagnostic-names"
|
||||||
|
|||||||
@@ -63,32 +63,40 @@ dependencies {
|
|||||||
class KotlinModuleShadowTransformer(private val logger: Logger) : Transformer {
|
class KotlinModuleShadowTransformer(private val logger: Logger) : Transformer {
|
||||||
@Suppress("ArrayInDataClass")
|
@Suppress("ArrayInDataClass")
|
||||||
private data class Entry(val path: String, val bytes: ByteArray)
|
private data class Entry(val path: String, val bytes: ByteArray)
|
||||||
|
|
||||||
private val data = mutableListOf<Entry>()
|
private val data = mutableListOf<Entry>()
|
||||||
|
|
||||||
override fun getName() = "KotlinModuleShadowTransformer"
|
override fun getName() = "KotlinModuleShadowTransformer"
|
||||||
|
|
||||||
override fun canTransformResource(element: FileTreeElement): Boolean =
|
override fun canTransformResource(element: FileTreeElement): Boolean =
|
||||||
element.path.substringAfterLast(".") == KOTLIN_MODULE
|
element.path.substringAfterLast(".") == KOTLIN_MODULE
|
||||||
|
|
||||||
override fun transform(context: TransformerContext) {
|
override fun transform(context: TransformerContext) {
|
||||||
fun relocate(content: String): String =
|
fun relocate(content: String): String =
|
||||||
context.relocators.fold(content) { acc, relocator -> relocator.applyToSourceContent(acc) }
|
context.relocators.fold(content) { acc, relocator -> relocator.applyToSourceContent(acc) }
|
||||||
|
|
||||||
val metadata = KotlinModuleMetadata.read(context.`is`.readBytes())
|
val internalData = org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping.loadModuleMapping(
|
||||||
?: error("Not a .kotlin_module file: ${context.path}")
|
context.`is`.readBytes(), javaClass.name, skipMetadataVersionCheck = true, isJvmPackageNameSupported = true
|
||||||
|
) {
|
||||||
|
}
|
||||||
val writer = KotlinModuleMetadata.Writer()
|
val writer = KotlinModuleMetadata.Writer()
|
||||||
logger.info("Transforming ${context.path}")
|
logger.info("Transforming ${context.path}")
|
||||||
metadata.accept(object : KmModuleVisitor(writer) {
|
val visitor = object : KmModuleVisitor(writer) {
|
||||||
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
|
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
|
||||||
assert(multiFileClassParts.isEmpty()) { multiFileClassParts } // There are no multi-file class parts in core
|
assert(multiFileClassParts.isEmpty()) { multiFileClassParts } // There are no multi-file class parts in core
|
||||||
super.visitPackageParts(relocate(fqName), fileFacades.map(::relocate), multiFileClassParts)
|
super.visitPackageParts(relocate(fqName), fileFacades.map(::relocate), multiFileClassParts)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
for ((fqName, parts) in internalData.packageFqName2Parts) {
|
||||||
|
val (fileFacades, multiFileClassParts) = parts.parts.partition { parts.getMultifileFacadeName(it) == null }
|
||||||
|
visitor.visitPackageParts(fqName, fileFacades, multiFileClassParts.associateWith { parts.getMultifileFacadeName(it)!! })
|
||||||
|
}
|
||||||
|
visitor.visitEnd()
|
||||||
|
|
||||||
data += Entry(context.path, writer.write().bytes)
|
data += Entry(context.path, writer.write().bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasTransformedResource(): Boolean =
|
override fun hasTransformedResource(): Boolean = data.isNotEmpty()
|
||||||
data.isNotEmpty()
|
|
||||||
|
|
||||||
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
|
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
|
||||||
for ((path, bytes) in data) {
|
for ((path, bytes) in data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user