[ConstraintLocator] Add special locator for synthesized arguments

This commit is contained in:
Pavel Yaskevich
2019-02-25 14:53:08 -08:00
parent 0b12c664b0
commit 1c54c5a08b
3 changed files with 19 additions and 2 deletions

View File

@@ -1264,8 +1264,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
if (diff < 0) {
for (unsigned i = func1Params.size(),
n = func2Params.size(); i != n; ++i) {
auto *argLoc =
getConstraintLocator(anchor, LocatorPathElt::getTupleElement(i));
auto *argLoc = getConstraintLocator(
anchor, LocatorPathElt::getSynthesizedArgument(i));
auto arg = func2Params[i].withType(createTypeVariable(argLoc));
func1Params.push_back(arg);

View File

@@ -74,6 +74,7 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
case ImplicitlyUnwrappedDisjunctionChoice:
case DynamicLookupResult:
case ContextualType:
case SynthesizedArgument:
if (unsigned numValues = numNumericValuesInPathElement(elt.getKind())) {
id.AddInteger(elt.getValue());
if (numValues > 1)
@@ -261,6 +262,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) {
case ContextualType:
out << "contextual type";
break;
case SynthesizedArgument:
out << " synthesized argument #" << llvm::utostr(elt.getValue());
break;
}
}

View File

@@ -125,6 +125,8 @@ public:
DynamicLookupResult,
/// The desired contextual type passed in to the constraint system.
ContextualType,
/// The missing argument synthesized by the solver.
SynthesizedArgument,
};
/// Determine the number of numeric values used for the given path
@@ -162,6 +164,7 @@ public:
case NamedTupleElement:
case TupleElement:
case KeyPathComponent:
case SynthesizedArgument:
return 1;
case TypeParameterRequirement:
@@ -217,6 +220,7 @@ public:
case ImplicitlyUnwrappedDisjunctionChoice:
case DynamicLookupResult:
case ContextualType:
case SynthesizedArgument:
return 0;
case FunctionArgument:
@@ -361,6 +365,10 @@ public:
static_cast<unsigned>(kind));
}
static PathElement getSynthesizedArgument(unsigned position) {
return PathElement(SynthesizedArgument, position);
}
/// Retrieve the kind of path element.
PathElementKind getKind() const {
switch (static_cast<StoredKind>(storedKind)) {
@@ -447,6 +455,10 @@ public:
bool isConditionalRequirement() const {
return getKind() == PathElementKind::ConditionalRequirement;
}
bool isSynthesizedArgument() const {
return getKind() == PathElementKind::SynthesizedArgument;
}
};
/// Return the summary flags for an entire path.