Kotlin 1.2 M2 released

Milestone release 2 of official supported Android language is out now 
10 August 2017   795

Jet Brains works hard to make Kotlin coders happy. Recently, Kotlin 1.2 M2 was released.

This released is focused on stability and bugfixes to Kotlin compiler and tooling. Also, there are some improvements of Kotlin standart library.  It also includes many of the tooling features available in the upcoming release of Kotlin 1.1.4.

Let's see what's inside!

Revised windowed/pairwise operations

Changes to hunked, windowed, pairwise functions:

  • windowed function now has its step parameter defaulting to 1.
    It also gets an additional optional parameter partialWindows, which controls what to do with incomplete windows in the end. By default it is false, which means incomplete windows are dropped.
  • pairwise function name was too confusing, it was unclear how it paired the elements together. Now it is called zipWithNext, so it is more clear that each element is zipped with the next element in a collection.

Common math operations in the standard library

kotlin.math package now released:

  • constants: PI and E;
  • trigonometric: cossintan and inverse of them: acosasinatanatan2;
  • hyperbolic: coshsinhtanh;
  • exponentation: pow (an extension function), sqrthypotexpexpm1;
  • logarithms: loglog2log10lnln1p;
  • rounding:
    • ceilfloortruncateround (half to even) functions;
    • roundToIntroundToLong (half to integer) extension functions;
  • sign and absolute value:
    • abs and sign functions;
    • absoluteValue and sign extension properties;
    • withSign extension function;
  • max and min of two values;
  • binary representation:
    • ulp extension property;
    • nextUpnextDownnextTowards extension functions;
    • toBitstoRawBitsDouble.fromBits (these are in the kotlin package).

The same set of functions (but without constants) is also available for Float arguments.
Most of these functions (except the binary representation group) are also available in JS, thus solving the problem of writing the same calculations for both platforms.

Full release notes:

Android

  • Android Extensions fails to compile when importing synthetic properties for layouts in other modules

Compiler

  • Switch warning to error for java-default method calls within 1.6 target
  • Do not use non-existing class for suspend markers
  • Exception on building gradle project with collection literals
  • Fix collection literals resolve in gradle-based projects

IDE. Inspections and Intentions

  • Circular autofix actions between redundant modality and non-final variable with allopen plugin 
  • "Protected in final" inspection works incorrectly with all-open
  • "Redundant modality" is not reported with all-open
  • Redundant "make open" for abstract class member with all-open

Standard Library

  • windowed function: make default step equals to 1, add partialWindows parameter
  • rename pairwise function to zipWithNext
  • Support math operations in stdlib
  • Provide Double and Float bit conversion functions as extensions

Tools. kapt

  • Kapt3, IC: Kapt does not generate annotation value for constant values in documented types

 

JetBrains to Roll Out Kotlin/Native 0.8

Version 0.8 of Kotlin/Native brings new features and bug fixes
13 July 2018   137

The project team of Kotlin / Native introduced the release of version 0.8. Corrections and additions have concerned the security of multithreaded programming, the expansion of library functionality and support for iOS devices. As always, alot of bugs are fixed.

Parallelism

Implemented the concept of object freezing

object Config {
  var width: Int = 10
  private set
  init {
    val file = fopen("config.txt", "r")
    if (file != null) {
              try {
              val buffer = ByteArray(2 * 1024)
                 while (true) {
                 val nextLine = fgets(buffer.refTo(0), buffer.size, file)?.toKString()
                 if (nextLine == null || nextLine.isEmpty()) break
                 val records = nextLine.split('=')
                 if (records.size != 2) continue
                 val key = records[0].trim()
                 val value = records[1].trim()
                 when (key) {
                         "width" -> width = value.toInt()
                            }
                          }
                        }
             } finally {
                fclose(file)
                    }
         }
}

This code considers the configuration file and will later receive the Config.width property. 

The Config file itself is divided for any number of threads or vorkers. After publication, the object is frozen and any attempt to change it will result in an exception (InvalidMutabilityException).

The second peculiarity of parallelism in the Kotlin / Native project is indivisible values and references. Let's add an image:

object Config {
private val icon_ = AtomicReference()
val icon: Image
get() = icon_.get()!!
fun updateIcon(file: String) {
val imageData = Image(file)
icon_.compareAndSwap(icon_.get(), imageData.freeze())
}
}

All information about the icon in the AtomicReference is frozen. Any changes are indivisible and similar information is visible to each client.

Kotlin Libraries

Starting v 0.8, the standard library (kotlin. *) is compatible with other platforms. Standard number generator and the function of mixing the collections are designed to eliminate the use of sharpened for a specific platform API. As an experiment, the project supports other libraries, for example, kotlinx.coroutines, kotlinx.serialization, and also the Ktor HTTP client.

Changes for iOS devices

Fixed issues with the publication in the App Store and the initialization of the platform. Support for the 32-bit ARM architecture of iOS processors, which allows using Kotlin / Native on older devices from Apple added.