Commit Graph

8745 Commits

Author SHA1 Message Date
Kallen Tu c8ee0e78a5 [flow] Pipe the language feature flag inference-update-4 through flow analysis.
Weaves the flag `inference-update-4` through to `FlowAnalysis` and updating both the analyzer and CFE point-of-entry to include the flag.

This flag will be used in `flow_analysis.dart` to hide upcoming bug fixes to flow analysis.

Change-Id: Ib0004eb4bcf0b6e579116632b5973fe969e51e90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388582
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-10-08 16:32:24 +00:00
Paul Berry 5eacff3ab8 Make type variable constraint generation conventions uniform.
This CL changes the CFE's
TypeConstraintGatherer._isNullabilityAwareSubtypeMatch method so that
it is responsible for restoring the constraint state if there is no
match, making it consistent with the contraint gathering methods in
the analyzer and _fe_analyzer_shared.

This made it possible to remove much of the calls to state restoring
logic that _isNullabilityAwareSubtypeMatch previously had to do after
making recursive calls to itself, as well as a lot of state restoring
logic in _fe_analyzer_shared. It also made it possible to eliminate
_tryNullabilityAwareSubtypeMatch from the CFE (since
_isNullabilityAwareSubtypeMatch now has the same behavior).

Making this change now should hopefully simplify the remaining steps
in sharing type variable constraint generation logic, since it will no
longer be necessary to adjust state restoring logic when moving code
between the CFE and _fe_analyzer_shared.

I also took the liberty of rewriting some of the documentation
comments to try to clarify the new conventions.

In the process I also discovered several instances of unnecessary
state restoring logic in the analyzer; I'll make a separate CL to
clean those up (and adjust the analyzer documentation too).

Change-Id: If74c8be06f1d53f61d109e5ea2a8526d5cbcd347
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388265
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
2024-10-08 05:44:20 +00:00
Chloe Stefantsova 06223ff9f0 [parser] Add missing handling of null-aware elements in if-else
Part of https://github.com/dart-lang/sdk/issues/55954

Change-Id: Ie22ff9ddf50f47e20b1cfbf11f01bdc900123619
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388003
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-10-07 09:41:35 +00:00
Kallen Tu e872e360cf Add experiment flag for more flow analysis updates.
Working on a few bugs for flow analysis and I'll be putting them under this feature flag until we're ready to release.

Change-Id: I2bf01856d8d9cf0a8600a67c20df1a9b1c42e296
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388052
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-10-04 17:18:49 +00:00
Johnni Winther c8442b4a82 [cfe] Lookup references from index when creating builders
Change-Id: I4ab82475a05c3862f6818ba5b5ba573118309fb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387964
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-04 09:14:00 +00:00
Johnni Winther f223d01848 [kernel] Split ast.dart into parts
Change-Id: Ic5089390b9e50795b956e79f1c36c57f0eefeeef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388000
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-10-03 06:36:42 +00:00
Chloe Stefantsova 5eb2996148 [cfe] Add an inference test for null-aware elements
This CL also removes an obsoleted comment about adding flow analysis
to null-aware elements in lists and sets. Since the null-aware
elements don't introduce changes to the control flow in lists and
sets, such analysis isn't necessary.

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

Change-Id: I3dbe3f0bd76ce19ff232dc5be20376f5c43f1323
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387962
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-10-02 12:19:23 +00:00
Johnni Winther d4b78e9c60 [cfe] Add subtype_measure
Add instrumenter to measure subtype checks

Change-Id: Ida25671e3e4d572a1eaa2114cb384c6e8c5c769a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387704
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-02 09:46:26 +00:00
Jens Johansen e7d825fb3c [CFE/kernel/vm] Incremental compiler/serializer and metadata
This CL:
* Makes the incremental compiler copy over the metadata just created for
  the libraries compiled into the Component returned.
* Preserves metadata when serializing via the incremental serializer.
* Fixes loading a multi-component with metadata.
* Lets the VM copy all metadata in "_combinePendingDeltas"
  when there is only one component to "combine".

It is generally my view, that to do better, metadata has to be redone
(among other things likely has to live on the Library instead).

https://github.com/dart-lang/sdk/issues/39302

With this CL:

```
rm foo.dill ; tools/sdks/dart-sdk/bin/dart pkg/frontend_server/bin/frontend_server_starter.dart --no-print-incremental-dependencies --target=vm --sdk-root=out/ReleaseX64 --platform=vm_platform_strong.dill --output-dill=foo.dill --packages=.dart_tool/package_config.json pkg/compiler/lib/src/dart2js.dart
tools/sdks/dart-sdk/bin/dart pkg/vm/bin/dump_kernel.dart foo.dill foo.dump
grep "@vm.call-site-attributes" foo.dump | wc -l
```

(i.e. a one-shot compile) prints 9500.

```
rm foo.dill ; tools/sdks/dart-sdk/bin/dart pkg/frontend_server/bin/frontend_server_starter.dart --incremental --no-incremental-serialization --no-print-incremental-dependencies --target=vm --sdk-root=out/ReleaseX64 --platform=vm_platform_strong.dill --output-dill=foo.dill --packages=.dart_tool/package_config.json pkg/compiler/lib/src/dart2js.dart
tools/sdks/dart-sdk/bin/dart pkg/vm/bin/dump_kernel.dart foo.dill foo.dump
grep "@vm.call-site-attributes" foo.dump | wc -l
```

(i.e. an incremental compile but without incremental serialization) prints 9500.

and

```
rm foo.dill ; tools/sdks/dart-sdk/bin/dart pkg/frontend_server/bin/frontend_server_starter.dart --incremental --no-print-incremental-dependencies --target=vm --sdk-root=out/ReleaseX64 --platform=vm_platform_strong.dill --output-dill=foo.dill --packages=.dart_tool/package_config.json pkg/compiler/lib/src/dart2js.dart
tools/sdks/dart-sdk/bin/dart pkg/vm/bin/dump_kernel.dart foo.dill foo.dump
grep "@vm.call-site-attributes" foo.dump | wc -l
```

(i.e. an incremental compile with incremental serialization) prints 9500.

If not deleting the dill file first (which will then initialize from it)
metadata might be different though.
If there are no changes and the incremental serializer was and is used
we should still get `9530` (because the bytes are just copied), but
otherwise we might get different results because it's not really
possible to otherwise pick-and-choose and/or merge the metadata.

TEST=Existing tests that it didn't get worse.

Change-Id: I19d530357e7e2a174d7408dbbf0ed7e0248a5b70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358444
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-10-02 09:37:31 +00:00
Johnni Winther 56c6891f49 [cfe] Add test for export conflict with dart:
Change-Id: Ib8851b36f7d37ca8f79cc619406e277bfdce2f90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387720
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-02 07:22:40 +00:00
Paul Berry e9e761644d [analyzer][cfe] Share constraint generation for non-generic function types
This change combines function-handling logic from the analyzer's
`TypeConstraintGatherer._functionType0` and the CFE's
`TypeConstraintGatherer._isNullabilityAwareSubtypeMatch` methods into
`TypeConstraintGenerator.performSubtypeConstraintGenerationForFunctionTypes`,
which is in `_fe_analyzer_shared`.

The CFE and the analyzer have some pretty significant differences in
how they represent function types:

- In the analyzer, all function parameters are in a single
  `parameters` list; each element of this list (of type
  `ParameterElement`) can be queried to find out if it is named or
  unnamed, and if it is required or optional. A convention enforced
  partially by the `FunctionType` constructor is that the `parameters`
  list stores reqired unnamed parameters first, then either optional
  unnamed parameters or named parameters; named parameters are sorted
  by name. The analyzer provides additional getters
  `namedParameterTypes`, `normalParameterNames`,
  `normalParameterTypes`, `optionalParameterNames`, and
  `optionalParameterTypes`, which provide other views of this
  information (for example, `namedParameterTypes` contains just the
  named parameters, as a map from name to `ParameterElement`).

- In the CFE, unnamed and named parameters are in two separate lists
  (`positionalParameters`, of type `List<DartType>`, and
  `namedParameters`, of type `List<NamedType>`); in
  `positionalParameters`, required parameters come before optional
  ones. A single integer (`requiredParameterCount`) indicates how many
  elements of `positionalParameters` are required, and by convention,
  `namedParameters` is sorted by name.

In order to share logic between these representations, I had to come
up with a common API that these two representations could be easily
adapted to. The analyzer's representation proved to be easier to
adapt, so I based the common API mostly on the CFE's representation,
but with some name changes for clarity. The shared API is:

- `positionalParameterTypes` gets a list of positional parameter types

- `requiredPositionalParameterCount` tells how many entries in
  `positionalParameterTypes` are required.

- `returnType` gets the function type's return type.

- `sortedNamedParameters` gets a list of information about named
  parameters. The list elements are sorted by name, and each element
  of this list is of type `FunctionParameterStructure` (a common
  interface implemented both by the analyzer's `ParameterElement` and
  the CFE's `NamedType`).

- `typeFormals` gets a list of the function type's formal type
  parameters.

To minimize the performance impact of adapting the analyzer to this
API, the analyzer computes `positionalParameterTypes`,
`requiredPositionalParameterCount`, and `sortedNamedParameters` at the
time a `FunctionType` is constructed. Hopefully this should not be too
much of a performance hit, since doing so does not take too much more
effort than checking that the named parameters are sorted (which the
`FunctionType` constructor was already doing).

This is based on previous work by Chloe Stefantsova in
https://dart-review.googlesource.com/c/sdk/+/386480.

Change-Id: Iefe18d72771146399d81747ceab9c929516b0523
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386322
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-10-01 16:08:52 +00:00
Chloe Stefantsova 7bb6899a2c [cfe] Remove unknownFunction
The `unknownFunction` marker object was used to indicate a type of a
function that accepts an unspecified amount of arguments. The uses of
the marker object in the CFE are already replaced by
InvocationTargetType and its subtypes. This CL simply removes the
object itself, which is no longer in use.

Change-Id: I48fe53460d1f96f4fee0a91fb1572e219fbd1502
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387702
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-01 10:00:20 +00:00
Johnni Winther a101a99ec7 [cfe] Handle assert in unevaluated extension type constructors
Closes #56803

Change-Id: Icea17859c35128db7d965732bb2329c5c10689bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387540
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-10-01 09:10:22 +00:00
Johnni Winther 51dbd34ed3 [cfe] Add SourceLibraryBuilder.prefixNameSpace
This moves the prefix builders from the libraryNameSpace to a
separate prefixNameSpace. This is in preparation for the enhanced parts
feature where the prefix scope are handled separately from the library
scopes.

Change-Id: I8fda7529634b70ff511d2aab736d18ed1ad99086
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387041
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-01 09:02:34 +00:00
Johnni Winther 5bcfc0578c [cfe] Cleanup prefix scope
This splits up [computeAmbiguousDeclarationForScope] into
[computeAmbiguousDeclarationForExport], which is moved to [LibraryBuilder], and [computeAmbiguousDeclarationForImport].

Change-Id: I2fad4784904eef6caf731a41300b98c6f172039d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387080
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-01 09:02:34 +00:00
Chloe Stefantsova bc8104f3b2 [analyzer][cfe] Implement flow analysis for null-aware map entries
Closes https://github.com/dart-lang/sdk/issues/56786

Change-Id: I738c98b6f4e632cfbbe51221bbc3547edbc718fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386800
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-09-30 09:48:27 +00:00
Ben Konyi 12d9f40961 Reapply "[ CLI ] Don't disable DDS when --disable-dart-dev is provided"
This reverts commit 9f5246e8c6.

TEST=Existing tests

Change-Id: I658290f248d8b26c05f24b7125c3ba71de318bf9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385121
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2024-09-26 15:29:05 +00:00
Paul Berry 6e249578f6 Add unit tests for _fe_analyzer_shared subtype functionality.
These tests cover just the portion of the subtype constraint
generation mechanism that's currently shared between the analyzer and
the CFE. I plan to add more unit tests as more functionality becomes
shared.

Note that as part of this change, I've eliminated the methods
`performSubtypeConstraintGenerationForFutureOrRightSchema` and
`performSubtypeConstraintGenerationForFutureOrLeftSchema`, and instead
made `_performSubtypeConstraintGenerationForFutureOrInternal` public
(renaming it to `performSubtypeConstraintGenerationForFutureOr`). My
rationale for this change is as follows:

- It makes testing easier, since only one method needs to be tested
  rather than two.

- Removing these two methods simplifies the call sites in the analyzer
  and CFE, since instead of having to use an `if` test to decide which
  method to call, they can simply pass in the appropriate boolean
  switch for the `leftSchema` argument.

Change-Id: I0911c80fc8e9a4fbdd3dd0063dd203066006c218
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386861
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-09-26 13:38:13 +00:00
Paul Berry 72c2e73f0b Fill out return type of TypeAnalyzerOperations.matchTypeDeclarationType
The return type of this method was previously
`TypeDeclarationMatchResult?` (with no explicit type arguments),
meaning that the generic type parameters of
`TypeDeclarationMatchResult` would be filled in by
instantiate-to-bounds as `Object, Object, Object`. But the
implementations always return the more precise type
`TypeDeclarationMatchResult<TypeDeclarationType, TypeDeclaration,
TypeStructure>?`, and the use sites all expect this type. Adding
explicit type arguments improves type safety and probably allows the
compiler to elide some of the type casts involved in pattern matching.

Also, the "mini_ast" implementation of this method contained a subtle

bug: instead of using `unwrappedType.type` for the `typeDeclaration`
Change-Id: Ic7bffc1b0b3e9bfc86c0168d4e6bdf442af8ae39
argument, it should use `unwrappedType.name`. This ensures that if the
type being matched is generic, the generic arguments don't show up in
the `typeDeclaration`.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386681
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-09-26 13:32:20 +00:00
Johnni Winther 63dff0db52 [cfe] Create SourceLibraryBuilder for libraries only
Change-Id: I1da8b463c7314566abfb573039316807546cb49d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386803
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-26 07:29:12 +00:00
Chloe Stefantsova f6fe5615c4 [analyzer][cfe] Generate constraints based on type variable bounds
In response to https://github.com/dart-lang/language/issues/3009

Change-Id: I918d392e422f1997736bf2543c8107cb44d3d6f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364721
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-09-25 10:59:51 +00:00
Johnni Winther 1bf0bc349a [cfe] Add LibraryProblemReporting
This adds an implementation of ProblemReporting that registers
the reported errors with a Library node.

Change-Id: I5d3f60f9691fe34b54322f9ed788025ff29cca29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386202
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-25 10:52:11 +00:00
Jens Johansen a086649e42 [scanner] Support 0-byte in input
Fixes https://github.com/dart-lang/sdk/issues/18090

Change-Id: I9bcd49c9ade7923eb087c5dd617a2f33cc84ee96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386161
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-09-25 09:15:19 +00:00
Johnni Winther a31c6dfc31 [cfe] Remove Builder.parent setter
This also moves some uses from .parent to .declarationBuilder to reduce
the reliance on the Builder.parent getter.

Change-Id: Ie99a7237a0f2bb68016cd1e0643f4e9045600a1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386140
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-25 08:34:14 +00:00
Jens Johansen 3dce89fbe0 [scanner] Don't give the Utf8 scanner a 0-terminated byte sequence
Not having to do the read-allocate-copy dance for files to add a 0-byte
at the end results in these changes when using the CFE to compile
(a fixed version of) the CFE:

```
msec task-clock:u: -1.7356% +/- 0.2164% (-73.16 +/- 9.12)
page-faults:u: -2.6957% +/- 0.0111% (-2914.83 +/- 12.00)
cycles:u: -1.7128% +/- 0.2223% (-297927979.70 +/- 38660477.01)
instructions:u: -1.6814% +/- 0.0002% (-361315766.86 +/- 36853.71)
branch-misses:u: -3.3289% +/- 0.9669% (-2153126.00 +/- 625370.97)
seconds time elapsed: -1.7372% +/- 0.2154% (-0.07 +/- 0.01)
seconds user: -1.5998% +/- 0.2740% (-0.06 +/- 0.01)
seconds sys: -4.1451% +/- 2.9801% (-0.01 +/- 0.01)
Scavenge(   new space) goes from 62 to 61
```

TEST=Existing test coverage.

Change-Id: I8e182bcee39839f6ed1e658c30c85c40ecf0b259
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385722
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-25 08:33:48 +00:00
Johnni Winther 6d150d21b3 [cfe] Create PrefixBuilder through fragments
This creates a PrefixFragment during outline building and creates
a PrefixBuilder for each unique prefix during computation of import
scopes.

Change-Id: I0ac7ba22ec7db1aee288f088c60994c36c38f43a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385723
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-25 07:44:07 +00:00
Jens Johansen 23f0c0b27b [scanner/paser] Don't use identical on ints
Short explanation: For whatever reason, when using `identical` on `int`s
the ints are first boxed (`BoxInt64`) before being compared
(`StrictCompare`) whereas just doing `==` just does a compare
(`EqualityCompare`).

Results:

With the CFE compiling (a fixed version of) itself I get these results:

```
instructions:u: -0.5756% +/- 0.0003% (-124825401.80 +/- 64013.17)
```

i.e. almost 125 mio instructions saved.

Another run - with 100 iterations each - I get

```
msec task-clock:u: -0.4927% +/- 0.2585% (-20.85 +/- 10.94)
page-faults:u: 0.0174% +/- 0.0139% (18.80 +/- 15.00)
cycles:u: -0.5233% +/- 0.2683% (-91305451.82 +/- 46815747.30)
instructions:u: -0.5754% +/- 0.0002% (-124793061.49 +/- 37426.30)
branch-misses:u: -1.6903% +/- 1.1207% (-1091410.69 +/- 723627.04)
seconds time elapsed: -0.4863% +/- 0.2581% (-0.02 +/- 0.01)
seconds user: -0.4547% +/- 0.3253% (-0.02 +/- 0.01)
```

In the scanner benchmark with `--string` (i.e. using string scanner) I
get these results:

```
msec task-clock:u: -3.7992% +/- 0.3316% (-190.54 +/- 16.63)
cycles:u: -4.1423% +/- 0.3566% (-836808313.28 +/- 72033424.19)
instructions:u: -3.3524% +/- 0.0000% (-1480262370.08 +/- 828.58)
branch-misses:u: -1.7591% +/- 0.9582% (-1781144.28 +/- 970258.82)
seconds time elapsed: -3.7988% +/- 0.3303% (-0.19 +/- 0.02)
seconds user: -4.0211% +/- 0.4161% (-0.19 +/- 0.02)
```

(Just running the benchmark also sees the characters/µs go from ~93 to
~97).

In the scanner benchmark with `--bytes` (i.e. using the utf8 scanner) I
get these results:

```
msec task-clock:u: -4.2872% +/- 0.4467% (-185.64 +/- 19.34)
cycles:u: -4.2972% +/- 0.4382% (-812955454.92 +/- 82892232.23)
instructions:u: -3.4867% +/- 0.0000% (-1479744935.28 +/- 297.12)
seconds time elapsed: -4.2872% +/- 0.4470% (-0.19 +/- 0.02)
seconds user: -4.2204% +/- 0.4730% (-0.18 +/- 0.02)
```

(Just running the benchmark also sees the bytes/µs go from ~108 to ~113).

In both cases we notice how the actual time, cycles and instructions
agree pretty well.

Combining the data for the compile and the benchmark I assume this CL
actually reduces the runtime of the CFE compiling itself by a about
half a percent.

Change-Id: I67d056837240aef61b6707d02507ab4121b31715
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385940
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-25 07:08:56 +00:00
Sam Rawlins 7d4994fa4a linter: Report when single statement if-statement body is not on the same line as if-keyword
Fixes https://github.com/dart-lang/linter/issues/4870

Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try
Change-Id: Ibd8969afe35f719a020e5aa37efdc1792addac7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353140
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-24 01:59:23 +00:00
Johnni Winther 200cf86026 [cfe] Ensure getter references for fragments
Change-Id: I7e0fbe232b0d8638b61b1f26f3c23c634c6ce4fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385724
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-23 08:02:46 +00:00
Johnni Winther f7e3aa29ad [cfe] Don't pass parent to FormalParameterBuilder
The parent relation was set up in the SourceFunctionBuilder constructor,
anyway, and this avoids yet another use of the SourceLibraryBuilder in
BuilderFactoryImpl.

Change-Id: Ia0995b6c0a770b205c876eea3a93097337ee39ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386000
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-20 14:26:53 +00:00
Johnni Winther 74eb7b38ea [cfe] Replace VoidDeclarationTypeBuilder with VoidTypeBuilder
This adds a FixedTypeBuilder subtype VoidTypeBuilder to encode the
`void` type instead of creating a `VoidDeclarationTypeBuilder` for
each occurrence.

Change-Id: I0f9643007b786f97fa6d54c94a1fd02ee2d0ae94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385721
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-20 08:57:20 +00:00
Chloe Stefantsova 3e85a29951 [cfe] Use the type of the coerced expression in inference
Closes https://github.com/dart-lang/sdk/issues/56666
Closes https://github.com/dart-lang/sdk/issues/33298

Change-Id: I4873247d89aad858df78795c031a4fb65b9a0e2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-09-20 08:02:50 +00:00
Jens Johansen ab85479ce4 [CFE] Allow crash test minimizer to work in more scenarios
This change allows to reproduce and minimize the bug in
https://dart-review.googlesource.com/c/sdk/+/385441/2 via this
(mouthful) of a command:

```
out/ReleaseX64/dart pkg/front_end/test/crashing_test_case_minimizer.dart --platform=out/ReleaseX64/vm_platform_strong.dill --invalidate=package:_fe_analyzer_shared/src/messages/codes.dart --invalidate=package:front_end/src/type_inference/assignable_errors.dart --initial-only-outline --load-from-component-before-invalidate --invalidate-all-at-once --packages=.dart_tool/package_config.json pkg/front_end/lib/src/type_inference/assignable_errors.dart
```

Which - after renames - creates a reproduction like this:

```
# Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

# Reproduce a crash.

type: newworld
worlds:
  - entry:
      - a.dart
    sources:
      a.dart: |
        import 'b.dart';
      b.dart: |
        export 'c.dart';
      c.dart: |
        class Message {}
        typedef SummaryTemplate = Message Function(int, int, num, num, num);
    expectedLibraryCount: 3

  - entry:
      - a.dart
    worldType: updated
    expectInitializeFromDill: false
    invalidate:
      - c.dart
      - a.dart
    expectedLibraryCount: 3
    advancedInvalidation: bodiesOnly
```

(this was already reproduced and fixed in
https://dart-review.googlesource.com/c/sdk/+/385720 but still)

Change-Id: I63d5510b1b848309cc4c74a15cdc1f33400d4861
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385740
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-09-18 15:01:27 +00:00
Chloe Stefantsova f80e649f0c [cfe] Report error on missing initializer in extension types
More specifically, the error is now reported on a missing initializer
of an optional named or positional parameter of an extension type
constructor.

Closes https://github.com/dart-lang/sdk/issues/56402

Change-Id: I4bd290d6342be5fdaa63dc848ae8c00e23d3a0ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385563
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-09-18 13:57:04 +00:00
Johnni Winther ab8693b25d [cfe] Register Typedef references
References to typedefs were not register in
`fragmentsCreatedWithReferences` and exports would therefore try to
look up the enclosing library through the `Typedef` node. This caused
a crash when the `Typedef` was from a source library, which would not
have had the parent relation set up yet.

Change-Id: I92ace4dd26ed7c357cafeaeebece95b7bd5e68f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385720
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-18 12:29:08 +00:00
Johnni Winther fa5af54ad1 [cfe] Create SourceFactoryBuilder from fragments
Change-Id: Id9473e5c6cd78cb502c6c7a0a05dc6dc75a79a77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385561
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-18 09:07:19 +00:00
Jens Johansen 44e79f520f [CFE] Better error and reproduction on compile and lint crash
Change-Id: I7555d9d2c7244325d4eacba4cc8780c2a98a4fc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385600
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-09-18 06:28:23 +00:00
Johnni Winther 7ceddaad71 [cfe] Create SourceConstructorBuilder through fragments
Change-Id: I78e40b1c5cd80e9e32a0c96f99ec9c9a172ad8e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385580
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-17 14:57:35 +00:00
Johnni Winther df4e73cfa1 [cfe] Create SourceProcedureBuilder through fragments
Change-Id: If7fe7cc1b7779950e2d2a0227dde20c02eafddbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385440
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-17 13:33:57 +00:00
Robert Nystrom 13323eeac6 Migrate internal CFE tools to the new DartFormatter API.
As far as I can tell, these scripts are all only used internally for
formatting generated code, so it should be safe to just parse the code
at the latest language version.

I didn't migrate:

  pkg/front_end/test/fasta/textual_outline_suite.dart

I believe that one may need to pass in a specific language version if it
needs to support formatting code from before Dart 3.0. (In particular
if it needs to handle code using old switch constant expressions that
are not supported in Dart 3.0 and later like `case 1 + 2:`.)

Bug: https://github.com/dart-lang/sdk/issues/56687
Change-Id: Ib5cef82c22fc749223095215d3b692e6c27decc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385341
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2024-09-17 10:59:41 +00:00
Johnni Winther a88b46caab [cfe] Create SourceFieldBuilder through fragments
Change-Id: If82172a16fbf1ab0b9d961a6ea01f528fb48363c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385420
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-17 10:57:22 +00:00
Johnni Winther 7472c2ba21 [cfe] Remove parent from TypeVariableBuilder
Change-Id: Idc36d0da07bd450380a01c3d697a4ad6b324890d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385203
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-17 09:48:28 +00:00
Johnni Winther a746400b68 [cfe] Create named mixin applications through fragments
Change-Id: I3a68a9adc02a025eaec9d7a0c333018633740c12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385281
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-17 09:48:28 +00:00
Johnni Winther 4d80d8d429 [cfe] Create SourceClassBuilder through fragments
Change-Id: I311a103efbe4cb1d2bd022c0fccc6e278b16efa2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385162
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-17 08:26:39 +00:00
Chloe Stefantsova cfcea0b076 [cfe] Handle structural against type parameter type in subtype tests
Closes https://github.com/dart-lang/sdk/issues/56633

This is also a follow-up to
https://dart-review.googlesource.com/c/sdk/+/382000/comment/9801301a_05a82175/

Change-Id: Id6f791292ee424ca0bf971cdd0c99dfbb6b79a10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385421
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-09-17 07:25:20 +00:00
Jens Johansen dfb414a0ec [parser] Replace optional for some calls
This CL replaces the `optional` call in some places (more will likely
follow in follow-up-CLs) with the (badly named) `optional2` which is
both better typed (doesn't use strings) and is faster.

In this CL I've replaced the most used calls (when using the CFE to
compile itself), saving ~100 mio instructions.

Sometimes statistics just says the ~100 mio instructions saved, other
times I get statistics like this:

```
msec task-clock:u: -0.6861% +/- 0.2300% (-28.64 +/- 9.60)
page-faults:u: 0.1113% +/- 0.0114% (116.33 +/- 11.97)
cycles:u: -0.7966% +/- 0.2280% (-137543215.11 +/- 39365289.96)
instructions:u: -0.4655% +/- 0.0003% (-100120984.16 +/- 56848.83)
branch-misses:u: -3.5671% +/- 0.8585% (-2249707.82 +/- 541442.75)
seconds time elapsed: -0.6788% +/- 0.2307% (-0.03 +/- 0.01)
seconds user: -0.8448% +/- 0.2950% (-0.03 +/- 0.01)
```

```
msec task-clock:u: -0.4102% +/- 0.2224% (-17.29 +/- 9.37)
page-faults:u: 0.1194% +/- 0.0130% (124.99 +/- 13.61)
cycles:u: -0.4368% +/- 0.2296% (-75891577.97 +/- 39893793.33)
instructions:u: -0.4658% +/- 0.0003% (-100182606.12 +/- 62071.96)
branch-misses:u: -1.5890% +/- 0.9771% (-1012729.95 +/- 622739.88)
seconds time elapsed: -0.4072% +/- 0.2224% (-0.02 +/- 0.01)
seconds user: -0.4771% +/- 0.3049% (-0.02 +/- 0.01)
```

```
msec task-clock:u: -0.4542% +/- 0.2160% (-19.18 +/- 9.12)
page-faults:u: 0.1219% +/- 0.0115% (127.61 +/- 12.03)
cycles:u: -0.4774% +/- 0.2225% (-83126015.12 +/- 38752062.54)
instructions:u: -0.4658% +/- 0.0003% (-100174778.84 +/- 61310.55)
branch-misses:u: -1.9576% +/- 0.9711% (-1253736.65 +/- 621904.22)
seconds time elapsed: -0.4471% +/- 0.2160% (-0.02 +/- 0.01)
seconds user: -0.4976% +/- 0.2645% (-0.02 +/- 0.01)
```

These are statistics on 100 runs (each) of the CFE compiling itself when
run as an AOT compile with `--deterministic`. It seems likely that it
saves something like 0.4% in both instructions, cycles and actual
runtime.

Change-Id: I12763c23b1ec33357a31aaf47ed93ca16264c0f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385160
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-09-17 07:00:41 +00:00
Jens Johansen 10622639f8 [CFE] Coverage auto-ignores assert message
Change-Id: Ia07503b7e66f4014366906b7697abed3df266a1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385163
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-09-17 06:35:10 +00:00
Johnni Winther 8f6ead121e [cfe] Update coverage
Change-Id: If20446b4a2b2be7ff6860942ddaeb9585d27ba03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385161
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-09-13 10:50:01 +00:00
Johnni Winther b2c6eec1ee [cfe] Create SourceEnumBuilder via fragments
Change-Id: Ifee08965f4c257912d51d5220ae8fd58423d9ecd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385040
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-13 10:50:01 +00:00
Johnni Winther e14a272d11 [cfe] Make applyMixins and copyTypeVariables static in BuilderFactoryImpl
This is done in preparation for moving the creation of class builders to
after outline building.

Change-Id: I3a6e06ff68055b9e4c915fbe8c44227b492cdf63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384702
Reviewed-by: Jens Johansen <jensj@google.com>
2024-09-13 10:50:01 +00:00