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

[紹介]Writing Your First Kotlin Compiler Plugin ...

scache
October 15, 2018

[紹介]Writing Your First Kotlin Compiler Plugin by Kevin Most

KotlinConfの"Writing Your First Kotlin Compiler Plugin" by Kevin Most
というセッションがとてもよかったので、その紹介です

scache

October 15, 2018
Tweet

More Decks by scache

Other Decks in Programming

Transcript

  1. ❖ Writing Your First Kotlin Compiler Plugin by Kevin Most

    ❖ https://www.youtube.com/watch?v=w-GMlaziIyo
  2. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

    Kotlin/JavaίʔυΛॲཧ • Multiplatform • Compiler Plugin • ίϯύΠϧ࣌
  3. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

    Kotlin/JavaίʔυΛॲཧ • Multiplatform • Compiler Plugin • ίϯύΠϧ࣌ • υΩϡϝϯτ
  4. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

    Kotlin/JavaίʔυΛॲཧ • Multiplatform • Compiler Plugin • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaόΠτίʔυ(or LLVM IR)Λੜ੒
  5. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

    Kotlin/JavaίʔυΛॲཧ • Multiplatform • Compiler Plugin • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaόΠτίʔυ(or LLVM IR)Λੜ੒ • KotlinίʔυΛॲཧ
  6. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

    Kotlin/JavaίʔυΛॲཧ • Multiplatform • Compiler Plugin • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaόΠτίʔυ(or LLVM IR)Λੜ੒ • KotlinίʔυΛॲཧ • Multiplatform
  7. Compiler Plugin ྫ ❖ all-open: ࢦఆͨ͠ΫϥεΛopen classʹ͢Δ ❖ no-arg: ࢦఆͨ͠ΫϥεͷҾ਺ͳ͠ίϯετϥΫλੜ੒

    ❖ android-extensions: @ParcelizeͳͲ ❖ kotlin-serialization: Serializableͷ࣮૷Λੜ੒ ❖ MultiplatformରԠ
  8. Plugin ΞʔΩςΫνϟ Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • ίʔυੜ੒෦෼

    • όΠτίʔυ(or LLVM IR) Λهड़ • extensionͷछྨ • ExpressionCodegenExtension • ClassBuilderInterceptorExtension • StorageComponentContainerContributor • IrGenerationExtension • …
  9. ίʔυྫ fun prime(n: Int): Long { println("-> prime(n=$n)") val startTime

    = System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("<- prime [ran in $timeToRun ms]") return result }
  10. ίʔυྫ fun prime(n: Int): Long { println("-> prime(n=$n)") val startTime

    = System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("<- prime [ran in $timeToRun ms]") return result }
  11. ίʔυྫ fun prime(n: Int): Long { println("-> prime(n=$n)") val startTime

    = System.currentTimeMillis() val result = primeNumberSequence.take(n).last() val timeToRun = System.currentTimeMillis() - startTime println("<- prime [ran in $timeToRun ms]") return result } @DebugLog fun prime(n: Int): Long { return primeNumberSequence.take(n).last() }
  12. ❖ ଓ͖͸ ❖ Writing Your First Kotlin Compiler Plugin by

    Kevin Most ❖ https://www.youtube.com/watch?v=w-GMlaziIyo