Skip to content

Commit 6a65810

Browse files
committed
[Constraint] NFC: Rename ClosureBodyElement to SyntacticElement
`SyntacticElement` represents a statement, pattern, declaration, condition, or expression and could originate from i.e. a closure, a function or a result builder body.
1 parent 565ed69 commit 6a65810

File tree

10 files changed

+84
-84
lines changed

10 files changed

+84
-84
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.

lib/Sema/CSClosure.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void createConjunction(ConstraintSystem &cs,
213213
if (isIsolated)
214214
element.walk(paramCollector);
215215

216-
constraints.push_back(Constraint::createClosureBodyElement(
216+
constraints.push_back(Constraint::createSyntacticElement(
217217
cs, element, context, elementLoc, isDiscarded));
218218
}
219219

@@ -264,7 +264,7 @@ class ClosureConstraintGenerator
264264

265265
void visitPattern(Pattern *pattern, ContextualTypeInfo context) {
266266
auto parentElement =
267-
locator->getLastElementAs<LocatorPathElt::ClosureBodyElement>();
267+
locator->getLastElementAs<LocatorPathElt::SyntacticElement>();
268268

269269
if (!parentElement) {
270270
hadError = true;
@@ -486,7 +486,7 @@ class ClosureConstraintGenerator
486486
void visitPatternBinding(PatternBindingDecl *patternBinding,
487487
SmallVectorImpl<ElementInfo> &patterns) {
488488
auto *baseLoc = cs.getConstraintLocator(
489-
locator, LocatorPathElt::ClosureBodyElement(patternBinding));
489+
locator, LocatorPathElt::SyntacticElement(patternBinding));
490490

491491
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
492492
auto *pattern = TypeChecker::resolvePattern(
@@ -742,7 +742,7 @@ class ClosureConstraintGenerator
742742
{makeElement(
743743
errorExpr,
744744
cs.getConstraintLocator(
745-
locator, LocatorPathElt::ClosureBodyElement(errorExpr)),
745+
locator, LocatorPathElt::SyntacticElement(errorExpr)),
746746
{errType, CTP_ThrowStmt})},
747747
locator);
748748
}
@@ -790,7 +790,7 @@ class ClosureConstraintGenerator
790790
"Unsupported statement: Switch");
791791

792792
auto *switchLoc = cs.getConstraintLocator(
793-
locator, LocatorPathElt::ClosureBodyElement(switchStmt));
793+
locator, LocatorPathElt::SyntacticElement(switchStmt));
794794

795795
SmallVector<ElementInfo, 4> elements;
796796
{
@@ -816,7 +816,7 @@ class ClosureConstraintGenerator
816816
"Unsupported statement: DoCatch");
817817

818818
auto *doLoc = cs.getConstraintLocator(
819-
locator, LocatorPathElt::ClosureBodyElement(doStmt));
819+
locator, LocatorPathElt::SyntacticElement(doStmt));
820820

821821
SmallVector<ElementInfo, 4> elements;
822822

@@ -839,7 +839,7 @@ class ClosureConstraintGenerator
839839

840840
{
841841
auto parent =
842-
locator->castLastElementTo<LocatorPathElt::ClosureBodyElement>()
842+
locator->castLastElementTo<LocatorPathElt::SyntacticElement>()
843843
.getElement();
844844

845845
if (parent.isStmt(StmtKind::Switch)) {
@@ -856,7 +856,7 @@ class ClosureConstraintGenerator
856856
bindSwitchCasePatternVars(closure, caseStmt);
857857

858858
auto *caseLoc = cs.getConstraintLocator(
859-
locator, LocatorPathElt::ClosureBodyElement(caseStmt));
859+
locator, LocatorPathElt::SyntacticElement(caseStmt));
860860

861861
SmallVector<ElementInfo, 4> elements;
862862
for (auto &caseLabelItem : caseStmt->getMutableCaseLabelItems()) {
@@ -875,7 +875,7 @@ class ClosureConstraintGenerator
875875

876876
if (isChildOf(StmtKind::Case)) {
877877
auto *caseStmt = cast<CaseStmt>(
878-
locator->castLastElementTo<LocatorPathElt::ClosureBodyElement>()
878+
locator->castLastElementTo<LocatorPathElt::SyntacticElement>()
879879
.asStmt());
880880

881881
for (auto caseBodyVar : caseStmt->getCaseBodyVariablesOrEmptyArray()) {
@@ -901,7 +901,7 @@ class ClosureConstraintGenerator
901901
elements.push_back(makeElement(
902902
element,
903903
cs.getConstraintLocator(
904-
locator, LocatorPathElt::ClosureBodyElement(element)),
904+
locator, LocatorPathElt::SyntacticElement(element)),
905905
/*contextualInfo=*/{}, isDiscarded));
906906
}
907907

@@ -998,7 +998,7 @@ class ClosureConstraintGenerator
998998
return false;
999999

10001000
auto parentElt =
1001-
locator->getLastElementAs<LocatorPathElt::ClosureBodyElement>();
1001+
locator->getLastElementAs<LocatorPathElt::SyntacticElement>();
10021002
return parentElt ? parentElt->getElement().isStmt(kind) : false;
10031003
}
10041004
};
@@ -1067,14 +1067,14 @@ bool isConditionOfStmt(ConstraintLocatorBuilder locator) {
10671067
if (path.empty())
10681068
return false;
10691069

1070-
if (auto closureElt = path.back().getAs<LocatorPathElt::ClosureBodyElement>())
1070+
if (auto closureElt = path.back().getAs<LocatorPathElt::SyntacticElement>())
10711071
return closureElt->getElement().dyn_cast<Stmt *>();
10721072

10731073
return false;
10741074
}
10751075

10761076
ConstraintSystem::SolutionKind
1077-
ConstraintSystem::simplifyClosureBodyElementConstraint(
1077+
ConstraintSystem::simplifySyntacticElementConstraint(
10781078
ASTNode element, ContextualTypeInfo context, bool isDiscarded,
10791079
TypeMatchOptions flags, ConstraintLocatorBuilder locator) {
10801080
auto *closure = castToExpr<ClosureExpr>(locator.getAnchor());
@@ -1711,10 +1711,10 @@ void ConjunctionElement::findReferencedVariables(
17111711
auto referencedVars = Element->getTypeVariables();
17121712
typeVars.insert(referencedVars.begin(), referencedVars.end());
17131713

1714-
if (Element->getKind() != ConstraintKind::ClosureBodyElement)
1714+
if (Element->getKind() != ConstraintKind::SyntacticElement)
17151715
return;
17161716

1717-
ASTNode element = Element->getClosureElement();
1717+
ASTNode element = Element->getSyntacticElement();
17181718
auto *locator = Element->getLocator();
17191719

17201720
TypeVariableRefFinder refFinder(cs, locator->getAnchor(), typeVars);

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21892189
case ConstraintKind::DefaultClosureType:
21902190
case ConstraintKind::UnresolvedMemberChainBase:
21912191
case ConstraintKind::PropertyWrapper:
2192-
case ConstraintKind::ClosureBodyElement:
2192+
case ConstraintKind::SyntacticElement:
21932193
case ConstraintKind::BindTupleOfFunctionParams:
21942194
llvm_unreachable("Not a conversion");
21952195
}
@@ -2352,7 +2352,7 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
23522352
case ConstraintKind::DefaultClosureType:
23532353
case ConstraintKind::UnresolvedMemberChainBase:
23542354
case ConstraintKind::PropertyWrapper:
2355-
case ConstraintKind::ClosureBodyElement:
2355+
case ConstraintKind::SyntacticElement:
23562356
case ConstraintKind::BindTupleOfFunctionParams:
23572357
return true;
23582358
}
@@ -2796,7 +2796,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
27962796
case ConstraintKind::DefaultClosureType:
27972797
case ConstraintKind::UnresolvedMemberChainBase:
27982798
case ConstraintKind::PropertyWrapper:
2799-
case ConstraintKind::ClosureBodyElement:
2799+
case ConstraintKind::SyntacticElement:
28002800
case ConstraintKind::BindTupleOfFunctionParams:
28012801
llvm_unreachable("Not a relational constraint");
28022802
}
@@ -6012,7 +6012,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
60126012
case ConstraintKind::DefaultClosureType:
60136013
case ConstraintKind::UnresolvedMemberChainBase:
60146014
case ConstraintKind::PropertyWrapper:
6015-
case ConstraintKind::ClosureBodyElement:
6015+
case ConstraintKind::SyntacticElement:
60166016
case ConstraintKind::BindTupleOfFunctionParams:
60176017
llvm_unreachable("Not a relational constraint");
60186018
}
@@ -13145,7 +13145,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1314513145
case ConstraintKind::KeyPath:
1314613146
case ConstraintKind::KeyPathApplication:
1314713147
case ConstraintKind::DefaultClosureType:
13148-
case ConstraintKind::ClosureBodyElement:
13148+
case ConstraintKind::SyntacticElement:
1314913149
llvm_unreachable("Use the correct addConstraint()");
1315013150
}
1315113151

@@ -13675,9 +13675,9 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1367513675
constraint.getFirstType(), constraint.getSecondType(),
1367613676
/*flags=*/None, constraint.getLocator());
1367713677

13678-
case ConstraintKind::ClosureBodyElement:
13679-
return simplifyClosureBodyElementConstraint(
13680-
constraint.getClosureElement(), constraint.getElementContext(),
13678+
case ConstraintKind::SyntacticElement:
13679+
return simplifySyntacticElementConstraint(
13680+
constraint.getSyntacticElement(), constraint.getElementContext(),
1368113681
constraint.isDiscardedElement(),
1368213682
/*flags=*/None, constraint.getLocator());
1368313683

0 commit comments

Comments
 (0)