Skip to content

Commit efe9002

Browse files
committed
[IDE] Remove extension binding logic from typeCheckContextAt
Now that we correctly bind extensions after mutating the AST, this is no longer necessary.
1 parent 19ee72e commit efe9002

File tree

5 files changed

+8
-51
lines changed

5 files changed

+8
-51
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,12 +1485,12 @@ void CodeCompletionCallbacksImpl::typeCheckWithLookup(
14851485
ASTNode Call = CallExpr::create(
14861486
CurDeclContext->getASTContext(), AttrWithCompletion->getTypeExpr(),
14871487
AttrWithCompletion->getArgs(), /*implicit=*/true);
1488-
typeCheckContextAt(
1488+
swift::typeCheckASTNodeAtLoc(
14891489
TypeCheckASTNodeAtLocContext::node(CurDeclContext, Call),
14901490
CompletionLoc);
14911491
}
14921492
} else {
1493-
typeCheckContextAt(
1493+
swift::typeCheckASTNodeAtLoc(
14941494
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
14951495
CompletionLoc);
14961496
}
@@ -1551,8 +1551,9 @@ void CodeCompletionCallbacksImpl::postfixCompletion(SourceLoc CompletionLoc,
15511551

15521552
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
15531553
Context.CompletionCallback, &Lookup);
1554-
typeCheckContextAt(TypeCheckASTNodeAtLocContext::node(CurDeclContext, AE),
1555-
CompletionLoc);
1554+
swift::typeCheckASTNodeAtLoc(
1555+
TypeCheckASTNodeAtLocContext::node(CurDeclContext, AE),
1556+
CompletionLoc);
15561557
Lookup.collectResults(/*IsLabeledTrailingClosure=*/true, CompletionLoc,
15571558
CurDeclContext, CompletionContext);
15581559
}
@@ -1711,7 +1712,7 @@ void CodeCompletionCallbacksImpl::doneParsing(SourceFile *SrcFile) {
17111712

17121713
if (Kind != CompletionKind::TypeSimpleWithDot) {
17131714
// Type member completion does not need a type-checked AST.
1714-
typeCheckContextAt(
1715+
swift::typeCheckASTNodeAtLoc(
17151716
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
17161717
ParsedExpr ? ParsedExpr->getLoc()
17171718
: CurDeclContext->getASTContext()

lib/IDE/ConformingMethodList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void ConformingMethodListCallbacks::doneParsing(SourceFile *SrcFile) {
109109
{
110110
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
111111
Context.CompletionCallback, &TypeCheckCallback);
112-
typeCheckContextAt(
112+
swift::typeCheckASTNodeAtLoc(
113113
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
114114
CCExpr->getLoc());
115115
}

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,45 +40,6 @@
4040
using namespace swift;
4141
using namespace ide;
4242

43-
//===----------------------------------------------------------------------===//
44-
// typeCheckContextAt(DeclContext, SourceLoc)
45-
//===----------------------------------------------------------------------===//
46-
47-
void swift::ide::typeCheckContextAt(TypeCheckASTNodeAtLocContext TypeCheckCtx,
48-
SourceLoc Loc) {
49-
// Make sure the extension has been bound.
50-
auto DC = TypeCheckCtx.getDeclContext();
51-
// Even if the extension is invalid (e.g. nested in a function or another
52-
// type), we want to know the "intended nominal" of the extension so that
53-
// we can know the type of 'Self'.
54-
SmallVector<ExtensionDecl *, 1> extensions;
55-
for (auto typeCtx = DC->getInnermostTypeContext(); typeCtx != nullptr;
56-
typeCtx = typeCtx->getParent()->getInnermostTypeContext()) {
57-
if (auto *ext = dyn_cast<ExtensionDecl>(typeCtx))
58-
extensions.push_back(ext);
59-
}
60-
while (!extensions.empty()) {
61-
extensions.back()->computeExtendedNominal();
62-
extensions.pop_back();
63-
}
64-
65-
// If the completion happens in the inheritance clause of the extension,
66-
// 'DC' is the parent of the extension. We need to iterate the top level
67-
// decls to find it. In theory, we don't need the extended nominal in the
68-
// inheritance clause, but ASTScope lookup requires that. We don't care
69-
// unless 'DC' is not 'SourceFile' because non-toplevel extensions are
70-
// 'canNeverBeBound()' anyway.
71-
if (auto *SF = dyn_cast<SourceFile>(DC)) {
72-
auto &SM = DC->getASTContext().SourceMgr;
73-
for (auto *decl : SF->getTopLevelDecls())
74-
if (auto *ext = dyn_cast<ExtensionDecl>(decl))
75-
if (SM.rangeContainsTokenLoc(ext->getSourceRange(), Loc))
76-
ext->computeExtendedNominal();
77-
}
78-
79-
swift::typeCheckASTNodeAtLoc(TypeCheckCtx, Loc);
80-
}
81-
8243
//===----------------------------------------------------------------------===//
8344
// findParsedExpr(DeclContext, Expr)
8445
//===----------------------------------------------------------------------===//

lib/IDE/ExprContextAnalysis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class ValueDecl;
2828
namespace ide {
2929
enum class SemanticContextKind : uint8_t;
3030

31-
/// Type check parent contexts of the given decl context, and the body of the
32-
/// given context until \c Loc if the context is a function body.
33-
void typeCheckContextAt(TypeCheckASTNodeAtLocContext TypeCheckCtx,
34-
SourceLoc Loc);
35-
3631
/// From \p DC, find and returns the outer most expression which source range is
3732
/// exact the same as \p TargetRange. Returns \c nullptr if not found.
3833
Expr *findParsedExpr(const DeclContext *DC, SourceRange TargetRange);

lib/IDE/TypeContextInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void ContextInfoCallbacks::doneParsing(SourceFile *SrcFile) {
119119
{
120120
llvm::SaveAndRestore<TypeCheckCompletionCallback *> CompletionCollector(
121121
Context.CompletionCallback, &TypeCheckCallback);
122-
typeCheckContextAt(
122+
swift::typeCheckASTNodeAtLoc(
123123
TypeCheckASTNodeAtLocContext::declContext(CurDeclContext),
124124
ParsedExpr->getLoc());
125125
}

0 commit comments

Comments
 (0)