Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftコンパイラがSwiftで開発できるようになる話

 SwiftコンパイラがSwiftで開発できるようになる話

1405a601755e5fcbfdc93a2560368bb1?s=128

freddi(Yuki Aki)

July 21, 2021
Tweet

Transcript

  1. 2021/07/21 SwiftѪ޷ձ SwiftίϯύΠϥ͕SwiftͰ։ൃͰ͖ΔΑ͏ʹͳΔ࿩ freddi (@_ _ _ freddi _ _

    _)
  2. ͓·͑ͩΕ • freddi • iOS Engineer at Fukuoka • LINEελϯϓൢചத

    • ΦϦδφϧTγϟπ΋
  3. ͓·͑ͩΕ • Geekle ͱ͍͏ஂମ͕ओ࠵ͯ͠Δ iOS Conference ʹొஃ͠·͢ʂ • https://geekle.us/ios

  4. SwiftίϯύΠϥ͕SwiftͰ։ൃͰ͖ΔΑ͏ʹͳΔ

  5. ͨͩ͠Ұ෦ͷ࿩

  6. SwiftίϯύΠϥͷ։ൃݴޠ • ϨϙδτϦͷ൒෼͸C++ • ඪ४ϥΠϒϥϦΛআ͍ͯ΄΅ C++ • Driver, Parser, Type

    Checker, Optimizer ͳͲ • ࣮૷ΛಡΉʹ΋C++΍LLVMͷࣄલ஌͕͍͔ࣝͭ͘ඞཁ
  7. Swift Driver ʹ͍ͭͯ

  8. Swift Driver ʹ͍ͭͯ • ࣮͸ͪΒͬͱࠓ೥ͷWWDCͰݴٴ͞Ε͍ͯΔ • ΠϯΫϦϝϯλϧϏϧυΛߴ଎Խ͢ΔͨΊͷ3ͭͷओཁͳվળͷҰͭ https://developer.apple.com/videos/play/wwdc2021/10192/

  9. ͜͜ͰͷDriverͱ͸Կ • USBͱ͔ͷυϥΠόͱ͸શ͘ผ෺ͳͷͰ஫ҙ͞Εͨ͠ • DriverϓϩάϥϜͱ͸ɺ • ͍͔ͭ͘ͷύʔπͱͯ͠ͷϓϩάϥϜΛద੾ʹݺͼग़͢ϓϩάϥϜ • gcc ίϚϯυ͸υϥΠόϓϩάϥϜ

    • ࣮͸ swift ΍ swiftc ίϚϯυ΋υϥΠόϓϩάϥϜ
  10. swift ͷ৔߹ swift 
 (driver) package hello.swift (Կ΋ͳ͠) REPLͷىಈ helllo.swift

    ͷίϯύΠϧɾϏϧυ 
 ࣮ߦϑΝΠϧੜ੒ Swift package ؔ࿈ͷಈ࡞ swift 
 (driver) swift 
 (driver) … υϥΠό …υϥΠό΁ͷ໋ྩ … ݁Ռ
  11. ίϚϯυϥΠϯͷҾ਺ͱͷؔ܎ swift 
 (driver) package hello.swift (Կ΋ͳ͠) REPLͷىಈ helllo.swift ͷίϯύΠϧɾϏϧυ

    
 ࣮ߦϑΝΠϧੜ੒ Swift package ؔ࿈ͷಈ࡞ swift 
 (driver) swift 
 (driver) $ swift package $ swift hello.world $ swift … ϝΠϯͷίϚϯυ … Ҿ਺ͳͲ … ݁Ռ … ίϚϯυϥΠϯ্Ͱͷॻ͖ํ
  12. SwiftͷDriver • swift ίϚϯυ͕ Driver ͕ͩɺ࣮ଶ͸ swift-driver ίϚϯυ • swift-driver

    ࣗ਎͕Ͳ͏͍͏໊લͰݺ͹Ε͔ͨɺٴͼҾ਺ʹΑͬͯ
 ৼΔ෣͍΍ɺݺͼग़͢SwiftίϯύΠϥͷϞδϡʔϧΛม͑Δ • ͳͷͰίϚϯυࣗ਎͕ swift swiftc ͱݺ͹ΕΔ͔ʹΑͬͯ෼ذ͕͋Δ • swift swiftc ͸࣮͸΄΅ swift-driver ͱಉ͡ίϚϯυ • ҎલͷDriver͸C++࣮૷͕ͩɺSwift Driver ͸ Swift Ͱॻ͔Ε͍ͯΔ
  13. ͜Ε͔Βͷ Swift Driver ʹ͍ͭͯ • Swift 5.5 (Xcode 13 Beta)

    Ҏ߱Ͱඪ४Ͱར༻͞ΕΔ
  14. ͜Ε͔Βͷ Swift Driver ʹ͍ͭͯ • Swift Driver ͷ࿩ͷϝϦοτ͸͋·Γ·ͱ·ͬͯͳ͍ • ͳΜ͔

    Twitter ʹస͕͍ͬͯΔ͘Β͍ • https://twitter.com/dgregor79/status/1260798039515488257 ͜͜ • ࠓ๺࢈ۀ • SwiftPM ޲͚ͳͲͷΠϯΫϦϝϯλϧϏϧυͷվળ • ΞʔΩςΫνϟ͕վળ͞Εͯɺར఺͕૿͑ΔʢฒྻԽͳͲʣ • ৺ஔ͖ͳ͘޷͖ͳݴޠʢSwiftʣͰॻ͚Δ
  15. Swift Driver ʹؔ͢Δৄ͍͠ࢿྉ • ೔ຊޠͷࢿྉ • https://speakerdeck.com/freddi/jin-ri-karashi-meruswift-driver • https://qiita.com/freddi_/items/4c2149055959248dda28 •

    ݱঢ়ݸਓͰॻ͍ͯΔࢿྉ͸ੈքͰ๻ͷ͘Β͍͔͠ͳ͍ • ϓϩδΣΫτࣗମ͸OSSͳͷͰͦͪΒ΋ࢀর͞Εͨ͠ • https://github.com/apple/swift-driver
  16. ࠷దԽʹ͍ͭͯ

  17. SwiftίϯύΠϥͷ࠷దԽ෦෼ • ࠷దԽ෦෼ͷ࣮૷͸͢΂ͯC++ͩͬͨ • ͔͠͠ɺlibswift ͱ͍͏΋ͷʹΑͬͯ Swift Ͱ΋ॻ͚ΔΑ͏ʹͳͬͨ • ଟ෼ஈ֊తʹҠߦ͢Δʁ

    • https://github.com/apple/swift/blob/main/libswift/README.md
  18. SwiftίϯύΠϥͷ࠷దԽ෦෼ raw SIL canonical SIL Pass Pass Pass Pass •

    Swift ίʔυ͸ίϯύΠϥ಺Ͱ SIL ͱݺ͹ΕΔίʔυʹม׵͞ΕΔ • SIL ͸࠷దԽ͞ΕΔ͕ɺ࠷దԽલ͕ raw SILɺޙ͕ canonical SIL • raw SIL ΛͦΕͧΕͷ໾ׂͰ࠷దԽ͢ΔϞδϡʔϧ͕ Pass • Pass ͕ Swift Ͱॻ͚ΔΑ͏ʹͳͬͨɺͱ͍͏࿩ (libswift)
  19. SwiftίϯύΠϥͷ࠷దԽ෦෼ • NSSpain 2020 Ͱ ͜͜Β΁Μͷৄ͍͠࿩͕͋ΔͷͰؾʹͳΔํ͸
 ࢀর͞Εͨ͠ https://vimeo.com/479467405

  20. C++ ͔Β Swift ʹ͢Δࡍͷݒ೦ • SwiftͷϝϞϦ؅ཧํ๏͸ ARCɺҰํC++͸΄΅ϓϩάϥϚ͕΍Δ • ARC ͸ศར͚ͩͲΦʔόʔϔου͕͋Δ

    • ARCͷΧ΢ϯτ෼ɺཪͰίʔυ͕૿͑ͨΓ͍ͯ͠Δͷ͸ࣄ࣮ • libswift Ͱ͸ͦΕΛճආ͢ΔͨΊͷ޻෉͕͋Δ Θ͍Θ͍swiftc #29 Ͱ͜͜Β΁Μͷ࿩͕͋Γ·͢ʂ https://iosdiscord.connpass.com/event/218858/
  21. Swift Ͱॻ͘ํ๏ • libswift ͸ Swift Package Manager ܦ༝ͰimportՄೳʂ •

    ͔ΜͨΜʹ Optimizer ͷ Pass Λ։ൃͰ͖·͢ Θ͍Θ͍swiftc #29 Ͱ͜͜Β΁Μͷ࿩͕͋Γ·͢ʂ https://iosdiscord.connpass.com/event/218858/
  22. ·ͱΊ

  23. SwiftίϯύΠϥͷҰ෦͕SwiftͰ։ൃͰ͖Δ • Swift Driver Project • https://github.com/apple/swift-driver • https://twitter.com/dgregor79/status/1260798039515488257 •

    Swift ͷ࠷దԽ෦෼ • https://github.com/apple/swift/blob/main/libswift/README.md • Θ͍Θ͍swiftc #29 Ͱղઆ͞ΕΔͷͰདྷͯͶʂ
 https://iosdiscord.connpass.com/event/218858/