@@ -228,23 +228,23 @@ static StringRef getKeyContent(KeyKind Kind) {
228
228
}
229
229
230
230
// The node kind appearing in the tree that describes the content of the SDK
231
- enum class SDKNodeKind {
231
+ enum class SDKNodeKind : uint8_t {
232
232
#define NODE_KIND (NAME ) NAME,
233
233
#include " DigesterEnums.def"
234
234
};
235
235
236
- enum class NodeAnnotation {
236
+ enum class NodeAnnotation : uint8_t {
237
237
#define NODE_ANNOTATION (NAME ) NAME,
238
238
#include " DigesterEnums.def"
239
239
};
240
240
241
- enum class KnownTypeKind {
241
+ enum class KnownTypeKind : uint8_t {
242
242
#define KNOWN_TYPE (NAME ) NAME,
243
243
#include " DigesterEnums.def"
244
244
Unknown,
245
245
};
246
246
247
- enum class SDKDeclAttrKind {
247
+ enum class SDKDeclAttrKind : uint8_t {
248
248
#define DECL_ATTR (Name ) DAK_##Name,
249
249
#include " DigesterEnums.def"
250
250
};
@@ -283,6 +283,7 @@ struct SDKNodeInitInfo {
283
283
bool IsMutating = false ;
284
284
bool IsStatic = false ;
285
285
Optional<uint8_t > SelfIndex;
286
+ Ownership Ownership = Ownership::Strong;
286
287
std::vector<SDKDeclAttrKind> DeclAttrs;
287
288
std::vector<TypeAttrKind> TypeAttrs;
288
289
SDKNodeInitInfo () = default ;
@@ -344,20 +345,22 @@ class SDKNodeDecl : public SDKNode {
344
345
StringRef ModuleName;
345
346
std::vector<SDKDeclAttrKind> DeclAttributes;
346
347
bool IsStatic;
348
+ uint8_t Ownership;
347
349
bool hasDeclAttribute (SDKDeclAttrKind DAKind) const ;
348
350
349
351
protected:
350
352
SDKNodeDecl (SDKNodeInitInfo Info, SDKNodeKind Kind) : SDKNode(Info, Kind),
351
353
DKind (Info.DKind), Usr(Info.USR), Location(Info.Location),
352
354
ModuleName(Info.ModuleName), DeclAttributes(Info.DeclAttrs),
353
- IsStatic(Info.IsStatic) {}
355
+ IsStatic(Info.IsStatic), Ownership( uint8_t (Info.Ownership)) {}
354
356
355
357
public:
356
358
StringRef getUsr () const { return Usr; }
357
359
StringRef getLocation () const { return Location; }
358
360
StringRef getModuleName () const {return ModuleName;}
359
361
void addDeclAttribute (SDKDeclAttrKind DAKind);
360
362
ArrayRef<SDKDeclAttrKind> getDeclAttributes () const ;
363
+ swift::Ownership getOwnership () const { return swift::Ownership (Ownership); }
361
364
bool isObjc () const { return Usr.startswith (" c:" ); }
362
365
static bool classof (const SDKNode *N);
363
366
DeclKind getDeclKind () const { return DKind; }
@@ -762,6 +765,10 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
762
765
auto WithQuote = cast<llvm::yaml::ScalarNode>(N)->getRawValue ();
763
766
return WithQuote.substr (1 , WithQuote.size () - 2 );
764
767
};
768
+
769
+ static auto getAsInt = [&](llvm::yaml::Node *N) -> int {
770
+ return std::stoi (cast<llvm::yaml::ScalarNode>(N)->getRawValue ());
771
+ };
765
772
SDKNodeKind Kind;
766
773
SDKNodeInitInfo Info;
767
774
NodeOwnedVector Children;
@@ -778,8 +785,7 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
778
785
Info.Name = GetScalarString (Pair.getValue ());
779
786
break ;
780
787
case KeyKind::KK_selfIndex:
781
- Info.SelfIndex = std::stoi (cast<llvm::yaml::ScalarNode>(Pair.getValue ())->
782
- getRawValue ());
788
+ Info.SelfIndex = getAsInt (Pair.getValue ());
783
789
break ;
784
790
case KeyKind::KK_usr:
785
791
Info.USR = GetScalarString (Pair.getValue ());
@@ -808,6 +814,10 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
808
814
case KeyKind::KK_static:
809
815
Info.IsStatic = true ;
810
816
break ;
817
+ case KeyKind::KK_ownership:
818
+ Info.Ownership = swift::Ownership (getAsInt (Pair.getValue ()));
819
+ assert (Info.Ownership != swift::Ownership::Strong && " Stong is implied." );
820
+ break ;
811
821
812
822
case KeyKind::KK_typeAttributes: {
813
823
auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue ());
@@ -1013,6 +1023,13 @@ static Optional<uint8_t> getSelfIndex(ValueDecl *VD) {
1013
1023
return None;
1014
1024
}
1015
1025
1026
+ static Ownership getOwnership (ValueDecl *VD) {
1027
+ if (auto OA = VD->getAttrs ().getAttribute <OwnershipAttr>()) {
1028
+ return OA->get ();
1029
+ }
1030
+ return Ownership::Strong;
1031
+ }
1032
+
1016
1033
SDKNodeInitInfo::SDKNodeInitInfo (Type Ty) : Name(getTypeName(Ty)),
1017
1034
PrintedName (getPrintedName(Ty)) {
1018
1035
if (isFunctionTypeNoEscape (Ty))
@@ -1025,7 +1042,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(ValueDecl *VD) :
1025
1042
USR(calculateUsr(VD)), Location(calculateLocation(VD)),
1026
1043
ModuleName(VD->getModuleContext ()->getName().str()),
1027
1044
IsThrowing(isFuncThrowing(VD)), IsMutating(isFuncMutating(VD)),
1028
- IsStatic(VD->isStatic ()), SelfIndex(getSelfIndex(VD)) {
1045
+ IsStatic(VD->isStatic ()), SelfIndex(getSelfIndex(VD)),
1046
+ Ownership(getOwnership(VD)) {
1029
1047
if (VD->getAttrs ().getDeprecated (VD->getASTContext ()))
1030
1048
DeclAttrs.push_back (SDKDeclAttrKind::DAK_deprecated);
1031
1049
}
@@ -1383,6 +1401,11 @@ namespace swift {
1383
1401
if (!Attributes.empty ())
1384
1402
out.mapRequired (getKeyContent (KeyKind::KK_declAttributes).data (),
1385
1403
Attributes);
1404
+ // Strong reference is implied, no need for serialization.
1405
+ if (D->getOwnership () != Ownership::Strong) {
1406
+ uint8_t Raw = uint8_t (D->getOwnership ());
1407
+ out.mapRequired (getKeyContent (KeyKind::KK_ownership).data (), Raw);
1408
+ }
1386
1409
} else if (auto T = dyn_cast<SDKNodeType>(value.get ())) {
1387
1410
auto Attributes = T->getTypeAttributes ();
1388
1411
if (!Attributes.empty ())
0 commit comments