Skip to content

Commit 31279be

Browse files
committed
[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.
1 parent 20ffe48 commit 31279be

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,17 +3293,19 @@ RewriteTreeNode::bestMatch(GenericParamKey base, RelativeRewritePath path,
32933293
[&](unsigned length, RewritePath path) {
32943294
// Determine how much of the original path will be replaced by the rewrite.
32953295
unsigned adjustedLength = length;
3296+
bool changesBase = false;
32963297
if (auto newBase = path.getBase()) {
32973298
adjustedLength += prefixLength;
32983299

32993300
// If the base is unchanged, make sure we're reducing the length.
3300-
if (*newBase == base && adjustedLength <= path.getPath().size())
3301+
changesBase = *newBase != base;
3302+
if (!changesBase && adjustedLength <= path.getPath().size())
33013303
return;
33023304
}
33033305

3304-
if (adjustedLength == 0) return;
3306+
if (adjustedLength == 0 && !changesBase) return;
33053307

3306-
if (adjustedLength > bestAdjustedLength ||
3308+
if (adjustedLength > bestAdjustedLength || !best ||
33073309
(adjustedLength == bestAdjustedLength &&
33083310
path.compare(best->second) < 0)) {
33093311
best = { length, path };
@@ -3836,6 +3838,7 @@ bool GenericSignatureBuilder::addGenericParameterRequirements(
38363838
void GenericSignatureBuilder::addGenericParameter(GenericTypeParamType *GenericParam) {
38373839
GenericParamKey Key(GenericParam);
38383840
auto params = getGenericParams();
3841+
(void)params;
38393842
assert(params.empty() ||
38403843
((Key.Depth == params.back()->getDepth() &&
38413844
Key.Index == params.back()->getIndex() + 1) ||

0 commit comments

Comments
 (0)