Skip to content

Commit bbc4d42

Browse files
committed
AST: Refactor the mangler to use getRequirementsWithInverses()
1 parent 7a2e178 commit bbc4d42

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,35 +3005,29 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
30053005
appendOperator("d");
30063006
}
30073007

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-
30233008
bool ASTMangler::appendGenericSignature(GenericSignature sig,
30243009
GenericSignature contextSig) {
30253010
auto canSig = sig.getCanonicalSignature();
30263011

3012+
// FIXME: We just ignore invertible requirements for now.
3013+
SmallVector<Requirement, 2> reqs;
3014+
SmallVector<InverseRequirement, 2> inverseReqs;
3015+
canSig->getRequirementsWithInverses(reqs, inverseReqs);
3016+
30273017
unsigned initialParamDepth;
30283018
ArrayRef<CanTypeWrapper<GenericTypeParamType>> genericParams;
3029-
SmallVector<Requirement, 4> requirements;
30303019
if (contextSig) {
30313020
// If the signature is the same as the context signature, there's nothing
30323021
// to do.
30333022
if (contextSig.getCanonicalSignature() == canSig) {
30343023
return false;
30353024
}
30363025

3026+
// FIXME: We just ignore invertible requirements for now.
3027+
SmallVector<Requirement, 2> contextReqs;
3028+
SmallVector<InverseRequirement, 2> contextInverseReqs;
3029+
contextSig->getRequirementsWithInverses(contextReqs, contextInverseReqs);
3030+
30373031
// The signature depth starts above the depth of the context signature.
30383032
if (!contextSig.getGenericParams().empty()) {
30393033
initialParamDepth = contextSig.getGenericParams().back()->getDepth() + 1;
@@ -3053,26 +3047,25 @@ bool ASTMangler::appendGenericSignature(GenericSignature sig,
30533047
// have a special-case mangling for that.
30543048
if (genericParams.empty() &&
30553049
contextSig.getGenericParams().size() == 1 &&
3056-
contextSig.getRequirements().empty()) {
3050+
contextReqs.empty()) {
30573051
initialParamDepth = 0;
30583052
genericParams = canSig.getGenericParams();
3059-
withoutInvertibleRequirements(canSig.getRequirements(), requirements);
30603053
} else {
3061-
withoutInvertibleRequirements(
3062-
canSig.requirementsNotSatisfiedBy(contextSig), requirements);
3054+
llvm::erase_if(reqs, [&](Requirement req) {
3055+
return contextSig->isRequirementSatisfied(req);
3056+
});
30633057
}
30643058
} else {
30653059
// Use the complete canonical signature.
30663060
initialParamDepth = 0;
30673061
genericParams = canSig.getGenericParams();
3068-
withoutInvertibleRequirements(canSig.getRequirements(), requirements);
30693062
}
30703063

3071-
if (genericParams.empty() && requirements.empty())
3064+
if (genericParams.empty() && reqs.empty())
30723065
return false;
30733066

30743067
appendGenericSignatureParts(sig, genericParams,
3075-
initialParamDepth, requirements);
3068+
initialParamDepth, reqs);
30763069
return true;
30773070
}
30783071

0 commit comments

Comments
 (0)