@@ -228,23 +228,23 @@ static StringRef getKeyContent(KeyKind Kind) {
228228}
229229
230230// The node kind appearing in the tree that describes the content of the SDK
231- enum class SDKNodeKind {
231+ enum class SDKNodeKind : uint8_t {
232232#define NODE_KIND (NAME ) NAME,
233233#include " DigesterEnums.def"
234234};
235235
236- enum class NodeAnnotation {
236+ enum class NodeAnnotation : uint8_t {
237237#define NODE_ANNOTATION (NAME ) NAME,
238238#include " DigesterEnums.def"
239239};
240240
241- enum class KnownTypeKind {
241+ enum class KnownTypeKind : uint8_t {
242242#define KNOWN_TYPE (NAME ) NAME,
243243#include " DigesterEnums.def"
244244 Unknown,
245245};
246246
247- enum class SDKDeclAttrKind {
247+ enum class SDKDeclAttrKind : uint8_t {
248248#define DECL_ATTR (Name ) DAK_##Name,
249249#include " DigesterEnums.def"
250250};
@@ -283,6 +283,7 @@ struct SDKNodeInitInfo {
283283 bool IsMutating = false ;
284284 bool IsStatic = false ;
285285 Optional<uint8_t > SelfIndex;
286+ Ownership Ownership = Ownership::Strong;
286287 std::vector<SDKDeclAttrKind> DeclAttrs;
287288 std::vector<TypeAttrKind> TypeAttrs;
288289 SDKNodeInitInfo () = default ;
@@ -344,20 +345,22 @@ class SDKNodeDecl : public SDKNode {
344345 StringRef ModuleName;
345346 std::vector<SDKDeclAttrKind> DeclAttributes;
346347 bool IsStatic;
348+ uint8_t Ownership;
347349 bool hasDeclAttribute (SDKDeclAttrKind DAKind) const ;
348350
349351protected:
350352 SDKNodeDecl (SDKNodeInitInfo Info, SDKNodeKind Kind) : SDKNode(Info, Kind),
351353 DKind (Info.DKind), Usr(Info.USR), Location(Info.Location),
352354 ModuleName(Info.ModuleName), DeclAttributes(Info.DeclAttrs),
353- IsStatic(Info.IsStatic) {}
355+ IsStatic(Info.IsStatic), Ownership( uint8_t (Info.Ownership)) {}
354356
355357public:
356358 StringRef getUsr () const { return Usr; }
357359 StringRef getLocation () const { return Location; }
358360 StringRef getModuleName () const {return ModuleName;}
359361 void addDeclAttribute (SDKDeclAttrKind DAKind);
360362 ArrayRef<SDKDeclAttrKind> getDeclAttributes () const ;
363+ swift::Ownership getOwnership () const { return swift::Ownership (Ownership); }
361364 bool isObjc () const { return Usr.startswith (" c:" ); }
362365 static bool classof (const SDKNode *N);
363366 DeclKind getDeclKind () const { return DKind; }
@@ -762,6 +765,10 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
762765 auto WithQuote = cast<llvm::yaml::ScalarNode>(N)->getRawValue ();
763766 return WithQuote.substr (1 , WithQuote.size () - 2 );
764767 };
768+
769+ static auto getAsInt = [&](llvm::yaml::Node *N) -> int {
770+ return std::stoi (cast<llvm::yaml::ScalarNode>(N)->getRawValue ());
771+ };
765772 SDKNodeKind Kind;
766773 SDKNodeInitInfo Info;
767774 NodeOwnedVector Children;
@@ -778,8 +785,7 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
778785 Info.Name = GetScalarString (Pair.getValue ());
779786 break ;
780787 case KeyKind::KK_selfIndex:
781- Info.SelfIndex = std::stoi (cast<llvm::yaml::ScalarNode>(Pair.getValue ())->
782- getRawValue ());
788+ Info.SelfIndex = getAsInt (Pair.getValue ());
783789 break ;
784790 case KeyKind::KK_usr:
785791 Info.USR = GetScalarString (Pair.getValue ());
@@ -808,6 +814,10 @@ NodeUniquePtr SDKNode::constructSDKNode(llvm::yaml::MappingNode *Node) {
808814 case KeyKind::KK_static:
809815 Info.IsStatic = true ;
810816 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 ;
811821
812822 case KeyKind::KK_typeAttributes: {
813823 auto *Seq = cast<llvm::yaml::SequenceNode>(Pair.getValue ());
@@ -1013,6 +1023,13 @@ static Optional<uint8_t> getSelfIndex(ValueDecl *VD) {
10131023 return None;
10141024}
10151025
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+
10161033SDKNodeInitInfo::SDKNodeInitInfo (Type Ty) : Name(getTypeName(Ty)),
10171034 PrintedName (getPrintedName(Ty)) {
10181035 if (isFunctionTypeNoEscape (Ty))
@@ -1025,7 +1042,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(ValueDecl *VD) :
10251042 USR(calculateUsr(VD)), Location(calculateLocation(VD)),
10261043 ModuleName(VD->getModuleContext ()->getName().str()),
10271044 IsThrowing(isFuncThrowing(VD)), IsMutating(isFuncMutating(VD)),
1028- IsStatic(VD->isStatic ()), SelfIndex(getSelfIndex(VD)) {
1045+ IsStatic(VD->isStatic ()), SelfIndex(getSelfIndex(VD)),
1046+ Ownership(getOwnership(VD)) {
10291047 if (VD->getAttrs ().getDeprecated (VD->getASTContext ()))
10301048 DeclAttrs.push_back (SDKDeclAttrKind::DAK_deprecated);
10311049}
@@ -1383,6 +1401,11 @@ namespace swift {
13831401 if (!Attributes.empty ())
13841402 out.mapRequired (getKeyContent (KeyKind::KK_declAttributes).data (),
13851403 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+ }
13861409 } else if (auto T = dyn_cast<SDKNodeType>(value.get ())) {
13871410 auto Attributes = T->getTypeAttributes ();
13881411 if (!Attributes.empty ())
0 commit comments