@@ -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
@@ -1562,7 +1562,7 @@ void ASTMangler::appendContextOf(const ValueDecl *decl) {
1562
1562
}
1563
1563
1564
1564
// Just mangle the decl's DC.
1565
- appendContext (decl->getDeclContext ());
1565
+ appendContext (decl->getDeclContext (), decl-> getAlternateModuleName () );
1566
1566
}
1567
1567
1568
1568
namespace {
@@ -1618,14 +1618,14 @@ static Optional<VarDecl*> findFirstVariable(PatternBindingDecl *binding) {
1618
1618
return None;
1619
1619
}
1620
1620
1621
- void ASTMangler::appendContext (const DeclContext *ctx) {
1621
+ void ASTMangler::appendContext (const DeclContext *ctx, StringRef useModuleName ) {
1622
1622
switch (ctx->getContextKind ()) {
1623
1623
case DeclContextKind::Module:
1624
- return appendModule (cast<ModuleDecl>(ctx));
1624
+ return appendModule (cast<ModuleDecl>(ctx), useModuleName );
1625
1625
1626
1626
case DeclContextKind::FileUnit:
1627
1627
assert (!isa<BuiltinUnit>(ctx) && " mangling member of builtin module!" );
1628
- appendContext (ctx->getParent ());
1628
+ appendContext (ctx->getParent (), useModuleName );
1629
1629
return ;
1630
1630
1631
1631
case DeclContextKind::SerializedLocal: {
@@ -1646,12 +1646,12 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1646
1646
} else {
1647
1647
// This is incorrect in that it does not produce a /unique/ mangling,
1648
1648
// but it will at least produce a /valid/ mangling.
1649
- appendContext (ctx->getParent ());
1649
+ appendContext (ctx->getParent (), useModuleName );
1650
1650
}
1651
1651
return ;
1652
1652
}
1653
1653
case LocalDeclContextKind::TopLevelCodeDecl:
1654
- return appendContext (local->getParent ());
1654
+ return appendContext (local->getParent (), useModuleName );
1655
1655
}
1656
1656
}
1657
1657
@@ -1664,7 +1664,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1664
1664
auto decl = ExtD->getExtendedNominal ();
1665
1665
// Recover from erroneous extension.
1666
1666
if (!decl)
1667
- return appendContext (ExtD->getDeclContext ());
1667
+ return appendContext (ExtD->getDeclContext (), useModuleName );
1668
1668
1669
1669
if (!ExtD->isEquivalentToExtendedContext ()) {
1670
1670
// Mangle the extension if:
@@ -1680,7 +1680,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1680
1680
// If the extension is constrained, mangle the generic signature that
1681
1681
// constrains it.
1682
1682
appendAnyGenericType (decl);
1683
- appendModule (ExtD->getParentModule ());
1683
+ appendModule (ExtD->getParentModule (), useModuleName );
1684
1684
if (sig && ExtD->isConstrainedExtension ()) {
1685
1685
Mod = ExtD->getModuleContext ();
1686
1686
auto nominalSig = ExtD->getSelfNominalTypeDecl ()
@@ -1734,7 +1734,7 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1734
1734
} else {
1735
1735
// This is incorrect in that it does not produce a /unique/ mangling,
1736
1736
// but it will at least produce a /valid/ mangling.
1737
- appendContext (ctx->getParent ());
1737
+ appendContext (ctx->getParent (), useModuleName );
1738
1738
}
1739
1739
return ;
1740
1740
}
@@ -1743,26 +1743,35 @@ void ASTMangler::appendContext(const DeclContext *ctx) {
1743
1743
1744
1744
case DeclContextKind::TopLevelCodeDecl:
1745
1745
// Mangle the containing module context.
1746
- return appendContext (ctx->getParent ());
1746
+ return appendContext (ctx->getParent (), useModuleName );
1747
1747
}
1748
1748
1749
1749
llvm_unreachable (" bad decl context" );
1750
1750
}
1751
1751
1752
- void ASTMangler::appendModule (const ModuleDecl *module ) {
1752
+ void ASTMangler::appendModule (const ModuleDecl *module ,
1753
+ StringRef useModuleName) {
1753
1754
assert (!module ->getParent () && " cannot mangle nested modules!" );
1754
1755
1755
1756
// Try the special 'swift' substitution.
1756
- if (module ->isStdlibModule ())
1757
+ if (module ->isStdlibModule ()) {
1758
+ assert (useModuleName.empty ());
1757
1759
return appendOperator (" s" );
1760
+ }
1758
1761
1759
1762
StringRef ModName = module ->getName ().str ();
1760
- if (ModName == MANGLING_MODULE_OBJC)
1763
+ if (ModName == MANGLING_MODULE_OBJC) {
1764
+ assert (useModuleName.empty ());
1761
1765
return appendOperator (" So" );
1762
- if (ModName == MANGLING_MODULE_CLANG_IMPORTER)
1766
+ }
1767
+ if (ModName == MANGLING_MODULE_CLANG_IMPORTER) {
1768
+ assert (useModuleName.empty ());
1763
1769
return appendOperator (" SC" );
1764
-
1765
- appendIdentifier (ModName);
1770
+ }
1771
+ if (!useModuleName.empty ())
1772
+ appendIdentifier (useModuleName);
1773
+ else
1774
+ appendIdentifier (ModName);
1766
1775
}
1767
1776
1768
1777
// / Mangle the name of a protocol as a substitution candidate.
@@ -2328,7 +2337,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2328
2337
assert (discriminator != AbstractClosureExpr::InvalidDiscriminator
2329
2338
&& " closure must be marked correctly with discriminator" );
2330
2339
2331
- appendContext (parentContext);
2340
+ appendContext (parentContext, StringRef () );
2332
2341
2333
2342
if (!Ty)
2334
2343
Ty = ErrorType::get (parentContext->getASTContext ());
@@ -2340,7 +2349,7 @@ void ASTMangler::appendClosureComponents(Type Ty, unsigned discriminator,
2340
2349
2341
2350
void ASTMangler::appendDefaultArgumentEntity (const DeclContext *func,
2342
2351
unsigned index) {
2343
- appendContext (func);
2352
+ appendContext (func, StringRef () );
2344
2353
appendOperator (" fA" , Index (index));
2345
2354
}
2346
2355
@@ -2543,8 +2552,11 @@ ASTMangler::appendProtocolConformance(const ProtocolConformance *conformance) {
2543
2552
needsModule = false ;
2544
2553
}
2545
2554
}
2546
- if (needsModule)
2547
- appendModule (Mod);
2555
+ if (needsModule) {
2556
+ auto *DC = conformance->getDeclContext ();
2557
+ assert (DC->getAsDecl ());
2558
+ appendModule (Mod, DC->getAsDecl ()->getAlternateModuleName ());
2559
+ }
2548
2560
2549
2561
contextSig =
2550
2562
conformingType->getAnyNominal ()->getGenericSignatureOfContext ();
@@ -2566,7 +2578,10 @@ void ASTMangler::appendProtocolConformanceRef(
2566
2578
// Same as "conformance module matches type", below.
2567
2579
appendOperator (" HP" );
2568
2580
} else if (isRetroactiveConformance (conformance)) {
2569
- appendModule (conformance->getDeclContext ()->getParentModule ());
2581
+ auto *DC = conformance->getDeclContext ();
2582
+ assert (DC->getAsDecl ());
2583
+ appendModule (conformance->getDeclContext ()->getParentModule (),
2584
+ DC->getAsDecl ()->getAlternateModuleName ());
2570
2585
} else if (conformance->getDeclContext ()->getParentModule () ==
2571
2586
conformance->getType ()->getAnyNominal ()->getParentModule ()) {
2572
2587
appendOperator (" HP" );
0 commit comments