Extend @available to support PackageDescription

<rdar://problem/46548531> Extend @available to support PackageDescription

This introduces a new private availability kind "_PackageDescription" to
allow availability testing by an arbitary version that can be passed
using a new command-line flag "-swiftpm-manifest-version". The semantics
are exactly same as Swift version specific availability. In longer term,
it maybe possible to remove this enhancement once there is
a language-level availability support for 3rd party libraries.

Motivation:

Swift packages are configured using a Package.swift manifest file. The
manifest file uses a library called PackageDescription, which contains
various settings that can be configured for a package. The new additions
in the PackageDescription APIs are gated behind a "tools version" that
every manifest must declare. This means, packages don't automatically
get access to the new APIs. They need to update their declared tools
version in order to use the new API. This is basically similar to the
minimum deployment target version we have for our OSes.

This gating is important for allowing packages to maintain backwards
compatibility. SwiftPM currently checks for API usages at runtime in
order to implement this gating. This works reasonably well but can lead
to a poor experience with features like code-completion and module
interface generation in IDEs and editors (that use sourcekit-lsp) as
SwiftPM has no control over these features.
This commit is contained in:
Ankit Aggarwal
2018-12-04 17:28:10 +05:30
parent 9536d40718
commit 92d09f4e19
23 changed files with 370 additions and 93 deletions

View File

@@ -199,6 +199,16 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
diagnoseSwiftVersion(vers, A, Args, Diags);
}
if (auto A = Args.getLastArg(OPT_package_description_version)) {
auto vers = version::Version::parseVersionString(
A->getValue(), SourceLoc(), &Diags);
if (vers.hasValue()) {
Opts.PackageDescriptionVersion = vers.getValue();
} else {
return true;
}
}
Opts.AttachCommentsToDecls |= Args.hasArg(OPT_dump_api_path);
Opts.UseMalloc |= Args.hasArg(OPT_use_malloc);