@@ -842,7 +842,7 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
842842 case SymbolKind::DynamicThunk: return appendOperator (" TD" );
843843 case SymbolKind::SwiftAsObjCThunk: return appendOperator (" To" );
844844 case SymbolKind::ObjCAsSwiftThunk: return appendOperator (" TO" );
845- case SymbolKind::DistributedThunk: return appendOperator (" Td " );
845+ case SymbolKind::DistributedThunk: return appendOperator (" TE " );
846846 }
847847}
848848
@@ -1023,6 +1023,41 @@ void ASTMangler::appendOpaqueDeclName(const OpaqueTypeDecl *opaqueDecl) {
10231023 }
10241024}
10251025
1026+ void ASTMangler::appendExistentialLayout (
1027+ const ExistentialLayout &layout, GenericSignature sig,
1028+ const ValueDecl *forDecl) {
1029+ bool First = true ;
1030+ bool DroppedRequiresClass = false ;
1031+ bool SawRequiresClass = false ;
1032+ for (Type protoTy : layout.getProtocols ()) {
1033+ auto proto = protoTy->castTo <ProtocolType>()->getDecl ();
1034+ // If we aren't allowed to emit marker protocols, suppress them here.
1035+ if (!AllowMarkerProtocols && proto->isMarkerProtocol ()) {
1036+ if (proto->requiresClass ())
1037+ DroppedRequiresClass = true ;
1038+
1039+ continue ;
1040+ }
1041+
1042+ if (proto->requiresClass ())
1043+ SawRequiresClass = true ;
1044+
1045+ appendProtocolName (protoTy->castTo <ProtocolType>()->getDecl ());
1046+ appendListSeparator (First);
1047+ }
1048+ if (First)
1049+ appendOperator (" y" );
1050+
1051+ if (auto superclass = layout.explicitSuperclass ) {
1052+ appendType (superclass, sig, forDecl);
1053+ return appendOperator (" Xc" );
1054+ } else if (layout.hasExplicitAnyObject ||
1055+ (DroppedRequiresClass && !SawRequiresClass)) {
1056+ return appendOperator (" Xl" );
1057+ }
1058+ return appendOperator (" p" );
1059+ }
1060+
10261061// / Mangle a type into the buffer.
10271062// /
10281063void ASTMangler::appendType (Type type, GenericSignature sig,
@@ -1199,31 +1234,15 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
11991234 return appendOperator (" t" );
12001235
12011236 case TypeKind::Protocol: {
1202- bool First = true ;
1203- appendProtocolName (cast<ProtocolType>(tybase)->getDecl ());
1204- appendListSeparator (First);
1205- return appendOperator (" p" );
1237+ return appendExistentialLayout (
1238+ ExistentialLayout (cast<ProtocolType>(tybase)), sig, forDecl);
12061239 }
12071240
12081241 case TypeKind::ProtocolComposition: {
12091242 // We mangle ProtocolType and ProtocolCompositionType using the
12101243 // same production:
1211- bool First = true ;
12121244 auto layout = type->getExistentialLayout ();
1213- for (Type protoTy : layout.getProtocols ()) {
1214- appendProtocolName (protoTy->castTo <ProtocolType>()->getDecl ());
1215- appendListSeparator (First);
1216- }
1217- if (First)
1218- appendOperator (" y" );
1219-
1220- if (auto superclass = layout.explicitSuperclass ) {
1221- appendType (superclass, sig, forDecl);
1222- return appendOperator (" Xc" );
1223- } else if (layout.hasExplicitAnyObject ) {
1224- return appendOperator (" Xl" );
1225- }
1226- return appendOperator (" p" );
1245+ return appendExistentialLayout (layout, sig, forDecl);
12271246 }
12281247
12291248 case TypeKind::UnboundGeneric:
@@ -2220,6 +2239,8 @@ void ASTMangler::appendModule(const ModuleDecl *module,
22202239// / Mangle the name of a protocol as a substitution candidate.
22212240void ASTMangler::appendProtocolName (const ProtocolDecl *protocol,
22222241 bool allowStandardSubstitution) {
2242+ assert (AllowMarkerProtocols || !protocol->isMarkerProtocol ());
2243+
22232244 if (allowStandardSubstitution && tryAppendStandardSubstitution (protocol))
22242245 return ;
22252246
@@ -2370,6 +2391,8 @@ void ASTMangler::appendAnyGenericType(const GenericTypeDecl *decl) {
23702391 appendOperator (" a" );
23712392 break ;
23722393 case DeclKind::Protocol:
2394+ assert (AllowMarkerProtocols ||
2395+ !cast<ProtocolDecl>(decl)->isMarkerProtocol ());
23732396 appendOperator (" P" );
23742397 break ;
23752398 case DeclKind::Class:
@@ -2689,6 +2712,11 @@ void ASTMangler::appendRequirement(const Requirement &reqt,
26892712 case RequirementKind::Layout: {
26902713 } break ;
26912714 case RequirementKind::Conformance: {
2715+ // If we don't allow marker protocols but we have one here, skip it.
2716+ if (!AllowMarkerProtocols &&
2717+ reqt.getProtocolDecl ()->isMarkerProtocol ())
2718+ return ;
2719+
26922720 appendProtocolName (reqt.getProtocolDecl ());
26932721 } break ;
26942722 case RequirementKind::Superclass:
@@ -3226,6 +3254,12 @@ void ASTMangler::appendAnyProtocolConformance(
32263254 GenericSignature genericSig,
32273255 CanType conformingType,
32283256 ProtocolConformanceRef conformance) {
3257+ // If we have a conformance to a marker protocol but we aren't allowed to
3258+ // emit marker protocols, skip it.
3259+ if (!AllowMarkerProtocols &&
3260+ conformance.getRequirement ()->isMarkerProtocol ())
3261+ return ;
3262+
32293263 if (conformingType->isTypeParameter ()) {
32303264 assert (genericSig && " Need a generic signature to resolve conformance" );
32313265 auto path = genericSig->getConformanceAccessPath (conformingType,
0 commit comments