Skip to content

Commit 4c7822c

Browse files
authored
Merge pull request #71213 from al45tair/eng/PR-121522431
[Frontend][AST][IRGen] Improve availability support.
2 parents a77d119 + b8284ba commit 4c7822c

File tree

15 files changed

+443
-478
lines changed

15 files changed

+443
-478
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ include(FetchContent)
101101
check_language(Swift)
102102
if(CMAKE_Swift_COMPILER)
103103
enable_language(Swift)
104+
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION "${CMAKE_Swift_COMPILER_VERSION}")
104105
else()
105106
message(STATUS "WARNING! Did not find a host compiler swift?! Can not build
106107
any compiler host sources written in Swift")
108+
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION)
107109
endif()
108110

109111
# A convenience pattern to match Darwin platforms. Example:
@@ -464,6 +466,10 @@ set(SWIFT_DARWIN_MODULE_ARCHS "" CACHE STRING
464466
targets on Darwin platforms. These targets are in addition to the full \
465467
library targets.")
466468

469+
set(SWIFT_MIN_RUNTIME_VERSION "${DEFAULT_SWIFT_MIN_RUNTIME_VERSION}" CACHE STRING
470+
"Specify the minimum version of the runtime that we target when building \
471+
the compiler itself. This is used on non-Darwin platforms to ensure \
472+
that it's possible to build the compiler using host tools.")
467473

468474
#
469475
# User-configurable Android specific options.

SwiftCompilerSources/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ function(add_swift_compiler_modules_library name)
106106
"-Xcc" "-std=c++17"
107107
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"
108108
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
109+
109110
if (NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
111+
if(SWIFT_MIN_RUNTIME_VERSION)
112+
list(APPEND swift_compile_options
113+
"-Xfrontend" "-min-runtime-version"
114+
"-Xfrontend" "${SWIFT_MIN_RUNTIME_VERSION}")
115+
endif()
110116
list(APPEND swift_compile_options "-Xfrontend" "-disable-implicit-string-processing-module-import")
111117
endif()
112118

include/swift/AST/ASTContext.h

Lines changed: 84 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_AST_ASTCONTEXT_H
1919

2020
#include "swift/AST/ASTAllocated.h"
21+
#include "swift/AST/Availability.h"
2122
#include "swift/AST/Evaluator.h"
2223
#include "swift/AST/GenericSignature.h"
2324
#include "swift/AST/Identifier.h"
@@ -884,159 +885,124 @@ class ASTContext final {
884885
addCleanup([&object]{ object.~T(); });
885886
}
886887

887-
/// Get the runtime availability of the class metadata update callback
888-
/// mechanism for the target platform.
889-
AvailabilityContext getObjCMetadataUpdateCallbackAvailability();
890-
891-
/// Get the runtime availability of the objc_getClass() hook for the target
892-
/// platform.
893-
AvailabilityContext getObjCGetClassHookAvailability();
894-
895-
/// Get the runtime availability of features introduced in the Swift 5.0
896-
/// compiler for the target platform.
897-
AvailabilityContext getSwift50Availability();
898-
899-
/// Get the runtime availability of the opaque types language feature for the
900-
/// target platform.
901-
AvailabilityContext getOpaqueTypeAvailability();
902-
903-
/// Get the runtime availability of the objc_loadClassref() entry point for
904-
/// the target platform.
905-
AvailabilityContext getObjCClassStubsAvailability();
906-
907-
/// Get the runtime availability of features introduced in the Swift 5.1
908-
/// compiler for the target platform.
909-
AvailabilityContext getSwift51Availability();
910-
911-
/// Get the runtime availability of
912-
/// swift_getTypeByMangledNameInContextInMetadataState.
913-
AvailabilityContext getTypesInAbstractMetadataStateAvailability();
914-
915-
/// Get the runtime availability of support for prespecialized generic
916-
/// metadata.
917-
AvailabilityContext getPrespecializedGenericMetadataAvailability();
918-
919-
/// Get the runtime availability of the swift_compareTypeContextDescriptors
920-
/// for the target platform.
921-
AvailabilityContext getCompareTypeContextDescriptorsAvailability();
922-
923-
/// Get the runtime availability of the
924-
/// swift_compareProtocolConformanceDescriptors entry point for the target
925-
/// platform.
926-
AvailabilityContext getCompareProtocolConformanceDescriptorsAvailability();
927-
928-
/// Get the runtime availability of support for inter-module prespecialized
929-
/// generic metadata.
930-
AvailabilityContext getIntermodulePrespecializedGenericMetadataAvailability();
931-
932-
/// Get the runtime availability of support for concurrency.
933-
AvailabilityContext getConcurrencyAvailability();
934-
935-
/// Get the runtime availability of task executors.
936-
AvailabilityContext getTaskExecutorAvailability();
937-
938-
/// Get the runtime availability of the `DiscardingTaskGroup`,
939-
/// and supporting runtime functions function
940-
AvailabilityContext getConcurrencyDiscardingTaskGroupAvailability();
941-
942-
/// Get the back-deployed availability for concurrency.
943-
AvailabilityContext getBackDeployedConcurrencyAvailability();
944-
945-
/// The the availability since when distributed actors are able to have custom
946-
/// executors.
947-
AvailabilityContext
948-
getConcurrencyDistributedActorWithCustomExecutorAvailability();
949-
950-
/// Get the runtime availability of support for differentiation.
951-
AvailabilityContext getDifferentiationAvailability();
952-
953-
/// Get the runtime availability of support for typed throws.
954-
AvailabilityContext getTypedThrowsAvailability();
955-
956-
/// Get the runtime availability of getters and setters of multi payload enum
957-
/// tag single payloads.
958-
AvailabilityContext getMultiPayloadEnumTagSinglePayload();
959-
960-
/// Get the runtime availability of the Objective-C enabled
961-
/// swift_isUniquelyReferenced functions.
962-
AvailabilityContext getObjCIsUniquelyReferencedAvailability();
888+
/// Get the availability of features introduced in the specified version
889+
/// of the Swift compiler for the target platform.
890+
AvailabilityContext getSwiftAvailability(unsigned major, unsigned minor) const;
891+
892+
// For each feature defined in FeatureAvailability, define two functions;
893+
// the latter, with the suffix RuntimeAvailabilty, is for use with
894+
// AvailabilityContext::forRuntimeTarget(), and only looks at the Swift
895+
// runtime version.
896+
#define FEATURE(N, V) \
897+
inline AvailabilityContext get##N##Availability() const { \
898+
return getSwiftAvailability V; \
899+
} \
900+
inline AvailabilityContext get##N##RuntimeAvailability() const { \
901+
return AvailabilityContext(VersionRange::allGTE(llvm::VersionTuple V)); \
902+
}
963903

964-
/// Get the runtime availability of metadata manipulation runtime functions
965-
/// for extended existential types.
966-
AvailabilityContext getParameterizedExistentialRuntimeAvailability();
904+
#include "swift/AST/FeatureAvailability.def"
967905

968-
/// Get the runtime availability of array buffers placed in constant data
969-
/// sections.
970-
AvailabilityContext getStaticReadOnlyArraysAvailability();
906+
/// Get the runtime availability of features that have been introduced in the
907+
/// Swift compiler for future versions of the target platform.
908+
AvailabilityContext getSwiftFutureAvailability() const;
971909

972-
/// Get the runtime availability of runtime functions for
973-
/// variadic generic types.
974-
AvailabilityContext getVariadicGenericTypeAvailability();
910+
/// Returns `true` if versioned availability annotations are supported for the
911+
/// target triple.
912+
bool supportsVersionedAvailability() const;
975913

976-
/// Get the runtime availability of the conformsToProtocol runtime entrypoint
977-
/// that takes a signed protocol descriptor pointer.
978-
AvailabilityContext getSignedConformsToProtocolAvailability();
914+
//===--------------------------------------------------------------------===//
915+
// Compatibility availability functions
916+
//===--------------------------------------------------------------------===//
979917

980-
/// Get the runtime availability of runtime entrypoints that take signed type
981-
/// descriptors.
982-
AvailabilityContext getSignedDescriptorAvailability();
918+
// Note: Don't add more of these version-specific availability functions;
919+
// just use getSwiftAvailability() instead.
983920

984-
/// Get the runtime availability of the swift_initRawStructMetadata entrypoint
985-
/// that fixes up the value witness table of @_rawLayout dependent types.
986-
AvailabilityContext getInitRawStructMetadataAvailability();
921+
/// Get the runtime availability of features introduced in the Swift 5.0
922+
/// compiler for the target platform.
923+
inline AvailabilityContext getSwift50Availability() const {
924+
return getSwiftAvailability(5, 0);
925+
}
987926

988-
/// Get the runtime availability of being able to use symbolic references to
989-
/// objective c protocols.
990-
AvailabilityContext getObjCSymbolicReferencesAvailability();
927+
/// Get the runtime availability of features introduced in the Swift 5.1
928+
/// compiler for the target platform.
929+
inline AvailabilityContext getSwift51Availability() const {
930+
return getSwiftAvailability(5, 1);
931+
}
991932

992933
/// Get the runtime availability of features introduced in the Swift 5.2
993934
/// compiler for the target platform.
994-
AvailabilityContext getSwift52Availability();
935+
inline AvailabilityContext getSwift52Availability() const {
936+
return getSwiftAvailability(5, 2);
937+
}
995938

996939
/// Get the runtime availability of features introduced in the Swift 5.3
997940
/// compiler for the target platform.
998-
AvailabilityContext getSwift53Availability();
941+
inline AvailabilityContext getSwift53Availability() const {
942+
return getSwiftAvailability(5, 3);
943+
}
999944

1000945
/// Get the runtime availability of features introduced in the Swift 5.4
1001946
/// compiler for the target platform.
1002-
AvailabilityContext getSwift54Availability();
947+
inline AvailabilityContext getSwift54Availability() const {
948+
return getSwiftAvailability(5, 4);
949+
}
1003950

1004951
/// Get the runtime availability of features introduced in the Swift 5.5
1005952
/// compiler for the target platform.
1006-
AvailabilityContext getSwift55Availability();
953+
inline AvailabilityContext getSwift55Availability() const {
954+
return getSwiftAvailability(5, 5);
955+
}
1007956

1008957
/// Get the runtime availability of features introduced in the Swift 5.6
1009958
/// compiler for the target platform.
1010-
AvailabilityContext getSwift56Availability();
959+
inline AvailabilityContext getSwift56Availability() const {
960+
return getSwiftAvailability(5, 6);
961+
}
1011962

1012963
/// Get the runtime availability of features introduced in the Swift 5.7
1013964
/// compiler for the target platform.
1014-
AvailabilityContext getSwift57Availability();
965+
inline AvailabilityContext getSwift57Availability() const {
966+
return getSwiftAvailability(5, 7);
967+
}
1015968

1016969
/// Get the runtime availability of features introduced in the Swift 5.8
1017970
/// compiler for the target platform.
1018-
AvailabilityContext getSwift58Availability();
971+
inline AvailabilityContext getSwift58Availability() const {
972+
return getSwiftAvailability(5, 8);
973+
}
1019974

1020975
/// Get the runtime availability of features introduced in the Swift 5.9
1021976
/// compiler for the target platform.
1022-
AvailabilityContext getSwift59Availability();
977+
inline AvailabilityContext getSwift59Availability() const {
978+
return getSwiftAvailability(5, 9);
979+
}
1023980

1024-
/// Get the runtime availability of features introduced in the Swift 5.9
981+
/// Get the runtime availability of features introduced in the Swift 5.10
1025982
/// compiler for the target platform.
1026-
AvailabilityContext getSwift511Availability();
1027-
1028-
// Note: Update this function if you add a new getSwiftXYAvailability above.
1029-
/// Get the runtime availability for a particular version of Swift (5.0+).
1030-
AvailabilityContext
1031-
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion);
983+
inline AvailabilityContext getSwift510Availability() const {
984+
return getSwiftAvailability(5, 10);
985+
}
1032986

1033-
/// Get the runtime availability of features that have been introduced in the
1034-
/// Swift compiler for future versions of the target platform.
1035-
AvailabilityContext getSwiftFutureAvailability();
987+
/// Get the runtime availability of features introduced in the Swift 5.11
988+
/// compiler for the target platform.
989+
inline AvailabilityContext getSwift511Availability() const {
990+
return getSwiftAvailability(5, 11);
991+
}
1036992

1037-
/// Returns `true` if versioned availability annotations are supported for the
1038-
/// target triple.
1039-
bool supportsVersionedAvailability() const;
993+
/// Get the runtime availability for a particular version of Swift (5.0+).
994+
inline AvailabilityContext
995+
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion) const {
996+
return getSwiftAvailability(swiftVersion.getMajor(),
997+
*swiftVersion.getMinor());
998+
}
999+
1000+
/// Get the runtime availability of getters and setters of multi payload enum
1001+
/// tag single payloads.
1002+
inline AvailabilityContext getMultiPayloadEnumTagSinglePayload() const {
1003+
// This didn't fit the pattern, so needed renaming
1004+
return getMultiPayloadEnumTagSinglePayloadAvailability();
1005+
}
10401006

10411007
//===--------------------------------------------------------------------===//
10421008
// Diagnostics Helper functions

include/swift/AST/Availability.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,15 @@ class AvailabilityContext {
238238

239239
/// Creates a context that imposes the constraints of the ASTContext's
240240
/// deployment target.
241-
static AvailabilityContext forDeploymentTarget(ASTContext &Ctx);
241+
static AvailabilityContext forDeploymentTarget(const ASTContext &Ctx);
242242

243243
/// Creates a context that imposes the constraints of the ASTContext's
244244
/// inlining target (i.e. minimum inlining version).
245-
static AvailabilityContext forInliningTarget(ASTContext &Ctx);
245+
static AvailabilityContext forInliningTarget(const ASTContext &Ctx);
246+
247+
/// Creates a context that imposes the constraints of the ASTContext's
248+
/// minimum runtime version.
249+
static AvailabilityContext forRuntimeTarget(const ASTContext &Ctx);
246250

247251
/// Creates a context that imposes no constraints.
248252
///
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===--- FeatureAvailability.def - Availability Metaprogramming -*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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 macros used for macro-metaprogramming with feature
14+
// availability.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
/// FEATURE(N, V)
19+
/// N - The name of the feature (in UpperCamelCase).
20+
/// V - The Swift version number, as a tuple, or FUTURE.
21+
#ifndef FEATURE
22+
#define FEATURE(N, V)
23+
#endif
24+
25+
/// FUTURE
26+
///
27+
/// The version to use for future support.
28+
#ifndef FUTURE
29+
#define FUTURE (99, 99)
30+
#endif
31+
32+
FEATURE(ObjCMetadataUpdateCallback, (5, 0))
33+
FEATURE(ObjCGetClassHook, (5, 0))
34+
35+
FEATURE(OpaqueType, (5, 1))
36+
FEATURE(ObjCClassStubs, (5, 1))
37+
FEATURE(BackDeployedConcurrency, (5, 1))
38+
39+
FEATURE(TypesInAbstractMetadataState, (5, 2))
40+
41+
FEATURE(PrespecializedGenericMetadata, (5, 4))
42+
FEATURE(CompareTypeContextDescriptors, (5, 4))
43+
FEATURE(CompareProtocolConformanceDescriptors, (5, 4))
44+
FEATURE(IntermodulePrespecializedGenericMetadata, (5, 4))
45+
46+
FEATURE(Concurrency, (5, 5))
47+
48+
FEATURE(MultiPayloadEnumTagSinglePayload, (5, 6))
49+
FEATURE(ObjCIsUniquelyReferenced, (5, 6))
50+
51+
FEATURE(ParameterizedExistentialRuntime, (5, 7))
52+
53+
FEATURE(VariadicGenericType, (5, 9))
54+
FEATURE(SignedConformsToProtocol, (5, 9))
55+
FEATURE(ConcurrencyDiscardingTaskGroup, (5, 9))
56+
FEATURE(ConcurrencyDistributedActorWithCustomExecutor, (5, 9))
57+
FEATURE(SignedDescriptor, (5, 9))
58+
59+
FEATURE(ObjCSymbolicReferences, (5, 11))
60+
FEATURE(TypedThrows, (5, 11))
61+
FEATURE(StaticReadOnlyArrays, (5, 11))
62+
63+
FEATURE(TaskExecutor, FUTURE)
64+
FEATURE(Differentiation, FUTURE)
65+
FEATURE(InitRawStructMetadata, FUTURE)
66+
67+
#undef FEATURE
68+
#undef FUTURE

0 commit comments

Comments
 (0)