Commit graph

13323 commits

Author SHA1 Message Date
Konstantin Shcheglov 636abe3ab7 Extract TreeStringSink and ElementPrinter, reuse in a few tests.
Change-Id: I78cafbd198af113f11216d7c0322559dc5d20cd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312320
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-04 21:43:23 +00:00
Sam Rawlins e67a2193da Add jsonEncode for use in unreachable_from_main
Bug: https://github.com/dart-lang/linter/issues/4495
Change-Id: I74b0a6cb516d2850bb922005e463f58f58453b4f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312280
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-07-04 03:02:47 +00:00
Konstantin Shcheglov 37003ee3be Add InterfaceElementImpl, move many methods into it.
Change-Id: I7f77e318586b2c05874b3a0d25d2d940869b6a0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312240
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-04 01:41:38 +00:00
Konstantin Shcheglov d4de535a3a Use identical() instead of == for elements in RuntimeTypeEqualityVisitor.
See https://github.com/dart-lang/mockito/issues/658#issuecomment-1615269018

Change-Id: I5b9e4b1d82ec935bcd2097ec76cf5a8e28c5e29e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312205
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-04 01:33:12 +00:00
Konstantin Shcheglov 44a94e8400 Remove 'Clients may not extend...', because all these classes are final.
Change-Id: If20d22b0407a67f630aa87debada6dab1d803c71
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312201
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-04 00:17:10 +00:00
Kallen Tu c86af3c39b [analyzer] Refactor visitMethodInvocation in the const evaluator.
Change-Id: I9ae6c17967c98770ed06dead200c8bd87ae7f2a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309829
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-30 18:32:27 +00:00
Konstantin Shcheglov 8828fee865 Deprecate ExecutableElement.returnType, use returnType2 instead.
Change-Id: Ibd29c3fbec0439236c2cf45c57f820c45427df9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311932
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-29 23:16:59 +00:00
Jake Macdonald 34f25c4a28 Add library introspection apis for macros.
Allows you to ask for the types in a library in the declarations phase, and all
the top level declarations in the definitions phase.

Bug: https://github.com/dart-lang/language/issues/2839
Change-Id: If0f8fb777fd8a006d686d457cf5d5ca11fcca9ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311900
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-06-29 22:05:58 +00:00
Kallen Tu 74adf1626e [analyzer] Refactor visitNamedType and other visitors in const evaluator.
Change-Id: Ia3c22fc87c96d719cfa3617c72f5586badfec183
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310972
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-06-29 21:26:14 +00:00
Konstantin Shcheglov fae9e418ea Deprecate Element.enclosingElement, use enclosingElement2 instead.
Change-Id: I78edb6d433949eb8bd86f397fb873a078edf9fc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311827
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-29 19:45:19 +00:00
Konstantin Shcheglov 8a037770f9 Tweaks for element model documentation comments.
As requested in https://dart-review.googlesource.com/c/sdk/+/311725

Change-Id: I76cd2322f9cca9845f3ec767adfd1e5dca9d7c47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311826
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-28 20:28:30 +00:00
Konstantin Shcheglov 6f01da06a2 Put aside invalid mixin constructors, quick fix for MIXIN_DECLARES_CONSTRUCTOR.
Change-Id: If1b808bf7746b4f2c2c856d7fb7e72499023759f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311823
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-28 19:49:08 +00:00
Konstantin Shcheglov 1fd7e2b670 Update a few documentation comments to the style guide.
Change-Id: If019e456de041081ed688cfce4c7f5063055ba39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311821
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-28 17:44:08 +00:00
Konstantin Shcheglov 892a7fbe4e Put aside invalid nodes during parsing, fix for EXTENSION_DECLARES_CONSTRUCTOR.
Change-Id: Ic01f4c1116ecb29087c8d1bff679906522b7562e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311726
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-28 15:17:23 +00:00
Konstantin Shcheglov a49dbe539f Extract NamedInstanceElement from InstanceElement, use for ExtensionElement.
Change-Id: Iee49f110afacc3f5c54fb15e70b3f18ac18c67a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311725
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-28 15:16:18 +00:00
Liam Appelbe 13ec07415b [vm] Async FFI callbacks
More details about the design:
https://docs.google.com/document/d/1QDjyY_6wOTOgURwpeYMKU9qEz0gKxx2MUrdruC6Kp6c/edit?usp=sharing

Change-Id: Ie3985d86dca7f5010044ca46c33ca177588c0f69
Bug: #37022
CoreLibraryReviewExempt: Reviewed by vm and api groups. web and wasm groups not affected because FFI isn't on those platforms.
TEST=async_void_function_callbacks_test.dart, ffi_callback_metadata_test.cc, other front end tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305900
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-28 01:00:18 +00:00
Konstantin Shcheglov d264ceeb05 Add InstanceElement as a super-interface for InterfaceElement and InlineClassElement.
Change-Id: Ie92168509cccb5b145bc5c9adea2945813725038
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311721
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-28 00:56:05 +00:00
Ludi Zhan cdd1163b27 [analyzer] Address coding style comments for visibleOutsideTemplate change
Addressing additional comments got from:
https://dart-review.googlesource.com/c/sdk/+/304825?tab=comments

Change-Id: I973c2c33a9a850122542389fc65d66c6fb810deb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311300
Auto-Submit: Ludi Zhan <ludizhan@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-27 03:53:37 +00:00
Jake Macdonald d1ecf01f71 Cache remote objects by ID, only send IDs for already sent objects
This is done through a synchronized cache between the server and client. When serializing a remote instance, if the server has already serialized that object then it will only send the ID in the future.

These caches currently only live as long as a single macro application in a given phase, but could live longer in the future. They do need to get reliably cleared out to avoid memory leaks though, and the shorter lifetime is easier to manage consistently.

This also allowed me to remove the specialized server/client modes (clients would always only send back IDs previously).

Change-Id: I4e8a102403153829d66b0ac379636f5a95a70cea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311420
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-06-26 22:36:37 +00:00
Parker Lougheed 5200d086d1 [pkg/analyzer] Add class to diagnostic messages for special highlighting
Will be used on dart.dev for customizing the highlight syntax in code blocks to be red underlines rather than yellow highlighting.

Related: https://github.com/dart-lang/site-www/pull/5006
Change-Id: Ib33ee8f6f7307efb649b627dfd9a5d90187cca1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311500
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-06-26 19:58:56 +00:00
Konstantin Shcheglov 69c62b1a31 Remove shipped features, and deprecated experiments from tests.
Change-Id: I428906a1d75a0dacedc8a5d5fd805f84ca8e3ce0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311156
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-24 16:23:28 +00:00
Konstantin Shcheglov b013a40f39 Add isInline to ClassElement.
Change-Id: I80dafc9ef0dc03b8090032a7b7168302a8d6ad66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311150
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-23 22:49:09 +00:00
Marcin Wojnarowski e56ef707eb Fix grammar docs for type aliases in AST
Closes https://github.com/dart-lang/sdk/pull/52515

GitOrigin-RevId: aa7b3ddee2a5b90bbb671e15b9a777ae441f83b4
Change-Id: Ib201d5ef9193b50305138efc23e97b8c5be8336f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305840
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-22 21:17:52 +00:00
Kallen Tu 951d589c20 [analyzer] Refactor visitPrefixExpression, visitNamedExpression, and visitParenthesizedExpression.
Change-Id: I5a5fa0897d25aab3092fc526342c5af12a67e0a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310770
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-22 20:48:48 +00:00
Jake Macdonald b9bcfa7004 add Library and LanguageVersion classes, all declarations now have a library
Bug: https://github.com/dart-lang/language/issues/2839
Change-Id: Id09b2da070302b67f7c9921f1ad8a6d91a129f77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311000
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-06-22 20:37:14 +00:00
Kallen Tu 9ec1a84f29 [analyzer] Produce CONST_EVAL_EXTENSION_METHOD diagnostic when using extension methods in const contexts.
More specific error code.

Semi-related to work in https://dart-review.googlesource.com/c/sdk/+/301505.

Change-Id: I1233e9e31389d387a9c777fe83cdd30a224bd00e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310760
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-22 20:35:29 +00:00
Konstantin Shcheglov 5940badbd3 Prepare to publish analyzer 6.0.0 and _fe_analyzer_shared 62.0.0
Change-Id: Ic816540e8b052fdd1fd59f030c334c3bf56e79f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310961
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-22 19:00:56 +00:00
Keerti Parthasarathy ab884b7d7f Refactors to allow for parse only mode for lints and fixes.
- Make CorrectionProducer as base class for {Parsed/Resolved}CorrectionProducer.
- Use ParsedCorrectionProducer for ConvertDocumentationIntoLine
- Move sort imports test to used ParsedUnitResult
- Add getter to LintRule to indicate that rule can be run using just parsed AST


Change-Id: Id11466c445e6e505ea752d097b57143f18c47060
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310484
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-06-22 18:20:15 +00:00
Kallen Tu b8d8da0183 [analyzer] Refactor visitListLiteral to handle Constants.
Add CONST_FOR_LOOP error message to be clearer that for loops are not
allowed in const contexts.

visitListLiteral handles Constants.

Change-Id: I84465ecf4e1f044c256db45c723fac081b50a40c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306917
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-21 18:20:51 +00:00
Brian Wilkerson bf62bc27bc Adjust the definition of coveringNode to favor identifiers
I would like to use `Selection` for code completion, but the current
definition of `coveringNode` too often favors the parent node over the
child node. This will effectively cause the cursor to bind more closely
to an identifier token than to other tokens, making it more useful for
code completion.

If we don't like this change for the general case, I can make these changes in a specialized `coveringNodeForCompletion`, but I'd rather not have two approaches.

Change-Id: I39e70f83ad44d50cec55a8bee1f7061dd83746fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310060
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-06-21 17:55:36 +00:00
Paul Berry 2ca7380ab0 Flow analysis: fix first phase handling of pattern assignments.
Prior to this change, the first phase of flow analysis, in which flow
analysis "looks ahead" to see which variables are potentially assigned
in each code block, was failing to properly account for variables that
are assigned by pattern assignment expressions. This "look ahead"
information is used by flow analysis to determine the effects of
nonlinear control flow (e.g. to figure out which variables to demote
at the top of a loop, or to figure out which variables are potentially
assigned inside a closure). As a result, it was possible to construct
correct code that would be rejected by the analyzer and compiler, as
well as incorrect code that would (unsoundly) be accepted.

The fix is to call `AssignedVariables.write` from the analyzer's
`FlowAnalysisVisitor`, and from the CFE's `BodyBuilder`, to let flow
analysis know about variable assignments that occur inside pattern
assignment expressions.

Fixes #52745.

Change-Id: I0e6f426a5c5c36f214d5a206aaf5a2de0bfdaac1
Bug: https://github.com/dart-lang/sdk/issues/52745
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310502
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-21 14:33:42 +00:00
Kallen Tu 3deaeb84dd [analyzer] Refactor visitFunctionReference for the const evaluator.
Simple functions can be printed in dart_object_printer.dart.
Moving function reference tests around so they can be easily found together.


Change-Id: If022721f7dca4881d51cbebd65ed968cd89c33c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308261
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-21 14:29:48 +00:00
Liam Appelbe 583da435e9 [analyzer] Support for RawVoidCallbacks
Pointer.fromFunction returns a native function pointer to a Dart
function, but has the restriction that the native code must invoke it
on the same thread as the isolate that created it. RawVoidCallbacks is
a new API that is similar to Pointer.fromFunction. It returns a native
function pointer that can be invoked on any thread, with the
restriction that the Dart function must return void. Under the hood we
forward the function args over a port to the target isolate.

We're not 100% settled on the name of the class, but the overall API
design won't change. I'll make sure to get the naming finalized before
submitting this CL. Doc with discussion of naming:
https://docs.google.com/document/d/1z9Rgahoid2AhC9JXwsDAEODvlJS6dvBHCbcGkOxv_ws/edit?resourcekey=0-TbdNiSL-fdwskla02QaPwg#heading=h.te70ikwelbw8

Bug: https://github.com/dart-lang/sdk/issues/37022
Change-Id: Iba98f6f803c52919b942fa054df1060991574c8c
TEST=ffi_async_callback_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Marya Belanger <mbelanger@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-18 23:28:52 +00:00
Paul Berry 80bc65bb0b Flow analysis: add field promotion support for cascades.
This change updates the flow analysis support for field promotion
(which is not yet switched on by default) so that it supports field
accesses inside cascade expressions. The key moving parts are:

- The type hierarchy `PropertyTarget` (which is used by the client to
  tell flow analysis whether the target of a property access is
  `this`, `super`, or an ordinary expression) now has a new class,
  `CascadePropertyTarget`, to represent the situation where the target
  of the property access is an implicit reference to the target of the
  innermost enclosing cascade expression.

- Flow analysis has two new methods on its API:
  `cascadeExpression_afterTarget` and `cascadeExpression_end`, so that
  the client can inform flow analysis when a cascade expression is
  being analyzed.

- Flow analysis uses its `_makeTemporaryReference` method to track the
  implicit temporary variable that stores the target of cascade
  expressions. (This method was developed as part of flow analysis
  support for patterns, where it creates the data structures necessary
  to track the implicit variables that are created as part of pattern
  desugaring).

- The "mini-AST" pseudo-language used by flow analysis unit tests now
  has a way to represent cascade expressions and method invocations.

- In addition to unit tests for `_fe_analyzer_shared`, `analyzer`, and
  `front_end`, there are new language tests in
  `tests/language/inference_update_2` to test cascaded field
  promotions in end-to-end fashion.

Bug: https://github.com/dart-lang/language/issues/2020
Change-Id: I21353bbc884ed599cb1739cecfb68ad1d975d18b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309220
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-06-17 08:13:20 +00:00
Jake Macdonald 96dcb2a5ab add support for type annotations and code arguments
Change-Id: I14ad05e810494de94f7935b7ca11b1922f90ecda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309021
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-06-16 16:59:06 +00:00
Konstantin Shcheglov 21cfe2ce61 Breaking changes for analyzer version 6.0.0
Change-Id: I792c3d66fb10ab779e2a5011b2909efa5738aba7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265183
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-16 16:31:27 +00:00
Jake Macdonald 4590fc83e7 Reland "Add wrappers for macro arguments to help with serialization."
The type arguments have to be explicitly given for collection types,
but this should be doable given they are all constants and only certain
types are allowed.

Change-Id: I2721f37d194d73de1df81302298101adeb87534c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309460
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-06-16 14:02:05 +00:00
Parker Lougheed 67ea3cafee [pkg/analyzer] Focus inference_failure_on_function_return_type target on function name
Closes https://github.com/dart-lang/sdk/issues/52700

Bug: https://github.com/dart-lang/sdk/issues/52700
Change-Id: I1a252c275da1a7702df568e97301fd180a662d52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309443
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-14 19:22:51 +00:00
Ilya Yanok 396ed71267 Revert "Add wrappers for macro arguments to help with serialization."
This reverts commit ea7e014c3c.

Reason for revert: breaks Analyzer tests, CBuild regression.

Original change's description:
> Add wrappers for macro arguments to help with serialization.
>
> In particular this allows us to reproduce type arguments for collections in the
> macro expansion isolate.
>
> The type arguments have to be explicitly given for collection types,
> but this should be doable given they are all constants and only certain
> types are allowed.
>
> Bug: https://github.com/dart-lang/language/issues/2212
> Change-Id: I14a688ed294cf060c004849efa975b5bef053d5b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308202
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Jake Macdonald <jakemac@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

Bug: https://github.com/dart-lang/language/issues/2212
Change-Id: I402802c7a1c27f9aee3f23baef8c0deb71ec06e9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309284
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-06-14 15:34:37 +00:00
Jake Macdonald ea7e014c3c Add wrappers for macro arguments to help with serialization.
In particular this allows us to reproduce type arguments for collections in the
macro expansion isolate.

The type arguments have to be explicitly given for collection types,
but this should be doable given they are all constants and only certain
types are allowed.

Bug: https://github.com/dart-lang/language/issues/2212
Change-Id: I14a688ed294cf060c004849efa975b5bef053d5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308202
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-06-14 14:54:30 +00:00
Kallen Tu 0f6e13a220 [analyzer] Refactor visitConstructorReference and tests in the const evaluator.
Change-Id: I24eb2a2daa3bd7437dfdc5ab2f4fed4899209fbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308260
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-06-13 17:06:39 +00:00
Kallen Tu b80d5479c1 [analyzer] Change error message for mixin subtypes of final and base types.
Add new diagnostics for mixin subtypes since they can only be 'base'.

Bug: https://github.com/dart-lang/sdk/issues/52686
Change-Id: I8e4d6830c5c735c5b42d7fbe78d197c9506bbf4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308806
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-06-13 16:00:21 +00:00
Konstantin Shcheglov d9e2f515ea Check the id of the formal parameter in update, and formal parameters vs. target.
Change-Id: I5f6d1f65386d385d470a7b1d0de3727c0f7788e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308843
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-13 15:52:28 +00:00
Konstantin Shcheglov a4ac770b44 Add List.stablePartition(), use in CreateConstructorForFinalFields.
See https://en.cppreference.com/w/cpp/algorithm/stable_partition

Change-Id: I1cf77ed7c057e4e42009ec4dd1d15ee2af7dd128
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308812
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-13 15:03:49 +00:00
Brian Wilkerson a2dbcf7a56 Initial coding style documentation
Change-Id: I1f29d10a0eff99a98e8e79500288f9766fcc9a64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-06-13 01:11:56 +00:00
Konstantin Shcheglov 27e5ab180d Make all AST classes 'sealed', excluding 'AstNode'.
Change-Id: I340d2372ec15c59a64ea63bd267b2952a3adcd9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308520
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-12 21:43:34 +00:00
Konstantin Shcheglov 4c660a8f73 Seal DirectiveUri hierarchy.
Change-Id: I5287e73fa74f3d0d8c34b461a4124b639f469fdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308582
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-12 16:13:18 +00:00
Konstantin Shcheglov ecec8e70cd Remove DeclaredSimpleIdentifier and AstFactoryImpl.
Change-Id: Ifaf4d2c134a4be075afe75c3b8c841644b14da3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308500
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-11 23:51:37 +00:00
Konstantin Shcheglov 5698c12549 Use UriResolution in FileState(s) instead of Either2.
With sealed classes we don't need Either2 anymore.
Specific class hierarchies are better, support more than two variants,
don't require additional classes to nest more than one piece of data,
and being supoorted by the language itself, provide exhaustiveness
checking.

Change-Id: I47c7e770d37fb6246f54bcda3600c2fa04fc1d50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308540
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-11 23:51:27 +00:00
Konstantin Shcheglov 70da08865b Make previosly abstract XyzImpl classes 'sealed', and non-abstract XyzImpl classes 'final'.
Change-Id: Iec06de844e070cff940ca2dc2ea704abda30089d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308501
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-10 22:20:19 +00:00
Konstantin Shcheglov edd17a8638 Merge AST interfaces into implementation library, re-export.
Bug: https://github.com/dart-lang/language/issues/3135
Change-Id: Icbc2a4e506e9e58c830b53f7aecce92189bb2d1b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308402
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-10 16:57:59 +00:00
Konstantin Shcheglov db143df804 Increment AnalysisDriver.DATA_VERSION
This should have been done in
https://dart-review.googlesource.com/c/sdk/+/267340

Change-Id: Ie1e6ea56bbfdd807c2e7097c6c06b898693b2850
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-09 18:05:15 +00:00
Konstantin Shcheglov 028ca9d02f Remove null assert in _contextFor()
Change-Id: Iea684f57eb356b676a620bb08e82a28d1df99022
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307971
Reviewed-by: Janice Collins <jcollins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-08 19:52:30 +00:00
Ludi Zhan 4079a47cc4 [analyzer] Introduce a new annotation @visibleOutsideTemplate
The new annotation is intended to be used on members of class, enum or mixin to opt out the @visibleForTemplate visibility restriction cascaded from class- / enum- / mixin- level.

1. Throw warning if the annotation is added to a invalid target.
2. Update @visibleForTemplate diagnostics logic to opt out members annotated with @visibleOutsideTemplate.

Change-Id: Iec546fc7785cd45f39a1b2a2cc8849ef1cf9d04a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304825
Reviewed-by: Marya Belanger <mbelanger@google.com>
Auto-Submit: Ludi Zhan <ludizhan@google.com>
Commit-Queue: Ludi Zhan <ludizhan@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-08 18:47:15 +00:00
Konstantin Shcheglov f569174ea0 Stop using elementMatcher() method, use textual expectaitons.
Change-Id: I11946d135a4e82e8fcdd382d3c4cc50e6ab1666f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308163
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-08 18:27:14 +00:00
Konstantin Shcheglov 4ff67a7ccb Remove assertMember(), use textual expectations.
Change-Id: I009a17ba1ffecd7614577b73f191a954cb9d3680
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307976
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-08 15:59:07 +00:00
Kallen Tu 3542e86611 [analyzer] Fix CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST not reporting.
Found a bug related to https://dart-review.googlesource.com/c/sdk/+/307182 which
surfaced the fact that we don't handle InvalidConstants in ConstantVerifier._validateFieldInitializers.

Change-Id: If270faa4718f67a930f8ec5ea32f1dd1d8a7e97c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307966
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-07 21:30:34 +00:00
Konstantin Shcheglov 692ef6be03 Add quotedAndCommaSeparatedWithOr and use for TransformSetParser.
Change-Id: Ie599d1e7b24efa137cb342392d278df051fbed33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307666
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-07 17:19:59 +00:00
Konstantin Shcheglov 8e37b41c05 Issue 52624. Report type parameters in NamedType(s) inside constant patterns.
Bug: https://github.com/dart-lang/sdk/issues/52624
Change-Id: Ic779641025fdf9d80b67457a26c704c5481e57ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307663
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-07 17:13:58 +00:00
Konstantin Shcheglov 5cb4093613 Issue 52432. Create DefaultSuperFormalParameterElementImpl for invalid code.
Bug: https://github.com/dart-lang/sdk/issues/52432
Change-Id: I03a1320dce1a56448046bf625ae751cdb8f931af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307670
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-07 01:32:58 +00:00
Kallen Tu bc94e7662b [analyzer] Refactor visitConditionExpression in the const evaluator.
Moved a test from `constant_test.dart` to slowly migrate it over.

Change-Id: Id7d0ef0edcfa4fced056ec8fc937b060a74f4468
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306919
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-06 19:30:19 +00:00
Konstantin Shcheglov 526ce3aba4 Issue 52005. Convert non-exhaustive returning SwitchStatement to SwitchExpression when followed by throw.
Bug: https://github.com/dart-lang/sdk/issues/52005
Change-Id: I16bf21703e4404e805dbc40906be5936e95f102c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307510
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-05 22:44:53 +00:00
Kallen Tu f92c6da7bf [analyzer] Refactor visitAsExpression and visitIsExpression in the constant evaluator.
Changed the signature of `_getConstant` as a smaller change.

Change-Id: Iac258558a32f11030db53edd658371bacbcc5ee6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307182
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-05 20:10:15 +00:00
Konstantin Shcheglov 88f05965ac Issue 52606. Fix AstNodeExtension.nodeCovering() when selection if at the end of Comment.
Bug: https://github.com/dart-lang/sdk/issues/52606
Change-Id: I1cfe427979e82e837d34e5fa45a310474b0a2aa8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307504
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-05 18:39:27 +00:00
Keerti Parthasarathy 56cb8de973 Make ParsedUnitResult and ParsedLibraryResult superclasses of ResolvedUnitResult and ResolvedLibraryResult respectively.
Change-Id: I00a8c07b8487c27c22997523803028fd01b4293a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306909
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-06-05 16:43:24 +00:00
Paul Berry 39de3f2e5b Field promotion: track field accesses via SSA node.
If a user promotes a field and then subsequently changes the variable
used to access it, the promotion must be discarded. For example, in
this code:

    class C {
      int? _i;
    }
    test(C c1, C c2) {
      C c = c1;           // (1)
      if (c._i != null) { // (2)
        print(c._i + 1);  // (3)
        c = c2;           // (4)
        print(c._i + 1);  // (5)
      }
    }

The test at (2) promotes `c._i` to non-null, so (3) is ok. But since
`c` is reassigned at (4), (5) should be a compile-time error.

Previously, flow analysis used one promotion key to track `c` and one
promotion key to track `c._i`. The `PromotionKeyStore` associated each
promotion key with a map containing the promotion keys of all of its
properties. So, for example, if the promotion key for `c` was 10 and
the promotion key for `c._i` was 11, the `PromotionKeyStore` would
associate promotion key 10 with the map `{'_i': 11}`, so that each
time `c._i` was accessed, promotion key 11 would be found. In order to
detect the compile-time error at (5), it had to keep track of the fact
that keys 10 and 11 were related, so that the assignment to `c` at (4)
could invalidate the promotion of `c._i`. It accomplished this by
linking together all the related promotion keys in a circularly linked
list, which it would walk at the time of any variable assignment.

This worked, but it required a lot of complex bookkeeping. Also, it
posed problems for integrating field promotion with cascades, for
example, in the following code:

    class B {
      void f([_]) { ... }
    }
    class C {
      B? _b;
    }
    test(C c1, C c2) {
      C c = c1;           // (6)
      if (c._b != null) { // (7)
        c.._b.f(          // (8)
	    [
              c = c2,     // (9)
	      c._b.f(),   // (10)
	    ])
         .._b.f();        // (11)
      }
    }

The cascaded access `.._b.f` at (8) should be ok, since `c._b` has
been promoted. But since there is an assignment to `c` at (9), the
promotion should not carry over to (10), and an error should be
reported. However, no error should be reported at (11) because the
cascaded access to `.._b.f` at that location is using the old value of
`c` that was captured at the beginning of the cascade, prior to the
assignment. There's no way to achieve this by invalidation alone,
since the code locations at which the promotion is valid ((8) and
(11), but not (10)) aren't even contiguous.

The solution to the problem is to store property promotion keys in
`SsaNode`s used by flow analysis, rather than in the
`PromotionKeyStore`. Since a fresh `SsaNode` is allocated each time a
variable is assigned, this automatically invalidates any previous
property promotions without the need for any extra bookkeeping. So, in
the first example, at (1), an `SsaNode` is allocated and associated
with the promotion key for `c`. At (2), a promotion key is created for
`c._i` and stored in `c`'s `SsaNode`, and the flow model is updated to
indicate that that key has been promoted to non-null. At (3), that
promotion key is reacalled from the `c`'s `SsaNode`, so the promotion
is still in effect. At (4), a fresh `SsaNode` is associated with
`c`. Since that `SsaNode` doesn't contain any promotion keys yet, at
(5), the access to `c._i` causes a fresh promotion key to be
allocated, with no associated promotions. So the invalidation happens
automatically due to the fact that a new `SsaNode` was created.

Flow analysis doesn't yet support cascades, but here's how the second
example is intended to work: as before, at (6), an `SsaNode` is
allocated and associated with the promotion key for `c`. At (7), a
promotion key is created for `c._b` and stored in `c`'s `SsaNode`, and
the flow model is updated to indicate that `c._b` has been promoted to
non-null. At (8), the `SsaNode` for `c` is captured and saved for
later use. At (9), a fresh `SsaNode` is created and associated with
`c`. That fresh `SsaNode` is consulted at (10), so `c._b` is not
promoted at this point. However, at (11), the previously stored
`SsaNode` is used, so the promotion of `._b` still works.

Change-Id: I64519fbcb2368a37aa18adf35cee0ffd290db9b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307140
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-06-04 19:41:54 +00:00
Paul Berry f180b7037c Shared analysis: remove bogus support for late variable patterns.
When I was first developing the shared analysis logic for patterns, I
imagined that ordinary variable declaration statements would
eventually be re-interpreted as pattern variable declarations, where
the pattern was simply a variable pattern. In order to facilitate
this, I added support for late variable patterns, so that a
decalration of a late variable could be interpreted as a pattern
variable declaration where the pattern was a "late variable pattern".

In the final implementation, however, this functionality never got
used, except in flow analysis unit tests. Both the analyzer and the
CFE continue to use their old logic for analyzing ordinary variable
declarations (including late variable declarations), and only invoke
the shared logic when the declaration in question is truly a pattern
variable declaration.

In retrospect I believe this is the right approach; ordinary
(non-patterned) variable declarations are common enough that it makes
sense to have separate logic for analyzing theem; invoking the full
generality of pattern variable declarations would simply waste CPU
cycles.

So this CL removes support for late variable patterns from the shared
implementation; this will make future refactoring of flow analysis
logic easier.

Since the flow analysis unit tests *were* taking advantage of the
shared logic for late variable patterns, I had to add some separate
logic to the tests to replicate the old functionality when analyzing
an ordinary late variable declaration. This new logic is only used in
tests.

Change-Id: If51efab3c63bdc20d1f2772c2d2dd1e3f487bb00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307183
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-06-04 19:40:37 +00:00
Kallen Tu 4f2f3405fb [analyzer] Refactor visitInterpolationExpression in constant evaluator.
Added `_getConstant` to handle the unfortunate `null`s returned by the ConstantVisitor. Refactored other code with this new helper too.

Change-Id: Ic2ce009b78fee151a1a6fa5b2d2621646cbf2c3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306672
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-02 19:55:02 +00:00
Parker Lougheed 25c0ae1c42 Link to dart.dev for linter rules
This allows more flexibility as we can configure the redirect overtime, compared to the GitHub hosted site which we have less control over. It could even redirect to the old linter site in the meantime if desired.

Contributes to https://github.com/dart-lang/linter/issues/4411 and https://github.com/dart-lang/site-www/issues/4498

Change-Id: I3512002cdf7f62c0338d67cec0d7091f1166479d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307000
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-02 18:26:13 +00:00
Jake Macdonald 310baf2737 mark all public interfaces as abstract interface classes
make Code a sealed type, and all subtypes base classes

Change-Id: I328b6a25446dc89e88ae2f1c7e137b969f1b86ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306682
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-06-01 19:30:41 +00:00
Kallen Tu 0d1a9df087 [analyzer] Refactor visitAdjacentStrings and visitStringInterpolation for the constant evaluator.
In doing so, made Constant sealed to use in switches.

We want to avoid passing back null as much as possible, so replacing those with InvalidConstant errors.

Change-Id: I5271c15961679316f7cbee9159150e3c7350926f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306671
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-06-01 16:30:18 +00:00
Paul Berry 709c0e4ccd Flow analysis: combine ExpressionInfo, ReferenceWithType, and EqualityInfo.
Previously, flow analysis used three classes to keep track of
information about expressions that have been visited:

- ExpressionInfo, to keep track of information about expressions whose
  truth or falsity has an effect on flow analysis (such as `== null`
  checks, `is` checks, and combinations thereof those using `&&` and
  `||`), as well as identifying the literal expression `Null`.

- ReferenceWithType, to keep track of information about expressions
  that represent something that can be promoted (references to
  variables and fields), as well as the static type of the expression.

- EqualityInfo, which wrapped ExpressionInfo and ReferenceWithType,
  and also redundantly stored the static type of the expression.

These have now been combined into a single class hierarchy with a base
class called `ExpressionInfo`. This makes the code easier to reason
about, because it is no longer necessary to think about which of the
three above classes is needed in a given situation. Also, it helps
prepare for a follow-up CL in which I plan to refactor how flow
analysis gathers this information; the refactor will be easier with
just a single class hierarchy of information to be gathered.

This required a modest expansion of the API to flow analysis to
include more static types, since previously, static types weren't
needed by the ExpressionInfo class.

Change-Id: Id3de8b19049f8d920ebe85ab58c624ae3e55f226
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304211
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-06-01 15:53:18 +00:00
Konstantin Shcheglov 6879f9586c Issue 52535. Mark imported extensions used in pattern fields as used.
Bug: https://github.com/dart-lang/sdk/issues/52535
Change-Id: If851ad42fad5741dccc3856a55ee0454e949beeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306669
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-31 20:04:25 +00:00
Konstantin Shcheglov e64a6dc87c Issue 52453. Collect constant dependencies for relational patterns.
Bug: https://github.com/dart-lang/sdk/issues/52453
Change-Id: Id0f59659ac7b6b67e4caad97f7c97c3ca1c55ea6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306681
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-31 19:58:22 +00:00
Konstantin Shcheglov 5db76194e9 Cache the whole library result when compute a unit result.
Bug: https://github.com/dart-lang/sdk/issues/47968
Change-Id: I2b20a3931f0374a20151c14c0e99fd5b971553ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306660
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-31 19:29:38 +00:00
Jens Johansen bda10d7987 [analyzer] Cache FeatureSets
This CL caches `FeatureSet`s (really `ExperimentStatus`s) in the
FeatureSetProvider.

When analyzing rwf-materials (562 contexts) with a filled cache I get
these numbers:

Before:
509,901 instances of `ExperimentStatus`.
Current memory: 3.21GB.
Peak memory: 3.24GB.
Heap: 2.61GB of 2.68GB.

After:
2,246 instances of `ExperimentStatus`.
Current memory: 2.80GB
Peak memory: 2.85GB
Heap: 2.21GB of 2.28GB

Difference:
Instances: -99.55%.
Current memory: -12.77%.
Peak memory: -12.03%.
Heap: -15.32% (used); -14.92% (size).
Change-Id: I3901310eed70733f8bd06ad81bf940b848734723
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306460
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-05-31 06:22:19 +00:00
Konstantin Shcheglov b9302286cd Issue 52548. When checking constant pattern matching, union 'T?' bound with Null.
Bug: https://github.com/dart-lang/sdk/issues/52548
Change-Id: I103134c48ea30df95f8e710518b92360b6f13d98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306309
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-30 20:30:14 +00:00
Konstantin Shcheglov b0bd3926a8 Issue 52538. Don't report RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA when no parenthesis.
Bug: https://github.com/dart-lang/sdk/issues/52538
Change-Id: I1f49090c72d51993ec811cfcd93b8a19199dc96f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306306
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-30 19:59:27 +00:00
Kallen Tu 4fa021ced5 [analyzer] Change return type of ConstantVisitor (initial)
Changes the return type of ConstantVisitor and make sure everything works
by unwrapping Constants. Added a bunch of TODOs to slowly go through
in follow up CLs.

Change-Id: I5dbb3f4eb6c72daa1fb649b746c8fdc4fb83dadb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305847
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2023-05-30 18:18:22 +00:00
Konstantin Shcheglov c8c99b5f94 Cache getResolvedLibrary() results for priority libraries.
Bug: https://github.com/dart-lang/sdk/issues/47968
Change-Id: I123e8cea6ed629dd3fc1379e7e3a86ae5685d65e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306302
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-30 17:25:29 +00:00
Paul Berry 76f803a41c Additional test cases in support of record/variable pattern disambiguation.
Two of these tests (`recordPattern_nullable_beforeAs` and
`recordPattern_nullable_beforeWhen`) verify that the fix for #52439
(Destructuring with explicit type of nullable record is a parsing
error), which causes `(...)? identifier` to be recognized as a
variable pattern, doesn't get confused by the pseudo-identifiers `as`
and `when`, and so it continues to correctly parse `(...)? as ...` as a
cast pattern and `(...)? when ...` as a guarded pattern.

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

Bug: https://github.com/dart-lang/sdk/issues/52439
Change-Id: I866e1c7a6a8e47e0cd91a1a77654405f395b50da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305844
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-30 12:48:26 +00:00
Daco Harkes e1ae1b48ae [vm/ffi] dartdev CLI native-assets
This CL introduces native assets suport for `dart run` and introduces
`dart build` which is similar to `dart compile` but outputs a folder
instead to that native assets can be bundled with an executable.

Change-Id: Ib6cfb95539f0adee46c99e531e440928c3f72f2b
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267340
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-05-30 09:10:28 +00:00
Konstantin Shcheglov fbdcfdf2ae Use WithLanguage219Mixin, and language 2.19 instead of 2.18
It is 2.19 that is different from 3.0, and has different features.

Change-Id: I869ac0de76502f0d2b606e0782fee83f66e86283
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306127
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-26 20:32:48 +00:00
Konstantin Shcheglov 3091cefa1f Issue 52514. Fix for UNUSED_IMPORT when extension declares '[]='.
Bug: https://github.com/dart-lang/sdk/issues/52514
Change-Id: I88fcf39440fbb9969d901c5a293d9a1b11aff30b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306123
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 19:14:37 +00:00
Konstantin Shcheglov fc399d16b3 Issue 52528. Report an error for 'const' instance creation with not a constructor of enum.
Bug: https://github.com/dart-lang/sdk/issues/52528
Change-Id: I8123e4c8d6bb2e62278b14c8e8b0cb1ef542ff15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306061
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 18:24:08 +00:00
Konstantin Shcheglov 2077a811f7 Issue 51323. Don't parse RecordLiteral(s) before language 3.0
Bug: https://github.com/dart-lang/sdk/issues/51323
Change-Id: Icd896b0beec5b43775d9d9e04364f086da23cdb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305142
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-26 18:22:34 +00:00
Paul Berry e213846ba0 Patterns parsing: fix record-typed variable patterns before certain tokens.
Previously, if a record-typed variable pattern lacked a `var` or
`final` keyword, and was followed by one of the tokens `||`, `&&`,
`as`, `?`, `!`, `when`, or `=>`, the parser would fail to recognize
it. This happened because the call to `computeVariablePatternType`
wasn't passing `true` for the optional parameter `required`; that in
turn placed `computeType` in a mode where it believed it was parsing a
potentially ambiguous construct in a top-level declaration, and hence
it would only accept the record type if the variable name was followed
by something that looked like part of a correct declaration (e.g. a
comma).

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

Fixes #52521.

Change-Id: If20772ad914827a29df45c27eefb382ec1f470d2
Bug: https://github.com/dart-lang/sdk/issues/52521
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305848
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-26 13:51:31 +00:00
Jens Johansen 54a59072a1 [analyzer] Improve AbstractDartSdk._getPath more
This is the follow-up to
https://dart-review.googlesource.com/c/sdk/+/282280 that I had
forgotten about.

When analyzing rwf-materials (562 contexts) with a filled cache I get
these numbers:

Before this CL (i.e. parent CL):
99671 ms
98499 ms
99678 ms

With this CL:
85764 ms
86204 ms
86548 ms

Difference at 95.0% confidence
        -13110.7 +/- 1256.93
        -13.2054% +/- 1.26601%
        (Student's t, pooled s = 554.547)

Change-Id: Idcde0c9b92eb34467ce69ee7d552f4a8d035286f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305681
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 06:35:01 +00:00
Jens Johansen a3df9a1ed1 [analyzer] Don't do string concat in String.startsWith
When analyzing rwf-materials (562 contexts) with a filled cache I get
these numbers:

Before this CL (i.e. parent CL):
102829 ms
100934 ms
100991 ms

With this CL:
99671 ms
98499 ms
99678 ms

Difference at 95.0% confidence
        -2302 +/- 2041.63
        -2.26609% +/- 2.00979%
        (Student's t, pooled s = 900.749)

Change-Id: I30025b15f7b8c637d83b2cef234c0e7a602535f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305680
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 06:27:47 +00:00
Jens Johansen b5224c5f72 [analyzer] ContextRootImpl.isAnalyzed already have the resource, don't get it again
When analyzing rwf-materials (562 contexts) with a filled cache this
CL removes something like ~1.6 million calls to "isDirectorySync" which -
I think - reads from the filesystem.

On Linux I get this change (on Windows I'm guessing the change is bigger
as the filesystem is often slower):

Before the fix:
111662 ms
112053 ms
112176 ms

With this fix:
102829 ms
100934 ms
100991 ms

Difference at 95.0% confidence
        -10379 +/- 1780.48
        -9.26997% +/- 1.59023%
        (Student's t, pooled s = 785.532)

I.e. it makes it ~10 seconds or ~9% faster.

Change-Id: I42f54b2ff7510365c5a683c993b6b759b35bd152
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305661
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 06:26:58 +00:00
Konstantin Shcheglov 7d138719ec Use OwnedFiles to track which files are owned by which driver.
So, we don't have to recompute it at every symbol search.
For Flutter repository, searching for 'ButtonStyle' is 40% faster.

SHA: 47fe150674
Description: before
  [mean: 56.4][stdDev: 1.471][min: 54.0][max: 61.0]

Description: own files
  [mean: 35.0][stdDev: 1.308][min: 33.0][max: 38.0]
Change-Id: Id497bf4117bdfafeeccd04601fd0198e22624c0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305843
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-26 00:42:12 +00:00
Kallen Tu d48f955121 [analyzer] Add Constant and InvalidConstant to the const evaluator.
Adds an abstract type Constant with two subtypes: DartObjectImpl and
InvalidConstant.
Initial set up for changing the return type in the constant evaluator.

Change-Id: Ia713dee6453937f87d1ae72d3bd240e67d6c13eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305500
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-25 17:15:57 +00:00
Paul Berry 54372b3308 Flow analysis: simplify API for accessing field properties.
Instead of having separate API methods `propertyGet` (for accessing
the properties of an explicit target) and `thisOrSuperPropertyGet`
(for accessing the properties of `this` or `super`), switch to a
single `propertyGet` method. Make the `target` parameter of
`propertyGet` a sealed class (`PropertyTarget`) with three subtypes
representing the three possible kinds of targets:
- `ExpressionPropertyTarget` for an explicit target expression,
- `SuperPropertyTarget` is the target is `super`, and
- `ThisPropertyTarget` if the target is `this`.

Also adjust the API for `promotedPropertyType` to use the new
`PropertyTarget` class for its `target` parameter, rather than a
nullable `target` expression and boolean `isSuperAccess` parameter.

Change-Id: I90535f6d6741776548bc4d60359fd4c40c0fab90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304763
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-05-24 17:50:57 +00:00
Konstantin Shcheglov 305fa3d77c Use names mask to filter libraries when search for symbols.
Before.
SHA: 7501d10e51
Description: check if the library is ready in getLibraryByUri()
  [mean: 43.2][stdDev: 1.350][min: 41.0][max: 47.0]

After.
Description: pre-filter whole libraries using name masks
  [mean: 37.2][stdDev: 1.362][min: 35.0][max: 41.0]

Change-Id: I041ba68c48e3afa8ac528477aa470cbaa770b4cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304830
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-24 17:14:47 +00:00
Konstantin Shcheglov 645587bc70 Issue 52486. Fix LinterContext.resolveNameInScope() in SwitchExpression cases.
Bug: https://github.com/dart-lang/sdk/issues/52486
Change-Id: I7d00ed03f8da37e7adb2959a62acefbd1904770a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305060
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-23 19:19:38 +00:00
Sam Rawlins 6c5836e424 Fix typo in MockSdk
Change-Id: I22373c7f1fe5106423aab3b89d60e54d54550e3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304761
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-22 23:45:34 +00:00
Konstantin Shcheglov d856c6a460 Move FuzzyMatcher to analyzer.
In a future CL I'd like to filter out whole libraries depending
on whether they could have a match. At this point the search, filtering,
and matching become entangled too much to bind them with outside
code in the server. Instead, it all will be the analyzer's concern.

Change-Id: Iefdadbf92046218b3a2607fbeadd37494522112e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304841
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-22 23:10:07 +00:00
pq 9998ad2561 Update hint code doc
Change-Id: I79de29c4b12a04a1419c75678904023392cf44e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304822
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-05-22 21:40:20 +00:00
Konstantin Shcheglov d85aa126e3 Require SDK 3.0.0 for analyzer/.
Change-Id: I9e787930d2101b39808c44d2e7bd537337ac3855
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304286
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-22 20:51:40 +00:00
pq c6720775bb Report replacedBy info for deprecated lints
Fixes https://github.com/dart-lang/sdk/issues/52472


Bug: https://github.com/dart-lang/sdk/issues/52472
Change-Id: I4278a735774cca731d0a3d96cd483eeefc884baf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304800
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-22 20:20:20 +00:00