@@ -1020,6 +1020,40 @@ void ASTMangler::appendOpaqueDeclName(const OpaqueTypeDecl *opaqueDecl) {
1020
1020
}
1021
1021
}
1022
1022
1023
+ void ASTMangler::appendExistentialLayout (
1024
+ const ExistentialLayout &layout, const ValueDecl *forDecl) {
1025
+ bool First = true ;
1026
+ bool DroppedRequiresClass = false ;
1027
+ bool SawRequiresClass = false ;
1028
+ for (Type protoTy : layout.getProtocols ()) {
1029
+ auto proto = protoTy->castTo <ProtocolType>()->getDecl ();
1030
+ // If we aren't allowed to emit marker protocols, suppress them here.
1031
+ if (!AllowMarkerProtocols && proto->isMarkerProtocol ()) {
1032
+ if (proto->requiresClass ())
1033
+ DroppedRequiresClass = true ;
1034
+
1035
+ continue ;
1036
+ }
1037
+
1038
+ if (proto->requiresClass ())
1039
+ SawRequiresClass = true ;
1040
+
1041
+ appendProtocolName (protoTy->castTo <ProtocolType>()->getDecl ());
1042
+ appendListSeparator (First);
1043
+ }
1044
+ if (First)
1045
+ appendOperator (" y" );
1046
+
1047
+ if (auto superclass = layout.explicitSuperclass ) {
1048
+ appendType (superclass, forDecl);
1049
+ return appendOperator (" Xc" );
1050
+ } else if (layout.hasExplicitAnyObject ||
1051
+ (DroppedRequiresClass && !SawRequiresClass)) {
1052
+ return appendOperator (" Xl" );
1053
+ }
1054
+ return appendOperator (" p" );
1055
+ }
1056
+
1023
1057
// / Mangle a type into the buffer.
1024
1058
// /
1025
1059
void ASTMangler::appendType (Type type, const ValueDecl *forDecl) {
@@ -1189,31 +1223,15 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
1189
1223
return appendOperator (" t" );
1190
1224
1191
1225
case TypeKind::Protocol: {
1192
- bool First = true ;
1193
- appendProtocolName (cast<ProtocolType>(tybase)->getDecl ());
1194
- appendListSeparator (First);
1195
- return appendOperator (" p" );
1226
+ return appendExistentialLayout (
1227
+ ExistentialLayout (cast<ProtocolType>(tybase)), forDecl);
1196
1228
}
1197
1229
1198
1230
case TypeKind::ProtocolComposition: {
1199
1231
// We mangle ProtocolType and ProtocolCompositionType using the
1200
1232
// same production:
1201
- bool First = true ;
1202
1233
auto layout = type->getExistentialLayout ();
1203
- for (Type protoTy : layout.getProtocols ()) {
1204
- appendProtocolName (protoTy->castTo <ProtocolType>()->getDecl ());
1205
- appendListSeparator (First);
1206
- }
1207
- if (First)
1208
- appendOperator (" y" );
1209
-
1210
- if (auto superclass = layout.explicitSuperclass ) {
1211
- appendType (superclass, forDecl);
1212
- return appendOperator (" Xc" );
1213
- } else if (layout.hasExplicitAnyObject ) {
1214
- return appendOperator (" Xl" );
1215
- }
1216
- return appendOperator (" p" );
1234
+ return appendExistentialLayout (layout, forDecl);
1217
1235
}
1218
1236
1219
1237
case TypeKind::UnboundGeneric:
@@ -2196,6 +2214,8 @@ void ASTMangler::appendModule(const ModuleDecl *module,
2196
2214
// / Mangle the name of a protocol as a substitution candidate.
2197
2215
void ASTMangler::appendProtocolName (const ProtocolDecl *protocol,
2198
2216
bool allowStandardSubstitution) {
2217
+ assert (AllowMarkerProtocols || !protocol->isMarkerProtocol ());
2218
+
2199
2219
if (allowStandardSubstitution && tryAppendStandardSubstitution (protocol))
2200
2220
return ;
2201
2221
@@ -2344,6 +2364,8 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
2344
2364
appendOperator (" a" );
2345
2365
break ;
2346
2366
case DeclKind::Protocol:
2367
+ assert (AllowMarkerProtocols ||
2368
+ !cast<ProtocolDecl>(decl)->isMarkerProtocol ());
2347
2369
appendOperator (" P" );
2348
2370
break ;
2349
2371
case DeclKind::Class:
@@ -2657,6 +2679,11 @@ void ASTMangler::appendRequirement(const Requirement &reqt) {
2657
2679
case RequirementKind::Layout: {
2658
2680
} break ;
2659
2681
case RequirementKind::Conformance: {
2682
+ // If we don't allow marker protocols but we have one here, skip it.
2683
+ if (!AllowMarkerProtocols &&
2684
+ reqt.getProtocolDecl ()->isMarkerProtocol ())
2685
+ return ;
2686
+
2660
2687
appendProtocolName (reqt.getProtocolDecl ());
2661
2688
} break ;
2662
2689
case RequirementKind::Superclass:
@@ -3187,6 +3214,12 @@ void ASTMangler::appendAnyProtocolConformance(
3187
3214
CanGenericSignature genericSig,
3188
3215
CanType conformingType,
3189
3216
ProtocolConformanceRef conformance) {
3217
+ // If we have a conformance to a marker protocol but we aren't allowed to
3218
+ // emit marker protocols, skip it.
3219
+ if (!AllowMarkerProtocols &&
3220
+ conformance.getRequirement ()->isMarkerProtocol ())
3221
+ return ;
3222
+
3190
3223
if (conformingType->isTypeParameter ()) {
3191
3224
assert (genericSig && " Need a generic signature to resolve conformance" );
3192
3225
auto path = genericSig->getConformanceAccessPath (conformingType,
0 commit comments