Skip to content

Commit 0ebdba0

Browse files
committed
[ConstraintSystem] Add a new locator element - type for body of a closure
1 parent c72940f commit 0ebdba0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/Sema/ConstraintLocator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ void ConstraintLocator::Profile(llvm::FoldingSetNodeID &id, Expr *anchor,
6767
case TypeParameterRequirement:
6868
case ContextualType:
6969
case SynthesizedArgument:
70-
case TernaryBranch: {
70+
case TernaryBranch:
71+
case ClosureBody: {
7172
auto numValues = numNumericValuesInPathElement(elt.getKind());
7273
for (unsigned i = 0; i < numValues; ++i)
7374
id.AddInteger(elt.getValue(i));
@@ -87,6 +88,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
8788
case ConstraintLocator::ApplyFunction:
8889
case ConstraintLocator::SequenceElementType:
8990
case ConstraintLocator::ClosureResult:
91+
case ConstraintLocator::ClosureBody:
9092
case ConstraintLocator::ConstructorMember:
9193
case ConstraintLocator::InstanceType:
9294
case ConstraintLocator::AutoclosureResult:
@@ -327,6 +329,10 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
327329
out << "closure result";
328330
break;
329331

332+
case ClosureBody:
333+
out << "type of a closure body";
334+
break;
335+
330336
case ConstructorMember:
331337
out << "constructor member";
332338
break;

lib/Sema/ConstraintLocator.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
7171
case PatternMatch:
7272
return 0;
7373

74+
case ClosureBody:
7475
case ContextualType:
7576
case OpenedGeneric:
7677
case GenericArgument:
@@ -717,6 +718,20 @@ class LocatorPathElt::TypeParameterRequirement final
717718
}
718719
};
719720

721+
class LocatorPathElt::ClosureBody final : public LocatorPathElt {
722+
public:
723+
ClosureBody(bool hasExplicitReturn = false)
724+
: LocatorPathElt(ConstraintLocator::ClosureBody,
725+
hasExplicitReturn) {}
726+
727+
/// Indicates whether body of the closure has any `return` statements.
728+
bool hasExplicitReturn() const { return bool(getValue(0)); }
729+
730+
static bool classof(const LocatorPathElt *elt) {
731+
return elt->getKind() == ConstraintLocator::ClosureBody;
732+
}
733+
};
734+
720735
class LocatorPathElt::ContextualType final : public LocatorPathElt {
721736
public:
722737
ContextualType(bool isForSingleExprFunction = false)

lib/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ SIMPLE_LOCATOR_PATH_ELT(AutoclosureResult)
5454
/// The result of a closure.
5555
SIMPLE_LOCATOR_PATH_ELT(ClosureResult)
5656

57+
/// The type of a closure body.
58+
CUSTOM_LOCATOR_PATH_ELT(ClosureBody)
59+
5760
/// The lookup for a constructor member.
5861
SIMPLE_LOCATOR_PATH_ELT(ConstructorMember)
5962

0 commit comments

Comments
 (0)