Skip to content

Commit b03cde6

Browse files
authored
Merge pull request #39342 from DougGregor/back-deploy-concurrency-5.5
Back-deploy concurrency
2 parents 92a2a51 + dab326a commit b03cde6

File tree

217 files changed

+3856
-1726
lines changed

Some content is hidden

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

217 files changed

+3856
-1726
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,11 @@ else()
10041004
add_subdirectory(stdlib/toolchain)
10051005
endif()
10061006

1007+
if (BUILD_SWIFT_CONCURRENCY_BACK_DEPLOYMENT_LIBRARIES)
1008+
# Build the back-deployed concurrency library.
1009+
add_subdirectory(stdlib/public/BackDeployConcurrency)
1010+
endif()
1011+
10071012
# Some tools (e.g. swift-reflection-dump) rely on a host swiftReflection, so
10081013
# ensure we build that when building tools.
10091014
if(SWIFT_INCLUDE_TOOLS)

cmake/modules/Libdispatch.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ foreach(sdk ${DISPATCH_SDKS})
6969
foreach(arch ${ARCHS})
7070
set(LIBDISPATCH_VARIANT_NAME "libdispatch-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
7171

72+
if(sdk MATCHES WINDOWS)
73+
set(SWIFT_LIBDISPATCH_COMPILER_TRIPLE_CMAKE_ARGS -DCMAKE_C_COMPILER_TARGET=${SWIFT_SDK_WINDOWS_ARCH_${arch}_TRIPLE};-DCMAKE_CXX_COMPILER_TARGET=${SWIFT_SDK_WINDOWS_ARCH_${arch}_TRIPLE})
74+
endif()
75+
76+
7277
if(NOT sdk STREQUAL ANDROID)
7378
set(SWIFT_LIBDISPATCH_SYSTEM_PROCESSOR -DCMAKE_SYSTEM_PROCESSOR=${arch})
7479
endif()
@@ -80,6 +85,7 @@ foreach(sdk ${DISPATCH_SDKS})
8085
-DCMAKE_AR=${CMAKE_AR}
8186
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
8287
${SWIFT_LIBDISPATCH_COMPILER_CMAKE_ARGS}
88+
${SWIFT_LIBDISPATCH_COMPILER_TRIPLE_CMAKE_ARGS}
8389
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
8490
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
8591
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}

cmake/modules/SwiftComponents.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
# The set of "defined" swift components are as follows:
4747
#
4848
# * autolink-driver -- the Swift driver support tools
49+
# * back-deployment -- Swift back-deployment libraries
4950
# * compiler -- the Swift compiler and (on supported platforms) the REPL.
5051
# * clang-builtin-headers -- install a copy of Clang builtin headers under
5152
# 'lib/swift/clang'. This is useful when Swift compiler is installed in
@@ -66,7 +67,7 @@
6667
# * toolchain-dev-tools -- install development tools useful in a shared toolchain
6768
# * dev -- headers and libraries required to use Swift compiler as a library.
6869
set(_SWIFT_DEFINED_COMPONENTS
69-
"autolink-driver;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
70+
"autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;stdlib;stdlib-experimental;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers")
7071

7172
# The default install components include all of the defined components, except
7273
# for the following exceptions.
@@ -85,6 +86,8 @@ else()
8586
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "sourcekit-xpc-service")
8687
endif()
8788
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "stdlib-experimental")
89+
# back-deployment libraries are opt-in
90+
list(REMOVE_ITEM _SWIFT_DEFAULT_COMPONENTS "back-deployment")
8891

8992
macro(swift_configure_components)
9093
# Set the SWIFT_INSTALL_COMPONENTS variable to the default value if it is not passed in via -D

include/swift/AST/ASTContext.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ class ASTContext final {
731731
/// Get the runtime availability of support for concurrency.
732732
AvailabilityContext getConcurrencyAvailability();
733733

734+
/// Get the back-deployed availability for concurrency.
735+
AvailabilityContext getBackDeployedConcurrencyAvailability();
736+
734737
/// Get the runtime availability of support for differentiation.
735738
AvailabilityContext getDifferentiationAvailability();
736739

@@ -750,6 +753,11 @@ class ASTContext final {
750753
/// compiler for the target platform.
751754
AvailabilityContext getSwift55Availability();
752755

756+
// Note: Update this function if you add a new getSwiftXYAvailability above.
757+
/// Get the runtime availability for a particular version of Swift (5.0+).
758+
AvailabilityContext
759+
getSwift5PlusAvailability(llvm::VersionTuple swiftVersion);
760+
753761
/// Get the runtime availability of features that have been introduced in the
754762
/// Swift compiler for future versions of the target platform.
755763
AvailabilityContext getSwiftFutureAvailability();

include/swift/AST/ASTMangler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class ASTMangler : public Mangler {
5757
/// to fill these in.
5858
bool AllowSymbolicReferences = false;
5959

60+
/// If enabled, allows the use of standard substitutions for types in the
61+
/// concurrency library.
62+
bool AllowConcurrencyStandardSubstitutions = true;
63+
6064
public:
6165
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,
6266
const OpaqueTypeDecl *>;

include/swift/AST/IRGenOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ class IRGenOptions {
381381
/// Pull in runtime compatibility shim libraries by autolinking.
382382
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityLibraryVersion;
383383
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion;
384+
Optional<llvm::VersionTuple>
385+
AutolinkRuntimeCompatibilityConcurrencyLibraryVersion;
384386

385387
JITDebugArtifact DumpJIT = JITDebugArtifact::None;
386388

include/swift/Demangling/ManglingUtils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ char translateOperatorChar(char op);
9999
std::string translateOperator(StringRef Op);
100100

101101
/// Returns the standard type kind for an 'S' substitution, e.g. 'i' for "Int".
102-
llvm::Optional<StringRef> getStandardTypeSubst(StringRef TypeName);
102+
///
103+
/// \param allowConcurrencyManglings When true, allows the standard
104+
/// substitutions for types in the _Concurrency module that were introduced in
105+
/// Swift 5.5.
106+
llvm::Optional<StringRef> getStandardTypeSubst(
107+
StringRef TypeName, bool allowConcurrencyManglings);
103108

104109
/// Mangles an identifier using a generic Mangler class.
105110
///

include/swift/Demangling/StandardTypesMangling.def

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
/// STANDARD_TYPE(KIND, MANGLING, TYPENAME)
1414
/// The 1-character MANGLING for a known TYPENAME of KIND.
1515
///
16-
/// STANDARD_TYPE_2(KIND, MANGLING, TYPENAME)
16+
/// STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME)
1717
/// The 1-character MANGLING for a known TYPENAME of KIND that is in the
18-
/// second level of standard types, all of which are mangled with the form
19-
/// Sc<MANGLING>.
18+
/// second level of standard types in the Concurrency model, all of which are
19+
/// mangled with the form Sc<MANGLING>.
2020
///
2121
/// OBJC_INTEROP_STANDARD_TYPE(KIND, MANGLING, TYPENAME)
2222
/// The 1-character MANGLING for a known TYPENAME of KIND, for a type that's
@@ -79,25 +79,25 @@ STANDARD_TYPE(Protocol, y, StringProtocol)
7979
STANDARD_TYPE(Protocol, Z, SignedInteger)
8080
STANDARD_TYPE(Protocol, z, BinaryInteger)
8181

82-
STANDARD_TYPE_2(Protocol, A, Actor)
83-
STANDARD_TYPE_2(Structure, C, CheckedContinuation)
84-
STANDARD_TYPE_2(Structure, c, UnsafeContinuation)
85-
STANDARD_TYPE_2(Structure, E, CancellationError)
86-
STANDARD_TYPE_2(Structure, e, UnownedSerialExecutor)
87-
STANDARD_TYPE_2(Protocol, F, Executor)
88-
STANDARD_TYPE_2(Protocol, f, SerialExecutor)
89-
STANDARD_TYPE_2(Structure, G, TaskGroup)
90-
STANDARD_TYPE_2(Structure, g, ThrowingTaskGroup)
91-
STANDARD_TYPE_2(Protocol, I, AsyncIteratorProtocol)
92-
STANDARD_TYPE_2(Protocol, i, AsyncSequence)
93-
STANDARD_TYPE_2(Structure, J, UnownedJob)
94-
STANDARD_TYPE_2(Class, M, MainActor)
95-
STANDARD_TYPE_2(Structure, P, TaskPriority)
96-
STANDARD_TYPE_2(Structure, S, AsyncStream)
97-
STANDARD_TYPE_2(Structure, s, AsyncThrowingStream)
98-
STANDARD_TYPE_2(Structure, T, Task)
99-
STANDARD_TYPE_2(Structure, t, UnsafeCurrentTask)
82+
STANDARD_TYPE_CONCURRENCY(Protocol, A, Actor)
83+
STANDARD_TYPE_CONCURRENCY(Structure, C, CheckedContinuation)
84+
STANDARD_TYPE_CONCURRENCY(Structure, c, UnsafeContinuation)
85+
STANDARD_TYPE_CONCURRENCY(Structure, E, CancellationError)
86+
STANDARD_TYPE_CONCURRENCY(Structure, e, UnownedSerialExecutor)
87+
STANDARD_TYPE_CONCURRENCY(Protocol, F, Executor)
88+
STANDARD_TYPE_CONCURRENCY(Protocol, f, SerialExecutor)
89+
STANDARD_TYPE_CONCURRENCY(Structure, G, TaskGroup)
90+
STANDARD_TYPE_CONCURRENCY(Structure, g, ThrowingTaskGroup)
91+
STANDARD_TYPE_CONCURRENCY(Protocol, I, AsyncIteratorProtocol)
92+
STANDARD_TYPE_CONCURRENCY(Protocol, i, AsyncSequence)
93+
STANDARD_TYPE_CONCURRENCY(Structure, J, UnownedJob)
94+
STANDARD_TYPE_CONCURRENCY(Class, M, MainActor)
95+
STANDARD_TYPE_CONCURRENCY(Structure, P, TaskPriority)
96+
STANDARD_TYPE_CONCURRENCY(Structure, S, AsyncStream)
97+
STANDARD_TYPE_CONCURRENCY(Structure, s, AsyncThrowingStream)
98+
STANDARD_TYPE_CONCURRENCY(Structure, T, Task)
99+
STANDARD_TYPE_CONCURRENCY(Structure, t, UnsafeCurrentTask)
100100

101101
#undef STANDARD_TYPE
102102
#undef OBJC_INTEROP_STANDARD_TYPE
103-
#undef STANDARD_TYPE_2
103+
#undef STANDARD_TYPE_CONCURRENCY

include/swift/Frontend/BackDeploymentLibs.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
2828
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
2929
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
30+
BACK_DEPLOYMENT_LIB((5, 5), all, "swiftCompatibilityConcurrency")
3031

3132
#undef BACK_DEPLOYMENT_LIB

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ def type_info_dump_filter_EQ : Joined<["-"], "type-info-dump-filter=">,
765765
Flags<[FrontendOption]>,
766766
HelpText<"One of 'all', 'resilient' or 'fragile'">;
767767

768-
769768
def emit_ldadd_cfile_path
770769
: Separate<["-"], "emit-ldadd-cfile-path">, MetaVarName<"<path>">,
771770
HelpText<"Generate .c file defining symbols to add back">;

include/swift/Option/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,12 @@ def disable_autolinking_runtime_compatibility_dynamic_replacements
12061206
HelpText<"Do not use autolinking for the dynamic replacement runtime "
12071207
"compatibility library">;
12081208

1209+
def disable_autolinking_runtime_compatibility_concurrency
1210+
: Flag<[ "-" ], "disable-autolinking-runtime-compatibility-concurrency">,
1211+
Flags<[ FrontendOption ]>,
1212+
HelpText<"Do not use autolinking for the concurrency runtime "
1213+
"compatibility library">;
1214+
12091215
def emit_symbol_graph: Flag<["-"], "emit-symbol-graph">,
12101216
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
12111217
HelpText<"Emit a symbol graph">;

include/swift/Runtime/Exclusivity.h

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,6 @@ SWIFT_RUNTIME_EXPORT
4040
void swift_beginAccess(void *pointer, ValueBuffer *buffer,
4141
ExclusivityFlags flags, void *pc);
4242

43-
/// Loads the replacement function pointer from \p ReplFnPtr and returns the
44-
/// replacement function if it should be called.
45-
/// Returns null if the original function (which is passed in \p CurrFn) should
46-
/// be called.
47-
#ifdef __APPLE__
48-
__attribute__((weak_import))
49-
#endif
50-
SWIFT_RUNTIME_EXPORT
51-
char *swift_getFunctionReplacement(char **ReplFnPtr, char *CurrFn);
52-
53-
/// Returns the original function of a replaced function, which is loaded from
54-
/// \p OrigFnPtr.
55-
/// This function is called from a replacement function to call the original
56-
/// function.
57-
#ifdef __APPLE__
58-
__attribute__((weak_import))
59-
#endif
60-
SWIFT_RUNTIME_EXPORT
61-
char *swift_getOrigOfReplaceable(char **OrigFnPtr);
6243

6344
/// Stop dynamically tracking an access.
6445
SWIFT_RUNTIME_EXPORT
@@ -91,6 +72,13 @@ void swift_dumpTrackedAccesses();
9172

9273
#endif
9374

75+
// When building the concurrency library for back deployment, we rename these
76+
// symbols unformly so they don't conflict with the real concurrency library.
77+
#ifdef SWIFT_CONCURRENCY_BACK_DEPLOYMENT
78+
# define swift_task_enterThreadLocalContext swift_task_enterThreadLocalContextBackDeploy
79+
# define swift_task_exitThreadLocalContext swift_task_exitThreadLocalContextBackDeploy
80+
#endif
81+
9482
/// Called when a task inits, resumes and returns control to caller synchronous
9583
/// code to update any exclusivity specific state associated with the task.
9684
///
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- FunctionReplacement.h --------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 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+
#ifndef SWIFT_RUNTIME_FUNCTIONREPLACEMENT_H
14+
#define SWIFT_RUNTIME_FUNCTIONREPLACEMENT_H
15+
16+
#include "swift/Runtime/Config.h"
17+
18+
namespace swift {
19+
20+
/// Loads the replacement function pointer from \p ReplFnPtr and returns the
21+
/// replacement function if it should be called.
22+
/// Returns null if the original function (which is passed in \p CurrFn) should
23+
/// be called.
24+
#ifdef __APPLE__
25+
__attribute__((weak_import))
26+
#endif
27+
SWIFT_RUNTIME_EXPORT char *
28+
swift_getFunctionReplacement(char **ReplFnPtr, char *CurrFn);
29+
30+
/// Returns the original function of a replaced function, which is loaded from
31+
/// \p OrigFnPtr.
32+
/// This function is called from a replacement function to call the original
33+
/// function.
34+
#ifdef __APPLE__
35+
__attribute__((weak_import))
36+
#endif
37+
SWIFT_RUNTIME_EXPORT char *
38+
swift_getOrigOfReplaceable(char **OrigFnPtr);
39+
40+
} // namespace swift
41+
42+
#endif

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,24 @@ FUNCTION(GetFunctionMetadataGlobalActor,
610610
TypeMetadataPtrTy),
611611
ATTRS(NoUnwind, ReadOnly))
612612

613+
// Metadata *
614+
// swift_getFunctionTypeMetadataGlobalActorBackDeploy(unsigned long flags,
615+
// unsigned long diffKind,
616+
// const Metadata **parameters,
617+
// const uint32_t *parameterFlags,
618+
// const Metadata *result,
619+
// const Metadata *globalActor);
620+
FUNCTION(GetFunctionMetadataGlobalActorBackDeploy,
621+
swift_getFunctionTypeMetadataGlobalActorBackDeploy,
622+
C_CC, OpaqueTypeAvailability,
623+
RETURNS(TypeMetadataPtrTy),
624+
ARGS(SizeTy,
625+
SizeTy,
626+
TypeMetadataPtrTy->getPointerTo(0),
627+
Int32Ty->getPointerTo(0),
628+
TypeMetadataPtrTy,
629+
TypeMetadataPtrTy),
630+
ATTRS(NoUnwind, ReadOnly))
613631

614632
// Metadata *swift_getFunctionTypeMetadata0(unsigned long flags,
615633
// const Metadata *resultMetadata);

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2935,7 +2935,8 @@ bool ASTMangler::tryAppendStandardSubstitution(const GenericTypeDecl *decl) {
29352935
return false;
29362936

29372937
if (isa<NominalTypeDecl>(decl)) {
2938-
if (auto Subst = getStandardTypeSubst(decl->getName().str())) {
2938+
if (auto Subst = getStandardTypeSubst(
2939+
decl->getName().str(), AllowConcurrencyStandardSubstitutions)) {
29392940
if (!SubstMerging.tryMergeSubst(*this, *Subst, /*isStandardSubst*/ true)){
29402941
appendOperator("S", *Subst);
29412942
}

lib/AST/Availability.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ AvailabilityContext ASTContext::getConcurrencyAvailability() {
330330
return getSwift55Availability();
331331
}
332332

333+
AvailabilityContext ASTContext::getBackDeployedConcurrencyAvailability() {
334+
return getSwift51Availability();
335+
}
336+
333337
AvailabilityContext ASTContext::getDifferentiationAvailability() {
334338
return getSwiftFutureAvailability();
335339
}
@@ -446,3 +450,20 @@ AvailabilityContext ASTContext::getSwiftFutureAvailability() {
446450
return AvailabilityContext::alwaysAvailable();
447451
}
448452
}
453+
454+
AvailabilityContext
455+
ASTContext::getSwift5PlusAvailability(llvm::VersionTuple swiftVersion) {
456+
if (swiftVersion.getMajor() == 5) {
457+
switch (*swiftVersion.getMinor()) {
458+
case 0: return getSwift50Availability();
459+
case 1: return getSwift51Availability();
460+
case 2: return getSwift52Availability();
461+
case 3: return getSwift53Availability();
462+
case 4: return getSwift54Availability();
463+
case 5: return getSwift55Availability();
464+
default: break;
465+
}
466+
}
467+
llvm::report_fatal_error("Missing call to getSwiftXYAvailability for Swift " +
468+
swiftVersion.getAsString());
469+
}

0 commit comments

Comments
 (0)