@@ -1768,14 +1768,16 @@ class StorageRestrictionsAttr final
1768
1768
// / The @_implements attribute, which treats a decl as the implementation for
1769
1769
// / some named protocol requirement (but otherwise not-visible by that name).
1770
1770
class ImplementsAttr : public DeclAttribute {
1771
- TypeRepr *TyR;
1771
+ // / If constructed by the \c create() variant with a TypeRepr, the TypeRepr;
1772
+ // / if constructed by the \c create() variant with a DeclContext and
1773
+ // / ProtocolDecl, the DeclContext.
1774
+ llvm::PointerUnion<TypeRepr *, DeclContext *> TyROrDC;
1772
1775
DeclName MemberName;
1773
1776
DeclNameLoc MemberNameLoc;
1774
1777
1775
1778
ImplementsAttr (SourceLoc atLoc, SourceRange Range,
1776
- TypeRepr *TyR,
1777
- DeclName MemberName,
1778
- DeclNameLoc MemberNameLoc);
1779
+ llvm::PointerUnion<TypeRepr *, DeclContext *> TyROrDC,
1780
+ DeclName MemberName, DeclNameLoc MemberNameLoc);
1779
1781
1780
1782
public:
1781
1783
static ImplementsAttr *create (ASTContext &Ctx, SourceLoc atLoc,
@@ -1795,7 +1797,9 @@ class ImplementsAttr : public DeclAttribute {
1795
1797
// / otherwise `nullopt`. This should only be used for dumping.
1796
1798
std::optional<ProtocolDecl *> getCachedProtocol (DeclContext *dc) const ;
1797
1799
1798
- TypeRepr *getProtocolTypeRepr () const { return TyR; }
1800
+ TypeRepr *getProtocolTypeRepr () const {
1801
+ return TyROrDC.dyn_cast <TypeRepr *>();
1802
+ }
1799
1803
1800
1804
DeclName getMemberName () const { return MemberName; }
1801
1805
DeclNameLoc getMemberNameLoc () const { return MemberNameLoc; }
@@ -1806,8 +1810,12 @@ class ImplementsAttr : public DeclAttribute {
1806
1810
1807
1811
// / Create a copy of this attribute.
1808
1812
ImplementsAttr *clone (ASTContext &ctx) const {
1809
- return new (ctx) ImplementsAttr (
1810
- AtLoc, Range, TyR, getMemberName (), getMemberNameLoc ());
1813
+ if (auto tyR = getProtocolTypeRepr ()) {
1814
+ return create (ctx, AtLoc, Range, tyR, getMemberName (),
1815
+ getMemberNameLoc ());
1816
+ }
1817
+ auto dc = TyROrDC.dyn_cast <DeclContext *>();
1818
+ return create (dc, getProtocol (dc), getMemberName ());
1811
1819
}
1812
1820
};
1813
1821
0 commit comments