Skip to content

Commit 8ca814c

Browse files
author
Max Moiseev
committed
Merge remote-tracking branch 'origin/master' into new-integer-protocols
2 parents b7f715f + 4e04061 commit 8ca814c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+768
-250
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);

include/swift/IDE/APIDigesterData.h

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#define SWIFT_IDE_APIDIGESTERDATA_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/StringRef.h"
19+
#include "llvm/ADT/StringSwitch.h"
1820
#include "llvm/Support/raw_ostream.h"
1921

2022
namespace swift {
@@ -27,26 +29,42 @@ enum class SDKNodeKind: uint8_t {
2729
#include "DigesterEnums.def"
2830
};
2931

32+
SDKNodeKind parseSDKNodeKind(StringRef Content);
33+
3034
enum class NodeAnnotation: uint8_t{
3135
#define NODE_ANNOTATION(NAME) NAME,
3236
#include "DigesterEnums.def"
3337
};
3438

39+
NodeAnnotation parseSDKNodeAnnotation(StringRef Content);
40+
41+
enum class APIDiffItemKind: uint8_t{
42+
#define DIFF_ITEM_KIND(NAME) ADK_##NAME,
43+
#include "DigesterEnums.def"
44+
};
45+
3546
// Redefine << so that we can output the name of the annotation kind.
3647
raw_ostream &operator<<(raw_ostream &Out, const NodeAnnotation Value);
3748

3849
// Redefine << so that we can output the name of the node kind.
3950
raw_ostream &operator<<(raw_ostream &Out, const SDKNodeKind Value);
4051

41-
// DiffItem describes how an element in SDK evolves in a way that migrator can
42-
// read conveniently. Each DiffItem corresponds to one JSON element and contains
52+
struct APIDiffItem {
53+
virtual void streamDef(llvm::raw_ostream &S) const = 0;
54+
virtual APIDiffItemKind getKind() const = 0;
55+
virtual StringRef getKey() const = 0;
56+
virtual ~APIDiffItem() = default;
57+
};
58+
59+
// CommonDiffItem describes how an element in SDK evolves in a way that migrator can
60+
// read conveniently. Each CommonDiffItem corresponds to one JSON element and contains
4361
// sub fields explaining how migrator can assist client code to cope with such
4462
// SDK change. For instance, the following first JSON element describes an unwrap
4563
// optional change in the first parameter of function "c:@F@CTTextTabGetOptions".
4664
// Similarly, the second JSON element describes a type parameter down cast in the
4765
// second parameter of function "c:objc(cs)NSXMLDocument(im)insertChildren:atIndex:".
4866
// We keep both usrs because in the future this may support auto-rename.
49-
struct DiffItem {
67+
struct CommonDiffItem: public APIDiffItem {
5068
SDKNodeKind NodeKind;
5169
NodeAnnotation DiffKind;
5270
StringRef ChildIndex;
@@ -56,15 +74,21 @@ struct DiffItem {
5674
StringRef RightComment;
5775
StringRef ModuleName;
5876

59-
DiffItem(SDKNodeKind NodeKind, NodeAnnotation DiffKind, StringRef ChildIndex,
60-
StringRef LeftUsr, StringRef RightUsr, StringRef LeftComment,
61-
StringRef RightComment, StringRef ModuleName);
77+
CommonDiffItem(SDKNodeKind NodeKind, NodeAnnotation DiffKind,
78+
StringRef ChildIndex, StringRef LeftUsr, StringRef RightUsr,
79+
StringRef LeftComment, StringRef RightComment,
80+
StringRef ModuleName);
6281

6382
static StringRef head();
64-
bool operator<(DiffItem Other) const;
83+
bool operator<(CommonDiffItem Other) const;
84+
static bool classof(const APIDiffItem *D);
6585
static void describe(llvm::raw_ostream &os);
6686
static void undef(llvm::raw_ostream &os);
67-
void streamDef(llvm::raw_ostream &S) const;
87+
void streamDef(llvm::raw_ostream &S) const override;
88+
StringRef getKey() const override { return LeftUsr; }
89+
APIDiffItemKind getKind() const override {
90+
return APIDiffItemKind::ADK_CommonDiffItem;
91+
}
6892
};
6993

7094

@@ -149,46 +173,95 @@ struct DiffItem {
149173
// myColor.components
150174
//
151175
//
152-
struct TypeMemberDiffItem {
176+
struct TypeMemberDiffItem: public APIDiffItem {
153177
StringRef usr;
154178
StringRef newTypeName;
155179
StringRef newPrintedName;
156180
Optional<uint8_t> selfIndex;
157181
StringRef oldPrintedName;
158182

183+
TypeMemberDiffItem(StringRef usr, StringRef newTypeName,
184+
StringRef newPrintedName, Optional<uint8_t> selfIndex,
185+
StringRef oldPrintedName) : usr(usr),
186+
newTypeName(newTypeName), newPrintedName(newPrintedName),
187+
selfIndex(selfIndex), oldPrintedName(oldPrintedName) {}
159188
static StringRef head();
160189
static void describe(llvm::raw_ostream &os);
161190
static void undef(llvm::raw_ostream &os);
162-
void streamDef(llvm::raw_ostream &os) const;
191+
void streamDef(llvm::raw_ostream &os) const override;
163192
bool operator<(TypeMemberDiffItem Other) const;
193+
static bool classof(const APIDiffItem *D);
194+
StringRef getKey() const override { return usr; }
195+
APIDiffItemKind getKind() const override {
196+
return APIDiffItemKind::ADK_TypeMemberDiffItem;
197+
}
164198
};
165199

166-
struct NoEscapeFuncParam {
200+
struct NoEscapeFuncParam: public APIDiffItem {
167201
StringRef Usr;
168202
unsigned Index;
169203

170204
NoEscapeFuncParam(StringRef Usr, unsigned Index) : Usr(Usr), Index(Index) {}
171205
static StringRef head();
172206
static void describe(llvm::raw_ostream &os);
173207
static void undef(llvm::raw_ostream &os);
174-
void streamDef(llvm::raw_ostream &os) const;
208+
void streamDef(llvm::raw_ostream &os) const override;
175209
bool operator<(NoEscapeFuncParam Other) const;
210+
static bool classof(const APIDiffItem *D);
211+
StringRef getKey() const override { return Usr; }
212+
APIDiffItemKind getKind() const override {
213+
return APIDiffItemKind::ADK_NoEscapeFuncParam;
214+
}
176215
};
177216

178217
/// This info is about functions meet the following criteria:
179218
/// - This function is a member function of a type.
180219
/// - This function is overloaded.
181-
struct OverloadedFuncInfo {
220+
struct OverloadedFuncInfo: public APIDiffItem {
182221
StringRef Usr;
183222

184223
OverloadedFuncInfo(StringRef Usr) : Usr(Usr) {}
185224
static StringRef head();
186225
static void describe(llvm::raw_ostream &os);
187226
static void undef(llvm::raw_ostream &os);
188-
void streamDef(llvm::raw_ostream &os) const;
227+
void streamDef(llvm::raw_ostream &os) const override;
189228
bool operator<(OverloadedFuncInfo Other) const;
229+
static bool classof(const APIDiffItem *D);
230+
StringRef getKey() const override { return Usr; }
231+
APIDiffItemKind getKind() const override {
232+
return APIDiffItemKind::ADK_OverloadedFuncInfo;
233+
}
234+
};
235+
236+
/// APIDiffItem store is the interface that migrator should communicates with;
237+
/// Given a key, usually the usr of the system entity under migration, the store
238+
/// should return a slice of related changes in the same format of
239+
/// swift-api-digester. This struct also handles the serialization and
240+
/// deserialization of all kinds of API diff items declared above.
241+
struct APIDiffItemStore {
242+
struct Implementation;
243+
Implementation &Impl;
244+
static void serialize(llvm::raw_ostream &os, ArrayRef<APIDiffItem*> Items);
245+
APIDiffItemStore();
246+
~APIDiffItemStore();
247+
ArrayRef<APIDiffItem*> getDiffItems(StringRef Key) const;
248+
ArrayRef<APIDiffItem*> getAllDiffItems() const;
249+
250+
/// Add a path of a JSON file dumped from swift-api-digester that contains
251+
/// API changes we care about. Calling this can be heavy since the procedure
252+
/// will parse and index the data inside of the given file.
253+
void addStorePath(StringRef Path);
190254
};
191255
}
192256
}
257+
namespace json {
258+
template<>
259+
struct ScalarEnumerationTraits<ide::api::SDKNodeKind> {
260+
static void enumeration(Output &out, ide::api::SDKNodeKind &value) {
261+
#define NODE_KIND(X) out.enumCase(value, #X, ide::api::SDKNodeKind::X);
262+
#include "swift/IDE/DigesterEnums.def"
263+
}
264+
};
265+
}
193266
}
194267
#endif // SWIFT_IDE_APIDIGESTERDATA_H

include/swift/IDE/DigesterEnums.def

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#define KNOWN_TYPE(NAME)
1919
#endif
2020

21+
#ifndef DIFF_ITEM_KIND
22+
#define DIFF_ITEM_KIND(NAME)
23+
#endif
24+
25+
#ifndef DIFF_ITEM_KEY_KIND
26+
#define DIFF_ITEM_KEY_KIND(NAME)
27+
#endif
28+
2129
NODE_KIND(Root)
2230
NODE_KIND(TypeDecl)
2331
NODE_KIND(TypeNominal)
@@ -82,6 +90,41 @@ KNOWN_TYPE(Void)
8290
KNOWN_TYPE(Unmanaged)
8391
KNOWN_TYPE(Function)
8492

93+
DIFF_ITEM_KIND(CommonDiffItem)
94+
DIFF_ITEM_KIND(TypeMemberDiffItem)
95+
DIFF_ITEM_KIND(NoEscapeFuncParam)
96+
DIFF_ITEM_KIND(OverloadedFuncInfo)
97+
98+
#ifndef DIFF_ITEM_KEY_KIND_STRING
99+
#define DIFF_ITEM_KEY_KIND_STRING(NAME) DIFF_ITEM_KEY_KIND(NAME)
100+
#endif
101+
102+
#ifndef DIFF_ITEM_KEY_KIND_INT
103+
#define DIFF_ITEM_KEY_KIND_INT(NAME) DIFF_ITEM_KEY_KIND(NAME)
104+
#endif
105+
106+
DIFF_ITEM_KEY_KIND_STRING(DiffItemKind)
107+
DIFF_ITEM_KEY_KIND_STRING(NodeKind)
108+
DIFF_ITEM_KEY_KIND_STRING(NodeAnnotation)
109+
DIFF_ITEM_KEY_KIND_STRING(Usr)
110+
DIFF_ITEM_KEY_KIND_STRING(ChildIndex)
111+
DIFF_ITEM_KEY_KIND_STRING(LeftUsr)
112+
DIFF_ITEM_KEY_KIND_STRING(LeftComment)
113+
DIFF_ITEM_KEY_KIND_STRING(RightUsr)
114+
DIFF_ITEM_KEY_KIND_STRING(RightComment)
115+
DIFF_ITEM_KEY_KIND_STRING(ModuleName)
116+
DIFF_ITEM_KEY_KIND_STRING(NewTypeName)
117+
DIFF_ITEM_KEY_KIND_STRING(NewPrintedName)
118+
DIFF_ITEM_KEY_KIND_STRING(OldPrintedName)
119+
120+
DIFF_ITEM_KEY_KIND_INT(SelfIndex)
121+
DIFF_ITEM_KEY_KIND_INT(Index)
122+
123+
#undef DIFF_ITEM_KEY_KIND_INT
124+
#undef DIFF_ITEM_KEY_KIND_STRING
125+
126+
#undef DIFF_ITEM_KEY_KIND
127+
#undef DIFF_ITEM_KIND
85128
#undef KNOWN_TYPE
86129
#undef KEY
87130
#undef DECL_ATTR

0 commit comments

Comments
 (0)