Skip to content

Commit 8441871

Browse files
committed
[concurrency] Implement a compatibility .a library for Concurrency.
In a back deployment scenario, this will provide a place where one could provide function implementations that are not available in the relevant stdlib. This is just setting up for future work and isn't doing anything interesting beyond wiring it up/making sure that it is wired up correctly with tests.
1 parent 35aa862 commit 8441871

File tree

15 files changed

+105
-6
lines changed

15 files changed

+105
-6
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ class IRGenOptions {
370370
/// Pull in runtime compatibility shim libraries by autolinking.
371371
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityLibraryVersion;
372372
Optional<llvm::VersionTuple> AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion;
373+
Optional<llvm::VersionTuple>
374+
AutolinkRuntimeCompatibilityConcurrencyLibraryVersion;
373375

374376
JITDebugArtifact DumpJIT = JITDebugArtifact::None;
375377

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/Options.td

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

1231+
def disable_autolinking_runtime_compatibility_concurrency
1232+
: Flag<[ "-" ], "disable-autolinking-runtime-compatibility-concurrency">,
1233+
Flags<[ FrontendOption ]>,
1234+
HelpText<"Do not use autolinking for the concurrency runtime "
1235+
"compatibility library">;
1236+
12311237
def emit_symbol_graph: Flag<["-"], "emit-symbol-graph">,
12321238
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput, HelpHidden]>,
12331239
HelpText<"Emit a symbol graph">;

lib/Driver/DarwinToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments,
409409
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
410410
} else if (value.equals("5.1")) {
411411
runtimeCompatibilityVersion = llvm::VersionTuple(5, 1);
412+
} else if (value.equals("5.5")) {
413+
runtimeCompatibilityVersion = llvm::VersionTuple(5, 5);
412414
} else if (value.equals("none")) {
413415
runtimeCompatibilityVersion = None;
414416
} else {

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ ToolChain::constructInvocation(const CompileJobAction &job,
560560
options::OPT_disable_autolinking_runtime_compatibility)) {
561561
Arguments.push_back("-disable-autolinking-runtime-compatibility");
562562
}
563-
563+
564564
if (auto arg = context.Args.getLastArg(
565565
options::OPT_runtime_compatibility_version)) {
566566
Arguments.push_back("-runtime-compatibility-version");
@@ -581,6 +581,9 @@ ToolChain::constructInvocation(const CompileJobAction &job,
581581
Arguments,
582582
options::
583583
OPT_disable_autolinking_runtime_compatibility_dynamic_replacements);
584+
context.Args.AddLastArg(
585+
Arguments,
586+
options::OPT_disable_autolinking_runtime_compatibility_concurrency);
584587

585588
if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
586589
context.Args.AddLastArg(Arguments, options::OPT_emit_symbol_graph);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
18361836
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
18371837
} else if (version.equals("5.1")) {
18381838
runtimeCompatibilityVersion = llvm::VersionTuple(5, 1);
1839+
} else if (version.equals("5.5")) {
1840+
runtimeCompatibilityVersion = llvm::VersionTuple(5, 5);
18391841
} else {
18401842
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
18411843
versionArg->getAsString(Args), version);
@@ -1858,6 +1860,12 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
18581860
getRuntimeCompatVersion();
18591861
}
18601862

1863+
if (!Args.hasArg(
1864+
options::OPT_disable_autolinking_runtime_compatibility_concurrency)) {
1865+
Opts.AutolinkRuntimeCompatibilityConcurrencyLibraryVersion =
1866+
getRuntimeCompatVersion();
1867+
}
1868+
18611869
if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
18621870
if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
18631871
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,

lib/IRGen/GenDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,9 @@ void IRGenModule::emitSourceFile(SourceFile &SF) {
485485
if (libraryName == "swiftCompatibilityDynamicReplacements") {
486486
compatibilityVersion = IRGen.Opts.
487487
AutolinkRuntimeCompatibilityDynamicReplacementLibraryVersion;
488+
} else if (libraryName == "swiftCompatibilityConcurrency") {
489+
compatibilityVersion =
490+
IRGen.Opts.AutolinkRuntimeCompatibilityConcurrencyLibraryVersion;
488491
} else {
489492
compatibilityVersion = IRGen.Opts.
490493
AutolinkRuntimeCompatibilityLibraryVersion;

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ function(_compile_swift_files
459459
if (SWIFTFILE_IS_STDLIB OR SWIFTFILE_IS_SDK_OVERLAY)
460460
list(APPEND swift_flags "-runtime-compatibility-version" "none")
461461
list(APPEND swift_flags "-disable-autolinking-runtime-compatibility-dynamic-replacements")
462+
list(APPEND swift_flags "-Xfrontend" "-disable-autolinking-runtime-compatibility-concurrency")
462463
endif()
463464

464465
if (SWIFTFILE_IS_STDLIB_CORE OR SWIFTFILE_IS_SDK_OVERLAY)

stdlib/toolchain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ add_subdirectory(legacy_layouts)
5454
add_subdirectory(Compatibility50)
5555
add_subdirectory(Compatibility51)
5656
add_subdirectory(CompatibilityDynamicReplacements)
57+
add_subdirectory(CompatibilityConcurrency)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
set(library_name "swiftCompatibilityConcurrency")
2+
3+
add_swift_target_library("${library_name}" STATIC
4+
CompatibilityConcurrency.cpp
5+
6+
TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
7+
8+
C_COMPILE_FLAGS ${CXX_COMPILE_FLAGS}
9+
LINK_FLAGS ${CXX_LINK_FLAGS}
10+
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
11+
DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX}
12+
DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS}
13+
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
14+
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
15+
16+
INSTALL_IN_COMPONENT compiler
17+
INSTALL_WITH_SHARED)
18+
19+
# FIXME: We need a more flexible mechanism to add lipo targets generated by
20+
# add_swift_target_library to the ALL target. Until then this hack is necessary
21+
# to ensure these libraries build.
22+
foreach(sdk ${SWIFT_SDKS})
23+
set(target_name "${library_name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
24+
if(NOT TARGET "${target_name}")
25+
continue()
26+
endif()
27+
28+
set_target_properties("${target_name}"
29+
PROPERTIES
30+
EXCLUDE_FROM_ALL FALSE)
31+
endforeach()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--- CompatibilityConcurrency.cpp -------------------------------------===//
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+
// Allow this library to get force-loaded by autolinking
14+
__attribute__((weak, visibility("hidden"))) extern "C" char
15+
_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency = 0;

test/Driver/print_target_info.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
// CHECK-IOS: "libraryName": "swiftCompatibility51",
2626
// CHECK-IOS: "libraryName": "swiftCompatibilityDynamicReplacements"
2727
// CHECK-IOS: "filter": "executable"
28+
// CHECK-IOS: "libraryName": "swiftCompatibilityConcurrency"
29+
// CHECK-IOS: "filter": "all"
2830
// CHECK-IOS: ],
2931
// CHECK-IOS: "librariesRequireRPath": true
3032
// CHECK-IOS: }

test/IRGen/autolink-runtime-compatibility.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// REQUIRES: OS=macosx,CPU=x86_64
22

33
// Doesn't autolink compatibility library because autolinking is disabled
4-
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -target %target-cpu-apple-macosx10.9 -disable-autolinking-runtime-compatibility -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=NO-FORCE-LOAD %s
5-
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version 5.0 -disable-autolinking-runtime-compatibility -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=NO-FORCE-LOAD %s
4+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -target %target-cpu-apple-macosx10.9 -disable-autolinking-runtime-compatibility -disable-autolinking-runtime-compatibility-concurrency -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=NO-FORCE-LOAD %s
5+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version 5.0 -disable-autolinking-runtime-compatibility -disable-autolinking-runtime-compatibility-concurrency -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=NO-FORCE-LOAD %s
66

77
// Doesn't autolink compatibility library because runtime compatibility library is disabled
88
// RUN: %target-swift-frontend -runtime-compatibility-version none -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=NO-FORCE-LOAD %s
@@ -16,29 +16,49 @@
1616
// Autolinks because compatibility library was explicitly asked for
1717
// RUN: %target-swift-frontend -runtime-compatibility-version 5.0 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD %s
1818
// RUN: %target-swift-frontend -runtime-compatibility-version 5.1 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s
19+
// RUN: %target-swift-frontend -runtime-compatibility-version 5.5 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-55 %s
1920
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.24 -runtime-compatibility-version 5.0 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD %s
2021
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.24 -runtime-compatibility-version 5.1 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-51 %s
22+
// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.24 -runtime-compatibility-version 5.5 -emit-ir -parse-stdlib %s | %FileCheck -check-prefix=FORCE-LOAD-55 %s
2123

2224
public func foo() {}
2325

2426
// NO-FORCE-LOAD-NOT: FORCE_LOAD
2527
// NO-FORCE-LOAD-NOT: !{!"-lswiftCompatibility50"}
2628
// NO-FORCE-LOAD-NOT: !{!"-lswiftCompatibility51"}
2729
// NO-FORCE-LOAD-NOT: !{!"-lswiftCompatibilityDynamicReplacements"}
30+
// NO-FORCE-LOAD-NOT: !{!"-lswiftCompatibilityConcurrency"}
2831

2932
// FORCE-LOAD: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibility50"
3033
// FORCE-LOAD: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
34+
// FORCE-LOAD: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
3135
// FORCE-LOAD-DAG: [[AUTOLINK_SWIFT_COMPAT:![0-9]+]] = !{!"-lswiftCompatibility50"}
3236
// FORCE-LOAD-DAG: !{!"-lswiftCompatibility51"}
3337
// FORCE-LOAD-DAG: !{!"-lswiftCompatibilityDynamicReplacements"}
38+
// FORCE-LOAD-DAG: !{!"-lswiftCompatibilityConcurrency"}
3439
// FORCE-LOAD-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT]]{{[,}]}}
3540

3641
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
3742
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
38-
// FORCE-LOAD-51: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibility51"
43+
// FORCE-LOAD-51-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibility51"
44+
// FORCE-LOAD-51-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
3945
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
4046
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
4147
// FORCE-LOAD-51-DAG: [[AUTOLINK_SWIFT_COMPAT:![0-9]+]] = !{!"-lswiftCompatibility51"}
42-
// FORCE-LOAD-51-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT]]{{[,}]}}
48+
// FORCE-LOAD-51-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
49+
// FORCE-LOAD-51-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT]], {{.*}}[[AUTOLINK_SWIFT_COMPAT_CONCURRENCY]]{{[,}]}}
4350
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
4451
// FORCE-LOAD-51-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
52+
53+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
54+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
55+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
56+
// FORCE-LOAD-55-DAG: declare {{.*}} @"_swift_FORCE_LOAD_$_swiftCompatibilityConcurrency"
57+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
58+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
59+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"
60+
// FORCE-LOAD-55-DAG: [[AUTOLINK_SWIFT_COMPAT_CONCURRENCY:![0-9]+]] = !{!"-lswiftCompatibilityConcurrency"}
61+
// FORCE-LOAD-55-DAG: !llvm.linker.options = !{{{.*}}[[AUTOLINK_SWIFT_COMPAT_CONCURRENCY]]{{[,}]}}
62+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility50"
63+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"
64+
// FORCE-LOAD-55-NOT: @"_swift_FORCE_LOAD_$_swiftCompatibility51"

test/IRGen/unused.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -primary-file %s -emit-ir | %FileCheck -check-prefix CHECK -check-prefix NEGATIVE -check-prefix CHECK-%target-object-format %s
1+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-concurrency -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -primary-file %s -emit-ir | %FileCheck -check-prefix CHECK -check-prefix NEGATIVE -check-prefix CHECK-%target-object-format %s
22

33
// REQUIRES: CPU=x86_64
44

test/Serialization/autolinking.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -parse-stdlib -o %t -module-name someModule -module-link-name module %S/../Inputs/empty.swift
33
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -emit-ir -lmagic %s -I %t > %t/out.txt
4+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-concurrency -runtime-compatibility-version none -emit-ir -lmagic %s -I %t > %t/out.txt
45
// RUN: %FileCheck %s < %t/out.txt
56
// RUN: %FileCheck -check-prefix=NO-FORCE-LOAD %s < %t/out.txt
67

78
// RUN: %empty-directory(%t/someModule.framework/Modules/someModule.swiftmodule)
89
// RUN: mv %t/someModule.swiftmodule %t/someModule.framework/Modules/someModule.swiftmodule/%target-swiftmodule-name
910
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -emit-ir -lmagic %s -F %t > %t/framework.txt
11+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-concurrency -runtime-compatibility-version none -emit-ir -lmagic %s -F %t > %t/framework.txt
1012
// RUN: %FileCheck -check-prefix=FRAMEWORK %s < %t/framework.txt
1113
// RUN: %FileCheck -check-prefix=NO-FORCE-LOAD %s < %t/framework.txt
1214

@@ -19,11 +21,13 @@
1921
// RUN: %FileCheck -check-prefix NO-FORCE-LOAD-CLIENT %s < %t/force-load.txt
2022

2123
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift | %FileCheck --check-prefix=NO-FORCE-LOAD %s
24+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-concurrency -runtime-compatibility-version none -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift | %FileCheck --check-prefix=NO-FORCE-LOAD %s
2225
// RUN: %target-swift-frontend -runtime-compatibility-version none -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift -autolink-force-load | %FileCheck --check-prefix=FORCE-LOAD %s
2326
// RUN: %target-swift-frontend -runtime-compatibility-version none -emit-ir -parse-stdlib -module-name someModule -module-link-name 0module %S/../Inputs/empty.swift -autolink-force-load | %FileCheck --check-prefix=FORCE-LOAD-HEX %s
2427

2528
// RUN: %target-swift-frontend -emit-module -parse-stdlib -o %t -module-name someModule -module-link-name module %S/../Inputs/empty.swift -public-autolink-library anotherLib
2629
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-dynamic-replacements -runtime-compatibility-version none -emit-ir -lmagic %s -I %t > %t/public-autolink.txt
30+
// RUN: %target-swift-frontend -disable-autolinking-runtime-compatibility-concurrency -runtime-compatibility-version none -emit-ir -lmagic %s -I %t > %t/public-autolink.txt
2731
// RUN: %FileCheck %s < %t/public-autolink.txt
2832
// RUN: %FileCheck -check-prefix=PUBLIC-DEP %s < %t/public-autolink.txt
2933

0 commit comments

Comments
 (0)