docs/swift-export/testing-usr-stability.md
Swift symbol USRs (Unified Symbol Resolution) are compiler-generated identifiers emitted by
swift symbolgraph-extract. The Swift export integration tests assert on demangled USRs
(SwiftSymbol.demangledId) for readability, while the raw USR is used only during extraction.
extractModuleSymbols reads the symbolgraph JSON and extracts raw USRs and pathComponents.xcrun swift-demangle --compact and stored in
SwiftSymbol.demangledId.toString() returns demangledId, so assertion failure diffs are human-readable.Compound USRs containing ::SYNTHESIZED:: (used for protocol extension members that Swift
synthesizes automatically, such as localizedDescription from Foundation.Error) are split,
each part demangled separately, and reassembled as
"<demangled lhs> [SYNTHESIZED for <demangled rhs>]".
The tests assume that, for the same Kotlin sources and export configuration, the resulting USR strings remain stable across runs. This is generally true within a fixed toolchain, but USRs can change when:
A change in USRs is not automatically a regression. It can be either:
SwiftSymbol entries in the test (demangledId and
pathComponents).--compact (matches the tests) and either:
xcrun swift-demangle --compact '$s6Shared3fooyyF'
$s prefix explicitly):
echo '$s6Shared3fooyyF' | xcrun swift-demangle --compact
SwiftExportIT.kt — test expectations with hardcoded symbolsSwiftExportUtils.kt — SwiftSymbol, parsing, demangling, and assertion helpers