Jacob’s Tech Tavern

Jacob’s Tech Tavern

2 Minute Tips: The Dark Secrets of Bools

Mysteries of the Swift Standard Library

Jacob Bartlett's avatar
Jacob Bartlett
Dec 25, 2023
Image generated by Dall-E 3. Looks like AI isn’t coming after our jobs anytime soon.

Booleans are the simplest type in the Swift language.

They’re simply true or false. The most basic language primitive you could imagine.

I was so naïve.

We only see the public interface of the Swift Bool. Much like seeing a sausage made; vivisecting its innards in the source code might put you off forever.

A Frozen Struct

// Bool.swift

@frozen
public struct Bool: Sendable { 

// ...

That’s right. Like all the basic Swift types you know and love, Bool is a struct masquerading as a native language feature.

It’s marked @frozen — so instance properties can’t be added or removed. This ensures the memory layout (i.e. number of bits) used is constant between Standard Library versions, which is critical for ABI stability.

Bool is Sendable, so the compiler doesn’t throw a fit when you to pass it between threads.

Let’s keep spelunking through the type.

Builtins.Int1

Four lines deep and we hit our second big WTF moment. Sit down and compose yourself.

public struct Bool: Sendable { 

    @usableFromInline
    internal var _value: Builtin.Int1

// ...

The Swift Bool lives a double-life. The duplicitous struct has just one instance property — a 1-bit integer.

Think that’s okay? Think again. It isn’t even a real Int!

Subscribe for free to continue reading

Enter your email and get every post from Jacob’s Tech Tavern.
Already have an account? Sign in
© 2026 Jacob Bartlett · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture