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

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

07cc3901ba91cc4fc0fee0d26944e314?s=47 scache
October 15, 2018

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

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

07cc3901ba91cc4fc0fee0d26944e314?s=128

scache

October 15, 2018
Tweet

Transcript

  1. Writing Your First Kotlin Compiler Plugin by Kevin Most (Introduction)

    CA.kt #7 scache @scal_ch AbemaTV, Inc.
  2. ❖ Writing Your First Kotlin Compiler Plugin by Kevin Most

    ❖ https://www.youtube.com/watch?v=w-GMlaziIyo
  3. Α͋͘Δ࣭໰

  4. Α͋͘Δ࣭໰ ❖ AnnotationProcessorͱ͸ҧ͏ͷʁ

  5. AnnotationProcessorͱͷൺֱ

  6. AnnotationProcessorͱͷൺֱ • AnnotationProcessor

  7. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌

  8. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ

  9. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒

  10. AnnotationProcessorͱͷൺֱ • AnnotationProcessor • ίϯύΠϧ࣌ • υΩϡϝϯτ • JavaίʔυΛੜ੒ •

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

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

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

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

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

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

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

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

    ❖ android-extensions: @ParcelizeͳͲ ❖ kotlin-serialization: Serializableͷ࣮૷Λੜ੒ ❖ MultiplatformରԠ
  19. Plugin ΞʔΩςΫνϟ Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension } Gradle

    Plugin } Kotlin Plugin
  20. Plugin ΞʔΩςΫνϟ Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • build.gradle͔ΒϓϥάΠ

    ϯͷઃఆΛಡࠐΉ • CommandLineProcessorʹ ઃఆΛ౉͢
  21. Plugin ΞʔΩςΫνϟ Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • ίϯύΠϥΦϓγϣϯͷɹ

    ಡΈࠐΈ • Extensionͷొ࿥
  22. Plugin ΞʔΩςΫνϟ Plugin Subplugin CommandLineProcessor ComponentRegistrar Extension Extension • ίʔυੜ੒෦෼

    • όΠτίʔυ(or LLVM IR) Λهड़ • extensionͷछྨ • ExpressionCodegenExtension • ClassBuilderInterceptorExtension • StorageComponentContainerContributor • IrGenerationExtension • …
  23. ίʔυྫ 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 }
  24. ίʔυྫ 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 }
  25. ίʔυྫ 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() }
  26. ❖ ଓ͖͸ ❖ Writing Your First Kotlin Compiler Plugin by

    Kevin Most ❖ https://www.youtube.com/watch?v=w-GMlaziIyo
  27. ࠷ޙʹ ❖ ॲཧͷྲྀΕ͸AnnotationProcessorͱࣅ͍ͯΔ ❖ JavaίʔυͰ͸ͳ͘όΠτίʔυΛੜ੒ ❖ CompilerPluginͷํ͕ࣗ༝౓͕ߴ͍ ❖ ·ͣ͸AnnotationProcessorΛݕ౼

  28. Have a nice Kotlin !