@@ -113,7 +113,7 @@ std::string ASTMangler::mangleIVarInitDestroyEntity(const ClassDecl *decl,
113
113
bool isDestroyer,
114
114
SymbolKind SKind) {
115
115
beginMangling ();
116
- appendContext (decl);
116
+ appendContext (decl, decl-> getAlternateModuleName () );
117
117
appendOperator (isDestroyer ? " fE" : " fe" );
118
118
appendSymbolKind (SKind);
119
119
return finalize ();
@@ -436,7 +436,7 @@ std::string ASTMangler::mangleObjCRuntimeName(const NominalTypeDecl *Nominal) {
436
436
assert (isa<ProtocolDecl>(Nominal));
437
437
Buffer << ' P' ;
438
438
}
439
- appendModule (Ctx->getParentModule ());
439
+ appendModule (Ctx->getParentModule (), StringRef () );
440
440
appendIdentifier (Nominal->getName ().str ());
441
441
if (isProto)
442
442
Buffer << ' _' ;
@@ -479,7 +479,7 @@ std::string ASTMangler::mangleObjCRuntimeName(const NominalTypeDecl *Nominal) {
479
479
std::string ASTMangler::mangleTypeAsContextUSR (const NominalTypeDecl *type) {
480
480
beginManglingWithoutPrefix ();
481
481
llvm::SaveAndRestore<bool > allowUnnamedRAII (AllowNamelessEntities, true );
482
- appendContext (type);
482
+ appendContext (type, type-> getAlternateModuleName () );
483
483
return finalize ();
484
484
}
485
485
@@ -1561,7 +1561,7 @@ void ASTMangler::appendContextOf(const ValueDecl *decl) {
1561
1561
}
1562
1562
1563
1563
// Just mangle the decl's DC.
1564
- appendContext (decl->getDeclContext ());
1564
+ appendContext (decl->getDeclContext (), decl-> getAlternateModuleName () );
1565
1565
}
1566
1566
1567
1567
namespace {
@@ -1617,14 +1617,14 @@ static Optional<VarDecl*> findFirstVariable(PatternBindingDecl *binding) {
1617
1617
return None;
1618
1618
}
1619
1619
1620
- void ASTMangler::appendContext (const DeclContext *ctx) {
1620
+ void ASTMangler::appendContext (const DeclContext *ctx, StringRef useModuleName ) {
1621
1621
switch (ctx->getContextKind ()) {
1622
1622
case DeclContextKind::Module:
1623
- return appendModule (cast<ModuleDecl>(ctx));
1623
+ return appendModule (cast<ModuleDecl>(ctx), useModuleName );
1624
1624
1625
1625
case DeclContextKind::FileUnit:
1626
1626
assert (!isa<BuiltinUnit>(ctx) && " mangling member of builtin module!" );
1627
- appendContext (ctx->getParent ());
1627
+ appendContext (ctx->getParent (), useModuleName );
1628
1628
return ;
1629
1629
1630
1630
case DeclContextKind::SerializedLocal: {
@@ -1645,12 +1645,12 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1645
1645
} else {
1646
1646
// This is incorrect in that it does not produce a /unique/ mangling,
1647
1647
// but it will at least produce a /valid/ mangling.
1648
- appendContext (ctx->getParent ());
1648
+ appendContext (ctx->getParent (), useModuleName );
1649
1649
}
1650
1650
return ;
1651
1651
}
1652
1652
case LocalDeclContextKind::TopLevelCodeDecl:
1653
- return appendContext (local->getParent ());
1653
+ return appendContext (local->getParent (), useModuleName );
1654
1654
}
1655
1655
}
1656
1656
@@ -1663,7 +1663,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1663
1663
auto decl = ExtD->getExtendedNominal ();
1664
1664
// Recover from erroneous extension.
1665
1665
if (!decl)
1666
- return appendContext (ExtD->getDeclContext ());
1666
+ return appendContext (ExtD->getDeclContext (), useModuleName );
1667
1667
1668
1668
if (!ExtD->isEquivalentToExtendedContext ()) {
1669
1669
// Mangle the extension if:
@@ -1679,7 +1679,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1679
1679
// If the extension is constrained, mangle the generic signature that
1680
1680
// constrains it.
1681
1681
appendAnyGenericType (decl);
1682
- appendModule (ExtD->getParentModule ());
1682
+ appendModule (ExtD->getParentModule (), useModuleName );
1683
1683
if (sig && ExtD->isConstrainedExtension ()) {
1684
1684
Mod = ExtD->getModuleContext ();
1685
1685
auto nominalSig = ExtD->getSelfNominalTypeDecl ()
@@ -1733,7 +1733,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1733
1733
} else {
1734
1734
// This is incorrect in that it does not produce a /unique/ mangling,
1735
1735
// but it will at least produce a /valid/ mangling.
1736
- appendContext (ctx->getParent ());
1736
+ appendContext (ctx->getParent (), useModuleName );
1737
1737
}
1738
1738
return ;
1739
1739
}
@@ -1742,26 +1742,35 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1742
1742
1743
1743
case DeclContextKind::TopLevelCodeDecl:
1744
1744
// Mangle the containing module context.
1745
- return appendContext (ctx->getParent ());
1745
+ return appendContext (ctx->getParent (), useModuleName );
1746
1746
}
1747
1747
1748
1748
llvm_unreachable (" bad decl context" );
1749
1749
}
1750
1750
1751
- void ASTMangler::appendModule (const ModuleDecl *module ) {
1751
+ void ASTMangler::appendModule (const ModuleDecl *module ,
1752
+ StringRef useModuleName) {
1752
1753
assert (!module ->getParent () && " cannot mangle nested modules!" );
1753
1754
1754
1755
// Try the special 'swift' substitution.
1755
- if (module ->isStdlibModule ())
1756
+ if (module ->isStdlibModule ()) {
1757
+ assert (useModuleName.empty ());
1756
1758
return appendOperator (" s" );
1759
+ }
1757
1760
1758
1761
StringRef ModName = module ->getName ().str ();
1759
- if (ModName == MANGLING_MODULE_OBJC)
1762
+ if (ModName == MANGLING_MODULE_OBJC) {
1763
+ assert (useModuleName.empty ());
1760
1764
return appendOperator (" So" );
1761
- if (ModName == MANGLING_MODULE_CLANG_IMPORTER)
1765
+ }
1766
+ if (ModName == MANGLING_MODULE_CLANG_IMPORTER) {
1767
+ assert (useModuleName.empty ());
1762
1768
return appendOperator (" SC" );
1763
-
1764
- appendIdentifier (ModName);
1769
+ }
1770
+ if (!useModuleName.empty ())
1771
+ appendIdentifier (useModuleName);
1772
+ else
1773
+ appendIdentifier (ModName);
1765
1774
}
1766
1775
1767
1776
// / Mangle the name of a protocol as a substitution candidate.
@@ -2327,7 +2336,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2327
2336
assert (discriminator != AbstractClosureExpr::InvalidDiscriminator
2328
2337
&& " closure must be marked correctly with discriminator" );
2329
2338
2330
- appendContext (parentContext);
2339
+ appendContext (parentContext, StringRef () );
2331
2340
2332
2341
if (!Ty)
2333
2342
Ty = ErrorType::get (parentContext->getASTContext ());
@@ -2339,7 +2348,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2339
2348
2340
2349
void ASTMangler::appendDefaultArgumentEntity (const DeclContext *func,
2341
2350
unsigned index) {
2342
- appendContext (func);
2351
+ appendContext (func, StringRef () );
2343
2352
appendOperator (" fA" , Index (index));
2344
2353
}
2345
2354
@@ -2542,8 +2551,11 @@ ASTMangler::appendProtocolConformance(const ProtocolConformance *conformance) {
2542
2551
needsModule = false ;
2543
2552
}
2544
2553
}
2545
- if (needsModule)
2546
- appendModule (Mod);
2554
+ if (needsModule) {
2555
+ auto *DC = conformance->getDeclContext ();
2556
+ assert (DC->getAsDecl ());
2557
+ appendModule (Mod, DC->getAsDecl ()->getAlternateModuleName ());
2558
+ }
2547
2559
2548
2560
contextSig =
2549
2561
conformingType->getAnyNominal ()->getGenericSignatureOfContext ();
@@ -2565,7 +2577,10 @@ void ASTMangler::appendProtocolConformanceRef(
2565
2577
// Same as "conformance module matches type", below.
2566
2578
appendOperator (" HP" );
2567
2579
} else if (isRetroactiveConformance (conformance)) {
2568
- appendModule (conformance->getDeclContext ()->getParentModule ());
2580
+ auto *DC = conformance->getDeclContext ();
2581
+ assert (DC->getAsDecl ());
2582
+ appendModule (conformance->getDeclContext ()->getParentModule (),
2583
+ DC->getAsDecl ()->getAlternateModuleName ());
2569
2584
} else if (conformance->getDeclContext ()->getParentModule () ==
2570
2585
conformance->getType ()->getAnyNominal ()->getParentModule ()) {
2571
2586
appendOperator (" HP" );
0 commit comments