Skip to content

Commit 5601e31

Browse files
committed
[CS] Add Solution::getTargetFor
1 parent 40cc72e commit 5601e31

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,14 @@ class Solution {
16291629
return None;
16301630
}
16311631

1632+
Optional<SyntacticElementTarget>
1633+
getTargetFor(SyntacticElementTargetKey key) const {
1634+
auto known = targets.find(key);
1635+
if (known == targets.end())
1636+
return None;
1637+
return known->second;
1638+
}
1639+
16321640
ConstraintLocator *getCalleeLocator(ConstraintLocator *locator,
16331641
bool lookThroughApply = true) const;
16341642

lib/IDE/ArgumentCompletion.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,18 @@ static bool isExpressionResultTypeUnconstrained(const Solution &S, Expr *E) {
9595
return true;
9696
}
9797
}
98-
auto targetIt = S.targets.find(E);
99-
if (targetIt == S.targets.end()) {
98+
auto target = S.getTargetFor(E);
99+
if (!target)
100100
return false;
101-
}
102-
auto target = targetIt->second;
103-
assert(target.kind == SyntacticElementTarget::Kind::expression);
104-
switch (target.getExprContextualTypePurpose()) {
101+
102+
assert(target->kind == SyntacticElementTarget::Kind::expression);
103+
switch (target->getExprContextualTypePurpose()) {
105104
case CTP_Unused:
106105
// If we aren't using the contextual type, its unconstrained by definition.
107106
return true;
108107
case CTP_Initialization: {
109108
// let x = <expr> is unconstrained
110-
auto contextualType = target.getExprContextualType();
109+
auto contextualType = target->getExprContextualType();
111110
return !contextualType || contextualType->is<UnresolvedType>();
112111
}
113112
default:

lib/IDE/PostfixCompletion.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ getClosureActorIsolation(const Solution &S, AbstractClosureExpr *ACE) {
5252
// the contextual type might have a global actor attribute but because no
5353
// methods from that global actor are called in the closure, the closure has
5454
// a non-actor type.
55-
auto target = S.targets.find(dyn_cast<ClosureExpr>(E));
56-
if (target != S.targets.end()) {
57-
if (auto Ty = target->second.getClosureContextualType()) {
55+
if (auto target = S.getTargetFor(dyn_cast<ClosureExpr>(E))) {
56+
if (auto Ty = target->getClosureContextualType())
5857
return Ty;
59-
}
6058
}
6159
if (!S.hasType(E)) {
6260
return Type();

lib/IDE/TypeCheckCompletionCallback.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ bool swift::ide::isContextAsync(const constraints::Solution &S,
165165
// closure that doesn't contain any async calles. Thus the closure is
166166
// type-checked as non-async, but it might get converted to an async
167167
// closure based on its contextual type
168-
auto target = S.targets.find(dyn_cast<ClosureExpr>(DC));
169-
if (target != S.targets.end()) {
170-
if (auto ContextTy = target->second.getClosureContextualType()) {
168+
if (auto target = S.getTargetFor(dyn_cast<ClosureExpr>(DC))) {
169+
if (auto ContextTy = target->getClosureContextualType()) {
171170
if (auto ContextFuncTy =
172171
S.simplifyType(ContextTy)->getAs<AnyFunctionType>()) {
173172
return ContextFuncTy->isAsync();

0 commit comments

Comments
 (0)