Skip to content

Commit 17f5a6e

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 fb8f71e commit 17f5a6e

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
@@ -1366,10 +1366,11 @@ class Parser {
13661366
return nullptr;
13671367
}
13681368

1369-
// Spin the lexer until we get to the ending location.
1370-
while (Tok.getLoc().getOpaquePointerValue() < endLocPtr &&
1371-
!Tok.is(tok::eof))
1372-
consumeToken();
1369+
// Reset the lexer to the ending location.
1370+
StringRef contents =
1371+
SourceMgr.extractText(SourceMgr.getRangeForBuffer(L->getBufferID()));
1372+
L->resetToOffset((const char *)endLocPtr - contents.data());
1373+
L->lex(Tok);
13731374

13741375
return makeParserResult(astNode);
13751376
}

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)