One small function followed through every stage of the Swift compiler, with real SIL, LLVM IR and x86-64 / ARM64 assembly, and a measured look at how optimization changes the cost of protocols, generics, closures and classes.
Source β Lexer β Parser β AST β Type checker β SIL β SIL optimizer β LLVM IR β LLVM optimizer β Machine code β Object file β Linker β Binary
Last year I lost most of an afternoon to a single line of arithmetic. It was in a geometry helper, nothing clever, a handful of numbers, a couple of Double(...) conversions and some parentheses. Every clean build took noticeably longer than it should have, and when I finally ran the compiler with type-checking timers switched on, that one line was the culprit.
That sent me down a path I'd been avoiding for years: actually reading what swiftc produces between my source file and the binary. This article is the write-up I wish I'd had at the start. We'll follow one tiny function through every stage of the pipeline.β¦