Skip to content

Commit d337376

Browse files
jensjohaCommit Queue
authored andcommitted
[parser] Cheaper recovery for List<Foo>[ and Map<Foo, Bar>{}
Recovery for erroneous literals like `Map<int, int>{}` was added in https://dart-review.googlesource.com/c/sdk/+/190022. This CL makes it cheaper. pkg/analyzer/lib/src/dart/ast/ast.dart: JIT (tokens per microsecond): No change. AOT (tokens per microsecond): 7.9552% +/- 2.1091% (2.41 +/- 0.64) (30.27 -> 32.67) Benchmarker (AOT): ``` msec task-clock:u: -2.1591% +/- 0.8194% (-55.46 +/- 21.05) (2568.82 -> 2513.36) page-faults:u: 0.2247% +/- 0.0145% (23.00 +/- 1.49) (10235.92 -> 10258.92) cycles:u: -2.2243% +/- 0.8087% (-248083632.76 +/- 90197190.45) (11153502206.48 -> 10905418573.72) instructions:u: -3.6023% +/- 0.0000% (-827054283.92 +/- 721.20) (22958796659.48 -> 22131742375.56) seconds time elapsed: -2.1582% +/- 0.8241% (-0.06 +/- 0.02) (2.57 -> 2.51) seconds user: -2.2825% +/- 0.8882% (-0.06 +/- 0.02) (2.55 -> 2.49) ``` pkg/front_end/lib/src/type_inference/inference_visitor.dart: JIT (tokens per microsecond): 4.3711% +/- 1.3011% (0.84 +/- 0.25) (19.11 -> 19.94) AOT (tokens per microsecond): 5.3025% +/- 1.0032% (1.32 +/- 0.25) (24.95 -> 26.27) Benchmarker (AOT): ``` msec task-clock:u: -4.2295% +/- 1.0942% (-104.20 +/- 26.96) (2463.65 -> 2359.45) page-faults:u: 0.0773% +/- 0.0141% (7.68 +/- 1.40) (9937.76 -> 9945.44) cycles:u: -4.3497% +/- 1.0959% (-465492322.32 +/- 117280203.19) (10701783151.44 -> 10236290829.12) instructions:u: -5.0470% +/- 0.0000% (-1145391707.84 +/- 802.85) (22694337726.36 -> 21548946018.52) seconds time elapsed: -4.2224% +/- 1.0991% (-0.10 +/- 0.03) (2.47 -> 2.36) seconds user: -4.2597% +/- 1.1024% (-0.10 +/- 0.03) (2.44 -> 2.34) ``` Change-Id: I77b865c455d80557646b77921f0b808383c67bdb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443060 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 77850b7 commit d337376

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8757,11 +8757,11 @@ class Parser {
87578757
Token next = token.next!;
87588758
if (next.kind == IDENTIFIER_TOKEN) {
87598759
Token identifier = next;
8760-
String value = identifier.lexeme;
8761-
if (value == "Map" || value == "Set") {
8762-
potentialTypeArg = computeTypeParamOrArg(identifier);
8763-
afterToken = potentialTypeArg.skip(identifier).next!;
8764-
if (afterToken.isA(TokenType.OPEN_CURLY_BRACKET)) {
8760+
potentialTypeArg = computeTypeParamOrArg(identifier);
8761+
afterToken = potentialTypeArg.skip(identifier).next!;
8762+
if (afterToken.isA(TokenType.OPEN_CURLY_BRACKET)) {
8763+
String value = identifier.lexeme;
8764+
if (value == "Map" || value == "Set") {
87658765
// Recover by ignoring the `Map`/`Set` and parse as a literal map/set.
87668766
reportRecoverableError(
87678767
identifier,
@@ -8772,12 +8772,11 @@ class Parser {
87728772
);
87738773
return parsePrimary(identifier, context, ConstantPatternContext.none);
87748774
}
8775-
} else if (value == "List") {
8776-
potentialTypeArg = computeTypeParamOrArg(identifier);
8777-
afterToken = potentialTypeArg.skip(identifier).next!;
8778-
if ((potentialTypeArg != noTypeParamOrArg &&
8779-
afterToken.isA(TokenType.OPEN_SQUARE_BRACKET)) ||
8780-
afterToken.isA(TokenType.INDEX)) {
8775+
} else if ((potentialTypeArg != noTypeParamOrArg &&
8776+
afterToken.isA(TokenType.OPEN_SQUARE_BRACKET)) ||
8777+
afterToken.isA(TokenType.INDEX)) {
8778+
String value = identifier.lexeme;
8779+
if (value == "List") {
87818780
// Recover by ignoring the `List` and parse as a literal List.
87828781
// Note that we here require the `<...>` for `[` as `List[` would be
87838782
// an indexed expression. `List[]` wouldn't though, so we don't

0 commit comments

Comments
 (0)