Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3757,41 +3757,71 @@ class SemanticAvailableAttr final {
/// The source range of the `introduced:` version component.
SourceRange getIntroducedSourceRange() const { return attr->IntroducedRange; }

/// Returns the effective introduction range indicated by this attribute.
/// This may correspond to the version specified by the `introduced:`
/// component (remapped or canonicalized if necessary) or it may be "always"
/// for an attribute indicating availability in a version-less domain. Returns
/// `std::nullopt` if the attribute does not indicate introduction.
/// See `getIntroducedDomainAndRange()`.
std::optional<AvailabilityRange>
getIntroducedRange(const ASTContext &Ctx) const;
getIntroducedRange(const ASTContext &ctx) const {
if (auto domainAndRange = getIntroducedDomainAndRange(ctx))
return domainAndRange->getRange();
return std::nullopt;
}

/// Returns the effective introduction range indicated by this attribute,
/// along with the domain that it applies to (which may be different than the
/// domain which the attribute was written with if a remap is required). This
/// may correspond to the version specified by the `introduced:` component
/// (remapped or canonicalized if necessary) or it may be "always" for an
/// attribute indicating availability in a version-less domain. Returns
/// `std::nullopt` if the attribute does not indicate introduction.
std::optional<AvailabilityDomainAndRange>
getIntroducedDomainAndRange(const ASTContext &ctx) const;

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

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

/// Returns the effective deprecation range indicated by this attribute.
/// This may correspond to the version specified by the `deprecated:`
/// component (remapped or canonicalized if necessary) or it may be "always"
/// for an unconditional deprecation attribute. Returns `std::nullopt` if the
/// attribute does not indicate deprecation.
/// See `getDeprecatedDomainAndRange()`.
std::optional<AvailabilityRange>
getDeprecatedRange(const ASTContext &Ctx) const;
getDeprecatedRange(const ASTContext &ctx) const {
if (auto domainAndRange = getDeprecatedDomainAndRange(ctx))
return domainAndRange->getRange();
return std::nullopt;
}

/// Returns the effective deprecation range indicated by this attribute, along
/// with the domain that it applies to (which may be different than the domain
/// which the attribute was written with if a remap is required). This may
/// correspond to the version specified by the `deprecated:` component
/// (remapped or canonicalized if necessary) or it may be "always" for an
/// unconditional deprecation attribute. Returns `std::nullopt` if the
/// attribute does not indicate deprecation.
std::optional<AvailabilityDomainAndRange>
getDeprecatedDomainAndRange(const ASTContext &ctx) const;

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

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

/// Returns the effective obsoletion range indicated by this attribute.
/// This always corresponds to the version specified by the `obsoleted:`
/// component (remapped or canonicalized if necessary). Returns `std::nullopt`
/// if the attribute does not indicate obsoletion (note that unavailability is
/// separate from obsoletion.
/// See `getObsoletedDomainAndRange()`.
std::optional<AvailabilityRange>
getObsoletedRange(const ASTContext &Ctx) const;
getObsoletedRange(const ASTContext &ctx) const {
if (auto domainAndRange = getObsoletedDomainAndRange(ctx))
return domainAndRange->getRange();
return std::nullopt;
}

/// Returns the effective obsoletion range indicated by this attribute, along
/// with the domain that it applies to (which may be different than the domain
/// which the attribute was written with if a remap is required). This always
/// corresponds to the version specified by the `obsoleted:` component
/// (remapped or canonicalized if necessary). Returns `std::nullopt` if the
/// attribute does not indicate obsoletion (note that unavailability is
/// separate from obsoletion.
std::optional<AvailabilityDomainAndRange>
getObsoletedDomainAndRange(const ASTContext &ctx) const;

/// Returns the `message:` field of the attribute, or an empty string.
StringRef getMessage() const { return attr->Message; }
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/AvailabilityConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ class AvailabilityConstraint {
/// Returns the domain that the constraint applies to.
AvailabilityDomain getDomain() const { return getAttr().getDomain(); }

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

/// Some availability constraints are active for type-checking but cannot
/// be translated directly into an `if #available(...)` runtime query.
Expand Down
28 changes: 28 additions & 0 deletions include/swift/AST/AvailabilityDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ class AvailabilityDomain final {
/// descendants of the iOS domain.
AvailabilityDomain getRootDomain() const;

/// Returns the canonical domain that versions in this domain must be remapped
/// to before making availability comparisons in the current compilation
/// context. Sets \p didRemap to `true` if a remap was required.
const AvailabilityDomain getRemappedDomain(const ASTContext &ctx,
bool &didRemap) const;

/// Returns the canonical domain that versions in this domain must be remapped
/// to before making availability comparisons in the current compilation
/// context.
const AvailabilityDomain getRemappedDomain(const ASTContext &ctx) const {
bool unused;
return getRemappedDomain(ctx, unused);
}

bool operator==(const AvailabilityDomain &other) const {
return storage.getOpaqueValue() == other.storage.getOpaqueValue();
}
Expand Down Expand Up @@ -420,6 +434,20 @@ class AvailabilityDomainOrIdentifier {
void print(llvm::raw_ostream &os) const;
};

/// Represents an `AvailabilityRange` paired with the `AvailabilityDomain` that
/// the range applies to.
class AvailabilityDomainAndRange {
AvailabilityDomain domain;
AvailabilityRange range;

public:
AvailabilityDomainAndRange(AvailabilityDomain domain, AvailabilityRange range)
: domain(domain), range(range) {};

AvailabilityDomain getDomain() const { return domain; }
AvailabilityRange getRange() const { return range; }
};

} // end namespace swift

namespace llvm {
Expand Down
5 changes: 0 additions & 5 deletions include/swift/AST/AvailabilityInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ class AvailabilityInference {
const SemanticAvailableAttr &attr, const ASTContext &ctx,
AvailabilityDomain &domain, llvm::VersionTuple &platformVer);

static void
updateAvailabilityDomainForFallback(const SemanticAvailableAttr &attr,
const ASTContext &ctx,
AvailabilityDomain &domain);

/// For the attribute's before version, update the platform and version
/// values to the re-mapped platform's, if using a fallback platform.
/// Returns `true` if a remap occured.
Expand Down
Loading