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
社内版SwiftコンパイラにContributeするまで
Search
freddi(Yuki Aki)
October 09, 2020
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
社内版SwiftコンパイラにContributeするまで
freddi(Yuki Aki)
October 09, 2020
More Decks by freddi(Yuki Aki)
See All by freddi(Yuki Aki)
輝け俺のViewController 〜海外iOSカンファレンス登壇編〜
freddi
4
430
Deep Dive into "any" and "some"
freddi
3
1.8k
挑戦!ISUCON de Server-side Swift 〜タイムゾーンには気をつけろ〜
freddi
0
2.2k
意外と知られてないXcode13の新しい参照カウンタ最適化オプションの挙動
freddi
2
210
How to develop SIL Optimizer in Swift Language
freddi
0
420
SwiftコンパイラがSwiftで開発できるようになる話
freddi
3
710
知ろう! ShazamKit
freddi
1
250
Swift Optimizing at Compiler World
freddi
2
920
Recap Pointfree Vol. 1~3
freddi
1
920
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
600
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Mind Mapping
helmedeiros
1
370
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Utilizing Notion as your number one productivity tool
mfonobong
4
590
Transcript
SwiftίϯύΠϥʹContribute͢Δ·Ͱ freddi (LINE Fukuoka) Engineer Casual Meetup - Oct. 9
2020
Agenda • Contributeͨ͠༰ ͷͳ͠ • Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • Swift
Intermediate Language ͷͳ͠ • SILOptimizer ʹ͍ͭͯ • (͋ΒͨΊͯ) Contributeͨ͠༰ ͷͳ͠
Agenda • Contributeͨ͠༰ ͷͳ͠ • Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • Swift
Intermediate Language ͷͳ͠ • SILOptimizer ʹ͍ͭͯ • (͋ΒͨΊͯ) Contributeͨ͠༰ ͷͳ͠ ͷೖϑϩʔ
Contributeͨ͠༰ ͷͳ͠ • ̎ͭ Contribute ͨ͠ • https://github.com/apple/swift/pull/33851 • ࠷దԽϩδοΫͷϛε
• https://github.com/apple/swift/pull/31847 • Docs ͷ BNF Ͱॻ͔Εͨ Grammer ͷϛε
Contributeͨ͠༰ ͷͳ͠ • https://github.com/apple/swift/pull/33851 • ࠷దԽϩδοΫͷϛε • ʮ෭࡞༻͕͋Δ͔Εͳ͍ʯϩδοΫͷݕग़ϛε • Ұ෦ڧ੍Ϋϥογϡ͕ʮ෭࡞༻ͳ͠ʯʹͳΔϛε
• ࠷దԽϩδοΫ͕ҙਤͨ͠ͷͰͳ͘ͳΔՄೳੑ
Contributeͨ͠༰ ͷͳ͠
Contributeͨ͠༰ ͷͳ͠ • https://github.com/apple/swift/pull/31847 • υΩϡϝϯτͰղઆ͍ͯ͠Δ Grammer ͷϛε • ͕ࣗಡΜͩ
SIL ͷίʔυ ͱҧ͏͔Βؾ͍ͮͨ • SIL ͷυΩϡϝϯτͨ·ʹΨόΨό
Contributeͨ͠༰ ͷͳ͠ • https://github.com/apple/swift/pull/33851 • ࠷దԽϩδοΫͷϛε ← ࠓͬͪ͜ͷ • ͜ͷ
มߋͷཧղΛ௨ͯ͡SwiftίϯύΠϥʹೖ͢Δ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • Swift ͜ΜͳϑϩʔͰίϯύΠϧ͞ΕΔ • Swift ίϯύΠϥΔͱͷإΑΓݟΔ͜ͱʹͳΔ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • օ͞Μ͓ͳ͡Έ Swift ίʔυ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • AST (நߏจ) • ϓϩάϥϜΛจ๏ͷߏʹ฿ͬͨߏʹͨ͠ͷ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • AST (நߏจ) • ԋࢉࢠͷ༏ઌͱ͔ߏจͷߏͰܾ·ͬͨΓ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • SIL (Swift Intermediate Language) • Swift
ಛ༗ͷநදݱ
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • SIL (Swift Intermediate Language) • ͜͜ͰSwiftಛ༗ͷ
࠷దԽ͕ߦΘΕΔ • ࠓͷTopic
Swift ͷίϯύΠϧϑϩʔ ͷͳ͠ • LLVM IR => … • SIL
Λ LLVM IR ʹͯ͠LLVM ʹ͛Δ • ͦͷ͋ͱϦϯΧʹ͛ΒΕͨΓ • όΠφϦʹͳΔ
Swift Intermediate Language ͷͳ͠ • Swift ಛ༗ͷதؒදݱ • ͜͜Ͱ Swiftಛ༗ͷ࠷దԽ͕ߦΘΕΔ
Swift Intermediate Language ͷͳ͠ • ͲͪΒखݩʹ swiftc ίϚϯυ͕͋ΕੜՄೳ
Swift Intermediate Language ͷͳ͠ • ࢼ͠ʹ hello world! Λ SIL
Ͱ ੜͯ͠ΈΔ • ࠓճ͕࣌ؒͳ͍ͷͰ raw SIL ͚ͩ
Swift Intermediate Language ͷͳ͠ • ͍ɾಡΈͮΒ͍ʢʁʣ
Swift Intermediate Language ͷͳ͠ • SIL͕swiftίʔυΑΓ͘ͳΔཧ༝ • ؔʢԾʣςʔϒϧͷใ • ࡉ͔͍ϝϞϦͷ֬อϦϑΝϨϯεΧϯτͷ໋ྩ
• Main ؔͳͲͷల։
Swift Intermediate Language ͷͳ͠ • SIL ͷߏΛେ͖͍ॱʹ • SILModule (ιʔείʔυશମ)
• SILFunction (֤ؔ) • SILBasicBlock (͍ΘΏΔείʔϓ) • SILInstruction (SILίʔυҰจҰจ)
Swift Intermediate Language ͷͳ͠ • ͍͍ͩͨ͜ΕΒΛཧղ͢ΔͱSILͬ͘͟ΓಡΊΔ • SIL͕swiftίʔυΑΓ͘ͳΔཧ༝ • SIL
ͷߏͷॱং
Swift Intermediate Language ͷͳ͠ • SILModule
SILFunction
SILBasicBlock
SILBasicBlock
SILBasicBlock Α͘ΈͨΒ bb0: ͬͯͳ͍ͬͯΔ -> basic block ͷུͰ͢ ݅ذͰBasic Block૿͑Δ
SILInstruction
Swift Intermediate Language ͷͳ͠ • ͜ͷߏΛ͍ͬͯΔͱίϯύΠϥͷίʔυͷҰ෦͕ ಡΊΔΑ͏ʹͳΔ • ͦΕ͕ SILOptimizer
ͷίʔυ
SILOptimizer ʹ͍ͭͯ • SIL (Swift Intermediate Language) • ͜͜ͰSwiftಛ༗ͷ ࠷దԽ͕ߦΘΕΔ
SILOptimizer ʹ͍ͭͯ
SILOptimizer ʹ͍ͭͯ
SILOptimizer ʹ͍ͭͯ • raw SIL ੜޙɺSILOptimizer ʹΑͬͯ࠷దԽ͞ΕΔ • SILOptimizerதͷͨ͘͞Μ͋ΔPassͱ͍͏ϞδϡʔϧͰ ͦΕͧΕͷతͷ࠷దԽ͕ߦΘΕΔ
• ࠓͦͷPassͷίʔυΛಡΉ • Passͷίʔυͷجૅ͕٧·͍ͬͯΔ
SILOptimizer ʹ͍ͭͯ • ࠓ AssumeSingleThreaded ΛಡΉ • γϯάϧεϨου͚ͩͰಈ͔͞ΕΔͷʹಛԽ͢ΔΑ͏ʹ ͢Δ࠷దԽ •
ΦϓγϣϯͰൃಈ͞ΕΔ • PassͷதͰଟҰ൪͍
SILOptimizer ʹ͍ͭͯ
SILOptimizer ʹ͍ͭͯ SILFunctionTransform Λܧঝ -> FuncitonΛࠪ͢ΔPassʹͳΔ
SILOptimizer ʹ͍ͭͯ Ծؔ run Λ࣮ -> Pass ͷ࠷దԽϩδοΫ͜͜ʹॻ͘
SILOptimizer ʹ͍ͭͯ ίϯύΠϥͷυϥΠόʢίϚϯυʣʹ͞ΕͨΦϓγϣϯΛΈΔ
SILOptimizer ʹ͍ͭͯ ࠓݟ͍ͯΔؔΛSILFunctionܕͷ σʔλͱͯ͠ड͚औΔ
SILOptimizer ʹ͍ͭͯ SILFunctionSILBasicBlockͷCollection ͱͯ͠ѻ͑ΔʢͳͷͰBBʣ
SILOptimizer ʹ͍ͭͯ SILBasicBlockSILInstructionͷCollection ͱͯ͠ѻ͑ΔʢͳͷͰIʣ
SILOptimizer ʹ͍ͭͯ ͳͷͰɺ͜͜Ͱؔͷ InstructionΛ͍ࠪͯ͠Δ
SILOptimizer ʹ͍ͭͯ ֤InstructionܕͰදݱ͞Ε͍ͯΔ ΩϟετͰಛఆͷInstruction͔ௐΔ
SILOptimizer ʹ͍ͭͯ ϦϑΝϨϯεΧϯλؔͷInscrutionͳΒ NonAtomicʹ͢Δ
SILOptimizer ʹ͍ͭͯ • AssumeSingleThreaded ʹ͍ͭͯ • FunctionͷInstructionΛࠪ • ϦϑΝϨϯεΧϯλؔͩͬͨΒnon Atomicʹ͢Δ
SILOptimizer ʹ͍ͭͯ • SILOptimizer ͷίʔυΛಡΉͱ͖ͷTips • ུޠ͕ଟ͍ͷͰίϯςΫετͰஅ͢Δ • ෳࡶͳϩδοΫ C++
Λཧղ͔ͯ͠ΒಡΉ
Contributeͨ͠༰ ͷͳ͠ • ࠓճͨ͠ͷɺmayHaveSideEffect ͱ͍͏ؔ • ʮ෭࡞༻͕͋Δ͔Εͳ͍ʯInstructionΛݟΔ • SILInstruction ܕͷ
ϝϯόม • Dead Code EliminationʹΘΕΔ
Contributeͨ͠༰ ͷͳ͠ • ͜ͷ݅ͷ̍൪͕ϛε͍ͬͯͨ(mayTrap ؔ)
Contributeͨ͠༰ ͷͳ͠
Contributeͨ͠༰ ͷͳ͠ • ίϯύΠϥͷInstructionͷछྨͷදݱํ๏ • ઌఔਃ্͛ͨ͠ܕʹΑΔදݱʢΩϟετʹΑΔผʣ • Enum ʹΑΔදݱʢswitch ͳͲ
ʹΑΔผʣ • मਖ਼Օॴͬͪ͜Ͱදݱ͞Ε͍ͯΔ
Contributeͨ͠༰ ͷͳ͠ • ͪΐͬͱ̎൪Ίͷհ
Contributeͨ͠༰ ͷͳ͠ • ϝϞϦΞΫηε͕ى͜Γͦ͏ͳInstructionͷݕํ๏ • SILInstruction ͷଐੑΛݟΔ • LLVMͷInstruction ͷଐੑΛݟΔ
• apply Instruction ͳΒݺͼग़͠ઌͷؔͷଐੑΛݟΔ • ͜͜ΒΜͷॲཧͯͯ͝͝ͷXϚΫϩ͕ೖͬͨॲཧͳͷ ͰׂѪɻڵຯ͕͋ͬͨΒ࣭Ͱฉ͍͍ͯͩ͘͞
Contributeͨ͠༰ ͷͳ͠
Contributeͨ͠༰ ͷͳ͠
Contributeͨ͠༰ ͷͳ͠ • ͏গ͠Γ͍ͨํ Θ͍Θ͍swiftc #20 ͷͷࢿྉΛݟ͍ͯͩ͘͞
• https://speakerdeck.com/freddi/mayhavesideeffect
Contributeͨ͠༰ ͷͳ͠ • ͜ͷमਖ਼ՕॴͳΜͰݟ͚ͭͨͷʁ • झຯͰίϯύΠϥίʔυಡΜͰ͍ͨΒۮવΈ͚ͭͨ • bug.swift.orgͰόάνέοτʹͳ͔ͬͨ
Contributeͨ͠༰ ͷͳ͠ • PRग़ͨ͠ΒɺTest ॻ͍ͨΒϚʔδ͢ΔͱݴΘΕͨ • SILͷςετ LLVMͷlitΛ͍ͬͯΔΒ͍͠ • LLVM
Integrated Tester ͷུ • ͦΜͳ͜ΜͳͰϚʔδ͞Εͨ • ͭʹόάνέοτΛΔඞཁͳ͍Β͍͠
Contributeͨ͠༰ ͷͳ͠ • SIL.rst ͱ͍͏υΩϡϝϯτ͕SILʹ͍ͭͯৄ͘͠هࡌ • https://github.com/apple/swift/blob/main/docs/SIL.rst • ͨͩ͠ɺSIL.rst ΨόΨόͳͷͰContributeνϟϯε͕
ͨ͘͞Μ͋Δ • ͜͜मਖ਼Λ͛ͨ͜ͱ͕͋Δ
·ͱΊ • SILΛಡΈ͡ΊΔͱίϯύΠϥೖΓ͍͢ • SIL͕ಡΊΔͱ࠷దԽͷίʔυ͕ಡΊΔΑ͏ʹͳΔ • Contributeʹؔͯ͠ݫ͍͠ϧʔϧͳ͍ͷͰ ؾܰʹͰ͖Δ • ಛʹυΩϡϝϯτΨόΨόͳͷͰContributeͯ͠ΈΑ͏