Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error in file lowering: java.lang.IllegalStateException: This API is not supported for K2 #1475

Closed
sergeshustoff opened this issue Aug 4, 2023 · 2 comments

Comments

@sergeshustoff
Copy link

sergeshustoff commented Aug 4, 2023

How frequently does the bug occur?

Always

Description

Compiler plugin uses deprecated api that is incompatible with k2.
I assume that the only required fix is changing argument of IrPluginContext.referenceClass calls from FqName to ClassId, but it's possible that other functions marked with @FirIncompatiblePluginAPI are used somewhere else.

Stacktrace & log output

Details: Internal error in file lowering: java.lang.IllegalStateException: This API is not supported for K2
	at org.jetbrains.kotlin.fir.backend.Fir2IrPluginContext.referenceClass(Fir2IrPluginContext.kt:154)
	at io.realm.kotlin.compiler.IrUtilsKt.lookupClassOrThrow(IrUtils.kt:244)
	at io.realm.kotlin.compiler.RealmModelLowering.lower(RealmModelLoweringExtension.kt:100)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitClass(Lower.kt:104)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitClass(IrElementVisitorVoid.kt:111)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitClass(Lower.kt:95)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitClass(Lower.kt:95)
	at org.jetbrains.kotlin.ir.declarations.IrClass.accept(IrClass.kt:73)
	at org.jetbrains.kotlin.ir.declarations.IrFile.acceptChildren(IrFile.kt:37)
	at org.jetbrains.kotlin.ir.visitors.IrVisitorsKt.acceptChildrenVoid(IrVisitors.kt:15)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitElement(Lower.kt:99)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitPackageFragment(IrElementVisitorVoid.kt:190)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitPackageFragment(Lower.kt:95)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:200)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitFile(Lower.kt:95)
	at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitFile(IrElementVisitorVoid.kt:198)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitFile(Lower.kt:95)
	at org.jetbrains.kotlin.backend.common.ClassLoweringVisitor.visitFile(Lower.kt:95)
	at org.jetbrains.kotlin.ir.declarations.IrFile.accept(IrFile.kt:31)
	at org.jetbrains.kotlin.ir.visitors.IrVisitorsKt.acceptVoid(IrVisitors.kt:11)
	at org.jetbrains.kotlin.backend.common.LowerKt.runOnFilePostfix(Lower.kt:92)
	at io.realm.kotlin.compiler.RealmModelLowering.lower(RealmModelLoweringExtension.kt:59)
	at org.jetbrains.kotlin.backend.common.LowerKt.lower(Lower.kt:76)
	at io.realm.kotlin.compiler.RealmModelLoweringExtension.generate(RealmModelLoweringExtension.kt:48)
	at org.jetbrains.kotlin.fir.backend.Fir2IrConverter.runSourcesConversion(Fir2IrConverter.kt:106)
	at org.jetbrains.kotlin.fir.backend.Fir2IrConverter.access$runSourcesConversion(Fir2IrConverter.kt:43)
	at org.jetbrains.kotlin.fir.backend.Fir2IrConverter$Companion.createModuleFragmentWithSignaturesIfNeeded(Fir2IrConverter.kt:499)
	at org.jetbrains.kotlin.fir.pipeline.ConvertToIrKt.convertToIr(convertToIr.kt:159)
	at org.jetbrains.kotlin.fir.pipeline.ConvertToIrKt.convertToIrAndActualize(convertToIr.kt:107)
	at org.jetbrains.kotlin.fir.pipeline.ConvertToIrKt.convertToIrAndActualize$default(convertToIr.kt:64)
	at org.jetbrains.kotlin.fir.pipeline.ConvertToIrKt.convertToIrAndActualizeForJvm(convertToIr.kt:52)
	at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.CompilerPipelineKt.convertAnalyzedFirToIr(compilerPipeline.kt:241)
	at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.CompilerPipelineKt.compileModulesUsingFrontendIrAndLightTree(compilerPipeline.kt:143)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:149)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:460)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:62)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:476)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:399)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:280)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:124)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:636)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1598)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: This API is not supported for K2
	... 64 more

Can you reproduce the bug?

Always

Reproduction Steps

Use kotlin 1.9.0 and enable k2 using kotlin.experimental.tryK2=true in gradle.properties
Try to compile desktop (jvm) or android project with realm compiler plugin and some classes extending RealmObject

Version

1.10.2

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

jvm (desktop), android

Build environment

Android Studio version: IntelliJ IDEA 2023.2 (Community Edition)
Gradle version: 8.2.1

@cmelchior
Copy link
Contributor

cmelchior commented Aug 7, 2023

Hi, it is true that the Realm plugin doesn't yet support K2. There are a few places we use FIR-incompatible APIs, which we are looking into fixing, the bigger problem is that we right now depend on the ComponentRegistrar (which doesn't support K2) because we need run after other plugins like Serialization to avoid conflicts and build errors: https://github.com/realm/realm-kotlin/blob/main/packages/plugin-compiler/src/main/kotlin/io/realm/kotlin/compiler/Registrar.kt#L54

We are still exploring ideas on how to work around this.

EDIT: Ups, it looks like I am wrong. After looking into recent updates in https://youtrack.jetbrains.com/issue/KT-55300, it might be enough to remove the FIR incompatible APIs.

@cmelchior cmelchior self-assigned this Aug 14, 2023
@cmelchior
Copy link
Contributor

We just merged #1476 which should "fix" this, but proper K2 supports needs to come from #1483.

I will be folding this issue into #1483.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants