Skip to content

Commit 9dcfbf2

Browse files
committed
[Parser] Reset C++ lexer just past the whole ASTGen-parsed syntax node
Instead of "spinning" the C++ lexer, consuming tokens uptil we get past the point where ASTGen told us the end of the syntax node was, just reset the lexer to exactly that position. This is more efficient, but also fixes problems where we would end up skipping past a `>` that had been split.
1 parent f3d8feb commit 9dcfbf2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/swift/Parse/Parser.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,10 +1361,11 @@ class Parser {
13611361
return nullptr;
13621362
}
13631363

1364-
// Spin the lexer until we get to the ending location.
1365-
while (Tok.getLoc().getOpaquePointerValue() < endLocPtr &&
1366-
!Tok.is(tok::eof))
1367-
consumeToken();
1364+
// Reset the lexer to the ending location.
1365+
StringRef contents =
1366+
SourceMgr.extractText(SourceMgr.getRangeForBuffer(L->getBufferID()));
1367+
L->resetToOffset((const char *)endLocPtr - contents.data());
1368+
L->lex(Tok);
13681369

13691370
return makeParserResult(astNode);
13701371
}

test/ASTGen/types.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ func test12a(i: Int) {
3535
func test13(body: (_ value: Int) -> Void, i: Int) {
3636
body(i)
3737
}
38+
39+
func test14() {
40+
_ = Array<Array<Array<Int>>>().count
41+
}

0 commit comments

Comments
 (0)