@@ -378,18 +378,19 @@ Decl::getIntroducedOSVersion(PlatformKind Kind) const {
378378}
379379
380380Optional<llvm::VersionTuple>
381- Decl::getBackDeployBeforeOSVersion (PlatformKind Kind ) const {
381+ Decl::getBackDeployBeforeOSVersion (ASTContext &Ctx ) const {
382382 for (auto *attr : getAttrs ()) {
383383 if (auto *backDeployAttr = dyn_cast<BackDeployAttr>(attr)) {
384- if (backDeployAttr->Platform == Kind && backDeployAttr->Version ) {
384+ if (backDeployAttr->isActivePlatform (Ctx) && backDeployAttr->Version ) {
385385 return backDeployAttr->Version ;
386386 }
387387 }
388388 }
389389
390390 // Accessors may inherit `@_backDeploy`.
391391 if (getKind () == DeclKind::Accessor) {
392- return cast<AccessorDecl>(this )->getStorage ()->getBackDeployBeforeOSVersion (Kind);
392+ return cast<AccessorDecl>(this )->getStorage ()->getBackDeployBeforeOSVersion (
393+ Ctx);
393394 }
394395
395396 return None;
@@ -927,14 +928,20 @@ bool Decl::isStdlibDecl() const {
927928}
928929
929930AvailabilityContext Decl::getAvailabilityForLinkage () const {
931+ ASTContext &ctx = getASTContext ();
932+
933+ // When computing availability for linkage, use the "before" version from
934+ // the @_backDeploy attribute, if present.
935+ if (auto backDeployVersion = getBackDeployBeforeOSVersion (ctx))
936+ return AvailabilityContext{VersionRange::allGTE (*backDeployVersion)};
937+
930938 auto containingContext =
931939 AvailabilityInference::annotatedAvailableRange (this , getASTContext ());
932940 if (containingContext.hasValue ()) {
933- // If this entity comes from the concurrency module, adjust it's
941+ // If this entity comes from the concurrency module, adjust its
934942 // availability for linkage purposes up to Swift 5.5, so that we use
935943 // weak references any time we reference those symbols when back-deploying
936944 // concurrency.
937- ASTContext &ctx = getASTContext ();
938945 if (getModuleContext ()->getName () == ctx.Id_Concurrency ) {
939946 containingContext->intersectWith (ctx.getConcurrencyAvailability ());
940947 }
0 commit comments