Skip to content

Commit b7d94e4

Browse files
committed
Drop TypeChecker out of some Code Completion utilities
1 parent 7bad9aa commit b7d94e4

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ static bool isDeclMoreConstrainedThan(ValueDecl *decl1, ValueDecl *decl2) {
313313

314314
/// Determine whether one protocol extension is at least as specialized as
315315
/// another.
316-
static bool isProtocolExtensionAsSpecializedAs(TypeChecker &tc,
317-
DeclContext *dc1,
316+
static bool isProtocolExtensionAsSpecializedAs(DeclContext *dc1,
318317
DeclContext *dc2) {
319318
assert(dc1->getExtendedProtocolDecl());
320319
assert(dc2->getExtendedProtocolDecl());
@@ -390,9 +389,6 @@ llvm::Expected<bool> CompareDeclSpecializationRequest::evaluate(
390389
Evaluator &eval, DeclContext *dc, ValueDecl *decl1, ValueDecl *decl2,
391390
bool isDynamicOverloadComparison) const {
392391
auto &C = decl1->getASTContext();
393-
// FIXME: Remove dependency on the global type checker.
394-
auto *tc = C.getLegacyGlobalTypeChecker();
395-
396392
if (C.LangOpts.DebugConstraintSolver) {
397393
auto &log = C.TypeCheckerDebug->getStream();
398394
log << "Comparing declarations\n";
@@ -445,8 +441,8 @@ llvm::Expected<bool> CompareDeclSpecializationRequest::evaluate(
445441
// Both members are in protocol extensions.
446442
// Determine whether the 'Self' type from the first protocol extension
447443
// satisfies all of the requirements of the second protocol extension.
448-
bool better1 = isProtocolExtensionAsSpecializedAs(*tc, outerDC1, outerDC2);
449-
bool better2 = isProtocolExtensionAsSpecializedAs(*tc, outerDC2, outerDC1);
444+
bool better1 = isProtocolExtensionAsSpecializedAs(outerDC1, outerDC2);
445+
bool better2 = isProtocolExtensionAsSpecializedAs(outerDC2, outerDC1);
450446
if (better1 != better2) {
451447
return completeResult(better1);
452448
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
24492449
}
24502450

24512451
static FunctionType *
2452-
getTypeOfCompletionOperatorImpl(TypeChecker &TC, DeclContext *DC, Expr *expr,
2452+
getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
24532453
ConcreteDeclRef &referencedDecl) {
24542454
auto &Context = DC->getASTContext();
24552455

@@ -2467,7 +2467,7 @@ getTypeOfCompletionOperatorImpl(TypeChecker &TC, DeclContext *DC, Expr *expr,
24672467
if (!expr)
24682468
return nullptr;
24692469

2470-
if (TC.getLangOpts().DebugConstraintSolver) {
2470+
if (Context.LangOpts.DebugConstraintSolver) {
24712471
auto &log = Context.TypeCheckerDebug->getStream();
24722472
log << "---Initial constraints for the given expression---\n";
24732473
expr->dump(log);
@@ -2481,7 +2481,7 @@ getTypeOfCompletionOperatorImpl(TypeChecker &TC, DeclContext *DC, Expr *expr,
24812481
return nullptr;
24822482

24832483
auto &solution = viable[0];
2484-
if (TC.getLangOpts().DebugConstraintSolver) {
2484+
if (Context.LangOpts.DebugConstraintSolver) {
24852485
auto &log = Context.TypeCheckerDebug->getStream();
24862486
log << "---Solution---\n";
24872487
solution.dump(log);
@@ -2516,7 +2516,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
25162516

25172517
// For the infix operator, find the actual LHS from pre-folded LHS.
25182518
if (refKind == DeclRefKind::BinaryOperator)
2519-
LHS = findLHS(DC, LHS, opName);
2519+
LHS = TypeChecker::findLHS(DC, LHS, opName);
25202520

25212521
if (!LHS)
25222522
return nullptr;
@@ -2549,7 +2549,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
25492549
ParenExpr Args(SourceLoc(), LHS, SourceLoc(),
25502550
/*hasTrailingClosure=*/false);
25512551
PostfixUnaryExpr postfixExpr(opExpr, &Args);
2552-
return getTypeOfCompletionOperatorImpl(*this, DC, &postfixExpr,
2552+
return getTypeOfCompletionOperatorImpl(DC, &postfixExpr,
25532553
referencedDecl);
25542554
}
25552555

@@ -2561,11 +2561,11 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
25612561
// (code_completion_expr)))
25622562
CodeCompletionExpr dummyRHS(Loc);
25632563
auto Args = TupleExpr::create(
2564-
Context, SourceLoc(), {LHS, &dummyRHS}, {}, {}, SourceLoc(),
2564+
DC->getASTContext(), SourceLoc(), {LHS, &dummyRHS}, {}, {}, SourceLoc(),
25652565
/*hasTrailingClosure=*/false, /*isImplicit=*/true);
25662566
BinaryExpr binaryExpr(opExpr, Args, /*isImplicit=*/true);
25672567

2568-
return getTypeOfCompletionOperatorImpl(*this, DC, &binaryExpr,
2568+
return getTypeOfCompletionOperatorImpl(DC, &binaryExpr,
25692569
referencedDecl);
25702570
}
25712571

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ static void checkDefaultArguments(TypeChecker &tc, ParameterList *params) {
20382038
auto *initContext = param->getDefaultArgumentInitContext();
20392039

20402040
auto resultTy =
2041-
tc.typeCheckParameterDefault(e, initContext, param->getType(),
2041+
typeCheckParameterDefault(e, initContext, param->getType(),
20422042
/*isAutoClosure=*/param->isAutoClosure());
20432043

20442044
if (resultTy) {

lib/Sema/TypeCheckExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Expr *TypeChecker::findLHS(DeclContext *DC, Expr *E, Identifier name) {
237237
if (!left)
238238
// LHS is not binary expression.
239239
return E;
240-
switch (Context.associateInfixOperators(left, right)) {
240+
switch (DC->getASTContext().associateInfixOperators(left, right)) {
241241
case swift::Associativity::None:
242242
return nullptr;
243243
case swift::Associativity::Left:

lib/Sema/TypeChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ swift::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
686686
ConcreteDeclRef &referencedDecl) {
687687
auto &ctx = DC->getASTContext();
688688
DiagnosticSuppression suppression(ctx.Diags);
689-
TypeChecker &TC = createTypeChecker(ctx);
690-
return TC.getTypeOfCompletionOperator(DC, LHS, opName, refKind,
691-
referencedDecl);
689+
(void)createTypeChecker(ctx);
690+
return TypeChecker::getTypeOfCompletionOperator(DC, LHS, opName, refKind,
691+
referencedDecl);
692692
}
693693

694694
bool swift::typeCheckExpression(DeclContext *DC, Expr *&parsedExpr) {

lib/Sema/TypeChecker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,10 +1190,10 @@ class TypeChecker final {
11901190

11911191
/// Return the type of operator function for specified LHS, or a null
11921192
/// \c Type on error.
1193-
FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
1194-
Identifier opName,
1195-
DeclRefKind refKind,
1196-
ConcreteDeclRef &referencedDecl);
1193+
static FunctionType *getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
1194+
Identifier opName,
1195+
DeclRefKind refKind,
1196+
ConcreteDeclRef &refdDecl);
11971197

11981198
/// Check the key-path expression.
11991199
///
@@ -1575,7 +1575,7 @@ class TypeChecker final {
15751575

15761576
/// Given an pre-folded expression, find LHS from the expression if a binary
15771577
/// operator \c name appended to the expression.
1578-
Expr *findLHS(DeclContext *DC, Expr *E, Identifier name);
1578+
static Expr *findLHS(DeclContext *DC, Expr *E, Identifier name);
15791579

15801580
/// @}
15811581

0 commit comments

Comments
 (0)