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
590
15年メンテしてきたdotfilesから開発トレンドを振り返る 2011 - 2026
giginet
PRO
2
490
Claude Codeログ基盤の構築
giginet
PRO
7
4.7k
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.7k
Mergeable Libraryで 高速なアプリ起動を実現しよう!
giginet
PRO
2
8.5k
5分でわかるExplicitly Built Modules
giginet
PRO
2
1.9k
Other Decks in Programming
See All in Programming
Java 27新機能 / Java 27 new features
kishida
2
150
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.1k
Intent as Code
shoppingjaws
6
1.1k
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
5
3.5k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
220
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
210
新卒PdEのリアル
ryu1013
1
510
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
250
アクセシビリティから考える情報設計
high_g_engineer
0
380
Jetpack Compose メカニズム
skydoves
0
450
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
380
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
220
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
52k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
Faster Mobile Websites
deanohume
310
32k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
940
Being A Developer After 40
akosma
91
590k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
530
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
It's Worth the Effort
3n
188
29k
Speed Design
sergeychernyshev
33
2.1k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
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ͳܯࠂΛղফ͍ͯ͘͠ඞཁ ͕͋Δ