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

Add support for unsigned integers (UByte UShort UInt ULong) #310

Closed
LanderlYoung opened this issue Dec 18, 2018 · 3 comments
Closed

Add support for unsigned integers (UByte UShort UInt ULong) #310

LanderlYoung opened this issue Dec 18, 2018 · 3 comments
Labels

Comments

@LanderlYoung
Copy link

LanderlYoung commented Dec 18, 2018

Kotlin 1.3 introduced unsigned integers, but it seems that kotlinx.serialization can't handle them. However some serialization solution like (protobuf) does have unsigned types. Please add support for them, thanks.

I have such code

@Serializable
data class UnsignedTest(
        val x: UInt
)

and the compiler complains:

e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
Cause: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILkotlin/UInt;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
bytecode:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILkotlin/UInt;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
File being compiled at position: (82,1) in /Users/young/Documents/github/Kotlin-mpp/SharedCode/src/commonMain/kotlin/io/github/landerlyoung/kotlin/mpp/zhihudaily/model.kt
The root cause was thrown at: TransformationMethodVisitor.java:88
File being compiled at position: file:///Users/young/Documents/github/Kotlin-mpp/SharedCode/src/commonMain/kotlin/io/github/landerlyoung/kotlin/mpp/zhihudaily/model.kt
The root cause was thrown at: FunctionCodegen.java:1004
	at org.jetbrains.kotlin.codegen.CompilationErrorHandler.lambda$static$0(CompilationErrorHandler.java:24)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:74)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:97)
	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:68)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:47)
	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:39)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:446)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:142)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:362)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:225)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:91)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:103)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:606)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:455)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1029)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
	at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1071)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1028)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:454)
	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:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
	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$0(TCPTransport.java:683)
	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: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILkotlin/UInt;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
bytecode:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILkotlin/UInt;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
File being compiled at position: (82,1) in /Users/young/Documents/github/Kotlin-mpp/SharedCode/src/commonMain/kotlin/io/github/landerlyoung/kotlin/mpp/zhihudaily/model.kt
The root cause was thrown at: TransformationMethodVisitor.java:88
	at org.jetbrains.kotlin.codegen.FunctionCodegen.endVisit(FunctionCodegen.java:1004)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethodBody(FunctionCodegen.java:488)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:264)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.generateMethod(FunctionCodegen.java:182)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.JVMCodegenUtilKt.generateMethod(JVMCodegenUtil.kt:129)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializableCodegenImpl.generateInternalConstructor(SerializableCodegenImpl.kt:64)
	at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCodegen.generateSyntheticInternalConstructor(SerializableCodegen.kt:39)
	at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializableCodegen.generate(SerializableCodegen.kt:33)
	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializableCodegenImpl$Companion.generateSerializableExtensions(SerializableCodegenImpl.kt:51)
	at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension.generateClassSyntheticParts(SerializationCodegenExtension.kt:29)
	at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateSyntheticPartsAfterBody(ImplementationBodyCodegen.java:440)
	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:130)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:300)
	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:284)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassOrObject(PackageCodegenImpl.java:161)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:86)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:119)
	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:66)
	... 44 more
Caused by: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't transform method node:
<init> (ILkotlin/UInt;Lkotlinx/serialization/SerializationConstructorMarker;)V:
   L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
    ILOAD 1
    ICONST_1
    IAND
    ICONST_0
    IF_ICMPNE L1
    NEW kotlinx/serialization/MissingFieldException
    DUP
    LDC "x"
    INVOKESPECIAL kotlinx/serialization/MissingFieldException.<init> (Ljava/lang/String;)V
    CHECKCAST java/lang/Throwable
    ATHROW
   L1
    ALOAD 0
    ILOAD 2
    PUTFIELD io/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest.x : I
    RETURN
   L2
    LOCALVARIABLE this Lio/github/landerlyoung/kotlin/mpp/zhihudaily/UnsignedTest; L0 L2 0
    LOCALVARIABLE seen I L0 L2 1
    LOCALVARIABLE x Lkotlin/UInt; L0 L2 2
    LOCALVARIABLE serializationConstructorMarker Lkotlinx/serialization/SerializationConstructorMarker; L0 L2 3
    MAXSTACK = 3
    MAXLOCALS = 4

Cause: AFTER mandatory stack transformations: incorrect bytecode
Element is unknownThe root cause was thrown at: MethodVerifier.kt:28
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.java:88)
	at org.jetbrains.kotlin.codegen.FunctionCodegen.endVisit(FunctionCodegen.java:992)
	... 61 more
Caused by: java.lang.AssertionError: AFTER mandatory stack transformations: incorrect bytecode
	at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:28)
	at org.jetbrains.kotlin.codegen.optimization.transformer.CompositeMethodTransformer.transform(CompositeMethodTransformer.kt:25)
	at org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor.performTransformations(OptimizationMethodVisitor.kt:62)
	at org.jetbrains.kotlin.codegen.TransformationMethodVisitor.visitEnd(TransformationMethodVisitor.java:65)
	... 62 more
Caused by: java.lang.RuntimeException: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 16: Expected I, but found R
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:34)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.analyze(MethodTransformer.java:44)
	at org.jetbrains.kotlin.codegen.optimization.MethodVerifier.transform(MethodVerifier.kt:26)
	... 65 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 16: Expected I, but found R
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:295)
	at org.jetbrains.kotlin.codegen.optimization.transformer.MethodTransformer.runAnalyzer(MethodTransformer.java:31)
	... 67 more
Caused by: org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException: Expected I, but found R
	at org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier.copyOperation(BasicVerifier.java:95)
	at org.jetbrains.org.objectweb.asm.tree.analysis.BasicVerifier.copyOperation(BasicVerifier.java:47)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Frame.execute(Frame.java:277)
	at org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:200)
	... 68 more

> Task :SharedCode:compileKotlinAndroid FAILED
@Qubitium
Copy link

Qubitium commented Sep 3, 2019

Any update to this? Uint are inline classes and without inline class support, there is no way to do Uint support. Can we expect this be completed in 2019?

@sandwwraith
Copy link
Member

@diegomontoya It's in our radar, so it definitely would be finished before 1.0 release. We also want to complete this as soon as possible :)

@qwwdfsad
Copy link
Collaborator

Closing as duplicate of #259

Unfortunately, it won't happen in the 1.0.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants