Skip to content

[Frontend][AST][IRGen] Improve availability support. #71213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 2, 2024
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ include(FetchContent)
check_language(Swift)
if(CMAKE_Swift_COMPILER)
enable_language(Swift)
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION "${CMAKE_Swift_COMPILER_VERSION}")
else()
message(STATUS "WARNING! Did not find a host compiler swift?! Can not build
any compiler host sources written in Swift")
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION)
endif()

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

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

#
# User-configurable Android specific options.
Expand Down
6 changes: 6 additions & 0 deletions SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ function(add_swift_compiler_modules_library name)
"-Xcc" "-std=c++17"
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")

if (NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
if(SWIFT_MIN_RUNTIME_VERSION)
list(APPEND swift_compile_options
"-Xfrontend" "-min-runtime-version"
"-Xfrontend" "${SWIFT_MIN_RUNTIME_VERSION}")
endif()
list(APPEND swift_compile_options "-Xfrontend" "-disable-implicit-string-processing-module-import")
endif()

Expand Down
202 changes: 84 additions & 118 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define SWIFT_AST_ASTCONTEXT_H

#include "swift/AST/ASTAllocated.h"
#include "swift/AST/Availability.h"
#include "swift/AST/Evaluator.h"
#include "swift/AST/GenericSignature.h"
#include "swift/AST/Identifier.h"
Expand Down Expand Up @@ -876,159 +877,124 @@ class ASTContext final {
addCleanup([&object]{ object.~T(); });
}

/// Get the runtime availability of the class metadata update callback
/// mechanism for the target platform.
AvailabilityContext getObjCMetadataUpdateCallbackAvailability();

/// Get the runtime availability of the objc_getClass() hook for the target
/// platform.
AvailabilityContext getObjCGetClassHookAvailability();

/// Get the runtime availability of features introduced in the Swift 5.0
/// compiler for the target platform.
AvailabilityContext getSwift50Availability();

/// Get the runtime availability of the opaque types language feature for the
/// target platform.
AvailabilityContext getOpaqueTypeAvailability();

/// Get the runtime availability of the objc_loadClassref() entry point for
/// the target platform.
AvailabilityContext getObjCClassStubsAvailability();

/// Get the runtime availability of features introduced in the Swift 5.1
/// compiler for the target platform.
AvailabilityContext getSwift51Availability();

/// Get the runtime availability of
/// swift_getTypeByMangledNameInContextInMetadataState.
AvailabilityContext getTypesInAbstractMetadataStateAvailability();

/// Get the runtime availability of support for prespecialized generic
/// metadata.
AvailabilityContext getPrespecializedGenericMetadataAvailability();

/// Get the runtime availability of the swift_compareTypeContextDescriptors
/// for the target platform.
AvailabilityContext getCompareTypeContextDescriptorsAvailability();

/// Get the runtime availability of the
/// swift_compareProtocolConformanceDescriptors entry point for the target
/// platform.
AvailabilityContext getCompareProtocolConformanceDescriptorsAvailability();

/// Get the runtime availability of support for inter-module prespecialized
/// generic metadata.
AvailabilityContext getIntermodulePrespecializedGenericMetadataAvailability();

/// Get the runtime availability of support for concurrency.
AvailabilityContext getConcurrencyAvailability();

/// Get the runtime availability of task executors.
AvailabilityContext getTaskExecutorAvailability();

/// Get the runtime availability of the `DiscardingTaskGroup`,
/// and supporting runtime functions function
AvailabilityContext getConcurrencyDiscardingTaskGroupAvailability();

/// Get the back-deployed availability for concurrency.
AvailabilityContext getBackDeployedConcurrencyAvailability();

/// The the availability since when distributed actors are able to have custom
/// executors.
AvailabilityContext
getConcurrencyDistributedActorWithCustomExecutorAvailability();

/// Get the runtime availability of support for differentiation.
AvailabilityContext getDifferentiationAvailability();

/// Get the runtime availability of support for typed throws.
AvailabilityContext getTypedThrowsAvailability();

/// Get the runtime availability of getters and setters of multi payload enum
/// tag single payloads.
AvailabilityContext getMultiPayloadEnumTagSinglePayload();

/// Get the runtime availability of the Objective-C enabled
/// swift_isUniquelyReferenced functions.
AvailabilityContext getObjCIsUniquelyReferencedAvailability();
/// Get the availability of features introduced in the specified version
/// of the Swift compiler for the target platform.
AvailabilityContext getSwiftAvailability(unsigned major, unsigned minor) const;

// For each feature defined in FeatureAvailability, define two functions;
// the latter, with the suffix RuntimeAvailabilty, is for use with
// AvailabilityContext::forRuntimeTarget(), and only looks at the Swift
// runtime version.
#define FEATURE(N, V) \
inline AvailabilityContext get##N##Availability() const { \
return getSwiftAvailability V; \
} \
inline AvailabilityContext get##N##RuntimeAvailability() const { \
return AvailabilityContext(VersionRange::allGTE(llvm::VersionTuple V)); \
}

/// Get the runtime availability of metadata manipulation runtime functions
/// for extended existential types.
AvailabilityContext getParameterizedExistentialRuntimeAvailability();
#include "swift/AST/FeatureAvailability.def"

/// Get the runtime availability of array buffers placed in constant data
/// sections.
AvailabilityContext getStaticReadOnlyArraysAvailability();
/// Get the runtime availability of features that have been introduced in the
/// Swift compiler for future versions of the target platform.
AvailabilityContext getSwiftFutureAvailability() const;

/// Get the runtime availability of runtime functions for
/// variadic generic types.
AvailabilityContext getVariadicGenericTypeAvailability();
/// Returns `true` if versioned availability annotations are supported for the
/// target triple.
bool supportsVersionedAvailability() const;

/// Get the runtime availability of the conformsToProtocol runtime entrypoint
/// that takes a signed protocol descriptor pointer.
AvailabilityContext getSignedConformsToProtocolAvailability();
//===--------------------------------------------------------------------===//
// Compatibility availability functions
//===--------------------------------------------------------------------===//

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

/// Get the runtime availability of the swift_initRawStructMetadata entrypoint
/// that fixes up the value witness table of @_rawLayout dependent types.
AvailabilityContext getInitRawStructMetadataAvailability();
/// Get the runtime availability of features introduced in the Swift 5.0
/// compiler for the target platform.
inline AvailabilityContext getSwift50Availability() const {
return getSwiftAvailability(5, 0);
}

/// Get the runtime availability of being able to use symbolic references to
/// objective c protocols.
AvailabilityContext getObjCSymbolicReferencesAvailability();
/// Get the runtime availability of features introduced in the Swift 5.1
/// compiler for the target platform.
inline AvailabilityContext getSwift51Availability() const {
return getSwiftAvailability(5, 1);
}

/// Get the runtime availability of features introduced in the Swift 5.2
/// compiler for the target platform.
AvailabilityContext getSwift52Availability();
inline AvailabilityContext getSwift52Availability() const {
return getSwiftAvailability(5, 2);
}

/// Get the runtime availability of features introduced in the Swift 5.3
/// compiler for the target platform.
AvailabilityContext getSwift53Availability();
inline AvailabilityContext getSwift53Availability() const {
return getSwiftAvailability(5, 3);
}

/// Get the runtime availability of features introduced in the Swift 5.4
/// compiler for the target platform.
AvailabilityContext getSwift54Availability();
inline AvailabilityContext getSwift54Availability() const {
return getSwiftAvailability(5, 4);
}

/// Get the runtime availability of features introduced in the Swift 5.5
/// compiler for the target platform.
AvailabilityContext getSwift55Availability();
inline AvailabilityContext getSwift55Availability() const {
return getSwiftAvailability(5, 5);
}

/// Get the runtime availability of features introduced in the Swift 5.6
/// compiler for the target platform.
AvailabilityContext getSwift56Availability();
inline AvailabilityContext getSwift56Availability() const {
return getSwiftAvailability(5, 6);
}

/// Get the runtime availability of features introduced in the Swift 5.7
/// compiler for the target platform.
AvailabilityContext getSwift57Availability();
inline AvailabilityContext getSwift57Availability() const {
return getSwiftAvailability(5, 7);
}

/// Get the runtime availability of features introduced in the Swift 5.8
/// compiler for the target platform.
AvailabilityContext getSwift58Availability();
inline AvailabilityContext getSwift58Availability() const {
return getSwiftAvailability(5, 8);
}

/// Get the runtime availability of features introduced in the Swift 5.9
/// compiler for the target platform.
AvailabilityContext getSwift59Availability();
inline AvailabilityContext getSwift59Availability() const {
return getSwiftAvailability(5, 9);
}

/// Get the runtime availability of features introduced in the Swift 5.9
/// Get the runtime availability of features introduced in the Swift 5.10
/// compiler for the target platform.
AvailabilityContext getSwift511Availability();

// Note: Update this function if you add a new getSwiftXYAvailability above.
/// Get the runtime availability for a particular version of Swift (5.0+).
AvailabilityContext
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion);
inline AvailabilityContext getSwift510Availability() const {
return getSwiftAvailability(5, 10);
}

/// Get the runtime availability of features that have been introduced in the
/// Swift compiler for future versions of the target platform.
AvailabilityContext getSwiftFutureAvailability();
/// Get the runtime availability of features introduced in the Swift 5.11
/// compiler for the target platform.
inline AvailabilityContext getSwift511Availability() const {
return getSwiftAvailability(5, 11);
}

/// Returns `true` if versioned availability annotations are supported for the
/// target triple.
bool supportsVersionedAvailability() const;
/// Get the runtime availability for a particular version of Swift (5.0+).
inline AvailabilityContext
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion) const {
return getSwiftAvailability(swiftVersion.getMajor(),
*swiftVersion.getMinor());
}

/// Get the runtime availability of getters and setters of multi payload enum
/// tag single payloads.
inline AvailabilityContext getMultiPayloadEnumTagSinglePayload() const {
// This didn't fit the pattern, so needed renaming
return getMultiPayloadEnumTagSinglePayloadAvailability();
}

//===--------------------------------------------------------------------===//
// Diagnostics Helper functions
Expand Down
8 changes: 6 additions & 2 deletions include/swift/AST/Availability.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,15 @@ class AvailabilityContext {

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

/// Creates a context that imposes the constraints of the ASTContext's
/// inlining target (i.e. minimum inlining version).
static AvailabilityContext forInliningTarget(ASTContext &Ctx);
static AvailabilityContext forInliningTarget(const ASTContext &Ctx);

/// Creates a context that imposes the constraints of the ASTContext's
/// minimum runtime version.
static AvailabilityContext forRuntimeTarget(const ASTContext &Ctx);

/// Creates a context that imposes no constraints.
///
Expand Down
68 changes: 68 additions & 0 deletions include/swift/AST/FeatureAvailability.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//===--- FeatureAvailability.def - Availability Metaprogramming -*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for macro-metaprogramming with feature
// availability.
//
//===----------------------------------------------------------------------===//

/// FEATURE(N, V)
/// N - The name of the feature (in UpperCamelCase).
/// V - The Swift version number, as a tuple, or FUTURE.
#ifndef FEATURE
#define FEATURE(N, V)
#endif

/// FUTURE
///
/// The version to use for future support.
#ifndef FUTURE
#define FUTURE (99, 99)
#endif

FEATURE(ObjCMetadataUpdateCallback, (5, 0))
FEATURE(ObjCGetClassHook, (5, 0))

FEATURE(OpaqueType, (5, 1))
FEATURE(ObjCClassStubs, (5, 1))
FEATURE(BackDeployedConcurrency, (5, 1))

FEATURE(TypesInAbstractMetadataState, (5, 2))

FEATURE(PrespecializedGenericMetadata, (5, 4))
FEATURE(CompareTypeContextDescriptors, (5, 4))
FEATURE(CompareProtocolConformanceDescriptors, (5, 4))
FEATURE(IntermodulePrespecializedGenericMetadata, (5, 4))

FEATURE(Concurrency, (5, 5))

FEATURE(MultiPayloadEnumTagSinglePayload, (5, 6))
FEATURE(ObjCIsUniquelyReferenced, (5, 6))

FEATURE(ParameterizedExistentialRuntime, (5, 7))

FEATURE(VariadicGenericType, (5, 9))
FEATURE(SignedConformsToProtocol, (5, 9))
FEATURE(ConcurrencyDiscardingTaskGroup, (5, 9))
FEATURE(ConcurrencyDistributedActorWithCustomExecutor, (5, 9))
FEATURE(SignedDescriptor, (5, 9))

FEATURE(ObjCSymbolicReferences, (5, 11))
FEATURE(TypedThrows, (5, 11))
FEATURE(StaticReadOnlyArrays, (5, 11))

FEATURE(TaskExecutor, FUTURE)
FEATURE(Differentiation, FUTURE)
FEATURE(InitRawStructMetadata, FUTURE)

#undef FEATURE
#undef FUTURE
Loading