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

(非公開スライド追加)座談会 「Strict ConcurrencyとSwift 6が開く新時...

(非公開スライド追加)座談会 「Strict ConcurrencyとSwift 6が開く新時代: 私たちはどう生きるか?」

iOSDC Japan 2024 座談会資料(非公開スライド付き)

[email protected]

August 23, 2024
Tweet

Other Decks in Programming

Transcript

  1. ຊ೔ͷ಺༰ w 4XJGU$PODVSSFODZͷཧղΛਂΊΔ w ೝࣝ߹Θͤ w *TPMBUJPO͕Θ͔Γ·ͤΜʂ w σʔλΛอޢ͢Δͱ͖͸͢΂ͯBDUPSΛ࢖͏΂͖Ͱ͔͢ʁ w

    $PNQMFUF4USJDU$PODVSSFODZ΁ͷҠߦઓུΛߟ͑Δ w J04ΞϓϦ։ൃʹదͨ͠$PODVSSFODZͷ࢖͍ํ͸͋Γ·͔͢ʁ w ͍ͭ·Ͱʹ4USJDU$PODVSSFODZରԠ͢Ε͹ྑ͍Ͱ͔͢ʁ w Ͳ͔͜ΒҠߦΛ࢝ΊΔͱྑ͍Ͱ͔͢ʁ w Ͳ͏΍ͬͯҠߦ͍ͯ͘͠ͱྑ͍Ͱ͔͢ʁ w 4XJGU$PODVSSFODZͷֶशํ๏ w 4XJGUͷؾʹͳΔഁյతมߋ w 4&'PSXBSE5SBJMJOH$MPTVSFT w ஫໨ͷ4XJGUͷ৽ػೳ w 4&4XJGU#BDLUSBDF"1*
  2. ྑ͍఺ wՄಡੑ্͕͕ͬͨ w ίʔυ͕࣮ߦ͞ΕΔॱ൪͕෼͔Γ΍͘͢ͳͬͨ ॲཧ͕௥͍΍͍͢ wॻ͖΍͘͢ͳͬͨ w ඇಉظॲཧΛಉظతʹॻ͚Δ ୤ίʔϧόοΫ஍ࠈɺϧʔϓॲཧ 

    w ߏ଄Λҙࣝͯ͠ॻ͚Δ w ͔ͬ͜Αͯ͘ؾ෼͕͍͍ wίϯύΠϥ͕νΣοΫͯ͘͠ΕΔͷͰ҆৺ײ͕૿ͨ͠ w εϨουηʔϑΛอূͯ͘͠ΕΔ w σουϩοΫ͕ͳ͘ͳͬͨ ࣄલΞϯέʔτͷ݁Ռ ͸͍ͱ ౴͑ͨํ
  3. ྑͦ͞͏ͩͱࢥ͏఺ wΑΓ҆શʹͳΓͦ͏ w ίϯύΠϥ͕νΣοΫͯ͘͠ΕΔ w εϨουΛؾʹͤͣʹ҆શʹϓϩάϥϛϯά͕Ͱ͖ͦ͏ w σʔλڝ߹΁ͷෆ͕҆ݮΔ wಡΈ΍͘͢ͳΓͦ͏ w

    ίʔϧόοΫΛ࢖ͬͨඇಉظॲཧ͕γϯϓϧʹͳͬͯݟ΍ͦ͢͏ wΑΓॻ͖΍͘͢ͳΓͦ͏ w EFMFHBUF΍Ϋϩʔδϟͱൺ΂ͯඇಉظॲཧ͕Χϯλϯʹॻ͚ͦ͏ w 4XJGU6*΍"QQMFͷϑϨʔϜϫʔΫͱͷ૬ੑ͕Αͦ͞͏ w ωετ͕ݮΓͦ͏ ࣄલΞϯέʔτͷ݁Ռ ͍͍͑ͱ ౴͑ͨํ
  4. ೉͍͠఺ wֶशίετ͕ߴ͍ w ֮͑Δ͜ͱ͕͍ͬͺ͍͋Δ w Ͳ͜ͰֶΜͰ͍͍ͷ͔Θ͔Βͳ͍ w ֓೦͕೉͍͠ "DUPS*TPMBUJPOɺฒߦϓϩάϥϛϯάࣗମʜͳͲ 

    wܯࠂ΍Τϥʔ͕Θ͔Βͳ͍ w ཧ༝͕Α͘Θ͔Βͳ͍ w Ͳ͏ରॲ͢Ε͹͍͍͔Θ͔Βͳ͍ w ѻ͍ͮΒ͍ͱ͜Ζ͕͋Δ w BDUPSϦΤϯτϥϯτɺΩϟϯηϧॲཧɺBDUPSҎ֎ͷՄมঢ়ଶͷ؅ཧɺϓ ϩάϨεͷ؅ཧɺ5BTLͷ࣮ߦॱংʜͳͲ ࣄલΞϯέʔτͷ݁Ռ ͸͍ͱ ౴͑ͨํ
  5. ೉ͦ͠͏ͩͱࢥ͏఺ wֶशίετ͕͔͔Γͦ͏ w 5BTL΍ΞΫλʔͱ͍ͬͨ֓೦ͷΩϟονΞοϓ w ·ͣɺ4FOEBCMF͕Θ͔Γʹ͘͘ɺԿΛ4FOEBCMFʹ͢΂͖ͳͷ͔͕͸͖ͬΓ͠ͳ͍ w࢖͍ํ͕೉ͦ͠͏ w σόοάํ๏ w

    Τϥʔϝοηʔδͷղಡ w ಛఆͷόοΫάϥ΢ϯυΩϡʔΛ࢖͏ํ๏ w ۩ମతͳΠϝʔδ͕༙͍͍ͯͳ͍ wҠߦ͕େมͦ͏ ࣄલΞϯέʔτͷ݁Ռ ͍͍͑ͱ ౴͑ͨํ
  6. %BUB*TPMBUJPO σʔλִ཭ w 4XJGUίϯύΠϥ͕͢΂ͯͷNVUBCMFTUBUF Մมঢ়ଶ ΛνΣο Ϋ͠ɺෳ਺εϨου͔Βಉ࣌ΞΫηεͰ͖ͳ͍ͯ͘͠Δ࢓૊Έ w ੩త TUBUJD

    ִ཭ͱಈత EZOBNJD ִ཭ͷछྨ͋Δ w ੩తִ཭ܕ΍ؔ਺ͷએݴͳͲ࣮ߦ࣌ͷঢ়ଶʹࠨӈ͞Εͳ͍ཁૉͰ ִ཭͢Δ࢓૊Έ ྫBDUPSɺ!.BJO"DUPS w ಈతִ཭੩తʹִ཭Ͱ͖ͳ͍৔߹ʹִ཭ΛίϯύΠϥʹ఻͑Δ ࢓૊ΈɻҰ࣌తͳղܾࡦ ྫ.BJO"DUPSBTTVNF*TPMBUFEɺ.BJO"DUPSSVO
  7. ඇִ཭ OPOJTPMBUFE  ໌ࣔతͳִ཭υϝΠϯ ΞΫλʔάϩʔόϧΞΫλʔ ʹଐ͞ͳ͍ঢ়ଶ ྫ௨ৗͷؔ਺΍σʔλߏ଄ɺOPOJTPMBUFE͕෇͍͍ͯΔ΋ͷ ΞΫλʔִ཭ BDUPSJTPMBUFE 

    ϝιου΍ม਺͕ΞΫλʔ͕࡞ΔυϝΠϯʹִ཭͞Ε͍ͯΔঢ়ଶ ྫBDUPSΫϥεɺJTPMBUFEύϥϝʔλΛ࣋ͭؔ਺ άϩʔόϧΞΫλʔִ཭ HMPCBMBDUPSJTPMBUFE  ϝιου΍ม਺͕άϩʔόϧΞΫλʔ͕࡞ΔυϝΠϯʹִ཭͞Ε͍ͯΔঢ়ଶ ྫ!.BJO"DUPSɺಠࣗʹఆٛͨ͠άϩʔόϧΞΫλʔ *TPMBUJPO%PNBJO ִ཭υϝΠϯ σʔλִ཭ʹΑͬͯϝιου΍ม਺Λִ཭͍ͯ͠ΔݸʑͷྖҬ
  8. actor Counter { var actorIsolated = 0 let constant =

    100 var nonSendableClass = NonSendableClass() func increment() { actorIsolated += randomNumber() } func incrementWithGlobalActorIsolated() async { actorIsolated += await globalActorIsolated } @MainActor var globalActorIsolated = 0 @MainActor var globalActorIsolatedValue: Int { globalActorIsolated } nonisolated var nonisolatedValue: Int { get async { await actorIsolated } } nonisolated func randomNumber() -> Int { Int.random(in: 0..<constant) } } ඇִ཭ OPOJTPMBUFE ΞΫλʔִ཭ BDUPSJTPMBUFE άϩʔόϧΞΫλʔִ཭ HMPCBMBDUPSJTPMBUFE
  9. actor Counter { var actorIsolated = 0 let constant =

    100 var nonSendableClass = NonSendableClass() func increment() { actorIsolated += randomNumber() } func incrementWithGlobalActorIsolated() async { actorIsolated += await globalActorIsolated } @MainActor var globalActorIsolated = 0 @MainActor var globalActorIsolatedValue: Int { globalActorIsolated } nonisolated var nonisolatedValue: Int { get async { await actorIsolated } } nonisolated func randomNumber() -> Int { Int.random(in: 0..<constant) } } ִ཭ڥք *TPMBUJPO#PVOEBSZ
  10. w σʔλִ཭ %BUB*TPMBUJPO  w ੩త TUBUJD ִ཭ͱಈత EZOBNJD ִ཭ͷछྨ͋Δ

    w ִ཭υϝΠϯ w σʔλִ཭ʹΑͬͯϝιου΍ม਺Λִ཭͍ͯ͠ΔݸʑͷྖҬ w ͢΂ͯͷม਺ͱؔ਺͸ɺඇִ཭ɺΞΫλʔִ཭ɺάϩʔόϧΞΫλʔִ ཭ͷ͍ͣΕ͔ʹؚ·ΕΔ w ִ཭ڥք w ִ཭υϝΠϯؒͷڥք w ִ཭ڥքΛӽ͑Δ w ҟͳΔछྨͷִ཭υϝΠϯؒͰ஋͕౉͞ΕΔ͜ͱ άϩʔ όϧΞΫ λʔִ཭ ΞΫλʔ ִ཭ ඇִ཭ ִ཭υϝΠϯ ִ཭ڥք ִ཭ڥքΛӽ͑Δ
  11. ϑϩʔηϯγςΟϒִ཭ղੳ 3FHJPOCBTFEJTPMBUJPO σʔλڝ߹ͷՄೳੑ͋Γʁ 4XJGU 9DPEF func passNonSendableType() async { let

    nonSendableClass = NonSendableClass() let counter = Counter() await counter.updateNonSendableClass(nonSendableClass) } actor Counter { private var nonSendableClass = NonSendableClass() func updateNonSendableClass(_ instance: NonSendableClass) { nonSendableClass = instance } } ϓϩϙʔβϧ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  12. ϑϩʔηϯγςΟϒִ཭ղੳ 3FHJPOCBTFEJTPMBUJPO 4XJGU 9DPEF OPO4FOEBCMF$MBTT͸DPVOUFSʹ౉͞Εͨޙ ΞΫηε͞Ε͍ͯͳ͍ͨΊσʔλڝ߹͸ى͖ͳ͍ func passNonSendableType() async {

    let nonSendableClass = NonSendableClass() let counter = Counter() await counter.updateNonSendableClass(nonSendableClass) } actor Counter { private var nonSendableClass = NonSendableClass() func updateNonSendableClass(_ instance: NonSendableClass) { nonSendableClass = instance } } ϓϩϙʔβϧ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  13. func passNonSendableType() async { let nonSendableClass = NonSendableClass() let counter

    = Counter() await counter.updateNonSendableClass(nonSendableClass) } ϑϩʔηϯγςΟϒִ཭ղੳ 3FHJPOCBTFEJTPMBUJPO ˞9DPEFͩͱ4XJGUͰ΋ͳ͔ͥܯࠂ͕ग़ͳ͍ 🟢 ϓϩϙʔβϧ ͜ͷྖҬ 3FHJPO શମΛݟͯ҆શͰ͋Ε͹0, 4XJGU 9DPEF Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  14. ϑϩʔηϯγςΟϒִ཭ղੳ 3FHJPOCBTFEJTPMBUJPO σʔλڝ߹͕ى͖ΔϦεΫ͕͋Δͱ͖͸❌ func passNonSendableType() async { let nonSendableClass =

    NonSendableClass() let counter = Counter() await counter.updateNonSendableClass(nonSendableClass) print(nonSendableClass.value) } ❌4FOEJOHOPO4FOEBCMF$MBTTSJTLTDBVTJOHEBUBSBDFT ϓϩϙʔβϧ 4XJGU 9DPEF Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ ඇִ཭ ΞΫλʔִ཭ 💥
  15. func passNonSendableType(counter: Counter, nonSendableClass: NonSendableClass ) async { await counter.updateNonSendableClass(nonSendableClass)

    } TFOEJOHύϥϝʔλ ϓϩϙʔβϧ 4XJGU 9DPEF Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  16. func passNonSendableType(counter: Counter, nonSendableClass: NonSendableClass ) async { await counter.updateNonSendableClass(nonSendableClass)

    } TFOEJOHύϥϝʔλ ❌4FOEJOHOPO4FOEBCMF$MBTTSJTLTDBVTJOHEBUBSBDFT ϓϩϙʔβϧ 4XJGU 9DPEF Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  17. ϓϩϙʔβϧ ݺͼग़͠ଆͰͲ͏࢖ΘΕ͍ͯΔͷ͔Θ͔Βͣ ҆શ͔൑அͰ͖ͳ͍ͨΊ❌ 4XJGU 9DPEF TFOEJOHύϥϝʔλ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ

    > جຊ func passNonSendableType(counter: Counter, nonSendableClass: NonSendableClass ) async { await counter.updateNonSendableClass(nonSendableClass) } Ͳ͜ʹִ཭͞Ε͍ͯΔʁ
  18. func passNonSendableType(counter: Counter, nonSendableClass: sending NonSendableClass ) async { await

    counter.updateNonSendableClass(nonSendableClass) } ϓϩϙʔβϧ 🟢 σʔλڝ߹ͷϦεΫ͕ى͖ͳ͍͜ͱΛίϯύΠϥʹ఻͑ΒΕΔ 4XJGU 9DPEF TFOEJOHύϥϝʔλ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ
  19. ϓϩϙʔβϧ func callPassNonSendableType() async { let counter = Counter() let

    nonSendableClass = NonSendableClass() await passNonSendableType(counter: counter, nonSendableClass: nonSendableClass) print(nonSendableClass.value) } 4XJGU 9DPEF ίϯύΠϥ͕ݺͼग़͠ଆΛνΣοΫ͢ΔΑ͏ʹͳΔ ඇִ཭ ΞΫλʔִ཭ 💥 TFOEJOHύϥϝʔλ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ await counter.updateNonSendableClass(nonSendableClass) ❌4FOEJOHOPO4FOEBCMF$MBTTSJTLT DBVTJOHEBUBSBDFT
  20. func useNonSendableTypeFromActor(counter: Counter) async { let nonSendableClass = await counter.makeNonSendableType()

    } ❌/POTFOEBCMFUZQF/PO4FOEBCMF$MBTTSFUVSOFECZDBMMUPBDUPSJTPMBUFEGVODUJPODBOOPUDSPTTBDUPSCPVOEBSZ actor Counter { private var nonSendableClass = NonSendableClass() func makeNonSendableType() -> NonSendableClass { NonSendableClass() } } ϓϩϙʔβϧ 4XJGU 9DPEF TFOEJOH໭Γ஋ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ ݺͼग़͠ઌͰ໭Γ஋͕Ͳ͏࢖ΘΕ͍ͯΔͷ͔͕Θ͔Βͣ ҆શ͔൑அͰ͖ͳ͍ͨΊ❌
  21. func useNonSendableTypeFromActor(counter: Counter) async { let nonSendableClass = await counter.makeNonSendableType()

    } actor Counter { private var nonSendableClass = NonSendableClass() func makeNonSendableType() -> sending NonSendableClass { NonSendableClass() } } 🟢 ϓϩϙʔβϧ 4XJGU 9DPEF ΠϯελϯεΛ࡞੒͍ͯ͠Δ͚ͩͳͷͰσʔλڝ߹ͷϦεΫͳ͠🟢 TFOEJOH໭Γ஋ Swift ConcurrencyͷཧղΛਂΊΔ > Isolationͷ࢓૊Έ > جຊ σʔλڝ߹ͷϦεΫ͕ى͖ͳ͍͜ͱΛίϯύΠϥʹ఻͑ΒΕΔ
  22. JTPMBUJPOͷॻ͖෼͚ ؔ਺ Ϋϩʔδϟ OPOJTPMBUFE UZQF JTPMBUFE QBSBNFUFS JTPMBUFE DBQUVSFE WBMVF

    JTPMBUFE func nonisolatedFunction() async {} nonisolated func explicitNonisolatedFunction() async {} func nonisolatedContext() async { let implicitNonisolatedClosure = { () in } // [SE-NNNN] Closure isolation control let nonisolatedClosure = { nonisolated () in } } @MainActor func typeIsolatedFunction() async {} @MainActor func typeContext() async { let implicitTypeIsolatedClosure = { () in } let typeIsolatedClosure = { @MainActor in } } func parameterIsolatedFunction( myActor: isolated MyActor ) async {} extension MyActor { func selfIsolatedFunction() async {} } let parameterIsolatedClosure = { (myActor: isolated MyActor) in } extension MyActor { var selfCapturedIsolatedFunction: () async -> Void { self.selfIsolatedFunction } } // [SE-NNNN] Closure isolation control let myActor = MyActor() let captureIsolatedClosure = { [isolated myActor] () in }
  23. .VUFY w εϨουΛಉظϒϩοΫ͢Δʮ-PDLʯͷϥούʔ w PT@VOGBJS@MPDLʢ04"MMPDBUFE6OGBJS-PDLʣΛ಺෦Ͱར༻ class FancyManagerOfSorts { let cache

    = Mutex<[String: Resource]>([:]) func save(_ resource: Resource, as key: String) { cache.withLock { $0[key] = resource } } }
  24. "UPNJD w εϨουΛʢҰॠ͚ͩʣಉظϒϩοΫ͢Δ"1* w EBUBSBDF͚ͩΛಉظతʹ๷͍͗ͨ৔߹ let counter = Atomic<Int>(0) DispatchQueue.concurrentPerform(iterations:

    10) { _ in for _ in 0 ..< 1_000_000 { counter.wrappingAdd(1, ordering: .relaxed) } } print(counter.load(ordering: .relaxed))
  25. wجຊ͸"DUPS w 4XJGU$PODVSSFODZ͸εϨουΛϒϩοΫ͠ͳ͍ࢥ૝ w "DUPS͸σουϩοΫΛى͜͞ͳ͍ ͨͩ͠ɺSBDFDPOEJUJPOΛى͜͢  w4XJGUνʔϜ΋શͯ"DUPSʹஔ͖׵͑ΒΕΔͱ͸ߟ͍͑ͯͳ͍ w ΫϦςΟΧϧηΫγϣϯ

    w BTZODΛ࢖͑ͳ͍৔߹ʢϨΨγʔίʔυɾͲ͏ͯ͠΋ಉظΞΫηε͍ͨ͠ʣ w.VUFYɺ"UPNJD ͨͩ͠ɺ4XJGUJ04Ҏ্  w J04Ҏલ͸ 04"MMPDBUFE6OGBJS-PDL͕.VUFYͷ୅ΘΓʹ࢖͑Δ
  26. ೉ͦ͠͏ͩͱࢥ͏఺ wܯࠂ΍Τϥʔ͕೉ͦ͠͏ w ϝοηʔδͷղಡ͕೉ͦ͠͏ w ܯࠂ΍Τϥʔमਖ਼ʹࠎ͕ંΕͦ͏ɻ%POUQBOJD͸ແཧ w طଘͷ໰୊͕ͳ͍ίʔυʹରͯ͠ܯࠂ΍Τϥʔ͕ग़ͯ͠·͏ જࡏతʹ͸໰୊͸͋Δ 

    w ͦ΋ͦ΋ɺͳʹΛνΣοΫͯ͠Δͷ͔͑͞ཧղग़དྷ͍ͯͳ͍ wطଘͷίʔυ͔ΒͷҠߦϓϩηε͕Θ͔Βͳ͍ w ࣗ෼ͷϓϩδΣΫτʹ߹ͬͨҠߦํ๏͕Θ͔Βͳ͍ w શମΛ$PODVSSFODZରԠͤ͞Δ͔ɺ!QSFDPODVSSFODZ౳ͷ࢑ఆରԠͤ͞Δͷ͔ w DMBTTͷѻ͍ํ w ࣮ϓϩμΫτͰͷஈ֊తͳਐΊํɻಛʹϑϨʔϜϫʔΫͷҠߦ͕ඞཁͳ৔߹ $PNCJOF͔Βͷ ஔ׵ͳͲ  wҠߦίετ͕͔͔Γͦ͏ w طଘίʔυ͕ଟ͗ͯ͢Ҡߦ͸ແཧͦ͏ɻԼखͨ͠ΒϞσϧ͔Βม͑ͳ͍ͱ͍͚ͳ͍ w ޻਺ʹݟ߹ͬͨରԠ͢ΔϝϦοτ͸͋Δͷ͔ʁ ͍͍͑ͱ ౴͑ͨํ ࣄલΞϯέʔτͷ݁Ռ
  27. ִ཭ڥքΛӽ͑ͳ͚Ε͹೉͍͜͠ͱ͸ͳ͍ .BJO"DUPS ִ཭ڥք *TPMBUJPO#PVOEBSZ 7JFX 7JFX 7JFX .PEFM 7JFX .PEFM

    .PEFM .PEFM .PEFM .BJO"DUPS಺Ͱͷ΍ΓͱΓʹ೉͠͞͸ͳ͍ (6*ΞϓϦͷଟ͘ͷ࣮૷͸ .BJO"DUPS಺ʹͱͲ·Δ
  28. 7JFX͔Β௚઀ΞΫηε͢Δঢ়ଶ͸.BJO"DUPSͰѻ͏ struct FooListView: View { @State var viewModel: FooViewModel =

    .init() var body: some View { List(viewModel.values) { value in // ... } } }
  29. ྫ.BJO"DUPSͰ΍Ε͹ྑ͍ॲཧ @MainActor @Observable final class FooStore { var idToValue: [Foo.ID:

    Foo] = [:] } @MainActor @Observable final class FooListViewModel { let store: FooStore var values: [Foo] { // O(n)͚ͩͲཁૉ਺͕ଟ͘ͳ͍ݶΓ໰୊ͳ͍ Array(store.idToValue.values) } }
  30. ྫෆཁʹִ཭ڥքΛӽ͑Δͱ೉͘͠ͳΔ actor FooStore { var idToValue: [Foo.ID: Foo] = [:]

    var values: [Foo] { Array(idToValue.values) } } @MainActor @Observable final class FooListViewModel { let store: FooStore var isBar: Bool = false func load() async { if isBar { return } let values = await Array(store.idToValue.values) if isBar { return } // suspension pointΛڬΜͩͷͰ࠶νΣοΫ // ... } }
  31. ֎ଆ͔Β࢝ΊΔ w ֎ଆ࠷্ҐϞδϡʔϧ ϝΠϯλʔήοτͳͲ  w ཧ༝ଞͷϞδϡʔϧ͔Βґଘ͞Ε͍ͯͳ͍ͨΊӨڹൣғΛ཈͑ΒΕΔ w ஫ҙઈରʹ͔͜͜Βͱ͍͏Θ͚Ͱ͸ͳ͍ w

    σʔλڝ߹҆શͰͳ͍άϩʔόϧͳঢ়ଶ΍ࣗಈͰ4FOEBCMFʹ४ڌ͍ͯ͠Δ ܕͷ͍ͤͰϓϩδΣΫτதʹܯࠂ͕େྔൃੜ͍ͯ͠Δ৔߹͸ɺͦͪΒΛ·ͣ ର৅ͱ͢Δͷ͕࠷΋ޮՌత ӳޠ൛ ೔ຊޠ൛
  32. ҆શੑ 7JFX 7JFX.PEFM .PEFM .PEFM .PEFM .BJO"DUPS 'PP"DUPS ඇಉظ ಉظ

    ಉظ σʔλڝ߹ͷ ৺഑ෆཁ ֎ଆ͔ΒରԠ͢Δ͜ͱͰɺӨڹΛड͚ΔϞδϡʔϧΛ ͢Ͱʹ$PODVSSFODZ4BGFʹݶఆͰ͖ɺൺֱత҆શʹมߋͰ͖Δ
  33. ҆શੑ 7JFX 7JFX.PEFM .PEFM .PEFM .PEFM 'PP"DUPS ඇಉظ ಉظ ಉظ

    σʔλڝ߹ͷ ৺഑͕͋Δ ֎ଆ͔ΒରԠ͢Δ͜ͱͰɺӨڹΛड͚ΔϞδϡʔϧΛ ͢Ͱʹ$PODVSSFODZ4BGFʹݶఆͰ͖ɺൺֱత҆શʹมߋͰ͖Δ
  34. %BUBSBDFͷओཁͳݪҼ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺  TUSVDUʹͰ͖ͳ͍͔ߟ͑Δ  BDUPSʹͰ͖ͳ͍͔ߟ͑Δ 

    04"MMPDBUFE6OGBJS-PDLΛ࢖ͬͯ4FOEBCMFʹ͢Δ  SFHJPOCBTFEJTPMBUJPOͰ৐Γ੾Δ class Counter { var value = 0 func increment() -> Int { ... } }
  35. %BUBSBDFͷओཁͳݪҼ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺  4FOEBCMFͷ৔߹  TUBUJDMFUDPNQVUFEQSPQFSUZʹ͢Δ 

    BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF  MPDLΛ࢖͏  OPO4FOEBCMFͷ৔߹ class FooManager { static var configuration = Configuration() }
  36. %BUBSBDFͷओཁͳݪҼ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺  4FOEBCMFͷ৔߹  TUBUJDMFUDPNQVUFEQSPQFSUZʹ͢Δ 

    BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF  MPDLΛ࢖͏  ؤுͬͯ4FOEBCMFʹ͢Δ  DPNQVUFEQSPQFSUZʹ͢Δ  BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF Λ࢖͏  OPO4FOEBCMFͷ৔߹ class FooManager { static var configuration = Configuration() }
  37. %BUBSBDFͷओཁͳݪҼ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺  TUSVDUʹͰ͖ͳ͍͔ߟ͑Δ  BDUPSʹͰ͖ͳ͍͔ߟ͑Δ 

    04"MMPDBUFE6OGBJS-PDLΛ࢖ͬͯ4FOEBCMFʹ͢Δ  SFHJPOCBTFEJTPMBUJPOͰ৐Γ੾Δ  4FOEBCMFͷ৔߹  TUBUJDMFUDPNQVUFEQSPQFSUZʹ͢Δ  BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF  MPDLΛ࢖͏  ؤுͬͯ4FOEBCMFʹ͢Δ  DPNQVUFEQSPQFSUZʹ͢Δ  BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF Λ࢖͏  OPO4FOEBCMFͷ৔߹
  38.  ؤுͬͯ4FOEBCMFʹ͢Δ  DPNQVUFEQSPQFSUZʹ͢Δ  BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF Λ࢖͏

     TUBUJDMFUDPNQVUFEQSPQFSUZʹ͢Δ  BDUPSʹִ཭͢Δ  OPOJTPMBUFE VOTBGF  MPDLΛ࢖͏  TUSVDUʹͰ͖ͳ͍͔ߟ͑Δ  BDUPSʹͰ͖ͳ͍͔ߟ͑Δ  04"MMPDBUFE6OGBJS-PDLΛ࢖ͬͯ4FOEBCMFʹ͢Δ  SFHJPOCBTFEJTPMBUJPOͰ৐Γ੾Δ %BUBSBDFͷओཁͳݪҼ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺  4FOEBCMFͷ৔߹  OPO4FOEBCMFͷ৔߹  BDUPSʹִ཭͢Δ  BDUPSʹִ཭͢Δ  BDUPSʹͰ͖ͳ͍͔ߟ͑Δ
  39. BDUPSʹ·ͭΘΔΑ͋͘ΔΤϥʔ  ར༻Օॴ͕ଟִ͗ͯ͢཭Ͱ͖ͳ͍ !QSFDPODVSSFODZ BDUPS  QSPUPDPM͕ཁٻ͢ΔBDUPSͱ ͋Δ΂͖BDUPS͕ҧ͏  QSFDPODVSSFODZDPOGPSNBODF

     OPOJTPMBUFE BTTVNF*TPMBUFE  OPOJTPMBUFE 5BTL  EFJOJU͕BDUPSʹִ཭͞Εͳ͍  EFJOJUͰඞཁͳ΋ͷʹ OPOJTPMBUFE VOTBGF Λ෇͚଍͢  EFJOJUͰඞཁͳ΋ͷΛBDUPSʹ ִ཭ͨ͠ϥούʔΛڬΉ
  40. %BUBSBDFͷओཁͳݪҼ BDUPSʹ·ͭΘΔΑ͋͘ΔΤϥʔ ར༻Օॴ͕ଟ͗ͯ͢ ִ཭Ͱ͖ͳ͍ !QSFDPODVSSFODZ BDUPS QSPUPDPM͕ ཁٻ͢ΔBDUPSͱ ͋Δ΂͖BDUPS ͕ҧ͏

    QSFDPODVSSFODZDPOGPSNBODF OPOJTPMBUFE BTTVNF*TPMBUFE OPOJTPMBUFE 5BTL EFJOJU͕ BDUPSʹ ִ཭͞Εͳ͍ EFJOJUͰඞཁͳ΋ͷʹ OPOJTPMBUFE VOTBGF Λ෇͚଍͢ EFJOJUͰඞཁͳ΋ͷΛBDUPSʹ ִ཭ͨ͠ϥούʔΛڬΉ w ϛϡʔλϒϧͳΫϥε w άϩʔόϧม਺ TUSVDUʹͰ͖ͳ͍͔ߟ͑Δ BDUPSʹͰ͖ͳ͍͔ߟ͑Δ 04"MMPDBUFE6OGBJS-PDL 4FOEBCMF SFHJPOCBTFEJTPMBUJPOͰ৐Γ੾Δ 4FOEBCMFͷ৔߹ TUBUJDMFUDPNQVUFEQSPQFSUZ BDUPSʹִ཭͢Δ OPOJTPMBUFE VOTBGF  MPDL ؤுͬͯ4FOEBCMFʹ͢Δ DPNQVUFEQSPQFSUZʹ͢Δ BDUPSʹִ཭͢Δ OPOJTPMBUFE VOTBGF Λ࢖͏ OPO4FOEBCMFͷ৔߹
  41. ৄ͘͠͸͜͜ΛΫϦοΫ ྫҟͳΔHMPCBMBDUPSϝιουͷݺͼग़͠ @SomeGlobalActor protocol P1 { func method() } class

    C1: P1 { func method() { } @OtherGlobalActor func testMethod() { method() _ = method } } // expected-error {{call to global actor 'SomeGlobalActor'-isolated instance method 'method()' in a synchronous global actor 'OtherGlobalActor'-isolated context}}
  42. ྫҟͳΔHMPCBMBDUPSϝιουͷݺͼग़͠ @SomeGlobalActor protocol P1 { func method() } class C1:

    P1 { func method() { } @OtherGlobalActor func testMethod() { method() _ = method } } // expected-error {{call to global actor 'SomeGlobalActor'-isolated instance method 'method()' in a synchronous global actor 'OtherGlobalActor'-isolated context}} Swift ConcurrencyͷཧղΛਂΊΔ > Τϥʔ(ܯࠂ)ͷௐ΂ํ ৄ͘͠͸͜͜ΛΫϦοΫ ࣮ࡍʹग़ྗ͞ΕΔจݴͱಉ͡
  43. @SomeGlobalActor protocol P1 { func method() } class C1: P1

    { func method() { } @OtherGlobalActor func testMethod() { method() _ = method } } ྫҟͳΔHMPCBMBDUPSϝιουͷݺͼग़͠ !4PNF(MPCBM"DUPS ܧঝ Swift ConcurrencyͷཧղΛਂΊΔ > Τϥʔ(ܯࠂ)ͷௐ΂ํ ৄ͘͠͸͜͜ΛΫϦοΫ
  44. @SomeGlobalActor protocol P1 { func method() } class C1: P1

    { func method() { } @OtherGlobalActor func testMethod() { method() _ = method } } ྫҟͳΔHMPCBMBDUPSϝιουͷݺͼग़͠ !4PNF(MPCBM"DUPS 💥 ෆҰக ܧঝ Swift ConcurrencyͷཧղΛਂΊΔ > Τϥʔ(ܯࠂ)ͷௐ΂ํ ৄ͘͠͸͜͜ΛΫϦοΫ
  45. @SomeGlobalActor protocol P1 { func method() } class C1: P1

    { func method() { } @OtherGlobalActor func testMethod() { method() _ = method } } ྫҟͳΔHMPCBMBDUPSϝιουͷݺͼग़͠ !4PNF(MPCBM"DUPS ❌Call to global actor 'SomeGlobalActor'-isolated instance method 'method()' in a synchronous global actor 'OtherGlobalActor'-isolated context 💥 ෆҰக ܧঝ Swift ConcurrencyͷཧղΛਂΊΔ > Τϥʔ(ܯࠂ)ͷௐ΂ํ ৄ͘͠͸͜͜ΛΫϦοΫ ࣮ࡍͷΤϥʔϝοηʔδ
  46. w4XJGU$PODVSSFODZΛཧղ͢Δ w 4XJGU.JHSBUJPO(VJEFΛಡΉ w 88%$ͷηογϣϯಈը w αϯϓϧίʔυΛࢼ͢ w ެࣜυΩϡϝϯτΛಡΉ w

    Τϥʔ΍ܯࠂͷௐ΂ํ w TXJGUMBOHTXJGUϦϙδτϦͷςετͰಉ͡ϝοηʔδ͕ग़ ྗ͞Ε͍ͯΔςετέʔεΛ୳ͯ͠ΈΔ
  47. 4&'PSXBSE5SBJMJOH$MPTVSFT func f( _ onAppear: (() -> Void)? = nil,

    _ onDisappear: (() -> Void)? = nil ) { if onAppear != nil { print("forward") } if onDisappear != nil { print("backward") } } // Swift6ະຬ͸backward // Swift6Ҏ্͸forward f {}
  48. 4& 4& 4& 4& 4& 4& 4& 4& 4& 4&

    4& 4& 4& 4& 4& 4& 4& 4& 4& 4&                           4&5ZQFEUISPXT 4&4XJGU#BDLUSBDF"1* 4&0CKFDUJWF$JNQMFNFOUBUJPOTJO4XJGU 4&5BTL&YFDVUPS1SFGFSFODF 4&.FUBUZQF,FZQBUIT 4&"DDFTTMFWFMNPEJ fi FSTPOJNQPSUEFDMBSBUJPOT 4&$PVOUBCMF3BOHFQSPUPDPM 4&4XJGU-BOHVBHF7FSTJPO1FS5BSHFU 4&/PODPQZBCMF(FOFSJDT 4&1BDL*UFSBUJPO 4&/PODPQZBCMF4UBOEBSE-JCSBSZ1SJNJUJWFT 4&'PSFJHOSFGFSFODFUZQFTJO4XJGU 4&#PSSPXJOHBOEDPOTVNJOHQBUUFSONBUDIJOHGPS/PODPQZBCMFUZQFT 4&1PJOUFS"SHVNFOU&YQSFTTJPOT 4&CJU*OUFHFS5ZQFT 4&$SFBUFBSSBZPGCZUFTGSPNTUBUJDTUSJOHMJUFSBMT 4&"TZODEBUBTUSFBNT 4&"EEJOHPQBRVFQBSBNFUFSEFDMBSBUJPOT 4&"EE6OJDPEF4VQQPSUGPS3FHFYMJUFSBMT 4&'VODUJPO#PEZ.BDSPT 4XJGUҎ߱ͷؾʹͳΔ৽ػೳ ࣄલΞϯέʔτͷ݁Ռ ޙճ͠Ͱ΋Αͦ͞͏ʁ