Skip to content

Commit d0f63a0

Browse files
committed
AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it can be included freely in other headers that need to use it as a complete type. NFC.
1 parent 4c109ee commit d0f63a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+194
-145
lines changed

include/swift/AST/ASTContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define SWIFT_AST_ASTCONTEXT_H
1919

2020
#include "swift/AST/ASTAllocated.h"
21-
#include "swift/AST/Availability.h"
21+
#include "swift/AST/AvailabilityRange.h"
2222
#include "swift/AST/Evaluator.h"
2323
#include "swift/AST/Identifier.h"
2424
#include "swift/AST/Import.h"

include/swift/AST/AvailabilityConstraint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#ifndef SWIFT_AST_AVAILABILITY_CONSTRAINT_H
1818
#define SWIFT_AST_AVAILABILITY_CONSTRAINT_H
1919

20-
#include "swift/AST/Availability.h"
20+
#include "swift/AST/AvailabilityRange.h"
2121
#include "swift/AST/PlatformKind.h"
2222
#include "swift/Basic/LLVM.h"
2323

include/swift/AST/AvailabilityContext.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#ifndef SWIFT_AST_AVAILABILITY_CONTEXT_H
1919
#define SWIFT_AST_AVAILABILITY_CONTEXT_H
2020

21-
#include "swift/AST/Availability.h"
21+
#include "swift/AST/AvailabilityRange.h"
2222
#include "swift/AST/PlatformKind.h"
23+
#include "swift/Basic/Debug.h"
2324
#include "swift/Basic/LLVM.h"
2425
#include <optional>
2526

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//===--- AvailabilityInference.h - Swift Availability Utilities -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines utilities for computing declaration availability.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_AST_AVAILABILITY_INFERENCE_H
18+
#define SWIFT_AST_AVAILABILITY_INFERENCE_H
19+
20+
#include "swift/AST/AvailabilityRange.h"
21+
#include "swift/AST/Type.h"
22+
#include "llvm/Support/VersionTuple.h"
23+
#include <optional>
24+
25+
namespace swift {
26+
class ASTContext;
27+
class AvailableAttr;
28+
class BackDeployedAttr;
29+
class Decl;
30+
31+
class AvailabilityInference {
32+
public:
33+
/// Returns the decl that should be considered the parent decl of the given
34+
/// decl when looking for inherited availability annotations.
35+
static const Decl *parentDeclForInferredAvailability(const Decl *D);
36+
37+
/// Infers the common availability required to access an array of
38+
/// declarations and adds attributes reflecting that availability
39+
/// to ToDecl.
40+
static void
41+
applyInferredAvailableAttrs(Decl *ToDecl,
42+
ArrayRef<const Decl *> InferredFromDecls);
43+
44+
static AvailabilityRange inferForType(Type t);
45+
46+
/// Returns the range of platform versions in which the decl is available.
47+
static AvailabilityRange availableRange(const Decl *D);
48+
49+
/// Returns the range of platform versions in which the decl is available and
50+
/// the attribute which determined this range (which may be `nullptr` if the
51+
/// declaration is always available.
52+
static std::pair<AvailabilityRange, const AvailableAttr *>
53+
availableRangeAndAttr(const Decl *D);
54+
55+
/// Returns true is the declaration is `@_spi_available`.
56+
static bool isAvailableAsSPI(const Decl *D);
57+
58+
/// Returns the range of platform versions in which a declaration with the
59+
/// given `@available` attribute is available.
60+
///
61+
/// NOTE: The attribute must be active on the current platform.
62+
static AvailabilityRange availableRange(const AvailableAttr *attr,
63+
ASTContext &C);
64+
65+
/// Returns the attribute that should be used to determine the availability
66+
/// range of the given declaration, or nullptr if there is none.
67+
static const AvailableAttr *attrForAnnotatedAvailableRange(const Decl *D);
68+
69+
/// Returns the context for which the declaration
70+
/// is annotated as available, or None if the declaration
71+
/// has no availability annotation.
72+
static std::optional<AvailabilityRange>
73+
annotatedAvailableRange(const Decl *D);
74+
75+
static AvailabilityRange
76+
annotatedAvailableRangeForAttr(const Decl *D, const SpecializeAttr *attr,
77+
ASTContext &ctx);
78+
79+
/// For the attribute's introduction version, update the platform and version
80+
/// values to the re-mapped platform's, if using a fallback platform.
81+
/// Returns `true` if a remap occured.
82+
static bool updateIntroducedPlatformForFallback(
83+
const AvailableAttr *attr, const ASTContext &Ctx,
84+
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
85+
86+
/// For the attribute's deprecation version, update the platform and version
87+
/// values to the re-mapped platform's, if using a fallback platform.
88+
/// Returns `true` if a remap occured.
89+
static bool updateDeprecatedPlatformForFallback(
90+
const AvailableAttr *attr, const ASTContext &Ctx,
91+
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
92+
93+
/// For the attribute's obsoletion version, update the platform and version
94+
/// values to the re-mapped platform's, if using a fallback platform.
95+
/// Returns `true` if a remap occured.
96+
static bool updateObsoletedPlatformForFallback(
97+
const AvailableAttr *attr, const ASTContext &Ctx,
98+
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
99+
100+
static void updatePlatformStringForFallback(
101+
const AvailableAttr *attr, const ASTContext &Ctx,
102+
llvm::StringRef &Platform);
103+
104+
/// For the attribute's before version, update the platform and version
105+
/// values to the re-mapped platform's, if using a fallback platform.
106+
/// Returns `true` if a remap occured.
107+
static bool updateBeforePlatformForFallback(const BackDeployedAttr *attr,
108+
const ASTContext &Ctx,
109+
llvm::StringRef &Platform,
110+
llvm::VersionTuple &PlatformVer);
111+
};
112+
113+
// FIXME: This should become a utility on Decl.
114+
115+
/// Given a declaration upon which an availability attribute would appear in
116+
/// concrete syntax, return a declaration to which the parser
117+
/// actually attaches the attribute in the abstract syntax tree. We use this
118+
/// function to determine whether the concrete syntax already has an
119+
/// availability attribute.
120+
const Decl *abstractSyntaxDeclForAvailableAttribute(const Decl *D);
121+
122+
} // end namespace swift
123+
124+
#endif

include/swift/AST/Availability.h include/swift/AST/AvailabilityRange.h

+5-99
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
1-
//===--- Availability.h - Swift Availability Structures ---------*- C++ -*-===//
1+
//===--- AvailabilityRange.h - Swift Availability Range ---------*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines data structures for API availability.
13+
// This file defines the AvailabilityRange utility.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#ifndef SWIFT_AST_AVAILABILITY_H
18-
#define SWIFT_AST_AVAILABILITY_H
17+
#ifndef SWIFT_AST_AVAILABILITY_RANGE_H
18+
#define SWIFT_AST_AVAILABILITY_RANGE_H
1919

20-
#include "swift/AST/PlatformKind.h"
21-
#include "swift/AST/Type.h"
2220
#include "swift/Basic/LLVM.h"
2321
#include "llvm/ADT/FoldingSet.h"
2422
#include "llvm/Support/VersionTuple.h"
2523
#include <optional>
2624

2725
namespace swift {
2826
class ASTContext;
29-
class AvailableAttr;
30-
class BackDeployedAttr;
31-
class Decl;
3227

3328
/// A lattice of version ranges of the form [x.y.z, +Inf).
3429
class VersionRange {
@@ -335,95 +330,6 @@ class AvailabilityRange {
335330
}
336331
};
337332

338-
class AvailabilityInference {
339-
public:
340-
/// Returns the decl that should be considered the parent decl of the given
341-
/// decl when looking for inherited availability annotations.
342-
static const Decl *parentDeclForInferredAvailability(const Decl *D);
343-
344-
/// Infers the common availability required to access an array of
345-
/// declarations and adds attributes reflecting that availability
346-
/// to ToDecl.
347-
static void
348-
applyInferredAvailableAttrs(Decl *ToDecl,
349-
ArrayRef<const Decl *> InferredFromDecls);
350-
351-
static AvailabilityRange inferForType(Type t);
352-
353-
/// Returns the range of platform versions in which the decl is available.
354-
static AvailabilityRange availableRange(const Decl *D);
355-
356-
/// Returns the range of platform versions in which the decl is available and
357-
/// the attribute which determined this range (which may be `nullptr` if the
358-
/// declaration is always available.
359-
static std::pair<AvailabilityRange, const AvailableAttr *>
360-
availableRangeAndAttr(const Decl *D);
361-
362-
/// Returns true is the declaration is `@_spi_available`.
363-
static bool isAvailableAsSPI(const Decl *D);
364-
365-
/// Returns the range of platform versions in which a declaration with the
366-
/// given `@available` attribute is available.
367-
///
368-
/// NOTE: The attribute must be active on the current platform.
369-
static AvailabilityRange availableRange(const AvailableAttr *attr,
370-
ASTContext &C);
371-
372-
/// Returns the attribute that should be used to determine the availability
373-
/// range of the given declaration, or nullptr if there is none.
374-
static const AvailableAttr *attrForAnnotatedAvailableRange(const Decl *D);
375-
376-
/// Returns the context for which the declaration
377-
/// is annotated as available, or None if the declaration
378-
/// has no availability annotation.
379-
static std::optional<AvailabilityRange>
380-
annotatedAvailableRange(const Decl *D);
381-
382-
static AvailabilityRange
383-
annotatedAvailableRangeForAttr(const Decl *D, const SpecializeAttr *attr,
384-
ASTContext &ctx);
385-
386-
/// For the attribute's introduction version, update the platform and version
387-
/// values to the re-mapped platform's, if using a fallback platform.
388-
/// Returns `true` if a remap occured.
389-
static bool updateIntroducedPlatformForFallback(
390-
const AvailableAttr *attr, const ASTContext &Ctx,
391-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
392-
393-
/// For the attribute's deprecation version, update the platform and version
394-
/// values to the re-mapped platform's, if using a fallback platform.
395-
/// Returns `true` if a remap occured.
396-
static bool updateDeprecatedPlatformForFallback(
397-
const AvailableAttr *attr, const ASTContext &Ctx,
398-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
399-
400-
/// For the attribute's obsoletion version, update the platform and version
401-
/// values to the re-mapped platform's, if using a fallback platform.
402-
/// Returns `true` if a remap occured.
403-
static bool updateObsoletedPlatformForFallback(
404-
const AvailableAttr *attr, const ASTContext &Ctx,
405-
llvm::StringRef &Platform, llvm::VersionTuple &PlatformVer);
406-
407-
static void updatePlatformStringForFallback(
408-
const AvailableAttr *attr, const ASTContext &Ctx,
409-
llvm::StringRef &Platform);
410-
411-
/// For the attribute's before version, update the platform and version
412-
/// values to the re-mapped platform's, if using a fallback platform.
413-
/// Returns `true` if a remap occured.
414-
static bool updateBeforePlatformForFallback(const BackDeployedAttr *attr,
415-
const ASTContext &Ctx,
416-
llvm::StringRef &Platform,
417-
llvm::VersionTuple &PlatformVer);
418-
};
419-
420-
/// Given a declaration upon which an availability attribute would appear in
421-
/// concrete syntax, return a declaration to which the parser
422-
/// actually attaches the attribute in the abstract syntax tree. We use this
423-
/// function to determine whether the concrete syntax already has an
424-
/// availability attribute.
425-
const Decl *abstractSyntaxDeclForAvailableAttribute(const Decl *D);
426-
427333
} // end namespace swift
428334

429335
#endif

include/swift/AST/AvailabilityScope.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#ifndef SWIFT_AVAILABILITYSCOPE_H
2020
#define SWIFT_AVAILABILITYSCOPE_H
2121

22-
#include "swift/AST/Availability.h"
2322
#include "swift/AST/AvailabilityContext.h"
23+
#include "swift/AST/AvailabilityRange.h"
2424
#include "swift/AST/Identifier.h"
2525
#include "swift/AST/Stmt.h" // for PoundAvailableInfo
2626
#include "swift/Basic/Debug.h"

include/swift/AST/AvailabilitySpec.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#define SWIFT_AST_AVAILABILITY_SPEC_H
1919

2020
#include "swift/AST/Identifier.h"
21-
#include "swift/Basic/SourceLoc.h"
2221
#include "swift/AST/PlatformKind.h"
22+
#include "swift/Basic/SourceLoc.h"
23+
#include "llvm/ADT/DenseMap.h"
2324
#include "llvm/Support/VersionTuple.h"
2425

2526
namespace swift {

include/swift/AST/Decl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "swift/AST/AccessScope.h"
2121
#include "swift/AST/Attr.h"
22-
#include "swift/AST/Availability.h"
22+
#include "swift/AST/AvailabilityRange.h"
2323
#include "swift/AST/CaptureInfo.h"
2424
#include "swift/AST/ClangNode.h"
2525
#include "swift/AST/ConcreteDeclRef.h"

include/swift/AST/Expr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "swift/AST/ArgumentList.h"
2121
#include "swift/AST/Attr.h"
22-
#include "swift/AST/Availability.h"
22+
#include "swift/AST/AvailabilityRange.h"
2323
#include "swift/AST/CaptureInfo.h"
2424
#include "swift/AST/ConcreteDeclRef.h"
2525
#include "swift/AST/Decl.h"

include/swift/AST/Stmt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "swift/AST/ASTAllocated.h"
2121
#include "swift/AST/ASTNode.h"
22-
#include "swift/AST/Availability.h"
22+
#include "swift/AST/AvailabilityRange.h"
2323
#include "swift/AST/AvailabilitySpec.h"
2424
#include "swift/AST/ConcreteDeclRef.h"
2525
#include "swift/AST/IfConfigClause.h"

include/swift/SIL/SILDeclRef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef SWIFT_SIL_SILDeclRef_H
2020
#define SWIFT_SIL_SILDeclRef_H
2121

22-
#include "swift/AST/Availability.h"
22+
#include "swift/AST/AvailabilityRange.h"
2323
#include "swift/AST/ClangNode.h"
2424
#include "swift/AST/GenericSignature.h"
2525
#include "swift/AST/TypeAlignments.h"

include/swift/SIL/SILFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define SWIFT_SIL_SILFUNCTION_H
1919

2020
#include "swift/AST/ASTNode.h"
21-
#include "swift/AST/Availability.h"
21+
#include "swift/AST/AvailabilityRange.h"
2222
#include "swift/AST/Module.h"
2323
#include "swift/AST/ResilienceExpansion.h"
2424
#include "swift/Basic/ProfileCounter.h"

include/swift/SIL/SILFunctionBuilder.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_SIL_SILFUNCTIONBUILDER_H
1414
#define SWIFT_SIL_SILFUNCTIONBUILDER_H
1515

16-
#include "swift/AST/Availability.h"
16+
#include "swift/AST/AvailabilityRange.h"
1717
#include "swift/SIL/SILModule.h"
1818

1919
namespace swift {

include/swift/Sema/OverloadChoice.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#ifndef SWIFT_SEMA_OVERLOADCHOICE_H
1919
#define SWIFT_SEMA_OVERLOADCHOICE_H
2020

21-
#include "llvm/ADT/PointerIntPair.h"
22-
#include "llvm/Support/ErrorHandling.h"
23-
#include "swift/AST/Availability.h"
21+
#include "swift/AST/AvailabilityRange.h"
2422
#include "swift/AST/FunctionRefInfo.h"
2523
#include "swift/AST/Types.h"
24+
#include "llvm/ADT/PointerIntPair.h"
25+
#include "llvm/Support/ErrorHandling.h"
2626

2727
namespace swift {
2828

lib/AST/Attr.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/ASTContext.h"
1919
#include "swift/AST/ASTPrinter.h"
2020
#include "swift/AST/AvailabilityDomain.h"
21+
#include "swift/AST/AvailabilityInference.h"
2122
#include "swift/AST/Decl.h"
2223
#include "swift/AST/Expr.h"
2324
#include "swift/AST/GenericEnvironment.h"

0 commit comments

Comments
 (0)