Skip to content

Commit babdec2

Browse files
authored
Merge pull request #3004 from xymus/cdecl-review
SE-0495: Clarify emitted symbols and compatibility header content for `@c` enums
2 parents c886c76 + 626a4af commit babdec2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

proposals/0495-cdecl.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Author: [Alexis Laferrière](https://github.com/xymus)
55
* Review Manager: [Steve Canon](https://github.com/stephentyrone)
66
* Status: **Active Review (September 25th...October 9th, 2025)**
7-
* Implementation: On `main` with the experimental feature flags `CDecl` for `@c`, and `CImplementation` for `@c @implementation`. With the exception of the `@objc` support for global functions which is available under the name `@_cdecl`.
7+
* Implementation: On `6.3`. With the exception of the `@objc` support for global functions which is not yet implemented.
88
* Review: ([pitch](https://forums.swift.org/t/pitch-formalize-cdecl/79557))([review](https://forums.swift.org/t/se-0495-c-compatible-functions-and-enums/82365))
99

1010
## Introduction
@@ -65,13 +65,17 @@ A `@c` enum may declare a custom C name, and must declare an integer raw type co
6565
```swift
6666
@c
6767
enum CEnum: CInt {
68-
case a
69-
case b
68+
case first
69+
case second
7070
}
7171
```
7272

7373
The attribute `@objc` is already accepted on enums. These enums qualify as an Objective-C representable type and are usable from `@objc` global function signatures but not from `@c` functions.
7474

75+
In the compatibility header, the `@c` enum is printed with the C name specified in the `@c` attribute or the Swift name by default. It defines a storage of the specified raw type with support for different dialects of C.
76+
77+
Each case is printed using a name composed of the enum name with the case name attached. The first letter of the case name is capitalized automatically. For the enum above, the generated cases for C are named `CEnumFirst` and `CEnumSecond`.
78+
7579
### `@c @implementation` global functions
7680

7781
Extend support for the `@implementation` attribute, introduced in [SE-0436](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md), to global functions marked with either `@c` or `@objc`. These functions are declared in an imported C or Objective-C header, while the Swift function provides their implementation. Type-checking ensures the declaration matches the implementation signature in Swift. Functions marked `@implementation` are not printed in the compatibility header.
@@ -165,7 +169,9 @@ Existing adopters of `@_cdecl` can replace the attribute with `@objc` to preserv
165169

166170
## ABI compatibility
167171

168-
Marking a global function with `@c` or `@objc` makes it use the C calling convention. Adding or removing these attributes on a function is an ABI breaking change. Updating existing `@_cdecl` to `@objc` or `@c` is ABI stable.
172+
The compiler emits a single symbol for `@c` and `@objc` functions, the symbol uses the C calling convention.
173+
174+
Adding or removing the attributes `@c` and `@objc` on a function is an ABI breaking change. Changing between `@c` and `@objc` is ABI stable. Changing between `@_cdecl` and either `@c` or `@objc` is an ABI breaking change since `@_cdecl` emits two symbols and Swift clients of `@_cdecl` call the one with the Swift calling convention.
169175

170176
Adding or removing the `@c` attribute on an enum is ABI stable, but changing its raw type is not.
171177

0 commit comments

Comments
 (0)