Skip to content

Commit b04abaa

Browse files
authored
Merge pull request #22997 from adrian-prantl/48259889-5.1
2 parents 2283543 + ef115cf commit b04abaa

27 files changed

+727
-350
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class ASTBuilder {
6060

6161
GenericTypeDecl *createTypeDecl(StringRef mangledName, bool &typeAlias);
6262

63-
GenericTypeDecl *createTypeDecl(const Demangle::NodePointer &node,
63+
GenericTypeDecl *createTypeDecl(NodePointer node,
6464
bool &typeAlias);
6565

66-
ProtocolDecl *createProtocolDecl(const Demangle::NodePointer &node);
66+
ProtocolDecl *createProtocolDecl(NodePointer node);
6767

6868
Type createNominalType(GenericTypeDecl *decl);
6969

@@ -126,22 +126,30 @@ class ASTBuilder {
126126

127127
Type getOpaqueType();
128128

129+
Type createOptionalType(Type base);
130+
131+
Type createArrayType(Type base);
132+
133+
Type createDictionaryType(Type key, Type value);
134+
135+
Type createParenType(Type base);
136+
129137
private:
130138
bool validateParentType(TypeDecl *decl, Type parent);
131139
CanGenericSignature demangleGenericSignature(
132140
NominalTypeDecl *nominalDecl,
133-
const Demangle::NodePointer &node);
134-
DeclContext *findDeclContext(const Demangle::NodePointer &node);
135-
ModuleDecl *findModule(const Demangle::NodePointer &node);
136-
Demangle::NodePointer findModuleNode(const Demangle::NodePointer &node);
141+
NodePointer node);
142+
DeclContext *findDeclContext(NodePointer node);
143+
ModuleDecl *findModule(NodePointer node);
144+
Demangle::NodePointer findModuleNode(NodePointer node);
137145

138146
enum class ForeignModuleKind {
139147
Imported,
140148
SynthesizedByImporter
141149
};
142150

143151
Optional<ForeignModuleKind>
144-
getForeignModuleKind(const Demangle::NodePointer &node);
152+
getForeignModuleKind(NodePointer node);
145153

146154
GenericTypeDecl *findTypeDecl(DeclContext *dc,
147155
Identifier name,

include/swift/AST/ASTMangler.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@ class ASTMangler : public Mangler {
214214

215215
void bindGenericParameters(CanGenericSignature sig);
216216

217-
/// Mangles a sugared type iff we are mangling for the debugger.
218-
template <class T> void appendSugaredType(Type type) {
219-
assert(DWARFMangling &&
220-
"sugared types are only legal when mangling for the debugger");
221-
auto *BlandTy = cast<T>(type.getPointer())->getSinglyDesugaredType();
222-
appendType(BlandTy);
223-
}
224-
225217
void appendBoundGenericArgs(Type type, bool &isFirstArgList);
226218

227219
/// Append the bound generics arguments for the given declaration context

include/swift/Demangling/Demangle.h

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -35,6 +35,11 @@ namespace Demangle {
3535

3636
enum class SymbolicReferenceKind : uint8_t;
3737

38+
/// A simple default implementation that assigns letters to type parameters in
39+
/// alphabetic order.
40+
std::string genericParameterName(uint64_t depth, uint64_t index);
41+
42+
/// Display style options for the demangler.
3843
struct DemangleOptions {
3944
bool SynthesizeSugarOnTypes = false;
4045
bool DisplayDebuggerGeneratedModule = true;
@@ -52,6 +57,8 @@ struct DemangleOptions {
5257
bool ShortenArchetype = false;
5358
bool ShowPrivateDiscriminators = true;
5459
bool ShowFunctionArgumentTypes = true;
60+
std::function<std::string(uint64_t, uint64_t)> GenericParameterName =
61+
genericParameterName;
5562

5663
DemangleOptions() {}
5764

@@ -142,32 +149,38 @@ class Node {
142149
friend class NodeFactory;
143150

144151
private:
145-
Kind NodeKind;
146152

147-
enum class PayloadKind : uint8_t {
148-
None, Text, Index
153+
struct NodeVector {
154+
NodePointer *Nodes;
155+
uint32_t Number = 0;
156+
uint32_t Capacity = 0;
149157
};
150-
PayloadKind NodePayloadKind;
151158

152159
union {
153-
llvm::StringRef TextPayload;
154-
IndexType IndexPayload;
160+
llvm::StringRef Text;
161+
IndexType Index;
162+
NodePointer InlineChildren[2];
163+
NodeVector Children;
155164
};
156165

157-
NodePointer *Children = nullptr;
158-
size_t NumChildren = 0;
159-
size_t ReservedChildren = 0;
166+
167+
Kind NodeKind;
168+
169+
enum class PayloadKind : uint8_t {
170+
None, Text, Index, OneChild, TwoChildren, ManyChildren
171+
};
172+
PayloadKind NodePayloadKind;
160173

161174
Node(Kind k)
162175
: NodeKind(k), NodePayloadKind(PayloadKind::None) {
163176
}
164177
Node(Kind k, llvm::StringRef t)
165178
: NodeKind(k), NodePayloadKind(PayloadKind::Text) {
166-
TextPayload = t;
179+
Text = t;
167180
}
168181
Node(Kind k, IndexType index)
169182
: NodeKind(k), NodePayloadKind(PayloadKind::Index) {
170-
IndexPayload = index;
183+
Index = index;
171184
}
172185
Node(const Node &) = delete;
173186
Node &operator=(const Node &) = delete;
@@ -178,37 +191,33 @@ class Node {
178191
bool hasText() const { return NodePayloadKind == PayloadKind::Text; }
179192
llvm::StringRef getText() const {
180193
assert(hasText());
181-
return TextPayload;
194+
return Text;
182195
}
183196

184197
bool hasIndex() const { return NodePayloadKind == PayloadKind::Index; }
185198
uint64_t getIndex() const {
186199
assert(hasIndex());
187-
return IndexPayload;
200+
return Index;
188201
}
189202

190-
using iterator = NodePointer *;
191-
using const_iterator = const NodePointer *;
192-
using size_type = size_t;
203+
using iterator = const NodePointer *;
204+
205+
size_t getNumChildren() const;
193206

194-
bool hasChildren() const { return NumChildren != 0; }
195-
size_t getNumChildren() const { return NumChildren; }
196-
iterator begin() { return Children; }
197-
iterator end() { return Children + NumChildren; }
198-
const_iterator begin() const { return Children; }
199-
const_iterator end() const { return Children + NumChildren; }
207+
bool hasChildren() const { return getNumChildren() != 0; }
208+
209+
iterator begin() const;
210+
211+
iterator end() const;
200212

201213
NodePointer getFirstChild() const {
202-
assert(NumChildren >= 1);
203-
return Children[0];
214+
return getChild(0);
204215
}
205216
NodePointer getChild(size_t index) const {
206-
assert(NumChildren > index);
207-
return Children[index];
217+
assert(getNumChildren() > index);
218+
return begin()[index];
208219
}
209220

210-
// inline void addChild(NodePointer Child, Context &Ctx);
211-
212221
// Only to be used by the demangler parsers.
213222
void addChild(NodePointer Child, NodeFactory &Factory);
214223
// Only to be used by the demangler parsers.
@@ -344,17 +353,19 @@ class Context {
344353
/// prefix: _T, _T0, $S, _$S.
345354
///
346355
/// \returns The demangled string.
347-
std::string demangleSymbolAsString(llvm::StringRef MangledName,
348-
const DemangleOptions &Options = DemangleOptions());
356+
std::string demangleSymbolAsString(
357+
llvm::StringRef MangledName,
358+
const DemangleOptions &Options = DemangleOptions());
349359

350360
/// Demangle the given type and return the readable name.
351361
///
352362
/// \param MangledName The mangled type string, which does _not_ start with
353363
/// a mangling prefix.
354364
///
355365
/// \returns The demangled string.
356-
std::string demangleTypeAsString(llvm::StringRef MangledName,
357-
const DemangleOptions &Options = DemangleOptions());
366+
std::string
367+
demangleTypeAsString(llvm::StringRef MangledName,
368+
const DemangleOptions &Options = DemangleOptions());
358369

359370
/// Returns true if the mangledName refers to a thunk function.
360371
///
@@ -473,7 +484,7 @@ void mangleIdentifier(const char *data, size_t length,
473484
/// Remangle a demangled parse tree.
474485
///
475486
/// This should always round-trip perfectly with demangleSymbolAsNode.
476-
std::string mangleNode(const NodePointer &root);
487+
std::string mangleNode(NodePointer root);
477488

478489
using SymbolicResolver =
479490
llvm::function_ref<Demangle::NodePointer (SymbolicReferenceKind,
@@ -483,13 +494,13 @@ using SymbolicResolver =
483494
/// symbolic references.
484495
///
485496
/// This should always round-trip perfectly with demangleSymbolAsNode.
486-
std::string mangleNode(const NodePointer &root, SymbolicResolver resolver);
497+
std::string mangleNode(NodePointer root, SymbolicResolver resolver);
487498

488499
/// Remangle in the old mangling scheme.
489500
///
490501
/// This is only used for objc-runtime names and should be removed as soon as
491502
/// we switch to the new mangling for those names as well.
492-
std::string mangleNodeOld(const NodePointer &root);
503+
std::string mangleNodeOld(NodePointer root);
493504

494505
/// Transform the node structure to a string.
495506
///
@@ -569,7 +580,6 @@ bool nodeConsumesGenericArgs(Node *node);
569580
bool isSpecialized(Node *node);
570581

571582
NodePointer getUnspecialized(Node *node, NodeFactory &Factory);
572-
std::string archetypeName(Node::IndexType index, Node::IndexType depth);
573583

574584
/// Form a StringRef around the mangled name starting at base, if the name may
575585
/// contain symbolic references.

include/swift/Demangling/DemangleNodes.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ NODE(FullTypeMetadata)
8888
CONTEXT_NODE(Function)
8989
NODE(FunctionSignatureSpecialization)
9090
NODE(FunctionSignatureSpecializationParam)
91+
NODE(FunctionSignatureSpecializationReturn)
9192
NODE(FunctionSignatureSpecializationParamKind)
9293
NODE(FunctionSignatureSpecializationParamPayload)
9394
NODE(FunctionType)
@@ -252,5 +253,9 @@ NODE(ModuleDescriptor)
252253
NODE(ExtensionDescriptor)
253254
NODE(AnonymousDescriptor)
254255
NODE(AssociatedTypeGenericParamRef)
256+
NODE(SugaredOptional)
257+
NODE(SugaredArray)
258+
NODE(SugaredDictionary)
259+
NODE(SugaredParen)
255260
#undef CONTEXT_NODE
256261
#undef NODE

include/swift/Demangling/Demangler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class NodeFactory {
132132
/// new memory address.
133133
/// The \p Capacity is enlarged at least by \p MinGrowth, but can also be
134134
/// enlarged by a bigger value.
135-
template<typename T> void Reallocate(T *&Objects, size_t &Capacity,
135+
template<typename T> void Reallocate(T *&Objects, uint32_t &Capacity,
136136
size_t MinGrowth) {
137137
size_t OldAllocSize = Capacity * sizeof(T);
138138
size_t AdditionalAlloc = MinGrowth * sizeof(T);
@@ -203,8 +203,8 @@ template<typename T> class Vector {
203203

204204
protected:
205205
T *Elems = nullptr;
206-
size_t NumElems = 0;
207-
size_t Capacity = 0;
206+
uint32_t NumElems = 0;
207+
uint32_t Capacity = 0;
208208

209209
public:
210210
using iterator = T *;
@@ -469,7 +469,7 @@ class Demangler : public NodeFactory {
469469
NodePointer demangleThunkOrSpecialization();
470470
NodePointer demangleGenericSpecialization(Node::Kind SpecKind);
471471
NodePointer demangleFunctionSpecialization();
472-
NodePointer demangleFuncSpecParam(Node::IndexType ParamIdx);
472+
NodePointer demangleFuncSpecParam(Node::Kind Kind);
473473
NodePointer addFuncSpecParamNumber(NodePointer Param,
474474
FunctionSigSpecializationParamKind Kind);
475475

0 commit comments

Comments
 (0)