IT lexicon › Programming › Swift calling convention

Swift calling convention

Programming På svenska → Updated: 2026-11-06

The custom calling convention, swiftcc in LLVM, that Swift uses instead of the platform's C convention so it can pass context, errors and return values in dedicated registers.

The C conventions were designed for C, and Swift wanted three things C doesn't do. Methods need a self, which gets its own fixed register (swiftself, r13 on x86-64). Throwing functions return the error in another reserved register (swifterror), so error handling is a cheap register test rather than exceptions with stack unwinding. And small structs come back directly in up to four registers instead of through memory.

Swift 5 made the ABI stable on Apple platforms in 2019, which turned the convention into part of the operating system: the system libraries are built with it and apps link against them without bundling their own runtime. When async/await arrived, one more register was set aside for the asynchronous context.

← Back to the lexicon