Skip to content

Commit 53707a1

Browse files
committed
Collapse two implementations into ExistentialLayout::containsNonMarkerProtocols
1 parent c7c152b commit 53707a1

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

include/swift/AST/ExistentialLayout.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct ExistentialLayout {
105105
/// calling this on a temporary is likely to be incorrect.
106106
ArrayRef<ProtocolDecl*> getProtocols() const && = delete;
107107

108+
/// Determine whether this refers to any non-marker protocols.
109+
bool containsNonMarkerProtocols() const;
110+
108111
ArrayRef<ParameterizedProtocolType *> getParameterizedProtocols() const & {
109112
return parameterized;
110113
}

lib/AST/ConformanceLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ swift::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
158158
// If the protocol is SendableMetatype, and there are no non-marker protocol
159159
// requirements, allow it via self-conformance.
160160
if (protocol->isSpecificProtocol(KnownProtocolKind::SendableMetatype) &&
161-
!containsNonMarkerProtocols(layout.getProtocols()))
161+
!layout.containsNonMarkerProtocols())
162162
return ProtocolConformanceRef(ctx.getSelfConformance(protocol));
163163

164164
// We didn't find our protocol in the existential's list; it doesn't

lib/AST/Type.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,15 @@ bool ExistentialLayout::isExistentialWithError(ASTContext &ctx) const {
11861186
return false;
11871187
}
11881188

1189+
bool ExistentialLayout::containsNonMarkerProtocols() const {
1190+
for (auto proto : getProtocols()) {
1191+
if (!proto->isMarkerProtocol())
1192+
return true;
1193+
}
1194+
1195+
return false;
1196+
}
1197+
11891198
LayoutConstraint ExistentialLayout::getLayoutConstraint() const {
11901199
if (hasExplicitAnyObject) {
11911200
return LayoutConstraint::getLayoutConstraint(

lib/SILGen/SILGenDynamicCast.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,6 @@ namespace {
303303
return CastStrategy::Address;
304304
}
305305

306-
static bool containsNonMarkerProtocols(ArrayRef<ProtocolDecl *> protocols) {
307-
for (auto proto : protocols) {
308-
if (!proto->isMarkerProtocol())
309-
return true;
310-
}
311-
312-
return false;
313-
}
314-
315306
CastingIsolatedConformances computedIsolatedConformances() const {
316307
// Non-existential types don't carry conformances, so we always allow
317308
// isolated conformances.
@@ -330,7 +321,7 @@ namespace {
330321
// If there are no non-marker protocols in the existential, there's no
331322
// need to prohibit isolated conformances.
332323
auto layout = checkType->getExistentialLayout();
333-
if (!containsNonMarkerProtocols(layout.getProtocols()))
324+
if (!layout.containsNonMarkerProtocols())
334325
return CastingIsolatedConformances::Allow;
335326

336327
// If the type conforms to SendableMetatype, prohibit isolated

0 commit comments

Comments
 (0)