What are Swift mangled names such as $s3sym7AccountV7deposityySiF, how do you read them, and where do they show up?
Predict first
What does swift demangle print for $s3sym7AccountV7deposityySiF?
// === main.swift ===
struct Account {
var balance = 0
mutating func deposit(_ x: Int) { balance += x }
}
var a = Account(); a.deposit(2); print(a.balance)
- sym.Account.deposit(Swift.Int) -> ()
- Account.deposit
- sym.deposit
Mental model. A packing label: short codes for sender, item and size, readable with the legend.
Swift encodes a symbol’s module, type, name and signature into its linker name. $s marks Swift 5+ mangling, then length-prefixed identifiers (3sym the module, 7Account the type with V for struct, 7deposit the function) and a signature tail (ySiF: takes Int, returns nothing). swift demangle reverses it: the check prints sym.Account.deposit(Swift.Int) -> (), and --simplified trims module prefixes. Suffixes mark compiler-made variants, such as a resume point of an async function (TY0_).
You meet mangled names in unsymbolicated crash reports, nm output, linker errors, Instruments without symbols and sample output. Pipe them through swift demangle (it demangles inside surrounding text), or xcrun swift-demangle. Never parse the mangling in your own tooling; it changes between compiler versions and depends on generics, concurrency and access level. Knowing the structure helps you recognise a closure, a witness or a thunk in a stack.
Module, type, function and signature are all in the name.
Common traps
- Hand-decoding names for tooling. Use the demangler of the matching toolchain.
- Expecting the same name across Swift versions. Mangling evolves.
They might follow up with
- Where are names stored? The symbol table, unless stripped (Q461).
- Why is a closure unnamed? It shows as
closure #1 in ….
Related questions
- 23.5.1 How do you read a crash report, what do the exception types and Swift runtime messages mean, and how does…
- 23.10.2 How do you symbolicate one crash address by hand: load address, ASLR slide, atos, stripped binaries and dSYMs?
How do you symbolicate one crash address by hand: load address, ASLR… →