5.8 · Symbol names, linkage, lazy globals and reflection metadata: what is in the binary
The compiled module has names, visibility and tables of its own: how a declaration becomes a symbol, why an unused internal function can vanish, when a global is initialised, and what the reflection tables cost and enable.
Mental model. Source-level access control becomes linkage, source names become mangled symbols, and a type also leaves metadata behind. Each of those is something you can look at.
Names and visibility
How a declaration is named in the object file, and which ones survive.
- What is name mangling in Swift, how do you read a symbol such as $s4Main3FooV3baryyF, and where do you meet mangled names in practice?
Swift has overloading, generics, modules and nested types, so a plain name cannot identify a function in an object file. The compiler builds a mangled name… - How do access levels become linkage in the object file, and why can an unused internal function disappear in a release build but a public one cannot?
The compiler maps access control onto symbol visibility. public and open declarations are exported: they stay in the module’s API, keep a default-visibility…
Initialisation and metadata
When globals run, and what reflection tables ship.
- When is a Swift global or static property initialised, what is swift_once, and when does the optimiser make the initialiser disappear?
Globals and static let properties in a normal file are lazy: the initialiser runs the first time the value is read, exactly once, even if several threads race.… - What reflection metadata does the compiler emit for every type, what depends on it, and what does -disable-reflection-metadata do?
For each struct, class and enum the compiler emits field descriptors: tables of stored-property names and types, in sections such as __swift5_fieldmd and…
More in Compiler & language internals
- 5.1 · From source to machine code, and how to look inside
- 5.2 · Devirtualisation, whole-module optimisation, inlining, exclusivity
- 5.3 · Specialisation, witness tables, and opaque vs existential in the compiled code
- 5.4 · Library evolution, module interfaces, and the ABI boundary
- 5.5 · How Swift macros work, and the roles they play
- 5.6 · Why it compiles slowly, and what rebuilds
- 5.7 · Swift 6 language mode and upcoming features
- 5.9 · Optimisation levels, closure contexts, ownership conventions and value layout
- 5.10 · What property wrappers, result builders, async and throws compile to
- 5.11 · Package access, SPI, internal imports, strict memory safety and pre-specialisation