Kotlin/Native v0.2 is out

Posted on by Nikolay Igotti

We’re happy to announce the release of Kotlin/Native v0.2, a feature and bugfix update to Kotlin/Native Technology Preview. This update adds support for coroutines and cross-module inline functions support, along with bugfixes and improvements all over the place.

This release includes samples showing how to use coroutines for concurrent non-blocking IO, a GUI application using GTK, as well as a TensorFlow machine learning framework client contributed by Julius Kunze.

For example, code as easy as

var connectionId = 0
acceptClientsAndRun(listenFd) {
  memScoped {
    val bufferLength = 100L
    val buffer = allocArray<ByteVar>(bufferLength)
    val connectionIdString = "#${++connectionId}: ".cstr
    val connectionIdBytes = connectionIdString.getPointer(this)
    try {
      while (true) {
        val length = read(buffer, bufferLength)
        if (length == 0L) break
        write(connectionIdBytes, connectionIdString.size.toLong())
        write(buffer, length)
      }
    } catch (e: IOException) {
      println("I/O error occurred: ${e.message}")
    }
  }
}

can be used to process multiple concurrent socket IO with coroutines and serve each client individually and concurrently.

And to create a GTK button with an event listener, just do:

 val button = gtk_button_new_with_label("Click me!")!!
 g_signal_connect(button, "clicked",
   staticCFunction { _: CPointer<GtkWidget>?, _: gpointer? -> println("Hi from Kotlin") }
)

So v0.2 release allows  to create fully functional small-footprint native applications written in Kotlin.

Both compilation and runtime performance were significantly improved, size of redistributable decreased.

The complete list of changes in this release can be found in the changelog.

Pre-built binaries for Linux and MacOS hosts are available.

Comments below can no longer be edited.

30 Responses to Kotlin/Native v0.2 is out

  1. Guangyu says:

    April 12, 2012

    Good news! I have downloaded the newest version, It’s awesome.
    Thanks for the great work!

  2. Neil says:

    April 12, 2012

    Great! I’m anxious to try it out. Could you fix the code snippet formatting in the online documention? Newlines in the text are not included (or something) and the code appears mostly on one line which obviously makes it very hard to read. I am using IE7. For example, the code example on this page is displayed as 8 lines.

    • Andrey Breslav says:

      April 12, 2012

      IE support is on the way (for now, you can use Chrome or FireFox)

  3. Sergii Rudchenko says:

    April 12, 2012

    Thanks! I’m eager to get started with Kotlin as a main language 🙂
    Andrey, are there any plans on Android support?

    • Andrey Breslav says:

      April 12, 2012

      Yes, there’re are. Some users report that basic Kotlin code runs fine on Android now.

  4. Jan Kotek says:

    April 12, 2012

    Great, this is best news of this month for me. Thanks guys.

  5. Bikal Gurung says:

    April 13, 2012

    What is the status of the javascript backend for this release? And also do you have any release date for the final product, i.e. version 1.0? Is this happening this year or in the next few months?

    • Andrey Breslav says:

      April 13, 2012

      The JavaScript back-end is working, but the IDE UI and other tools do not provide access to it yet. This will be fixed pretty soon.

      On the release date: no, we don’t have a date for 1.0, because we think that a language is ready for a release after massive validation, i.e. production use. So, JetBrains is going to use Kotlin in production for a while, and only then release a 1.0. Of course, a stable beta will be available earlier.

      • Tommy says:

        April 13, 2012

        I think you have a great opportunity here if you can make the Javascript backend supported fully.

        With it working I see no use for Google Closure, Coffeescript and lots of other projects.

        Please grab that opportunity.

        • Andrey Breslav says:

          April 13, 2012

          We will. Thanks

        • Mirco says:

          April 21, 2012

          Yes! Full Javascript support would be great. The world is craving for a modern statically typed language compiling to javascript with an great mature IDE.

  6. Vadim says:

    April 16, 2012

    What about compilation speed? Have you measured it (comparing to Java and Scala)?

    • Andrey Breslav says:

      April 16, 2012

      To measure compilation speed properly we’d need a big Kotlin codebase that does not exist yet. Some micro-measurements show that there’s quite some space for improvement in compilation speed, and we are working on it constantly. To date, no language feature seems to be a performance blocker in Kotlin, though many optimizations and a lot of profiling work is to be done.

  7. Roadmap de #kotlin | Kotlin.es says:

    August 22, 2015

    […] oficial en inglés, […]

  8. Pavel says:

    May 12, 2017

    Congrats!
    Could you provide a tutorial to build simple kotlin-native app with IntelliJ Idea?

  9. Kotlin/Native v0.2 is out (Official announcement from Jetbrains) | Ace Infoway says:

    May 12, 2017

    […] is out (Official announcement from Jetbrains) {$excerpt:n} submitted by /u/michalg82 [link] [comments] Source: […]

  10. Nikolay Igotti says:

    May 12, 2017

    IDE support for Kotlin/Native is in progress, you may try to use Gradle support in IDEA along with Kotlin/Native Gradle plugin (see https://github.com/JetBrains/kotlin-native/blob/master/GRADLE_PLUGIN.md)

  11. Kotlin/Native v0.2 发布,将 Kotlin 编译成机器码 | News Pod says:

    May 13, 2017

    […] 发布主页 […]

  12. Clóvis Valadares says:

    May 14, 2017

    When a windows version?

    • Nikolay Igotti says:

      May 14, 2017

      Windows version is being worked on, but we cannot provide ETA yet.

  13. Al says:

    May 14, 2017

    Does the existence of Kotlin Native mean there will be proper tail call elimination even without the JVM supporting it? I’ve always felt that lacking this is annoying considering it’s entirely technically possible even on the JVM if resources were invested to make it a reality (it’s just not important to Oracle’s customers for Java). Even Microsoft’s F# supports these optimizations despite running on the CLR.

    • Nikolay Igotti says:

      May 14, 2017

      For tail recursion case there’s ‘tailrec’ keyword, which is being supported in Native as well. For other cases, tail call elimination could be done by LLVM backend for some cases.

  14. Marcel Bradea says:

    May 19, 2017

    Guys where are Kotlin feature requests tracked? Can’t find anywhere to post this.

    Anyways our feedback from maintaining a full dual-platform Swift/Kotlin codebase (same engineer implements features natively in both platforms) is that there are still several features that Kotlin as a language still lacks in order to be on par with Swift and thus iOS.

    One in particular that comes up constantly is the lack of lateinit in delegated properties.
    ie: There is essentially no way to convert the following Swift code in Kotlin:

    var link:Link! {
        didSet {
            // hydrate
            hydrate()
        }
    }
    

    The closest Kotlin equivalent forces the variable to be optional, which loses the semantic and is against the whole Kotlin/Swift optionals movement (ie: forces you to use a nullable field for something that is semantically non-null):

    // Closest current workaround: use a backing field with accessor wrapper 
    private var _link:Link? by Delegates.observable<Link?>( null ){ property, oldValue, newValue ->
        // hydrate
        hydrate()
    }
    var link:Link
        get() = _link!!
        set( newValue ){
            _link = newValue
        }
    

    Of course the real solution is to allow ‘lateinit’ to be used in conjunction with delegated properties:

    // PROPOSED
    lateinit private var link:Link by Delegates.observable<Link?>(/*NOTE: no default value*/){ property, oldValue, newValue ->
        // hydrate
        hydrate()
    }
    
    • Nikolay Igotti says:

      May 19, 2017

      Please use Kotlin issue tracker here: https://youtrack.jetbrains.com/issues/KT

    • Alexander Udalov says:

      May 19, 2017

      Wouldn’t declaring a custom delegate help here?

      class PropertyWithOnSetAction(private val onSet: () -> Unit) : ReadWriteProperty {
          private var value: T? = null
      
          override fun getValue(thisRef: Any?, property: KProperty<*>): T =
                  value ?: error("Property ${property.name} is not initialized yet")
      
          override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
              this.value = value
              onSet()
          }
      }
      
      var link: Link by PropertyWithOnSetAction { hydrate() }
      
      • Marcel Bradea says:

        May 19, 2017

        Thanks for that example Alexander.

        I bring this up in particular because if you are to support iOS native, this is an extremely common scenario in literally every Swift codebase I have seen – and has no current out-of-box Kotlin equivalent.

        I don’t think requiring teams to make their own custom delegated properties is the way. This needs to be standardized and provided either at the language level or in the base Kotlin libraries (ie: delegates.observable).

        I’ve filed an issue for it here: https://youtrack.jetbrains.com/issue/KT-17979

        Congrats again to the huge Android/Google news guys.

  15. Roman says:

    May 20, 2017

    Have you done any benchmarking of Kotlin Native vs Kotlin JVM ? Which one is expected to have better performance?

    • Nikolay Igotti says:

      May 20, 2017

      Performance is multidimensional notion, so it really depends on what is measured. Startup performance, memory management pauses and pure computations are likely better with Kotlin/Native, while massive object manipulations shall be better with Kotlin/JVM. Also note that current Kotlin/Native runtime wasn’t optimized, unlike modern JVMs, where thousands engineer/years spent on optimizations.

      • Roman says:

        May 20, 2017

        I see, so it depends on particular application. Is it possible to use two runtimes simulatneousy and how interop will look like? Can I for example call K/N funciton from K/JVM and pass reference to JVM managed object as a parameter?

        • Nikolay Igotti says:

          May 20, 2017

          Kotlin/JVM -> Kotlin/Native interop is not currently supported, beyond generic Kotlin/JVM -> C interop. Arbitrary object interoperability is unlikely to be supported soon.

Subscribe

Subscribe for updates