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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
610
15年メンテしてきたdotfilesから開発トレンドを振り返る 2011 - 2026
giginet
PRO
2
500
Claude Codeログ基盤の構築
giginet
PRO
7
4.7k
Inside of Swift Export
giginet
PRO
1
3.6k
Swiftビルド弾丸ツアー - Swift Buildが作る新しいエコシステム
giginet
PRO
0
3k
SwiftでMCPサーバーを作ろう!
giginet
PRO
3
490
Creating Intuitive Developer Tool in Swift
giginet
PRO
0
1.7k
Mergeable Libraryで 高速なアプリ起動を実現しよう!
giginet
PRO
2
8.6k
5分でわかるExplicitly Built Modules
giginet
PRO
2
1.9k
Other Decks in Programming
See All in Programming
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
640
phperだってパンチカードでコーディングしたい
o0h
PRO
0
330
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
golang-bob.pdf
iwatsukayura
0
130
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Jetpack Compose Mechanisms
skydoves
3
820
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
AWSに止められる覚悟してますか?
morizo_1984
2
530
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Optimizing for Happiness
mojombo
378
71k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
330
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
A Modern Web Designer's Workflow
chriscoyier
699
190k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Claude Code のすすめ
schroneko
67
230k
Between Models and Reality
mayunak
4
500
Faster Mobile Websites
deanohume
310
32k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
New Earth Scene 8
popppiees
4
2.7k
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ͳܯࠂΛղফ͍ͯ͘͠ඞཁ ͕͋Δ