Swift Shims


(Fernando Rodríguez) #1

Hi,

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?

Thanks!

FRR


(Dmitri Gribenko) #2

SwiftShims is a private interface between the standard library, the
runtime, and the OS. Unless you are working on the standard library,
you don't need to worry about it.

Dmitri

···

On Wed, Aug 3, 2016 at 8:39 PM, Fernando Rodríguez <swift-corelibs-dev@swift.org> wrote:

Hi,

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...

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/


(Brent Royal-Gordon) #3

"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.

···

On Aug 3, 2016, at 8:39 PM, Fernando Rodríguez via swift-corelibs-dev <swift-corelibs-dev@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?

--
Brent Royal-Gordon
Architechies


(Fernando Rodríguez) #4

Thanks, cristal clear! :slight_smile:

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.

···

On August 3, 2016 at 9:51:38 PM, Brent Royal-Gordon (brent@architechies.com) wrote:

On Aug 3, 2016, at 8:39 PM, Fernando Rodríguez via swift-corelibs-dev < swift-corelibs-dev@swift.org> wrote:

--
Brent Royal-Gordon
Architechies