Getting Under Swift's Skin @ NSMeetup
Three ways to get under Swift's skin: reflection, debug toolchains, and SIL
I gave a talk Getting Under Swift’s Skin at NSMeetup, where I went over three ways to go a bit deeper in working with Swift:
- The Swift language itself, lowered to SIL
- Looking at the Swift standard library in the debugger and with custom toolchains
- Examining runtime instances with reflection
Why would you want to do these things? It can be fun to go below the surface and see how things are made. You can improve your debugging skills and get a greater understanding of the system and runtime for your apps.
As a wise man once said: let’s go one more level down.
The following are some notes and links for more information on things mentioned in the talk.
Swift and SIL
Basic SIL characteristics:
- Locals start with
- Globals start with
- Static single assignment, where variables are named with incrementing numbers and are set only once.
To see the SIL representation of your Swift source:
$ swiftc -emit-sil source.swift
To demangle symbols, run the
$ xcrun swift-demangle
- The reference guide to SIL
- Swift’s High-Level IR: A Case Study of Complementing LLVM IR with Language-Specific Optimization — talk by Joe Groff and Chris Lattner at the 2015 LLVM Developers’ Meeting
- Compiler explorer
- Swift Standard library source code on GitHub
- Ole Begemann’s guide to working with the standard library source, including how to build it
- Greg’s articles on swiftunboxed.com, including ones about the standard library
- Debugging and Reflection reference
- Advanced Swift reflection from Zewo
- Objective-C Runtime documentation: function reference for things including method swizzling, direct ivar access, querying the class of an object, setting the class of an object, etc.
- Swift’s Reflective Underpinnings — talk by Joe Groff at Swift Summit 2017.