Kotlin compiler error inline function, not exactly sure what's going on
Asked Answered
P

0

12

I got this confusing error that seems to be in the Kotlin compiler, I don't mind changing my code but I am trying to figure out if I actually did something wrong. I think the code it's having trouble with is this:

inline fun <T> fiberListener(bufferSize: Int = 50,
                             policy: Channels.OverflowPolicy = Channels.OverflowPolicy.BACKOFF,
                             singleProducer: Boolean = true,
                             singleConsumer: Boolean = true,
                             crossinline action: (T) -> Unit): SendPort<T> {
    val channel = Channels.newChannel<T>(bufferSize, policy, singleProducer, singleConsumer)
    fiber { channel.forEach(action) }
    return channel
}

Not sure what more to say, I can make this not inline but I think this code should work. I am using Kotlin 1.0.4 with Gradle. On another note I am not positive inlining this is actually providing a performance improvement, I am still a bit unclear about crossinline. But either way seems like it should work and I get no IDE or compiler error except this internal one.

Error:(37, 45) Kotlin: [Internal Error] org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'fiberListener' into
local final fun <anonymous>(module: org.tenkiv.nexus.thermal.module.ProducerModule): kotlin.Unit defined in org.tenkiv.nexus.thermal.control_point.StateMaintainer.<init>[AnonymousFunctionDescriptor@392d1483]
{ module ->
            module.levelSensor?.addListener(fiberListener { onLevelEvent() })
        }
Cause: fiberListener$default (ILco/paralleluniverse/strands/channels/Channels$OverflowPolicy;ZZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lco/paralleluniverse/strands/channels/SendPort;:
   L0
    ALOAD 6
    IFNULL L1
    NEW java/lang/UnsupportedOperationException
    DUP
    LDC "Super calls with default arguments not supported in this target, function: fiberListener"
    INVOKESPECIAL java/lang/UnsupportedOperationException.<init> (Ljava/lang/String;)V
    ATHROW
   L1
    ILOAD 5
    ICONST_1
    IAND
    IFEQ L2
   L3
    LINENUMBER 13 L3
    BIPUSH 50
    ISTORE 0
   L2
    ILOAD 5
    ICONST_2
    IAND
    IFEQ L4
   L5
    LINENUMBER 14 L5
    GETSTATIC co/paralleluniverse/strands/channels/Channels$OverflowPolicy.BACKOFF : Lco/paralleluniverse/strands/channels/Channels$OverflowPolicy;
    ASTORE 1
   L4
    ILOAD 5
    ICONST_4
    IAND
    IFEQ L6
   L7
    LINENUMBER 15 L7
    ICONST_1
    ISTORE 2
   L6
    ILOAD 5
    BIPUSH 8
    IAND
    IFEQ L8
   L9
    LINENUMBER 16 L9
    ICONST_1
    ISTORE 3
   L8
   L10
   L11
    ALOAD 1
    LDC "policy"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
    ALOAD 4
    LDC "action"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkParameterIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
   L12
    LINENUMBER 40 L12
    ILOAD 0
    ALOAD 1
    ILOAD 2
    ILOAD 3
    INVOKESTATIC co/paralleluniverse/strands/channels/Channels.newChannel (ILco/paralleluniverse/strands/channels/Channels$OverflowPolicy;ZZ)Lco/paralleluniverse/strands/channels/Channel;
    ASTORE 6
   L13
   L14
    LINENUMBER 41 L14
    NEW org/tenkiv/nexus/computer/QuasarKt$fiberListener$1
    DUP
    ALOAD 6
    ALOAD 4
    INVOKESPECIAL org/tenkiv/nexus/computer/QuasarKt$fiberListener$1.<init> (Lco/paralleluniverse/strands/channels/Channel;Lkotlin/jvm/functions/Function1;)V
    CHECKCAST kotlin/jvm/functions/Function0
    INVOKESTATIC co/paralleluniverse/kotlin/KotlinKt.fiber (Lkotlin/jvm/functions/Function0;)Lco/paralleluniverse/fibers/Fiber;
    POP
   L15
    LINENUMBER 42 L15
    ALOAD 6
    CHECKCAST co/paralleluniverse/strands/channels/SendPort
    DUP
    LDC "channel"
    INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkExpressionValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
    ARETURN
   L16
   L17
    ARETURN
    LOCALVARIABLE channel Lco/paralleluniverse/strands/channels/Channel; L13 L17 6
    LOCALVARIABLE bufferSize I L0 L17 0
    LOCALVARIABLE policy Lco/paralleluniverse/strands/channels/Channels$OverflowPolicy; L0 L17 1
    LOCALVARIABLE singleProducer Z L0 L17 2
    LOCALVARIABLE singleConsumer Z L0 L17 3
    LOCALVARIABLE action Lkotlin/jvm/functions/Function1; L0 L17 4
    LOCALVARIABLE $i$f$fiberListener I L10 L17 5
    MAXSTACK = 4
    MAXLOCALS = 7
Cause: Parameter specified as non-null is null: method org.jetbrains.kotlin.codegen.inline.ParametersBuilder.addCapturedParam, parameter original
File being compiled and position: (37,45) in /Users/zjuhasz/Git/Nexus_Brain/src/main/kotlin/org/tenkiv/nexus/thermal/control_point/StateMaintainer.kt
PsiElement: fiberListener { onLevelEvent() }
The root cause was thrown at: ParametersBuilder.kt:-1
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.java:172)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.genCallInner(InlineCodegen.java:158)
    at org.jetbrains.kotlin.codegen.CallGenerator.genCall(CallGenerator.kt:100)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2625)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2583)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:44)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:23)
    at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:65)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:109)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:102)
    at org.jetbrains.kotlin.codegen.CallGenerator$DefaultCallGenerator.genValueAndPut(CallGenerator.kt:58)
    at org.jetbrains.kotlin.codegen.CallBasedArgumentGenerator.generateExpression(CallBasedArgumentGenerator.java:73)
    at org.jetbrains.kotlin.codegen.ArgumentGenerator.generate(ArgumentGenerator.kt:59)
    at org.jetbrains.kotlin.codegen.CallBasedArgumentGenerator.generate(CallBasedArgumentGenerator.java:60)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2605)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2583)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:44)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:23)
    at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:65)
    at org.jetbrains.kotlin.codegen.CoercionValue.putSelector(StackValue.kt:28)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:109)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:102)
    at org.jetbrains.kotlin.codegen.StackValue$StackValueWithSimpleReceiver.putReceiver(StackValue.java:1507)
    at org.jetbrains.kotlin.codegen.StackValueWithLeaveTask.putReceiver(StackValue.kt:53)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:107)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:102)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:324)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.returnExpression(ExpressionCodegen.java:2066)
    at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$FunctionDefault.doGenerateBody(FunctionGenerationStrategy.java:50)
    at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:72)
    at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:378)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.generateMethodBody(InlineCodegen.java:512)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.generateLambdaBody(InlineCodegen.java:477)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.generateClosuresBodies(InlineCodegen.java:456)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.inlineCall(InlineCodegen.java:365)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.genCallInner(InlineCodegen.java:149)
    at org.jetbrains.kotlin.codegen.CallGenerator.genCall(CallGenerator.kt:100)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2625)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.invokeMethodWithArguments(ExpressionCodegen.java:2583)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:44)
    at org.jetbrains.kotlin.codegen.Callable$invokeMethodWithArguments$1.invoke(Callable.kt:23)
    at org.jetbrains.kotlin.codegen.OperationStackValue.putSelector(StackValue.kt:65)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:109)
    at org.jetbrains.kotlin.codegen.StackValue.put(StackValue.java:102)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1727)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.generateBlock(ExpressionCodegen.java:1676)
    at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:56)
    at org.jetbrains.kotlin.codegen.CodegenStatementVisitor.visitBlockExpression(CodegenStatementVisitor.java:22)
    at org.jetbrains.kotlin.psi.KtBlockExpression.accept(KtBlockExpression.java:44)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.genQualified(ExpressionCodegen.java:283)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.genStatement(ExpressionCodegen.java:342)
    at org.jetbrains.kotlin.codegen.ExpressionCodegen.gen(ExpressionCodegen.java:312)
    at org.jetbrains.kotlin.codegen.MemberCodegen.generateInitializers(MemberCodegen.java:377)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateInitializers(ImplementationBodyCodegen.java:1099)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generatePrimaryConstructorImpl(ImplementationBodyCodegen.java:1038)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.access$300(ImplementationBodyCodegen.java:92)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen$3.doGenerateBody(ImplementationBodyCodegen.java:946)
    at org.jetbrains.kotlin.codegen.FunctionGenerationStrategy$CodegenBased.generateBody(FunctionGenerationStrategy.java:72)
    at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:378)
    at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:213)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generatePrimaryConstructor(ImplementationBodyCodegen.java:942)
    at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateConstructors(ImplementationBodyCodegen.java:397)
    at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:79)
    at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:118)
    at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:232)
    at org.jetbrains.kotlin.codegen.PackageCodegen.generateClassOrObject(PackageCodegen.java:145)
    at org.jetbrains.kotlin.codegen.PackageCodegen.generateFile(PackageCodegen.java:98)
    at org.jetbrains.kotlin.codegen.PackageCodegen.generate(PackageCodegen.java:61)
    at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.generatePackage(KotlinCodegenFacade.java:99)
    at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:77)
    at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:44)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:452)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:150)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:183)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:199)
    at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:154)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execAndOutputXml(CLICompiler.java:73)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$remoteIncrementalCompile$1.invoke(CompileServiceImpl.kt:247)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$remoteIncrementalCompile$1.invoke(CompileServiceImpl.kt:70)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$1$1.invoke(CompileServiceImpl.kt:421)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$1$1.invoke(CompileServiceImpl.kt:70)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:454)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$checkedCompile(CompileServiceImpl.kt:70)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$1.invoke(CompileServiceImpl.kt:420)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$1.invoke(CompileServiceImpl.kt:70)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive(CompileServiceImpl.kt:565)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive$default(CompileServiceImpl.kt:504)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:411)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.remoteIncrementalCompile(CompileServiceImpl.kt:244)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(TCPTransport.java:683)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/2057391342.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method org.jetbrains.kotlin.codegen.inline.ParametersBuilder.addCapturedParam, parameter original
    at org.jetbrains.kotlin.codegen.inline.ParametersBuilder.addCapturedParam(ParametersBuilder.kt)
    at org.jetbrains.kotlin.codegen.inline.LambdaInfo.addAllParameters(LambdaInfo.java:158)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner$1.visitMethodInsn(MethodInliner.java:223)
    at org.jetbrains.org.objectweb.asm.tree.MethodInsnNode.accept(MethodInsnNode.java:133)
    at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
    at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:311)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:111)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:95)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethod(AnonymousObjectTransformer.java:230)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethodAndUpdateGlobalResult(AnonymousObjectTransformer.java:191)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.doTransform(AnonymousObjectTransformer.java:144)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner$1.handleAnonymousObjectRegeneration(MethodInliner.java:180)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner$1.anew(MethodInliner.java:199)
    at org.jetbrains.org.objectweb.asm.commons.InstructionAdapter.visitTypeInsn(InstructionAdapter.java:478)
    at org.jetbrains.org.objectweb.asm.tree.TypeInsnNode.accept(TypeInsnNode.java:83)
    at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
    at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:311)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:111)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:95)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethod(AnonymousObjectTransformer.java:230)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.inlineMethodAndUpdateGlobalResult(AnonymousObjectTransformer.java:191)
    at org.jetbrains.kotlin.codegen.inline.AnonymousObjectTransformer.doTransform(AnonymousObjectTransformer.java:144)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner$1.handleAnonymousObjectRegeneration(MethodInliner.java:180)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner$1.anew(MethodInliner.java:199)
    at org.jetbrains.org.objectweb.asm.commons.InstructionAdapter.visitTypeInsn(InstructionAdapter.java:478)
    at org.jetbrains.org.objectweb.asm.tree.TypeInsnNode.accept(TypeInsnNode.java:83)
    at org.jetbrains.org.objectweb.asm.tree.InsnList.accept(InsnList.java:162)
    at org.jetbrains.org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:817)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:311)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:111)
    at org.jetbrains.kotlin.codegen.inline.MethodInliner.doInline(MethodInliner.java:95)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.inlineCall(InlineCodegen.java:392)
    at org.jetbrains.kotlin.codegen.inline.InlineCodegen.genCallInner(InlineCodegen.java:149)
    ... 107 more
Polygraph answered 27/10, 2016 at 2:4 Comment(9)
Can you add the code where you call this function?Blest
It's in the stack trace from the compiler error: { module -> module.levelSensor?.addListener(fiberListener { onLevelEvent() }) }Polygraph
This is a bug, please report at kotl.in/issueOeflein
If you use noinline instead of crossinline, it might work.Koger
Is it still an issue with the most recent version of Kotlin?Obsolescent
@RomanElizarov I just tested and this is still an issue in 1.1.51, although the error seems to be different. Here is a Gist. gist.github.com/zjuhasz/0e2d7ed86e9b4390e833876e500fe8e8. We were using Quasar before kotlin 1.1. we've switched to kotlinx.coroutines so I am just testing this by checking out a very old commit. I know it's still a bug in the Kotlin compiler but it's not actively in my way at this time. Edit: had to redo because I don't understand how SO comments work...Polygraph
@AlexanderUdalov could you perhaps expand on this to provide some form of answer to this question?Hypoblast
For reference, I reported a similar issue to youtrack hereSynder
I was getting "Couldn't inline method call '...' into", I solved it by changing crossline to noinline.Utility

© 2022 - 2024 — McMap. All rights reserved.