Skip to content

Commit f4b4dc9

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 bfa991d commit f4b4dc9

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
@@ -3757,41 +3757,71 @@ class SemanticAvailableAttr final {
37573757
/// The source range of the `introduced:` version component.
37583758
SourceRange getIntroducedSourceRange() const { return attr->IntroducedRange; }
37593759

3760-
/// Returns the effective introduction range indicated by this attribute.
3761-
/// This may correspond to the version specified by the `introduced:`
3762-
/// component (remapped or canonicalized if necessary) or it may be "always"
3763-
/// for an attribute indicating availability in a version-less domain. Returns
3764-
/// `std::nullopt` if the attribute does not indicate introduction.
3760+
/// See `getIntroducedDomainAndRange()`.
37653761
std::optional<AvailabilityRange>
3766-
getIntroducedRange(const ASTContext &Ctx) const;
3762+
getIntroducedRange(const ASTContext &ctx) const {
3763+
if (auto domainAndRange = getIntroducedDomainAndRange(ctx))
3764+
return domainAndRange->getRange();
3765+
return std::nullopt;
3766+
}
3767+
3768+
/// Returns the effective introduction range indicated by this attribute,
3769+
/// along with the domain that it applies to (which may be different than the
3770+
/// domain which the attribute was written with if a remap is required). This
3771+
/// may correspond to the version specified by the `introduced:` component
3772+
/// (remapped or canonicalized if necessary) or it may be "always" for an
3773+
/// attribute indicating availability in a version-less domain. Returns
3774+
/// `std::nullopt` if the attribute does not indicate introduction.
3775+
std::optional<AvailabilityDomainAndRange>
3776+
getIntroducedDomainAndRange(const ASTContext &ctx) const;
37673777

37683778
/// The version tuple for the `deprecated:` component.
37693779
std::optional<llvm::VersionTuple> getDeprecated() const;
37703780

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

3774-
/// Returns the effective deprecation range indicated by this attribute.
3775-
/// This may correspond to the version specified by the `deprecated:`
3776-
/// component (remapped or canonicalized if necessary) or it may be "always"
3777-
/// for an unconditional deprecation attribute. Returns `std::nullopt` if the
3778-
/// attribute does not indicate deprecation.
3784+
/// See `getDeprecatedDomainAndRange()`.
37793785
std::optional<AvailabilityRange>
3780-
getDeprecatedRange(const ASTContext &Ctx) const;
3786+
getDeprecatedRange(const ASTContext &ctx) const {
3787+
if (auto domainAndRange = getDeprecatedDomainAndRange(ctx))
3788+
return domainAndRange->getRange();
3789+
return std::nullopt;
3790+
}
3791+
3792+
/// Returns the effective deprecation range indicated by this attribute, along
3793+
/// with the domain that it applies to (which may be different than the domain
3794+
/// which the attribute was written with if a remap is required). This may
3795+
/// correspond to the version specified by the `deprecated:` component
3796+
/// (remapped or canonicalized if necessary) or it may be "always" for an
3797+
/// unconditional deprecation attribute. Returns `std::nullopt` if the
3798+
/// attribute does not indicate deprecation.
3799+
std::optional<AvailabilityDomainAndRange>
3800+
getDeprecatedDomainAndRange(const ASTContext &ctx) const;
37813801

37823802
/// The version tuple for the `obsoleted:` component.
37833803
std::optional<llvm::VersionTuple> getObsoleted() const;
37843804

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

3788-
/// Returns the effective obsoletion range indicated by this attribute.
3789-
/// This always corresponds to the version specified by the `obsoleted:`
3790-
/// component (remapped or canonicalized if necessary). Returns `std::nullopt`
3791-
/// if the attribute does not indicate obsoletion (note that unavailability is
3792-
/// separate from obsoletion.
3808+
/// See `getObsoletedDomainAndRange()`.
37933809
std::optional<AvailabilityRange>
3794-
getObsoletedRange(const ASTContext &Ctx) const;
3810+
getObsoletedRange(const ASTContext &ctx) const {
3811+
if (auto domainAndRange = getObsoletedDomainAndRange(ctx))
3812+
return domainAndRange->getRange();
3813+
return std::nullopt;
3814+
}
3815+
3816+
/// Returns the effective obsoletion range indicated by this attribute, along
3817+
/// with the domain that it applies to (which may be different than the domain
3818+
/// which the attribute was written with if a remap is required). This always
3819+
/// corresponds to the version specified by the `obsoleted:` component
3820+
/// (remapped or canonicalized if necessary). Returns `std::nullopt` if the
3821+
/// attribute does not indicate obsoletion (note that unavailability is
3822+
/// separate from obsoletion.
3823+
std::optional<AvailabilityDomainAndRange>
3824+
getObsoletedDomainAndRange(const ASTContext &ctx) const;
37953825

37963826
/// Returns the `message:` field of the attribute, or an empty string.
37973827
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)