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

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

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

freddi(Yuki Aki)

July 21, 2021
Tweet

More Decks by freddi(Yuki Aki)

Other Decks in Technology

Transcript

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

    Checker, Optimizer ͳͲ • ࣮૷ΛಡΉʹ΋C++΍LLVMͷࣄલ஌͕͍͔ࣝͭ͘ඞཁ
  2. swift ͷ৔߹ swift 
 (driver) package hello.swift (Կ΋ͳ͠) REPLͷىಈ helllo.swift

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

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

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

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

    ݱঢ়ݸਓͰॻ͍ͯΔࢿྉ͸ੈքͰ๻ͷ͘Β͍͔͠ͳ͍ • ϓϩδΣΫτࣗମ͸OSSͳͷͰͦͪΒ΋ࢀর͞Εͨ͠ • https://github.com/apple/swift-driver
  7. SwiftίϯύΠϥͷ࠷దԽ෦෼ raw SIL canonical SIL Pass Pass Pass Pass •

    Swift ίʔυ͸ίϯύΠϥ಺Ͱ SIL ͱݺ͹ΕΔίʔυʹม׵͞ΕΔ • SIL ͸࠷దԽ͞ΕΔ͕ɺ࠷దԽલ͕ raw SILɺޙ͕ canonical SIL • raw SIL ΛͦΕͧΕͷ໾ׂͰ࠷దԽ͢ΔϞδϡʔϧ͕ Pass • Pass ͕ Swift Ͱॻ͚ΔΑ͏ʹͳͬͨɺͱ͍͏࿩ (libswift)
  8. C++ ͔Β Swift ʹ͢Δࡍͷݒ೦ • SwiftͷϝϞϦ؅ཧํ๏͸ ARCɺҰํC++͸΄΅ϓϩάϥϚ͕΍Δ • ARC ͸ศར͚ͩͲΦʔόʔϔου͕͋Δ

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

    ͔ΜͨΜʹ Optimizer ͷ Pass Λ։ൃͰ͖·͢ Θ͍Θ͍swiftc #29 Ͱ͜͜Β΁Μͷ࿩͕͋Γ·͢ʂ https://iosdiscord.connpass.com/event/218858/
  10. 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/