conner
08/21/2023, 11:34 AMarrow-reflect-compiler-plugin
published? I'm attempting to use it from a build system that isn't gradle, but I can't find it in maven.
Tangentially, is using arrow-reflect
recommended right now, or should I use arrow-meta
directly?raulraja
08/21/2023, 3:06 PMarrow-meta
is usable if you are gonna do anything with just kotlin backend IR, it has not been updated to latest versions of kotlin.
We want to pick it up and finalize arrow-reflection as to what arrow-meta will finally become. A simple library for macros in kotlin.
There are still a lot of rough edges and corners in there that don't work like they should due to limitations with the kotlin compiler api.conner
08/21/2023, 4:57 PMapatrida
09/26/2023, 1:30 AMClassBuilder
uses a deprecated class, needs to become extension on ClassGeneratorExtension
I think, but the error gives another options as well)
references now use IdSignature
and to use descriptors you need to go down a level, so:
pluginContext.symbols.externalSymbolTable.referenceField(this)
becomes
pluginContext.symbols.externalSymbolTable.descriptorExtension.referenceField(this)
Easy so far. BUT, then kotlin-compiler-testing
is so far out of date that all tests cannot be run (calls useIr
on compiler args but that is no longer a valid argument). PR's for kotlin-compiler-testing
for updating to 1.8.2x and then 1.9.x are all stalled it appears.apatrida
09/26/2023, 1:50 AMFirMetaCodegenExtension.kt
. A now missing FirQualifiedAccess
class used from Meta.kt that probably should replaced with something but it isn't used yet anyways. And then all the work to upgrade is in TemplateCompiler
with Fir2IrResult
becoming Fir2IrActualizedResult
and a bunch of related changes in convertToIR()
. Some new configuration is required and the call for convertToIrAndActualize
I think becomes convertToIrAndActualizeForJvm
unless you really want to deal with 10 new parameters that are fun to configure. But I'm not sure all of the intent there. I did this just to get compiling to see where things stood.
Add
configureFirParser(FirParser.Psi)
to the base test runner and you can get moving. But, I tried compiling the sandbox and get errors about FIR cache being cleared blowing everything up.
tests all fail because of different generation, but it must be close.
but sandbox blows up:
Unexpected caches clearing
at org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider.createCopyWithCleanCaches(FirCachingCompositeSymbolProvider.kt:77)
...
TemplateCompiler
apatrida
09/26/2023, 1:51 AMapatrida
09/26/2023, 1:53 AMproduct()
as a non-error and the correct type from the generated code.apatrida
09/26/2023, 1:53 AMapatrida
09/26/2023, 2:16 AMraulraja
09/26/2023, 8:58 AMarrow-reflection
once things were stable. We'd very much appreciate those PRs/suggestion to get us closer to update the project. thank you colorapatrida
09/26/2023, 1:22 PMapatrida
09/26/2023, 1:27 PM1.9.30-dev-3330
looks to be the same, no changes for compiling and tests passing.raulraja
09/26/2023, 2:00 PMapatrida
09/26/2023, 2:15 PMFirCachingCompositeSymbolProvider
with comments:
// This property is necessary just to make sure we don't use the hack at `createCopyWithCleanCaches` more than once or in cases
// we are not assumed to use it.
private val expectedCachesToBeCleanedOnce: Boolean = false,
and
// Unfortunately, this is a part of a hack for overcoming the problem of plugin's generated entities
// (for more details see its usage at org.jetbrains.kotlin.fir.resolve.transformers.plugin.FirCompilerRequiredAnnotationsResolveProcessor.afterPhase)
fun createCopyWithCleanCaches(): FirCachingCompositeSymbolProvider {
require(expectedCachesToBeCleanedOnce) { "Unexpected caches clearing" }
return FirCachingCompositeSymbolProvider(session, providers, expectedCachesToBeCleanedOnce = false)
}
Which explodes when TemplateCompiler
calls afterPhase
I'm looking to see how this is supposed to behave and what is done here that causes the exception.
The move from 1.9.20-Beta to 1.9.30-dev-3330 is a bit more involved, so I'm doing them separately.apatrida
09/26/2023, 2:20 PM@OptIn(FirSymbolProviderInternals::class)
override fun afterPhase() {
super.afterPhase()
val generatedDeclarationsSymbolProvider = session.generatedDeclarationsSymbolProvider
generatedDeclarationsSymbolProvider?.enable()
// This part is a bit hacky way to clear the caches in FirCachingCompositeSymbolProvider when there are plugins that may generate new entities.
// It's necessary because otherwise, when symbol provider is being queried on the stage of compiler-required annotations resolution
// we record incorrect (incomplete) results to its cache, so after the phase is completed we just start from the scratch
val symbolProvider = session.symbolProvider
if (generatedDeclarationsSymbolProvider != null && symbolProvider is FirCachingCompositeSymbolProvider) {
@OptIn(SessionConfiguration::class)
session.register(FirSymbolProvider::class, symbolProvider.createCopyWithCleanCaches())
}
}
apatrida
09/26/2023, 3:32 PMraulraja
09/26/2023, 4:11 PMapatrida
09/26/2023, 4:53 PMapatrida
09/26/2023, 4:57 PMtypeRef
becoming resolvedType
(or coneTypeOrNull
returning ConeKotlinType
apatrida
09/26/2023, 5:00 PMCompilerPipeline.kt
there when you started, with methods such as transformFirToIr
?apatrida
09/26/2023, 5:01 PMapatrida
09/26/2023, 5:02 PMconvertToIrAndActualize
is in that fileraulraja
09/26/2023, 5:06 PMraulraja
09/26/2023, 5:07 PMapatrida
09/26/2023, 5:09 PMapatrida
09/26/2023, 7:30 PMapatrida
09/26/2023, 7:39 PMbuild-2.0.0-dev-4182
... things are moving!apatrida
09/26/2023, 7:47 PMFirTotalResolveProcessor
, ConvertToIr
, compilerPpeline
, and in there is the reference to FirCompilerRequiredAnnotationsResolveProcessor
which has the code that calls the FirCachingCompositeSymbolProvider::createCopyWithCleanCaches()
method that blows up, so I'm checking for differences in the code you pulled THEN to NOWapatrida
09/26/2023, 10:09 PM// in TemplateCompiler.kt
@OptIn(SessionConfiguration::class)
fun process(files: List<FirFile>) {
for (processor in processors) {
// clear the cache myself
if (processor.session.symbolProvider is FirCachingCompositeSymbolProvider) {
processor.session.register(FirSymbolProvider::class,
FirCachingCompositeSymbolProvider(processor.session,
(processor.session.symbolProvider as FirCachingCompositeSymbolProvider).providers, true)
)
}
processor.beforePhase()
when (processor) {
...
apatrida
09/26/2023, 10:10 PMapatrida
09/26/2023, 10:16 PMPermittedSubclasses requires ASM9
at org.jetbrains.org.objectweb.asm.ClassVisitor
apatrida
09/26/2023, 10:23 PMapatrida
09/26/2023, 10:25 PMorg.jetbrains.kotlin.utils.exceptions.KotlinIllegalArgumentExceptionWithAttachments: Expected FirResolvedTypeRef with ConeKotlinType but was FirUserTypeRefImpl
at org.jetbrains.kotlin.fir.types.FirTypeUtilsKt.getConeType(FirTypeUtils.kt:192)
at org.jetbrains.kotlin.fir.resolve.ResolveUtilsKt.getCorrespondingClassSymbolOrNull(ResolveUtils.kt:507)
at arrow.reflect.compiler.plugin.fir.checkers.FirMetaAdditionalCheckersExtensionKt.metaAnnotations(FirMetaAdditionalCheckersExtension.kt:90)
at arrow.reflect.compiler.plugin.fir.codegen.FirMetaCodegenExtension.nestedClasses(FirMetaCodegenExtension.kt:190)
at arrow.reflect.compiler.plugin.fir.codegen.FirMetaCodegenExtension.getNestedClassifiersNames(FirMetaCodegenExtension.kt:198)
apatrida
09/26/2023, 10:28 PM- typeRef:
Class: org.jetbrains.kotlin.fir.types.impl.FirUserTypeRefImpl
Value:
Product
========
- typeRefElementKind:
KtRealSourceElementKind
========
- typeRefSource:
Class: org.jetbrains.kotlin.KtRealPsiSourceElement
Value:
<File name: Sample.kt, Physical: true>
@<ELEMENT>Product</ELEMENT>
data class Sample(val name: String, val age: Int)
apatrida
09/26/2023, 10:28 PMapatrida
09/26/2023, 10:32 PMapatrida
09/26/2023, 10:43 PMapatrida
09/26/2023, 10:45 PMapatrida
09/26/2023, 10:45 PMapatrida
09/26/2023, 10:47 PMmain
to work
Non-static main() method was invoked: class must have constructor with no parameters