Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go beyond the Actor Boundary ~ Swift 6へのConcurr...
Search
giginet
PRO
March 24, 2023
Programming
5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go beyond the Actor Boundary ~ Swift 6へのConcurrency対応 ~
giginet
PRO
March 24, 2023
More Decks by giginet
See All by giginet
🀄️ on swiftc
giginet
PRO
0
580
15年メンテしてきたdotfilesから開発トレンドを振り返る 2011 - 2026
giginet
PRO
2
450
Claude Codeログ基盤の構築
giginet
PRO
7
4.6k
Inside of Swift Export
giginet
PRO
1
3.5k
Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム
giginet
PRO
0
2.9k
SwiftでMCPサーバーを作ろう!
giginet
PRO
3
480
Creating Intuitive Developer Tool in Swift
giginet
PRO
0
1.6k
Mergeable Libraryで 高速なアプリ起動を実現しよう!
giginet
PRO
2
8.5k
5分でわかるExplicitly Built Modules
giginet
PRO
2
1.9k
Other Decks in Programming
See All in Programming
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
120
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
300
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
270
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
670
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
440
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
450
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
200
Security issues being discussed on Web Platforms
petamoriken
0
780
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
120
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
190
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.5k
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
830
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
Utilizing Notion as your number one productivity tool
mfonobong
4
590
The agentic SEO stack - context over prompts
schlessera
0
930
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
830
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
390
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
900
Why Our Code Smells
bkeepers
PRO
340
58k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
How STYLIGHT went responsive
nonsquared
100
6.3k
So, you think you're a good person
axbom
PRO
2
2.1k
My Coaching Mixtape
mlcsv
0
310
Transcript
Go beyond the Actor Boundary 2023/3/22 Swift 6ͷConcurrencyରԠ @giginet
୭ʁ • @giginet • LINEגࣜձࣾ Developer Experience։ൃνʔϜ • ٕज़ސ •
ϚωʔϑΥϫʔυ, peep, ϢϏϨδ • OSSϝϯςφ • Carthage, XcodeGen, fastlaneͳͲ • ϙέϞϯϥϯΫϚον
ࠓ͢͜ͱ • Swift Concurrencyʹ͍͓ͭͯ͞Β͍ • Race Conditions, Actor Boundary, Sendable
• Swift 6.0࣌ʹ͚ͯԿΛ͢Εྑ͍͔ • ݱঢ়ઃఆͰ͖ΔޓϞʔυʹ͍ͭͯڍಈݱঢ়Λௐͨ
Swift 6 • Swift 6͔ΒRace ConditionsͷνΣοΫ͕ݫ֨Խ • εϨουηʔϑͰͳ͍ίʔυίϯύΠϧΤϥʔʹͳͬͯ͠·͏ • Sendableʹద߹͍ͯ͠ͳ͍ܕΛϓϩηεΛ͑ͯڞ༗͍͚ͯ͠ͳ
͍ʢActor boundaryʣ
Race conditions? • ෳͷϓϩηεʢॲཧʣ͕ڞ༗ϦιʔεʹΞΫηεͯ͠༧ظ͠ͳ͍ڍ ಈΛҾ͖ى͜͢͜ͱ value = 1 value =
2 value = 2? 💥 ϓϩηε1 ϓϩηε2 ڞ༗Ϧιʔε let value = Shared.value Shared.value = value + 1 let value = Shared.value // Do long task await doLongTask() Shared.value = value + 1
Sendable • Race ConditionsΛ͙ͨΊʹSendableͱ͍͏protocol͕ಋೖ • ෳͷϓϩηε͔ΒΛڞ༗ͯ҆͠શͩͱ͍͏͜ͱΛࣔ͢ protocol • ҎԼͷUserෆมͰ͋Γɺෳ͔Βࢀরͯ͠Race Conditions
͕ى͖ͳ͍ • = Sendableʹద߹Ͱ͖Δ struct User: Sendable { let name: String let age: Int64 }
ࢀߟࢿྉ • Protect mutable state with Swift actors • https://developer.apple.com/videos/play/wwdc2021/10133/
• Eliminate data races using Swift Concurrency • https://developer.apple.com/videos/play/wwdc2022/110351/
Swift 6 • ͜ͷΑ͏ͳةݥͳίʔυΛίϯύΠϧ࣌ʹνΣοΫͯ͘͠ΕΔΑ͏ʹ ͳΔ • Sendable͕ඞཁͳՕॴͰඞਢʹͳΔ(Sendable Constraints) • ಛఆͷεϨουͰͷಈ࡞Λڧ੍
(Actor Isolation Checking) • →ࠓ·Ͱಈ͍͍ͯͨίʔυ͕ಈ͔ͳ͘ͳΔՄೳੑ • →Swift 6͕ग़ͨͱ͖ʹ߄ͯͳ͍Α͏ʹɺࠓͷ͏ͪʹ४උ͓ͯ͘͠ඞ ཁ͕͋Δ
Ͳ͏ͬͯҠߦ͍͚ͯ͠ྑ͍ͷʁ • Incremental migration to concurrency checking • https://github.com/apple/swift-evolution/blob/main/proposals/0337- support-incremental-migration-to-concurrency-checking.md
• ҆શͳඇಉظॲཧνΣοΫͷͨΊͷϚΠάϨʔγϣϯख๏ΛఏҊͨ͠ proposal
None
কདྷతʹյΕΔͱ͜ΖΛΔʹʁ • -warn-concurrency • Swift 6͔ΒΤϥʔʹͳΔ߲Λܯࠂͯ͘͠ΕΔϏϧυΦϓγϣϯ • ͜ΕΛ͚ͭΔ͜ͱͰɺSwift 6͔ΒΤϥʔʹͳΔ෦Λܯࠂͯ͘͠ΕΔΑ͏ ʹͳΔ
• Swift 5.7͔ΒมΘͬͨͷͰ࠷ۙਪ͞Εͳ͍ʢ·ͩ͑Δʣ
-strict-concurrency= • Swift 5.7(Xcode 14.0)͔ΒมΘͬͨ • https://github.com/apple/swift/pull/42523 • ΘΓʹ-strict-concurrency=LEVELͱ͍͏ΦϓγϣϯͰܯࠂϨϕϧΛબ ΔΑ͏ʹ
• minimal, targeted, completeͷ3ஈ֊ • completeϞʔυ͕-warn-concurrencyͱಉ
Xcode Projectͷઃఆ • ͳ͔ͥXcode 14.3βͰͣͬͱͿͬյΕ͍͕ͯͨɺ14.3RCͰͬͱͬͨ
// swift-tools-version: 5.8 // The swift-tools-version declares the minimum version
of Swift required to build this package. import PackageDescription let package = Package( name: "MyPackage", platforms: [ .macOS(.v11), ], targets: [ .executableTarget( name: "MyPackage", path: "Sources", swiftSettings: [ .unsafeFlags([ "-Xfrontend", "-strict-concurrency=complete", ]), ] ), ] ) Swift Packageͷઃఆ
֤ϨϕϧԿ͕ҧ͏ͷ͔ʁ • Proposalʹॻ͔Ε͍ͯͳ͍ • ͜ͷΦϓγϣϯ͕ಋೖ͞ΕͨPRswiftcͷ࣮ͰΔ͜ͱ͕Ͱ͖Δ • ͜ΕΛಡΜ͚ͩͩ͡ΌΑ͘Θ͔Βͳ͍ https://github.com/apple/swift/blob/main/include/swift/Basic/LangOptions.h https://github.com/apple/swift/pull/42523
Sendable Constraints Actor Isolation Checking Minimal ໌ࣔతʹSendableʹద߹͍ͯ͠ Δ߹ ConcurrencyΛ༻͍ͯ͠Δ߹ Targeted
ConcurrencyΛ༻͍ͯ͠Δ߹ ConcurrencyΛ༻͍ͯ͠Δ߹ Completed શͯͷίʔυ શͯͷίʔυ
Minimal • Xcodeͷॳظઃఆ • SendableΛ໌࣮ࣔͨ͠ʹؔͯ͠SendableͷνΣοΫ͕Δ ⚠Sendableʹద߹ग़དྷͳ͍߹ʹܯࠂʹͳΔ • ڞ༗͞ΕΔՄมͳ͕͋Δ߹ͳͲ
Targeted • ConcurrencyΛར༻͍ͯ͠ΔՕॴͰSendableͷνΣοΫ͕༗ޮʹͳΔ ⚠SendableͳclosureΛٻΊ͍ͯΔՕॴͰnon-sendableͳclosureΛ͢ ⚠SendableͰͳ͍ΛSendableͳclosureͰΩϟϓνϟ͢Δ
• non-sendableͳΛSendableͳclosureͰ͓͏ͱ͢Δ(Sendable Constraints) • actor͕ࢦఆ͞Ε͍ͯͳ͍asyncϝιουΛผͷactor͔Βݺ΅͏ͱ͢Δ(Actor isolation Checking)
Complete ɾSwift 6ޓϞʔυ ɾwarn-concurrencyͱಉ ⚠ConcurrencyΛ͍ͬͯͳ͍෦ʹؔͯ͠Sendable੍/Actor IsolationΛ νΣοΫ͢Δ • `MainActor(unsafe)`͕༗ޮʹͳΔ 🚨UIViewControllerͳͲɺϝΠϯεϨουͰͷಈ࡞Λఆ͍ͯ͠Δ࣮͕
MainActorҎ֎͔Βݺͳ͘ͳΔ
• ಉظؔʹ͍ͭͯSendable Constraints͕νΣοΫ͞ΕΔ • MainActor(unsafe)ͳ࣮͕MainActorʹͳΔͨΊɺ͜Ε·Ͱͱҧ͍ಉظతʹݺͳ͘ͳΔ • UIViewControllerͳͲ
ࢀߟ • Swift Concurrency ʹରԠ͍ͯͨ͘͠Ίͷ Strict Concurrency Check ͱ `@preconcurrency
import` • https://qiita.com/maiyama18/items/7f2a7c0ed4cce9d3af72
Ͳ͏͍ͬͯͯ͘͠ͷʁ • ࠷ऴతʹSwift 6·ͰʹCompleteͷܯࠂ͕ղফ͞Εͳ͍ͱϏϧυ͕௨Βͳ͘ ͳΔ • ࠓޙஈ֊తϚΠάϨʔγϣϯΛਐΊ͍ͯ͘͜ͱͰɺରԠͷݟ͕ཷ·͍͖ͬͯ ͦ͏ • ͪ͜ΒͷهࣄͰҠߦϓϥϯʹ͍ͭͯ৮ΕΒΕ͍ͯͨ
• Introducing Swift Concurrency to Merpay code • https://engineering.mercari.com/en/blog/entry/20221223-introducing- swift-concurrency-to-merpay-code/
Ͳ͏͍ͬͯͯ͘͠ͷʁ • Concurrencyͷཧղʹ5͕࣌ؒΓͳ͍ • ༷ʑͳݴޠ༷ඇಉظॲཧͷૉཆ͕ඞཁ • actor/@MainActor/Sendable/@preconcurrency • ଓ͖࠙ձͰ 🍻🍻
·ͱΊ • ܯࠂΛઃఆͯ͠Swift 6ʹ͚ͯিܸʹඋ͑Δ • -warn-concurrencyͰͳ͘ɺ-strict-concurrency=completeΛ͏ • ϚΠάϨʔγϣϯϓϥϯʹ͍ͭͯߟ͍͑ͯ͘ඞཁ͕͋Δ • ଟ͘ͷΞϓϦέʔγϣϯͰMain
Actor IsolatedͳܯࠂΛղফ͍ͯ͘͠ඞཁ ͕͋Δ