Commit graph

22967 commits

Author SHA1 Message Date
Nicholas Shahan 154cf8c52b [tests] Cleanup remnants of multi-test migration
- Rename some compile time errors tests to end with "error_test.dart"
- Delete runtime tests that no longer perform the operations they
  claim to be testing. In many cases they do nothing at all.

Change-Id: I49c7b50d6628f56641b878635b32dbc0bc016bbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345345
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2024-01-10 18:35:50 +00:00
Vyacheslav Egorov 3e0ae6da5f [vm] Remove dual mapping of code
We are no longer using Dart VM in a setting where this
matters as a security measure and it just complicates
portability for no benefit.

There is an indication that it is causing problems when
running Linux build of Dart VM under Docker on Mac OS X.

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

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try
Change-Id: I11bdaa8faebaca1df6fd59097049bdaea9cb8e12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344581
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-01-09 12:36:55 +00:00
Nate Biggs ef75007c2f [dart2js] Fix as-check type registration.
We would expect failing as checks to throw in all modes (unless --omit-as-casts is provided). However, the new test program fails in production mode. This is because we are not registering the type usage of the function's type parameter. This leads us to drop the as check completely later on.

We should be doing subtype checks with nullability if we want to consider an as test omitted.

Golem patch results: https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddart2js%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D107840%3BpatchA%3Dnatebiggs--dart2js--Fix-as-check-type-registration.-7%3BtargetB%3Ddart2js%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D107839%3BpatchB%3DNone

Fixed: https://github.com/dart-lang/sdk/issues/54419
Change-Id: If93f78a939a690f05f5398c1a5ca971df1fc9243
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343821
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-01-09 00:04:50 +00:00
Nate Biggs 5229eabddf Update tests to pass in web/production mode.
Change-Id: Ibea6022fcdd0eff53c6be9a5f7c0eeb0fbf20635
CoreLibraryReviewExempt: Updating tests to pass for web production backend.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343822
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-01-08 17:21:29 +00:00
Chloe Stefantsova 04e8677d59 [cfe] Infer mixins by directly solving for equality
The direct algorithm for solving for equality replaces the more
general constraint solving algorithm. It reduces complexity and
removes the requirement on the constraint gathering and solving engine
to be applicable at the earlier stages of compilation.

Change-Id: I73dfa39bb1534803c6985578708ecab198c26e25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343920
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-01-08 11:42:39 +00:00
David Morgan 5cb4351c76 [macros] Fix class definition augmentation test.
Resolve constructors, fields and methods correctly.

Tweaks to test and support code so they're closer to passing.

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

Bug: https://github.com/dart-lang/sdk/issues/54404
Change-Id: I5ccd5e0c3843dc32fb7838a4bc78b65f982f3ce9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343161
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-01-08 08:14:58 +00:00
Stephen Adams 7933cd741d [dart2js] Prevent type expressions being hoisted above guards
Use a pinned HTypeKnown on the receiver of the HInstanceEnvironment to
pin the type expression. When the the receiver has a wider type that
is legal for the type expression, this keeps the type expression at a
location where it is valid. Type expressions can still be hoisted if
the HTypeKnown is redundant and optimized away.

Bug: #54329
Change-Id: Iae378f9d517e3e22deca198195cad9811cf37772
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344841
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-01-05 19:03:29 +00:00
Daco Harkes ce1af47fa9 [vm/ffi] Check Array<T extends AbiSpecificInt> bounds [] and []=
TEST=tests/ffi/inline_array_test.dart

Closes: https://github.com/dart-lang/sdk/issues/54379
Change-Id: I89a637dce0af9520d29d18ec595d868cd0b1604c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345061
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-01-05 12:35:49 +00:00
Daco Harkes cd9eaef675 [vm/ffi] Check Array<T extends Struct> bounds on []
TEST=tests/ffi/inline_array_test.dart

Bug: https://github.com/dart-lang/sdk/issues/54379
Change-Id: I2799056ce48fa8cfa590512b241fe72f61a07dbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345060
Reviewed-by: Tess Strickland <sstrickl@google.com>
2024-01-05 12:35:49 +00:00
Daco Harkes d4f8f24dc8 [vm/ffi] Array fixes
`_checkIndex` was returning dynamic.

And it was missing for `PointerArray`.
Bug: https://github.com/dart-lang/sdk/issues/54379

TEST=tests/ffi/inline_array_test.dart

Change-Id: I148545e50463e89fb3a884757ef92444addefc61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345000
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-01-05 12:35:49 +00:00
Srujan Gaddam 4110b48950 Use asyncTest instead of main async in JS interop tests
The former waits for the test to complete while the latter does
not. Testing this on d8 uncovered two issues which are also
addressed in this CL:

1. async_test has a Promise that is rejected before it is handled.
2. Tests that use Promises don't work correctly on dart2js + d8,
and are therefore skipped for now until the issue is resolved.

Change-Id: I1fac1f4c653bb9ee30ed683d1b0d11bfbf14a58c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343682
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-01-05 00:21:29 +00:00
Konstantin Shcheglov 8898abbc7e Issue 54485. Report error when external constructor has a field formal parameter.
Bug: https://github.com/dart-lang/sdk/issues/54485
Change-Id: Id2cec10b1c8bdb7bba5d608f28a3b55b8f4146ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344180
Reviewed-by: Kallen Tu <kallentu@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-01-03 19:59:53 +00:00
Parker Lougheed f2e2c97600 [dart2wasm] Fix DateTime.timeZoneOffset calculation
This use of JS returns the value with the opposite sign of what it should be (in Dart). This is because Dart uses the difference between local time and UTC, while JS uses the opposite.

Also updates the test for this to also accept the longer style of timezone names as that is what Chrome and d8 on my mac are returning. I'm assuming that's why this wasn't caught earlier.

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

CoreLibraryReviewExempt: Specific to dart2wasm backend
Bug: https://github.com/dart-lang/sdk/issues/54448
Change-Id: I54ab721fa33ef638ccd158d08738ca68273a790b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343520
Reviewed-by: Ömer Ağacan <omersa@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-01-03 08:53:48 +00:00
Srujan Gaddam 4804d54792 [dart:js_interop] Add support for dynamically importing modules
Closes https://github.com/dart-lang/sdk/issues/52852

Allows importing of modules using the JS "import()" expression.
The result is a promise that resolves to a module, from which users
can then access exported members from.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I4c1caae689be55d1dbb038448e3243bcb80ac8b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343683
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-01-03 01:00:19 +00:00
Srujan Gaddam 3f275d858f [dart:js_interop_unsafe] Add has helper
Shorthand of hasProperty for the common case. Reworded some docs
to be less strict about not using this library (since has and
hasProperty have no good alternatives).

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I7e82385fd18ff4fbc83266e9b08c9d854ca62a78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343681
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-01-03 01:00:19 +00:00
Srujan Gaddam 3a80ec26be Reland "[dart2wasm] Disallow use of old interop libraries"
Includes small wording modifications and extra allowlisting for
benchmarks and Flutter engine tests.

This reverts commit c97a17b2349bcbdadd34204a65a9e7c7c13def83.

Change-Id: I2db391782c98c351d744ea7201c9421f13b97979
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343689
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2024-01-02 21:14:50 +00:00
Nate Biggs 2be26a709c [dart2js] Generate parameter stubs during codegen.
Today we make a half-hearted attempt to generate the correct default type arguments for parameter stubs. By the time we create them in the emitter we don't have enough information to fully replace all the type variables that might appear in a type parameter's bound. So instead we erase all type variables to "any".

By generating parameter stubs in SSA we can use existing RTI infrastructure to generate the correct recipes/bindings/evals. Instead of directly creating JS we create the appropriate SSA graph and let the normal function compiler do the heavy lifting.

There are benefits and drawbacks to this new approach:
1) The stub bodies go through the SSA optimizer so some parameters are abbreviated, some recurring nulls get replaced by a variable, etc. The net result is slightly more compact code.
2) We are now compiling code during the emitter phase. This is relatively fast (adds ~2% duration to the phase) but also requires deserializing some data we weren't previously using. This results in ~200MB more memory being used. I've changed the serialization layout a bit to try to mitigate this but some of it is unavoidable.

Change-Id: Ie786da933accc039716e1c8481dbb8a09f3cc9b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340700
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-12-29 07:13:09 +00:00
Nicholas Shahan e95b3ed417 [tests] Delete inert tests from multi-test migration
These tests were created by a script during a mass migration away
from multi-tests. The useful parts of the multi-tests still exist in:
- https://github.com/dart-lang/sdk/blob/main/tests/language/deferred/super_dependency_test.dart
- https://github.com/dart-lang/sdk/blob/main/tests/language/is/not_class2_test.dart

Tests Before migration:
- 07b9df22ac/tests/language_2/deferred_super_dependency_test.dart
- 192579020c/tests/language_2/is_not_class2_test.dart

Change-Id: I41b25d8ecbed340ea85f5fd16ff1412de275d002
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343686
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2023-12-28 17:16:09 +00:00
Srujan Gaddam 5f34ac9fa0 Revert "[dart2wasm] Disallow use of old interop libraries"
This reverts commit 8c246caa91.

Reason for revert: Need to allowlist benchmarks to use package:js.

Original change's description:
> [dart2wasm] Disallow use of old interop libraries
>
> Closes https://github.com/dart-lang/sdk/issues/54004
>
> Adds an error for imports of old interop libraries. Has an
> allowlist for existing usages/migrated usages that we'll need
> to migrate.
>
> Change-Id: Ie7174ae2a50c2d03a7aa2975e8a1914a4cba8a2c
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342521
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: Id7d3a3063d417830774d7a72eed5185599f9267f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343685
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
2023-12-28 16:22:21 +00:00
Nicholas Shahan f860d84ad7 [test] Use Uris in place of Strings in test
Provides consistent behavior for identical and equals across all
backends. The test was failing on JavaScript backends because 
Strings that are equal are also identical.

Change-Id: I85929f37746d8f7e192410e3d2f6530ce05176c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343860
Reviewed-by: Nate Bosch <nbosch@google.com>
Auto-Submit: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2023-12-28 03:19:30 +00:00
Nate Biggs 6a9b550f35 [dart2js] Handle MarkerValue in NegateValue binary operations.
The MarkerValue class was added fairly recently: 404edd9435

Fixed: https://github.com/dart-lang/sdk/issues/54453
Change-Id: Ia0e306d9b42ebba5beae461d8edfcd45f19e1c64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343800
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-28 00:36:22 +00:00
Nicholas Shahan ab9a746f77 [test] Prevent minification of dart2js type names
Allows test to succeed when calling .toString on a type and expecting
a specific string.

Change-Id: Icf50d324c59e7432a6a9af3d722db3e9e3d8545e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343684
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2023-12-27 22:03:19 +00:00
Srujan Gaddam 8c246caa91 [dart2wasm] Disallow use of old interop libraries
Closes https://github.com/dart-lang/sdk/issues/54004

Adds an error for imports of old interop libraries. Has an
allowlist for existing usages/migrated usages that we'll need
to migrate.

Change-Id: Ie7174ae2a50c2d03a7aa2975e8a1914a4cba8a2c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342521
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-27 18:31:37 +00:00
Nate Biggs 7e5ce1f688 [dart2js] Fix scope visitor missing not visiting structural parameter default type.
By not visiting the default type of structural type parameters, the scope visitor was not registering the T type parameter as being potentially needed for RTI. So then the SSA RTI builder did not have the necessary scope info to create the RTI objects for the closures' signatures.

Fixed: 54451
Change-Id: I96f2af985bd176e71a6779fd27b09efdd76fe6cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343660
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-26 21:06:29 +00:00
Srujan Gaddam 4fc73d2d52 [dart:js_interop] Add createJSInteropWrapper
This method is the JS typed replacement of createDartExport. Tests
are duplicated to make sure this method is tested as well. We avoid
exposing a JS typed version of createStaticInteropMock as the
signature would not be compatible with @staticInterop classes, and
due to the low usage (there's only 1 result in google3 and 0 in
GitHub afaict), we should wait until we support interop extension
types in this method before exposing it.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I1a47e86e33563f740e0813d4657c26d555e57508
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342520
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-25 20:02:49 +00:00
Srujan Gaddam 6fbd07f2b0 [dart:js_interop] Reach (mostly) parity with js_util
https://github.com/dart-lang/sdk/issues/54004

In order to reach parity with js_util, we expose operators
through an extension and do some partial renames in order
to make the member names sound better e.g. `equals` instead
of `equal`. We also expose the following from js_util:

- NullRejectionException

We don't expose `isJavaScriptArray` and `isJavaScriptSimpleObject`
as they can expressed through other forms of interop. There
was an esoteric bug where we needed these members for Firefox
in pkg:test, but the package no longer uses these members, so to
avoid increasing the API space too much, we do not export them.

For the same reason, we also don't expose `objectGetPrototypeOf`,
`objectPrototype`, `objectKeys`.

We don't expose `allowInteropCaptureThis` as it will take some
work to handle this in dart2wasm. That work is tracked in
https://github.com/dart-lang/sdk/issues/54381.

Lastly, `instanceof` and `instanceOfString` is moved to be on
`JSAny?`, as this operator is useful to avoid needing to
downcast to `JSObject` e.g. `any.instanceOfString('Window')`
instead of `any.typeofEquals('object') &&
(any as JSObject).instanceOfString('Window')`.

Extensions are reorganized and renamed to handle these changes.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: Ib1a7fabc3fa985ef6638620becccd27eeca68c25
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341140
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-12-25 20:02:49 +00:00
Nicholas Shahan 4bebe882be [ddc] Fix broken named record elements
Some named elements were colliding with existing properties on
record object instances.

Use a symbol in the runtime library for the shape and values
properties.

Ensure that the `.constructor` and `.prototype` getters are renamed
to match the expectation when compiling the access.

Add regression test for all 4 named elements.

Fixes: https://github.com/dart-lang/sdk/issues/54375
Change-Id: I7f3577455bfcff7dece6350e8c7e3ee7ffdbbac6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342703
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2023-12-21 19:23:04 +00:00
Johnni Winther 6f9c9b935b [cfe] Generate throw for unsound switch
Closes #54420

Change-Id: I4d1abe7096ef679021a9ac4b979ed3aa740ba3ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343100
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-12-21 14:17:49 +00:00
Simon Binder 6ce0504924 [vm/ffi] Support native array fields
This lifts the restriction preventing `@Native` fields from having
`Array` types.

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

TEST=tests/ffi/vmspecific_static_checks_native_test.dart
TEST=pkg/analyzer/test/src/diagnostics/ffi_native_test.dart
Cq-Include-Trybots: luci.dart.try:analyzer-mac-release-try
Change-Id: Ic485c86bac9a42ab06097a84a01aba3c481b98e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Marya Belanger <mbelanger@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-12-21 08:47:58 +00:00
Simon Binder a967ead7e9 [vm/ffi] Fix dylib_open_test on macOS
Different versions of macOS seem to be using a different error message,
which the test didn't reflect.

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

TEST=tests/ffi/dylib_open_test.dart
Cq-Include-Trybots: luci.dart.try:vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-linux-release-x64-try,vm-win-release-x64-try
Change-Id: I6e7a20bce9defd1550abbd0e8eb7487b5f833257
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342901
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-12-21 07:38:49 +00:00
Mayank Patke de871364c3 [dart2js, rti] Add missing cases for record types.
Fixes: #54373
Change-Id: I8acd7363d1b712bb702f044dbd7836f58dcbacaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343041
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2023-12-20 23:21:33 +00:00
Daco Harkes ece281d7fa [vm/ffi] Clean up static errors test
The migration to the new test format ended up duplicating
`EmptyStruct` leading to many unrelated errors.

This CL removes all the duplicates. And accepts the current analyzer
and frontend semantics as is.

TEST=tests/ffi/vmspecific_static_checks_test.dart

Change-Id: I4f8ad08a892804d6a6a4335807fde324578e900a
Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,analyzer-win-release-try,front-end-linux-release-x64-try,front-end-nnbd-linux-release-x64-try,front-end-nnbd-mac-release-x64-try,front-end-nnbd-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342900
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-12-20 19:04:58 +00:00
Ömer Sinan Ağacan 1d0a7b28e3 [dart2wasm] Fix while statement context allocation in async functions
When compiling a `while` in an `async` function, we need to allocate the
context for the `while` *before* compiling the `while` condition,
because any variables introduced in `while` condition will be stored in
the `while` context, rather than the parent context.

Instead of fixing where we allocate `while` context, we could update
`CaptureFinder` to add variables in the condition to the parent context,
and update `for` code generator, as it currently allocates `for` context
before the conditions.

I don't know if that has any advantages, for now it should be OK to
update `while` code generator.

`for` code generator allocates the context before the conditions and
does not have this issue.

Fixes #54406.

Change-Id: I3c6bb7558a352d78c8f8a46a56d9bd3af68841a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342760
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-12-20 16:39:59 +00:00
Simon Binder ada6b81761 [vm/ffi] Improve error messages on Windows
Use `FormatMessageA` to allocate an English description of an error code.
Previously, only the error code itself was shown.

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

TEST=tests/ffi/dylib_open_test.dart
Cq-Include-Trybots: luci.dart.try:vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-aot-win-debug-x64c-try,vm-aot-asan-linux-release-x64-try,vm-asan-linux-release-x64-try
Change-Id: Iccae6c763fb16d4bb999b9c260fcfea9c5de276b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328420
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-12-20 13:24:16 +00:00
David Morgan 0a00546277 [macros] Add language tests for macro class augmentation.
R=jakemac@google.com

Change-Id: Ifa13747e2e05bcdc9dcb82a11acf0a043c9e9545
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341483
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2023-12-20 09:27:18 +00:00
Johnni Winther 41d2d8d5a4 [analyzer,cfe] Support contained types in as-pattern
This adds a new rule to exhaustiveness handling of the as-pattern. The
new rule checks whether the cast type is fully contained in the space
of the subpattern. If so, we can assume that the whole context type has
been matched because there is no value that passes the as-test that
would be rejected by the subpattern.

Closes #51986
Closes #54125

Change-Id: I0dc7fb072395aa3bc9f0b143afb320966f9d64c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338760
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-12-20 09:05:26 +00:00
Johnni Winther 8791b441a7 [cfe] Report errors on primary constructors
This adds reporting of errors on initializing formals and
function formal parameters in primary constructors of
extension types. These are not supported by the current grammar.

Change-Id: I9e09ea599b9a455398a20c34b79c375fd884423d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342583
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-12-19 21:13:49 +00:00
Alexander Markov 6b12473f75 [vm] Adjust return value of async/async*/sync* after the language spec change
Calculation of element type for the value returned from
async/async*/sync* functions was recently adjusted
in the spec to address soundness issue
(https://github.com/dart-lang/language/pull/3218).

This change adjusts Dart VM to conform to the new spec.

TEST=language/async/regression_54311_test
TEST=co19/Language/Functions/element_type_*

Fixes https://github.com/dart-lang/sdk/issues/54316
Issue https://github.com/dart-lang/sdk/issues/54311
Issue https://github.com/dart-lang/sdk/issues/54159

Change-Id: I4c51e7cba704d034350519375210bdb2086c5432
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342082
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-12-19 16:14:39 +00:00
Paul Berry 1de6bc74d2 Restore mixed-mode language tests.
This change reverts https://dart-review.googlesource.com/c/sdk/+/341020.

The reverted CL removed tests from `tests/language` that contained
legacy code (code with a language version less than 2.12). The primary
purpose of the removal was to unblock removal of legacy support from
the analyzer. It seemed safe to do because legacy code isn't supported
anymore, and no legacy code exists in google3 anymore. However,
several of those tests exercised important "weak mode" runtime
semantics of the web and VM platforms. See discussion at
https://dart-review.googlesource.com/c/sdk/+/341020/comments/bce31aa1_f5392ce1
for details.

This CL restores the deleted tests. Fortunately, since all the
restored tests are annotated with `Requirements=nnbd-weak`, they will
be skipped on the analyzer (thanks to
https://dart-review.googlesource.com/c/sdk/+/342080), so restoring
them no longer gets in the way of removing legacy support from the
analyzer.

Change-Id: Ib828be76f5c7eaeecaad0b7e7f7b0e3ff2f4bdb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342090
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-19 13:50:18 +00:00
David Morgan 12c548d331 [macros] Add first language tests for introspection.
R=jakemac@google.com

Change-Id: Ic6e081a0a97f23c35b90bc3d935d3c97f4ec5bcd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341963
Reviewed-by: Jake Macdonald <jakemac@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
2023-12-19 09:56:46 +00:00
Paul Berry 6a9216a46f Remove Requirements=nnbd-weak from superinterfaces_out_of_order_error_test.dart.
The annotation `Requirements=nnbd-weak` controls prevents a test from
being run on a platform that doesn't have weak mode runtime semantics
(e.g. a program running with sound null safety).

In a previous CL
(https://dart-review.googlesource.com/c/sdk/+/341020), I removed
several tests from `tests/language` that contained legacy code, in
order to unblock removal of legacy support from the analyzer; those
tests all contained this annotation. However, after discussion with
Siggi, we've decided that it would be better to keep those tests
around for a while longer, because they exercise important runtime
behaviors of unsound null safety mode on the web and VM platforms, and
not all google3 code has been migrated off of unsound null safety mode
yet.

So, I intend to take a different approach to unblocking removal of
legacy support from the analyzer: stop running tests with the
annotation `Requirements=nnbd-weak` through the analyzer. This will
allow the tests removed in
https://dart-review.googlesource.com/c/sdk/+/341020 to be restored,
but it will have a side effect of causing a small number of additional
analyzer tests to be skipped. All those tests are benign to skip on
the analyzer (because they are purely concerned with runtime
semantics) except for one:
`superinterfaces_out_of_order_error_test.dart`.

This test doesn't have any runtime semantics at all; it merely checks
that the analyzer and CFE produce the correct errors for certain
compile-time type checks that have nothing to do with weak mode
runtime semantics.

So, to prevent a gap in test coverage when the analyzer begins
skipping tests annotated with `Requirements=nnbd-weak`, we need to
remove this annotation from
`superinterfaces_out_of_order_error_test.dart`.

Change-Id: I7932a0200be750116c41a303b48aaef50bc952ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341980
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-19 00:08:19 +00:00
James Lin 48ac398f11 Fix Directory.current setter compatibility with IOOverrides
The `Directory.current` setter has a `dynamic` parameter so that it
can accept either `String` or `Directory` arguments. (This is
asymmetric with the getter, which always returns a `Directory`.)

The corresponding `IOOverrides` callback, however, assumes that the
argument is always a `String`, and `Directory.current` passed its
`dynamic` argument through unchanged.  Consequently, overriding
the `Directory.current` setter would result in a `TypeError` when
setting `Directory.current` to a `Directory` object.

Changing `IOOverrides.setCurrentDirectory` to use a `dynamic`
parameter would be a breaking change, so instead make the
`Directory.current` setter check the argument's runtime type before
passing it along.

Bug: https://github.com/dart-lang/sdk/issues/52140
Change-Id: I3c5bba6b442b314c798bd7949dfeb5eb6251dc6e
CoreLibraryReviewExempt: No API changes and VM-only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336604
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: James Lin <jamesdlin@gmail.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2023-12-18 20:23:21 +00:00
Shikhar Soni 81dc3f6f6e [tests/ffi]: Fix failing pointer arithmetic test.
Closes #54397.

R=dacoharkes@google.com

Cq-Include-Trybots: luci.dart.try:vm-aot-asan-linux-release-x64-try,vm-asan-linux-release-x64-try
Change-Id: I4ae2cbc7f4eee1bfcd6d608dbc0d838da703c7e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342460
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
Auto-Submit: Shikhar <shikharish05@gmail.com>
2023-12-18 18:38:05 +00:00
Alexander Markov dcdfcc2b8d Reland "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit 1800039c2a.

The changes fd2e9b9f1a and
c20f9eaf6f are relanded as is.

Reason for revert was fixed separately in
https://dart-review.googlesource.com/c/sdk/+/341621

TEST=ci

CoreLibraryReviewExempt: Implementation change only.
Issue: https://github.com/dart-lang/sdk/issues/54172
Issue: https://github.com/dart-lang/sdk/issues/39692
Change-Id: I1a2324768502e5ffbce328127938c0d3c96c38ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341642
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-12-15 15:25:29 +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
Paul Berry f08dab3b11 Add some test cases to function_type_bounds_test.dart.
Change-Id: Iba7bb2b1e2a1f63a228154be2a9ce23d46da54cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341382
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-12-14 17:33:17 +00:00
Paul Berry d6a47a4a23 Rework inference_update_2 tests using expectStaticType.
Using `expectStaticType` is a more effective test, because it verifies
that the type is _exactly_ what is expected. It also makes the test
easier to read.

Change-Id: I4b0a22f32601a5dca830a182ff4d37cddd657776
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340580
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-12-14 14:00:35 +00:00
Shikhar Soni efb60eac59 [ffi]: Add extension operator methods(+,-) for pointer arithmetic
Closes [#54250](https://github.com/dart-lang/sdk/issues/54250).

TEST=test/ffi

Change-Id: I2299e019b6c0b0db74662e4f9439feac46bc9b40
CoreLibraryReviewExempt: FFI only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341420
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Shikhar <shikharish05@gmail.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-12-14 11:42:38 +00:00
Chloe Stefantsova c6c6c09819 [cfe] Break cycles in cyclic typedefs during the check for it
This CL breaks the dependency cycles in typedefs, allowing the
subsequent phases of compilation to rely on typdefs no longer being cyclic.

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

Change-Id: Id5e2d579c65019ad7072913ccf586ea2a1963ef9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341180
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2023-12-14 10:43:36 +00:00