From 1a0455a22659da7c94a57d3db29c468ec9fd6bf5 Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 09:10:45 -0600 Subject: [PATCH 1/6] upgrade to Kotlin compiler 1.9.20-Beta2 Incomplete, fails due to a new assert in the compiler --- .../src/main/kotlin/arrow/meta/Meta.kt | 4 +- .../kotlin/arrow/meta/TemplateCompiler.kt | 64 +++++++++++++++---- .../fir/codegen/FirMetaCodegenExtension.kt | 13 ++-- .../compiler/plugin/runners/BaseTestRunner.kt | 4 ++ .../services/PluginAnnotationsConfigurator.kt | 3 + gradle/libs.versions.toml | 2 +- sandbox/build.gradle.kts | 4 +- sandbox/settings.gradle.kts | 16 +++-- settings.gradle.kts | 18 +++--- 9 files changed, 87 insertions(+), 41 deletions(-) diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt index 18a65ce..f75fd48 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt @@ -182,7 +182,7 @@ annotation class Meta { } interface ArrayOfCall : FrontendTransformer { - fun FirMetaCheckerContext.arrayOfCall(arrayOfCall: FirArrayOfCall): FirStatement + fun FirMetaCheckerContext.arrayOfCall(arrayOfCall: FirArrayLiteral): FirStatement } interface AssignmentOperatorStatement : FrontendTransformer { @@ -394,7 +394,7 @@ annotation class Meta { } interface QualifiedAccess : FrontendTransformer { - fun FirMetaCheckerContext.qualifiedAccess(qualifiedAccess: FirQualifiedAccess): FirStatement + fun FirMetaCheckerContext.qualifiedAccess(qualifiedAccess: FirQualifiedAccessExpression): FirStatement } interface QualifiedAccessExpression : FrontendTransformer { diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt index dd85c67..7c75e4e 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt @@ -1,3 +1,5 @@ +@file:OptIn(PrivateForInline::class) + package arrow.meta import com.intellij.psi.PsiDocumentManager @@ -6,21 +8,29 @@ import org.jetbrains.kotlin.KtInMemoryTextSourceFile import org.jetbrains.kotlin.KtIoFileSourceFile import org.jetbrains.kotlin.KtSourceFile import org.jetbrains.kotlin.backend.jvm.JvmIrDeserializerImpl +import org.jetbrains.kotlin.backend.jvm.JvmIrTypeSystemContext +import org.jetbrains.kotlin.builtins.DefaultBuiltIns import org.jetbrains.kotlin.cli.common.messages.* import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.modules.ModuleBuilder import org.jetbrains.kotlin.cli.jvm.compiler.* import org.jetbrains.kotlin.config.* +import org.jetbrains.kotlin.constant.EvaluatedConstTracker import org.jetbrains.kotlin.diagnostics.* import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.analysis.collectors.FirDiagnosticsCollector +import org.jetbrains.kotlin.fir.backend.Fir2IrConfiguration import org.jetbrains.kotlin.fir.backend.Fir2IrResult +import org.jetbrains.kotlin.fir.backend.jvm.FirJvmVisibilityConverter import org.jetbrains.kotlin.fir.backend.jvm.JvmFir2IrExtensions +import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilder import org.jetbrains.kotlin.fir.builder.BodyBuildingMode -import org.jetbrains.kotlin.fir.builder.RawFirBuilder +import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir +import org.jetbrains.kotlin.fir.pipeline.Fir2IrActualizedResult +import org.jetbrains.kotlin.fir.pipeline.ModuleCompilerAnalyzedOutput import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.ImplicitDispatchReceiverValue import org.jetbrains.kotlin.fir.resolve.dfa.DataFlowAnalyzerContext @@ -53,6 +63,9 @@ import org.jetbrains.kotlin.readSourceFileWithMapping import java.io.File import java.util.concurrent.atomic.AtomicInteger import org.jetbrains.kotlin.fir.pipeline.convertToIrAndActualize +import org.jetbrains.kotlin.fir.pipeline.convertToIrAndActualizeForJvm +import org.jetbrains.kotlin.util.PrivateForInline +import kotlin.reflect.jvm.internal.impl.builtins.jvm.JvmBuiltIns class FirResult( val session: FirSession, @@ -87,7 +100,7 @@ class TemplateCompiler( data class TemplateResult( val firResults: List, - val irResults: List + val irResults: List ) var compiling: Boolean = false @@ -105,7 +118,7 @@ class TemplateCompiler( println("parsing source:\n$source") println("session: ${session::class}") val outputs: ArrayList = arrayListOf() - val irOutput: ArrayList = arrayListOf() + val irOutput: ArrayList = arrayListOf() val messageCollector: MessageCollector = MessageCollector.NONE for (module in chunk) { val moduleConfiguration = projectConfiguration//.applyModuleProperties(module, buildFile) @@ -121,7 +134,7 @@ class TemplateCompiler( if (produceIr) { outputs.forEach { - irOutput.add(convertToIR(it, moduleConfiguration)) + irOutput.add(convertToIR(metaCheckerContext, it, moduleConfiguration)) } } } @@ -147,18 +160,42 @@ class TemplateCompiler( return firResult } - fun convertToIR(firResult: FirResult, moduleConfiguration: CompilerConfiguration): Fir2IrResult { + fun convertToIR(metaCheckerContext: FirMetaCheckerContext?, firResult: FirResult, moduleConfiguration: CompilerConfiguration): Fir2IrActualizedResult { + val diagnosticReporter = DiagnosticReporterFactory.createPendingReporter() val fir2IrExtensions = JvmFir2IrExtensions(moduleConfiguration, JvmIrDeserializerImpl(), JvmIrMangler) val linkViaSignatures = moduleConfiguration.getBoolean(JVMConfigurationKeys.LINK_VIA_SIGNATURES) val scopeFiles = firResult.scopeDeclarations.filterIsInstance() val files = firResult.files + scopeFiles val validatedFirResult = with(firResult) { - org.jetbrains.kotlin.fir.pipeline.FirResult(platformOutput = org.jetbrains.kotlin.fir.pipeline.ModuleCompilerAnalyzedOutput( - session = session, scopeSession = scopeSession, fir = files - ), commonOutput = null) + org.jetbrains.kotlin.fir.pipeline.FirResult(listOf( + ModuleCompilerAnalyzedOutput(session = session, scopeSession = scopeSession, fir = files) + )) } - val fir2IrResult = validatedFirResult.convertToIrAndActualize(fir2IrExtensions= fir2IrExtensions, irGeneratorExtensions = emptyList(), linkViaSignatures = linkViaSignatures) + + val fir2IrConfiguration = Fir2IrConfiguration( + languageVersionSettings = moduleConfiguration.languageVersionSettings, + diagnosticReporter = diagnosticReporter, + linkViaSignatures = linkViaSignatures, + evaluatedConstTracker = moduleConfiguration + .putIfAbsent(CommonConfigurationKeys.EVALUATED_CONST_TRACKER, EvaluatedConstTracker.create()), + inlineConstTracker = moduleConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER], + allowNonCachedDeclarations = false + ) + + val fir2IrResult = validatedFirResult.convertToIrAndActualizeForJvm( + fir2IrExtensions= fir2IrExtensions, + irGeneratorExtensions = emptyList(), + fir2IrConfiguration = fir2IrConfiguration, + ) ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() + val diagnosticsContext = metaCheckerContext?.checkerContext + if (diagnosticsContext != null) { + diagnosticReporter.diagnostics.forEach { + metaCheckerContext.diagnosticReporter.report(it, diagnosticsContext) + println("error: [" + it.factory.name + "] " + it.factory.ktRenderer.render(it)) + } + } + return fir2IrResult } @@ -204,7 +241,6 @@ class TemplateCompiler( val scopeSession: ScopeSession, scopeDeclarations: List ) { - private val processors: List = createAllCompilerResolveProcessors( session, scopeSession, @@ -217,7 +253,9 @@ class TemplateCompiler( when (processor) { is FirTransformerBasedResolveProcessor -> { for (file in files) { - processor.processFile(file) + withFileAnalysisExceptionWrapping(file) { + processor.processFile(file) + } } } @@ -258,7 +296,7 @@ class TemplateCompiler( fun FirSession.buildFirFromKtFiles(ktFiles: Collection): List { val firProvider = (firProvider as? FirProviderImpl) - val builder = RawFirBuilder(this, kotlinScopeProvider, BodyBuildingMode.NORMAL) + val builder = PsiRawFirBuilder(this, kotlinScopeProvider, BodyBuildingMode.NORMAL) return ktFiles.map { builder.buildFirFile(it).also { firFile -> firProvider?.recordFile(firFile) @@ -345,7 +383,7 @@ class FirBodyResolveTransformerAdapter( implicitTypeOnly = false, scopeSession = scopeSession, outerBodyResolveContext = BodyResolveContext( - ReturnTypeCalculatorForFullBodyResolve, + ReturnTypeCalculatorForFullBodyResolve.Default, DataFlowAnalyzerContext(session), scopeDeclarations.filterIsInstance().toSet() ) diff --git a/arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/codegen/FirMetaCodegenExtension.kt b/arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/codegen/FirMetaCodegenExtension.kt index 45fe6fa..3d120f7 100644 --- a/arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/codegen/FirMetaCodegenExtension.kt +++ b/arrow-reflect-compiler-plugin/src/main/kotlin/arrow/reflect/compiler/plugin/fir/codegen/FirMetaCodegenExtension.kt @@ -9,10 +9,7 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy -import org.jetbrains.kotlin.fir.extensions.AnnotationFqn -import org.jetbrains.kotlin.fir.extensions.FirDeclarationGenerationExtension -import org.jetbrains.kotlin.fir.extensions.FirDeclarationPredicateRegistrar -import org.jetbrains.kotlin.fir.extensions.MemberGenerationContext +import org.jetbrains.kotlin.fir.extensions.* import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider @@ -37,7 +34,7 @@ class FirMetaCodegenExtension( private fun metaContext(generationContext: MemberGenerationContext?): FirMetaContext = FirMetaMemberGenerationContext(templateCompiler, session, generationContext) - override fun generateNestedClassLikeDeclaration(owner: FirClassSymbol<*>, name: Name): FirClassLikeSymbol<*>? { + override fun generateNestedClassLikeDeclaration(owner: FirClassSymbol<*>, name: Name, context: NestedClassGenerationContext): FirClassLikeSymbol<*>? { return if (!templateCompiler.compiling) { val firClass: FirClass? = invokeMeta( true, @@ -46,7 +43,7 @@ class FirMetaCodegenExtension( Meta.Generate.Members.NestedClasses::class, "nestedClasses" ) - firClass?.symbol ?: super.generateNestedClassLikeDeclaration(owner, name) + firClass?.symbol ?: super.generateNestedClassLikeDeclaration(owner, name, context) } else null } @@ -142,7 +139,7 @@ class FirMetaCodegenExtension( } else super.generateProperties(callableId, context) } - override fun getCallableNamesForClass(classSymbol: FirClassSymbol<*>): Set = + override fun getCallableNamesForClass(classSymbol: FirClassSymbol<*>, context: MemberGenerationContext): Set = constructors(classSymbol).orEmpty() + properties(classSymbol).orEmpty() + functions(classSymbol).orEmpty() @@ -197,7 +194,7 @@ class FirMetaCodegenExtension( ) // else null - override fun getNestedClassifiersNames(classSymbol: FirClassSymbol<*>): Set = + override fun getNestedClassifiersNames(classSymbol: FirClassSymbol<*>, context: NestedClassGenerationContext): Set = nestedClasses(classSymbol).orEmpty() fun topLevelFunctions(): Set? = diff --git a/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/runners/BaseTestRunner.kt b/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/runners/BaseTestRunner.kt index 6a355af..d5c9ef0 100644 --- a/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/runners/BaseTestRunner.kt +++ b/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/runners/BaseTestRunner.kt @@ -2,9 +2,11 @@ package arrow.reflect.compiler.plugin.runners import arrow.reflect.compiler.plugin.services.* import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.test.FirParser import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives +import org.jetbrains.kotlin.test.directives.configureFirParser import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade import org.jetbrains.kotlin.test.initIdeaConfiguration import org.jetbrains.kotlin.test.model.DependencyKind @@ -37,6 +39,8 @@ fun TestConfigurationBuilder.commonFirWithPluginFrontendConfiguration() { +AdditionalFilesDirectives.SOME_FILE_DIRECTIVE } + configureFirParser(FirParser.LightTree) + globalDefaults { targetBackend = TargetBackend.JVM_IR targetPlatform = JvmPlatforms.defaultJvmPlatform diff --git a/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/services/PluginAnnotationsConfigurator.kt b/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/services/PluginAnnotationsConfigurator.kt index a9f18e1..da3293f 100644 --- a/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/services/PluginAnnotationsConfigurator.kt +++ b/arrow-reflect-compiler-plugin/src/test/kotlin/arrow/reflect/compiler/plugin/services/PluginAnnotationsConfigurator.kt @@ -2,7 +2,9 @@ package arrow.reflect.compiler.plugin.services import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.test.FirParser import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.configureFirParser import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.EnvironmentConfigurator import org.jetbrains.kotlin.test.services.RuntimeClasspathProvider @@ -58,5 +60,6 @@ class MetaRuntimeClasspathProvider(testServices: TestServices) : RuntimeClasspat fun TestConfigurationBuilder.configureForRuntimeAnnotationLibrary() { useConfigurators(::PluginAnnotationsConfigurator) useCustomRuntimeClasspathProviders(::MetaRuntimeClasspathProvider) + configureFirParser(FirParser.LightTree) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1dbd32..b6b8eea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] arrowGradleConfig = "0.11.0" classgraph = "4.8.154" -kotlin = "1.8.255-SNAPSHOT" +kotlin = "1.9.20-Beta2" reflections = "0.10.2" [libraries] diff --git a/sandbox/build.gradle.kts b/sandbox/build.gradle.kts index 8c693dc..054a677 100644 --- a/sandbox/build.gradle.kts +++ b/sandbox/build.gradle.kts @@ -1,10 +1,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -val kotlinVersion = "1.8.255-SNAPSHOT" +val kotlinVersion = "1.9.20-Beta2" plugins { - id("org.jetbrains.kotlin.jvm") version "1.8.255-SNAPSHOT" + id("org.jetbrains.kotlin.jvm") version "1.9.20-Beta2" id("io.arrow-kt.reflect") version "0.1.0" application } diff --git a/sandbox/settings.gradle.kts b/sandbox/settings.gradle.kts index eb53e75..2efdbf7 100644 --- a/sandbox/settings.gradle.kts +++ b/sandbox/settings.gradle.kts @@ -1,29 +1,31 @@ pluginManagement { repositories { - mavenCentral() - gradlePluginPortal() - maven(url = "https://oss.sonatype.org/content/repositories/snapshots") - maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") mavenLocal { content { includeGroup("io.arrow-kt") includeGroup("io.arrow-kt.reflect") } } + mavenCentral() + gradlePluginPortal() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") } } dependencyResolutionManagement { repositories { - mavenCentral() - maven(url = "https://oss.sonatype.org/content/repositories/snapshots") - maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") mavenLocal { content { includeGroup("io.arrow-kt") includeGroup("io.arrow-kt.reflect") } } + mavenCentral() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") } } diff --git a/settings.gradle.kts b/settings.gradle.kts index e403e1a..782dbcc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,30 +1,32 @@ pluginManagement { repositories { - mavenCentral() - gradlePluginPortal() - maven(url = "https://oss.sonatype.org/content/repositories/snapshots") - maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") mavenLocal { content { includeGroup("io.arrow-kt") includeGroup("io.arrow-kt.reflect") } } + mavenCentral() + gradlePluginPortal() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") } } dependencyResolutionManagement { repositories { - mavenCentral() - gradlePluginPortal() - maven(url = "https://oss.sonatype.org/content/repositories/snapshots") - maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") mavenLocal { content { includeGroup("io.arrow-kt") includeGroup("io.arrow-kt.reflect") } } + mavenCentral() + gradlePluginPortal() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") + maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") } } From ec685962a3dce13d35094de93544e60f98bfbbb8 Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 09:29:29 -0600 Subject: [PATCH 2/6] add TODO to check `allowNonCachedDeclarations` configuration flag --- .../src/main/kotlin/arrow/meta/TemplateCompiler.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt index 7c75e4e..097e5f1 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt @@ -179,6 +179,7 @@ class TemplateCompiler( evaluatedConstTracker = moduleConfiguration .putIfAbsent(CommonConfigurationKeys.EVALUATED_CONST_TRACKER, EvaluatedConstTracker.create()), inlineConstTracker = moduleConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER], + // TODO: read notes on this flag allowNonCachedDeclarations = false ) From ef680e84688be032259b4e5376704c32159fec58 Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 09:36:34 -0600 Subject: [PATCH 3/6] update sandbox as well to 1.9.20-Beta2 --- sandbox/gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox/gradle/libs.versions.toml b/sandbox/gradle/libs.versions.toml index c1dbd32..b6b8eea 100644 --- a/sandbox/gradle/libs.versions.toml +++ b/sandbox/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] arrowGradleConfig = "0.11.0" classgraph = "4.8.154" -kotlin = "1.8.255-SNAPSHOT" +kotlin = "1.9.20-Beta2" reflections = "0.10.2" [libraries] From 01d3d0bd00cc934e50adbc8fb426eda9ad044fed Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 09:43:26 -0600 Subject: [PATCH 4/6] change sandbox to Kotlin language v2 instead of useK2 flag --- sandbox/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sandbox/build.gradle.kts b/sandbox/build.gradle.kts index 054a677..e7fcdc9 100644 --- a/sandbox/build.gradle.kts +++ b/sandbox/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile val kotlinVersion = "1.9.20-Beta2" @@ -22,7 +23,7 @@ tasks { withType().configureEach { compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) - useK2.set(true) + languageVersion.set(KotlinVersion.KOTLIN_2_0) freeCompilerArgs.add("-Xcontext-receivers") } } From d8a31f14e0e1f6dc11989985c49988a21fd44d09 Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 13:21:20 -0600 Subject: [PATCH 5/6] from 1.9.20-Beta2 up to 1.9.30-dev-3330 --- .../src/main/kotlin/arrow/meta/Meta.kt | 2 +- .../src/main/kotlin/arrow/meta/MetaContext.kt | 4 ++++ .../main/kotlin/arrow/meta/TemplateCompiler.kt | 17 ++++++++++------- gradle/libs.versions.toml | 2 +- sandbox/build.gradle.kts | 4 ++-- sandbox/gradle/libs.versions.toml | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt index f75fd48..d581024 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/Meta.kt @@ -51,7 +51,7 @@ annotation class Meta { newElement: FirFunctionCall ): FirCall { val args = newElement.arguments - val argsApplied = args.mapIndexed { n, expr -> "args[$n] as ${+expr.typeRef}" } + val argsApplied = args.mapIndexed { n, expr -> "args[$n] as ${+expr.resolvedType}" } val name = newElement.toResolvedCallableSymbol()?.callableId?.asSingleFqName()?.asString() return compile( diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/MetaContext.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/MetaContext.kt index 099f1d9..a5fdb45 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/MetaContext.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/MetaContext.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.extensions.MemberGenerationContext import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol +import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.renderReadableWithFqNames @@ -128,6 +129,9 @@ abstract class FirMetaContext( ?: source?.text?.toString() ?: error("$this has no source psi text element") + operator fun ConeKotlinType.unaryPlus(): String = + type.renderReadableWithFqNames().replace("/", ".") + val String.call: FirCall get() = compile( diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt index 097e5f1..b94341f 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt @@ -163,24 +163,27 @@ class TemplateCompiler( fun convertToIR(metaCheckerContext: FirMetaCheckerContext?, firResult: FirResult, moduleConfiguration: CompilerConfiguration): Fir2IrActualizedResult { val diagnosticReporter = DiagnosticReporterFactory.createPendingReporter() val fir2IrExtensions = JvmFir2IrExtensions(moduleConfiguration, JvmIrDeserializerImpl(), JvmIrMangler) - val linkViaSignatures = moduleConfiguration.getBoolean(JVMConfigurationKeys.LINK_VIA_SIGNATURES) val scopeFiles = firResult.scopeDeclarations.filterIsInstance() val files = firResult.files + scopeFiles val validatedFirResult = with(firResult) { - org.jetbrains.kotlin.fir.pipeline.FirResult(listOf( - ModuleCompilerAnalyzedOutput(session = session, scopeSession = scopeSession, fir = files) - )) + org.jetbrains.kotlin.fir.pipeline.FirResult( + listOf( + ModuleCompilerAnalyzedOutput(session = session, scopeSession = scopeSession, fir = files) + ) + ) } val fir2IrConfiguration = Fir2IrConfiguration( languageVersionSettings = moduleConfiguration.languageVersionSettings, diagnosticReporter = diagnosticReporter, - linkViaSignatures = linkViaSignatures, + linkViaSignatures = moduleConfiguration.getBoolean(JVMConfigurationKeys.LINK_VIA_SIGNATURES), evaluatedConstTracker = moduleConfiguration .putIfAbsent(CommonConfigurationKeys.EVALUATED_CONST_TRACKER, EvaluatedConstTracker.create()), inlineConstTracker = moduleConfiguration[CommonConfigurationKeys.INLINE_CONST_TRACKER], - // TODO: read notes on this flag - allowNonCachedDeclarations = false + // TODO: read notes on these new flags + allowNonCachedDeclarations = false, + // TODO: see KT-61514 + useIrFakeOverrideBuilder = moduleConfiguration.getBoolean(CommonConfigurationKeys.USE_IR_FAKE_OVERRIDE_BUILDER) ) val fir2IrResult = validatedFirResult.convertToIrAndActualizeForJvm( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b6b8eea..67f76fd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] arrowGradleConfig = "0.11.0" classgraph = "4.8.154" -kotlin = "1.9.20-Beta2" +kotlin = "1.9.30-dev-3330" reflections = "0.10.2" [libraries] diff --git a/sandbox/build.gradle.kts b/sandbox/build.gradle.kts index e7fcdc9..b3fd2d4 100644 --- a/sandbox/build.gradle.kts +++ b/sandbox/build.gradle.kts @@ -2,10 +2,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -val kotlinVersion = "1.9.20-Beta2" +val kotlinVersion = "1.9.30-dev-3330" plugins { - id("org.jetbrains.kotlin.jvm") version "1.9.20-Beta2" + id("org.jetbrains.kotlin.jvm") version "1.9.30-dev-3330" id("io.arrow-kt.reflect") version "0.1.0" application } diff --git a/sandbox/gradle/libs.versions.toml b/sandbox/gradle/libs.versions.toml index b6b8eea..67f76fd 100644 --- a/sandbox/gradle/libs.versions.toml +++ b/sandbox/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] arrowGradleConfig = "0.11.0" classgraph = "4.8.154" -kotlin = "1.9.20-Beta2" +kotlin = "1.9.30-dev-3330" reflections = "0.10.2" [libraries] From 109bb327d3c0e8723b705927a4197860e455a711 Mon Sep 17 00:00:00 2001 From: apatrida Date: Tue, 26 Sep 2023 16:31:38 -0600 Subject: [PATCH 6/6] possible work-around for the cache clearing assertion (but not sure if we WANT to clear 1 time, or keep existing cache that can never be cleared) --- .../src/main/kotlin/arrow/meta/TemplateCompiler.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt index b94341f..534e817 100644 --- a/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt +++ b/arrow-reflect-annotations/src/main/kotlin/arrow/meta/TemplateCompiler.kt @@ -64,6 +64,9 @@ import java.io.File import java.util.concurrent.atomic.AtomicInteger import org.jetbrains.kotlin.fir.pipeline.convertToIrAndActualize import org.jetbrains.kotlin.fir.pipeline.convertToIrAndActualizeForJvm +import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider +import org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider +import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.util.PrivateForInline import kotlin.reflect.jvm.internal.impl.builtins.jvm.JvmBuiltIns @@ -251,8 +254,18 @@ class TemplateCompiler( scopeDeclarations ) + @OptIn(SessionConfiguration::class) fun process(files: List) { for (processor in processors) { + if (processor.session.symbolProvider is FirCachingCompositeSymbolProvider) { + // TODO: clear the cache? + //val wrapProviders = (processor.session.symbolProvider as FirCachingCompositeSymbolProvider).providers + // TODO: or keep the cache and wrap it to prevent clearing: + val wrapProviders = listOf(processor.session.symbolProvider) + processor.session.register(FirSymbolProvider::class, + FirCachingCompositeSymbolProvider(processor.session, wrapProviders, true) + ) + } processor.beforePhase() when (processor) { is FirTransformerBasedResolveProcessor -> {