Commit Graph

9390 Commits

Author SHA1 Message Date
Konstantin Shcheglov 2261250bea Macro. Implement typesOf()
Change-Id: I25a104c58e6c850a233b51e4ab737ee72bfd1063
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342160
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-15 23:06:10 +00:00
Konstantin Shcheglov b848a72837 Macro. Test isExactly() and resolveType() when using RawTypeAnnotationCode.
Change-Id: I42ade6b9c0bce41ee91309c520ea441e95c4dc86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342089
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-15 22:32:35 +00:00
pq a00dc1504e remove TypeSystemImpl.strict{Casts|Inference}
Fixes: https://github.com/dart-lang/sdk/issues/53873

Change-Id: I8cb982c8f6549a604c6815cfebbeede27f56b030
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342102
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-12-15 22:05:47 +00:00
pq 40e5e46a54 migrate strict{Casts,Inference} from typeSystem
Another angle on removing tracking of `strictCasts` and `strictInference` from the type system, this time threading these configuration values individually to the functions that need them. (In contrast to the solution in https://dart-review.googlesource.com/c/sdk/+/341326).

See: https://github.com/dart-lang/sdk/issues/53873.

Change-Id: I63d73fd81401ac03121831af5e8d4ca43200bb7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341336
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-15 19:45:09 +00:00
Konstantin Shcheglov 3d24839907 Macro. Support more elements in resolveIdentifier(), parts.
Change-Id: I88c5b15f826113a21869228f66ac4a1ede7a0415
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342084
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-15 18:55:17 +00:00
Simon Binder 150e61a662 [vm/ffi] Support @Native fields
Allow annotating top-level or static fields with `@Native` to create
fields backed by native memory.
By using the `_addressOf` operator implemented in the VM, these fields
can be implemented in the CFE by replacing them with accessors looking
up the pointer and then using existing methods to load and store the
value.

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

TEST=tests/ffi/native_assets/asset_*_test.dart
TEST=pkg/analyzer/test/src/diagnostics/ffi_native_test.dart

CoreLibraryReviewExempt: VM & dart2wasm only feature
Change-Id: I61dccc88076723d6a6ba02d7fd848b18e4caf780
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338020
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-12-15 11:20:23 +00:00
Johnni Winther 8ca0aa23ea [cfe] Report error on covariant in extension type methods
Closes #53324

Change-Id: Iff86c4eb7c141f27c64de29459390ac395e1c4ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341487
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-12-15 09:13:07 +00:00
Konstantin Shcheglov b305954b60 Macro. Support enums introspection.
Only from nodes for now.

Change-Id: I2fe9419590b78b4cf87d1d30587845c362f6129d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341822
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-15 00:44:49 +00:00
Sam Rawlins aad9e57674 Revert "Revert "[analyzer] new warning for nullable '==' parameter type""
This reverts commit 885457e1d3.

[analyzer] new warning for nullable '==' parameter type

This rule checks that a parameter to an `operator ==` implementation has
a non-nullable type.

I intentionally did not enforce, in this rule, that the parameter is
exactly `Object`. It is legal to narrow the parameter type to a
different non-nullable type, like `int`. I can't imagine doing it, but
it seems to be unrelated to whether the type should be nullable or not.

Fixes https://github.com/dart-lang/linter/issues/3441

Replaces https://github.com/dart-lang/linter/pull/3923

Change-Id: Ic0be2bfebaf59b0336e9a3a58e5b7f5359eb8646
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291042
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-14 23:58:12 +00:00
Konstantin Shcheglov 0696f66e4d Macro. Introspect extensions, extension types, more functions from elements.
Change-Id: Ib9df35d5e03c00ee58be14ba1df4df0b4c315885
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341623
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-14 21:05:16 +00:00
Konstantin Shcheglov 2b0c848cbe Macro. Use the types of formal parameters of the macro constructor for argument types.
Change-Id: I0570832a4b8c842013e87460e24408d15a42310f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341396
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-14 19:42:17 +00:00
Konstantin Shcheglov 55bd60be32 Macro. Find the declaration to introspect by URI and name, when from elements.
This makes the output more compact.

This also allows to introspect declarations that are otherwise hard
to reference, such as functions. I will add more in following CLs.

Change-Id: I4775beca6aac5e642028b05f40aac31b079ba9de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341391
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-14 02:27:26 +00:00
Konstantin Shcheglov 9a452fb98a Macro. Use 'optionalPositionalParameters' for resolveType(), and when build FunctionTypeAnnotationCode.
Change-Id: I4103e95bacc47bd0a97129329a003e0e83393ab5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341333
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-13 17:28:57 +00:00
Konstantin Shcheglov 3e4a2813cc Macro. Support for RecordTypeAnnotationCode.
Change-Id: I9c02b6cb2221e213ef225664ceedbcf78f13bd13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341388
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-13 00:52:18 +00:00
Konstantin Shcheglov 706d105007 Macro. Support for resolving OmittedTypeAnnotationCode.
Change-Id: Ida96aae6e2c2e64c4deb00ad029de64b69a2dccc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341386
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 21:02:00 +00:00
pq f3be94a9ca deprecate singelton analysisOptions getter
Change-Id: I2c1e93ef16862b8f5cbe1fe69fd30947cc0a784a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341323
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-12 19:27:18 +00:00
Konstantin Shcheglov 45944662db Update Blaze language version reference.
From https://critique.corp.google.com/cl/590196257

Change-Id: Ic1e89a9449ac9f16e8064e0d6256a56593934dea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341380
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-12-12 19:08:10 +00:00
Konstantin Shcheglov 4e0260727c Print the package of BasicWorkspace.
So that when we reference it from a file, we have it defined.

Change-Id: I572a4508baab907e26b797ae32ea331a1c4e5036
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341103
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 05:53:00 +00:00
Konstantin Shcheglov 8637cd6010 Simplify usual case of a single included path in AnalysisContextCollectionTest.
Change-Id: Ib618a7104ec3e9cb3d4a83f7d0583c2895ffae2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341162
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 05:43:09 +00:00
Sam Rawlins 9ea048bc89 Do not allow void results in record literals
I also privatize all of the "repor"t methods, so the sort makes for a
big diff.

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

Change-Id: I0e7b2602e27ffe2eeab7688787d38ed039895b15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341163
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 03:44:47 +00:00
Konstantin Shcheglov 89d7197b89 Macro. Distinguish named and named required formal parameters in Code.
Change-Id: I18a9a868371ad783bb780faba2be01819112b6e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341161
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 01:34:48 +00:00
Konstantin Shcheglov d156344a08 Macro. Implement inferOmittedType()
Change-Id: I0e2b3ee2eefb7da99b604d552a7909bca1dc9737
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341102
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-12 00:54:28 +00:00
pq 12598e6b0f deprecate analysis options sdkVersionConstraint getter
Noteworthy:

* deprecates the `sdkVersionConstraint` getter and updates uses
* migrates tests for sdk contstraints in the absence of a pubspec from context_builder_test to analysis_context_collection_test
* makes `pubPackages` getter broadly visible

Next step: remove the code that sets the `sdkVersionConstraint` in the analysis options object and remove the getter.


Change-Id: I443cdd15ec8d28ac6fa6786e06c1e4b027eee747
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341084
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-12-12 00:20:50 +00:00
Daco Harkes 40094c8cfd [vm/ffi] Unwrap typed data in FFI calls
Enables passing inner pointers to typed data in FFI leaf calls.

This works for typed data's in the Dart heap, external typed datas
(constructed from `Pointer.asTypedList`), and typed data views.

Notable implementation details:
1. The Dart signature is used in the Marshaller now. This means it
   needs to keep track of whether there's a pointer argument in the
   signature (`asFunction`) or not (`@Native`).
2. Unwrapping is done in `FfiCallInstr::EmitNativeCode` before moving
   the arguments to their native location. This ensures we can use
   the assembler logic to load the `TypedDataBase::data` field.
3. The `XXXList` user visible classes don't have predefined cids.
   So the implementation uses symbols for comparison.
4. The type checking logic takes `isLeaf` as input to reject typed
   data. This leads to an error message about the type not accepted.
   Alternatively, we could consider adding an error message that
   specifically says the function should be leaf.
5. To cover all calling convention variants, tests are generated with
   up to 20 arguments.

TEST=pkg/analyzer/test/src/diagnostics/ffi_unwrap_typed_data_test.dart
TEST=tests/ffi/unwrap_typeddata_generated_native_test.dart
TEST=tests/ffi/unwrap_typeddata_generated_test.dart
TEST=tests/ffi/vmspecific_static_checks_typeddata_test.dart

Closes: https://github.com/dart-lang/sdk/issues/44589
Change-Id: Ia78f18bf3238d42ac6882929b441f6dc432fcefe
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338620
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-12-12 00:05:02 +00:00
Keerti Parthasarathy 208c99fca3 Revert changes to support multiple packages in PubWorkspace.
The changes caused a regression, caught in https://golem.corp.goog/Revision?repository=dart&revision=107434.

Change-Id: If867769fc9c64765ba967f778e5de10e52a11c42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341081
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-12-11 22:17:19 +00:00
Konstantin Shcheglov 45f2fff8e5 Macro. Add more types to resolveType(), use in isExact().
Change-Id: I7953ee15be8a756fec53ee140df09dad95d9ad65
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341082
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-11 21:46:38 +00:00
Ahmed Ashour d9962e5053 [analyzer] UNNECESSARY_SET_LITERAL to handle multiple expressions
Bug: https://github.com/dart-lang/sdk/issues/50900
Change-Id: Id09e102c2cc12c9043d3f6c22b3af3babf18920e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284021
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Oleh Prypin <oprypin@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Oleh Prypin <oprypin@google.com>
2023-12-11 21:24:59 +00:00
Konstantin Shcheglov 3ab16cf2ce Use FileState to get file properties, include URI to output.
No need to re-discover WorkspacePackage.

Change-Id: I68a343ec1c18d9f13cf8fbc7c7dce967a3acb6f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-11 17:55:24 +00:00
Konstantin Shcheglov 8371eb481f Macro. Introspect top-level functions.
Change-Id: Ida8e7768efb3072870fd32bb48d0905d235ad343
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340740
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-11 17:36:21 +00:00
Konstantin Shcheglov c31dfad2df Macro. Implement StaticType.isExactly()
Partial tests, only interface types, and nullable.
More in future CLs, as resolution into other `StaticType`s implemented.

Change-Id: Ibab214a0a4625ce26c6090f95d056cfd42a25754
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340820
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-11 17:04:38 +00:00
Erik Ernst f9d64593ff Adjust UP to move the intersection type rules up
This CL implements the spec change in https://github.com/dart-lang/language/pull/3435. It changes the implementation of UP in the CFE and in the analyzer such that it matches the updated specification in language PR dart-lang/language#3435.

Change-Id: I2fb56c11e671e6917baffb89f9fb231072d22a0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333922
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2023-12-11 08:31:10 +00:00
Konstantin Shcheglov 9facf4d60f Macro. Run declarations phase also when introspecting fields and constructors.
Use DeclareInType() instead of specialized new macros.

Change-Id: I66764ca956c42477dfb6b89162a2904666d54504
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340642
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-08 22:58:00 +00:00
Konstantin Shcheglov d2e2ff9b4b Macro. Introspection of type methods during declarations phase runs the target type macros.
Change-Id: Ibaccebe04463481b9f1db2fbb68f5e513fa1c6df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340641
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-08 20:59:02 +00:00
Sam Rawlins 9d949a2498 analyzer: Remove pre-NNBD code from strong_mode_test; default to NNBD in ResolutionTest
`isNullSafetyEnabled` is now flipped to true in ResolutionTest, and only
overridden to false in WithoutNullSafetyMixin.

Change-Id: If10a5ba852eada2f719450118683a6d42c1002e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-12-08 18:27:21 +00:00
pq d27b887fec update expectations to include sdk constraints
* Adds sdkConstraints to package string dumps
* Addresses TODO, migrating test to use text-based expectations
* Fixes path issue breaking windows test bots

Change-Id: I7381e18fc6756693a8cf13857d2f467934275f13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2023-12-08 03:58:29 +00:00
Dillon Nys cb38f836a2 Include alias in InterfaceTypeImpl.withNullability()
Follow up on https://github.com/dart-lang/sdk/issues/54260. This is another place where `withNullability` fails to pass the optional `alias` associated with the type.

R=leafp@google.com

Bug: https://github.com/dart-lang/sdk/issues/54277
Change-Id: I8d97a9dad209a608cfcc9a6b53a8abc95ea63352
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340289
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Dillon Nys <dillon.andre.nys@gmail.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2023-12-08 01:06:15 +00:00
Konstantin Shcheglov 8d8e7edaee Tweak AnalysisContextCollectionTest presentation.
Change-Id: Icea421a2606ffe99beaa5e85dfa0a407e3d950e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340305
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-08 00:51:48 +00:00
Paul Berry 004f564f40 Allow "field promotion" to apply to abstract getters.
A quirk of analyzer and CFE implementations is that they resolve
property gets such as `foo.bar` to specific field or getter
declarations that may be not be directly defined on the target type;
for example if `foo` has type `B`, and `B` extends `A`, and `A`
contains a field called `bar`, then `foo.bar` is considered to refer
to `A.bar`, for example:

    class A {
      int? bar;
    }
    class B extends A {}
    f(B foo) {
      print(foo.bar); // Resolved to `A.bar`.
    }

This is in contrast with the language specification, which makes a
clean distinction between class _declarations_ and the _interfaces_
implied by those declarations. While a class declaration can contain
(among other things) both getters and fields, which might be concrete
or abstract, an interface doesn't distinguish between getters and
fields, and is inherently abstract.

The advantage of the analyzer/CFE approach is that it allows more
intuitive error messages and "go to definition" behavior, which
benefits users. But it has some ill-defined corner cases involving
complex class hierarchies, because not every property access can be
resolved to a unique declaration (sometimes a getter is multiply
inherited from multiple interfaces, for example). The language spec
approach has the advantage of being well-defined and consistent even
in situations involving complex class hierarchies.

When I initially implemented field promotion, I took advantage of this
quirk of the analyzer and CFE implementations, so that I could make
property gets that refer to field declarations promotable, while
keeping property gets that refer to abstract getter declarations
non-promotable. This caused unpredictable behaviors in the ill-defined
corner cases. It also meant that in certain rare cases, a property
access might not be promoted even when it would be sound to do so
(e.g. a property access might refer to a private abstract getter
declaration, but the only concrete _implementation_ of that abstract
getter was a final field).

This CL changes the rule for promotability so that any get of a
private property is considered promotable, provided that the
containing library doesn't contain any concrete getters, non-final
fields, or external fields with the same name. It no longer matters
whether the private property refers to a field or a getter. This rule
is simpler than the old rule, restores the spec's clean distinction
between class declarations and interfaces, and allows more promotions
without sacrificing soundness.

For additional details please see the breaking change announcement at
https://github.com/dart-lang/sdk/issues/54056, as well as the original
change proposal at https://github.com/dart-lang/language/issues/3328.

Fixes https://github.com/dart-lang/sdk/issues/54056.
Fixes https://github.com/dart-lang/language/issues/3328.

Change-Id: I38ffcb9ecce8bccb93b1b2586a1222a0fb1005a7
Bug: https://github.com/dart-lang/sdk/issues/54056
Bug: https://github.com/dart-lang/language/issues/3328
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337609
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-12-07 23:40:27 +00:00
Konstantin Shcheglov 9683fd4a50 Macro. Update introspection text after model change.
Oh, accidentally we were just discussing it :-)

Change-Id: If54d17665a9fa5c01834f1410f307301f916be67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-07 21:43:34 +00:00
Konstantin Shcheglov 92bf6a4a9b Issue 54260. Inclide alias in RecordTypeImpl.withNullability()
Bug: https://github.com/dart-lang/sdk/issues/54260
Change-Id: I95c356b09e43f73f168bc2b61e2499d106030d79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340383
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2023-12-07 20:22:37 +00:00
David Morgan eff8c0d946 [macros] Finish and fix ExtensionTypeDeclaration.
Add corresponding `DeclarationKind`, rename `onType` to
`representationType`.

R=jakemac@google.com, scheglov@google.com

Change-Id: I0ce697de6c0b03d4a69a0f55379a0c9d9850233b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340400
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
2023-12-07 15:37:39 +00:00
David Morgan 296a7f642e [macros] Remove Introspectable* types.
Per https://github.com/dart-lang/language/issues/3442 inrospection will
be allowed to succeed if possible, failing if there are cycles.

Change-Id: I341cc4ae87d1399df82cebb1d5c9df7e5070e777
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339620
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2023-12-07 09:44:59 +00:00
Keerti Parthasarathy f3024ea876 Add test in analysis_context_collection_test. If this format looks ok, will add more tests for PubWorkspacePackage.
Change-Id: Ia63b33920fa55269474e1903b20409e867f2d678
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339781
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2023-12-06 22:06:39 +00:00
Konstantin Shcheglov 6e9af1e2f8 Macro. Introspect extension types.
Change-Id: I4de2b755a975471648804c06280e6edeeacd0b50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-06 21:28:23 +00:00
pq a354347178 Add PubWorkspacePackage.sdkVersionConstraint.
See: https://github.com/dart-lang/sdk/issues/54043.

In a follow-up, we'll:

* deprecate `AnalysisOptions.sdkVersionConstraint` and
* update all callers to use `PubWorkspacePackage`

Change-Id: Ie24861d50168de79e6a6db511887aea5148987f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340021
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-06 20:41:13 +00:00
Paul Berry 08405de9c6 Fix parser crash when skipping unmatched begin tokens.
Sometimes when the parser is performing error recovery it skips tokens
until it finds the next `,` or `;`, to try to get back on track. This
is handled by the `Parser.findNextCommaOrSemicolon` method.

When this method encounters a `BeginToken` (i.e., `(`, `[`, `{`, or
`<`), it needs to skip to the matching end token (using the `endToken`
getter), so that it doesn't try to resume parsing inside some nested
structure.

However, sometimes there is no matching end token (either because the
user has failed to properly matched `()`, `[]`, or `{}`, or because
the `BeginToken` is `<`, which doesn't always have a matching `>`). To
avoid a crash when this happens, `Parser.findNextCommaOrSemicolon`
needs to treat an unmatched `BeginToken` like an ordinary token, and
just advance to the next token.

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

Bug: https://github.com/dart-lang/sdk/issues/54236
Change-Id: Id208c7a46c9c00b69f7f460a638d59486ebaffea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339980
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-06 15:01:19 +00:00
Konstantin Shcheglov a0cc7ae0da Macro. Introspec extensions.
Change-Id: Ib3eb3c370ff1d56d24784ea1ce2789b46c7c71ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340066
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-06 04:08:26 +00:00
Konstantin Shcheglov 569f19749c Macro. Use templates for encoding top-level identifier references in add/augment tests.
Change-Id: I30bce9677205bc7514c555e7e9cfface71dbbf6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340062
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-05 21:33:56 +00:00
Konstantin Shcheglov 59946bece7 Macro. Fix for 'add field', 'augment field' sequence, getters, setters.
Change-Id: Ib6c45bd02084d7ebe9ff59b8a1641f9d462a9211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339722
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-12-05 17:57:29 +00:00
Simon Binder a44a524bb0 [vm/ffi]: Add Native.addressOf
This adds the `Native.addressOf` function, which takes a constant tear-
off of a method annotated with `@Native` as a parameter and returns a
pointer to the underlying C function.

The CFE will resolve these calls in two steps: First, the existing
transformer for `@Native` methods adds a pragma describing the fully-
resolved native annotation (with the asset id inferred from the library
if not given explicitly). Then, the FFI use sites transformer rewrites
calls to `Native.addressOf` by searching for this pragma on the passed
function and passing the `Native` constants to `Native._addressOf`. The
latter method is implemented in the VM, which can re-use existing parts
already used for `@Native` calls.
An alternative implementation strategy would have been to forward
`addressOf` calls to `Native.ffi_resolver_function` directly without
any special consideration in the VM. However, the chosen approach makes
it easier to support static linking in the future, as this requires
unresolved symbols in the generated assembly.

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

TEST=pkg/vm/testcases/transformations/ffi/ffinative.dart
TEST=tests/ffi/native_assets/asset_*_test.dart
TEST=tests/ffi/vmspecific_static_checks_ffinative_test.dart
TEST=pkg/analyzer/test/src/diagnostics/ffi_native_test.dart

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-kernel-precomp-linux-release-x64-try
CoreLibraryReviewExempt: VM & dart2wasm only feature
Change-Id: Ic8e3a390146dffd44c95578f975a4472db79a0ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333920
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-05 13:10:36 +00:00