[K2] Support legacy serialization for custom function type extensions.

For Compose libraries, it is important that libraries built with
K2 in version 2.0 can be read and used by a version 1.9 K1
compiler. That is not possible if custom function types are
in the metadata.

^KT-58456 Fixed
This commit is contained in:
Mads Ager
2023-05-10 13:39:51 +02:00
committed by teamcity
parent fb476612af
commit 089928ba2b
12 changed files with 114 additions and 2 deletions
@@ -22,6 +22,7 @@ dependencies {
testApi(projectTests(":compiler:tests-common-new"))
testApi(projectTests(":compiler:test-infrastructure"))
testApi(projectTests(":compiler:test-infrastructure-utils"))
testApi(projectTests(":compiler:fir:analysis-tests"))
testApi(project(":compiler:fir:checkers"))
testApi(project(":compiler:fir:checkers:checkers.jvm"))
testApi(project(":compiler:fir:checkers:checkers.js"))
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.plugin.types
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.extensions.FirFunctionTypeKindExtension
import org.jetbrains.kotlin.fir.plugin.fqn
@@ -31,6 +32,9 @@ object ComposableFunction : FunctionTypeKind(
override val prefixForTypeRender: String
get() = "@MyComposable"
override val serializeAsFunctionWithAnnotationUntil: String
get() = LanguageVersion.KOTLIN_2_1.versionString
override fun reflectKind(): FunctionTypeKind = KComposableFunction
}
@@ -40,5 +44,8 @@ object KComposableFunction : FunctionTypeKind(
MY_COMPOSABLE_ANNOTATION_CLASS_ID,
isReflectType = true
) {
override val serializeAsFunctionWithAnnotationUntil: String
get() = LanguageVersion.KOTLIN_2_1.versionString
override fun nonReflectKind(): FunctionTypeKind = ComposableFunction
}
@@ -0,0 +1 @@
public final fun runComposable(block: R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() some/MyComposableFunction0<kotlin/Unit>|): R|kotlin/Unit|
@@ -0,0 +1,7 @@
// API_VERSION: 2.0
// LANGUAGE_VERSION: 2.1
package test
import org.jetbrains.kotlin.fir.plugin.MyComposable
fun runComposable(block: @MyComposable () -> Unit) {}
@@ -0,0 +1 @@
public final fun runComposable(block: R|@R|org/jetbrains/kotlin/fir/plugin/MyComposable|() () -> kotlin/Unit|): R|kotlin/Unit|
@@ -0,0 +1,8 @@
// API_VERSION: 2.0
// LANGUAGE_VERSION: 2.0
package test
import org.jetbrains.kotlin.fir.plugin.MyComposable
fun runComposable(block: @MyComposable () -> Unit) {}
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.plugin.runners;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/fir-plugin-prototype/testData/firLoadK2Compiled")
@TestDataPath("$PROJECT_ROOT")
public class FirLoadK2CompiledKotlinWithPluginTestGenerated extends AbstractFirLoadK2CompiledKotlinWithPluginTest {
@Test
public void testAllFilesPresentInFirLoadK2Compiled() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir-plugin-prototype/testData/firLoadK2Compiled"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple.kt");
}
@Test
@TestMetadata("simple-lang-ver-2.1.kt")
public void testSimple_lang_ver_2_1() throws Exception {
runTest("plugins/fir-plugin-prototype/testData/firLoadK2Compiled/simple-lang-ver-2.1.kt");
}
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.plugin.services.PluginAnnotationsProvider
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.ENABLE_PLUGIN_PHASES
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP
import org.jetbrains.kotlin.test.runners.AbstractFirLoadK2CompiledKotlin
import org.jetbrains.kotlin.test.runners.AbstractFirPsiDiagnosticTest
import org.jetbrains.kotlin.test.runners.codegen.AbstractFirLightTreeBlackBoxCodegenTest
import org.jetbrains.kotlin.test.runners.enableLazyResolvePhaseChecking
@@ -28,6 +29,13 @@ abstract class AbstractFirPsiPluginDiagnosticTest : AbstractFirPsiDiagnosticTest
}
}
open class AbstractFirLoadK2CompiledKotlinWithPluginTest : AbstractFirLoadK2CompiledKotlin() {
override fun configure(builder: TestConfigurationBuilder) {
super.configure(builder)
builder.commonFirWithPluginFrontendConfiguration()
}
}
fun TestConfigurationBuilder.commonFirWithPluginFrontendConfiguration() {
enableLazyResolvePhaseChecking()