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

Context Receiversに思いを馳せる / Context Receivers

uzzu
October 05, 2022

Context Receiversに思いを馳せる / Context Receivers

DroidKaigi2022 Dialogs - 2022/10/05 14:20-14:45
https://droidkaigi.jp/2022/timetable/363729

uzzu

October 05, 2022
Tweet

More Decks by uzzu

Other Decks in Technology

Transcript

  1. Context Receiversʹ


    ࢥ͍Λ஘ͤΔ
    uzzu @ 2022/10/05 DroidKaigi 2022 DAY.01

    View Slide

  2. Cluster, Inc. All Rights Reserved. 2
    ஫ҙ
    2022/09࣌఺Ͱͷ


    ৘ใΛݩʹൃද͓ͯ͠Γ·͢


    ࢥ͍Λ஘ͤΔ಺༰ͳͷͰओ؍΋ؚ·Ε͓ͯΓ·͢


    Context Receivers͸ݱࡏprototypeஈ֊Ͱ͢


    ྃ͝ঝ͍ͩ͘͞

    View Slide

  3. Cluster, Inc. All Rights Reserved. 3
    ࣗݾ঺հ
    @uzzu




    Cluster, Inc.


    ιϑτ΢ΣΞΤϯδχΞ


    झຯ: VR, ࡶଟͳٕज़ݕূ, ಡॻ, DTM, ֨ήʔ, εϓϥ

    View Slide

  4. Cluster, Inc. All Rights Reserved. 4
    ClusterͷAndroidΞϓϦʹ͍ͭͯ
    AndroidΞϓϦ ࠾༻৘ใ
    AndroidΞϓϦΤϯδχΞืू
    ⬆ inroom (Unity as a Library)


    ⬅︎
    outroom (Native App)ɹɹɹ

    View Slide

  5. Cluster, Inc. All Rights Reserved. 5
    ΞδΣϯμ
    ɾContext Receivers͕དྷΔ·Ͱͷ͓͞Β͍


    ɾContext Receiversͱ͸ɺ࢖༻ྫ


    ɾContext Receiversͷ՝୊ɺࢥ͍


    ɾ·ͱΊ

    View Slide

  6. Cluster, Inc. All Rights Reserved. 6
    ContextReceivers͕དྷΔ·Ͱͷ͓͞Β͍
    KEEP(https://github.com/Kotlin/KEEP)


    YouTrack(https://youtrack.jetbrains.com/)


    Kotlin Slack(https://kotlinlang.slack.com/)


    ͍͔ͭ͋͘Δ͕ͦͷதͰ΋2ͭͷissueΛൈਮ

    View Slide

  7. Cluster, Inc. All Rights Reserved. 7
    Compile-time Extension Interfaces
    https://github.com/Kotlin/KEEP/pull/87


    2017/10ࠒ


    ɾ࠷ॳظ͸ʮType Classesʯͱ͍͏λΠτϧͰproposal͕ॻ͔Ε͍ͯͨ


    ɾʮ͍ͭʹKotlinʹ΋ܕΫϥε͕དྷΔ…?!ʯͱ͍͏ࣄͰք۾͸੝Γ্͕Δ

    View Slide

  8. Cluster, Inc. All Rights Reserved. 8
    Compile-time Extension Interfaces
    https://github.com/Kotlin/KEEP/pull/87

    View Slide

  9. Cluster, Inc. All Rights Reserved. 9
    Compile-time Extension Interfaces
    https://github.com/Kotlin/KEEP/pull/87
    ɾcompanion objectͱͷ໾ׂͷॏෳ


    ɾJVMͱͷ૬ޓӡ༻


    ɾෳ਺ͷϨγʔόʹର͢Δ֦ுߏจ͕ඞཁ


    ɾimplicit parameterͷ೉͠͞


    ɾetc…

    View Slide

  10. Cluster, Inc. All Rights Reserved. 10
    Multiple receivers on extension functions/properties
    https://youtrack.jetbrains.com/issue/KT-10468


    https://youtrack.jetbrains.com/issue/KT-42435

    View Slide

  11. Cluster, Inc. All Rights Reserved. 11
    ͦͯ͠Context Receivers΁
    https://github.com/Kotlin/KEEP/issues/259


    https://github.com/Kotlin/KEEP/blob/master/proposals/context-
    receivers.md


    ឯ༨ۂંʹ͍ͭͯ΋Proposalʹॻ͔Ε͍ͯΔ


    (Alternative approaches and design tradeoffs)


    1.6.20-M1 ʹͯPrototypeͱͯ͠ϦϦʔε


    https://blog.jetbrains.com/kotlin/2022/02/kotlin-1-6-20-m1-
    released/


    freeCompilerArgs = listOf("-Xcontext-receivers")

    View Slide

  12. Cluster, Inc. All Rights Reserved. 12
    Context ReceiversͷGoal (ͷ͏ͪ2͚ͭͩ঺հ)
    ɾίϯςΩετந৅ԽΛهड़͢ΔͨΊͷ


    ɹmember extension(ϝϯόʔ֦ு)ΛऔΓআ͘

    View Slide

  13. Cluster, Inc. All Rights Reserved. 13
    Context ReceiversͷGoal (ͷ͏ͪ2͚ͭͩ঺հ)

    View Slide

  14. Cluster, Inc. All Rights Reserved. 14
    Context ReceiversͷGoal (ͷ͏ͪ2͚ͭͩ঺հ)

    View Slide

  15. Cluster, Inc. All Rights Reserved. 15
    Context ReceiversͷGoal (ͷ͏ͪ2͚ͭͩ঺հ)

    View Slide

  16. Cluster, Inc. All Rights Reserved. 16
    Context ReceiversͷGoal (ͷ͏ͪ2͚ͭͩ঺հ)
    ɾKotlinͷܕγεςϜͰෳ਺ͷϨγʔόΛ࣋ͭ


    ɹίʔυϒϩοΫΛදݱͰ͖ΔΑ͏ʹ͢Δ

    View Slide

  17. Cluster, Inc. All Rights Reserved. 17
    Context Receiversͷͦͷଞͷྫ
    ɾίϯετϥΫλͷӅṭ + Contextࢀর

    View Slide

  18. Cluster, Inc. All Rights Reserved. 18
    Context Receiversͷͦͷଞͷྫ
    ɾOverloading(※஫ҙ఺͋Γ)
    ͜͏͍͏ίʔυ͸ॻ͔ͳ͍Ͱɺͳ಺༰΋Proposalʹهࡌ͞Ε͍ͯΔ


    (contexts-and-coding-style)

    View Slide

  19. Cluster, Inc. All Rights Reserved. 19
    ɾContext Functionͷείʔϓ֊૚ͷਂ͞(ݕ౼த)


    ɾReflectionະରԠ(Prototypeஈ֊Ͱ͸΍Βͳͦ͏ͳؾ͕)


    ɾΤοδέʔε΁ͷରԠ (Kotlin 1.8.0ͰҰ෦मਖ਼ࡁ)


    ɾSyntax Highlighting(Τϥʔ͸ు͘ͷͰے೑Ͱ)


    ɾetc…
    Context Receiversͷ՝୊(Future Work)

    View Slide

  20. Cluster, Inc. All Rights Reserved. 20
    (ϓϩτλΠϓஈ֊Ͱͱ΍͔͍͘͏΂͖


    Ͱ͸ͳ͍ͷ͸ঝ஌Ͱ)


    ɾهड़ͷબ୒ࢶ͕ଟͯ͋͘Μ·Γࠓ·ͰͷKotlinΒ͘͠ͳ͍Α͏ͳؾ͕͢Δͷ͕


    ɹݸਓతʹ͸ٯʹ໘ന͍


    ɾCompile-time extensionํ໘Ͱ্͕ͬͨ՝୊͔ΒݟΔʹՄೳͳهड़͸


    ɹ͜Ε͔ΒߜΒΕ͍ͯͬͯཉ͍͠ͳʔͱࢥ͍ͬͯΔ

    ɹ(ཞ༻͕ාͯ͘ਂ͘͸৮Εͳ͍ਓʑ͕͍ͦ͏ͳͷ͸΋͍ͬͨͳ͍ɺͱ͍͏ҙຯͰ)


    ɾݱঢ়Ͱ΋ᙱ͍ͱ͜Ζʹख͕ಧ͘ͷͰݸਓతʹ͸ॿ͔Δ
    Context Receivers΁ͷࢥ͍

    View Slide

  21. Cluster, Inc. All Rights Reserved. 21
    Context Receivers΁ͷࢥ͍
    ɾͦ΋ͦ΋ͳͥ ”Context” ʹͳͬͨͷ͔…ʁ


    ɹ=> Multiple receiversͷϓϩτλΠϓͷஈ֊Ͱ


    ɹɹύϥϝʔλΛஔ͖׵͑ΔͨΊʹ͋ΔΘ͚Ͱ͸ͳ͘


    ɹɹؔ਺ݺͼग़͠ͷͨΊͷίϯςΩετΛ௥Ճ͢Δҝͷ


    ɹɹઃܭ͕ඞཁͩͱؾ͍ͮͨҝ


    ɹɹ=> ύϥϝʔλͷ୅ΘΓʹ࢖༻͢Δ৔߹ʹ͸


    ɹɹɹهड़͕৑௕ʹͳΔΑ͏׶͍͑ͯͯ͠Δ


    ɹɹɹ=> ཞ༻͞Εͳ͍Α͏ʹ
    https://youtrack.jetbrains.com/issue/KT-10468/Multiple-receivers-on-extension-functionsproperties#focus=Comments-27-4608759.0-0

    View Slide

  22. Cluster, Inc. All Rights Reserved. 22
    Context Receivers΁ͷࢥ͍
    ɾͦ΋ͦ΋ͳͥ ”Context” ʹͳͬͨͷ͔…ʁ


    ɹ=> Multiple receiversͷϓϩτλΠϓͷஈ֊Ͱ


    ɹɹύϥϝʔλΛஔ͖׵͑ΔͨΊʹ͋ΔΘ͚Ͱ͸ͳ͘


    ɹɹؔ਺ݺͼग़͠ͷͨΊͷίϯςΩετΛ௥Ճ͢Δҝͷ


    ɹɹઃܭ͕ඞཁͩͱؾ͍ͮͨҝ


    ɹɹ=> ύϥϝʔλͷ୅ΘΓʹ࢖༻͢Δ৔߹ʹ͸


    ɹɹɹهड़͕৑௕ʹͳΔΑ͏׶͍͑ͯͯ͠Δ


    ɹɹɹ=> ཞ༻͞Εͳ͍Α͏ʹ
    https://youtrack.jetbrains.com/issue/KT-10468/Multiple-receivers-on-extension-functionsproperties#focus=Comments-27-4608759.0-0
    ͻΐͬͱͯ͠ਅ໘໨ʹimplicit parameterʹcode generationͳΓͰ


    ͪΌΜͱରԠͰ͖ΔΑ͏ʹɺ༨നͱͯ͠࢒͍ͯ͠ΔͷͩΖ͏͔…ʁ


    ؾʹͳΔ…ͦΘͦΘ…ৄ͍͠ਓڭ͍͑ͯͩ͘͞

    View Slide

  23. Cluster, Inc. All Rights Reserved. 23
    ·ͱΊ
    ɾContext Receivers͸ܕΫϥεͷProposal͔Β

    ɹෳ਺ͷϨγʔόʹର͢Δ֦ுߏจ͕ඞཁͱ͍͏

    ɹྲྀΕͰ࡞ΒΕͨ


    ɾKotlinʹͯ͠͸௝ࣗ͘͠༝౓ͷߴ͍Proposal


    ɾָ͍͠ͷ͸ࠓ͚͔ͩ΋…ʁ

    ɹProposalΛಡΜͰָ͘͠ɹ ʂ


    View Slide

  24. Context Receiversʹ


    ࢥ͍Λ஘ͤΔ
    uzzu @ 2022/10/05 DroidKaigi 2022 DAY.01

    View Slide