I think it would help to be a bit clearer about your expectations here, and where the labels would come from. C doesn't have argument labels in a way that maps 1-to-1 to Swift's argument labels, so there need to be some clear-cut rules about how this would work.
In C, these are all identical declarations for the same function:
int add(int x, int y);
int add(int a, int b);
int add(int, int);
In Swift, these are all entirely different functions which can coexist simultaneously:
func add(x: Int, y: Int) -> Int { /* ... */ }
func add(a: Int, b: Int) -> Int { /* ... */ }
func add(_: Int, _: Int) -> Int { /* ... */ }
Given a C function in a header, is your expectation that you will get 1-to-1 mappings like
int add(int x, int y) ↔︎ func add(x: Int, y: Int) -> Int
int add(int a, int b) ↔︎ func add(a: Int, b: Int) -> Int
int add(int, int) ↔︎ func add(_: Int, _: Int) -> Int
If so, then you actually couldn't call SDL_CreateRGBSurface
the way you'd want; you'd need to write
SDL_CreateRGBSurface(
flags: 0,
width: 8,
height: 8,
depth: 32,
Rmask: 0,
Gmask: 0,
Bmask: 0,
Amask: 0
)
because the full declaration of the function is
SDL_Surface* SDL_CreateRGBSurface
(Uint32 flags, int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
If by "optionally allow labels", you mean that you would be allowed to label some arguments to the C function, but not others, I think this would be a pretty stark departure from how Swift currently works. (There are many follow-on questions like, "what makes C special that allows Swift to behave like this for C functions but not Swift functions?" and "what do we do about ambiguity when you omit an argument label?")
In the general case, Swift doesn't import C function argument names from headers because they're not reliable; because they're not required in C,
- Argument names are in too many cases an afterthought: there's no consequence for inconsistent or abbreviated names in C, missing argument names altogether, etc.; but, they would very much affect how they're called in Swift. Because of this,
- It's easy to innocuously change a name in a C header without thought (perhaps for the better as part of cleanup!); but, these changes which have absolutely no effect in C would be source-breaking and ABI-breaking changes when imported into Swift
The risk of easily breaking Swift code arguably outweighs the detriment of either consciously choosing names via swift_name
, or writing a more Swift-focused wrapper for the underlying library.