Commit Graph

1720 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
Kallen Tu 53bad058b1 [flow] Add unit test for postIncDec().
Add Flow Analysis unit tests for FlowAnalysis.postIncDec() which should be used for postfix increment and decrement operations.

Bug: https://github.com/dart-lang/language/issues/3658
Change-Id: If77b6fbb5fc80d5f5d014ec0516d77578446dced
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393441
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-11-05 18:54:02 +00:00
Jens Johansen 817882c36b [parser] Recover missing identifier in new style typedef
Before, when parsing a new style typedef without an identifier (e.g.
`typedef = whatnot`) it concluded that the token after the equal-sign
wasn't an equal sign an that it thus had to be an old style typedef,
followed by recovery there.

This CL makes the recovery insert an identifier after `typedef` (what
the recovery of the old style actually did too), and then parse it as a
new style typedef.

This causes the previous many errors to just be `Expected an identifier,
but got '='.`

It is furthermore verified that the parsing of such a case is ~the same
as when having an indentifier.

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

Change-Id: I5cde1f29839555b1d6027a7d040dc6f60ac614a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392560
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-11-04 11:18:38 +00:00
Johnni Winther bdacb7d034 [_fe_analyzer_shared] Add evaluateExpression
This adds a helper method that evaluates an [Expression] based on
the semantics that can be deduced from the syntax.

Change-Id: I1b54ee03c1380d337969671133179aa557702a9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-11-01 09:26:44 +00:00
Johnni Winther 58c336e22b [_fe_analyzer_shared] Avoid deconstruction of potentially nullable type variables
The exhaustiveness model relies on null being extracted from nullable, for instance modeling `int?` as `int|Null`. This failed on type variable that are potentially nullable but not explicitly nullable. For these `Null` should be extract from their bound and not from themselves.

The logic in the getStaticType method now uses `isNullable` to determine both when to extract and to combine, so to avoid extracting but not combining `Null` for type variables and also not combine but not extract for instance for `void`.

Closes #56998

Change-Id: I47c2d0d6535ca66fe00e6344b11550c4308a7388
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392944
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-11-01 08:47:02 +00:00
Chloe Stefantsova 297c90b50b [analyzer][cfe] Share the constraint collecting procedures
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I98dae68a61536cc3292f2a4f05cab22a8014486d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392581
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-11-01 07:38:15 +00:00
Kallen Tu 00e4c92a64 [flow] Part 3 Issue 3658 Avoid writing promotion information for postfix inc/dec expressions.
Postfix increment and decrement expressions should not be saving any promotion information.

An example of where saving the promotion information after the write is unsafe is:
```
class A {
  A operator +(int i) {
    return new B();
  }
}

class B extends A {}

main() {
  A x = A();
  if ((x++) is B) {
    // x should not be B
  }
}
```

This change is only for the analyzer because the CFE does something different (converts the postfix increment/decrement into a let expression).

Bug: https://github.com/dart-lang/language/issues/3658
Change-Id: Ic22f69bf79da66965908ade80bdf70399f0bcaa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391494
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-10-31 22:15:14 +00:00
Ömer Sinan Ağacan 01238a49ec [_fe_analyzer_shared] Fix missing reference in a documentation in string_canonicalizer
Change-Id: I24f93b4461bb9ecb7fcdeccad97cd1ae85ff90bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392340
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-29 09:38:10 +00:00
Jens Johansen 329760d5cf [cfe/parser] Parser doesn't set wrong endToken on handleThrowExpression; fix cfe coverage related to that
Change-Id: Ie1f936d1b914f38a819b3761770742c60d9be1e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392121
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-10-28 12:08:50 +00:00
Johnni Winther 01dddf659e [_fe_analyzer_shared] Shared literal parsing
This adds shared helpers for parsing bool, int, and double literals to
their corresponding values.

The macro metadata literals are updated support digit separators and
to hold the literal value.

Change-Id: I709018b6c3a3b8ab09188d36c28f3c09636e0ea0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391964
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-28 09:03:45 +00:00
Johnni Winther b7aa0faa44 [_fe_analyzer_shared] Add test for named mixin application in macro metadata
Change-Id: Ia968e49f2663970496ba289c5098802e1794799a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391760
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-25 08:31:35 +00:00
Johnni Winther d96cecb4ff [_fe_analyzer_shared] Support mixins in macro metadata
Change-Id: I1eec1feb0230fa938b727c8eff88a048a53794be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391660
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-25 08:31:35 +00:00
Alexander Markov c409e77d1e Validation of dynamic modules
TEST=pkg/front_end/testcases/general/dynamic_modules


Change-Id: I591d029ed163961f5ece859233874f828d63c857
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388442
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-10-24 16:51:53 +00:00
Paul Berry 6a5b3d0457 Flow analysis: don't capture type information in equalityOperand_end.
There are two pieces of information flow analysis needs to know about
an equality test operand (i.e., an operands of `==`, `!=`, or
`identical()`):

- Their static types. This is used for reachability (e.g., flow
  analysis knows that if `f()` has type `Null`, then the body of `if
  (f() != null)` is unreachable).

- Whether they take the form of a null literal or a reference to
  something promotable. This is used to determine when an `if` test
  should promote a something to a non-nullable type.

Previous to this change, both pieces of information were captured by
`FlowAnalysis.equalityOperand_end` into an `ExpressionInfo` object,
and then those objects were passed into
`FlowAnalysis.equalityOperation_end`.

With this change, the client is now responsible for passing the static
types of the operands as separate arguments to
`FlowAnalysis.equalityOperation_end`, and the only information
captured by `equalityOperand_end` is whether the operand is a null
literal or a reference to something promotable.

This has two advantages:

- It avoids unnecessary allocations when analyzing code that doesn't
  have flow analysis consequences, since flow analysis no longer needs
  to allocate an `ExpressionInfo` for every equality test operand; it
  only has to allocate them for null literals and references to things
  that are promotable (which is a much smaller number of allocations).

- It means that `FlowAnalysis.equalityOperation_end` no longer needs
  to use the `type` field of `ExpressionInfo`. This helps build toward
  an eventual goal I have of removing this field, so that
  `ExpressionInfo` will simply be a container for a pair of flow
  models (one representing the flow state if the expression is `true`,
  one representing the flow state if the expression is `false`). I
  believe this will make flow analysis easier to reason about, and
  will help build toward a long term goal of cleaning up bugs in the
  "why not promoted" logic.

Making this change required adding a little bit of plumbing to the
analyzer, so that when analyzing an invocation of `identical`, it
keeps track of both the `ExpressionInfo` and the static type of the
operands; previously it just had to keep track of an `ExpressionInfo`
for each operand. The performance impact of this additional tracking
should be negligible, since this tracking doesn't happen for
invocations of anything other than `identical`.

Change-Id: I3e5473af095f3c8a747e9f527d7e14a21269dc95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389361
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-24 16:37:11 +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 4b2b07bf20 [_fe_analyzer_shared] Test late resolution of macro metadata
This delays the resolution of the identifier in metadata, such the
parsed annotation expression is initially unresolved and
`Expression.resolve` must be called in order to resolve it.

This execises the support for references to identifiers declare via
macros, which will initially occur as unresolved identifiers.

Change-Id: I4863ce950ded0b9d2c1744421d9751cddea6e80c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391641
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-10-24 09:40:25 +00:00
Johnni Winther c0381d06b9 [_fe_analyzer_shared] Support enums in macro metadata
Change-Id: Ic6534fcbd48881184d6cb64c556d638f3e1d97b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391601
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-10-24 08:13:21 +00:00
Johnni Winther 875a130a42 [_fe_analyzer_shared] Support extension types in macro metadata
Change-Id: I91d4a2837285583ec8c05f0f8f3c4c906f861411
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391402
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-10-24 08:13:21 +00:00
Johnni Winther bf16a40a97 [_fe_analyzer_shared] Support extensions in macro metadata
Change-Id: I06d3eeab53d8f739ec75dc5795ce46b57ef6f05b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391400
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-23 07:48:23 +00:00
Johnni Winther 35db90aef6 [cfe][analyzer] Add metadata parser
This adds a shared metadata parser to be used for macros. The parser
create a new AST which supports unresolved ASTs and delayed AST resolution.
An id-test is added for the generated AST from both CFE and analyzer.

Change-Id: Ie51817493fa6e668727a7af3a55cd22e2be722b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391100
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-23 07:48:15 +00:00
Chloe Stefantsova d75fe77231 [anlyzer][cfe] Use bounds to restrict choices during inference
Closes https://github.com/dart-lang/language/issues/1194

Change-Id: I6866b6ab6f29cddbb293122e09588f705aaea1c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387020
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-10-23 07:35:37 +00:00
Paul Berry c3ce683cca [Breaking change] Account for field promotion to Null when computing reachability based on equality tests.
Fixes https://github.com/dart-lang/sdk/issues/56893.
Fixes https://github.com/dart-lang/language/issues/4127.

Bug: https://github.com/dart-lang/sdk/issues/56893
Bug: https://github.com/dart-lang/language/issues/4127
Change-Id: If8bb0144ebe7024a7f4f7c1733e24632b4549c7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389660
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
2024-10-22 22:10:50 +00:00
Kallen Tu 47d550277d [flow] Issue 1721 - Allow better promotions for final variables.
Promotions should happen for final variables because they are assigned and won't be re-assigned by the time they're evaluated. In a conservative join, promotions should not be cancelled for final variables.

Language tests made in https://dart-review.googlesource.com/c/sdk/+/390340.

Bug: https://github.com/dart-lang/language/issues/1721
Change-Id: I7bb577a694ddb5572a28884de70bd8c5b68e3c25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390803
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-10-22 20:05:50 +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
Kallen Tu b85c499b60 [flow] Part 1 Issue 3658 - Store variable information after a write.
Assignments in the condition of an if statements don't store the promoted information (for the write of that variable). This fix stores the promotion of that expression for when we use it to null check or otherwise.

Part 1 because there's still some holes with postfix operators and null asserts that need to be fixed, but this behaviour stands on its own at the moment.

Everything is behind the flag so we'll iterate.

Bug: https://github.com/dart-lang/language/issues/3658
Change-Id: I8663f089a451468651efccadeb3991b34a37d899
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388903
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-10-17 17:51:54 +00:00
Chloe Stefantsova 0083afa5d5 [parser] Make NullAwareEntry to be treated as a direct entry
Previously NullAwareEntry set the hasEntry property to false, which
meant that it relied on a nested entry element to handle the rest of
its contents. However, according to the grammar for null-aware
elements (see
https://github.com/dart-lang/language/blob/main/accepted/future-releases/0323-null-aware-elements/feature-specification.md#syntax),
null-aware elements and entries are leaf nodes and can only contain
expressions.

This CL also fixes some crashes in the CFE that expects the map
entries appearing in lists to be handled by the parser.

Change-Id: I3d7a3f3e8507a2ef8a290e51b49e4749260dfcda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389900
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-16 07:45:41 +00:00
Johnni Winther 307e5a62ce [cfe] Include offended version number and package name in too high/low version message
Closes #48819

Change-Id: I8700ed909c916b9c656cc8bc0e34eb1dd6ef0c09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390200
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-16 06:36:21 +00:00
Kallen Tu 1bf5482e1e Enable 'wildcard-variables' feature flag.
This CL enables the wildcard variables feature by default in Dart 3.7.

Local variables and parameters named `_` are now non-binding and they can be declared multiple times without collisions. All wildcard variable declaration types that have this behavior are described in the
wildcard variables specification: https://github.com/dart-lang/language/blob/main/accepted/future-releases/wildcard-variables/feature-specification.md.

Top-level variables, top-level function names, type names, member names, etc.
are unchanged. They can be named `_` and used as they are today.

These are a few examples of where wildcard variables can be used:
```dart
Foo(_, this._, super._, void _()) {}

typedef T = void Function(String _, String _);

main() {
  var _ = 1;
  int _ = 2;

  list.where((_) => true);
}
```

Bug: https://github.com/dart-lang/sdk/issues/55673
Fixes: https://github.com/dart-lang/sdk/issues/55654
Change-Id: I80e904d39b364f5e54b8406b4db02ec40ecc9db0
TEST=Existing tests, language tests for wildcards.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381311
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2024-10-15 19:12:31 +00:00
Paul Berry 4f01b048dd Add tests reproducing language issue 4127.
These tests exercise the current (unintended) behavior described
https://github.com/dart-lang/language/issues/4127, which was
previously not well tested.

Adding these tests acts as a safeguard to make sure that we don't
change the current behavior by accident.  If/when we decide to fix
https://github.com/dart-lang/language/issues/4127, the test
expectations will need to be updated.

Bug: https://github.com/dart-lang/language/issues/4127
Change-Id: I02fd1d393038a304401d11cf2c19e97755ba90a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389584
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-10-15 13:11:36 +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
Paul Berry 1041fe59ff Document flow analysis "expression info" and "expression reference" logic.
This CL adds documentation to the flow analysis methods
`_getExpressionInfo`, `_getExpressionReference`, `_setExpressionInfo`,
and `_setExpressionReference`, which allow flow analysis to keep track
of information between API calls.

It also documents the assumptions flow analysis makes about the order
in which the client traverses the AST. Note that these assumptions are
not always satisfied (see
https://github.com/dart-lang/sdk/issues/56887).

Change-Id: I66fd9a75f1491a8b926281d4e3b90e90d857c89a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389590
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-10-14 13:09:28 +00:00
Johnni Winther e94acd387d [cfe] Extract GetterFragment and SetterFragment from MethodFragment
This prepares for creating a PropertyBuilder that uses FieldFragment,
GetterFragment, and SetterFragment.

Change-Id: I31b9b6c3c1561ef17a561871aea9873f10f4fddc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389840
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-14 12:52:17 +00:00
Paul Berry 7e18fad7d8 Remove expression info invalidation from nonNullAssert_end.
This logic was a hack that was needed for the null safety migration
tool, to account for the fact that when inserting a non-null assertion
operator (`!`), it used the same Expression object to refer to the
non-null assertion operation as it did to refer to the operand. So the
normal flow analysis mechanism for ignoring irrelevant expression info
(noticing that the expressions are different) didn't work.

Now that the null safety migration tool no longer exists, flow
analysis no longer needs this hack.

Change-Id: I63a504371a70e3eb0b43303010cb0b4eac032479
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389262
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
2024-10-12 13:49:37 +00:00
Jake Macdonald 18774fc04b Revert package:json sdk constraint, add experimental release version of 3.6 for enhanced parts and augmentations.
Bug: https://github.com/dart-lang/sdk/issues/56867
Change-Id: I6d1c190b71e5492d620682cf8ff9cb003b8917c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389240
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-10-11 08:26:50 +00:00
Konstantin Shcheglov ddb81c1ad3 Prepare to publish analyzer 6.11.0 and _fe_analyzer_shared 76.0.0
Change-Id: I6ccb41385f74168891d8888db198ebda0a1716a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389540
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-10-10 18:53:14 +00:00
Paul Berry e8ff9efe9a Add _PropertyElement.toString.
This improves the debug experience when debugging flow analysis code.

Change-Id: I876dece6213b0495caae5a9e673376898198e709
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389221
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
2024-10-10 17:40:03 +00:00
Paul Berry 4a9c2c09f6 Fix nonspecific type annotation in _getNonPromotionReasons.
Without this change, the local variable `nonPromotionHistory` winds up
getting type `NonPromotionHistory<dynamic>?`, and then the assignment
`Type nonPromotedType = nonPromotionHistory.type;` winds up performing
an implicit dynamic downcast.

Change-Id: I4ece2433ac90623b22aa14cff3e1bfe16c9b491c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389260
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-10-09 20:04:02 +00:00
Jens Johansen 8c5dce6994 [parser] Replace optional/optional2/isOneOf/isOneOfOrEof with extension method calls
The entire scanner/parser now no longer uses `optional` or `optional2`,
the latter being completely removed.

Furthermore, when compiling a fixed version of the CFE with the CFE
this CL reduces the instructions used by ~13.6 mio.

```
page-faults:u: -0.3695% +/- 0.0676% (-384.20 +/- 70.23)
instructions:u: -0.0645% +/- 0.0007% (-13671097.80 +/- 153289.78)
```

Change-Id: Ib93dd2983aa1b4df0610d099010ac10f55f357f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388323
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-09 12:11:50 +00:00
Jens Johansen fd2b247b68 [scanner/parser] Naturally avoid bounds check in SimpleToken.type
By making the constant array have size 256 we "naturally" avoid the
bounds check in SimpleToken.type.

Stats for 10 runs each before/after:
```
page-faults:u: -0.1222% +/- 0.0686% (-127.40 +/- 71.50)
instructions:u: -0.2589% +/- 0.0007% (-55273529.20 +/- 147748.67)
```

Stats for 100 runs each before/after:
```
msec task-clock:u: -1.6562% +/- 0.7810% (-71.89 +/- 33.90)
page-faults:u: -0.1251% +/- 0.0186% (-130.44 +/- 19.36)
cycles:u: -1.6881% +/- 0.8129% (-302264895.65 +/- 145560853.90)
instructions:u: -0.2593% +/- 0.0002% (-55345822.71 +/- 36070.85)
branch-misses:u: -5.9592% +/- 2.5980% (-4206550.69 +/- 1833947.73)
seconds time elapsed: -1.6470% +/- 0.7804% (-0.07 +/- 0.03)
seconds user: -1.6494% +/- 0.8506% (-0.07 +/- 0.04)
```

To my surprise this also reduced the size of the aot compiled CFE
by ~20 kb.

Change-Id: I149eda23a0b88f06953156021389bd85728e97ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387920
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-10-09 11:56:20 +00:00
Paul Berry a1c805431e [cfe][analyzer] Change performSubtypeConstraintGenerationForFunctionTypes to return a bool.
Previously, this method returned `bool?`, however the only two
possible return values were `true` and `null`.

Change-Id: Ib111d6b3da87f8d04de884635fbec9ec7046dd8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388860
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
2024-10-09 05:37:22 +00:00
Konstantin Shcheglov 6655f50989 Prepare to publish analyzer 6.10.0 and _fe_analyzer_shared 75.0.0
Change-Id: I05c4b308b8ca8f700cd4e135a999041db6271de8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388941
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-10-08 17:19:40 +00:00
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
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
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
Paul Berry 38c08f919d [flow analysis] Remove ExpressionInfo.after.
Previously, the base `ExpressionInfo` class contained four fields:

- `type`: the type of the expression.

- `ifTrue`: a flow model describing the state of the program after the
  expression is evaluated, assuming the expression evaluates to
  `true`.

- `ifFalse`: a flow model describing the state of the program after
  the expression is evaluated, assuming the expression evaluates to
  `false`.

- `after`: a flow model describing the state of the prorgam after the
  expression is evaluated, making no assumptions about what value the
  expression evaluates to.

The `after` field was largely redundant, since it tracked the same
information as `FlowAnalysisImpl._current`. In fact, flow analysis
contained a substantial amount of code to copy from
`ExpressionInfo.after` to `FlowAnalysisImpl._current`, or vice versa,
in order to keep the two in sync.

The one exception was in `FlowAnalysisImpl.conditional_end`, which is
called at the end of visiting a conditional expression (`e1 ? e2 :
e3`): it joined the `after` flow models from `e2` and `e3` in order to
determine the state of the program after the conditional expression
completes. To preserve this behavior, a small amount of extra
accounting logic had to be added to the handling of conditional
expressions, to keep track of these flow models. (`e2.after` is now
stored in `_ConditionalContext.thenModel`, and `e3.after` comes from
the state of `_current` at the time of entry into
`FlowAnalysisImpl.conditional_end`).

Change-Id: I46e771f8b029550d43a5fe50366177f189a6a91d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388081
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
2024-10-04 13:44:40 +00:00
Paul Berry 7a40688209 Sort named fields in mini types record representation.
This brings the "mini types" representation of records (which is used
for _fe_analyzer_shared unit tests) into alignment with the behavior
of analyzer and CFE record types (which sort their fields), and makes
the representation more consistent with that of function types.

Since all implementations of record types now maintain named fields in
sorted order, documentation has been added to
SharedRecordTypeStructure to indicate that the fields returned by the
`namedTypes` getter are sorted.

This exposed a minor bug in the error recovery logic in the shared
pattern type analyzer: upon encountering a record pattern with
duplicate field names, after reporting the appropriate error, it would
nonetheless attempt to create a record type containing duplicate
fields (potentially breaking the assumptions made by other code that
handles record types). This bug was fixed by adjusting the record
pattern analysis logic so that it drops duplicate field names when
constructing record types.

Change-Id: Ib06b86df980afcf17896e10ac7856f994aeda86f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388041
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-10-03 21:26:50 +00:00
Paul Berry b452721942 Change "mini types" type parameters to match CFE and analyzer.
Previously, the "mini types" representation used in
`_fe_analyzer_shared` unit tests represented unpromoted type
parameters using the `PrimaryType` class (which was also used for
interface types and special built-in types like `void`) and
represented promoted type parameters using a separate
`PromotedTypeVariableType` class.

This CL changes the "mini types" representation to use a single
`TypeParameterType` class for both unpromoted and promoted type
parameters.  This parallels the representation used by the analyzer
and CFE, so it should help pave the way for sharing type system logic
between the analyzer and CFE.

To allow the `Type` constructor to distinguish whether a given
identifier represents an interface type or a type variable, tests must
register all type names they will need, using either the static method
`TypeRegistry.addTypeParameter` or the static method
`TypeRegistry.addInterfaceTypeName`.

To prevent the type names registered by one unit test from interfering
with those registered by another, tests should call
`TypeRegistry.init` in a `setUp` callback and `TypeRegistry.uninit` in
a `tearDown` callback. Methods in `TypeRegistry` contain error checks
to help make sure these calls aren't forgotten.

Change-Id: I701842ad94899c819f1a059e660510a616d00456
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387822
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-10-02 12:53:10 +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