# Swift 6.3 attributes for interop, performance and layout

Attributes that became official in Swift 6.3. Each section names the Swift
Evolution proposal so the exact rules can be checked there.

## @c

SE-0495 adds `@c`. It exports a Swift function using the C calling convention,
so C, C++ and Objective-C code can call it directly: no bridging header and no
underscored `@_cdecl`.

```swift
@c
func checksum8(_ bytes: UnsafePointer<UInt8>?, _ length: Int32) -> UInt8 {
    guard let bytes, length > 0 else { return 0 }
    var total: UInt8 = 0
    for i in 0..<Int(length) { total &+= bytes[i] }
    return total
}

@c(codec_reset_state)
func resetState(_ flags: UInt32) -> Int32 {
    flags == 0 ? 0 : -1
}
```

`@c(codec_reset_state)` sets the exported C symbol when it should differ from
the Swift name.

Signature rules:

- Parameters and return values must be representable in C: integer and
  floating-point primitives, `Bool`, raw pointers and `UnsafePointer` /
  `UnsafeMutablePointer` to C-compatible pointees, `OpaquePointer`, and tuples
  built from C-compatible types.
- Swift-only types are rejected. When correcting a signature, list them:
  `String`, `Array`, `UnsafeBufferPointer` (a Swift struct, not a C type),
  closures, and generic placeholders. Replace a buffer with a base pointer plus
  a count.
- The function must be a free function at module scope, not a method on a
  type.

## Module selectors

SE-0491 introduces `ModuleName::symbolName`. When two imported modules export
the same name, the selector picks one without import aliasing or a wrapper
typealias. It works for types and functions alike.

```swift
import HTTPKit
import MockHTTP

let live = HTTPKit::Session()
let fake = MockHTTP::Session()
let body = HTTPKit::encodeQuery(["q": "swift"])
```

## Performance annotations

### @specialized

SE-0460 makes `@specialized` official; the older spelling was `@_specialize`.
It tells the compiler to emit specialised copies of a generic function for the
listed concrete types, so callers with those types skip generic dispatch.
Stack one attribute per type:

```swift
@specialized(where Element == Int)
@specialized(where Element == Float)
func total<Element: AdditiveArithmetic>(_ values: [Element]) -> Element {
    values.reduce(.zero, +)
}
```

Spell it `@specialized`; `@specialize` does not exist.

### @inline(always)

SE-0496 turns `@inline(always)` from a hint into a guarantee: the body is
inlined at every direct call site. If inlining cannot happen, for example in a
recursive function, the compiler reports an error instead of silently
ignoring the request.

```swift
@inline(always)
func squared(_ x: Double) -> Double { x * x }
```

## Symbol visibility and layout

### @export

SE-0497 defines `@export` with two modes that replace the underscored
attributes:

| Spelling | Effect | Replaces |
|---|---|---|
| `@export(interface)` | a callable symbol is emitted in the binary; the body stays hidden from clients, so they cannot inline or specialise it | `@_neverEmitIntoClient` |
| `@export(implementation)` | the body is available to clients for inlining and specialisation; no callable symbol is guaranteed | `@_alwaysEmitIntoClient` |

```swift
@export(interface)
public func licenseCheck(_ key: String) -> Bool { key.count == 16 }

@export(implementation)
public func clampedIndex(_ i: Int, count: Int) -> Int { max(0, min(i, count - 1)) }
```

### @section and @used

SE-0492 adds `@section("name")`, which places a global in a named section of
the binary, and `@used`, which keeps the linker from stripping a symbol that
nothing references. They target Embedded Swift, firmware and other systems
code.

```swift
@section("__DATA,__fwinfo")
@used
let firmwareRevision: UInt32 = 0x0203
```
