Skip to content

Commit 2976edb

Browse files
committed
[CS] Rename SolutionApplicationTarget -> SyntacticElementTarget
1 parent cbea535 commit 2976edb

24 files changed

+441
-474
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 86 additions & 96 deletions
Large diffs are not rendered by default.

include/swift/Sema/IDETypeChecking.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace swift {
5353
namespace constraints {
5454
class ConstraintSystem;
5555
class Solution;
56-
class SolutionApplicationTarget;
56+
class SyntacticElementTarget;
5757
}
5858

5959
/// Typecheck binding initializer at \p bindingIndex.
@@ -161,7 +161,7 @@ namespace swift {
161161
/// \returns `true` if target was applicable and it was possible to infer
162162
/// types for code completion, `false` otherwise.
163163
bool typeCheckForCodeCompletion(
164-
constraints::SolutionApplicationTarget &target, bool needsPrecheck,
164+
constraints::SyntacticElementTarget &target, bool needsPrecheck,
165165
llvm::function_ref<void(const constraints::Solution &)> callback);
166166

167167
/// Thunk around \c TypeChecker::resolveDeclRefExpr to make it available to

include/swift/Sema/SolutionApplicationTarget.h renamed to include/swift/Sema/SyntacticElementTarget.h

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SolutionApplicationTarget.h - Solution Target ----------*- C++ -*-===//
1+
//===--- SyntacticElementTarget.h - Syntactic Element Target ----*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,12 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the SolutionApplicationTarget class.
13+
// This file defines the SyntacticElementTarget class.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
#ifndef SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H
18-
#define SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H
17+
#ifndef SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H
18+
#define SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H
1919

2020
#include "swift/AST/AnyFunctionRef.h"
2121
#include "swift/AST/Expr.h"
@@ -48,7 +48,7 @@ struct ForEachStmtInfo {
4848

4949
/// Describes the target to which a constraint system's solution can be
5050
/// applied.
51-
class SolutionApplicationTarget {
51+
class SyntacticElementTarget {
5252
public:
5353
enum class Kind {
5454
expression,
@@ -169,68 +169,67 @@ class SolutionApplicationTarget {
169169
void maybeApplyPropertyWrapper();
170170

171171
public:
172-
SolutionApplicationTarget(Expr *expr, DeclContext *dc,
173-
ContextualTypePurpose contextualPurpose,
174-
Type convertType,
175-
ConstraintLocator *convertTypeLocator,
176-
bool isDiscarded)
177-
: SolutionApplicationTarget(expr, dc, contextualPurpose,
178-
TypeLoc::withoutLoc(convertType),
179-
convertTypeLocator, isDiscarded) {}
180-
181-
SolutionApplicationTarget(Expr *expr, DeclContext *dc,
182-
ContextualTypePurpose contextualPurpose,
183-
Type convertType, bool isDiscarded)
184-
: SolutionApplicationTarget(expr, dc, contextualPurpose, convertType,
185-
/*convertTypeLocator*/ nullptr, isDiscarded) {
186-
}
187-
188-
SolutionApplicationTarget(Expr *expr, DeclContext *dc,
189-
ContextualTypePurpose contextualPurpose,
190-
TypeLoc convertType,
191-
ConstraintLocator *convertTypeLocator,
192-
bool isDiscarded);
193-
194-
SolutionApplicationTarget(Expr *expr, DeclContext *dc, ExprPattern *pattern,
195-
Type patternType)
196-
: SolutionApplicationTarget(expr, dc, CTP_ExprPattern, patternType,
197-
/*isDiscarded=*/false) {
172+
SyntacticElementTarget(Expr *expr, DeclContext *dc,
173+
ContextualTypePurpose contextualPurpose,
174+
Type convertType,
175+
ConstraintLocator *convertTypeLocator,
176+
bool isDiscarded)
177+
: SyntacticElementTarget(expr, dc, contextualPurpose,
178+
TypeLoc::withoutLoc(convertType),
179+
convertTypeLocator, isDiscarded) {}
180+
181+
SyntacticElementTarget(Expr *expr, DeclContext *dc,
182+
ContextualTypePurpose contextualPurpose,
183+
Type convertType, bool isDiscarded)
184+
: SyntacticElementTarget(expr, dc, contextualPurpose, convertType,
185+
/*convertTypeLocator*/ nullptr, isDiscarded) {}
186+
187+
SyntacticElementTarget(Expr *expr, DeclContext *dc,
188+
ContextualTypePurpose contextualPurpose,
189+
TypeLoc convertType,
190+
ConstraintLocator *convertTypeLocator,
191+
bool isDiscarded);
192+
193+
SyntacticElementTarget(Expr *expr, DeclContext *dc, ExprPattern *pattern,
194+
Type patternType)
195+
: SyntacticElementTarget(expr, dc, CTP_ExprPattern, patternType,
196+
/*isDiscarded=*/false) {
198197
setPattern(pattern);
199198
}
200199

201-
SolutionApplicationTarget(ClosureExpr *closure, Type convertType) {
200+
SyntacticElementTarget(ClosureExpr *closure, Type convertType) {
202201
kind = Kind::closure;
203202
this->closure.closure = closure;
204203
this->closure.convertType = convertType;
205204
}
206205

207-
SolutionApplicationTarget(AnyFunctionRef fn)
208-
: SolutionApplicationTarget(fn, fn.getBody()) { }
206+
SyntacticElementTarget(AnyFunctionRef fn)
207+
: SyntacticElementTarget(fn, fn.getBody()) {}
209208

210-
SolutionApplicationTarget(StmtCondition stmtCondition, DeclContext *dc) {
209+
SyntacticElementTarget(StmtCondition stmtCondition, DeclContext *dc) {
211210
kind = Kind::stmtCondition;
212211
this->stmtCondition.stmtCondition = stmtCondition;
213212
this->stmtCondition.dc = dc;
214213
}
215214

216-
SolutionApplicationTarget(AnyFunctionRef fn, BraceStmt *body) {
215+
SyntacticElementTarget(AnyFunctionRef fn, BraceStmt *body) {
217216
kind = Kind::function;
218217
function.function = fn;
219218
function.body = body;
220219
}
221220

222-
SolutionApplicationTarget(CaseLabelItem *caseLabelItem, DeclContext *dc) {
221+
SyntacticElementTarget(CaseLabelItem *caseLabelItem, DeclContext *dc) {
223222
kind = Kind::caseLabelItem;
224223
this->caseLabelItem.caseLabelItem = caseLabelItem;
225224
this->caseLabelItem.dc = dc;
226225
}
227226

228-
SolutionApplicationTarget(PatternBindingDecl *patternBinding) {
227+
SyntacticElementTarget(PatternBindingDecl *patternBinding) {
229228
kind = Kind::patternBinding;
230229
this->patternBinding = patternBinding;
231230
}
232231

233-
SolutionApplicationTarget(VarDecl *uninitializedWrappedVar)
232+
SyntacticElementTarget(VarDecl *uninitializedWrappedVar)
234233
: kind(Kind::uninitializedVar) {
235234
if (auto *PDB = uninitializedWrappedVar->getParentPatternBinding()) {
236235
uninitializedVar.binding = PDB;
@@ -245,60 +244,61 @@ class SolutionApplicationTarget {
245244
uninitializedVar.type = Type();
246245
}
247246

248-
SolutionApplicationTarget(PatternBindingDecl *binding, unsigned index,
249-
Pattern *var, Type patternTy)
247+
SyntacticElementTarget(PatternBindingDecl *binding, unsigned index,
248+
Pattern *var, Type patternTy)
250249
: kind(Kind::uninitializedVar) {
251250
uninitializedVar.binding = binding;
252251
uninitializedVar.index = index;
253252
uninitializedVar.declaration = var;
254253
uninitializedVar.type = patternTy;
255254
}
256255

257-
SolutionApplicationTarget(ForEachStmt *stmt, DeclContext *dc,
258-
bool bindPatternVarsOneWay)
259-
: kind(Kind::forEachStmt) {
256+
SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc,
257+
bool bindPatternVarsOneWay)
258+
: kind(Kind::forEachStmt) {
260259
forEachStmt.stmt = stmt;
261260
forEachStmt.dc = dc;
262261
forEachStmt.bindPatternVarsOneWay = bindPatternVarsOneWay;
263262
}
264263

265264
/// Form a target for the initialization of a pattern from an expression.
266-
static SolutionApplicationTarget forInitialization(
267-
Expr *initializer, DeclContext *dc, Type patternType, Pattern *pattern,
268-
bool bindPatternVarsOneWay);
265+
static SyntacticElementTarget
266+
forInitialization(Expr *initializer, DeclContext *dc, Type patternType,
267+
Pattern *pattern, bool bindPatternVarsOneWay);
269268

270269
/// Form a target for the initialization of a pattern binding entry from
271270
/// an expression.
272-
static SolutionApplicationTarget forInitialization(
273-
Expr *initializer, DeclContext *dc, Type patternType,
274-
PatternBindingDecl *patternBinding, unsigned patternBindingIndex,
275-
bool bindPatternVarsOneWay);
271+
static SyntacticElementTarget
272+
forInitialization(Expr *initializer, DeclContext *dc, Type patternType,
273+
PatternBindingDecl *patternBinding,
274+
unsigned patternBindingIndex, bool bindPatternVarsOneWay);
276275

277276
/// Form a target for a for-in loop.
278-
static SolutionApplicationTarget forForEachStmt(
279-
ForEachStmt *stmt, DeclContext *dc,
280-
bool bindPatternVarsOneWay);
277+
static SyntacticElementTarget forForEachStmt(ForEachStmt *stmt,
278+
DeclContext *dc,
279+
bool bindPatternVarsOneWay);
281280

282281
/// Form a target for a property with an attached property wrapper that is
283282
/// initialized out-of-line.
284-
static SolutionApplicationTarget
283+
static SyntacticElementTarget
285284
forUninitializedWrappedVar(VarDecl *wrappedVar) {
286285
return {wrappedVar};
287286
}
288287

289-
static SolutionApplicationTarget
290-
forUninitializedVar(PatternBindingDecl *binding, unsigned index,
291-
Type patternTy) {
288+
static SyntacticElementTarget forUninitializedVar(PatternBindingDecl *binding,
289+
unsigned index,
290+
Type patternTy) {
292291
return {binding, index, binding->getPattern(index), patternTy};
293292
}
294293

295294
/// Form a target for a synthesized property wrapper initializer.
296-
static SolutionApplicationTarget forPropertyWrapperInitializer(
297-
VarDecl *wrappedVar, DeclContext *dc, Expr *initializer);
295+
static SyntacticElementTarget
296+
forPropertyWrapperInitializer(VarDecl *wrappedVar, DeclContext *dc,
297+
Expr *initializer);
298298

299-
static SolutionApplicationTarget forExprPattern(Expr *expr, DeclContext *dc,
300-
ExprPattern *pattern,
301-
Type patternTy) {
299+
static SyntacticElementTarget forExprPattern(Expr *expr, DeclContext *dc,
300+
ExprPattern *pattern,
301+
Type patternTy) {
302302
return {expr, dc, pattern, patternTy};
303303
}
304304

@@ -373,8 +373,7 @@ class SolutionApplicationTarget {
373373
return patternBinding->getDeclContext();
374374

375375
case Kind::uninitializedVar: {
376-
if (auto *wrappedVar =
377-
uninitializedVar.declaration.dyn_cast<VarDecl *>())
376+
if (auto *wrappedVar = uninitializedVar.declaration.dyn_cast<VarDecl *>())
378377
return wrappedVar->getDeclContext();
379378

380379
return uninitializedVar.binding->getInitContext(uninitializedVar.index);
@@ -472,9 +471,7 @@ class SolutionApplicationTarget {
472471
ContextualPattern getContextualPattern() const;
473472

474473
/// Whether this target is for a for-in statement.
475-
bool isForEachStmt() const {
476-
return kind == Kind::forEachStmt;
477-
}
474+
bool isForEachStmt() const { return kind == Kind::forEachStmt; }
478475

479476
/// Whether this is an initialization for an Optional.Some pattern.
480477
bool isOptionalSomePatternInit() const {
@@ -516,8 +513,8 @@ class SolutionApplicationTarget {
516513
if (!apply || !wrappedVar)
517514
return false;
518515

519-
// Don't create property wrapper generator functions for static variables and
520-
// local variables with initializers.
516+
// Don't create property wrapper generator functions for static variables
517+
// and local variables with initializers.
521518
bool hasInit = expression.propertyWrapper.hasInitialWrappedValue;
522519
if (wrappedVar->isStatic() ||
523520
(hasInit && wrappedVar->getDeclContext()->isLocalContext()))
@@ -856,7 +853,7 @@ class SolutionApplicationTarget {
856853

857854
case Kind::uninitializedVar: {
858855
if (auto *wrappedVar =
859-
uninitializedVar.declaration.dyn_cast<VarDecl *>()) {
856+
uninitializedVar.declaration.dyn_cast<VarDecl *>()) {
860857
return wrappedVar->getLoc();
861858
}
862859
return uninitializedVar.declaration.get<Pattern *>()->getLoc();
@@ -869,10 +866,10 @@ class SolutionApplicationTarget {
869866
}
870867

871868
/// Walk the contents of the application target.
872-
Optional<SolutionApplicationTarget> walk(ASTWalker &walker) const;
869+
Optional<SyntacticElementTarget> walk(ASTWalker &walker) const;
873870
};
874871

875-
}
876-
}
872+
} // namespace constraints
873+
} // namespace swift
877874

878-
#endif /* SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H */
875+
#endif /* SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H */

lib/IDE/ArgumentCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ static bool isExpressionResultTypeUnconstrained(const Solution &S, Expr *E) {
9595
return true;
9696
}
9797
}
98-
auto targetIt = S.solutionApplicationTargets.find(E);
99-
if (targetIt == S.solutionApplicationTargets.end()) {
98+
auto targetIt = S.targets.find(E);
99+
if (targetIt == S.targets.end()) {
100100
return false;
101101
}
102102
auto target = targetIt->second;
103-
assert(target.kind == SolutionApplicationTarget::Kind::expression);
103+
assert(target.kind == SyntacticElementTarget::Kind::expression);
104104
switch (target.getExprContextualTypePurpose()) {
105105
case CTP_Unused:
106106
// If we aren't using the contextual type, its unconstrained by definition.

lib/IDE/PostfixCompletion.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ void PostfixCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
3636
}
3737
}
3838

39-
SolutionApplicationTarget completionTarget(fallbackExpr, fallbackDC,
40-
CTP_Unused, Type(),
41-
/*isDiscared=*/true);
39+
SyntacticElementTarget completionTarget(fallbackExpr, fallbackDC, CTP_Unused,
40+
Type(),
41+
/*isDiscared=*/true);
4242

4343
typeCheckForCodeCompletion(completionTarget, /*needsPrecheck*/ true,
4444
[&](const Solution &S) { sawSolution(S); });
@@ -52,8 +52,8 @@ 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.solutionApplicationTargets.find(dyn_cast<ClosureExpr>(E));
56-
if (target != S.solutionApplicationTargets.end()) {
55+
auto target = S.targets.find(dyn_cast<ClosureExpr>(E));
56+
if (target != S.targets.end()) {
5757
if (auto Ty = target->second.getClosureContextualType()) {
5858
return Ty;
5959
}
@@ -97,7 +97,7 @@ void PostfixCompletionCallback::sawSolutionImpl(
9797
llvm::DenseMap<AbstractClosureExpr *, ClosureActorIsolation>
9898
ClosureActorIsolations;
9999
bool IsAsync = isContextAsync(S, DC);
100-
for (auto SAT : S.solutionApplicationTargets) {
100+
for (auto SAT : S.targets) {
101101
if (auto ACE = getAsExpr<AbstractClosureExpr>(SAT.second.getAsASTNode())) {
102102
ClosureActorIsolations[ACE] = getClosureActorIsolation(S, ACE);
103103
}
@@ -112,7 +112,7 @@ void PostfixCompletionCallback::sawSolutionImpl(
112112
DisallowVoid |= ExpectedTy && !ExpectedTy->isVoid();
113113
DisallowVoid |= !ParentExpr &&
114114
CS.getContextualTypePurpose(CompletionExpr) != CTP_Unused;
115-
for (auto SAT : S.solutionApplicationTargets) {
115+
for (auto SAT : S.targets) {
116116
if (DisallowVoid) {
117117
// DisallowVoid is already set. No need to iterate further.
118118
break;

lib/IDE/TypeCheckCompletionCallback.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void TypeCheckCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
3131
if (!fallback)
3232
return;
3333

34-
SolutionApplicationTarget completionTarget(fallback->E, fallback->DC,
35-
CTP_Unused, Type(),
36-
/*isDiscared=*/true);
34+
SyntacticElementTarget completionTarget(fallback->E, fallback->DC, CTP_Unused,
35+
Type(),
36+
/*isDiscared=*/true);
3737
typeCheckForCodeCompletion(completionTarget, /*needsPrecheck=*/true,
3838
[&](const Solution &S) { sawSolution(S); });
3939
}
@@ -165,8 +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.solutionApplicationTargets.find(dyn_cast<ClosureExpr>(DC));
169-
if (target != S.solutionApplicationTargets.end()) {
168+
auto target = S.targets.find(dyn_cast<ClosureExpr>(DC));
169+
if (target != S.targets.end()) {
170170
if (auto ContextTy = target->second.getClosureContextualType()) {
171171
if (auto ContextFuncTy =
172172
S.simplifyType(ContextTy)->getAs<AnyFunctionType>()) {

0 commit comments

Comments
 (0)