Preparing for Swift 5 Ownership

Preparing for Swift 5 Ownership

Swift 5 の Ownership に備える

try! Swift Tokyo 2018 #tryswiftconf
https://www.tryswift.co/events/2018/tokyo/en/

Ee6254efe6c4bc4c08967c11d4939245?s=128

kotetu (kotetuco)

March 02, 2018
Tweet

Transcript

  1. Preparing for Swift 5 Ownership <4XJGUͷ0XOFSTIJQʹඋ͑Δ>

  2. Kuriyama Toru <܀ࢁప> iOS Engineer at Sansan app (iOS/Android) “Business

    card-based contact management” Twitter: @kotetuɹɹɹɹɹɹ Github: @kotetuco
  3. OwnershipManifesto.md (in GitHub - apple/swift) ഉଞଇ͸4XJGUͰ࣮૷ࡁΈ (swift-evolution’s proposal : SE-0176)

    Ownership
  4. ίϐʔ΍ࢀরʹର͢ΔΑΓࡉ੍͔͍ޚͷ࣮ݱ ΑΓߴ౓ͳύϑΥʔϚϯενϡʔχϯά͕Մೳʹ Feature1: Advanced memory management

  5. Example (shared values) func distance(start: shared CGPoint, end: shared CGPoint)

    -> Double { ... } let result = distance(start: CGPoint(x: 0, y: 0), end: CGPoint(x: 10, y: 10))
  6. Example (shared values) func distance(start: shared CGPoint, end: shared CGPoint)

    -> Double { ... } let result = distance(start: CGPoint(x: 0, y: 0), end: CGPoint(x: 10, y: 10)) not copied not copied
  7. func distance(start: shared CGPoint, end: shared CGPoint) -> Double {

    ... } let result = distance(start: CGPoint(x: 0, y: 0), end: CGPoint(x: 10, y: 10)) Example (shared values) not copied read-only not copied read-only
  8. Non-copyable types ίϐʔෆՄೳͳܕ ҉໧తͳίϐʔΛ੍ݶ͢Δ  JavaͷAtomicBooleanͷΑ͏ͳදݱ͕Մೳʹ moveonly struct Array<Element> {

    ... }
  9. ࢖͍͜ͳ͢ʹ͸ֶशίετ͕͔͔Δ ͳ͔ͳ͔ফ͑ͳ͍ίϯύΠϧΤϥʔ ઌൃͷRustͰ΋ֶशίετͷߴ͕͞՝୊ʹ Feature2: Ownership is not easy

  10. Ownership͸ഉଞଇҎ֎͸ΦϓτΠϯػೳ SwiftͰ͸OwnershipΛ஌Βͳͯ͘΋ࢧো͸ͳ͍ ͜Ε·Ͱͱಉ͡ॻ͖ํͰ΋0,  RustͰ͸OwnershipΛ஌Βͳ͍ͱॻ͚ͳ͍ Feature3: Opt-in

  11. Conclusions 1. ϝϞϦΞΫηε΍ίϐʔʹ͍ͭͯߴ౓ͳ੍ޚ ͕Ͱ͖Δ 2. ֶशίετ͕͔͔Δ 3. ࢖͏͔Ͳ͏͔Λબ୒͢Δ͜ͱ͕Ͱ͖Δ

  12. Referenced by • https://github.com/apple/swift/blob/master/docs/ OwnershipManifesto.md • https://github.com/apple/swift-evolution/blob/master/proposals/ 0176-enforce-exclusive-access-to-memory.md • https://qiita.com/omochimetaru/items/c5f0eabde516e4713367

    • https://github.com/omochi/swift-ownership-jp/blob/master/ OwnershipManifesto.md • https://github.com/rust-lang/rust-roadmap
  13. I hope you'll enjoy it !

  14. Thanks!