@@ -2376,16 +2376,16 @@ diagnosePotentialUnavailability(const RootProtocolConformance *rootConf,
2376
2376
2377
2377
// / Returns the availability attribute indicating deprecation of the
2378
2378
// / declaration is deprecated or null otherwise.
2379
- static const AvailableAttr * getDeprecated (const Decl *D) {
2379
+ static std::optional<SemanticAvailableAttr> getDeprecated (const Decl *D) {
2380
2380
auto &Ctx = D->getASTContext ();
2381
2381
if (auto Attr = D->getDeprecatedAttr ())
2382
- return Attr-> getParsedAttr () ;
2382
+ return Attr;
2383
2383
2384
2384
if (Ctx.LangOpts .WarnSoftDeprecated ) {
2385
2385
// When -warn-soft-deprecated is specified, treat any declaration that is
2386
2386
// deprecated in the future as deprecated.
2387
2387
if (auto Attr = D->getSoftDeprecatedAttr ())
2388
- return Attr-> getParsedAttr () ;
2388
+ return Attr;
2389
2389
}
2390
2390
2391
2391
// Treat extensions methods as deprecated if their extension
@@ -2395,18 +2395,17 @@ static const AvailableAttr *getDeprecated(const Decl *D) {
2395
2395
return getDeprecated (ED);
2396
2396
}
2397
2397
2398
- return nullptr ;
2398
+ return std::nullopt ;
2399
2399
}
2400
2400
2401
2401
static void fixItAvailableAttrRename (InFlightDiagnostic &diag,
2402
2402
SourceRange referenceRange,
2403
2403
const ValueDecl *renamedDecl,
2404
- const AvailableAttr *attr,
2405
- const Expr *call) {
2404
+ StringRef newName, const Expr *call) {
2406
2405
if (isa<AccessorDecl>(renamedDecl))
2407
2406
return ;
2408
2407
2409
- ParsedDeclName parsed = swift::parseDeclName (attr-> Rename );
2408
+ ParsedDeclName parsed = swift::parseDeclName (newName );
2410
2409
if (!parsed)
2411
2410
return ;
2412
2411
@@ -2514,7 +2513,6 @@ static void fixItAvailableAttrRename(InFlightDiagnostic &diag,
2514
2513
// let's just prepend it, otherwise we'll end up with an incorrect fix-it.
2515
2514
auto base = sourceMgr.extractText (selfExprRange);
2516
2515
if (!base.empty () && base.front () == ' .' ) {
2517
- auto newName = attr->Rename ;
2518
2516
// If this is not a rename, let's not
2519
2517
// even try to emit a fix-it because
2520
2518
// it's going to be invalid.
@@ -2764,9 +2762,9 @@ namespace {
2764
2762
} // end anonymous namespace
2765
2763
2766
2764
static std::optional<ReplacementDeclKind>
2767
- describeRename (ASTContext &ctx, const AvailableAttr *attr , const ValueDecl *D,
2765
+ describeRename (ASTContext &ctx, StringRef newName , const ValueDecl *D,
2768
2766
SmallVectorImpl<char > &nameBuf) {
2769
- ParsedDeclName parsed = swift::parseDeclName (attr-> Rename );
2767
+ ParsedDeclName parsed = swift::parseDeclName (newName );
2770
2768
if (!parsed)
2771
2769
return std::nullopt;
2772
2770
@@ -2809,7 +2807,7 @@ static void diagnoseIfDeprecated(SourceRange ReferenceRange,
2809
2807
const ExportContext &Where,
2810
2808
const ValueDecl *DeprecatedDecl,
2811
2809
const Expr *Call) {
2812
- const AvailableAttr * Attr = getDeprecated (DeprecatedDecl);
2810
+ auto Attr = getDeprecated (DeprecatedDecl);
2813
2811
if (!Attr)
2814
2812
return ;
2815
2813
@@ -2835,57 +2833,60 @@ static void diagnoseIfDeprecated(SourceRange ReferenceRange,
2835
2833
if (shouldIgnoreDeprecationOfConcurrencyDecl (DeprecatedDecl, ReferenceDC))
2836
2834
return ;
2837
2835
2838
- StringRef Platform = Attr->prettyPlatformString ();
2836
+ StringRef Platform = Attr->getDomain (). getNameForDiagnostics ();
2839
2837
llvm::VersionTuple DeprecatedVersion;
2840
- if (Attr->Deprecated )
2841
- DeprecatedVersion = Attr->Deprecated .value ();
2842
-
2843
- if (Attr->Message .empty () && Attr->Rename .empty ()) {
2844
- Context.Diags .diagnose (
2845
- ReferenceRange.Start , diag::availability_deprecated,
2846
- DeprecatedDecl, Attr->hasPlatform (), Platform,
2847
- Attr->Deprecated .has_value (), DeprecatedVersion,
2848
- /* message*/ StringRef ())
2849
- .highlight (Attr->getRange ());
2838
+ if (Attr->getDeprecated ())
2839
+ DeprecatedVersion = Attr->getDeprecated ().value ();
2840
+
2841
+ auto Message = Attr->getMessage ();
2842
+ auto NewName = Attr->getRename ();
2843
+ if (Message.empty () && NewName.empty ()) {
2844
+ Context.Diags
2845
+ .diagnose (ReferenceRange.Start , diag::availability_deprecated,
2846
+ DeprecatedDecl, Attr->isPlatformSpecific (), Platform,
2847
+ Attr->getDeprecated ().has_value (), DeprecatedVersion,
2848
+ /* message*/ StringRef ())
2849
+ .highlight (Attr->getParsedAttr ()->getRange ());
2850
2850
return ;
2851
2851
}
2852
2852
2853
+ // FIXME: [availability] Remap before emitting diagnostic above.
2853
2854
llvm::VersionTuple RemappedDeprecatedVersion;
2854
2855
if (AvailabilityInference::updateDeprecatedPlatformForFallback (
2855
- Attr, Context, Platform, RemappedDeprecatedVersion))
2856
+ Attr-> getParsedAttr () , Context, Platform, RemappedDeprecatedVersion))
2856
2857
DeprecatedVersion = RemappedDeprecatedVersion;
2857
2858
2858
2859
SmallString<32 > newNameBuf;
2859
2860
std::optional<ReplacementDeclKind> replacementDeclKind =
2860
- describeRename (Context, Attr , /* decl*/ nullptr , newNameBuf);
2861
- StringRef newName = replacementDeclKind ? newNameBuf.str () : Attr-> Rename ;
2862
-
2863
- if (!Attr-> Message .empty ()) {
2864
- EncodedDiagnosticMessage EncodedMessage (Attr-> Message );
2865
- Context.Diags . diagnose (
2866
- ReferenceRange.Start , diag::availability_deprecated,
2867
- DeprecatedDecl, Attr->hasPlatform (), Platform,
2868
- Attr->Deprecated .has_value (), DeprecatedVersion,
2869
- EncodedMessage.Message )
2870
- .highlight (Attr->getRange ());
2861
+ describeRename (Context, NewName , /* decl*/ nullptr , newNameBuf);
2862
+ StringRef newName = replacementDeclKind ? newNameBuf.str () : NewName ;
2863
+
2864
+ if (!Message.empty ()) {
2865
+ EncodedDiagnosticMessage EncodedMessage (Message);
2866
+ Context.Diags
2867
+ . diagnose ( ReferenceRange.Start , diag::availability_deprecated,
2868
+ DeprecatedDecl, Attr->isPlatformSpecific (), Platform,
2869
+ Attr->getDeprecated () .has_value (), DeprecatedVersion,
2870
+ EncodedMessage.Message )
2871
+ .highlight (Attr->getParsedAttr ()-> getRange ());
2871
2872
} else {
2872
2873
unsigned rawReplaceKind = static_cast <unsigned >(
2873
2874
replacementDeclKind.value_or (ReplacementDeclKind::None));
2874
- Context.Diags . diagnose (
2875
- ReferenceRange.Start , diag::availability_deprecated_rename,
2876
- DeprecatedDecl, Attr->hasPlatform (), Platform,
2877
- Attr->Deprecated .has_value (), DeprecatedVersion,
2878
- replacementDeclKind.has_value (), rawReplaceKind, newName)
2879
- .highlight (Attr->getRange ());
2875
+ Context.Diags
2876
+ . diagnose ( ReferenceRange.Start , diag::availability_deprecated_rename,
2877
+ DeprecatedDecl, Attr->isPlatformSpecific (), Platform,
2878
+ Attr->getDeprecated () .has_value (), DeprecatedVersion,
2879
+ replacementDeclKind.has_value (), rawReplaceKind, newName)
2880
+ .highlight (Attr-> getParsedAttr () ->getRange ());
2880
2881
}
2881
2882
2882
- if (!Attr-> Rename .empty () && !isa<AccessorDecl>(DeprecatedDecl)) {
2883
+ if (!NewName .empty () && !isa<AccessorDecl>(DeprecatedDecl)) {
2883
2884
auto renameDiag = Context.Diags .diagnose (
2884
2885
ReferenceRange.Start ,
2885
2886
diag::note_deprecated_rename,
2886
2887
newName);
2887
2888
fixItAvailableAttrRename (renameDiag, ReferenceRange, DeprecatedDecl,
2888
- Attr , Call);
2889
+ NewName , Call);
2889
2890
}
2890
2891
}
2891
2892
@@ -2894,7 +2895,7 @@ static bool diagnoseIfDeprecated(SourceLoc loc,
2894
2895
const RootProtocolConformance *rootConf,
2895
2896
const ExtensionDecl *ext,
2896
2897
const ExportContext &where) {
2897
- const AvailableAttr * attr = getDeprecated (ext);
2898
+ auto attr = getDeprecated (ext);
2898
2899
if (!attr)
2899
2900
return false ;
2900
2901
@@ -2920,33 +2921,34 @@ static bool diagnoseIfDeprecated(SourceLoc loc,
2920
2921
auto type = rootConf->getType ();
2921
2922
auto proto = rootConf->getProtocol ()->getDeclaredInterfaceType ();
2922
2923
2923
- StringRef platform = attr->prettyPlatformString ();
2924
+ StringRef platform = attr->getDomain (). getNameForDiagnostics ();
2924
2925
llvm::VersionTuple deprecatedVersion;
2925
- if (attr->Deprecated )
2926
- deprecatedVersion = attr->Deprecated .value ();
2926
+ if (attr->getDeprecated () )
2927
+ deprecatedVersion = attr->getDeprecated () .value ();
2927
2928
2928
2929
llvm::VersionTuple remappedDeprecatedVersion;
2929
2930
if (AvailabilityInference::updateDeprecatedPlatformForFallback (
2930
- attr, ctx, platform, remappedDeprecatedVersion))
2931
+ attr-> getParsedAttr () , ctx, platform, remappedDeprecatedVersion))
2931
2932
deprecatedVersion = remappedDeprecatedVersion;
2932
2933
2933
- if (attr->Message .empty ()) {
2934
- ctx.Diags .diagnose (
2935
- loc, diag::conformance_availability_deprecated,
2936
- type, proto, attr->hasPlatform (), platform,
2937
- attr->Deprecated .has_value (), deprecatedVersion,
2938
- /* message*/ StringRef ())
2939
- .highlight (attr->getRange ());
2934
+ auto message = attr->getMessage ();
2935
+ if (message.empty ()) {
2936
+ ctx.Diags
2937
+ .diagnose (loc, diag::conformance_availability_deprecated, type, proto,
2938
+ attr->isPlatformSpecific (), platform,
2939
+ attr->getDeprecated ().has_value (), deprecatedVersion,
2940
+ /* message*/ StringRef ())
2941
+ .highlight (attr->getParsedAttr ()->getRange ());
2940
2942
return true ;
2941
2943
}
2942
2944
2943
- EncodedDiagnosticMessage encodedMessage (attr-> Message );
2944
- ctx.Diags . diagnose (
2945
- loc, diag::conformance_availability_deprecated,
2946
- type, proto, attr->hasPlatform (), platform,
2947
- attr->Deprecated .has_value (), deprecatedVersion,
2948
- encodedMessage.Message )
2949
- .highlight (attr->getRange ());
2945
+ EncodedDiagnosticMessage encodedMessage (message );
2946
+ ctx.Diags
2947
+ . diagnose ( loc, diag::conformance_availability_deprecated, type, proto ,
2948
+ attr->isPlatformSpecific (), platform,
2949
+ attr->getDeprecated () .has_value (), deprecatedVersion,
2950
+ encodedMessage.Message )
2951
+ .highlight (attr-> getParsedAttr () ->getRange ());
2950
2952
return true ;
2951
2953
}
2952
2954
@@ -3003,7 +3005,7 @@ static bool diagnoseExplicitUnavailability(const ValueDecl *D, SourceRange R,
3003
3005
D, R, Where, Flags, [=](InFlightDiagnostic &diag) {
3004
3006
auto attr = D->getUnavailableAttr ();
3005
3007
assert (attr);
3006
- fixItAvailableAttrRename (diag, R, D, attr->getParsedAttr (), call);
3008
+ fixItAvailableAttrRename (diag, R, D, attr->getRename (), call);
3007
3009
});
3008
3010
}
3009
3011
@@ -3559,7 +3561,7 @@ bool diagnoseExplicitUnavailability(
3559
3561
if (!Attr->Rename .empty ()) {
3560
3562
SmallString<32 > newNameBuf;
3561
3563
std::optional<ReplacementDeclKind> replaceKind =
3562
- describeRename (ctx, Attr, D, newNameBuf);
3564
+ describeRename (ctx, Attr-> Rename , D, newNameBuf);
3563
3565
unsigned rawReplaceKind = static_cast <unsigned >(
3564
3566
replaceKind.value_or (ReplacementDeclKind::None));
3565
3567
StringRef newName = replaceKind ? newNameBuf.str () : Attr->Rename ;
@@ -4168,7 +4170,7 @@ diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
4168
4170
diag.warnUntilSwiftVersion (6 );
4169
4171
4170
4172
if (!attr->getRename ().empty ()) {
4171
- fixItAvailableAttrRename (diag, R, D, attr->getParsedAttr (), call);
4173
+ fixItAvailableAttrRename (diag, R, D, attr->getRename (), call);
4172
4174
}
4173
4175
return true ;
4174
4176
}
0 commit comments