112 Commits

Author SHA1 Message Date
Konstantin Shcheglov f8ef9fdb61 Patterns. Fix for parsing nested pattern assigment: 'v2 = (v1) = 0'.
Change-Id: I4b3460dd57834eb52b4703c983ca6f8ed60fe270
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508684
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-06-03 08:52:55 -07:00
Konstantin Shcheglov b9d3c903a0 Patterns. Report invalidConstantPatternBinary for 'case a.b + c.d'.
Bug: https://github.com/dart-lang/sdk/issues/63356
Change-Id: Id26a0cebf5aa0320e1d3fc62ca630fe8e7716241
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507580
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-06-01 09:53:09 -07:00
Konstantin Shcheglov 4629bff7e9 Augment. Report extensionTypeAugmentationSpecifiesRepresentationField.
Add a syntactic diagnostic for extension type augmentations that declare
representation fields. Extension type augmentations may augment the
declaration, but they must not redeclare the representation.

Thread an explicit parser option through primary constructor parsing so
extension type augmentations can omit a representation without producing
the usual missing-primary-constructor diagnostics, while still reporting
an error when a representation is present.

Register the new diagnostic in the shared and analyzer generated
diagnostic tables and add it to fix status tracking.

Change-Id: I84815bb0669a76126564e590760e93096a3af046
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-22 17:36:54 -07:00
Jens Johansen 4ee8852d77 [CFE/parser] Update 'end' on endLiteralString; Set offset of StringConcatenation to the start; rename 'token' to 'operatorToken' on endBinaryPatterns
* The 'end' token on endLiteralString is now the last token of the
   string, not the next unrelated token.
 * Set the offset of StringConcatenation to the start of the string,
   not the start of the next unrelated token.
 * The 'end' token on endBinaryPatterns is renamed to 'operatorToken'.

Fixes https://github.com/dart-lang/sdk/issues/55690

Tested: Existing
Change-Id: Iae788464008594c21e759570a626971d89688033
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498601
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-30 01:05:23 -07:00
Johnni Winther 5b0def4a87 [parser][Augmentations] Remove support for macro class and import augment
These were part of the macros experiments which has been cancelled.

Change-Id: I14071bc8e86025f273a533c313a3194c8eae5190
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495341
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-04-16 02:25:05 -07:00
Konstantin Shcheglov e7c6654312 Augment. Allow abstract top-level variables.
Permit `abstract` on top-level variable declarations when the
augmentations feature is enabled. Previously the parser always reported
`abstract` as extraneous at the top level, which rejected valid syntax
and dropped the modifier before later stages could see it.

Thread the abstract token through top-level field parsing, record it on
`TopLevelVariableDeclaration`, and pass it through the front-end
builders. Reorder the field callback arguments so `augment` precedes
`abstract`, matching the augmentation grammar for incomplete top-level
variables and keeping the parser, listener, and outline plumbing
consistent.

Change-Id: I680414a746b707d483e485702685c95f28a9c9ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-14 16:12:24 -07:00
Johnni Winther beff8b11f2 [cfe][PrimaryConstructors] Avoid creating tear-off lowering for abstract classes
A flag that tells whether constructor is in an abstract class, enum or mixin was not correctly passed for primary constructors. This flag determines whether constructor tear-off lowerings are created for backends that use this, such dart2js and dartdevc.

The parser listener is updated to pass a DeclarationKind for primary constructors, similar to what is already done for regular constructors. The enable the CFE to pass the correct flag.

Change-Id: I114417795ae276dfeab9f10a0b0fcbcd2dbfc00b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490541
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-03-26 00:57:59 -07:00
Paul Berry 69a1a497f1 [messages] Stop using withArgumentsOld, batch 32.
This is one of several planned batches of changes to transition the
front end (and related packages) away from the old `withArgumentsOld`
diagnostic reporting method, and to the new `withArguments`
method. The difference between the two is that `withArguments` has
named parameters rather than positional ones, so (a) it's less likely
for parameters to be mixed up, and (b) it's compatible with the
calling conventions used by analyzer diagnostics.

As part of this transition, I'm taking the opportunity to rename the
parameters themselves (since the names previously were restricted to a
very small set of possibilities based on type), and to document them
in `messages.yaml`. To avoid fatigue (both for myself and code
reviewers), I've chosen to break the change into many smaller batches.

The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator, running the script
`use_new_with_arguments.dart`, and then updating front end parser
expectations.

Change-Id: I6a6a6964699f00e7e91af2e682ce1baa1846ca13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478060
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-02-04 10:05:41 -08:00
Paul Berry d579b03f71 [messages] Use withArguments for diagnostics translated by the analyzer.
Changes the `front_end` and `_fe_analyzer_shared` code that reports
the following diagnostics so that it uses `withArguments` rather than
`withArgumentsOld`:

- `expectedButGot`
- `expectedButGot2`
- `expectedAfterButGot`
- `expectedToken`
- `unmatchedToken`
- `constFieldWithoutInitializer`
- `finalFieldWithoutInitializer`
- `superclassHasNoMethod`
- `unavailableDartLibrary`
- `unsupportedPlatformDartLibraryImport`

These messages required special care because they are translated into
analyzer diagnostics by the analyzer method
`FastaErrorReporter.reportByCode`, and the logic to do the translation
depends on the exact parameter names used by the messages.

For some of the messages I've clarified the parameter names and
updated `FastaErrorReporter.reportByCode` accordingly. For others, I
left the parameter names as is.

Change-Id: I6a6a696481c75f4cbb198d1e012aa1ca4294ed61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476323
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-30 10:12:42 -08:00
Johnni Winther 0a154753c6 [parser][InternalNodes] Add handlePositionalArgument and handlePositionalRecordField
This [handlePositionalArgument] and [handlePositionalRecordField] methods to the parser listener, allowing listeners to normals arguments and record fields

Change-Id: I3947e196dafffea2ab383f797904c857db8327ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469620
Reviewed-by: Jens Johansen <jensj@google.com>
2026-01-06 02:30:12 -08:00
Johnni Winther 45679bcac9 [parser] Support new constructor syntax
This adds parser support of the new constructor syntax using `new` instead of the enclosing class name

Part of https://github.com/dart-lang/sdk/issues/61699

Change-Id: I3de50298e83f431c765a987435324b8c8931eef7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462042
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-19 03:05:01 -08:00
Johnni Winther 808b2512b4 [parser] Add beginConstructor
This adds a beginConstructor listener method and calls this before constructor instead of beginMethod. This makes it possible for listeners to fully separate handling of constructors from methods.

Change-Id: Ibcbcf76ccb6d97314d395c4c0efcb4f9d073519a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-18 05:26:52 -08:00
Johnni Winther d46bd8cf58 [parser] Merge parser listener endX methods
This merges endX methods for non-top-level members into endMethod, endConstructor, endFactory and endFields.

These methods now have a DeclarationKind parameter that can be used to distinguish them.

Change-Id: I458d37a70b6c7839612f7199dad95f9a61e76e7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462120
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-17 04:50:52 -08:00
Johnni Winther 7352e9c044 [parser] Remove getOrSet token from endXConstructor methods
These were never used and just confused implementations about what to handle.

Change-Id: I1fa4868e043a716b60bec107e4ba57018eee63be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460460
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-11-11 02:54:57 -08:00
Johnni Winther a58eb47216 [parser] Support new factory constructor syntax
Part of https://github.com/dart-lang/sdk/issues/61699

Change-Id: I6afa9f4991d4b965a60d39e14618731a10a04a1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459820
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-11-07 00:45:41 -08:00
Johnni Winther 02c3d9c3f0 [parser] Support declaring parameters
This allows `var int a` in primary constructors when the declaring constructors feature is enabled.

Part of https://github.com/dart-lang/sdk/issues/61699

Change-Id: I486ad8aa3ddbe09451455b024b3aa9cfbaa9a5e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456340
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-10-22 01:46:47 -07:00
Johnni Winther 49eb514005 [parser] Support primary constructor on classes, enums and extension types
This adds simple support for primary constructors in class, enum and extension type declarations. Declaring formals are not supported yet.

Change-Id: I2fb2cb3a819e38ec4ffe961da4713a871ac29a0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2025-10-17 01:52:11 -07:00
Jens Johansen 42c5fe7e05 [parser] Fix crash in _attemptPrecedenceLevelRecovery
`_recoverAtPrecedenceLevel` being set to `true` was carried over from
`parsePattern` to `_parsePrecedenceExpressionLoop` which caused it to
crash.

Fixes https://github.com/dart-lang/sdk/issues/61239.

Change-Id: I61eec96ebd403bf2167fed11703a2fac03cfc9b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445260
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-08-14 07:26:41 -07:00
Paul Berry ff5962306a [front end] Make code... objects usable as error templates.
This is part of a series of CLs that will standardize CFE error
reporting to always use `codeFoo.withArguments(...)` when reporting
errors that take arguments and `codeFoo` when reporting errors that
don't take arguments, rather than `templateFoo.withArguments(...)`
when reporting errors that take arguments and `messageFoo` when
reporting errors that don't take arguments. This change will have two
advantages:

- It will lend greater consistency to the CFE codebase, by allowing
  the same `code...` objects to be used both to name error codes
  (e.g., in test expectations) and to report errors. This will allow
  everything associated with a certain error code to be found using a
  single invocation of "Find References" in the editor, rather than
  having to search separately for uses of the code and the message or
  template.

- It should hopefully make the experience of writing code that reports
  errors more pleasant, since it will no longer be necessary to look
  up an error to see whether it takes arguments before using it;
  instead, the developer will be able to type the name of the message
  `code...` declaration, and then use autocompletion to see whether
  `.withArguments(...)` is required.

In this CL, the code generator for error messages is changed so that
both `template...` and `code...` declarations have the static type
`Template` (and, indeed, refer to the same constant
object). Previously, `code...` declarations had the static type
`Code`, and referred to a constant object with runtime type
`Code`. This will allow uses of `template...` to be replaced with
`code...`. In follow-up CLs, the uses of `template...` will be changed
to `code...`, and the `template...` declarations will be removed.

Since the `toString` methods on `Template` and `Code` differ, I had to
make some changes to ID tests and parser tests, both of which depend
on the behavior of `toString`:

- For ID tests, I was able to preserve the existing test expectations
  by modifying the `errorsToText` function (in
  `pkg/front_end/lib/src/testing/id_testing_utils.dart`).

- For parser tests, I wasn't able to find an easy way to preserve the
  existing test expectations, so I updated the expectations to match
  the new behavior.

Change-Id: I8a461d451b06dd2f88b3e59f0cb2153711b09461
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442731
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-08-06 06:37:31 -07:00
Johnni Winther 9404899248 [parser] Split handleEndingBinaryExpression into handleDotAccess and handleCascadeAccess
This splits handleEndingBinaryExpression into two new listeners handleDotAccess for `.` and `?.` access and handleCascadeAccess for `..` and `?..`, both with an explicit `isNullAware` flag.

This is a step towards handling `a.b` different from `a + b` in the parser such that listeners don't have to create a value for `b` the works in both use cases; in the first is just a named operation performed on the receiver, whereas in the second case it is a full expression in its own right.

Change-Id: I04ec80401f8f2dbb8dffa86543c434e530b18cf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442821
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-07-31 02:02:28 -07:00
Jens Johansen 04096b9891 [parser] Shortcut more common cases in parseArgumentsRest
A few more common cases: "<identifier> <period> <identifier> <comma>",
"<identifier> <period> <identifier> <end parens>", "<string> <comma">
and "<string> <end parens>".

pkg/analyzer/lib/src/dart/ast/ast.dart:

JIT (tokens per microsecond):
4.8482% +/- 1.4622% (1.11 +/- 0.34) (22.92 -> 24.03)

AOT (tokens per microsecond):
4.5974% +/- 1.6421% (1.40 +/- 0.50) (30.53 -> 31.94)

Benchmarker (AOT):
```
msec task-clock:u: -4.7108% +/- 2.0520% (-124.92 +/- 54.41) (2651.72 -> 2526.80)
cycles:u: -4.7512% +/- 2.0346% (-546787446.10 +/- 234152251.09) (11508497283.00 -> 10961709836.90)
instructions:u: -4.5849% +/- 0.0000% (-1115885935.90 +/- 1109.34) (24338242436.20 -> 23222356500.30)
seconds time elapsed: -4.7090% +/- 2.0523% (-0.12 +/- 0.05) (2.65 -> 2.53)
seconds user: -4.8217% +/- 2.0991% (-0.13 +/- 0.06) (2.63 -> 2.51)
```


pkg/front_end/lib/src/type_inference/inference_visitor.dart:

JIT (tokens per microsecond):
11.5950% +/- 3.4217% (1.96 +/- 0.58) (16.91 -> 18.87)

AOT (tokens per microsecond):
11.7128% +/- 1.4863% (2.61 +/- 0.33) (22.32 -> 24.94)

Benchmarker (AOT):
```
msec task-clock:u: -8.9523% +/- 0.8309% (-244.45 +/- 22.69) (2730.57 -> 2486.12)

page-faults:u: 0.0503% +/- 0.0216% (5.00 +/- 2.14) (9933.10 -> 9938.10)
cycles:u: -9.0605% +/- 0.8306% (-1075717286.20 +/- 98615789.63) (11872662784.50 -> 10796945498.30)
instructions:u: -13.7568% +/- 0.0000% (-3608232664.50 +/- 836.10) (26228691068.30 -> 22620458403.80)
branch-misses:u: 6.9875% +/- 4.6549% (2539140.50 +/- 1691509.92) (36338407.60 -> 38877548.10)
seconds time elapsed: -8.9450% +/- 0.8300% (-0.24 +/- 0.02) (2.73 -> 2.49)
seconds user: -8.9919% +/- 0.8899% (-0.24 +/- 0.02) (2.71 -> 2.47)
```
Change-Id: I207a35d8107ba1604646e387e590aa19a4ccd996
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439900
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-07-31 00:41:31 -07:00
Jens Johansen 59f19d8771 [parser] Shortcut common case in parseArgumentsRest
Observation: Often when about to call parseExpression in
parseArgumentsRest we see either "<identifier> <comma>" (say, we're
passing a variable) or "<identifier> <end parens>" (same case, but last
argument).

This CL allows us to shortcut such cases avoiding a lot of calls where
we check if it's other cases which it isn't.

pkg/analyzer/lib/src/dart/ast/ast.dart:

JIT (tokens per microsecond):
5.5605% +/- 4.0086% (1.16 +/- 0.84) (20.94 -> 22.10)

AOT (tokens per microsecond):
7.1788% +/- 2.5682% (2.04 +/- 0.73) (28.44 -> 30.48)

Benchmarker (AOT):
```
msec task-clock:u: -4.4173% +/- 1.7793% (-124.29 +/- 50.07) (2813.81 -> 2689.52)
page-faults:u: 0.1064% +/- 0.0131% (10.90 +/- 1.35) (10246.00 -> 10256.90)
cycles:u: -4.4718% +/- 1.7882% (-546472914.30 +/- 218528412.28) (12220314431.60 -> 11673841517.30)
instructions:u: -10.0011% +/- 0.0000% (-2704578213.40 +/- 1611.58) (27042820700.90 -> 24338242487.50)
seconds time elapsed: -4.4160% +/- 1.7779% (-0.12 +/- 0.05) (2.82 -> 2.69)
seconds user: -4.6324% +/- 1.8285% (-0.13 +/- 0.05) (2.80 -> 2.67)
```


pkg/front_end/lib/src/type_inference/inference_visitor.dart:

JIT (tokens per microsecond):
10.1981% +/- 1.2476% (1.58 +/- 0.19) (15.46 -> 17.04)

AOT (tokens per microsecond):
8.7843% +/- 1.5781% (1.79 +/- 0.32) (20.42 -> 22.22)

Benchmarker (AOT):
```
msec task-clock:u: -5.9322% +/- 2.7532% (-181.01 +/- 84.01) (3051.38 -> 2870.37)

page-faults:u: 0.0352% +/- 0.0261% (3.50 +/- 2.59) (9930.90 -> 9934.40)
cycles:u: -6.0726% +/- 2.7273% (-805818237.40 +/- 361907438.70) (13269703092.60 -> 12463884855.20)
instructions:u: -11.9540% +/- 0.0000% (-3561054138.90 +/- 1016.14) (29789745342.80 -> 26228691203.90)
seconds time elapsed: -5.9310% +/- 2.7520% (-0.18 +/- 0.08) (3.05 -> 2.87)
seconds user: -6.1531% +/- 2.7477% (-0.19 +/- 0.08) (3.03 -> 2.85)
```
Change-Id: Ia4fbdcbd438a38a0c07b3f4423812ef3507b626c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439880
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-07-31 00:41:03 -07:00
Jens Johansen 86b65842ed [parser] Manually inline 'isNextIdentifier'
pkg/analyzer/lib/src/dart/ast/ast.dart:

JIT (tokens per microsecond):
2.1064% +/- 1.6771% (0.44 +/- 0.35) (20.97 -> 21.42)

AOT (tokens per microsecond):
No change.

Benchmarker (AOT):
```
msec task-clock:u: -1.2559% +/- 0.6202% (-35.75 +/- 17.65) (2846.58 -> 2810.83)
cycles:u: -1.3051% +/- 0.6113% (-161347113.30 +/- 75579075.11) (12362747585.00 -> 12201400471.70)
instructions:u: -0.6245% +/- 0.0000% (-169931728.50 +/- 1390.09) (27212753414.40 -> 27042821685.90)
seconds time elapsed: -1.2465% +/- 0.6111% (-0.04 +/- 0.02) (2.85 -> 2.81)
seconds user: -1.3083% +/- 0.7709% (-0.04 +/- 0.02) (2.83 -> 2.79)
```


pkg/front_end/lib/src/type_inference/inference_visitor.dart:

JIT (tokens per microsecond):
No change.

AOT (tokens per microsecond):
No change.

Benchmarker (AOT):
```
instructions:u: -0.9284% +/- 0.0000% (-279155451.00 +/- 502.76) (30068900827.90 -> 29789745376.90)
```

Change-Id: I70eaae39d156f77e5e451a8592f6f3dab2da3d67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439780
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-07-30 07:13:16 -07:00
Jens Johansen 752b760308 [parser] notEofOrValue -> notEofOrType - skip string comparison
A small one.

pkg/analyzer/lib/src/dart/ast/ast.dart:

JIT (tokens per microsecond):
1.7597% +/- 1.4621% (0.37 +/- 0.30) (20.79 -> 21.15)

AOT (tokens per microsecond):
2.2547% +/- 1.6761% (0.62 +/- 0.46) (27.67 -> 28.30)

Benchmarker (AOT):
```
msec task-clock:u: -2.4779% +/- 1.3546% (-73.29 +/- 40.07) (2957.87 -> 2884.58)
cycles:u: -2.6238% +/- 1.3918% (-337224094.10 +/- 178886541.74) (12852601263.80 -> 12515377169.70)
instructions:u: -0.9484% +/- 0.0000% (-260552753.00 +/- 375.88) (27473305680.40 -> 27212752927.40)
branch-misses:u: -8.7134% +/- 6.9328% (-3191115.20 +/- 2538992.37) (36623085.10 -> 33431969.90)
seconds time elapsed: -2.4691% +/- 1.3512% (-0.07 +/- 0.04) (2.96 -> 2.89)
seconds user: -2.4294% +/- 1.3675% (-0.07 +/- 0.04) (2.93 -> 2.86)
```


pkg/front_end/lib/src/type_inference/inference_visitor.dart:

JIT (tokens per microsecond):
No change.

AOT (tokens per microsecond):
No change.

Benchmarker (AOT):
```
msec task-clock:u: -4.3099% +/- 1.9546% (-136.28 +/- 61.81) (3162.10 -> 3025.81)
cycles:u: -4.3066% +/- 1.9530% (-592061704.80 +/- 268488936.68) (13747787475.20 -> 13155725770.40)
instructions:u: -0.5194% +/- 0.0000% (-156988901.90 +/- 1876.14) (30225890142.20 -> 30068901240.30)
branch-misses:u: -14.2999% +/- 7.5350% (-6167339.80 +/- 3249736.99) (43128654.50 -> 36961314.70)
seconds time elapsed: -4.3098% +/- 1.9527% (-0.14 +/- 0.06) (3.16 -> 3.03)
seconds user: -4.3252% +/- 1.9575% (-0.14 +/- 0.06) (3.14 -> 3.01)
```

Change-Id: Ib70398e337c482f7427debb6875e2c17ccc6bd0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439740
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-07-30 07:06:17 -07:00
Johnni Winther dced5e0482 [cfe] Add LocalTypeParameterScope
This cleans up the LocalScope interface and the handling of named function expressions.

Change-Id: Id0432910a9e65d8ae966dfab67c66248639d241a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419842
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-04-03 03:43:30 -07:00
Jens Johansen e30f60791a [parser] Don't use the next token as the end on handleSend
Change-Id: Ic4bacffab3fdd9d23bea9b1ecd0f2cfdecb82e2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399060
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-12-05 15:10:34 +00:00
Johnni Winther 4d552d19eb [_fe_analyzer_shared] Rename StringJuxtaposition to AdjacentStringLiterals
Change-Id: I2ed9172f51f9a9011ca9dff59c62c42ffb56f05e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391605
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-24 09:40:25 +00:00
Johnni Winther cd236ece98 [parser] Add enclosingDeclarationName to beginMethod
This adds the enclosingDeclarationName to the beginMethod of the
parser listener.

This enables the removal BuilderFactory.currentTypeParameterScopeBuilder.

Change-Id: Ie2bec9432c20b8bdbd62a14e8a65c272179d4698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383182
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-09-05 07:40:09 +00:00
Johnni Winther bf3c716f36 [cfe] Create FunctionTypeParameterBuilder for function types
This changes the BodyBuilder to create FunctionTypeParameter instead
of FormalParameterBuilder for "parameters" in function types. This
avoids the creation of unnecessary VariableDeclaration nodes
function types.

The types of these VariableDeclarations where created before the type
variable scope was completed, introducing an artificial dependency on
the pending nullability computation.

Change-Id: Ie1203fa4c78a27f3e7a0dfad16725cbbde24a6a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381143
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-08-22 08:23:05 +00:00
Chloe Stefantsova a4c94716ba [analyzer][cfe] Introduce parsing for null-aware elements
Part of https://github.com/dart-lang/sdk/issues/55949
Closes https://github.com/dart-lang/sdk/issues/55954

Change-Id: I885772f292f6d70425d6eba15bad8b0c6dc86a1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370240
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-28 09:49:30 +00:00
Jens Johansen 5359af23a3 [parser] Add endToken on endSwitchExpressionCase, beginToken on endSwitchExpressionCase
Change-Id: I53c6bae47feb2d4570471a3b91c8e371838fcff5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373245
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-27 05:47:18 +00:00
Jens Johansen 40dad48ede [parser] Add more tokens
Add
 * endToken to endBinaryExpression
 * endToken to handleEndingBinaryExpression
 * endToken to endConditionalExpression
 * beginToken (and rename to endToken) on handleExpressionStatement
 * rightSeparator to handleForLoopParts

Change-Id: I55d5a0e6c795b82d8f3480365e4cc3fbb59c65b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372482
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-06-24 08:12:41 +00:00
Jens Johansen 5d352e6627 [parser] Add begin and/or end to endElseStatement, endIfStatement, endThenStatement, endTryStatement
Change-Id: I27b7241665042a7fae6dc4c7d4192da9ce141b3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-19 06:12:00 +00:00
Jens Johansen fc67d31862 [parser] Listener calls should not be on the next (unrelated) token
When the parser sends events to the listener some events has a pair of
parameters, `beginToken` and `endToken`. Most of these are constructed
in such a way that the `beginToken` is the first token and the
`endToken` is the last token in that construct. This is for instance the
case with `endClassDeclaration`.
It was, however, not the case for `endMetadata` where `endToken` instead
was the next token *not* in the metadata.

In this CL I've found a changed the following to point to the last token
in the construct instead of the next token not in the construct and
renamed the parameter where it made sense:

* `endAssert` --- and renamed `semicolonToken` (which only pointed to
  a semicolon for statements) to `endToken`.
* `endAwaitExpression`
* `endConstLiteral` --- and renamed `token` to `endToken`
* `endConstructorReference`
* `endFieldInitializer` --- and renamed `token` to `endToken`
* `endForIn`
* `endForInBody` --- and renamed `token` to `endToken`
* `endForStatement`
* `endForStatementBody` --- and renamed `token` to `endToken`
* `endFunctionExpression` --- and renamed `token` to `endToken`
* `endInitializer` --- and renamed `token` to `endToken`
* `endInitializers`
* `endInvalidAwaitExpression`
* `endMetadata`
* `endSwitchCase`
* `endTopLevelDeclaration` --- and renamed `nextToken` to `endToken`
* `endWhileStatement`
* `endWhileStatementBody` --- and renamed `token` to `endToken`
* `handleNoConstructorReferenceContinuationAfterTypeArguments`

In the few places in listeners where these values were used I've mostly
updated to do e.g. `endToken.text!` to retain the current behavior.

Change-Id: I25495e160d1eec5c75bcf1313b512cd04bcb1533
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364322
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-04-26 06:59:23 +00:00
Konstantin Shcheglov 5f6daed1e1 Augment. Parse 'augmentKeyword' for top-level variables.
Change-Id: If8f0cb6fc1af77fb91774952931db5da214142e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354520
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-02-27 16:48:18 +00:00
Paul Berry 08405de9c6 Fix parser crash when skipping unmatched begin tokens.
Sometimes when the parser is performing error recovery it skips tokens
until it finds the next `,` or `;`, to try to get back on track. This
is handled by the `Parser.findNextCommaOrSemicolon` method.

When this method encounters a `BeginToken` (i.e., `(`, `[`, `{`, or
`<`), it needs to skip to the matching end token (using the `endToken`
getter), so that it doesn't try to resume parsing inside some nested
structure.

However, sometimes there is no matching end token (either because the
user has failed to properly matched `()`, `[]`, or `{}`, or because
the `BeginToken` is `<`, which doesn't always have a matching `>`). To
avoid a crash when this happens, `Parser.findNextCommaOrSemicolon`
needs to treat an unmatched `BeginToken` like an ordinary token, and
just advance to the next token.

Fixes https://github.com/dart-lang/sdk/issues/54236.

Bug: https://github.com/dart-lang/sdk/issues/54236
Change-Id: Id208c7a46c9c00b69f7f460a638d59486ebaffea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339980
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-06 15:01:19 +00:00
Johnni Winther 1683fd5c16 [_fe_analyzer_shared] Ensure beginToken on class, enum, mixin, extension and extension type
This passes the first token of these top level declaration directly
to the endX listener method.

In the CFE this is used to ensure that can handle the new modifiers in
the textual outline. Furthermore, support for extension types is added
and having an "unknown chunk" now results in an error. The latter should
help us keep the textual outline up-to-date wrt new features.

Change-Id: I813d6162b6cba0a2bf550ed33a6091abf9bf49f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324702
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-09-15 13:01:10 +00:00
Johnni Winther b745fa8923 [cfe] Avoid "Instance of " in parser intertwined test expectations
Change-Id: I7d7b1c9a001c43ec160d26c478bd71b41505f273
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323361
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-09-04 13:06:29 +00:00
Johnni Winther e3621561aa [parser] Refactor BlockKind
Refactors BlockKind to pass an explicit template/message instead
of injecting words directly into the message which leads to
grammatically incorrect english in the output message.

Change-Id: I3b91abf2e5a748f3dfca2cc0a6c877e77b3ad7d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322121
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-09-04 09:40:21 +00:00
Johnni Winther b1594fa130 [parser] Handle invalid extension type header in error recovery
This expands the existing recovery for class headers to handle
invalid, out-of-order, and duplicate clauses in extension type
declaration headers.

Change-Id: I7b33b91cc718e4c0673137121b8d083fa0ef1562
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321900
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-08-24 11:20:18 +00:00
Johnni Winther 29003657e2 [parser] Remove support for 'inline class' syntax
+ removes tests using 'inline class' syntax or replace them with
  extension type syntax.

TEST=existing

Change-Id: Ic98178c4df9a1585ad0167cfd8847caa7b771e3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321120
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-08-22 11:26:54 +00:00
Jens Johansen a445fae681 [parser] Fix issue 52954 about nested record destructuring with shorthand
Fixes https://github.com/dart-lang/sdk/issues/52954

Change-Id: I41e229380ccc16aa8bab0696fa79ca701a43220f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317681
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-08-11 09:19:31 +00:00
Paul Berry 76f803a41c Additional test cases in support of record/variable pattern disambiguation.
Two of these tests (`recordPattern_nullable_beforeAs` and
`recordPattern_nullable_beforeWhen`) verify that the fix for #52439
(Destructuring with explicit type of nullable record is a parsing
error), which causes `(...)? identifier` to be recognized as a
variable pattern, doesn't get confused by the pseudo-identifiers `as`
and `when`, and so it continues to correctly parse `(...)? as ...` as a
cast pattern and `(...)? when ...` as a guarded pattern.

The other two tests (`recordPattern_nonNullable_beforeAs` and
`recordPattern_nonNullable_beforeWhen`) verify that `(...) as ...` and
`(...) when ...` are parsed correctly. These forms were never broken,
but they were not well tested either.

Bug: https://github.com/dart-lang/sdk/issues/52439
Change-Id: I866e1c7a6a8e47e0cd91a1a77654405f395b50da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305844
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-30 12:48:26 +00:00
Paul Berry e213846ba0 Patterns parsing: fix record-typed variable patterns before certain tokens.
Previously, if a record-typed variable pattern lacked a `var` or
`final` keyword, and was followed by one of the tokens `||`, `&&`,
`as`, `?`, `!`, `when`, or `=>`, the parser would fail to recognize
it. This happened because the call to `computeVariablePatternType`
wasn't passing `true` for the optional parameter `required`; that in
turn placed `computeType` in a mode where it believed it was parsing a
potentially ambiguous construct in a top-level declaration, and hence
it would only accept the record type if the variable name was followed
by something that looked like part of a correct declaration (e.g. a
comma).

The fix is to pass `true` for the optional parameter `required` of
`computeVariablePatternType`. This places `computeType` in a mode
where it accepts the record type regardless of what follows it. This
is correct behavior since at the point where a variable pattern is
being parsed, ambiguities have already been taken care of and the
construct being parsed is most definitely a variable pattern.

Fixes #52521.

Change-Id: If20772ad914827a29df45c27eefb382ec1f470d2
Bug: https://github.com/dart-lang/sdk/issues/52521
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305848
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-26 13:51:31 +00:00
Jens Johansen 284296f862 [parser] Support nullable record types in patterns
Not fixed for nullable record types in
https://dart-review.googlesource.com/c/sdk/+/280106.

Fixes: https://dartbug.com/52439
Closes: https://dartbug.com/52462

Change-Id: I52f42406f2e1c6b7c874a9828ef7f1de397b3c83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304642
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-05-25 10:28:05 +00:00
Paul Berry 8d2b2a197d [parser] Ensure that list and map pattern parsing always makes progress.
In rare circumstances involving syntax errors, the `parsePattern`
method inserts a synthetic token but does not consume any
tokens. Usually when this happens it's not a problem, because whatever
method is calling `parsePattern` consumes some tokens, so the parser
always makes progress. However, when parsing list patterns, after
calling `parsePattern`, the parser would look for a `,`, and if it
didn't find one, it would supply a synthetic `,` and call
`parsePattern` again, resulting in an infinite loop. A similar
situation happened with map patterns, though the situation was more
complex because in between the calls to `parsePattern`, the parser
would also create synthetic key expressions and `:`s.

To fix the problem, when parsing a list or map pattern, after the call
to `parsePattern`, the parser checks whether any tokens were
consumed. If no tokens were consumed, it ignores the next token from
the input stream in order to make progress.

I also investigated whether there were similar issues with
parenthesized/record patterns and switch expressions, since those
constructs also consist of a sequence of patterns separated by tokens
and other things that could in principle be supplied
synthetically. Fortunately, parser recovery doesn't get into an
infinite loop in those cases, so I didn't make any further
changes. But I did include test cases to make sure.

Fixes #52352.

Bug: https://github.com/dart-lang/sdk/issues/52352
Change-Id: Idc8140236f6054deb1fd3c862036fe47dd84f30b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302803
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-12 18:43:39 +00:00
Paul Berry 3713c0e264 Patterns parser: prohibit variable/identifier patterns named when/as.
In https://dart-review.googlesource.com/c/sdk/+/299400, the parser was
adjusted so that it no longer accepts `when` and `as` as the names for
variable patterns in cases where there is a possible ambiguity
(e.g. `int when` is not accepted as a pattern because `int` is a
legitimate pattern, therefore `when` could introduce a guard
clause). This change further prohibits `when` and `as` from being the
names of variable patterns or identifier patterns even in the case
where there is no ambiguity. This is in line with the discussion at
https://github.com/dart-lang/sdk/issues/52199#issuecomment-1526297771,
and the spec change at
https://github.com/dart-lang/language/pull/3033.

Three new error codes are introduced, to cover the three circumstances
in which `when` or `as` might be used illegally: in a declared
variable pattern, in an assigned variable pattern, or in an identifier
pattern. I've also added analyzer tests to ensure that the parser
recovers from these errors nicely. Unfortunately, nice error recovery
is only feasible in the non-ambiguous cases.

I've also updated the language test expectations in
`tests/language/patterns/version_2_32_changes_error_test.dart` to
reflect the new error messages, and added a few more examples of uses
of `when` and `as` that are still permitted.

Fixes #52260.

Bug: https://github.com/dart-lang/sdk/issues/52260
Change-Id: I229f627aa639659c30b83c74895759207da279f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301482
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-08 19:06:02 +00:00
Paul Berry 637dd76c7f Patterns parsing: fix ambiguity resolution for when and as.
This change fixes parsing of case clauses such as:

    case foo when !flag:

Constructions like this require some lookahead in order to parse
correctly, because the token `when` is valid both as an identifier and
as a part of the grammar for a case clause. Therefore, at the time
`foo` is encountered, the parser must decide whether it is looking at
a variable pattern (`foo when`, where `when` is the name of the
variable) or an identifier pattern (`foo`, where `when` begins the
case's guard clause). Previous to this fix, the algorithm for
disambiguating these two choices was as follows:

- If the token sequence starting at `foo` looked like a type, and the
  token that follows was an identifier, the parser assumed it was
  looking at a variable pattern with a type; otherwise it assumed it
  was looking at an identifier pattern.

- EXCEPT that if the token that followed the supposed type was `when`
  or `as` (both of which are valid identifiers), then it probed
  further:

- If the token that followed `when` or `as` was a token that could
  legitimately follow a pattern, then it assumed that it was looking
  at a variable pattern with a type. (The tokens that could
  legitimately follow a pattern are `,`, `:`, `||`, `&&`, `)`, `}`,
  `]`, `as`, `when`, `?`, `!`).

- Otherwise it assumed that it was looking at an identifier pattern.

This didn't fully disambiguate, because the third bullet didn't
account for the fact that the tokens `as`, `when`, and `!` could
_either_ legitimately follow a pattern _or_ legitimately begin an
expression (or, in the case of `when`, a type), therefore constructs
like the following were incorrectly parsed:

- `case foo when as:` (where `as` is a local boolean variable)
- `case foo when when:` (where `when` is a local boolean variable)
- `case foo when !flag:` (where `flag` is a local boolean variable)
- `case foo as when:` (where `when` is the name of a type)

The solution is to simplify the disambiguation logic so that if if the
token that follows the supposed type is `when` or `as`, then the
parser assumes that it's looking at an identifier pattern, _not_ a
typed variable pattern.

The consequence of this is that the above four constructions are
parsed correctly; however it is no longer possible for a typed
variable pattern to name a variable `when` or `as`.

For consistency we would like to prohibit _any_ variable pattern from
naming a variable `when` or `as`, however to keep this change as small
as possible (and reduce the risk involved in a possible cherry-pick)
that will be postponed until a later CL.

Fixes #52199.

Bug: https://github.com/dart-lang/sdk/issues/52199
Change-Id: Ibab9b92f01e3e4020d7d64f1ff000a9b964a4564
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299400
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-04-28 13:22:28 +00:00
Chloe Stefantsova 6b0acfecc1 [cfe] Put patterns in the scopes of their declared variables
Closes https://github.com/dart-lang/sdk/issues/51971

Change-Id: I8ba634e7303bafdb1895c50970fbc80321f4bf6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296581
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-04-24 07:30:00 +00:00
Paul Berry e3a18967cc Patterns parsing: test variable patterns with record types.
This already works, but there were no parser tests of it.

Bug: https://github.com/dart-lang/sdk/issues/50912
Change-Id: I2e64b9b4750cf7476df59afd2f9ebc9d66299e40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293580
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-04-05 13:17:47 +00:00