Skip to content

[SourceKit] Lessen an assertion in the range resolver walker to allow early stop. rdar://29159963 #5686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/IDE/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ struct RangeResolver::Implementation {
public:
Implementation(SourceFile &File, SourceLoc Start, SourceLoc End) :
File(File), Start(Start), End(End), Content(getContent()) {}
~Implementation() { assert(ContextStack.empty()); }
bool hasResult() { return Result.hasValue(); }
void enter(ASTNode Node) { ContextStack.emplace_back(Node); }
void leave() { ContextStack.pop_back(); }
void leave(ASTNode Node) {
assert(ContextStack.back().Parent.getOpaqueValue() == Node.getOpaqueValue());
ContextStack.pop_back();
}

void analyze(ASTNode Node) {
auto &DCInfo = getCurrentDC();
Expand All @@ -245,6 +247,8 @@ struct RangeResolver::Implementation {

bool shouldEnter(ASTNode Node) {
SourceManager &SM = File.getASTContext().SourceMgr;
if (hasResult())
return false;
if (SM.isBeforeInBuffer(End, Node.getSourceRange().Start))
return false;
if (SM.isBeforeInBuffer(Node.getSourceRange().End, Start))
Expand Down Expand Up @@ -288,44 +292,43 @@ bool RangeResolver::walkToExprPre(Expr *E) {
return false;
Impl.analyze(E);
Impl.enter(E);
return !Impl.hasResult();
return true;
}

bool RangeResolver::walkToStmtPre(Stmt *S) {
if (!Impl.shouldEnter(S))
return false;
Impl.analyze(S);
Impl.enter(S);
return !Impl.hasResult();
return true;
};

bool RangeResolver::walkToDeclPre(Decl *D, CharSourceRange Range) {
if (!Impl.shouldEnter(D))
return false;
Impl.analyze(D);
Impl.enter(D);
return !Impl.hasResult();
return true;
}

bool RangeResolver::walkToExprPost(Expr *E) {
Impl.leave();
Impl.leave(E);
return !Impl.hasResult();
}

bool RangeResolver::walkToStmtPost(Stmt *S) {
Impl.leave();
Impl.leave(S);
return !Impl.hasResult();
};

bool RangeResolver::walkToDeclPost(Decl *D) {
Impl.leave();
Impl.leave(D);
return !Impl.hasResult();
}

ResolvedRangeInfo RangeResolver::resolve() {
Impl.enter(ASTNode());
walk(Impl.File);
Impl.leave();
return Impl.getResult();
}

Expand Down