Commit Graph

1390 Commits

Author SHA1 Message Date
Paul Berry 0ebb4fe7d9 Sort declarations in shared_type.dart
Change-Id: Id75cbcb1f49dc21db6ad8536214dec7bd757d55e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396301
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-11-19 17:56:22 +00:00
Chloe Stefantsova d79fcdf4cd [analyzer][cfe] Remove unnecessary use of shared views
This CL removes the unnecessary conversion from `TypeStructure` types
to `SharedTypeView` and `SharedTypeSchemaView` and back. By design,
the shared constraint generation method is operating on
`TypeStructure` types and uses the shared procedures named with the
'Internal' suffix to transform those types. In this CL the shared
procedures that are only used in the shared constraint generation
method or in 'Internal' procedures are converted to 'Internal'
themselves, and the corresponding update in the parameters accepted
and returned by those procedures is made.

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

Change-Id: Ic8596b342bde7e78093e990fc0f12f705ff6dee1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395962
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-11-19 17:17:13 +00:00
Chloe Stefantsova e2c17b938f Enable 'inference-using-bounds' flag in 3.7
TEST=existing

Change-Id: If7f143ab6c60cfda962c1ceba78fdbfdd949a3cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-11-19 08:54:03 +00:00
Chloe Stefantsova be1b2a9712 [analyzer][cfe] Share type constraint generation
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I15f7a78c9390466f5a48400f81def175faeb9fd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395020
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-11-14 12:34:42 +00:00
Johnni Winther 72534f18fa [cfe] Remove library fasta.* names
Change-Id: I0a678e971395f70d09a3faf004e6476a9b5a48cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395000
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-11-14 07:32:21 +00:00
Chloe Stefantsova 3bc27ffa52 [analyzer][cfe] Share constraint generation from bounded parameters
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I545ce1faa08448bf6f573550ca1349c124e55e9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394780
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-11-13 15:15:04 +00:00
Jens Johansen 4b7c6b1fa6 [parser] Remove (extension) Token.isA2
With 0ca1ff2281 fixing the reason why we
had `isA2` we can get rid of it. One 100-run-each-benchmark of compiling
a fixed version of the CFE with the current version of the CFE I get

```
msec task-clock:u: -0.3133% +/- 0.2298% (-13.22 +/- 9.70)
cycles:u: -0.4109% +/- 0.2303% (-71702583.62 +/- 40176749.86)
instructions:u: -0.0150% +/- 0.0002% (-3206465.75 +/- 50567.00)
branch-misses:u: -0.9597% +/- 0.8046% (-615355.48 +/- 515877.98)
seconds time elapsed: -0.3138% +/- 0.2297% (-0.01 +/- 0.01)
seconds user: -0.2991% +/- 0.2978% (-0.01 +/- 0.01)
```

(the only real thing to look at here is likely the `instructions:u`
going down by ~3.2 mio.)

For anyone interested:
Manualy testing what 0ca1ff2281 did vs
the commit before (by running it 5 times each by hand through perf stat)
I get

instructions:u: -0.0831338% +/- 0.00115149% (-1.78503e+07 +/- 247246)
(i.e. almost 18 mio less instructions).
Change-Id: I01600c33364933da262b3354298255e8b2df8afb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394101
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-11-13 15:10:51 +00:00
Jens Johansen 0b07f2ebae [parser] Better recovery on variable declaration with missing name before type parameter
Change-Id: Ie3e2995748c6f36c2cd98235658cbadfc53157a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394303
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-11-13 08:41:41 +00:00
Chloe Stefantsova e25fecfcd8 [analyzer][cfe] Share left-FutureOr constraint gathering
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I825e522f370ac7fd39466b5f6aa6571fea5b5633
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394501
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-11-13 07:53:54 +00:00
Chloe Stefantsova 097d0a30d3 [analyzer][cfe] Add isDartCoreRecord to the shared methods
This is done by analogy with `isDartCoreFunction` and is used
similarly in the type constraint generation methods.

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

Change-Id: Ied3a4e5ee55846c9c0f7e68dbcdff87548b94787
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394100
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-11-13 07:08:55 +00:00
Chloe Stefantsova bba00472e7 [analyzer][cfe] Share constraint generation for generic functions
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ic025cdc36a266d35094626df175346ccac6f99fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393860
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-11-13 03:47:43 +00:00
Chloe Stefantsova be6ca13322 [analyzer][cfe] Share constraint generation for nullable types
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I9ce094d28de679002c81b0ff95d94d433369afcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393741
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-11-13 02:51:21 +00:00
Jens Johansen a0c4efddb8 [parser] Don't try to parse a function literal when in a continuation
Fixes https://github.com/dart-lang/sdk/issues/49477

Change-Id: Ie290a1af08ecc5c2cd270af21adeb43943ec289b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-11-12 08:16:42 +00:00
Jens Johansen 0512c58348 [parser] Use allowCascades when calling parseThrowExpression in _parsePrecedenceExpressionLoop instead of just false
For now, see what happens.

Bug: https://github.com/dart-lang/sdk/issues/54284
Change-Id: I8e9f081ae3aa5caff7e155ef628e90547cc8afe6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392561
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-11-11 09:08:40 +00:00
Johnni Winther 4177d28464 [_fe_analyzer_shared] Support deferencing of StaticGet
This adds support for replacement a [StaticGet] with the constant
initializer of the referenced constant during evaluation of macro
metadata. Currently constants defined in the same library or
compilation is supported. For full support the constant initializers
need to be included in the outlines/summaries.

Change-Id: I219f85dded63342d4e3f957f0b7321badbe376a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392907
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2024-11-11 07:04:20 +00:00
Chloe Stefantsova 41db3ab735 [analyzer][cfe] Share constraint generation for record types
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: I90ac37472e14f9d00ef5e7d20a41f2878fb2b8f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393100
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-11-08 13:12:55 +00:00
Kallen Tu 8b3c5aa8f5 Add experiment flag for enum shorthands.
This CL adds an experiment flag named `enum-shorthands`. We can start prototyping the work needed for the feature under the flag.

Bug: https://github.com/dart-lang/sdk/issues/57037
Change-Id: I5d5e679b20f993e0af59ce5b2d28e47269ecaedb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393521
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2024-11-07 20:42:41 +00:00
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
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 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 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
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