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