Skip to content

Commit 953ffc3

Browse files
committed
[NFC] Let SynthesizedProtocolAttrs be @unchecked
This is not yet used by anything.
1 parent 78ef550 commit 953ffc3

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

include/swift/AST/Attr.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ class DeclAttribute : public AttributeBase {
168168
);
169169

170170
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute,
171-
NumKnownProtocolKindBits,
172-
kind : NumKnownProtocolKindBits
171+
NumKnownProtocolKindBits+1,
172+
kind : NumKnownProtocolKindBits,
173+
isUnchecked : 1
173174
);
174175
} Bits;
175176

@@ -1276,11 +1277,13 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12761277

12771278
public:
12781279
SynthesizedProtocolAttr(KnownProtocolKind protocolKind,
1279-
LazyConformanceLoader *Loader)
1280+
LazyConformanceLoader *Loader,
1281+
bool isUnchecked)
12801282
: DeclAttribute(DAK_SynthesizedProtocol, SourceLoc(), SourceRange(),
12811283
/*Implicit=*/true), Loader(Loader)
12821284
{
12831285
Bits.SynthesizedProtocolAttr.kind = unsigned(protocolKind);
1286+
Bits.SynthesizedProtocolAttr.isUnchecked = unsigned(isUnchecked);
12841287
}
12851288

12861289
/// Retrieve the known protocol kind naming the protocol to be
@@ -1289,6 +1292,10 @@ class SynthesizedProtocolAttr : public DeclAttribute {
12891292
return KnownProtocolKind(Bits.SynthesizedProtocolAttr.kind);
12901293
}
12911294

1295+
bool isUnchecked() const {
1296+
return bool(Bits.SynthesizedProtocolAttr.isUnchecked);
1297+
}
1298+
12921299
/// Retrieve the lazy loader that will be used to populate the
12931300
/// synthesized conformance.
12941301
LazyConformanceLoader *getLazyLoader() const { return Loader; }

include/swift/AST/ProtocolConformance.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ class NormalProtocolConformance : public RootProtocolConformance,
514514
return ContextAndBits.getInt() & UncheckedFlag;
515515
}
516516

517+
/// Mark the conformance as unchecked (equivalent to the @unchecked
518+
/// conformance attribute).
519+
void setUnchecked() {
520+
// OK to mutate because the flags are not part of the folding set node ID.
521+
ContextAndBits.setInt(ContextAndBits.getInt() | UncheckedFlag);
522+
}
523+
517524
/// Get the kind of source from which this conformance comes.
518525
ConformanceEntryKind getSourceKind() const {
519526
return SourceKindAndImplyingConformance.getInt();

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5901,6 +5901,7 @@ swift::getInheritedForPrinting(
59015901
// Collect synthesized conformances.
59025902
auto &ctx = decl->getASTContext();
59035903
llvm::SetVector<ProtocolDecl *> protocols;
5904+
llvm::TinyPtrVector<ProtocolDecl *> uncheckedProtocols;
59045905
for (auto attr : decl->getAttrs().getAttributes<SynthesizedProtocolAttr>()) {
59055906
if (auto *proto = ctx.getProtocol(attr->getProtocolKind())) {
59065907
// The SerialExecutor conformance is only synthesized on the root
@@ -5913,11 +5914,14 @@ swift::getInheritedForPrinting(
59135914
cast<EnumDecl>(decl)->hasRawType())
59145915
continue;
59155916
protocols.insert(proto);
5917+
if (attr->isUnchecked())
5918+
uncheckedProtocols.push_back(proto);
59165919
}
59175920
}
59185921

59195922
for (size_t i = 0; i < protocols.size(); i++) {
59205923
auto proto = protocols[i];
5924+
bool isUnchecked = llvm::is_contained(uncheckedProtocols, proto);
59215925

59225926
if (!options.shouldPrint(proto)) {
59235927
// If private stdlib protocols are skipped and this is a private stdlib
@@ -5928,12 +5932,14 @@ swift::getInheritedForPrinting(
59285932
proto->isPrivateStdlibDecl(!options.SkipUnderscoredStdlibProtocols)) {
59295933
auto inheritedProtocols = proto->getInheritedProtocols();
59305934
protocols.insert(inheritedProtocols.begin(), inheritedProtocols.end());
5935+
if (isUnchecked)
5936+
copy(inheritedProtocols, std::back_inserter(uncheckedProtocols));
59315937
}
59325938
continue;
59335939
}
59345940

59355941
Results.push_back({TypeLoc::withoutLoc(proto->getDeclaredInterfaceType()),
5936-
/*isUnchecked=*/false});
5942+
isUnchecked});
59375943
}
59385944
}
59395945

lib/AST/ConformanceLookupTable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ ConformanceLookupTable::getConformance(NominalTypeDecl *nominal,
904904
// Set the conformance loader to the loader stashed inside
905905
// the attribute.
906906
normalConf->setLazyLoader(attr->getLazyLoader(), /*context=*/0);
907+
if (attr->isUnchecked())
908+
normalConf->setUnchecked();
907909
break;
908910
}
909911
}

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,12 @@ createValueConstructor(ClangImporter::Implementation &Impl,
14681468
static void addSynthesizedProtocolAttrs(
14691469
ClangImporter::Implementation &Impl,
14701470
NominalTypeDecl *nominal,
1471-
ArrayRef<KnownProtocolKind> synthesizedProtocolAttrs) {
1471+
ArrayRef<KnownProtocolKind> synthesizedProtocolAttrs,
1472+
bool isUnchecked = false) {
14721473
for (auto kind : synthesizedProtocolAttrs) {
14731474
nominal->getAttrs().add(new (Impl.SwiftContext)
1474-
SynthesizedProtocolAttr(kind, &Impl));
1475+
SynthesizedProtocolAttr(kind, &Impl,
1476+
isUnchecked));
14751477
}
14761478
}
14771479

0 commit comments

Comments
 (0)