Commit Graph

14852 Commits

Author SHA1 Message Date
Graciliano Monteiro Passos c2b99d21c1 _IndexAssembler.assemble: optimize using toList(growable: false)
Closes https://github.com/dart-lang/sdk/pull/56544

GitOrigin-RevId: 7b342c4b8c90465b4c858ccfb2ef6ed99d8d9830
Change-Id: Id2d58f23344e525b80dd87112bc3d04a4cfc3c43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381780
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2024-09-25 21:43:16 +00:00
Konstantin Shcheglov 5e5cf385ee Parts. Report AMBIGUOUS_EXPORT in parts.
Change-Id: If900bd4b254c5c89719af61368c9160c2e6ac7ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386684
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-25 21:04:09 +00:00
Konstantin Shcheglov edccc388f5 Elements. Use 'formalParameters' and 'typeParameters' names.
Change-Id: I4540f3f23c7b317e54a59037eab6041794c745bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386606
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-25 16:49:31 +00:00
Chloe Stefantsova f6fe5615c4 [analyzer][cfe] Generate constraints based on type variable bounds
In response to https://github.com/dart-lang/language/issues/3009

Change-Id: I918d392e422f1997736bf2543c8107cb44d3d6f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364721
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2024-09-25 10:59:51 +00:00
Konstantin Shcheglov d4b9bd6c38 Elements. Make 'firstFragment' nullable.
Change-Id: I696f5ede22cdd2ca60e9a057d035cfee7e4b93a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386604
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-24 23:14:38 +00:00
Parker Lougheed 59413a24f8 [analyzer/linter] Mark latest diagnostic docs as published
Change-Id: I60af7f164cc0a92e73e9a05605d11d8b2962b2d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386543
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-24 23:06:39 +00:00
Parker Lougheed 46cd8b627c [linter] Move old lint details out of source
- Makes way for slowly replacing them with new "why" docs.
- Slightly reduces snapshot size of analysis server
- Colocates docs in the new linter/messages.yaml file.

Change-Id: I8708b8b55455a183ccfa5c9d8c21098ae0655b51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385304
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
2024-09-24 23:06:34 +00:00
Konstantin Shcheglov b07eb3b325 Parts. Report PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER in parts.
This also moves the target to be the import prefix, not the declaration.
This is how the specification describes it, and scope lookup works.

Change-Id: Ic0f60a6b57bd8760589b1a91be8885fafb5c90c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386602
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2024-09-24 21:45:12 +00:00
Konstantin Shcheglov e9a7079ee3 Elements. Remove _writeCodeRange(), only fragments have offsets.
Change-Id: Ie0d1467feda42046620e5c24bbed924906696e0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386523
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-24 20:09:59 +00:00
Konstantin Shcheglov 26362db2bc Elements. Make ScopeLookupResultImpl constructor use named formal parameters.
Change-Id: Ib408b88e3adc0917a9af66f6f1c839dbaca135bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386600
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-24 17:37:22 +00:00
Konstantin Shcheglov d063ceb520 Elements. Store 'element2' in NamedTypeImpl, extract 'element' from it.
This is a step toward the state where we eventually want to be.

Change-Id: I8d3062478c08a5aac0992ccccd7848d2c74589de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386400
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-24 15:55:01 +00:00
Konstantin Shcheglov 2fbdc85da0 Elements. Write InterfaceType.element3 where we write elements.
Change-Id: I2a46321d59c83f04f27f67b8335b7f31cddedbe3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386264
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-23 22:14:49 +00:00
Konstantin Shcheglov 8393a6c895 Parts. Simplify MemberDuplicateDefinitionVerifier.
Change-Id: Ife514dcad7d248b39fa6a82c955b9df9facb469f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386263
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-23 21:18:10 +00:00
Konstantin Shcheglov ca996da11e Parts. Support for exports from library fragments in ExportLocation.
Change-Id: I1f489dbbfe96b0d17e6b8bdb1df262d057f8a4b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386362
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-23 21:08:18 +00:00
Konstantin Shcheglov b058a3a080 Elements. Don't write LibraryImport reference, it does not exist.
Change-Id: I420946f08e04248a4f962a218f95c705b7d7ddfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386340
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-23 19:55:08 +00:00
Konstantin Shcheglov 4684ef56dd Element. Don't cache setter name.
Follow up for https://dart-review.googlesource.com/c/sdk/+/381704
I think we  don't need to canonicalize it at all, and pay for map lookup.
If stop doing this, we actually save memory.
My suspicion is that we use setter names transiently.

And removing a field itself save some memory.

Before:
flutter_elements
  reachableObjects
    count: 11865740
      change: -0.01% -1335
    size: 993783127 = 970491 KB = 947.7 MB
      change: -0.01% -72336 = -70 KB


After:
flutter_elements
  reachableObjects
    count: 11861762
      change: -0.04% -5313
    size: 987428847 = 964285 KB = 941.7 MB
      change: -0.65% -6426616 = -6275 KB = -6.1 MB
Change-Id: Iaab513e545862df53ae1f144a7a8b1e695768d06
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386261
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-23 17:26:42 +00:00
Sam Rawlins 076dd1a2c0 Lint rule: prefer_interpolation, consider flattened chains
Fixes https://github.com/dart-lang/linter/issues/3814

This CL ends up solving a few problems, all rooted to one issue: binary
expressions were considered as they live in the syntax tree, but as they
are read by a human, they can be longer chains of additions.

1. We reported `'' + '' + ''` even though adding two string literals is
   considered OK. This is because the outer binary expression has
   `'' + ''` as its left operand, which isn't technically a string
   literal. This over-reporting is corrected.
2. Binary expressions inside string interpolations were not considered.
   This corrects that.
3. We can now report correctly the two issues in code like
   `x + '' + '' + x`.

Change-Id: If2a6fdf11d815d42d732cf2713b9e6dea3932e3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-23 16:40:09 +00:00
Brian Wilkerson 43df149acc Add more hooks to access the new element model
Adds additional members to accept or return elements from the new model
that will be necessary for the migration.

Also overrides `Element.name` in places where the name can't be `null`.

Change-Id: Id933afc423c891bf94c0528a41363f57c883bc66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386100
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-09-23 16:31:01 +00:00
Graciliano Monteiro Passos 3167da82f3 PropertyAccessorElementImpl: optimize name getter to avoid calls to considerCanonicalizeString
Closes https://github.com/dart-lang/sdk/pull/56545

GitOrigin-RevId: edc011b823f19d0cad0315b0264291735a2cc303
Change-Id: I7deb9260add03716c7508de96eb76f3c5e8041b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381704
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-23 16:16:47 +00:00
Konstantin Shcheglov 09e3261127 Elements. Write FormalParameterElementImpl.
Change-Id: Icb61913fe0a195271e507c61e500a3f2be0ec689
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-23 16:05:32 +00:00
Konstantin Shcheglov 6e0f03fd5e Elements. Print new elements for resolved AST.
Change-Id: I629151c61fafea61b4fe8cd1ff94a828d2a99754
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385800
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-19 12:12:28 +00:00
Konstantin Shcheglov d695bd0cbd Elements. Write Element2 as firstFragment#element.
In many cases `element:` property is not very interesting, and we
should replace it with checking cross-linking between elements and
fragments.

I kept `element:` for now as a demonstration.

However there are also useful additions, see: superConstructor: <testLibraryFragment>::@class::A::@constructor::new#element
in class_test.dart

Change-Id: I1ad16ddcf73be6af81da92f1d831d5b165629860
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385362
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-18 13:35:52 +00:00
Brian Wilkerson a6a2c57d68 Add API to AST nodes and session result objects to access the new element APIs
There will undoubtedly be other places where we need hooks, but I thought
that these would provide a good starting point for attempts to start
converting existing code to the new API.

Change-Id: If04aea4244efaca5a81553fbd88066b24c169290
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385303
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-13 23:29:47 +00:00
Konstantin Shcheglov 18bf3f3fd8 Elements. Write 'firstFragment' first, instead of 'reference' for Element2.
Change-Id: I6eadbb86af7060500b2b52f2fe903c9969445a7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385323
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-13 22:51:29 +00:00
Parker Lougheed 4819bd09aa [analyzer/linter] Deprecate LintRule.details to avoid new usages
Change-Id: I3d03d5f06901e0a548020522387e8984507a7f4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-13 18:13:26 +00:00
Konstantin Shcheglov 60b56e8ee7 Elements. Give duplicate fields/variables unique references.
Change-Id: I3265c9e45e444e4788224fbdf48f7329d0a29a81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385082
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-13 16:15:58 +00:00
Brian Wilkerson e17a0fe965 Minor cleanup for some doc comments
Change-Id: I952c7f60c11917ad85cca742041f0b836ce8cd9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385101
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 21:36:38 +00:00
Sam Rawlins b1416116b7 analyzer: rename most API references to 'plugins' to 'legacy plugins'
Change-Id: I56217045ff9d4da8a5a556cd709e0f63a507884f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384964
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 21:25:56 +00:00
Parker Lougheed 3bf33d6e43 [analyzer/linter] Remove unused lint rule description field
Looks like this was added in https://dart-review.googlesource.com/c/sdk/+/255280, but since the longer descriptions are stored in and used from the messages.yaml file, it looks like it's not needed.

Change-Id: I2feb26eeda7c3d76f2567d9e0a894acd25d713ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384825
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2024-09-12 20:46:37 +00:00
Konstantin Shcheglov 35bbfb2314 Parts. Move changes to prepare for removing deprecated 'enclosingElement'.
Change-Id: I79804b8907627e54d993a905c62ffc36e6d348b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384963
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-12 20:33:20 +00:00
Kallen Tu 4e452651c8 [unquoted-imports] Add feature flag for unquoted imports.
Adds a feature flag named 'unquoted-imports' for the unquoted imports feature. We'll hide all the work behind this flag until it's ready for release.

Bug: https://github.com/dart-lang/sdk/issues/56701
Change-Id: I99c0647c74d0da40672d15509178d5234e61ffd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384585
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-09-12 16:51:20 +00:00
Paul Berry a3c696fa58 Properly report unreachable switch cases containing when clauses.
When determining whether a switch statement is exhaustive, it's
important for the exhaustiveness algorithm to ignore cases containing
`when` clauses, since a `when` clause creates the possiblity that the
case won't match.

Previously, the way this was done in the analyzer was for the
`SpaceCreator.createRootSpace` method to create an unknown space for
cases containing `when` clauses. This approach produced the correct
behavior when determining whether the switch statement as a whole was
exhaustive, but since it discarded information about the pattern being
matched, it limited the ability to determine whether an individual
case was reachable, leading to
https://github.com/dart-lang/sdk/issues/56710.

To fix this, `SpaceCreator.createRootSpace` is changed so that it
always produces a space that describes the case pattern, regardless of
whether a `when` clause is present, and instead,
`computeExhaustiveness` is responsible for ensuring that the case is
properly excluded from the determination of whether the switch is
exhaustive. This allows `computeExhaustiveness` to properly computate
whether each individual case is reachable, even for cases that have
`when` clauses.

This change in approach produced some minor differences in the test
cases in `pkg/_fe_analyzer_shared/test/exhaustiveness/data`, but these
differences are not user-observable.

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

Change-Id: I36629a77c4c1832fb1b8abb6ea7b109e0ca14373
Bug: https://github.com/dart-lang/sdk/issues/56710
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384326
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-09-12 16:30:22 +00:00
Konstantin Shcheglov e48d848a5e Parts. Stop writing 'enclosingElement', write 'enclosingElement3' instead.
Preparation for a breaking change CL to remove 'enclosingElement'.

Change-Id: Ifd3cc6dc801a7222748421f0935ce8010db93472
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384862
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-12 16:22:19 +00:00
Erik Ernst 46cff10fc7 Add lint avoid_futureor_void
This CL adds support for a new lint, `avoid_futureor_void`, that reports on every occurrence of the type `FutureOr<void>` in a covariant or invariant position. More details can be found at https://github.com/dart-lang/linter/issues/4622.

Change-Id: I1b86e04921d1fb0b3661be091ea1f4ad72089e8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382403
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 10:49:48 +00:00
Moritz 81daf8e563 Use package:record_use
- Rename resource identifiers in the VM to usage recordings.
- Use package:record_use for serialization.
- Rename and use the experimental flag for this feature.
- Recognize tear-offs and top-level methods as well.

Next steps:

- Add constant instance recording.
- Expose API in package:native_assets_cli's link callback.

TEST=pkg/vm/test/transformations/record_use_test.dart

Change-Id: I8af3625165f78925ae943711245af93a239d1012
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383040
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Moritz Sümmermann <mosum@google.com>
2024-09-12 08:47:53 +00:00
Brian Wilkerson b06e324dd9 Implement local elements
As previously discussed, there are not tests for this code.

Change-Id: I008db0a7bece4538b22b74baf59d0c1d82c8e87d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384920
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-12 04:19:39 +00:00
Konstantin Shcheglov 28b9898433 Parts. Remove remaining 'augment library' uses in analyzer/.
Change-Id: I683dffae2dcc7ad91d856cfa49e12092aea7d143
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384822
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-11 22:58:39 +00:00
Danny Tuppeny 009f3d0868 [analyzer] Fix a bug in TopLevelDeclarations.publiclyExporting matching elements only by name
Previously this was only checking if an element existed in the library with the same name, and not that it was actually the element being searched for.

Change-Id: I2d571f175a17f040352399a3c9777e8606367d00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384781
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-11 19:18:45 +00:00
Brian Wilkerson eaef371b11 Improvements to the implementation of the new element model
This does a couple of things:
- Overrides `Fragment.element` consistently (and removes unnecessary
  casts)
- Adds the `element` for each fragment to the dump
- Implements support for field-formal and super-formal parameters and
  adds constructor parameters to the dump

Change-Id: Ie30806912842e3243e7bdc5e84ec7a11cb623751
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-11 18:24:57 +00:00
Konstantin Shcheglov 1a99ac6474 Parts. More tests for import/export related warnings.
Change-Id: Ia758cc27b05536a9969a6f510755e79b7d18f204
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-10 22:22:49 +00:00
Konstantin Shcheglov ac6f6723cb Parts. Tests for reporting UNNECESSARY_IMPORT in parts.
Change-Id: Ibeff3851f268ad8c46f062a26dddaf0c345b1b6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384584
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-10 21:52:35 +00:00
Konstantin Shcheglov 3316b15693 Parts. Test that DUPLICATE_PART is reported in a part.
Change-Id: I56df076442f3a40de8fa0b6b7521a49ed81229da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384583
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-10 21:36:19 +00:00
Paul Berry 0e2bb2691b Document what command to run after modifying messages.yaml.
Change-Id: I025b82d2add89d3ce50d867a7c617fbb091a1ecd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384563
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2024-09-10 21:36:10 +00:00
Brian Wilkerson 3639b1cafa Implement type aliases and top level function in new element model
Change-Id: I9eca7bc8ddcd8cd16de4d61d71ef6438d80b8ea5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384562
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-10 19:47:51 +00:00
Paul Berry cda2815bb1 Add UNREACHABLE_SWITCH_DEFAULT warning to the analyzer.
This warning is similar to the existing `UNREACHABLE_SWITCH_CASE`
warning, except that it warns if the `default` clause of a switch
statement is unreachable due to all the `case` clasuses fully
exhausting the switched type.

To make the implementation easier, I changed the API for the
`reportExhaustiveness` method in `_fe_analyzer_shared` (which is the
primary entry point to the shared exhaustiveness checker). Previously,
this method returned a list of `ExhaustivenessError`, where each list
element was either an `UnreachableCaseError` (indicating that a
certain case was unreachable) or a `NonExhaustiveError` (indicating
that the entire switch statement was not exhaustive). If the caller
passed in `false` for `computeUnreachable`, `UnreachableCaseError`s
would not be returned, so the returned list would either be empty or
contain a single `NonExhaustiveError`.

The new API renames the types for clarity:

- `NonExhaustiveError` becomes `NonExhaustiveness`, to highlight the
  fact that it's not necessarily an error for the switch's cases to be
  non-exhaustive; it's only an error if the scrutinee's static type is
  an "always exhaustive" type and there is no `default` clause.

- `UnreachableCaseError` becomes `CaseUnreachability`, to highlight
  the fact that it's not an error for a case to be unreachable; it's a
  warning.

Also, the new API adds instances of `CaseUnreachability` to an
optional user-provided list instead of returning a newly created list;
this allows callers to communicate that they don't need to see
`CaseUnreachability` information by passing `null`. This frees up the
return type to simply be an instance of `NonExhaustiveness` (if the
cases are not exhaustive) or `null` (if they are exhaustive). This
makes it easier for the analyzer to decide whether to issue the new
warning, because it doesn't have to dig around the list looking for an
instance of `NonExhaustiveness`.

The new warning has an associated quick fix (remove the unreachable
`default` clause). This quick fix uses the same `RemoveDeadCode` logic
in the analysis server that the existing `UNREACHABLE_SWITCH_CASE`
warning uses.

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

Bug: https://github.com/dart-lang/sdk/issues/54575
Change-Id: I18b6b7c5249d77d28ead7488b4aae4ea65c4b664
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378960
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2024-09-10 19:13:12 +00:00
Konstantin Shcheglov 1c55f6d831 Parts. Clear '_importsTracking' in LibraryFragmentScope.
This hopefully will fix the heap usage jump on Golem.

Change-Id: Id64087a439443549a8306ba0b2897d3adaab7325
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384561
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-10 18:10:21 +00:00
Konstantin Shcheglov 4dba633c0c Parts. Deprecate LibraryElement.accessibleExtensions
Change-Id: I59227d602d69949e49ed523285b5f77493f70299
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-09 22:18:52 +00:00
Konstantin Shcheglov 196751437f Parts. Move the element to imports map to tracking, fix heap usage.
Change-Id: I9debc9fe1633db3ee3c7d6001a4599746672052d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384442
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-09 21:28:39 +00:00
Konstantin Shcheglov 1266f5735b Parts. Tests for UNUSED_IMPORT in parts.
Change-Id: I6816eac501471b3402c824b92a0484c4bceb36f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384304
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-09-09 20:32:38 +00:00
Brian Wilkerson aeb46d93ae Update element writer to not print enclosing element/fragment
As noted in a TODO, I'd like to do the same for the previous/next
fragment chain. Let me know if you think we shouldn't.

Change-Id: I523765b4088e853b745fa5826b431aa4ff56625c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384300
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2024-09-09 17:18:39 +00:00