Skip to content

Commit 14dfa83

Browse files
authored
Merge pull request #3742 from swiftwasm/main
[pull] swiftwasm from main
2 parents 4646bc7 + 936ed1f commit 14dfa83

22 files changed

+616
-208
lines changed

include/swift/AST/FileUnit.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
288288
return nullptr;
289289
}
290290

291-
/// Returns the name to use when referencing entities in this file.
291+
/// Returns the real name of the enclosing module to use when referencing entities in this file.
292+
/// The 'real name' is the actual binary name of the module, which can be different from the 'name'
293+
/// if module aliasing was used (via -module-alias flag).
292294
///
293-
/// Usually this is the module name itself, but certain Clang features allow
295+
/// Usually this is the module real name itself, but certain Clang features allow
294296
/// substituting another name instead.
295297
virtual StringRef getExportedModuleName() const {
296-
return getParentModule()->getName().str();
298+
return getParentModule()->getRealName().str();
297299
}
298300

299301
/// Traverse the decls within this file.

include/swift/AST/Module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class ModuleDecl
176176
///
177177
/// For a Swift module, this will only ever have one component, but an
178178
/// imported Clang module might actually be a submodule.
179+
///
180+
/// *Note: see `StringRef operator*()` for details on the returned name for printing
181+
/// for a Swift module.
179182
class ReverseFullNameIterator {
180183
public:
181184
// Make this look like a valid STL iterator.
@@ -194,6 +197,9 @@ class ModuleDecl
194197
current = clangModule;
195198
}
196199

200+
/// Returns the name of the current module.
201+
/// Note that for a Swift module, it returns the current module's real (binary) name,
202+
/// which can be different from the name if module aliasing was used (see `-module-alias`).
197203
StringRef operator*() const;
198204
ReverseFullNameIterator &operator++();
199205

@@ -208,6 +214,9 @@ class ModuleDecl
208214

209215
/// This is a convenience function that writes the entire name, in forward
210216
/// order, to \p out.
217+
///
218+
/// It calls `StringRef operator*()` under the hood (see for more detail on the
219+
/// returned name for a Swift module).
211220
void printForward(raw_ostream &out, StringRef delim = ".") const;
212221
};
213222

@@ -802,6 +811,9 @@ class ModuleDecl
802811
///
803812
/// For a Swift module, this will only ever have one component, but an
804813
/// imported Clang module might actually be a submodule.
814+
///
815+
/// *Note: see `StringRef operator*()` for details on the returned name for printing
816+
/// for a Swift module.
805817
ReverseFullNameIterator getReverseFullModuleName() const {
806818
return ReverseFullNameIterator(this);
807819
}

include/swift/ClangImporter/ClangModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ClangModuleUnit final : public LoadedFile {
5959
ModuleDecl *getOverlayModule() const override;
6060

6161
/// Retrieve the "exported" name of the module, which is usually the module
62-
/// name, but might be the name of the public module through which this
62+
/// real name, but might be the name of the public module through which this
6363
/// (private) module is re-exported.
6464
StringRef getExportedModuleName() const override;
6565

lib/AST/ASTPrinter.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,13 +2338,16 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
23382338
llvm::interleave(decl->getImportPath(),
23392339
[&](const ImportPath::Element &Elem) {
23402340
if (!Mods.empty()) {
2341-
Identifier Name = Elem.Item;
2341+
// Should print the module real name in case module
2342+
// aliasing is used (see -module-alias), since that's
2343+
// the actual binary name.
2344+
Identifier Name = decl->getASTContext().getRealModuleName(Elem.Item);
23422345
if (Options.MapCrossImportOverlaysToDeclaringModule) {
23432346
if (auto *MD = Mods.front().getAsSwiftModule()) {
23442347
ModuleDecl *Declaring = const_cast<ModuleDecl*>(MD)
23452348
->getDeclaringModuleIfCrossImportOverlay();
23462349
if (Declaring)
2347-
Name = Declaring->getName();
2350+
Name = Declaring->getRealName();
23482351
}
23492352
}
23502353
Printer.printModuleRef(Mods.front(), Name);
@@ -4322,7 +4325,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
43224325
Mod = Declaring;
43234326
}
43244327

4325-
Identifier Name = Mod->getName();
4328+
// Should use the module real (binary) name here and everywhere else the
4329+
// module is printed in case module aliasing is used (see -module-alias)
4330+
Identifier Name = Mod->getRealName();
43264331
if (Options.UseExportedModuleNames && !ExportedModuleName.empty()) {
43274332
Name = Mod->getASTContext().getIdentifier(ExportedModuleName);
43284333
}
@@ -4343,7 +4348,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
43434348
bool isLLDBExpressionModule(ModuleDecl *M) {
43444349
if (!M)
43454350
return false;
4346-
return M->getName().str().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX);
4351+
return M->getRealName().str().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX);
43474352
}
43484353

43494354
bool shouldPrintFullyQualified(TypeBase *T) {
@@ -4374,7 +4379,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
43744379

43754380
// Don't print qualifiers for types from the standard library.
43764381
if (M->isStdlibModule() ||
4377-
M->getName() == M->getASTContext().Id_ObjectiveC ||
4382+
M->getRealName() == M->getASTContext().Id_ObjectiveC ||
43784383
M->isSystemModule() ||
43794384
isLLDBExpressionModule(M))
43804385
return false;
@@ -4637,7 +4642,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
46374642

46384643
void visitModuleType(ModuleType *T) {
46394644
Printer << "module<";
4640-
Printer.printModuleRef(T->getModule(), T->getModule()->getName());
4645+
// Should print the module real name in case module aliasing is
4646+
// used (see -module-alias), since that's the actual binary name.
4647+
Printer.printModuleRef(T->getModule(), T->getModule()->getRealName());
46414648
Printer << ">";
46424649
}
46434650

@@ -5697,13 +5704,13 @@ void ProtocolConformance::printName(llvm::raw_ostream &os,
56975704
case ProtocolConformanceKind::Normal: {
56985705
auto normal = cast<NormalProtocolConformance>(this);
56995706
os << normal->getProtocol()->getName()
5700-
<< " module " << normal->getDeclContext()->getParentModule()->getName();
5707+
<< " module " << normal->getDeclContext()->getParentModule()->getRealName();
57015708
break;
57025709
}
57035710
case ProtocolConformanceKind::Self: {
57045711
auto self = cast<SelfProtocolConformance>(this);
57055712
os << self->getProtocol()->getName()
5706-
<< " module " << self->getDeclContext()->getParentModule()->getName();
5713+
<< " module " << self->getDeclContext()->getParentModule()->getRealName();
57075714
break;
57085715
}
57095716
case ProtocolConformanceKind::Specialized: {

lib/AST/Module.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,11 @@ ModuleDecl::ReverseFullNameIterator::ReverseFullNameIterator(
14991499

15001500
StringRef ModuleDecl::ReverseFullNameIterator::operator*() const {
15011501
assert(current && "all name components exhausted");
1502-
1502+
// Return the module's real (binary) name, which can be different from
1503+
// the name if module aliasing was used (-module-alias flag). The real
1504+
// name is used for serialization and loading.
15031505
if (auto *swiftModule = current.dyn_cast<const ModuleDecl *>())
1504-
return swiftModule->getName().str();
1506+
return swiftModule->getRealName().str();
15051507

15061508
auto *clangModule =
15071509
static_cast<const clang::Module *>(current.get<const void *>());

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3623,7 +3623,8 @@ StringRef ClangModuleUnit::getExportedModuleName() const {
36233623
if (clangModule && !clangModule->ExportAsModule.empty())
36243624
return clangModule->ExportAsModule;
36253625

3626-
return getParentModule()->getName().str();
3626+
// Return module real name (see FileUnit::getExportedModuleName)
3627+
return getParentModule()->getRealName().str();
36273628
}
36283629

36293630
ModuleDecl *ClangModuleUnit::getOverlayModule() const {

lib/Serialization/Serialization.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,10 @@ IdentifierID Serializer::addModuleRef(const ModuleDecl *module) {
755755
return CURRENT_MODULE_ID;
756756
if (module == this->M->getASTContext().TheBuiltinModule)
757757
return BUILTIN_MODULE_ID;
758+
// Use module 'real name', which can be different from 'name'
759+
// in case module aliasing was used (-module-alias flag)
758760
auto moduleName =
759-
module->getASTContext().getIdentifier(module->getName().str());
761+
module->getASTContext().getIdentifier(module->getRealName().str());
760762
return addDeclBaseNameRef(moduleName);
761763
}
762764

@@ -965,7 +967,9 @@ void Serializer::writeHeader(const SerializationOptions &options) {
965967
control_block::RevisionLayout Revision(Out);
966968
control_block::IsOSSALayout IsOSSA(Out);
967969

968-
ModuleName.emit(ScratchRecord, M->getName().str());
970+
// Write module 'real name', which can be different from 'name'
971+
// in case module aliasing is used (-module-alias flag)
972+
ModuleName.emit(ScratchRecord, M->getRealName().str());
969973

970974
SmallString<32> versionStringBuf;
971975
llvm::raw_svector_ostream versionString(versionStringBuf);
@@ -1105,6 +1109,8 @@ void Serializer::writeHeader(const SerializationOptions &options) {
11051109
static void flattenImportPath(const ImportedModule &import,
11061110
SmallVectorImpl<char> &out) {
11071111
llvm::raw_svector_ostream outStream(out);
1112+
// This will write the module 'real name', which can be different
1113+
// from the 'name' in case module aliasing was used (see `-module-alias`)
11081114
import.importedModule->getReverseFullModuleName().printForward(
11091115
outStream, StringRef("\0", 1));
11101116

stdlib/public/Concurrency/linker-support/magic-symbols-for-install-name.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@
124124
RPATH_INSTALL_NAME_DIRECTIVE(11, 4)
125125
RPATH_INSTALL_NAME_DIRECTIVE(11, 5)
126126
RPATH_INSTALL_NAME_DIRECTIVE(11, 6)
127+
128+
// Link against @rpath/libswift_Concurrency.dylib for macCatalyst < 15.0.
129+
SWIFT_RUNTIME_EXPORT const char ld_previous_macCatalyst
130+
__asm("$ld$previous$@rpath/libswift_Concurrency.dylib$$6$1.0$15.0$");
131+
132+
const char ld_previous_macCatalyst = 0;
127133
#else
128134
#error Unknown target.
129135
#endif

test/Concurrency/Backdeploy/linking.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
// RUN: otool -L %t/linking_rpath | %FileCheck -check-prefix CHECK-RPATH %s
88
// RUN: otool -L %t/linking_rpath_old | %FileCheck -check-prefix CHECK-RPATH %s
99

10+
// RUN: %target-build-swift -disable-autolinking-runtime-compatibility-concurrency -target x86_64-apple-ios15.0-macabi %s -o %t/linking_direct
11+
// RUN: %target-build-swift -disable-autolinking-runtime-compatibility-concurrency -target x86_64-apple-ios14.0-macabi %s -o %t/linking_rpath
12+
13+
// RUN: otool -L %t/linking_direct | %FileCheck -check-prefix CHECK-DIRECT %s
14+
// RUN: otool -L %t/linking_rpath | %FileCheck -check-prefix CHECK-RPATH %s
15+
1016
// REQUIRES: OS=macosx
1117
// REQUIRES: CPU=x86_64
1218

test/Frontend/load-module-with-alias-chained-simple.swift

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/Frontend/load-module-with-alias-chained1.swift

Lines changed: 0 additions & 70 deletions
This file was deleted.

test/Frontend/load-module-with-alias-chained2.swift

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)