@@ -1752,14 +1752,16 @@ class StorageRestrictionsAttr final
1752
1752
// / The @_implements attribute, which treats a decl as the implementation for
1753
1753
// / some named protocol requirement (but otherwise not-visible by that name).
1754
1754
class ImplementsAttr : public DeclAttribute {
1755
- TypeRepr *TyR;
1755
+ // / If constructed by the \c create() variant with a TypeRepr, the TypeRepr;
1756
+ // / if constructed by the \c create() variant with a DeclContext and
1757
+ // / ProtocolDecl, the DeclContext.
1758
+ llvm::PointerUnion<TypeRepr *, DeclContext *> TyROrDC;
1756
1759
DeclName MemberName;
1757
1760
DeclNameLoc MemberNameLoc;
1758
1761
1759
1762
ImplementsAttr (SourceLoc atLoc, SourceRange Range,
1760
- TypeRepr *TyR,
1761
- DeclName MemberName,
1762
- DeclNameLoc MemberNameLoc);
1763
+ llvm::PointerUnion<TypeRepr *, DeclContext *> TyROrDC,
1764
+ DeclName MemberName, DeclNameLoc MemberNameLoc);
1763
1765
1764
1766
public:
1765
1767
static ImplementsAttr *create (ASTContext &Ctx, SourceLoc atLoc,
@@ -1779,7 +1781,9 @@ class ImplementsAttr : public DeclAttribute {
1779
1781
// / otherwise `nullopt`. This should only be used for dumping.
1780
1782
std::optional<ProtocolDecl *> getCachedProtocol (DeclContext *dc) const ;
1781
1783
1782
- TypeRepr *getProtocolTypeRepr () const { return TyR; }
1784
+ TypeRepr *getProtocolTypeRepr () const {
1785
+ return TyROrDC.dyn_cast <TypeRepr *>();
1786
+ }
1783
1787
1784
1788
DeclName getMemberName () const { return MemberName; }
1785
1789
DeclNameLoc getMemberNameLoc () const { return MemberNameLoc; }
@@ -1790,8 +1794,12 @@ class ImplementsAttr : public DeclAttribute {
1790
1794
1791
1795
// / Create a copy of this attribute.
1792
1796
ImplementsAttr *clone (ASTContext &ctx) const {
1793
- return new (ctx) ImplementsAttr (
1794
- AtLoc, Range, TyR, getMemberName (), getMemberNameLoc ());
1797
+ if (auto tyR = getProtocolTypeRepr ()) {
1798
+ return create (ctx, AtLoc, Range, tyR, getMemberName (),
1799
+ getMemberNameLoc ());
1800
+ }
1801
+ auto dc = TyROrDC.dyn_cast <DeclContext *>();
1802
+ return create (dc, getProtocol (dc), getMemberName ());
1795
1803
}
1796
1804
};
1797
1805
0 commit comments