[swift-corelibs-dev] Swift Shims

Brent Royal-Gordon brent at architechies.com
Wed Aug 3 23:51:35 CDT 2016

> On Aug 3, 2016, at 8:39 PM, Fernando Rodríguez via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> I'm having some trouble  understanding what on Earth SwiftShims are. The name probably makes it obvious to native English speakers, but it's not helping me...
> Could someone please enlighten me?

"Shim" is a relatively common programming term; it means a lightweight compatibility layer which corrects for differences between platforms. For instance, if you're supporting three different OSes with three different random number calls, you might write a `randomNumber()` shim function which calls whichever one is correct for that platform.

(Outside of programming, a "shim" is a thin piece of material, often wood, which you put under the leg of a piece of furniture if it's crooked or wobbly.)

SwiftShims specifically contains functions written in C, C++, or Objective-C++ which the Swift standard library's internals need to call. These functions often translate the parameter types of calls into forms which are easier to call from Swift, or fill in functionality that's missing on certain platforms. For instance, the I/O in the standard library's `readLine()` function is handled by a C++ function called `swift_stdlib_readLine_stdin()`. That function is part of SwiftShims; on most platforms, it calls through to a C standard library `getline()` function, but on a few it emulates that function's behavior.

Unless you're working on the standard library (or Foundation, which I believe uses a couple of SwiftShims calls), you shouldn't ever interact with or care about SwiftShims. It's a private implementation detail of Swift.

Brent Royal-Gordon

More information about the swift-corelibs-dev mailing list