The official Kotlin/Native documentation states that Kotlin/Native

..是Kotlin编译器基于LLVM的后端.

据我所知:

  • Kotlin编译器(kotlinc)生成.从Kotlin源文件中初始化文件(使用Java字节码).
  • 通用LLVM后端(与Kotlin无关)采用LLVM IR并将其转换为二进制代码.

Therefore, is Kotlin/Native converting Java bytecode into LLVM IR? If so, is it correct to state that Kotlin/Native is a LLVM backend? Does Kotlin code get compiled into LLVM IR? If not, what is the input and output of each compilation step? (e.g.: Kotlin -(kotlinc)-> Java bytecode -(LLVM backend-> native binary)

This篇博文指出,Kotlin前端编译器(我想它指的是kotlinc)生成了Kotlin IR,我从未读过它.

Kotlin编译器有一个前端,但有多个后端,这取决于您用来构建代码的插件.Kotlin/Native插件将Kotlin中间表示(IR)转换为本地代码(即机器可执行的代码).

Is this quote correct?

它告诉您,Java字节码、本机代码和JavaScript的编译过程是相同的.编译Kotlin代码,然后有3个后端编译器提供预期的输出格式(Java字节码、JavaScript、二进制代码).

最终的特定于平台的二进制文件是包含本地Kotlin标准库还是动态链接?

推荐答案

Kotlin编译器有一个前端,但有多个后端,这取决于您用来构建代码的插件.Kotlin/Native插件将Kotlin中间表示(IR)转换为本地代码(即机器可执行的代码).

Is this quote correct?

Yes, it's quite correct. The intermediate representation (IR) is a form that universally represents a Kotlin program, regardless of the platform. Then a platform-specific back-end translates the IR to the final binary form – the JVM class files for Kotlin/JVM, LLVM bitcode and other metadata packed into a *.klib for Kotlin/Native.

So, Kotlin/Native doesn't deal with the JVM bytecode in any way.

The intermediate representation is an implementation detail of the Kotlin compiler, and it's not used by any other consumer than the Kotlin compiler itself, so it's not a thing that a developer should care about. For the JVM, it's even kept in memory and never written to binaries. For Kotlin/Native, it's actually serialized and written into the *.klib to be reused.

它告诉您,Java字节码、本机代码和JavaScript的编译过程是相同的.编译Kotlin代码,然后有3个后端编译器提供预期的输出格式(Java字节码、JavaScript、二进制代码).

实际上,a part%的编译过程是相同的,即前端语言分析,包括解析、调用解析、类型推理、诊断和其他步骤,这些步骤不需要任何特定于平台的代码转换.即便如此,前端部分还是针对每个平台进行了调优,因为它们允许不同的语言功能集并提供不同的诊断集.

最后一个问题是,最终的特定于平台的二进制文件是否包含本地Kotlin标准库?或者它是动态链接的?

Currently, the standard library is statically linked into the resulting Kotlin/Native binaries.

Kotlin相关问答推荐

直接从SON解析NonEmptyList

Android前台服务 list —Altbeacon

Kotlin是否针对范围和进度优化sum()?

我可以在kotlin/java.util.scanner中跳过分隔符而不重复吗?

Kotlin 中命名构造函数的惯用方式

协程子作业(job)取消

Kotlin:调用 CoroutineScope.launch 与在协程内启动之间的区别

如何从 kotlin 中的数据类访问 val?

Kotlin - 创建指定长度的随机整数的 ArrayList?

Kotlin 中列表或数组的乘积

Moshi:解析单个对象或对象列表(kotlin)

包括登录Elvis operator?

如何在 Kotlin 中为变量设置监听器

ActivityOptions.makeSceneTransitionAnimation 在具有多个视图的 kotlin 中不起作用

如何为kotlin异常生成SerialVersionId?

如何在Kotlin中创建无限长的序列

Kotlin:使用自定义设置器时没有lateinit的解决方法?

查找是否在列表中找到具有特定属性值的元素

Kotlin,什么时候按map授权?

具有多个 parameter的 Kotlin 枚举