Skip to content

Commit d346977

Browse files
authored
Merge pull request #58423 from xedin/closure-handling-renames
[CSClosure] (Mostly NFC) Renames and introduction of `AnyFunctionRef`
2 parents 6723a45 + a282aaa commit d346977

File tree

10 files changed

+176
-160
lines changed

10 files changed

+176
-160
lines changed

include/swift/Sema/Constraint.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,9 @@ enum class ConstraintKind : char {
209209
/// inferred from a conversion, so the check is more relax comparing to
210210
/// `ConformsTo`.
211211
TransitivelyConformsTo,
212-
/// Represents an AST node contained in a body of a closure. It has only
213-
/// one type - type variable representing type of a node, other side is
214-
/// the AST node to infer the type for.
215-
ClosureBodyElement,
212+
/// Represents an AST node contained in a body of a function/closure.
213+
/// It only has an AST node to generate constraints and infer the type for.
214+
SyntacticElement,
216215
/// Do not add new uses of this, it only exists to retain compatibility for
217216
/// rdar://85263844.
218217
///
@@ -240,8 +239,8 @@ enum class ConstraintClassification : char {
240239
/// A conjunction constraint.
241240
Conjunction,
242241

243-
/// An element of a closure body.
244-
ClosureElement,
242+
/// An element of a closure/function body.
243+
SyntacticElement,
245244
};
246245

247246
/// Specifies a restriction on the kind of conversion that should be
@@ -448,7 +447,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
448447
ContextualTypeInfo Context;
449448
/// Identifies whether result of this node is unused.
450449
bool IsDiscarded;
451-
} ClosureElement;
450+
} SyntacticElement;
452451
};
453452

454453
/// The locator that describes where in the expression this
@@ -589,12 +588,12 @@ class Constraint final : public llvm::ilist_node<Constraint>,
589588
Optional<TrailingClosureMatching> trailingClosureMatching,
590589
ConstraintLocator *locator);
591590

592-
static Constraint *createClosureBodyElement(ConstraintSystem &cs,
591+
static Constraint *createSyntacticElement(ConstraintSystem &cs,
593592
ASTNode node,
594593
ConstraintLocator *locator,
595594
bool isDiscarded = false);
596595

597-
static Constraint *createClosureBodyElement(ConstraintSystem &cs,
596+
static Constraint *createSyntacticElement(ConstraintSystem &cs,
598597
ASTNode node,
599598
ContextualTypeInfo context,
600599
ConstraintLocator *locator,
@@ -708,8 +707,8 @@ class Constraint final : public llvm::ilist_node<Constraint>,
708707
case ConstraintKind::Conjunction:
709708
return ConstraintClassification::Conjunction;
710709

711-
case ConstraintKind::ClosureBodyElement:
712-
return ConstraintClassification::ClosureElement;
710+
case ConstraintKind::SyntacticElement:
711+
return ConstraintClassification::SyntacticElement;
713712
}
714713

715714
llvm_unreachable("Unhandled ConstraintKind in switch.");
@@ -732,7 +731,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
732731
case ConstraintKind::ValueWitness:
733732
return Member.First;
734733

735-
case ConstraintKind::ClosureBodyElement:
734+
case ConstraintKind::SyntacticElement:
736735
llvm_unreachable("closure body element constraint has no type operands");
737736

738737
default:
@@ -746,7 +745,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
746745
case ConstraintKind::Disjunction:
747746
case ConstraintKind::Conjunction:
748747
case ConstraintKind::BindOverload:
749-
case ConstraintKind::ClosureBodyElement:
748+
case ConstraintKind::SyntacticElement:
750749
llvm_unreachable("constraint has no second type");
751750

752751
case ConstraintKind::ValueMember:
@@ -855,19 +854,19 @@ class Constraint final : public llvm::ilist_node<Constraint>,
855854
return Member.UseDC;
856855
}
857856

858-
ASTNode getClosureElement() const {
859-
assert(Kind == ConstraintKind::ClosureBodyElement);
860-
return ClosureElement.Element;
857+
ASTNode getSyntacticElement() const {
858+
assert(Kind == ConstraintKind::SyntacticElement);
859+
return SyntacticElement.Element;
861860
}
862861

863862
ContextualTypeInfo getElementContext() const {
864-
assert(Kind == ConstraintKind::ClosureBodyElement);
865-
return ClosureElement.Context;
863+
assert(Kind == ConstraintKind::SyntacticElement);
864+
return SyntacticElement.Context;
866865
}
867866

868867
bool isDiscardedElement() const {
869-
assert(Kind == ConstraintKind::ClosureBodyElement);
870-
return ClosureElement.IsDiscarded;
868+
assert(Kind == ConstraintKind::SyntacticElement);
869+
return SyntacticElement.IsDiscarded;
871870
}
872871

873872
/// For an applicable function constraint, retrieve the trailing closure

include/swift/Sema/ConstraintLocator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,11 @@ class LocatorPathElt::ConstructorMemberType final
10121012
}
10131013
};
10141014

1015-
class LocatorPathElt::ClosureBodyElement final
1015+
class LocatorPathElt::SyntacticElement final
10161016
: public StoredPointerElement<void> {
10171017
public:
1018-
ClosureBodyElement(ASTNode element)
1019-
: StoredPointerElement(PathElementKind::ClosureBodyElement,
1018+
SyntacticElement(ASTNode element)
1019+
: StoredPointerElement(PathElementKind::SyntacticElement,
10201020
element.getOpaqueValue()) {
10211021
assert(element);
10221022
}
@@ -1054,7 +1054,7 @@ class LocatorPathElt::ClosureBodyElement final
10541054
}
10551055

10561056
static bool classof(const LocatorPathElt *elt) {
1057-
return elt->getKind() == PathElementKind::ClosureBodyElement;
1057+
return elt->getKind() == PathElementKind::SyntacticElement;
10581058
}
10591059
};
10601060

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ CUSTOM_LOCATOR_PATH_ELT(ImplicitConversion)
229229
/// An implicit call to a 'dynamicMember' subscript for a dynamic member lookup.
230230
SIMPLE_LOCATOR_PATH_ELT(ImplicitDynamicMemberSubscript)
231231

232-
/// The element of the closure body e.g. statement, declaration, or expression.
233-
CUSTOM_LOCATOR_PATH_ELT(ClosureBodyElement)
232+
/// The element of the closure/function body e.g. statement, pattern,
233+
/// declaration, or expression.
234+
CUSTOM_LOCATOR_PATH_ELT(SyntacticElement)
234235

235236
/// The element of the pattern binding declaration.
236237
CUSTOM_LOCATOR_PATH_ELT(PatternBindingElement)

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,9 +5120,9 @@ class ConstraintSystem {
51205120
TypeMatchOptions flags,
51215121
ConstraintLocatorBuilder locator);
51225122

5123-
/// Simplify a closure body element constraint by generating required
5123+
/// Simplify a syntactic element constraint by generating required
51245124
/// constraints to represent the given element in constraint system.
5125-
SolutionKind simplifyClosureBodyElementConstraint(
5125+
SolutionKind simplifySyntacticElementConstraint(
51265126
ASTNode element, ContextualTypeInfo context, bool isDiscarded,
51275127
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
51285128

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ void PotentialBindings::infer(Constraint *constraint) {
13851385
case ConstraintKind::EscapableFunctionOf:
13861386
case ConstraintKind::OpenedExistentialOf:
13871387
case ConstraintKind::KeyPath:
1388-
case ConstraintKind::ClosureBodyElement:
1388+
case ConstraintKind::SyntacticElement:
13891389
case ConstraintKind::Conjunction:
13901390
case ConstraintKind::BindTupleOfFunctionParams:
13911391
// Constraints from which we can't do anything.

0 commit comments

Comments
 (0)