Skip to content

Commit 6ed794d

Browse files
committed
Bake the _Concurrency -> Swift ABI module name into the compiler.
Using `-module-abi-name` for the `_Concurrency` module breaks older Swift compilers. Instead, hard-code that "Swift" is the ABI name of the "_Concurrency" module in the compiler to dodge the problem.
1 parent eeffb07 commit 6ed794d

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

include/swift/AST/Module.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
167167
friend class DirectPrecedenceGroupLookupRequest;
168168

169169
/// The ABI name of the module, if it differs from the module name.
170-
Identifier ModuleABIName;
170+
mutable Identifier ModuleABIName;
171171

172172
public:
173173
/// Produces the components of a given module's full name in reverse order.
@@ -348,9 +348,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
348348

349349
/// Retrieve the ABI name of the module, which is used for metadata and
350350
/// mangling.
351-
Identifier getABIName() const {
352-
return ModuleABIName.empty() ? getName() : ModuleABIName;
353-
}
351+
Identifier getABIName() const;
354352

355353
/// Set the ABI name of the module;
356354
void setABIName(Identifier name) {

lib/AST/Module.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,22 @@ ImportedModule::removeDuplicates(SmallVectorImpl<ImportedModule> &imports) {
13561356
imports.erase(last, imports.end());
13571357
}
13581358

1359+
Identifier ModuleDecl::getABIName() const {
1360+
if (!ModuleABIName.empty())
1361+
return ModuleABIName;
1362+
1363+
// Hard code that the _Concurrency module has Swift as its ABI name.
1364+
// FIXME: This works around a backward-compatibility issue where
1365+
// -module-abi-name is not supported on existing Swift compilers. Remove
1366+
// this hack later and pass -module-abi-name when building the _Concurrency
1367+
// module.
1368+
if (getName().str() == SWIFT_CONCURRENCY_NAME) {
1369+
ModuleABIName = getASTContext().getIdentifier(STDLIB_NAME);
1370+
return ModuleABIName;
1371+
}
1372+
1373+
return getName();
1374+
}
13591375

13601376
StringRef ModuleDecl::getModuleFilename() const {
13611377
// FIXME: Audit uses of this function and figure out how to migrate them to

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
8383
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
8484
-parse-stdlib
8585
-Xfrontend -enable-experimental-concurrency
86-
-module-abi-name Swift
8786
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
8887
INSTALL_IN_COMPONENT stdlib
8988
)

test/IRGen/module_abi_name.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
// CHECK-NOT: {{(5|")Hello}}
44

5-
// CHECK-DAG: [[MODULE_NAME:@.*]] = private constant [8 x i8] c"Goodbye\00"
6-
// CHECK-DAG: @"$s7GoodbyeMXM" = {{.*}} [[MODULE_NAME]]
7-
8-
// CHECK-DAG: @"$s7Goodbye8GreetingCMm" =
5+
// CHECK: [[MODULE_NAME:@.*]] = private constant [8 x i8] c"Goodbye\00"
6+
// CHECK: @"$s7GoodbyeMXM" = {{.*}} [[MODULE_NAME]]
7+
// CHECK: @"$s7Goodbye8GreetingCMn" =
98
public class Greeting { }
109

10+
11+
1112
// CHECK-NOT: {{(5|")Hello}}
12-
// CHECK: define swiftcc void @"$s7Goodbye8functionyyF"()
13+
// CHECK: define {{.*}} @"$s7Goodbye8functionyyF"
1314
@inlinable public func function() { }
1415

1516
func callFunction() {

0 commit comments

Comments
 (0)