Skip to content

Commit 5b79f61

Browse files
committed
AST/Sema: Fix remapping of iOS availability in diagnostics for visionOS.
When compiling for visionOS, iOS availability attributes are remapped into the visionOS availability domain automatically. While the version remapping was being performed correctly, there was a regression that caused the platform name to be printed incorrectly in many diagnostics. Whenever an iOS version is remapped to a visionOS version, availability diagnostics will now present those versions as visionOS versions instead of iOS versions. Resolves rdar://146293165.
1 parent 9b62aed commit 5b79f61

10 files changed

+317
-134
lines changed

include/swift/AST/Attr.h

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,41 +3625,71 @@ class SemanticAvailableAttr final {
36253625
/// The source range of the `introduced:` version component.
36263626
SourceRange getIntroducedSourceRange() const { return attr->IntroducedRange; }
36273627

3628-
/// Returns the effective introduction range indicated by this attribute.
3629-
/// This may correspond to the version specified by the `introduced:`
3630-
/// component (remapped or canonicalized if necessary) or it may be "always"
3631-
/// for an attribute indicating availability in a version-less domain. Returns
3632-
/// `std::nullopt` if the attribute does not indicate introduction.
3628+
/// See `getIntroducedDomainAndRange()`.
36333629
std::optional<AvailabilityRange>
3634-
getIntroducedRange(const ASTContext &Ctx) const;
3630+
getIntroducedRange(const ASTContext &ctx) const {
3631+
if (auto domainAndRange = getIntroducedDomainAndRange(ctx))
3632+
return domainAndRange->getRange();
3633+
return std::nullopt;
3634+
}
3635+
3636+
/// Returns the effective introduction range indicated by this attribute,
3637+
/// along with the domain that it applies to (which may be different than the
3638+
/// domain which the attribute was written with if a remap is required). This
3639+
/// may correspond to the version specified by the `introduced:` component
3640+
/// (remapped or canonicalized if necessary) or it may be "always" for an
3641+
/// attribute indicating availability in a version-less domain. Returns
3642+
/// `std::nullopt` if the attribute does not indicate introduction.
3643+
std::optional<AvailabilityDomainAndRange>
3644+
getIntroducedDomainAndRange(const ASTContext &ctx) const;
36353645

36363646
/// The version tuple for the `deprecated:` component.
36373647
std::optional<llvm::VersionTuple> getDeprecated() const;
36383648

36393649
/// The source range of the `deprecated:` version component.
36403650
SourceRange getDeprecatedSourceRange() const { return attr->DeprecatedRange; }
36413651

3642-
/// Returns the effective deprecation range indicated by this attribute.
3643-
/// This may correspond to the version specified by the `deprecated:`
3644-
/// component (remapped or canonicalized if necessary) or it may be "always"
3645-
/// for an unconditional deprecation attribute. Returns `std::nullopt` if the
3646-
/// attribute does not indicate deprecation.
3652+
/// See `getDeprecatedDomainAndRange()`.
36473653
std::optional<AvailabilityRange>
3648-
getDeprecatedRange(const ASTContext &Ctx) const;
3654+
getDeprecatedRange(const ASTContext &ctx) const {
3655+
if (auto domainAndRange = getDeprecatedDomainAndRange(ctx))
3656+
return domainAndRange->getRange();
3657+
return std::nullopt;
3658+
}
3659+
3660+
/// Returns the effective deprecation range indicated by this attribute, along
3661+
/// with the domain that it applies to (which may be different than the domain
3662+
/// which the attribute was written with if a remap is required). This may
3663+
/// correspond to the version specified by the `deprecated:` component
3664+
/// (remapped or canonicalized if necessary) or it may be "always" for an
3665+
/// unconditional deprecation attribute. Returns `std::nullopt` if the
3666+
/// attribute does not indicate deprecation.
3667+
std::optional<AvailabilityDomainAndRange>
3668+
getDeprecatedDomainAndRange(const ASTContext &ctx) const;
36493669

36503670
/// The version tuple for the `obsoleted:` component.
36513671
std::optional<llvm::VersionTuple> getObsoleted() const;
36523672

36533673
/// The source range of the `obsoleted:` version component.
36543674
SourceRange getObsoletedSourceRange() const { return attr->ObsoletedRange; }
36553675

3656-
/// Returns the effective obsoletion range indicated by this attribute.
3657-
/// This always corresponds to the version specified by the `obsoleted:`
3658-
/// component (remapped or canonicalized if necessary). Returns `std::nullopt`
3659-
/// if the attribute does not indicate obsoletion (note that unavailability is
3660-
/// separate from obsoletion.
3676+
/// See `getObsoletedDomainAndRange()`.
36613677
std::optional<AvailabilityRange>
3662-
getObsoletedRange(const ASTContext &Ctx) const;
3678+
getObsoletedRange(const ASTContext &ctx) const {
3679+
if (auto domainAndRange = getObsoletedDomainAndRange(ctx))
3680+
return domainAndRange->getRange();
3681+
return std::nullopt;
3682+
}
3683+
3684+
/// Returns the effective obsoletion range indicated by this attribute, along
3685+
/// with the domain that it applies to (which may be different than the domain
3686+
/// which the attribute was written with if a remap is required). This always
3687+
/// corresponds to the version specified by the `obsoleted:` component
3688+
/// (remapped or canonicalized if necessary). Returns `std::nullopt` if the
3689+
/// attribute does not indicate obsoletion (note that unavailability is
3690+
/// separate from obsoletion.
3691+
std::optional<AvailabilityDomainAndRange>
3692+
getObsoletedDomainAndRange(const ASTContext &ctx) const;
36633693

36643694
/// Returns the `message:` field of the attribute, or an empty string.
36653695
StringRef getMessage() const { return attr->Message; }

include/swift/AST/AvailabilityConstraint.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ class AvailabilityConstraint {
132132
/// Returns the domain that the constraint applies to.
133133
AvailabilityDomain getDomain() const { return getAttr().getDomain(); }
134134

135-
/// Returns the required range for `IntroducedInNewerVersion` requirements, or
136-
/// `std::nullopt` otherwise.
137-
std::optional<AvailabilityRange>
138-
getPotentiallyUnavailableRange(const ASTContext &ctx) const;
135+
/// Returns the domain and range (remapped if necessary) in which the
136+
/// constraint must be satisfied. How the range should be interpreted depends
137+
/// on the reason for the constraint.
138+
AvailabilityDomainAndRange getDomainAndRange(const ASTContext &ctx) const;
139139

140140
/// Some availability constraints are active for type-checking but cannot
141141
/// be translated directly into an `if #available(...)` runtime query.

include/swift/AST/AvailabilityDomain.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ class AvailabilityDomain final {
263263
/// descendants of the iOS domain.
264264
AvailabilityDomain getRootDomain() const;
265265

266+
/// Returns the canonical domain that versions in this domain must be remapped
267+
/// to before making availability comparisons in the current compilation
268+
/// context. Sets \p didRemap to `true` if a remap was required.
269+
const AvailabilityDomain getRemappedDomain(const ASTContext &ctx,
270+
bool &didRemap) const;
271+
272+
/// Returns the canonical domain that versions in this domain must be remapped
273+
/// to before making availability comparisons in the current compilation
274+
/// context.
275+
const AvailabilityDomain getRemappedDomain(const ASTContext &ctx) const {
276+
bool unused;
277+
return getRemappedDomain(ctx, unused);
278+
}
279+
266280
bool operator==(const AvailabilityDomain &other) const {
267281
return storage.getOpaqueValue() == other.storage.getOpaqueValue();
268282
}
@@ -420,6 +434,20 @@ class AvailabilityDomainOrIdentifier {
420434
void print(llvm::raw_ostream &os) const;
421435
};
422436

437+
/// Represents an `AvailabilityRange` paired with the `AvailabilityDomain` that
438+
/// the range applies to.
439+
class AvailabilityDomainAndRange {
440+
AvailabilityDomain domain;
441+
AvailabilityRange range;
442+
443+
public:
444+
AvailabilityDomainAndRange(AvailabilityDomain domain, AvailabilityRange range)
445+
: domain(domain), range(range) {};
446+
447+
AvailabilityDomain getDomain() const { return domain; }
448+
AvailabilityRange getRange() const { return range; }
449+
};
450+
423451
} // end namespace swift
424452

425453
namespace llvm {

include/swift/AST/AvailabilityInference.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ class AvailabilityInference {
8181
const SemanticAvailableAttr &attr, const ASTContext &ctx,
8282
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);
8383

84-
static void
85-
updateAvailabilityDomainForFallback(const SemanticAvailableAttr &attr,
86-
const ASTContext &ctx,
87-
AvailabilityDomain &domain);
88-
8984
/// For the attribute's before version, update the platform and version
9085
/// values to the re-mapped platform's, if using a fallback platform.
9186
/// Returns `true` if a remap occured.

0 commit comments

Comments
 (0)