Skip to content

Commit 4e04061

Browse files
authored
Merge pull request #8767 from jrose-apple/mangle-typealiases-better
Improve the mangling of USRs in several ways.
2 parents f2d2ef1 + 2d84981 commit 4e04061

File tree

21 files changed

+175
-139
lines changed

21 files changed

+175
-139
lines changed

docs/ABI.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ Entities
889889
entity-spec ::= decl-name type 'i' // subscript ('i'ndex) itself (not the individual accessors)
890890
entity-spec ::= decl-name type 'v' // variable
891891
entity-spec ::= decl-name type 'f' ACCESSOR
892-
entity-spec ::= decl-name type 'fp' // generic type parameter (not used?)
892+
entity-spec ::= decl-name type 'fp' // generic type parameter
893893
entity-spec ::= decl-name type 'fo' // enum element (currently not used)
894894

895895
ACCESSOR ::= 'm' // materializeForSet
@@ -958,14 +958,15 @@ Types
958958

959959
::
960960

961-
nominal-type ::= substitution
962-
nominal-type ::= context decl-name 'C' // nominal class type
963-
nominal-type ::= context decl-name 'O' // nominal enum type
964-
nominal-type ::= context decl-name 'V' // nominal struct type
965-
nominal-type ::= protocol 'P' // nominal protocol type
961+
any-generic-type ::= substitution
962+
any-generic-type ::= context decl-name 'C' // nominal class type
963+
any-generic-type ::= context decl-name 'O' // nominal enum type
964+
any-generic-type ::= context decl-name 'V' // nominal struct type
965+
any-generic-type ::= protocol 'P' // nominal protocol type
966+
any-generic-type ::= context decl-name 'a' // typealias type (used in DWARF and USRs)
966967

967-
nominal-type ::= 'S' KNOWN-TYPE-KIND // known nominal type substitution
968-
nominal-type ::= 'S' NATURAL KNOWN-TYPE-KIND // repeated known type substitutions of the same kind
968+
any-generic-type ::= 'S' KNOWN-TYPE-KIND // known nominal type substitution
969+
any-generic-type ::= 'S' NATURAL KNOWN-TYPE-KIND // repeated known type substitutions of the same kind
969970

970971
KNOWN-TYPE-KIND ::= 'a' // Swift.Array
971972
KNOWN-TYPE-KIND ::= 'b' // Swift.Bool
@@ -995,7 +996,6 @@ Types
995996
type ::= 'Bp' // Builtin.RawPointer
996997
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
997998
type ::= 'Bw' // Builtin.Word
998-
type ::= context decl-name 'a' // Type alias (DWARF only)
999999
type ::= function-signature 'c' // function type
10001000
type ::= function-signature 'X' FUNCTION-KIND // special function type
10011001
type ::= bound-generic-type
@@ -1042,7 +1042,7 @@ Types
10421042

10431043
type ::= archetype
10441044
type ::= associated-type
1045-
type ::= nominal-type
1045+
type ::= any-generic-type
10461046
type ::= protocol-list 'p' // existential type
10471047
type ::= protocol-list superclass 'Xc' // existential type with superclass
10481048
type ::= protocol-list 'Xl' // existential type with AnyObject

include/swift/AST/ASTMangler.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class ASTMangler : public Mangler {
3838
/// If enabled, Arche- and Alias types are mangled with context.
3939
bool DWARFMangling;
4040

41+
/// If enabled, entities that ought to have names but don't get a placeholder.
42+
///
43+
/// If disabled, it is an error to try to mangle such an entity.
44+
bool AllowNamelessEntities = false;
45+
4146
public:
4247
enum class SymbolKind {
4348
Default,
@@ -122,7 +127,7 @@ class ASTMangler : public Mangler {
122127

123128
std::string mangleTypeAsContextUSR(const NominalTypeDecl *type);
124129

125-
std::string mangleDeclAsUSR(ValueDecl *Decl, StringRef USRPrefix);
130+
std::string mangleDeclAsUSR(const ValueDecl *Decl, StringRef USRPrefix);
126131

127132
std::string mangleAccessorEntityAsUSR(AccessorKind kind,
128133
AddressorKind addressorKind,
@@ -167,7 +172,7 @@ class ASTMangler : public Mangler {
167172

168173
void appendProtocolName(const ProtocolDecl *protocol);
169174

170-
void appendNominalType(const NominalTypeDecl *decl);
175+
void appendAnyGenericType(const GenericTypeDecl *decl);
171176

172177
void appendFunctionType(AnyFunctionType *fn, bool forceSingleParam);
173178

@@ -207,7 +212,7 @@ class ASTMangler : public Mangler {
207212

208213
void appendDeclType(const ValueDecl *decl, bool isFunctionMangling = false);
209214

210-
bool tryAppendStandardSubstitution(const NominalTypeDecl *type);
215+
bool tryAppendStandardSubstitution(const GenericTypeDecl *type);
211216

212217
void appendConstructorEntity(const ConstructorDecl *ctor, bool isAllocating);
213218

include/swift/Basic/Mangler.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
#define SWIFT_BASIC_MANGLER_H
1515

1616
#include "swift/Demangling/ManglingUtils.h"
17+
#include "swift/Basic/LLVM.h"
1718
#include "llvm/ADT/DenseMap.h"
19+
#include "llvm/ADT/SmallString.h"
1820
#include "llvm/ADT/StringRef.h"
1921
#include "llvm/ADT/StringMap.h"
2022
#include "llvm/Support/raw_ostream.h"
2123

22-
using llvm::StringRef;
23-
using llvm::ArrayRef;
24-
2524
namespace swift {
2625
namespace Mangle {
2726

@@ -39,7 +38,7 @@ class Mangler {
3938
friend class SubstitutionMerging;
4039

4140
/// The storage for the mangled symbol.
42-
llvm::SmallVector<char, 128> Storage;
41+
llvm::SmallString<128> Storage;
4342

4443
/// The output stream for the mangled symbol.
4544
llvm::raw_svector_ostream Buffer;
@@ -106,7 +105,7 @@ class Mangler {
106105
void finalize(llvm::raw_ostream &stream);
107106

108107
/// Verify that demangling and remangling works.
109-
void verify(const std::string &mangledName);
108+
static void verify(StringRef mangledName);
110109

111110
/// Appends a mangled identifier string.
112111
void appendIdentifier(StringRef ident);

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ NODE(Tuple)
149149
NODE(TupleElement)
150150
NODE(TupleElementName)
151151
NODE(Type)
152-
NODE(TypeAlias)
152+
CONTEXT_NODE(TypeAlias)
153153
NODE(TypeList)
154154
NODE(TypeMangling)
155155
NODE(TypeMetadata)

include/swift/Demangling/Demangler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ class Demangler : public NodeFactory {
405405
NodePointer popTypeAndGetChild();
406406
NodePointer popTypeAndGetNominal();
407407
NodePointer demangleBuiltinType();
408-
NodePointer demangleNominalType(Node::Kind kind);
409-
NodePointer demangleTypeAlias();
408+
NodePointer demangleAnyGenericType(Node::Kind kind);
410409
NodePointer demangleExtensionContext();
411410
NodePointer demanglePlainFunction();
412411
NodePointer popFunctionType(Node::Kind kind);

0 commit comments

Comments
 (0)