Skip to content

Commit 4b7c6b1

Browse files
jensjohaCommit Queue
authored andcommitted
[parser] Remove (extension) Token.isA2
With 0ca1ff2 fixing the reason why we had `isA2` we can get rid of it. One 100-run-each-benchmark of compiling a fixed version of the CFE with the current version of the CFE I get ``` msec task-clock:u: -0.3133% +/- 0.2298% (-13.22 +/- 9.70) cycles:u: -0.4109% +/- 0.2303% (-71702583.62 +/- 40176749.86) instructions:u: -0.0150% +/- 0.0002% (-3206465.75 +/- 50567.00) branch-misses:u: -0.9597% +/- 0.8046% (-615355.48 +/- 515877.98) seconds time elapsed: -0.3138% +/- 0.2297% (-0.01 +/- 0.01) seconds user: -0.2991% +/- 0.2978% (-0.01 +/- 0.01) ``` (the only real thing to look at here is likely the `instructions:u` going down by ~3.2 mio.) For anyone interested: Manualy testing what 0ca1ff2 did vs the commit before (by running it 5 times each by hand through perf stat) I get instructions:u: -0.0831338% +/- 0.00115149% (-1.78503e+07 +/- 247246) (i.e. almost 18 mio less instructions). Change-Id: I01600c33364933da262b3354298255e8b2df8afb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394101 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent c1b7d34 commit 4b7c6b1

File tree

12 files changed

+454
-468
lines changed

12 files changed

+454
-468
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/identifier_context.dart

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -344,25 +344,25 @@ abstract class IdentifierContext {
344344
bool looksLikeExpressionStart(Token next) =>
345345
next.isIdentifier ||
346346
next.isKeyword && !looksLikeStatementStart(next) ||
347-
next.isA2(TokenType.DOUBLE) ||
348-
next.isA2(TokenType.DOUBLE_WITH_SEPARATORS) ||
349-
next.isA2(TokenType.HASH) ||
350-
next.isA2(TokenType.HEXADECIMAL) ||
351-
next.isA2(TokenType.HEXADECIMAL_WITH_SEPARATORS) ||
352-
next.isA2(TokenType.IDENTIFIER) ||
353-
next.isA2(TokenType.INT) ||
354-
next.isA2(TokenType.INT_WITH_SEPARATORS) ||
355-
next.isA2(TokenType.STRING) ||
356-
next.isA2(TokenType.OPEN_CURLY_BRACKET) ||
357-
next.isA2(TokenType.OPEN_PAREN) ||
358-
next.isA2(TokenType.OPEN_SQUARE_BRACKET) ||
359-
next.isA2(TokenType.INDEX) ||
360-
next.isA2(TokenType.LT) ||
361-
next.isA2(TokenType.BANG) ||
362-
next.isA2(TokenType.MINUS) ||
363-
next.isA2(TokenType.TILDE) ||
364-
next.isA2(TokenType.PLUS_PLUS) ||
365-
next.isA2(TokenType.MINUS_MINUS);
347+
next.isA(TokenType.DOUBLE) ||
348+
next.isA(TokenType.DOUBLE_WITH_SEPARATORS) ||
349+
next.isA(TokenType.HASH) ||
350+
next.isA(TokenType.HEXADECIMAL) ||
351+
next.isA(TokenType.HEXADECIMAL_WITH_SEPARATORS) ||
352+
next.isA(TokenType.IDENTIFIER) ||
353+
next.isA(TokenType.INT) ||
354+
next.isA(TokenType.INT_WITH_SEPARATORS) ||
355+
next.isA(TokenType.STRING) ||
356+
next.isA(TokenType.OPEN_CURLY_BRACKET) ||
357+
next.isA(TokenType.OPEN_PAREN) ||
358+
next.isA(TokenType.OPEN_SQUARE_BRACKET) ||
359+
next.isA(TokenType.INDEX) ||
360+
next.isA(TokenType.LT) ||
361+
next.isA(TokenType.BANG) ||
362+
next.isA(TokenType.MINUS) ||
363+
next.isA(TokenType.TILDE) ||
364+
next.isA(TokenType.PLUS_PLUS) ||
365+
next.isA(TokenType.MINUS_MINUS);
366366

367367
/// Returns `true` if [next] should be treated like the start of a pattern for
368368
/// the purposes of recovery.
@@ -371,59 +371,59 @@ bool looksLikeExpressionStart(Token next) =>
371371
/// we mostly re-use [looksLikeExpressionStart].
372372
bool looksLikePatternStart(Token next) =>
373373
next.isIdentifier ||
374-
next.isA2(TokenType.DOUBLE) ||
375-
next.isA2(TokenType.DOUBLE_WITH_SEPARATORS) ||
376-
next.isA2(TokenType.HASH) ||
377-
next.isA2(TokenType.HEXADECIMAL) ||
378-
next.isA2(TokenType.HEXADECIMAL_WITH_SEPARATORS) ||
379-
next.isA2(TokenType.IDENTIFIER) ||
380-
next.isA2(TokenType.INT) ||
381-
next.isA2(TokenType.INT_WITH_SEPARATORS) ||
382-
next.isA2(TokenType.STRING) ||
383-
next.isA2(Keyword.NULL) ||
384-
next.isA2(Keyword.FALSE) ||
385-
next.isA2(Keyword.TRUE) ||
386-
next.isA2(TokenType.OPEN_CURLY_BRACKET) ||
387-
next.isA2(TokenType.OPEN_PAREN) ||
388-
next.isA2(TokenType.OPEN_SQUARE_BRACKET) ||
389-
next.isA2(TokenType.INDEX) ||
390-
next.isA2(TokenType.LT) ||
391-
next.isA2(TokenType.LT_EQ) ||
392-
next.isA2(TokenType.GT) ||
393-
next.isA2(TokenType.GT_EQ) ||
394-
next.isA2(TokenType.BANG_EQ) ||
395-
next.isA2(TokenType.EQ_EQ) ||
396-
next.isA2(Keyword.VAR) ||
397-
next.isA2(Keyword.FINAL) ||
398-
next.isA2(Keyword.CONST);
374+
next.isA(TokenType.DOUBLE) ||
375+
next.isA(TokenType.DOUBLE_WITH_SEPARATORS) ||
376+
next.isA(TokenType.HASH) ||
377+
next.isA(TokenType.HEXADECIMAL) ||
378+
next.isA(TokenType.HEXADECIMAL_WITH_SEPARATORS) ||
379+
next.isA(TokenType.IDENTIFIER) ||
380+
next.isA(TokenType.INT) ||
381+
next.isA(TokenType.INT_WITH_SEPARATORS) ||
382+
next.isA(TokenType.STRING) ||
383+
next.isA(Keyword.NULL) ||
384+
next.isA(Keyword.FALSE) ||
385+
next.isA(Keyword.TRUE) ||
386+
next.isA(TokenType.OPEN_CURLY_BRACKET) ||
387+
next.isA(TokenType.OPEN_PAREN) ||
388+
next.isA(TokenType.OPEN_SQUARE_BRACKET) ||
389+
next.isA(TokenType.INDEX) ||
390+
next.isA(TokenType.LT) ||
391+
next.isA(TokenType.LT_EQ) ||
392+
next.isA(TokenType.GT) ||
393+
next.isA(TokenType.GT_EQ) ||
394+
next.isA(TokenType.BANG_EQ) ||
395+
next.isA(TokenType.EQ_EQ) ||
396+
next.isA(Keyword.VAR) ||
397+
next.isA(Keyword.FINAL) ||
398+
next.isA(Keyword.CONST);
399399

400400
/// Return `true` if the given [token] should be treated like the start of
401401
/// a new statement for the purposes of recovery.
402402
bool looksLikeStatementStart(Token token) =>
403-
token.isA2(TokenType.AT) ||
404-
token.isA2(Keyword.ASSERT) ||
405-
token.isA2(Keyword.BREAK) ||
406-
token.isA2(Keyword.CONTINUE) ||
407-
token.isA2(Keyword.DO) ||
408-
token.isA2(Keyword.ELSE) ||
409-
token.isA2(Keyword.FINAL) ||
410-
token.isA2(Keyword.FOR) ||
411-
token.isA2(Keyword.IF) ||
412-
token.isA2(Keyword.RETURN) ||
413-
token.isA2(Keyword.SWITCH) ||
414-
token.isA2(Keyword.TRY) ||
415-
token.isA2(Keyword.VAR) ||
416-
token.isA2(Keyword.VOID) ||
417-
token.isA2(Keyword.WHILE) ||
418-
token.isA2(TokenType.EOF);
403+
token.isA(TokenType.AT) ||
404+
token.isA(Keyword.ASSERT) ||
405+
token.isA(Keyword.BREAK) ||
406+
token.isA(Keyword.CONTINUE) ||
407+
token.isA(Keyword.DO) ||
408+
token.isA(Keyword.ELSE) ||
409+
token.isA(Keyword.FINAL) ||
410+
token.isA(Keyword.FOR) ||
411+
token.isA(Keyword.IF) ||
412+
token.isA(Keyword.RETURN) ||
413+
token.isA(Keyword.SWITCH) ||
414+
token.isA(Keyword.TRY) ||
415+
token.isA(Keyword.VAR) ||
416+
token.isA(Keyword.VOID) ||
417+
token.isA(Keyword.WHILE) ||
418+
token.isA(TokenType.EOF);
419419

420420
bool isOkNextValueInFormalParameter(Token token) =>
421-
token.isA2(TokenType.EQ) ||
422-
token.isA2(TokenType.COLON) ||
423-
token.isA2(TokenType.COMMA) ||
424-
token.isA2(TokenType.CLOSE_PAREN) ||
425-
token.isA2(TokenType.CLOSE_SQUARE_BRACKET) ||
426-
token.isA2(TokenType.CLOSE_CURLY_BRACKET);
421+
token.isA(TokenType.EQ) ||
422+
token.isA(TokenType.COLON) ||
423+
token.isA(TokenType.COMMA) ||
424+
token.isA(TokenType.CLOSE_PAREN) ||
425+
token.isA(TokenType.CLOSE_SQUARE_BRACKET) ||
426+
token.isA(TokenType.CLOSE_CURLY_BRACKET);
427427

428428
// TODO(ahe): Remove when analyzer supports generalized function syntax.
429429
typedef _MessageWithArgument<T> = Message Function(T);

0 commit comments

Comments
 (0)