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

Catch Up with Swift 5.10

ojun
March 07, 2024

Catch Up with Swift 5.10

ojun

March 07, 2024
Tweet

More Decks by ojun

Other Decks in Programming

Transcript

  1. Catch Up with Swift 5.10 SE-0327: On Actors and Initialization

    SE-0383: Deprecate @UIApplicationMain and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables
  2. SE-0404: Allow Protocols to be Nested in Non-Generic Contexts Swift

    5.10·Ͱ͸ɺඇδΣωϦοΫͳߏ଄ମɾΫϥεɾྻڍܕɾΞΫλʔ಺ʹ ଞͷಉྨͷܕΛωετ͢Δ͜ͱ͸Մೳͩͬͨ ҰํͰɺprotocol Λωετ͢Δ͜ͱ͸ෆՄೳͩͬͨ ͜ͷϓϩϙʔβϧʹΑΓɺωετ͞Εͨ protocol Λදݱ͢Δ͜ͱ͕Մೳͱͳͬͨ
  3. Swift 5.10 SE-0327: On Actors and Initialization SE-0383: Deprecate @UIApplicationMain

    and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables 􀇻
  4. count ͸ MainActor ʹִ཭͞Ε͍ͯΔ message ͸ SomeGlobalActor ʹִ཭͞Ε͍ͯΔ ॳظԽ͕ҟͳΔΞΫλʔʹΑͬͯߦΘΕΔͨΊ σʔλڝ߹ͷՄೳੑ͕͋Δ

    ͜Ε͸ɺҟͳΔΞΫλʔ͕ಉ࣌ʹҟͳΔεϨουͰ ࣮ߦ͞ΕΔͨΊɺ༧ظ͠ͳ͍λΠϛϯάͰ͜ΕΒͷ ϓϩύςΟ͕ॳظԽ͞ΕΔՄೳੑ͕͋ΔͨΊ
  5. Swift 5.10 SE-0327: On Actors and Initialization SE-0383: Deprecate @UIApplicationMain

    and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables 􀇻 􀇻
  6. SE-0412: Strict Concurrency for Global Variables Swift 5.10ʢͷݫ֨ͳฒߦੑνΣοΫͷԼͰ͸ʣ͢΂ͯͷάϩʔόϧม਺Λ άϩʔόϧΞΫλʔʹִ཭͢Δ͔ɺҎԼͷ྆ํͰ͋Δ͜ͱ͕ཁٻ͞ΕΔ 1.

    ෆมͰ͋Δ͜ͱ 2. SendableͰ͋Δ͜ͱ τοϓϨϕϧͷάϩʔόϧม਺͸طʹ MainActor ʹ҉໧తʹִ཭͞Ε͍ͯΔ Ώ͑ʹ্هͷཁ݅Λࣗಈతʹຬͨ͢
  7. SE-0412: Strict Concurrency for Global Variables Ұ෦ͷঢ়گͰ͸ɺಠࣗͷσʔλִ཭؅ཧʹґଘͰ͖ΔΑ͏ʹ੩తνΣοΫΛ ΦϓτΞ΢τ͢Δඞཁ͕͋Δ৔߹͕͋Δ ྫ: σʔλΞΫηεΛγϦΞϥΠζ͢ΔάϩʔόϧϩοΫͱؔ࿈෇͚ΒΕ͍ͯΔ৔߹ͳͲ

    nonisolated(unsafe) Λɺάϩʔόϧม਺ʹ࢖༻͢Δ͜ͱͰΦϓτΞ΢τग़དྷΔ ͜ΕʹΑΓɺάϩʔόϧม਺ͷσʔλִ཭ͷ੩తνΣοΫ͸ແޮʹͳΔ ͨͩ͠ɺ͜ͷଐੑΛ࢖༻͢Δ৔߹͸σʔλ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊͷಉظϝΧχζϜ ʢϩοΫ΍ηϚϑΥͳͲʣΛࣗ෼ୡͰ࣮૷͢Δඞཁ͕͋Δ
  8. Swift 5.10 SE-0327: On Actors and Initialization SE-0383: Deprecate @UIApplicationMain

    and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables 􀇻 􀇻 􀇻
  9. Swift 5.10 SE-0327: On Actors and Initialization SE-0383: Deprecate @UIApplicationMain

    and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables 􀇻 􀇻 􀇻 􀇻
  10. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  11. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  12. Actor ͸ Serial Executor ͱ͍͏ΩϡʔΛ͍࣋ͬͯΔ Actor ͸ϓϩύςΟ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊʹ Executor Λ࢖༻͍ͯ͠Δ →

    ϩοΫͷΑ͏ͳ໾ׂΛՌͨ͢ λεΫ͕ Actor ͷ Executor ্Ͱ࣮ߦ͞Ε͍ͯΔ৔߹ʹͷΈ ͦͷ Actor ͷִ཭͞Εͨঢ়ଶʹΞΫηεͰ͖Δ
  13. Actor ͸ Serial Executor ͱ͍͏ΩϡʔΛ͍࣋ͬͯΔ Actor ͸ϓϩύςΟ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊʹ Executor Λ࢖༻͍ͯ͠Δ →

    ϩοΫͷΑ͏ͳ໾ׂΛՌͨ͢ λεΫ͕ Actor ͷ Executor ্Ͱ࣮ߦ͞Ε͍ͯΔ৔߹ʹͷΈ ͦͷ Actor ͷִ཭͞Εͨঢ়ଶʹΞΫηεͰ͖Δ Actor ͷ Executor ΁ͷΞΫηεΛಘΔϓϩηε͸ λεΫ͔ΒͷΈʮඇಉظతʯʹߦΘΕΔ
  14. Actor ͸ Serial Executor ͱ͍͏ΩϡʔΛ͍࣋ͬͯΔ Actor ͸ϓϩύςΟ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊʹ Executor Λ࢖༻͍ͯ͠Δ →

    ϩοΫͷΑ͏ͳ໾ׂΛՌͨ͢ λεΫ͕ Actor ͷ Executor ্Ͱ࣮ߦ͞Ε͍ͯΔ৔߹ʹͷΈ ͦͷ Actor ͷִ཭͞Εͨঢ়ଶʹΞΫηεͰ͖Δ Actor ͷ Executor ΁ͷΞΫηεΛಘΔϓϩηε͸ λεΫ͔ΒͷΈʮඇಉظతʯʹߦΘΕΔ ↓ Actor ͷ֎෦͔Β Actor ͷඇಉظϝιουΛݺͼग़͢ࡍʹ͸ ՄೳͳதஅΛࣔ͢ҝʹ await ͕ඞཁʹͳΔ
  15. "hopping" onto the executor Actor ͸ Serial Executor ͱ͍͏ΩϡʔΛ͍࣋ͬͯΔ Actor

    ͸ϓϩύςΟ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊʹ Executor Λ࢖༻͍ͯ͠Δ → ϩοΫͷΑ͏ͳ໾ׂΛՌͨ͢ λεΫ͕ Actor ͷ Executor ্Ͱ࣮ߦ͞Ε͍ͯΔ৔߹ʹͷΈ ͦͷ Actor ͷִ཭͞Εͨঢ়ଶʹΞΫηεͰ͖Δ Actor ͷ Executor ΁ͷΞΫηεΛಘΔϓϩηε͸ λεΫ͔ΒͷΈʮඇಉظతʯʹߦΘΕΔ ↓ Actor ͷ֎෦͔Β Actor ͷඇಉظϝιουΛݺͼग़͢ࡍʹ͸ ՄೳͳதஅΛࣔ͢ҝʹ await ͕ඞཁʹͳΔ → ͜ͷϓϩϙʔβϧͰ͸্هͷϓϩηεͷ͜ͱΛ ʮ ExecutorͷϗοϐϯάʯͱݺΜͰΔ
  16. Actor ͸ Serial Executor ͱ͍͏ΩϡʔΛ͍࣋ͬͯΔ Actor ͸ϓϩύςΟ΁ͷΞΫηεΛ؅ཧ͢ΔͨΊʹ Executor Λ࢖༻͍ͯ͠Δ →

    ϩοΫͷΑ͏ͳ໾ׂΛՌͨ͢ λεΫ͕ Actor ͷ Executor ্Ͱ࣮ߦ͞Ε͍ͯΔ৔߹ʹͷΈ ͦͷ Actor ͷִ཭͞Εͨঢ়ଶʹΞΫηεͰ͖Δ Actor ͷ Executor ΁ͷΞΫηεΛಘΔϓϩηε͸ λεΫ͔ΒͷΈʮඇಉظతʯʹߦΘΕΔ ↓ ٯʹݴ͏ͱɺεϨουΛϒϩοΫͯ͠ΞΫηεΛ଴ͭ͜ͱ͸ Swift Concurrencyͷݪଇʹ൓͢Δ
  17. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  18. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  19. deinit ಺Ͱ΋ init ͱಉ༷ʹσʔλϨʔε͕ ൃੜ͢ΔՄೳੑ͕͋Δ ͞Βʹɺ͜ͷඇಉظλεΫʹΑͬͯselfͷण໋Λ ʢdeinit ͷऴྃޙΛ௒͑ͯʣԆ͹ͯ͠ ͠·͏Մೳੑ͕͋Δ Object

    0x6000025a4200 of class Counter deallocated with non-zero retain count 2. This object's deinit, or something called from it, may have created a strong reference to self which outlived deinit, resulting in a dangling reference. ࣮ߦ͢ΔͱΫϥογϡ͢Δ
  20. SwiftͰ͸ΦϒδΣΫτͷࢀরΧ΢ϯτ͕ 0 ʹͳΔͱ deinit ͕ݺͼग़͞ΕΔ deinit ͷ࣮ߦޙʹΦϒδΣΫτͷࢀরΧ΢ϯτ͕ ࠶౓ 1 ʹ૿͑Δ͜ͱ͸ະఆٛͷৼΔ෣͍Ͱ͋Δ

    Ώ͑ʹࢀরΧ΢ϯτ͕2౓໨ʹ0ʹͳΔͱ ϥϯμϜͳΫϥογϡ͕ൃੜ͢ΔݪҼͱͳΔ ·ͨɺࢀরܕͷ deinit ʹ͓͚Δण໋Ԇ௕ͷ ໰୊͸Ұൠతͳ໰୊ʢclass΋ؚΊͯʣ Ϋϥογϡʹؔͯ͠ิ଍
  21. SwiftͰ͸ΦϒδΣΫτͷࢀরΧ΢ϯτ͕ 0 ʹͳΔͱ deinit ͕ݺͼग़͞ΕΔ deinit ͷ࣮ߦޙʹΦϒδΣΫτͷࢀরΧ΢ϯτ͕ ࠶౓ 1 ʹ૿͑Δ͜ͱ͸ະఆٛͷৼΔ෣͍Ͱ͋Δ

    Ώ͑ʹࢀরΧ΢ϯτ͕2౓໨ʹ0ʹͳΔͱ ϥϯμϜͳΫϥογϡ͕ൃੜ͢ΔݪҼͱͳΔ ·ͨɺࢀরܕͷ deinit ʹ͓͚Δण໋Ԇ௕ͷ ໰୊͸Ұൠతͳ໰୊ʢclass΋ؚΊͯʣ ↓ কདྷͷผͷϓϩϙʔβϧͰղܾࡦΛݕ౼͢Δ ͜ͱʹͳΔ Ϋϥογϡʹؔͯ͠ิ଍
  22. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  23. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  24. count ͸ MainActor ʹִ཭͞Ε͍ͯΔ message ͸ SomeGlobalActor ʹִ཭͞Ε͍ͯΔ Initʹରͯ͠ͲͷΞΫλʔִ཭Λࢦఆ͢Ε͹Α͍ͷ͔͕ ໰୊ʹͳΔɻ

    count ͱ message ͕ҟͳΔάϩʔόϧΞΫλʔʹ ִ཭͞Ε͍ͯΔΏ͑ʹ1ͭͷΞΫλʔִ཭Λࢦఆ͢Δ͜ͱ͕ ෆՄೳͰ͋Δ
  25. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  26. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  27. actor ͷ৔߹͸ܧঝ͕ଘࡏ͠ͳ͍ ʹ΋͔͔ΘΒͣ Swift 5.5 ͷ؀ڥͰ͸ ΠχγϟϥΠβʔͷҠৡʹ͓͍ͯ convenience ΩʔϫʔυΛ࢖༻͢Δ͜ͱ͕ཁٻ͞Ε͍ͯͨ ↓

    Swift 5.9.1 ͷ؀ڥͩͱ convenience Ωʔϫʔυ Λ෇༩͢Δͱ warning ͕ग़ΔΑ͏ʹͳ͍ͬͯͨ ↓ ղܾࡁΈͩͱࢥΘΕΔ
  28. SE-0327: On Actors and Initialization 1. Non-asyncͳ init ͸ self

    Λ࢖ͬͯͰ͖Δ͜ͱ͕ݫ੍͘͠ݶ͞Ε͍ͯΔ 2. Actor ͷ deinit ͰσʔλϨʔε͕ൃੜ͢ΔՄೳੑ͕͋Δ 3. init ͷதͰʹৗʹ Global Actor ͷִ཭Λอ࣋͢Δ͜ͱ͕ Ͱ͖ͳ͍৔߹͕͋Δ 4. Actor ͕ܧঝΛαϙʔτ͍ͯ͠ͳ͍ʹ΋͔͔ΘΒͣ init ͷҕৡʹ͸Ϋϥεͱಉ༷ʹconvenienceΩʔϫʔυ͕ඞཁͳ͜ͱ ݱঢ়ͷ໰୊఺
  29. Swift 5.10 SE-0327: On Actors and Initialization SE-0383: Deprecate @UIApplicationMain

    and @NSApplicationMain SE-0404: Allow Protocols to be Nested in Non-Generic Contexts SE-0411: Isolated Default Value Expressions SE-0412: Strict Concurrency for Global Variables 􀇻 􀇻 􀇻 􀇻 􀇻