@@ -8278,56 +8278,83 @@ SemanticAvailableAttrRequest::evaluate(swift::Evaluator &evaluator,
8278
8278
auto attrName = attr->getAttrName ();
8279
8279
auto attrKind = attr->getKind ();
8280
8280
auto domainLoc = attr->getDomainLoc ();
8281
- auto string = attr->getDomainString ();
8282
- ASSERT (string);
8281
+ auto introducedVersion = attr->getRawIntroduced ();
8282
+ auto deprecatedVersion = attr->getRawDeprecated ();
8283
+ auto obsoletedVersion = attr->getRawObsoleted ();
8284
+ auto mutableAttr = const_cast <AvailableAttr *>(attr);
8285
+ auto domain = attr->getCachedDomain ();
8283
8286
8284
- // Attempt to resolve the domain specified for the attribute and diagnose
8285
- // if no domain is found.
8286
- auto domain = AvailabilityDomain::builtinDomainForString (*string);
8287
8287
if (!domain) {
8288
- if (auto suggestion = closestCorrectedPlatformString (*string)) {
8289
- diags
8290
- .diagnose (domainLoc, diag::attr_availability_suggest_platform,
8291
- *string, attrName, *suggestion)
8292
- .fixItReplace (SourceRange (domainLoc), *suggestion);
8293
- } else {
8294
- diags.diagnose (attrLoc, diag::attr_availability_unknown_platform, *string,
8295
- attrName);
8288
+ auto string = attr->getDomainString ();
8289
+ ASSERT (string);
8290
+
8291
+ // Attempt to resolve the domain specified for the attribute and diagnose
8292
+ // if no domain is found.
8293
+ domain = AvailabilityDomain::builtinDomainForString (*string);
8294
+ if (!domain) {
8295
+ if (auto suggestion = closestCorrectedPlatformString (*string)) {
8296
+ diags
8297
+ .diagnose (domainLoc, diag::attr_availability_suggest_platform,
8298
+ *string, attrName, *suggestion)
8299
+ .fixItReplace (SourceRange (domainLoc), *suggestion);
8300
+ } else {
8301
+ diags.diagnose (attrLoc, diag::attr_availability_unknown_platform,
8302
+ *string, attrName);
8303
+ }
8304
+ return std::nullopt;
8296
8305
}
8297
- return std::nullopt;
8306
+
8307
+ mutableAttr->setCachedDomain (*domain);
8298
8308
}
8299
8309
8310
+ auto domainName = domain->getNameForAttributePrinting ();
8311
+
8300
8312
if (domain->isSwiftLanguage () || domain->isPackageDescription ()) {
8301
8313
switch (attrKind) {
8302
8314
case AvailableAttr::Kind::Deprecated:
8303
8315
diags.diagnose (attrLoc,
8304
8316
diag::attr_availability_expected_deprecated_version,
8305
- attrName, *string );
8317
+ attrName, domainName );
8306
8318
return std::nullopt;
8307
8319
8308
8320
case AvailableAttr::Kind::Unavailable:
8309
8321
diags.diagnose (attrLoc, diag::attr_availability_cannot_be_used_for_domain,
8310
- " unavailable" , attrName, *string );
8322
+ " unavailable" , attrName, domainName );
8311
8323
return std::nullopt;
8312
8324
8313
8325
case AvailableAttr::Kind::NoAsync:
8314
8326
diags.diagnose (attrLoc, diag::attr_availability_cannot_be_used_for_domain,
8315
- " noasync" , attrName, *string );
8327
+ " noasync" , attrName, domainName );
8316
8328
break ;
8317
8329
case AvailableAttr::Kind::Default:
8318
8330
break ;
8319
8331
}
8320
8332
8321
- bool hasVersionSpec = (attr-> getRawIntroduced () ||
8322
- attr-> getRawDeprecated () || attr-> getRawObsoleted () );
8333
+ bool hasVersionSpec =
8334
+ (introducedVersion || deprecatedVersion || obsoletedVersion );
8323
8335
if (!hasVersionSpec) {
8324
8336
diags.diagnose (attrLoc, diag::attr_availability_expected_version_spec,
8325
- attrName, *string );
8337
+ attrName, domainName );
8326
8338
return std::nullopt;
8327
8339
}
8328
8340
}
8329
8341
8330
- const_cast <AvailableAttr *>(attr)->setCachedDomain (*domain);
8342
+ // Canonicalize platform versions.
8343
+ // FIXME: [availability] This should be done when remapping versions instead.
8344
+ if (domain->isPlatform ()) {
8345
+ auto canonicalizeVersion = [&](llvm::VersionTuple version) {
8346
+ return canonicalizePlatformVersion (domain->getPlatformKind (), version);
8347
+ };
8348
+ if (introducedVersion)
8349
+ mutableAttr->setRawIntroduced (canonicalizeVersion (*introducedVersion));
8350
+
8351
+ if (deprecatedVersion)
8352
+ mutableAttr->setRawDeprecated (canonicalizeVersion (*deprecatedVersion));
8353
+
8354
+ if (obsoletedVersion)
8355
+ mutableAttr->setRawObsoleted (canonicalizeVersion (*obsoletedVersion));
8356
+ }
8357
+
8331
8358
return SemanticAvailableAttr (attr);
8332
8359
}
8333
8360
0 commit comments