[swift-corelibs-dev] Unavailability macros for APIs that aren't going to be implemented on Linux?

Alex Blewitt alblue at apple.com
Fri Jul 28 09:07:36 CDT 2017


I've pushed a change which will add an unavailability warning for a method which was deprecated at the point of being added to Swift, has never worked, and likely never will:

https://github.com/apple/swift-corelibs-foundation/pull/1140 <https://github.com/apple/swift-corelibs-foundation/pull/1140>

There are some other types in Foundation which aren't likely to ever be implementable in Swift on Linux; Bundle.unload, NSPort/PortMessage, copy(with zone) etc. The majority of these methods use NSUnimplemented(), which means there are often unannounced runtime errors that you can get from something that compiled correctly.

I'd like to suggest that we attempt to resolve this problem, either by removing the features whihc are never going to be implemented (e.g. by commenting out the calls) or by marking them as @available(*,unavailable, message:"Not available on the Linux platform"). That way, calls that are known cannot work can be identified at compile time instead of at run-time.

I hope we'll then be able to remove the NSUnimplemented calls on the types that can never be implemented, so that we can focus on those types and functions that we can. Alternatively we can define a different macro, say NSUnavailableOnLinux, to indicate that this functionality cannot be present (as opposed to just leaving it blank).

What do you think?

$ git grep -c NSUnimplemented | sort -n -r -k2 -t:
Foundation/NSExpression.swift:37
Foundation/NSURLCache.swift:22
Foundation/FileManager.swift:22
Foundation/NSPort.swift:21
Foundation/NSOrderedSet.swift:20
Foundation/NSSortDescriptor.swift:19
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20170728/5b3a6084/attachment.html>


More information about the swift-corelibs-dev mailing list