[GSB] Properly apply rewrite rules for generic params -> generic params.

Although we were properly recording rewrite rules like tau_0_1 -> tau_0_0
in the rewrite tree, we were failing to apply them, so tau_0_1 wouldn’t
get properly canonicalized. Fix this, and add some assertions to make sure
we catch this with our current test suite.

Fixes rdar://problem/37469390.
This commit is contained in:
Doug Gregor
2018-02-16 11:19:35 -08:00
parent 20ffe48425
commit 31279be0cc

View File

@@ -3293,17 +3293,19 @@ RewriteTreeNode::bestMatch(GenericParamKey base, RelativeRewritePath path,
[&](unsigned length, RewritePath path) {
// Determine how much of the original path will be replaced by the rewrite.
unsigned adjustedLength = length;
bool changesBase = false;
if (auto newBase = path.getBase()) {
adjustedLength += prefixLength;
// If the base is unchanged, make sure we're reducing the length.
if (*newBase == base && adjustedLength <= path.getPath().size())
changesBase = *newBase != base;
if (!changesBase && adjustedLength <= path.getPath().size())
return;
}
if (adjustedLength == 0) return;
if (adjustedLength == 0 && !changesBase) return;
if (adjustedLength > bestAdjustedLength ||
if (adjustedLength > bestAdjustedLength || !best ||
(adjustedLength == bestAdjustedLength &&
path.compare(best->second) < 0)) {
best = { length, path };
@@ -3836,6 +3838,7 @@ bool GenericSignatureBuilder::addGenericParameterRequirements(
void GenericSignatureBuilder::addGenericParameter(GenericTypeParamType *GenericParam) {
GenericParamKey Key(GenericParam);
auto params = getGenericParams();
(void)params;
assert(params.empty() ||
((Key.Depth == params.back()->getDepth() &&
Key.Index == params.back()->getIndex() + 1) ||