Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Go beyond the Actor Boundary ~ Swift 6へのConcurr...

giginet
March 24, 2023

Go beyond the Actor Boundary ~ Swift 6へのConcurrency対応 ~

giginet

March 24, 2023
Tweet

More Decks by giginet

Other Decks in Programming

Transcript

  1. ୭ʁ • @giginet • LINEגࣜձࣾ Developer Experience։ൃνʔϜ • ٕज़ސ໰ •

    ϚωʔϑΥϫʔυ, peep, ϢϏϨδ • OSSϝϯςφ • Carthage, XcodeGen, fastlaneͳͲ • ϙέϞϯϥϯΫϚον੎
  2. ࠓ೔࿩͢͜ͱ • Swift Concurrencyʹ͍͓ͭͯ͞Β͍ • Race Conditions, Actor Boundary, Sendable

    • Swift 6.0࣌୅ʹ޲͚ͯԿΛ͢Ε͹ྑ͍͔ • ݱঢ়ઃఆͰ͖Δޓ׵Ϟʔυʹ͍ͭͯڍಈ΍ݱঢ়Λௐ΂ͨ
  3. 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
  4. ࢀߟࢿྉ • 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/
  5. Swift 6 • ͜ͷΑ͏ͳةݥͳίʔυΛίϯύΠϧ࣌ʹνΣοΫͯ͘͠ΕΔΑ͏ʹ ͳΔ • Sendable͕ඞཁͳՕॴͰ͸ඞਢʹͳΔ(Sendable Constraints) • ಛఆͷεϨουͰͷಈ࡞Λڧ੍

    (Actor Isolation Checking) • →ࠓ·Ͱಈ͍͍ͯͨίʔυ͕ಈ͔ͳ͘ͳΔՄೳੑ • →Swift 6͕ग़ͨͱ͖ʹ߄ͯͳ͍Α͏ʹɺࠓͷ͏ͪʹ४උ͓ͯ͘͠ඞ ཁ͕͋Δ
  6. // 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΁ͷઃఆ
  7. Sendable Constraints Actor Isolation Checking Minimal ໌ࣔతʹSendableʹద߹͍ͯ͠ Δ৔߹ ConcurrencyΛ࢖༻͍ͯ͠Δ৔߹ Targeted

    ConcurrencyΛ࢖༻͍ͯ͠Δ৔߹ ConcurrencyΛ࢖༻͍ͯ͠Δ৔߹ Completed શͯͷίʔυ શͯͷίʔυ
  8. ࢀߟ • Swift Concurrency ʹରԠ͍ͯͨ͘͠Ίͷ Strict Concurrency Check ͱ `@preconcurrency

    import` • https://qiita.com/maiyama18/items/7f2a7c0ed4cce9d3af72