[DON'T MERGE] Indirect availability declarations #29559
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proof of concept for a variant of
@availablethat copies availability information from another declaration. This would fix a pain point for us ABI-stable library developers by eliminating redundant availability incantations and simplifying the error-prone and onerously manual task of finalizing them before stable releases.@_availableRefis an implementation detail that doesn't affect the public interface of the module. (It gets expanded into the actual@availablelist on serialization.)Notes:
I have no idea what I'm doing here. 😅
We'll also need some equivalent of this for
if #available, so that we can use this in tests as well. (Maintaining#availabletests in unit tests is currently at least tricky as@availableattributes are in the actual code.)We need to decide how we want to spell this. Perhaps it makes sense to roll this functionality into
@availableitself. (Something like@available(at: _Stdlib_5_1)?)TypeRefinementContextBuilderresolves/propagates availability information before@availableattributes are type checked, which seems backward to me.@_availableRefneeds to resolve its target type -- I'm not sure if it's okay to do name resolution this early in the type checking process.The argument of
@_availableRefis currently restricted to a type name -- for extra points, it would be nice if it could refer to other kind of decls (enum cases especially).Using dummy type declarations for this seems like a hack. What if we introduced dedicated syntax for declaring aliases for shorthand-style availability declarations?
This would get rid of the need to resolve decl names, and it would allow us to use nice version tuples instead of ugly identifiers like
_Stdlib_5_1. It could also simplify deprecations/obsoletions:Note how this solves point (3) above -- it basically reuses the existing syntax for OS version numbers. (With some weirdness about how this interacts with the shorthand fallback platform
*.)