[swift-evolution] Rewrite imported C function signatures

Greg Parker gparker at apple.com
Mon Apr 25 17:11:48 CDT 2016

> On Mar 26, 2016, at 2:00 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
> If that's all you want, maybe we can have an attribute which says "prefer this version over that one":
> 	@preferred(since: 3.0, over: socket(_: Int32, _: Int32, _: Int32) -> Int32)
> 	func socket(domain:SocketDomain, type:SocketType, protocol:SocketProtocol) -> socket_t? {
>> 	}
> This would effectively apply an `@available(deprecated: 3.0, renamed: socket(domain: SocketDomain, type: SocketType, protocol: SocketProtocol) -> socket_t?)` to the other API.

This capability sounds useful in other situations where some outside API is undesirable in your code. For example in the Swift standard library itself we have our own "halt with an error" functions such as fatalError(). We almost always want to use those instead of something like abort() or exit(). It would be useful to mark fatalError() as the preferred replacement for abort() and exit(). Then the compiler would help enforce our policy.

(In C code we could enforce such non-usage with ugly things like `#define abort() dont_call_abort()`. That ugly solution is not available in Swift.)

Greg Parker     gparker at apple.com     Runtime Wrangler

More information about the swift-evolution mailing list