@@ -382,18 +382,19 @@ Decl::getIntroducedOSVersion(PlatformKind Kind) const {
382382}
383383
384384Optional<llvm::VersionTuple>
385- Decl::getBackDeployBeforeOSVersion (PlatformKind Kind ) const {
385+ Decl::getBackDeployBeforeOSVersion (ASTContext &Ctx ) const {
386386 for (auto *attr : getAttrs ()) {
387387 if (auto *backDeployAttr = dyn_cast<BackDeployAttr>(attr)) {
388- if (backDeployAttr->Platform == Kind && backDeployAttr->Version ) {
388+ if (backDeployAttr->isActivePlatform (Ctx) && backDeployAttr->Version ) {
389389 return backDeployAttr->Version ;
390390 }
391391 }
392392 }
393393
394394 // Accessors may inherit `@_backDeploy`.
395395 if (getKind () == DeclKind::Accessor) {
396- return cast<AccessorDecl>(this )->getStorage ()->getBackDeployBeforeOSVersion (Kind);
396+ return cast<AccessorDecl>(this )->getStorage ()->getBackDeployBeforeOSVersion (
397+ Ctx);
397398 }
398399
399400 return None;
@@ -937,14 +938,20 @@ bool Decl::isStdlibDecl() const {
937938}
938939
939940AvailabilityContext Decl::getAvailabilityForLinkage () const {
941+ ASTContext &ctx = getASTContext ();
942+
943+ // When computing availability for linkage, use the "before" version from
944+ // the @_backDeploy attribute, if present.
945+ if (auto backDeployVersion = getBackDeployBeforeOSVersion (ctx))
946+ return AvailabilityContext{VersionRange::allGTE (*backDeployVersion)};
947+
940948 auto containingContext =
941949 AvailabilityInference::annotatedAvailableRange (this , getASTContext ());
942950 if (containingContext.hasValue ()) {
943- // If this entity comes from the concurrency module, adjust it's
951+ // If this entity comes from the concurrency module, adjust its
944952 // availability for linkage purposes up to Swift 5.5, so that we use
945953 // weak references any time we reference those symbols when back-deploying
946954 // concurrency.
947- ASTContext &ctx = getASTContext ();
948955 if (getModuleContext ()->getName () == ctx.Id_Concurrency ) {
949956 containingContext->intersectWith (ctx.getConcurrencyAvailability ());
950957 }
0 commit comments