Skip to content

Commit 7f5c569

Browse files
authored
Merge pull request swiftlang#36405 from DougGregor/mangle-module-abi-name-concurrency
2 parents 937bfd9 + 6ed794d commit 7f5c569

File tree

62 files changed

+205
-86
lines changed

Some content is hidden

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

62 files changed

+205
-86
lines changed

include/swift/AST/Module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class ModuleDecl : public DeclContext, public TypeDecl {
166166
friend class DirectOperatorLookupRequest;
167167
friend class DirectPrecedenceGroupLookupRequest;
168168

169+
/// The ABI name of the module, if it differs from the module name.
170+
mutable Identifier ModuleABIName;
171+
169172
public:
170173
/// Produces the components of a given module's full name in reverse order.
171174
///
@@ -343,6 +346,15 @@ class ModuleDecl : public DeclContext, public TypeDecl {
343346
void getDeclaredCrossImportBystanders(
344347
SmallVectorImpl<Identifier> &bystanderNames);
345348

349+
/// Retrieve the ABI name of the module, which is used for metadata and
350+
/// mangling.
351+
Identifier getABIName() const;
352+
353+
/// Set the ABI name of the module;
354+
void setABIName(Identifier name) {
355+
ModuleABIName = name;
356+
}
357+
346358
private:
347359
/// A cache of this module's underlying module and required bystander if it's
348360
/// an underscored cross-import overlay.

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ class FrontendOptions {
4848
/// An Objective-C header to import and make implicitly visible.
4949
std::string ImplicitObjCHeaderPath;
5050

51-
/// The name of the module which the frontend is building.
51+
/// The name of the module that the frontend is building.
5252
std::string ModuleName;
5353

54+
/// The ABI name of the module that the frontend is building, to be used in
55+
/// mangling and metadata.
56+
std::string ModuleABIName;
57+
5458
/// The name of the library to link against when using this module.
5559
std::string ModuleLinkName;
5660

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ def module_link_name_EQ : Joined<["-"], "module-link-name=">,
421421
def autolink_force_load : Flag<["-"], "autolink-force-load">,
422422
Flags<[FrontendOption, ModuleInterfaceOption, HelpHidden]>,
423423
HelpText<"Force ld to link against this module even if no symbols are used">;
424+
def module_abi_name : Separate<["-"], "module-abi-name">,
425+
Flags<[FrontendOption, ModuleInterfaceOption]>,
426+
HelpText<"ABI name to use for the contents of this module">;
424427

425428
def emit_module : Flag<["-"], "emit-module">,
426429
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,

include/swift/Serialization/Validation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct ValidationInfo {
9393
class ExtendedValidationInfo {
9494
SmallVector<StringRef, 4> ExtraClangImporterOpts;
9595
StringRef SDKPath;
96+
StringRef ModuleABIName;
9697
struct {
9798
unsigned ArePrivateImportsEnabled : 1;
9899
unsigned IsSIB : 1;
@@ -145,6 +146,9 @@ class ExtendedValidationInfo {
145146
void setAllowModuleWithCompilerErrorsEnabled(bool val) {
146147
Bits.IsAllowModuleWithCompilerErrorsEnabled = val;
147148
}
149+
150+
StringRef getModuleABIName() const { return ModuleABIName; }
151+
void setModuleABIName(StringRef name) { ModuleABIName = name; }
148152
};
149153

150154
/// Returns info about the serialized AST in the given data.

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ struct ASTContext::Implementation {
164164
/// DenseMap.
165165
llvm::MapVector<Identifier, ModuleDecl *> LoadedModules;
166166

167+
/// The set of top-level modules we have loaded, indexed by ABI name.
168+
llvm::MapVector<Identifier, ModuleDecl *> LoadedModulesByABIName;
169+
167170
// FIXME: This is a StringMap rather than a StringSet because StringSet
168171
// doesn't allow passing in a pre-existing allocator.
169172
llvm::StringMap<Identifier::Aligner, llvm::BumpPtrAllocator&>

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,13 +2143,15 @@ void ASTMangler::appendModule(const ModuleDecl *module,
21432143
StringRef useModuleName) {
21442144
assert(!module->getParent() && "cannot mangle nested modules!");
21452145

2146+
StringRef ModName =
2147+
DWARFMangling ? module->getName().str() : module->getABIName().str();
2148+
21462149
// Try the special 'swift' substitution.
2147-
if (module->isStdlibModule()) {
2150+
if (ModName == STDLIB_NAME) {
21482151
assert(useModuleName.empty());
21492152
return appendOperator("s");
21502153
}
21512154

2152-
StringRef ModName = module->getName().str();
21532155
if (ModName == MANGLING_MODULE_OBJC) {
21542156
assert(useModuleName.empty());
21552157
return appendOperator("So");

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ StringRef Decl::getAlternateModuleName() const {
638638
}
639639
}
640640
}
641+
641642
for (auto *DC = getDeclContext(); DC; DC = DC->getParent()) {
642643
if (auto decl = DC->getAsDecl()) {
643644
if (decl == this)

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

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
231231
inputArgs.AddLastArg(arguments, options::OPT_import_underlying_module);
232232
inputArgs.AddLastArg(arguments, options::OPT_module_cache_path);
233233
inputArgs.AddLastArg(arguments, options::OPT_module_link_name);
234+
inputArgs.AddLastArg(arguments, options::OPT_module_abi_name);
234235
inputArgs.AddLastArg(arguments, options::OPT_nostdimport);
235236
inputArgs.AddLastArg(arguments, options::OPT_parse_stdlib);
236237
inputArgs.AddLastArg(arguments, options::OPT_resource_dir);

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ bool ArgsToFrontendOptionsConverter::convert(
217217
return true;
218218
}
219219

220+
if (const Arg *A = Args.getLastArg(OPT_module_abi_name))
221+
Opts.ModuleABIName = A->getValue();
222+
220223
if (const Arg *A = Args.getLastArg(OPT_module_link_name))
221224
Opts.ModuleLinkName = A->getValue();
222225

0 commit comments

Comments
 (0)