Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Экспериментальные и релизные фичи в Kotlin 1.3

Экспериментальные и релизные фичи в Kotlin 1.3

Станислав Ерохин рассказал про "экспериментальные и релизные фичи в 1.3".

Поговорили про будущий релиз Kotlin 1.3 — что нового будет добавлено, почему некоторое фичи будут экспериментальными и что это вообще означает. Обсудили новый back-end и зачем он нужен. Ну и напоследок Станислав рассказал про новый type inference и возможности, которые он привнесет.

More Decks by St. Petersburg Kotlin User Group

Other Decks in Programming

Transcript

  1. Disclaimer • Kotlin 1.3 in active developement • Everything in

    this talk just plans • Everything can be changed • No guarantees
  2. Coroutines • kotlin.coroutines.experimental→kotlin.coroutine • For old coroutines – support library

    since ~1.4 • In ~1.3 old/new coroutines interop these are just plans – no promises
  3. Coroutines changes • Performance improvements - do not generate state-machine

    where it isn’t nesesary • Supported all inline-related functionality • Callable reference on suspend function • API changes these are just plans – no promises
  4. Coroutines: Continuation interface Continuation<in T> { fun resume(value: T) fun

    resumeWithException(exception:Throwable) } class Result<out T> { val value: T? val exception: Throwable? } interface Continuation<in T> { fun resume(result: Result<T>) } these are just plans – no promises
  5. Inline class Result inline class Result<out T>(val o: Any?) {

    val value: T? get() = if (o is Box) null else o as T val exception: Throwable? get() = (o as? Box).exception } private class Box(val exception: Throwable) these are just plans – no promises
  6. Inline classes • Only one field allowed • Runtime representation

    – inner object or box wrapper • Box wrapper for generics – List<Result> vs List<Any?> • Primitive types supported these are just plans – no promises
  7. Unsigned arithmetics • For every primitive create corresponding inline class

    • Define arithmetics operations for them • Handle toString properly • Experimental in some future version inline class UInt(val i: Int) inline class ULong(val l: Long) these are just plans – no promises
  8. @JvmDefault • Like default in java 8 • In 1.2.x

    you can use it with opt-in flag • Probably will be released in 1.3 these are just plans – no promises
  9. Contract system fun test(x: Any) { check(x is String) println(x.length)

    } fun check(value: Boolean) { contract { returns() implies value } if (!value) throw … } these are just plans – no promises
  10. Contract system fun test() { val x: String run {

    x = "Hello” } println(x.length) } fun <R> run(block: () -> R): R { contract { callsInPlace(block, EXACTLY_ONCE) } return block() } these are just plans – no promises
  11. Type inference tweak: @NoInfer fun print(c: Collection<Any>) { ... }

    val c: Collection<Any> print(c.filterIsInstance()) print(c.filterIsInstance<String>()) fun <R> Iterable<*>.filterIsInstance(): List<@NoInfer R> these are just plans – no promises
  12. Type inference tweaks • @NoInfer, @Exact, @OnlyInputTypes • Now used

    in stdlib • Will be available with opt-in flag in 1.2.x these are just plans – no promises
  13. SAM for java methods static void test(Factory f, Runnable r)

    interface Factory { String produce(); } fun use(f: Factory) { test(f) { } // Factory != () → String } // fun test(Factory, Runnable) // fun test(() → String, () → Unit) these are just plans – no promises
  14. SAM for kotlin methods & interfaces fun test(r: Runnable) {…}

    sam interface Predicate<T> { fun test(t: T): Boolean } fun Collectio<T>.filter(p:Predicate<T>) :Collection<T> {…} fun use() { test { println(“Hello”) } val l = listOf(-1, 2, 3) l.filter { it > 0 } } these are just plans – no promises
  15. Smart inference for builders fun <T> buildList(l: MutableList<T>.()→ Unit) :List<T>

    {…} val list = buildList { add("one") add("two") } these are just plans – no promises
  16. New type inference engine • Experimental in ~1.3 • A

    lot of bugs fixed (~ ½ inference bugs) • Supported SAM conversion for Kotlin classes • Improved SAM conversion for java classes • Smart inference for builders these are just plans – no promises
  17. Progressive mode • One key that enable all experimental features

    • Compiler fixes in patch versions (1.2.x) • Fast deprecation cycle these are just plans – no promises
  18. Compiler scheme Front-end PSI + semantic info map JVM BE

    JS BE .class .js bin BE IR JVM Codogen JS Codogen LLVM Common BE FE IR these are just plans – no promises
  19. IR Back-end’s • JVM/JS BE by IR will be experimental

    in ~1.3.x • Native BE already use IR • Multiplatform libraries contains IR • IR as public API: - plugins for IR transformations - “replacement” for annotation processors these are just plans – no promises