Commit Graph

2352 Commits

Author SHA1 Message Date
Robert Nystrom 732b07a42b Roll dart_style into the SDK.
I'm still chasing down a couple of google3 failures, but this is ready for review so that I can get it approved and land it once the last couple of failures are fixed. Here is who I think should review what:

athom@ for:

- DEPS

johnniwinther@ for:

- pkg/_fe_analyzer_shared
- pkg/front_end
- pkg/kernel

brianwilkerson@ for:

- pkg/analysis_server
- pkg/analyzer_plugin
- pkg/analyzer_utilities

kenzieschmoll@ for:

- pkg/dartdev

pquitslund@ for:

- pkg/linter/lib/src/lint_codes.g.dart

If you're not the right person, feel free to summon someone else.

Most of the changes here are re-running code generators that auto-format the code they generate. The changes are:

Roll in the latest dart_style commit:

- DEPS

Manually updated these test expectations to expect the new style:

- pkg/analysis_server/test/lsp/format_test.dart
- pkg/analysis_server/test/services/refactoring/agnostic/change_method_signature_test.dart
- pkg/analysis_server/test/src/domains/flutter/set_property_value_test.dart
- pkg/analysis_server/test/src/services/flutter/container_properties_test.dart
- pkg/analysis_server/test/src/services/flutter/widget_descriptions_test.dart
- pkg/analysis_server/test/src/services/refactoring/convert_selected_formal_parameters_to_named_test.dart
- pkg/analysis_server/test/src/services/refactoring/move_selected_formal_parameters_left_test.dart

This was auto-generated by something, but I'm not sure why it thinks there is a diff:

- pkg/analyzer_plugin/doc/api.html

Updated to require a version of dart_style that accepts a language version in DartFormatter():

- pkg/analyzer_plugin/pubspec.yaml

Updated to always use the latest language version (and thus new style) when invoking the formatter:

- pkg/analyzer_utilities/lib/tools.dart

Manually updated the formatting in the code templates so that they matched the formatting expected by the tests, which implicitly format using the latest language version:

- pkg/dartdev/lib/src/templates/...

The rest are all generated files that are formatted so re-generated using the new style:

- pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart
- pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
- pkg/analysis_server_client/lib/handler/notification_handler.dart
- pkg/analysis_server_client/lib/src/protocol/...
- pkg/analysis_server/lib/protocol/protocol_generated.dart
- pkg/analysis_server/test/integration/support/integration_test_methods.dart
- pkg/analysis_server/test/integration/support/protocol_matchers.dart
- pkg/analyzer_plugin/lib/protocol/...
- pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart
- pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart
- pkg/analyzer/lib/src/analysis_options/error/option_codes.g.dart
- pkg/analyzer/lib/src/dart/error/...
- pkg/analyzer/lib/src/error/codes.g.dart
- pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart
- pkg/analyzer/lib/src/pubspec/pubspec_warning_code.g.dart
- pkg/analyzer/lib/src/summary/format.dart
- pkg/analyzer/lib/src/wolf/ir/ir.g.dart
- pkg/compiler/test/tool/graph_isomorphizer/golden/less_simple/lib_000_1.dart
- pkg/compiler/test/tool/graph_isomorphizer/golden/less_simple/lib_001_0.dart
- pkg/compiler/test/tool/graph_isomorphizer/golden/less_simple/lib_010_0.dart
- pkg/compiler/test/tool/graph_isomorphizer/golden/less_simple/lib_100_0.dart
- pkg/compiler/test/tool/graph_isomorphizer/golden/simple/...
- pkg/front_end/lib/src/api_prototype/experimental_flags_generated.dart
- pkg/front_end/lib/src/codes/cfe_codes_generated.dart
- pkg/front_end/lib/src/util/parser_ast_helper.dart
- pkg/front_end/test/parser_test_listener.dart
- pkg/front_end/test/parser_test_parser.dart
- pkg/front_end/testcases/...
- pkg/kernel/lib/src/coverage.dart generated
- pkg/kernel/lib/src/equivalence.dart generated
- pkg/linter/lib/src/lint_codes.g.dart

Change-Id: Ice0141b763e63b84f54692cd19a442a0719673c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391263
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-11-06 18:42:25 +00:00
Ömer Ağacan 95e7793b68 Revert "[dart2wasm] Make int, double, bool box fields immutable"
This reverts commit af2bea8162.

Reason for revert: Caused unexpected performance regressions.

Original change's description:
> [dart2wasm] Make int, double, bool box fields immutable
>
> Make the `value` fields of `BoxedInt`, `BoxedDouble` and `BoxedBool`
> `final`, to generate immutable Wasm fields for them.
>
> Immutable fields can potentially generate better code, as loads from the
> same object will always generate the same value.
>
> To allow making the `value` fields `final`, add a constructor.
>
> To allow adding a constructor, "implement` base classes instead of
> extending them. With `extends` the front-end wants us to call the
> superclass constructors, even though they don't have any constructors.
>
> Implementing `bool` (instead of extending) causes issues in TFA as it
> currently assumes bool literals are compiled as the `bool` class. Update
> TFA to treat bool literals the same way as `int` and `double` literals.
>
> Tested: existing tests
> Change-Id: I3282e188d784fa7a22421edc79ed47f9d85faf19
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393320
> Commit-Queue: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: I8bb49bcc4bd9cd01f3e8a692d7ba1bef889ab555
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393840
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Ömer Ağacan <omersa@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2024-11-06 09:30:00 +00:00
Ömer Sinan Ağacan af2bea8162 [dart2wasm] Make int, double, bool box fields immutable
Make the `value` fields of `BoxedInt`, `BoxedDouble` and `BoxedBool`
`final`, to generate immutable Wasm fields for them.

Immutable fields can potentially generate better code, as loads from the
same object will always generate the same value.

To allow making the `value` fields `final`, add a constructor.

To allow adding a constructor, "implement` base classes instead of
extending them. With `extends` the front-end wants us to call the
superclass constructors, even though they don't have any constructors.

Implementing `bool` (instead of extending) causes issues in TFA as it
currently assumes bool literals are compiled as the `bool` class. Update
TFA to treat bool literals the same way as `int` and `double` literals.

Tested: existing tests
Change-Id: I3282e188d784fa7a22421edc79ed47f9d85faf19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393320
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-11-05 12:09:10 +00:00
Jens Johansen 6d4ebea83b [kernel] Optimize reading of metadata further
This optimization is based on the assumption (which at least holds true
for the dill file extracted from the mentioned bug) that only very few
nodes actually have metadata associated with it. For the test file, more
than two million node-offsets is looked up, and only ~7.5 thousand nodes
actually have metadata on it.
What is done here is to assume that most often we ask offsets in order
and that most often the answer is that there's no metadata (when we fall
into this case we can return `false` quickly) and we can skip looking up
the actual metadata. This furthermore - although not benchmark here -
should make it (a lot) faster in the case where we have multiple
subsections as we here only lookup in in one index. Only upon a `true`
response from that we have to lookup in all subsections to find and read
the actual metadata to associate.

Reading the test file without metadata, taking an average of averages
(average of 5 runs of the binary benchmarks output for
"AstFromBinaryEager") takes: 374481.4 us.

Before https://dart-review.googlesource.com/c/sdk/+/391761 reading the
test file with metadata takes: 627120.68 us.
This was about a quarter of a second, or 67+% slower.

With https://dart-review.googlesource.com/c/sdk/+/391761 this number
became: 441784.44 us.
A reduction of ~185 ms, or almost 30%, making the tax of reading
metadata "only" ~18%.

With this CL this number goes to 398011.44 us.
This is a further reduction of ~43 ms, or almost 10% (for a combined
reduction of ~230 ms or 36+%).
The tax of reading metadata is now ~6.3%.

Bug: https://github.com/flutter/flutter/issues/156713
Change-Id: I20bbabecfc8976293fe897528d05fc2145e2a8c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392021
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-10-28 11:11:48 +00:00
Jens Johansen cb7aee58ca [kernel] Read metadata faster
On a flutter dill extracted via the mentioned bug I get these timings
when (once, i.e. I haven't done extra statistics) running

```
out/ReleaseX64/dart pkg/kernel/test/binary_bench2.dart --warmups=10 \
--iterations=5 --metadata AstFromBinaryEager <dill from flutter>
```
(and without `--metadata` for without metadata):

Without reading metadata: ~378 ms
With reading metadata before this CL: ~627 ms
With reading metadata with this CL: ~435 ms

Bug: https://github.com/flutter/flutter/issues/156713
Change-Id: Id6cb27bc00526ff61c48eeb66ebb86dff1b971a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391761
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-28 07:27:54 +00:00
Johnni Winther 27048206ce [cfe] Rename TypeVariable to TypeParameter
This makes the CFE and kernel terminology consistent.

Change-Id: I6e35d9f4ea58d50eac0ab84763633bf5e445771d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390861
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-10-21 09:35:06 +00:00
Parker Lougheed ffc82e6f17 Stop enabling the package_api_docs lint
The lint is non-functional and will be deprecated soon.

Bug: https://github.com/dart-lang/linter/issues/5107
Change-Id: I4d4b75a6c7978f584bef37351514391f55761c55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389594
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
2024-10-14 21:22:19 +00:00
Lasse R.H. Nielsen f8086c81ae Collect all test-related files in package:expect.
Collects files from `package:async_helper` and `tests/language`
that are generally useful, so that all test-related helpers are
in `package:expect`.

Moves the two libraries from `package:async_helper` into `package:expect`,
and the `tests/language/static_type_helper.dart` file too.

Deprecates `async_minitest.dart`, to follow `minitest.dart`,
expecting the Flutter use of it to have been fixed to not break
on deprecation (I believe Flutter no longer breaks builds on deprecations at all).

Patch 1 is the actual change.
Patch 2+4+8 is changing all existing references to the files.
Patch 6 ignores deprecation in files still using `async_minitest.dart`.

3+5+7+9 are updating this text to make the numbers match.
Then it's just test-expectations and small tweaks from there.

Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-11 16:53:52 +00:00
Reid Baker e1dc36994a Bump dart version to 3.7
Change-Id: I9fec9765abfb46b2a3753367c20ac807fbdd487e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388600
Commit-Queue: Reid Baker <reidbaker@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2024-10-08 13:17:47 +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
Johnni Winther dcb09246b8 [cfe] Cleanup TypeParameterType
This removes code no longer needed after the split of StructuralParameterType from TypeParameterType.

Change-Id: I64b943a49b4a0464ef0c629763ea34dc53e893f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387941
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-02 12:03:20 +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
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
Paul Berry 2a6d9cbb98 Introduce a shared base class for type parameters.
Change-Id: I341097643b6d6cec3c83c398a84aebbdf7500d09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386736
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-09-30 14:40:36 +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
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
Paul Berry 0850220ad5 Fix unreachable switch cases in standard_bounds.dart.
I'm currently working on a fix for
https://github.com/dart-lang/sdk/issues/56710 (Analyzer fails to
report UNREACHABLE_SWITCH_CASE when there is a when clause). In order
to avoid spurious warnings when I land the fix, I first need to fix
any existing locations in the SDK that would cause the warning to
fire.

One such place is in the `standard_bounds.dart` file.

Bug: https://github.com/dart-lang/sdk/issues/56710
Change-Id: Icc917c3289b76760d29b6d7386a3794030274807
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384861
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-09-12 12:31:49 +00:00
Chloe Stefantsova b6b375b2cb [cfe] Adjust type schema closures in UP and DOWN as per spec
See breaking change request
https://github.com/dart-lang/sdk/issues/56466

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

Change-Id: I7b04821da92b8b41cb8610e701fa7e7905ff2487
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375121
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-09-02 11:47:49 +00:00
Jens Johansen 0329ebfd99 [CFE et al] Lint for fields with StackTrace.current
This CL primarily adds a lint for fields with `StackTrace.current`
which is often useful for debugging, but shouldn't be left in.

* Add an ast visitor after the "explicit creation test",
  finding - for now - `StackTrace.current` calls in fields.
  This should have caught the left-in debug such in
  https://dart-review.googlesource.com/c/sdk/+/379281.
* Renamed explicit_creation to compile_and_lint
* Remove (for some time) unused "smoke_test_quick" files.
* Add kernel to the compile_and_lint suite, but ignore it for explicit
  creation (i.e. kernel will also be checked for fields
  with `StackTrace.current`).

Change-Id: Ib886d23a8945e7063dc673a7f99cbb3a6adc1139
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-08-28 09:46:08 +00:00
Chloe Stefantsova c9d7e3a4f3 [cfe] Use exhaustive switch in MORETOP and MOREBOTTOM
Change-Id: I9d0197fa0a51bd8a72cb8207f159ceff7076c3e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382161
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-26 12:36:48 +00:00
Chloe Stefantsova a02427fdf7 [cfe] Use exhaustive switch in isSubtypeOf
This CL uses exhaustive switch statement instead of chained if
statements in the implementation of isSubtypeOf. In addition to that,
all of the individual methods for computing isSubtypeOf for specific
pairs of DartTypes are inlined into the switch statement.

Change-Id: I425e8d415d07767313c6f1ff796f7715e35f10bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382000
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-26 06:11:21 +00:00
Chloe Stefantsova 3acd125e44 [analyzer][cfe] Implement types and type schemas as extension types
This CL removes Type and TypeSchema type variables from the abstract
classes with shared code between the CFE and the analyzer. Extension
types SharedTypeView and SharedTypeSchemaView are declared to replace
the type variables.

The update propagates the discipline of distinguishing between types
and type schemas into the clients of the shared code. Now the code in
the CFE and the Analyzer that uses the shared code needs to statically
specify the interpretation of their type objects as either types or
type schemas.

Another benefit of the update is SharedTypeView and
SharedTypeSchemaView being less opaque than the Type and TypeSchema
type variables, which removes the necessity for some code duplication
in abstract methods for types and type schemas.

Finally, the update enables some further changes in the shared code
between the Analyzer and the CFE.

Change-Id: I88e8cfcd47d4f721974b4f2612521e85bb54c30f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379302
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-08-23 08:10:09 +00:00
Chloe Stefantsova 531e4ca0ec [cfe] Provide a helper for computing interface member signature type
Change-Id: Iefad05b1a5e9b6f93f821ad29635af31e6c8926e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381642
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-08-22 15:55:39 +00:00
Johnni Winther 7e2aecb58e [cfe] Compute type variable nullability
This adds an explicit computation for the nullability of type variables
while taking cyclic dependencies into account. This removes the need
for post-processing of pending nullabilities.

Change-Id: Ic7c42eef8270610d3b4f1d27ea0067c80df88daa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381242
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-08-22 08:23:05 +00:00
Paul Berry 4f2a0e97ba Remove unreachable default clauses from type_checker.dart.
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(https://github.com/dart-lang/sdk/issues/54575). To avoid a bot
failure when the fix lands, these unreachable default clauses need to
be removed.

Bug: https://github.com/dart-lang/sdk/issues/54575
Change-Id: If97416de0f13bc66cf60a1da7df295838a8d18a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380962
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-08-19 14:17:08 +00:00
Chloe Stefantsova b9eefd2861 [cfe] Use exhaustiveness in the implementation of DOWN
Using exhaustive switch over type pairs ensures all combinations are
handled.

This is a follow-up to:
https://dart-review.googlesource.com/c/sdk/+/379800

Change-Id: I55c8f8bca70301c331898c259a7988eb2911b045
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381180
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-19 12:00:29 +00:00
Chloe Stefantsova 15b467f94e [cfe] Use exhaustiveness in the implementation of UP
Using exhaustive switch over type pairs ensures all combinations are
handled.

This is a follow-up to:
https://dart-review.googlesource.com/c/sdk/+/379800

Change-Id: Ia6c4279a42590b439388d9fdd8ec5a8c36dbe23a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-08-15 10:52:13 +00:00
Alexander Markov 531a4c8f62 Expose experimental dynamic modules API through package:dynamic_modules
Change-Id: I14963de5f6face564276955d21d63f4b038cf990
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378722
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-08-12 17:56:29 +00:00
Chloe Stefantsova 0d679017e1 [cfe] Handle StructuralParamtersType in UP
Closes https://github.com/dart-lang/sdk/issues/56420

Change-Id: I49104e0d021a7d85b458c7b74d6a9445710743e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379800
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-08-09 14:00:39 +00:00
Chloe Stefantsova cf0e927a43 [analyzer][cfe] Make SharedType into a family of recursive types
SharedType and its subtypes now all declare one recursive type
variable Type with the bound SharedType<Type>. It allows to treate
SharedType and its subtypes as an abstract familty of types that has a
specific structure.

More specifically, the type variables Type and TypeSchema in the
abstract classes for shared algorithms between the Analyzer and the
CFE can now be defined recursively as extending SharedType<Type> and
SharedType<TypeSchema>, giving both types and type schemas the
structure of the family of types with the root at SharedType.

One of the benefits for that is that some abstract members become
unnecessary. For example, a type or type schema can now be tested for
having the shape of the type 'dynamic' with a direct is-check,
comparing them, correspondingly, with SharedType<Type> and
SharedType<TypeSchema>.

More importantly, having the family of recursive types lays the
foundation for further work on sharing the type structure between the
Analyzer and the CFE.

Change-Id: I67904f878668c035702092e8c21d3ce66f5ca469
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378700
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-08-09 07:10:42 +00:00
Stephen Adams e28c480e12 [dart2js] Use addUnused method for unused fields in proto shaker
The call to the new method has fewer arguments, which helps code size.

Change-Id: I50668e54bfba07ac34e8db99a748f7d83c6e5be4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-06 21:58:29 +00:00
Jens Johansen 9cfb44e053 [kernel] Introduce (and use) Substitution.fromSingleton
Turns out most things calling `Substitution.fromMap` first creates a map
of size 1, in which case a map doesn't seem like the right thing to use.

Also replace a few `growable: true` with `growable: false`.

When compiling the CFE with the CFE with an AOT snapshot, this CL:
instructions:u: -0.4582% +/- 0.0019% (-97936268.60 +/- 405215.88)

Change-Id: Ia1f5221cf84cd763139fcc5bd8518cbe7e575dfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375503
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-31 06:34:17 +00:00
Alexander Markov 4e0b69fbd9 [vm/aot] Improve dynamic interface annotator
Dynamic interface annotator now automatically annotates classes and
members which are used implicitly:

* Targets of redirecting factories.
* Classes and members used in constants.
* Instance fields of classes used in instance constants or
  having a callable const constructor.
* Everything used in the bodies of extendable mixin declarations and
  mixin classes.
* Possible dispatch targets of instance calls
  (overrides/implementations).

Front-end server now also exposes '--dynamic-interface' option,
similar to gen_kernel tool.

Also, this change includes a couple of minor fixes:
* Typo in ast.dart.
* In the front-end server, additional dill file specified with
  '--import-dill' option is not ignored when '--link-platform' is
  also used.

TEST=pkg/vm/testcases/transformations/dynamic_interface_annotator

Change-Id: I705b64efb1834dec6e0bdc5873025607f3472139
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377761
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-07-30 16:24:51 +00:00
Johnni Winther 69bc1e86fb [kernel] Remove Extension.isExtensionTypeDeclaration flag
This was only used for an early extension types experiment.

TEST=existing

Change-Id: Icb85c744bc2ff48aae713ef01271719d3657b664
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376940
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-07-22 14:42:13 +00:00
Johnni Winther c4368b3cd7 [cfe] Stop passing local scope on the stack
This a LocalStack extension type for using a list as a typed stack and
uses this for local scopes in the body builder, instead of passing the
local scopes through the listener stack.

This also removes the need for LocalScope.parent

TEST=existing

Change-Id: I536c63258e4196a1582e9a1d73489adcfdaa6698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376400
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-07-19 14:41:26 +00:00
Jens Johansen 90e1205750 [kernel] Don't call Substitution.fromMap twice with the same data in getFreshStructuralParametersFromTypeParameters
When compiling the CFE with the CFE with an AOT snapshot, this CL:
instructions:u: -0.5575% +/- 0.0037% (-119851086.80 +/- 799956.68)

Though probably mostly because
Scavenge(   new space) goes from 62 to 61

Change-Id: Ida0a834d6da34c8e09f521df3ff1490c6b6a875b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375522
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-12 15:55:29 +00:00
Johnni Winther c17e9c116e [cfe] Clean up backend imports
This updates backend imports to use reexports from api_prototype
or api_unstable.

TEST=existing

Change-Id: I8d9d1c76ef72c709c578acac5497064710ee5579
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373462
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-07-08 11:32:30 +00:00
Jens Johansen 164c10a150 [kernel] Remove unused mixinInferrer in ClassHierarchy
Change-Id: Ib18715586f34db92a0764cdb621cb791085a4c15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-08 09:40:49 +00:00
Jens Johansen ad5fa7f5e4 [kernel] Fix ExtensionTypeDeclaration specification in binary.md
Change-Id: Ie7dfec81517a9ef9fbb2935c9a1eff8607d3be41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374360
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-07-03 13:23:51 +00:00
Jake Macdonald 87b790b6d0 Bump version to 3.6
Change-Id: I1d096140adb8c01914e0b9d1c7cb2017204e7f0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373940
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
Reviewed-by: Kevin Chisholm <kevinjchisholm@google.com>
2024-07-02 00:02:19 +00:00
Jens Johansen a8314dac74 [kernel] Fix crash in dart_scope_calculator when all scopes are artificial
Fixes https://github.com/dart-lang/sdk/issues/55986

Change-Id: Icc7e6dbb4272613e838b0bd2ef9ac4764dd068f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373200
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-06-26 08:23:59 +00:00
Johnni Winther e40cad30a3 [cfe] Move fasta/codes/ to src/ and rename to cfe_codes*
Part of removing uses of 'fasta'.

TEST=existing

Change-Id: Ibf144a126d8ff4ba15b6cfd2c4fb898e9a499362
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371685
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-06-20 09:36:39 +00:00
Kallen Tu 9ead08f053 [cfe] Local functions named _ are not in scope.
Local functions named `_` are treated the same as local wildcard variables.
They cannot be referred to.
This CL changes that behaviour.

Bug: https://github.com/dart-lang/sdk/issues/55655
Change-Id: Idbbe2a4f5b406d4499602e808f6541af6451fb31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371480
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-06-14 22:31:48 +00:00
Kallen Tu 141bb5417b [kernel] Add isWildcard flag to VariableDeclaration.
Adds the `isWildcard` flag to variables. Will be using this for producing better errors.

TEST= Existing expectations tests for wildcards pass with new flag.
Bug: https://github.com/dart-lang/sdk/issues/55655
Change-Id: If2f7a5555e7cc26e84d1b1e63e4261c81a157d78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370062
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-06-10 19:33:39 +00:00
Johnni Winther c5cd8ff349 [cfe] Remove agnostic mode
The agnostic mode was added to allow the platform dill embedded in
the VM to support both weak and strong mode. Since weak mode is no
longer supported in the VM, the agnostic mode can new be deleted.

All uses of the agnostic in Dart and Flutter have been removed prior
to this change.

Change-Id: Iff0f69d9cd64e887e01cd7e7d336a97761bd6d4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366801
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-06-06 11:02:37 +00:00
Johnni Winther b2517e934f [cfe] Remove Env.isNonNullableByDefault
+ a few other references of 'isNonNullableByDefault'

Change-Id: Ifcd6bf5c2cc5dbbca7dda1576248fc4cd59eed5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369023
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-06-03 06:42:54 +00:00
Johnni Winther e3efaf2b66 [cfe] Remove isNonNullable from type_algebra et al.
Change-Id: Idcb55bcbc2cf42f4a6f49fb0751f9883a47ff66b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369041
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-06-03 06:42:54 +00:00
Johnni Winther ce12e3c8ac [cfe] Remove isNonNullableByDefault from class hierarchy
Change-Id: Ib5942357578a6481e8038dd090e4a9d9ff49f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369022
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-03 06:42:54 +00:00
Paul Berry 547307e554 Add SharedType.nullabilitySuffix getter.
This allows TypeAnalyzerOperations.getNullabilitySuffix to be removed,
and allows shared code to access nullability suffixes directly as
properties of a type, in the same way that the analyzer does.

Change-Id: I33ab90798b779534b5b0b111ec5137845b32f23b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368443
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-30 16:43:29 +00:00