Skip to content

Commit 7d0d98b

Browse files
committed
xxx
1 parent f4fa6ea commit 7d0d98b

22 files changed

+34
-338
lines changed

include/swift/IDE/PostfixCompletion.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ class PostfixCompletionCallback : public TypeCheckCompletionCallback {
8686
PostfixCompletionCallback(CodeCompletionExpr *CompletionExpr, DeclContext *DC)
8787
: CompletionExpr(CompletionExpr), DC(DC) {}
8888

89-
/// Typecheck the code completion expression in isolation, calling
90-
/// \c sawSolution for each solution formed.
91-
void fallbackTypeCheck(DeclContext *DC) override;
92-
9389
/// Deliver code completion results that were discoverd by \c sawSolution to
9490
/// \p Consumer.
9591
/// \param DotLoc If we are completing after a dot, the location of the dot,

include/swift/IDE/TypeCheckCompletionCallback.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ class TypeCheckCompletionCallback {
5959
/// True if at least one solution was passed via the \c sawSolution
6060
/// callback.
6161
bool gotCallback() const { return GotCallback; }
62-
63-
/// Typecheck the code completion expression in its outermost expression
64-
/// context, calling \c sawSolution for each solution formed.
65-
virtual void fallbackTypeCheck(DeclContext *DC);
6662
};
6763

6864
// MARK: - Utility functions for subclasses of TypeCheckCompletionCallback

include/swift/Sema/CompletionContextFinder.h

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ class SyntacticElementTarget;
2525
}
2626

2727
class CompletionContextFinder : public ASTWalker {
28-
enum class ContextKind {
29-
FallbackExpression,
30-
StringInterpolation,
31-
SingleStmtClosure,
32-
MultiStmtClosure,
33-
ErrorExpression
34-
};
35-
36-
struct Context {
37-
ContextKind Kind;
38-
Expr *E;
39-
};
40-
41-
/// Stack of all "interesting" contexts up to code completion expression.
42-
llvm::SmallVector<Context, 4> Contexts;
43-
4428
/// If we are completing inside an expression, the \c CodeCompletionExpr that
4529
/// represents the code completion token.
4630

@@ -49,44 +33,18 @@ class CompletionContextFinder : public ASTWalker {
4933
/// component.
5034
llvm::PointerUnion<CodeCompletionExpr *, const KeyPathExpr *> CompletionNode;
5135

52-
Expr *InitialExpr = nullptr;
53-
DeclContext *InitialDC;
54-
55-
/// Whether we're looking for any viable fallback expression.
56-
bool ForFallback = false;
57-
58-
/// Finder for fallback completion contexts within the outermost non-closure
59-
/// context of the code completion expression's direct context.
60-
CompletionContextFinder(DeclContext *completionDC)
61-
: InitialDC(completionDC), ForFallback(true) {
62-
while (auto *ACE = dyn_cast<AbstractClosureExpr>(InitialDC))
63-
InitialDC = ACE->getParent();
64-
InitialDC->walkContext(*this);
65-
}
66-
6736
public:
6837
MacroWalking getMacroWalkingBehavior() const override {
6938
return MacroWalking::Arguments;
7039
}
7140

7241
/// Finder for completion contexts within the provided SyntacticElementTarget.
73-
CompletionContextFinder(constraints::SyntacticElementTarget target,
74-
DeclContext *DC);
75-
76-
static CompletionContextFinder forFallback(DeclContext *DC) {
77-
return CompletionContextFinder(DC);
78-
}
42+
CompletionContextFinder(constraints::SyntacticElementTarget target);
7943

8044
PreWalkResult<Expr *> walkToExprPre(Expr *E) override;
8145

82-
PostWalkResult<Expr *> walkToExprPost(Expr *E) override;
83-
8446
PreWalkAction walkToDeclPre(Decl *D) override;
8547

86-
bool locatedInStringInterpolation() const {
87-
return hasContext(ContextKind::StringInterpolation);
88-
}
89-
9048
bool hasCompletionExpr() const {
9149
return CompletionNode.dyn_cast<CodeCompletionExpr *>() != nullptr;
9250
}
@@ -114,28 +72,8 @@ class CompletionContextFinder : public ASTWalker {
11472
/// If we are completing in a key path, returns the index at which the key
11573
/// path has the code completion component.
11674
size_t getKeyPathCompletionComponentIndex() const;
117-
118-
struct Fallback {
119-
Expr *E; ///< The fallback expression.
120-
DeclContext *DC; ///< The fallback expression's decl context.
121-
bool SeparatePrecheck; ///< True if the fallback may require prechecking.
122-
};
123-
124-
/// As a fallback sometimes its useful to not only type-check
125-
/// code completion expression directly but instead add some
126-
/// of the enclosing context e.g. when completion is an argument
127-
/// to a call.
128-
std::optional<Fallback> getFallbackCompletionExpr() const;
129-
130-
private:
131-
bool hasContext(ContextKind kind) const {
132-
return llvm::find_if(Contexts, [&kind](const Context &currContext) {
133-
return currContext.Kind == kind;
134-
}) != Contexts.end();
135-
}
13675
};
13776

138-
13977
/// Returns \c true if \p range is valid and contains the IDE inspection
14078
/// target. This performs the underlying check based on \c CharSourceRange
14179
/// to make sure we correctly return \c true if the ide inspection target

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,6 @@ namespace swift {
140140
bool typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext TypeCheckCtx,
141141
SourceLoc TargetLoc);
142142

143-
/// Thunk around \c TypeChecker::typeCheckForCodeCompletion to make it
144-
/// available to \c swift::ide.
145-
/// Type check the given expression and provide results back to code
146-
/// completion via specified callback.
147-
///
148-
/// This method is designed to be used for code completion which means that
149-
/// it doesn't mutate given expression, even if there is a single valid
150-
/// solution, and constraint solver is allowed to produce partially correct
151-
/// solutions. Such solutions can have any number of holes in them.
152-
///
153-
/// \returns `true` if target was applicable and it was possible to infer
154-
/// types for code completion, `false` otherwise.
155-
bool typeCheckForCodeCompletion(
156-
constraints::SyntacticElementTarget &target, bool needsPrecheck,
157-
llvm::function_ref<void(const constraints::Solution &)> callback);
158-
159143
/// Thunk around \c TypeChecker::resolveDeclRefExpr to make it available to
160144
/// \c swift::ide
161145
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context);

lib/IDE/AfterPoundExprCompletion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "swift/IDE/AfterPoundExprCompletion.h"
1414
#include "swift/IDE/CodeCompletion.h"
1515
#include "swift/IDE/CompletionLookup.h"
16-
#include "swift/Sema/CompletionContextFinder.h"
1716
#include "swift/Sema/ConstraintSystem.h"
1817
#include "swift/Sema/IDETypeChecking.h"
1918

lib/IDE/CodeCompletion.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,18 +1494,6 @@ void CodeCompletionCallbacksImpl::typeCheckWithLookup(
14941494
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
14951495
CompletionLoc);
14961496
}
1497-
1498-
// This (hopefully) only happens in cases where the expression isn't
1499-
// typechecked during normal compilation either (e.g. member completion in a
1500-
// switch case where there control expression is invalid). Having normal
1501-
// typechecking still resolve even these cases would be beneficial for
1502-
// tooling in general though.
1503-
if (!Lookup.gotCallback()) {
1504-
if (Context.TypeCheckerOpts.DebugConstraintSolver) {
1505-
llvm::errs() << "--- Fallback typecheck for code completion ---\n";
1506-
}
1507-
Lookup.fallbackTypeCheck(CurDeclContext);
1508-
}
15091497
}
15101498

15111499
void CodeCompletionCallbacksImpl::postfixCompletion(SourceLoc CompletionLoc,

lib/IDE/PostfixCompletion.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/Basic/Assertions.h"
1413
#include "swift/IDE/PostfixCompletion.h"
14+
#include "swift/Basic/Assertions.h"
1515
#include "swift/IDE/CodeCompletion.h"
1616
#include "swift/IDE/CompletionLookup.h"
17-
#include "swift/Sema/CompletionContextFinder.h"
1817
#include "swift/Sema/ConstraintSystem.h"
1918
#include "swift/Sema/IDETypeChecking.h"
2019

@@ -72,37 +71,6 @@ void PostfixCompletionCallback::addResult(const Result &Res) {
7271
Results.push_back(Res);
7372
}
7473

75-
void PostfixCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
76-
assert(!gotCallback());
77-
78-
// Default to checking the completion expression in isolation.
79-
Expr *fallbackExpr = CompletionExpr;
80-
DeclContext *fallbackDC = DC;
81-
82-
auto finder = CompletionContextFinder::forFallback(DC);
83-
if (finder.hasCompletionExpr()) {
84-
if (auto fallback = finder.getFallbackCompletionExpr()) {
85-
fallbackExpr = fallback->E;
86-
fallbackDC = fallback->DC;
87-
}
88-
}
89-
90-
if (isa<AbstractClosureExpr>(fallbackDC)) {
91-
// If the expression is embedded in a closure, the constraint system tries
92-
// to retrieve that closure's type, which will fail since we won't have
93-
// generated any type variables for it. Thus, fallback type checking isn't
94-
// available in this case.
95-
return;
96-
}
97-
98-
SyntacticElementTarget completionTarget(fallbackExpr, fallbackDC, CTP_Unused,
99-
Type(),
100-
/*isDiscared=*/true);
101-
102-
typeCheckForCodeCompletion(completionTarget, /*needsPrecheck*/ true,
103-
[&](const Solution &S) { sawSolution(S); });
104-
}
105-
10674
static ActorIsolation
10775
getClosureActorIsolation(const Solution &S, AbstractClosureExpr *ACE) {
10876
auto getType = [&S](Expr *E) -> Type {

lib/IDE/TypeCheckCompletionCallback.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/Basic/Assertions.h"
1413
#include "swift/IDE/TypeCheckCompletionCallback.h"
14+
#include "swift/Basic/Assertions.h"
1515
#include "swift/IDE/CompletionLookup.h"
16-
#include "swift/Sema/CompletionContextFinder.h"
1716
#include "swift/Sema/ConstraintSystem.h"
1817
#include "swift/Sema/IDETypeChecking.h"
1918

2019
using namespace swift;
2120
using namespace swift::ide;
2221
using namespace swift::constraints;
2322

24-
void TypeCheckCompletionCallback::fallbackTypeCheck(DeclContext *DC) {
25-
assert(!GotCallback);
26-
27-
auto finder = CompletionContextFinder::forFallback(DC);
28-
if (!finder.hasCompletionExpr())
29-
return;
30-
31-
auto fallback = finder.getFallbackCompletionExpr();
32-
if (!fallback || isa<AbstractClosureExpr>(fallback->DC)) {
33-
// If the expression is embedded in a closure, the constraint system tries
34-
// to retrieve that closure's type, which will fail since we won't have
35-
// generated any type variables for it. Thus, fallback type checking isn't
36-
// available in this case.
37-
return;
38-
}
39-
40-
SyntacticElementTarget completionTarget(fallback->E, fallback->DC, CTP_Unused,
41-
Type(),
42-
/*isDiscared=*/true);
43-
typeCheckForCodeCompletion(completionTarget, /*needsPrecheck=*/true,
44-
[&](const Solution &S) { sawSolution(S); });
45-
}
46-
4723
// MARK: - Utility functions for subclasses of TypeCheckCompletionCallback
4824

4925
Type swift::ide::getTypeForCompletion(const constraints::Solution &S,

lib/IDE/UnresolvedMemberCompletion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/Basic/Assertions.h"
1413
#include "swift/IDE/UnresolvedMemberCompletion.h"
14+
#include "swift/Basic/Assertions.h"
1515
#include "swift/IDE/CodeCompletion.h"
1616
#include "swift/IDE/CompletionLookup.h"
17-
#include "swift/Sema/CompletionContextFinder.h"
1817
#include "swift/Sema/ConstraintSystem.h"
1918
#include "swift/Sema/IDETypeChecking.h"
2019

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func, Type builderType) {
10071007
cs.Options |= ConstraintSystemFlags::ForCodeCompletion;
10081008
cs.solveForCodeCompletion(solutions);
10091009

1010-
CompletionContextFinder analyzer(target, func->getDeclContext());
1010+
CompletionContextFinder analyzer(target);
10111011
if (analyzer.hasCompletion()) {
10121012
filterSolutionsForCodeCompletion(solutions, analyzer);
10131013
for (const auto &solution : solutions) {

0 commit comments

Comments
 (0)