Skip to content

Commit 54dff6f

Browse files
committed
[Mangling] do not mangle invertible protocols
Requirements for invertible protocols are always assumed to exist unless opted-out via an inverse requirement. Thus, it's the absence of those requirements that will (eventually) get mangled into symbols.
1 parent 287297c commit 54dff6f

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,15 @@ void ASTMangler::appendExistentialLayout(
11411141
bool DroppedRequiresClass = false;
11421142
bool SawRequiresClass = false;
11431143
for (auto proto : layout.getProtocols()) {
1144+
// Skip invertible protocols
1145+
//
1146+
// TODO: reconsituteInverses so the absence of such protocols gets mangled.
1147+
// I think here we need to see if any protocols inheritsFrom
1148+
// Copyable/Escapable, and if not, and none of those are found in the layout
1149+
// then it must have had an inverse.
1150+
if (proto->getInvertibleProtocolKind())
1151+
continue;
1152+
11441153
// If we aren't allowed to emit marker protocols, suppress them here.
11451154
if (!AllowMarkerProtocols && proto->isMarkerProtocol()) {
11461155
if (proto->requiresClass())
@@ -2996,14 +3005,28 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
29963005
appendOperator("d");
29973006
}
29983007

3008+
/// Filters out requirements stating that a type conforms to one of the
3009+
/// invertible protocols.
3010+
/// TODO: reconsituteInverses so the absence of conformances gets mangled
3011+
static void withoutInvertibleRequirements(ArrayRef<Requirement> requirements,
3012+
SmallVector<Requirement, 4> &output) {
3013+
for (auto req : requirements) {
3014+
// Skip conformance requirements for invertible protocols.
3015+
if (req.getKind() == RequirementKind::Conformance
3016+
&& req.getProtocolDecl()->getInvertibleProtocolKind())
3017+
continue;
3018+
3019+
output.push_back(req);
3020+
}
3021+
}
3022+
29993023
bool ASTMangler::appendGenericSignature(GenericSignature sig,
30003024
GenericSignature contextSig) {
30013025
auto canSig = sig.getCanonicalSignature();
30023026

30033027
unsigned initialParamDepth;
30043028
ArrayRef<CanTypeWrapper<GenericTypeParamType>> genericParams;
3005-
ArrayRef<Requirement> requirements;
3006-
SmallVector<Requirement, 4> requirementsBuffer;
3029+
SmallVector<Requirement, 4> requirements;
30073030
if (contextSig) {
30083031
// If the signature is the same as the context signature, there's nothing
30093032
// to do.
@@ -3033,16 +3056,16 @@ bool ASTMangler::appendGenericSignature(GenericSignature sig,
30333056
contextSig.getRequirements().empty()) {
30343057
initialParamDepth = 0;
30353058
genericParams = canSig.getGenericParams();
3036-
requirements = canSig.getRequirements();
3059+
withoutInvertibleRequirements(canSig.getRequirements(), requirements);
30373060
} else {
3038-
requirementsBuffer = canSig.requirementsNotSatisfiedBy(contextSig);
3039-
requirements = requirementsBuffer;
3061+
withoutInvertibleRequirements(
3062+
canSig.requirementsNotSatisfiedBy(contextSig), requirements);
30403063
}
30413064
} else {
30423065
// Use the complete canonical signature.
30433066
initialParamDepth = 0;
30443067
genericParams = canSig.getGenericParams();
3045-
requirements = canSig.getRequirements();
3068+
withoutInvertibleRequirements(canSig.getRequirements(), requirements);
30463069
}
30473070

30483071
if (genericParams.empty() && requirements.empty())

0 commit comments

Comments
 (0)