Skip to content

Commit 41ccedc

Browse files
committed
AST: Fix opaque type mangling used by type reconstruction
Make sure we mangle opaque types using the same settings as the debugger mangling (with OptimizeProtocolNames = false) to ensure that we can reconstruct those names again.
1 parent 2b93b5b commit 41ccedc

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ class ASTMangler : public Mangler {
236236

237237
std::string mangleLocalTypeDecl(const TypeDecl *type);
238238

239+
std::string mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl);
240+
239241
enum SpecialContext {
240242
ObjCContext,
241243
ClangImporterContext,

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "swift/AST/ProtocolConformance.h"
3030
#include "swift/AST/ProtocolConformanceRef.h"
3131
#include "swift/Basic/Defer.h"
32+
#include "swift/Demangling/ManglingMacros.h"
3233
#include "swift/Demangling/ManglingUtils.h"
3334
#include "swift/Demangling/Demangler.h"
3435
#include "swift/Strings.h"
@@ -691,6 +692,12 @@ std::string ASTMangler::mangleLocalTypeDecl(const TypeDecl *type) {
691692
return finalize();
692693
}
693694

695+
std::string ASTMangler::mangleOpaqueTypeDecl(const OpaqueTypeDecl *decl) {
696+
DWARFMangling = true;
697+
OptimizeProtocolNames = false;
698+
return mangleDeclAsUSR(decl->getNamingDecl(), MANGLING_PREFIX_STR);
699+
}
700+
694701
void ASTMangler::appendSymbolKind(SymbolKind SKind) {
695702
switch (SKind) {
696703
case SymbolKind::Default: return;

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7088,7 +7088,7 @@ Identifier OpaqueTypeDecl::getOpaqueReturnTypeIdentifier() const {
70887088
{
70897089
llvm::raw_svector_ostream os(mangleBuf);
70907090
Mangle::ASTMangler mangler;
7091-
os << mangler.mangleDeclAsUSR(getNamingDecl(), MANGLING_PREFIX_STR);
7091+
os << mangler.mangleOpaqueTypeDecl(this);
70927092
}
70937093

70947094
OpaqueReturnTypeIdentifier = getASTContext().getIdentifier(mangleBuf);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
5757
/// Don't worry about adhering to the 80-column limit for this line.
58-
const uint16_t SWIFTMODULE_VERSION_MINOR = 552; // simple didSet
58+
const uint16_t SWIFTMODULE_VERSION_MINOR = 553; // change to USR mangling
5959

6060
/// A standard hash seed used for all string hashes in a serialized module.
6161
///

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,8 +5067,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
50675067
for (auto OTD : opaqueReturnTypeDecls) {
50685068
hasOpaqueReturnTypes = true;
50695069
Mangle::ASTMangler Mangler;
5070-
auto MangledName = Mangler.mangleDeclAsUSR(OTD->getNamingDecl(),
5071-
MANGLING_PREFIX_STR);
5070+
auto MangledName = Mangler.mangleOpaqueTypeDecl(OTD);
50725071
opaqueReturnTypeGenerator.insert(MangledName, addDeclRef(OTD));
50735072
}
50745073
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir -g %s -disable-availability-checking
2+
3+
public protocol P {
4+
associatedtype Horse
5+
}
6+
7+
public protocol Feed {}
8+
9+
public struct Hay : Feed {}
10+
11+
public func hasOpaqueResult<T : P>(_: T.Type, _: T.Horse) -> some Feed {
12+
return Hay()
13+
}
14+
15+

0 commit comments

Comments
 (0)