Skip to content

Commit 1c54c5a

Browse files
committed
[ConstraintLocator] Add special locator for synthesized arguments
1 parent 0b12c66 commit 1c54c5a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
12641264
if (diff < 0) {
12651265
for (unsigned i = func1Params.size(),
12661266
n = func2Params.size(); i != n; ++i) {
1267-
auto *argLoc =
1268-
getConstraintLocator(anchor, LocatorPathElt::getTupleElement(i));
1267+
auto *argLoc = getConstraintLocator(
1268+
anchor, LocatorPathElt::getSynthesizedArgument(i));
12691269

12701270
auto arg = func2Params[i].withType(createTypeVariable(argLoc));
12711271
func1Params.push_back(arg);

lib/Sema/ConstraintLocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
7474
case ImplicitlyUnwrappedDisjunctionChoice:
7575
case DynamicLookupResult:
7676
case ContextualType:
77+
case SynthesizedArgument:
7778
if (unsigned numValues = numNumericValuesInPathElement(elt.getKind())) {
7879
id.AddInteger(elt.getValue());
7980
if (numValues > 1)
@@ -261,6 +262,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
261262
case ContextualType:
262263
out << "contextual type";
263264
break;
265+
266+
case SynthesizedArgument:
267+
out << " synthesized argument #" << llvm::utostr(elt.getValue());
268+
break;
264269
}
265270
}
266271

lib/Sema/ConstraintLocator.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class ConstraintLocator : public llvm::FoldingSetNode {
125125
DynamicLookupResult,
126126
/// The desired contextual type passed in to the constraint system.
127127
ContextualType,
128+
/// The missing argument synthesized by the solver.
129+
SynthesizedArgument,
128130
};
129131

130132
/// Determine the number of numeric values used for the given path
@@ -162,6 +164,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
162164
case NamedTupleElement:
163165
case TupleElement:
164166
case KeyPathComponent:
167+
case SynthesizedArgument:
165168
return 1;
166169

167170
case TypeParameterRequirement:
@@ -217,6 +220,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
217220
case ImplicitlyUnwrappedDisjunctionChoice:
218221
case DynamicLookupResult:
219222
case ContextualType:
223+
case SynthesizedArgument:
220224
return 0;
221225

222226
case FunctionArgument:
@@ -361,6 +365,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
361365
static_cast<unsigned>(kind));
362366
}
363367

368+
static PathElement getSynthesizedArgument(unsigned position) {
369+
return PathElement(SynthesizedArgument, position);
370+
}
371+
364372
/// Retrieve the kind of path element.
365373
PathElementKind getKind() const {
366374
switch (static_cast<StoredKind>(storedKind)) {
@@ -447,6 +455,10 @@ class ConstraintLocator : public llvm::FoldingSetNode {
447455
bool isConditionalRequirement() const {
448456
return getKind() == PathElementKind::ConditionalRequirement;
449457
}
458+
459+
bool isSynthesizedArgument() const {
460+
return getKind() == PathElementKind::SynthesizedArgument;
461+
}
450462
};
451463

452464
/// Return the summary flags for an entire path.

0 commit comments

Comments
 (0)