SwiftDemangle is a library designed for demangling Swift symbols, inspired by Swift's own swift-demangle tool. It follows the demangler of Swift 6.4.2, providing an easy-to-use interface for converting mangled Swift symbols into a human-readable format.
Hardening for malformed and untrusted input. Still follows the Swift 6.4.2 demangler.
- No traps on damaged symbols: truncated
_Tsymbols, overflowing numbers, thunks without children and oversized Punycode code points are returned unchanged - Depth limits: a tree deeper than 256 levels (64 nested types for
_T) is returned unchanged, so an optimized build stays within a 512 KB thread stack - Speed: long symbols demangle in linear time (a 160 KB identifier: 61 s → 0.03 s)
$prefix: added to a string starting withs/Sonly when that makes it demangle;"sorted".demangledis"sorted", not"$sorted"- Output changes (following upstream): key path index operators print as
key path index equality operator for (Swift.String), value generic parameters as<let A>; both printedunknown indexbefore - Deprecated:
demangling(_:printDebugInformation:); the parameter has no effect
Synced with the Swift 6.4.2 demangler.
- Output changes (same symbols, new text, following upstream):
read2/modify2accessors print asyielding_borrow/yielding_mutatepredefined @objc completion handler block implementationprints aschecked @objc completion handler block implementation
- New manglings:
borrow/mutateaccessors,Builtin.Borrow<T>, property wrapped field init accessors,@caller_isolatedSIL function types,@guaranteed_address/@guaranteed/@inoutSIL results, inverse requirements on associated types (A.Element: ~Swift.Copyable),representation changed ofspecializations - Function signature specializations: constant propagated structs, chained constant propagation, escaping closure propagation and
Same As Argument N - Node tree access:
String.nodereturns the demangled tree for read-only traversal (kind,children,text,index) - Nominal owner lookup:
String.nominalOwnerreturns the nominal type that owns a symbol, including type metadata, metaclass, value witness table and field offset symbols
- add swift package index documentation for swift 6.0
- remove binary target
- add xcframework.sh script to build xcframework
Version 6.0.2 of SwiftDemangle introduces significant updates and improvements, extending support for Swift's latest features. Key updates include:
- Swift 6.0(6.1) Compatibility: Full support for Swift 6.0 demangling features
- Enhanced Generic Type Parsing: Improved handling of complex generic type signatures
- Async/Await Context Support: Better parsing of async/await related symbols
- Structured Concurrency Elements: Support for structured concurrency related demangling
- Improved Macro Support: Extended capabilities for handling macro-generated code
- Extended Platform Support: Broader platform compatibility
# If using Swift Package Manager
dependencies: [
.package(url: "https://github.com/oozoofrog/SwiftDemangle", .upToNextMajor(from: "6.4.2"))
]import SwiftDemangle
// Example 1: Demangling a Builtin Vector Type
let mangledVector = "_TtBv4Bf16_"
let demangledVector = mangledVector.demangled
print(demangledVector) // Output: Builtin.Vec4xFPIEEE16
// Example 2: Demangling a Protocol Descriptor
let mangledProtocol = "$ss6SimpleHr"
let demangledProtocol = mangledProtocol.demangled
print(demangledProtocol) // Output: protocol descriptor runtime record for Swift.Simple
// Example 3: Finding the type that owns a symbol
let owner = "$s6Widget7ManagerC9operationyyF".nominalOwner
owner?.kind == .Class // true
owner?.children.map(\.text) // ["Widget", "Manager"]nominalOwner returns nil for module-level declarations and for symbol shapes it does not support, such as protocol witnesses and reabstraction thunks.
A string that cannot be demangled is returned unchanged; the library does not trap on truncated or damaged symbols.
- A string that starts with
sorSis also tried as a symbol without its$prefix ("s4main3fooyyF".demangledgivesmain.foo() -> ()). Other text is left as it is ("sorted".demangledgives"sorted"). - A symbol whose syntax tree is deeper than 256 levels is returned unchanged. For the old
_Tmangling the limit is 64 nested types.swift-demanglehas no such limit; the deepest tree among 1.49 million symbols from Xcode's frameworks has 121 levels. - A constant-propagated function inside a function signature specialization is demangled up to 8 symbols deep; deeper ones print as their mangled text.
- With these limits, an optimized build demangles any input within a 512 KB thread stack. A debug build uses far more stack per level, so demangle on a thread with a larger stack there.
demangling(_:printDebugInformation:)is deprecated; the parameter has no effect. Usedemangling(_:).
./xcframework.shContributions are welcome! If you have ideas for improvements or have found a bug, please feel free to fork the repository, make changes, and submit a pull request.
SwiftDemangle is released under the Apache 2.0 License, ensuring compatibility with the original Swift swift-demangle source code's license terms. For more details, see the LICENSE file in the repository.