Distinguish conformance and superclass generic requirements.

As part of this, use a different enum for parsed generic requirements.

NFC except that I noticed that ASTWalker wasn't visiting the second
type in a conformance constraint; fixing this seems to have no effect
beyond producing better IDE annotations.
This commit is contained in:
John McCall
2016-01-11 16:02:48 -08:00
parent 0b8468d36b
commit 1f3b3142b4
25 changed files with 246 additions and 196 deletions

View File

@@ -650,6 +650,7 @@ Type Mangler::getDeclTypeForMangling(const ValueDecl *decl,
continue;
case RequirementKind::Conformance:
case RequirementKind::Superclass:
// We don't need the requirement if the constrained type is above the
// method depth.
if (!genericParamIsBelowDepth(reqt.getFirstType(), initialParamDepth))
@@ -766,26 +767,28 @@ mangle_requirements:
case RequirementKind::WitnessMarker:
break;
case RequirementKind::Conformance: {
case RequirementKind::Conformance:
if (!didMangleRequirement) {
Buffer << 'R';
didMangleRequirement = true;
}
SmallVector<ProtocolDecl *, 2> protocols;
if (reqt.getSecondType()->isExistentialType(protocols)
&& protocols.size() == 1) {
// Protocol constraints are the common case, so mangle them more
// efficiently.
// TODO: We could golf this a little more by assuming the first type
// is a dependent type.
mangleConstrainedType(reqt.getFirstType()->getCanonicalType());
mangleProtocolName(protocols[0]);
break;
// Protocol constraints are the common case, so mangle them more
// efficiently.
// TODO: We could golf this a little more by assuming the first type
// is a dependent type.
mangleConstrainedType(reqt.getFirstType()->getCanonicalType());
mangleProtocolName(
reqt.getSecondType()->castTo<ProtocolType>()->getDecl());
break;
case RequirementKind::Superclass:
if (!didMangleRequirement) {
Buffer << 'R';
didMangleRequirement = true;
}
mangleConstrainedType(reqt.getFirstType()->getCanonicalType());
mangleType(reqt.getSecondType()->getCanonicalType(), 0);
break;
}
case RequirementKind::SameType:
if (!didMangleRequirement) {