Skip to content

Commit 2c1329e

Browse files
committed
[ClangImporter] Add "suppressed" bit to SynthesizedProtocolAttr
Makes it possible to support `~Sendable` and potentially other suppressible conformances.
1 parent c621295 commit 2c1329e

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

include/swift/AST/Attr.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ class DeclAttribute : public AttributeBase {
256256
kind : NumExternKindBits
257257
);
258258

259-
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute, 1,
260-
isUnchecked : 1
259+
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute, 2,
260+
isUnchecked : 1,
261+
isSuppressed: 1
261262
);
262263

263264
SWIFT_INLINE_BITFIELD(ObjCImplementationAttr, DeclAttribute, 3,
@@ -1754,12 +1755,13 @@ class SynthesizedProtocolAttr : public DeclAttribute {
17541755

17551756
public:
17561757
SynthesizedProtocolAttr(ProtocolDecl *protocol, LazyConformanceLoader *Loader,
1757-
bool isUnchecked)
1758+
bool isUnchecked, bool isSuppressed)
17581759
: DeclAttribute(DeclAttrKind::SynthesizedProtocol, SourceLoc(),
17591760
SourceRange(),
17601761
/*Implicit=*/true),
17611762
Loader(Loader), protocol(protocol) {
17621763
Bits.SynthesizedProtocolAttr.isUnchecked = unsigned(isUnchecked);
1764+
Bits.SynthesizedProtocolAttr.isSuppressed = unsigned(isSuppressed);
17631765
}
17641766

17651767
/// Retrieve the known protocol kind naming the protocol to be
@@ -1772,6 +1774,10 @@ class SynthesizedProtocolAttr : public DeclAttribute {
17721774
return bool(Bits.SynthesizedProtocolAttr.isUnchecked);
17731775
}
17741776

1777+
bool isSuppressed() const {
1778+
return bool(Bits.SynthesizedProtocolAttr.isSuppressed);
1779+
}
1780+
17751781
/// Retrieve the lazy loader that will be used to populate the
17761782
/// synthesized conformance.
17771783
LazyConformanceLoader *getLazyLoader() const { return Loader; }
@@ -1782,12 +1788,13 @@ class SynthesizedProtocolAttr : public DeclAttribute {
17821788

17831789
SynthesizedProtocolAttr *clone(ASTContext &ctx) const {
17841790
return new (ctx) SynthesizedProtocolAttr(
1785-
protocol, getLazyLoader(), isUnchecked());
1791+
protocol, getLazyLoader(), isUnchecked(), isSuppressed());
17861792
}
17871793

17881794
bool isEquivalent(const SynthesizedProtocolAttr *other,
17891795
Decl *attachedTo) const {
17901796
return isUnchecked() == other->isUnchecked()
1797+
&& isSuppressed() == other->isSuppressed()
17911798
&& getProtocol() == other->getProtocol()
17921799
&& getLazyLoader() == other->getLazyLoader();
17931800
}

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8270,6 +8270,7 @@ swift::getInheritedForPrinting(
82708270
// Collect synthesized conformances.
82718271
llvm::SetVector<ProtocolDecl *> protocols;
82728272
llvm::TinyPtrVector<ProtocolDecl *> uncheckedProtocols;
8273+
llvm::TinyPtrVector<ProtocolDecl *> suppressedProtocols;
82738274
for (auto attr : decl->getAttrs().getAttributes<SynthesizedProtocolAttr>()) {
82748275
if (auto *proto = attr->getProtocol()) {
82758276
// FIXME: Reconstitute inverses here
@@ -8289,12 +8290,15 @@ swift::getInheritedForPrinting(
82898290
protocols.insert(proto);
82908291
if (attr->isUnchecked())
82918292
uncheckedProtocols.push_back(proto);
8293+
if (attr->isSuppressed())
8294+
suppressedProtocols.push_back(proto);
82928295
}
82938296
}
82948297

82958298
for (size_t i = 0; i < protocols.size(); i++) {
82968299
auto proto = protocols[i];
82978300
bool isUnchecked = llvm::is_contained(uncheckedProtocols, proto);
8301+
bool isSuppressed = llvm::is_contained(suppressedProtocols, proto);
82988302

82998303
if (!options.shouldPrint(proto)) {
83008304
// If private stdlib protocols are skipped and this is a private stdlib
@@ -8319,7 +8323,7 @@ swift::getInheritedForPrinting(
83198323
if (isUnchecked)
83208324
options |= ProtocolConformanceFlags::Unchecked;
83218325
Results.push_back({TypeLoc::withoutLoc(proto->getDeclaredInterfaceType()),
8322-
options});
8326+
options, isSuppressed});
83238327
}
83248328
}
83258329

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ void ClangImporter::Implementation::addSynthesizedTypealias(
503503

504504
void ClangImporter::Implementation::addSynthesizedProtocolAttrs(
505505
NominalTypeDecl *nominal,
506-
ArrayRef<KnownProtocolKind> synthesizedProtocolAttrs, bool isUnchecked) {
506+
ArrayRef<KnownProtocolKind> synthesizedProtocolAttrs, bool isUnchecked,
507+
bool isSuppressed) {
507508
auto &ctx = nominal->getASTContext();
508509

509510
for (auto kind : synthesizedProtocolAttrs) {
@@ -512,7 +513,7 @@ void ClangImporter::Implementation::addSynthesizedProtocolAttrs(
512513
// ctx.getProtocol(kind) != nulltpr which would be nice.
513514
if (auto proto = ctx.getProtocol(kind))
514515
nominal->addAttribute(
515-
new (ctx) SynthesizedProtocolAttr(proto, this, isUnchecked));
516+
new (ctx) SynthesizedProtocolAttr(proto, this, isUnchecked, isSuppressed));
516517
}
517518
}
518519

@@ -9470,8 +9471,8 @@ void ClangImporter::Implementation::addExplicitProtocolConformance(
94709471
decl->getDeclaredInterfaceType(), conformsToValue);
94719472
}
94729473

9473-
decl->addAttribute(new (SwiftContext)
9474-
SynthesizedProtocolAttr(protocol, this, false));
9474+
decl->addAttribute(new (SwiftContext) SynthesizedProtocolAttr(
9475+
protocol, this, /*isUnchecked=*/false, /*isSuppressed=*/false));
94759476
} else {
94769477
HeaderLoc attrLoc((conformsToAttr)->getLocation());
94779478
diagnose(attrLoc, diag::conforms_to_not_protocol, result,

lib/ClangImporter/ImporterImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,8 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
12641264
void addSynthesizedProtocolAttrs(
12651265
NominalTypeDecl *nominal,
12661266
ArrayRef<KnownProtocolKind> synthesizedProtocolAttrs,
1267-
bool isUnchecked = false);
1267+
bool isUnchecked = false,
1268+
bool isSuppressed = false);
12681269

12691270
void makeComputed(AbstractStorageDecl *storage, AccessorDecl *getter,
12701271
AccessorDecl *setter);

0 commit comments

Comments
 (0)