Skip to content

Commit 5dc654c

Browse files
committed
AST: Move UnmetAvailabilityRequirement to Availability.h.
This type will need to be used outside of Sema.
1 parent a95891c commit 5dc654c

File tree

4 files changed

+81
-81
lines changed

4 files changed

+81
-81
lines changed

include/swift/AST/Availability.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,74 @@ class AvailabilityRange {
335335
}
336336
};
337337

338+
/// Represents the reason a declaration is considered unavailable in a certain
339+
/// context.
340+
class UnmetAvailabilityRequirement {
341+
public:
342+
enum class Kind {
343+
/// The declaration is referenced in a context in which it is
344+
/// generally unavailable. For example, a reference to a declaration that is
345+
/// unavailable on macOS from a context that may execute on macOS has this
346+
/// unmet requirement.
347+
AlwaysUnavailable,
348+
349+
/// The declaration is referenced in a context in which it is considered
350+
/// obsolete. For example, a reference to a declaration that is obsolete in
351+
/// macOS 13 from a context that may execute on macOS 13 or later has this
352+
/// unmet requirement.
353+
Obsoleted,
354+
355+
/// The declaration is only available in a different version. For example,
356+
/// the declaration might only be introduced in the Swift 6 language mode
357+
/// while the module is being compiled in the Swift 5 language mode.
358+
RequiresVersion,
359+
360+
/// The declaration is referenced in a context that does not have an
361+
/// adequate minimum version constraint. For example, a reference to a
362+
/// declaration that is introduced in macOS 13 from a context that may
363+
/// execute on earlier versions of macOS has this unmet requirement. This
364+
/// kind of unmet requirement can be addressed by tightening the minimum
365+
/// version of the context with `if #available(...)` or by adding or
366+
/// adjusting an `@available` attribute.
367+
IntroducedInNewerVersion,
368+
};
369+
370+
private:
371+
Kind kind;
372+
const AvailableAttr *attr;
373+
374+
UnmetAvailabilityRequirement(Kind kind, const AvailableAttr *attr)
375+
: kind(kind), attr(attr){};
376+
377+
public:
378+
static UnmetAvailabilityRequirement
379+
forAlwaysUnavailable(const AvailableAttr *attr) {
380+
return UnmetAvailabilityRequirement(Kind::AlwaysUnavailable, attr);
381+
}
382+
383+
static UnmetAvailabilityRequirement forObsoleted(const AvailableAttr *attr) {
384+
return UnmetAvailabilityRequirement(Kind::Obsoleted, attr);
385+
}
386+
387+
static UnmetAvailabilityRequirement
388+
forRequiresVersion(const AvailableAttr *attr) {
389+
return UnmetAvailabilityRequirement(Kind::RequiresVersion, attr);
390+
}
391+
392+
static UnmetAvailabilityRequirement
393+
forIntroducedInNewerVersion(const AvailableAttr *attr) {
394+
return UnmetAvailabilityRequirement(Kind::IntroducedInNewerVersion, attr);
395+
}
396+
397+
Kind getKind() const { return kind; }
398+
const AvailableAttr *getAttr() const { return attr; }
399+
400+
/// Returns the required range for `IntroducedInNewerVersion` requirements, or
401+
/// `std::nullopt` otherwise.
402+
std::optional<AvailabilityRange>
403+
getRequiredNewerAvailabilityRange(ASTContext &ctx) const;
404+
};
405+
338406
class AvailabilityInference {
339407
public:
340408
/// Returns the decl that should be considered the parent decl of the given

lib/AST/Availability.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ AvailabilityRange AvailabilityRange::forRuntimeTarget(const ASTContext &Ctx) {
6464
return AvailabilityRange(VersionRange::allGTE(Ctx.LangOpts.RuntimeVersion));
6565
}
6666

67+
std::optional<AvailabilityRange>
68+
UnmetAvailabilityRequirement::getRequiredNewerAvailabilityRange(
69+
ASTContext &ctx) const {
70+
switch (kind) {
71+
case Kind::AlwaysUnavailable:
72+
case Kind::RequiresVersion:
73+
case Kind::Obsoleted:
74+
return std::nullopt;
75+
case Kind::IntroducedInNewerVersion:
76+
return AvailabilityInference::availableRange(attr, ctx);
77+
}
78+
}
79+
6780
namespace {
6881

6982
/// The inferred availability required to access a group of declarations

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,6 @@ ExportContext::getExportabilityReason() const {
316316
return std::nullopt;
317317
}
318318

319-
std::optional<AvailabilityRange>
320-
UnmetAvailabilityRequirement::getRequiredNewerAvailabilityRange(
321-
ASTContext &ctx) const {
322-
switch (kind) {
323-
case Kind::AlwaysUnavailable:
324-
case Kind::RequiresVersion:
325-
case Kind::Obsoleted:
326-
return std::nullopt;
327-
case Kind::IntroducedInNewerVersion:
328-
return AvailabilityInference::availableRange(attr, ctx);
329-
}
330-
}
331-
332319
/// Returns the first availability attribute on the declaration that is active
333320
/// on the target platform.
334321
static const AvailableAttr *getActiveAvailableAttribute(const Decl *D,

lib/Sema/TypeCheckAvailability.h

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -200,74 +200,6 @@ class ExportContext {
200200
const AvailableAttr *shouldDiagnoseDeclAsUnavailable(const Decl *decl) const;
201201
};
202202

203-
/// Represents the reason a declaration is considered unavailable in a certain
204-
/// context.
205-
class UnmetAvailabilityRequirement {
206-
public:
207-
enum class Kind {
208-
/// The declaration is referenced in a context in which it is
209-
/// generally unavailable. For example, a reference to a declaration that is
210-
/// unavailable on macOS from a context that may execute on macOS has this
211-
/// unmet requirement.
212-
AlwaysUnavailable,
213-
214-
/// The declaration is referenced in a context in which it is considered
215-
/// obsolete. For example, a reference to a declaration that is obsolete in
216-
/// macOS 13 from a context that may execute on macOS 13 or later has this
217-
/// unmet requirement.
218-
Obsoleted,
219-
220-
/// The declaration is only available in a different version. For example,
221-
/// the declaration might only be introduced in the Swift 6 language mode
222-
/// while the module is being compiled in the Swift 5 language mode.
223-
RequiresVersion,
224-
225-
/// The declaration is referenced in a context that does not have an
226-
/// adequate minimum version constraint. For example, a reference to a
227-
/// declaration that is introduced in macOS 13 from a context that may
228-
/// execute on earlier versions of macOS has this unmet requirement. This
229-
/// kind of unmet requirement can be addressed by tightening the minimum
230-
/// version of the context with `if #available(...)` or by adding or
231-
/// adjusting an `@available` attribute.
232-
IntroducedInNewerVersion,
233-
};
234-
235-
private:
236-
Kind kind;
237-
const AvailableAttr *attr;
238-
239-
UnmetAvailabilityRequirement(Kind kind, const AvailableAttr *attr)
240-
: kind(kind), attr(attr){};
241-
242-
public:
243-
static UnmetAvailabilityRequirement
244-
forAlwaysUnavailable(const AvailableAttr *attr) {
245-
return UnmetAvailabilityRequirement(Kind::AlwaysUnavailable, attr);
246-
}
247-
248-
static UnmetAvailabilityRequirement forObsoleted(const AvailableAttr *attr) {
249-
return UnmetAvailabilityRequirement(Kind::Obsoleted, attr);
250-
}
251-
252-
static UnmetAvailabilityRequirement
253-
forRequiresVersion(const AvailableAttr *attr) {
254-
return UnmetAvailabilityRequirement(Kind::RequiresVersion, attr);
255-
}
256-
257-
static UnmetAvailabilityRequirement
258-
forIntroducedInNewerVersion(const AvailableAttr *attr) {
259-
return UnmetAvailabilityRequirement(Kind::IntroducedInNewerVersion, attr);
260-
}
261-
262-
Kind getKind() const { return kind; }
263-
const AvailableAttr *getAttr() const { return attr; }
264-
265-
/// Returns the required range for `IntroducedInNewerVersion` requirements, or
266-
/// `std::nullopt` otherwise.
267-
std::optional<AvailabilityRange>
268-
getRequiredNewerAvailabilityRange(ASTContext &ctx) const;
269-
};
270-
271203
/// Check if a declaration is exported as part of a module's external interface.
272204
/// This includes public and @usableFromInline decls.
273205
bool isExported(const ValueDecl *VD);

0 commit comments

Comments
 (0)