Skip to content

Commit deed2d2

Browse files
committed
Suppress printing of implicit opaque generic parameters
When printing the generic parameters and requirements clauses of declarations that involve opaque parameters, suppress the implicit generic parameters created by the opaque parameters as well as the generic requirements that involve said parameters.
1 parent 4c9bca9 commit deed2d2

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,42 @@ void PrintAST::printSingleDepthOfGenericSignature(
16581658
});
16591659
};
16601660

1661-
if (printParams) {
1661+
/// Separate the explicit generic parameters from the implicit, opaque
1662+
/// generic parameters. We only print the former.
1663+
TypeArrayView<GenericTypeParamType> opaqueGenericParams;
1664+
for (unsigned index : indices(genericParams)) {
1665+
auto gpDecl = genericParams[index]->getDecl();
1666+
if (!gpDecl)
1667+
continue;
1668+
1669+
if (gpDecl->isOpaqueType() && gpDecl->isImplicit()) {
1670+
// We found the first implicit opaque type parameter. Split the
1671+
// generic parameters array at this position.
1672+
opaqueGenericParams = genericParams.slice(index);
1673+
genericParams = genericParams.slice(0, index);
1674+
break;
1675+
}
1676+
}
1677+
1678+
// Determines whether a given type is based on one of the opaque generic
1679+
// parameters.
1680+
auto dependsOnOpaque = [&](Type type) {
1681+
if (opaqueGenericParams.empty())
1682+
return false;
1683+
1684+
if (!type->isTypeParameter())
1685+
return false;
1686+
1687+
auto rootGP = type->getRootGenericParam();
1688+
for (auto opaqueGP : opaqueGenericParams) {
1689+
if (rootGP->isEqual(opaqueGP))
1690+
return true;
1691+
}
1692+
1693+
return false;
1694+
};
1695+
1696+
if (printParams && !genericParams.empty()) {
16621697
// Print the generic parameters.
16631698
Printer << "<";
16641699
llvm::interleave(
@@ -1686,10 +1721,17 @@ void PrintAST::printSingleDepthOfGenericSignature(
16861721
continue;
16871722

16881723
auto first = req.getFirstType();
1724+
1725+
if (dependsOnOpaque(first))
1726+
continue;
1727+
16891728
Type second;
16901729

1691-
if (req.getKind() != RequirementKind::Layout)
1730+
if (req.getKind() != RequirementKind::Layout) {
16921731
second = req.getSecondType();
1732+
if (dependsOnOpaque(second))
1733+
continue;
1734+
}
16931735

16941736
if (!subMap.empty()) {
16951737
Type subFirst = substParam(first);
@@ -1748,7 +1790,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
17481790
}
17491791
}
17501792

1751-
if (printParams)
1793+
if (printParams && !genericParams.empty())
17521794
Printer << ">";
17531795
}
17541796

0 commit comments

Comments
 (0)