Commit graph

343 commits

Author SHA1 Message Date
Ömer Sinan Ağacan 1d8dde36e1 [dart2wasm] Add array.copy instruction and intrinsics
`array.copy` is used in [1] in `setRange` when source and destinations
are both typed arrays with the same Wasm array type.

[1]: https://dart-review.googlesource.com/c/sdk/+/312907

Change-Id: Iaeecea43c22805eca64b7d98751a52e607210a70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314080
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-07-17 16:51:25 +00:00
Joshua Litt 465d35fac9 [dart2wasm|js] Add support for JS backed subtypes of 64 bit typed data.
Change-Id: I534e946ffdfa6708af0c0ffdecb345adbc9561aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313286
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-07-13 15:29:37 +00:00
Joshua Litt 50c810e12c [js|dart2wasm] Add JS backed subtypes of Dart typed array classes.
Change-Id: I19a6d47bf857969abe2205e6b505b3a1dead5e3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310480
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-07-10 18:11:02 +00:00
Liam Appelbe 13ec07415b [vm] Async FFI callbacks
More details about the design:
https://docs.google.com/document/d/1QDjyY_6wOTOgURwpeYMKU9qEz0gKxx2MUrdruC6Kp6c/edit?usp=sharing

Change-Id: Ie3985d86dca7f5010044ca46c33ca177588c0f69
Bug: #37022
CoreLibraryReviewExempt: Reviewed by vm and api groups. web and wasm groups not affected because FFI isn't on those platforms.
TEST=async_void_function_callbacks_test.dart, ffi_callback_metadata_test.cc, other front end tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305900
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-28 01:00:18 +00:00
Devon Carew 9216f830c6 [deps] rev package:lints to the latest; address lints
Change-Id: I64032a39c589c291297decade18f6a46c08f9c5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310966
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-27 17:03:37 +00:00
Ömer Sinan Ağacan f041dd4af4 [dart2wasm] Simplify a list intrinsic
Change-Id: I769d33ac838a09350427dcdc14e3c2a6daf37cc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311381
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-27 14:50:00 +00:00
Joshua Litt 64290e1052 [js] Add JSStringImpl box for JSString.
Change-Id: I63a2ecdf3fd2331f91632ae5b2cc51813cd44c66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307961
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-26 17:15:24 +00:00
Srujan Gaddam e985d991b1 [dart:js_interop] Fix JSNumber conversions/semantics and JSBoxedDartObject
- Adds toDartInt and toDartDouble to JSNumber
- Changes semantics of int on external functions from truncate to
assert integer value
- Adds tests for number semantics
- Renames JSExportedDartObject -> JSBoxedDartObject to avoid confusion
with @JSExport
- Adds Object.toJSBox

JSNumber.toDart and Object.toJS will be removed in a future CL once
migrations are complete.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I8ff26ee5624c52703e49dd8483f62e829cb6fff0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309081
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-06-22 02:51:13 +00:00
Aske Simon Christensen 5838562040 [dart2wasm] Add option and target for stringref.
This adds basic infrastructure for a stringref implementation in
dart2wasm:

- A `--[no-]stringref` option to the compiler
- An option in the `WasmTarget`, controlling the name of the target
- Separate sets of patch files for the two targets
- Separate platform dill files for the two targets

For now, the patch file contents are the same, and the compiler flag
is not used by the backend (only by the `dart2wasm` script to select
the appropriate platform dill file). Both of these will change as the
implementation progresses.

Tested: ci + manual check that the option selects the correct dill
Change-Id: I2c9bb95ba06fd3de3f7007703ef545e3f0c728ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310621
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-06-21 14:25:38 +00:00
Ömer Sinan Ağacan 87a3de41b1 [dart2wasm] Implement micro-task scheduling
Use JS `setTimeout` for events and `queueMicrotask` for micro-tasks.

dart2js event loop implementation is copied in `run_wasm.js` to be able
to use `clearTimeout`, `setInterval`, `clearInterval`, and
`scheduleMicrotask`, which are not not available in d8, and `setTimeout`
in d8 does not wait before calling a callback.

New passing d8 tests:

- co19/LibTest/async/Future/Future.delayed_A01_t02
- co19/LibTest/async/Stream/Stream.periodic_A01_t01
- co19/LibTest/async/Stream/Stream.periodic_all_t01
- co19/LibTest/async/Stream/Stream.periodic_all_t02
- co19/LibTest/async/Stream/timeout_A04_t01
- co19/LibTest/async/StreamController/stream_all_A01_t01
- co19/LibTest/async/StreamController/stream_all_A01_t02
- co19/LibTest/async/StreamController/stream_all_A02_t01
- co19/LibTest/async/StreamController/stream_all_A02_t02
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t01
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t02
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t01
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t02
- co19/LibTest/async/Timer/Timer.periodic_A01_t01
- co19/LibTest/async/Timer/Timer_A01_t01
- co19/LibTest/core/Stopwatch/elapsedTicks_A01_t01
- language/async/call_test
- language/regress/regress21795_test
- lib/async/multiple_timer_test
- lib/async/periodic_timer2_test
- lib/async/periodic_timer3_test
- lib/async/periodic_timer4_test
- lib/async/schedule_microtask3_test
- lib/async/schedule_microtask_test
- lib/async/stream_timeout_test
- lib/async/timer_isActive_test
- lib/async/timer_repeat_test
- lib/async/timer_test

New passing Chrome tests:

- co19/LibTest/async/Stream/timeout_A04_t01
- language/async/call_test
- lib/async/schedule_microtask3_test

Tests below fail because of async* desugaring issues and will be fixed
separately:

- language/async_star/no_cancel2_test
- language/async_star/no_cancel_test

Tests below fail because of an existing issue (#29615):

- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03
- co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03
- co19/LibTest/async/StreamController/stream_all_A02_t03

Fixes #51599.

Change-Id: Ib313e99bf3b3cb3bebeddc9e47dc77425ef94481
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305201
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-19 10:21:35 +00:00
Srujan Gaddam 8f48ac3723 [dart:js_interop] Allow interop inline classes to elide @JS
Determines the ultimate representation type of an inline class to
determine if it can use external members. This allows users to
elide @JS if they don't need renaming. This CL adds some static
errors around inline interop members so its clearer that the
inline class should have an interop representation type.

There's a bit of cleanup in this CL too around interop members,
where extension members on @Native classes are now correctly
considered as interop members by the error checker.

Change-Id: I4d870d204933ea11b347ab5bb2e3de1b962f5ea3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308249
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-13 23:27:23 +00:00
Ömer Sinan Ağacan b123b29335 [dart2wasm] Fix continue compilation in switch in async code generator
`continue` in `switch` statements need to be compiled the same way as
normal `continue`/`break` to run finalizers between the jump target and
the `continue`.

New passing test: co19/Language/Statements/Continue/async_loops_t10

Change-Id: I0cdff74b8b296691c8a90404b424487b00343427
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307780
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-08 17:12:51 +00:00
Ömer Sinan Ağacan e8f370ca4e [dart2wasm] Implement noSuchMethod on null receivers
New passing tests:

- language/closure/tearoff_dynamic_test
- language/no_such_method/native_test

Change-Id: I42449f3e238ab5ecd02504d65ff1a696a76bb7a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307800
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-08 08:44:36 +00:00
Ömer Sinan Ağacan 8144a29966 [dart2wasm] Fix initializing exception variables
Currently setting exception variables in `catch` blocks assumes that the
variables are not captured and always creates a new local for the
variable.

This CL adds a new function for initializing a variables. The
implementation is similar to `VariableDeclration` visitor and handles
captured (updated or not updated) and non-captured variables. This
function is then used in `catch` blocks to initialize exception and
stack trace variables.

New passing tests:

- co19/LibTest/async/Zone/handleUncaughtError_A01_t04
- lib/async/future_test

Fixes #52556.

Change-Id: I428d8f30ab1509b5b4439f8136190134741dd4ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307042
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-06-07 09:34:17 +00:00
Srujan Gaddam 5b3a57908d [dart:js_interop] Remove ObjectLiteral
This annotation is unneeded as named arg external constructors
is enough to determine if an object literal is created. The one
exception is an empty object literal, but our guidance is to use
utility functions to create one instead. This is a better fit for
that purpose too as an interface for an empty object literal is
more uncommon.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I10cf891601b28ff7e56129842d099ea28863626d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307506
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-06-06 20:50:36 +00:00
Ömer Sinan Ağacan 877fe38f0c [dart2wasm] Fix runtime type tests
This was originally implemented in a289c4d but then reverted in dc33261
as it broke Flutter: https://github.com/flutter/flutter/issues/124282.

The problematic code in Flutter was updated, so landing the fix again.

Original commit message:

`emitTypeTest` optimizes a test like `x is List<T>` where `x :
Iterable<T>`, i.e. tested-against type is a subtype of the operand's
static type. In these cases we can check just the class ID of the
operand without checking the type arguments.

However this optimization cannot be done when the types don't have same
number of type arguments. Example:

    class H1<T> {}

    bool test(Object o) {
      return o is H1<num>;
    }

    void main() {
      print(test(H1<Object>()));
    }

Here `H1<num> <: Object`, but we still need to check the type parameter.

This CL checks that the types have the same number of type arguments
before optimizing the test.

Fixes #51187.

This fix reveals another bug in `static_interop_test`, which is tracked
in #51200. The test is updated to work around the bug for now.

New passing tests:

- co19/LanguageFeatures/Patterns/matching_cast_A01_t01
- co19/LanguageFeatures/Patterns/matching_list_A01_t01
- co19/LanguageFeatures/Patterns/matching_list_A01_t02
- co19/LanguageFeatures/Patterns/matching_list_A01_t03
- co19/LanguageFeatures/Patterns/matching_map_A01_t01
- co19/LanguageFeatures/Patterns/matching_map_A01_t02
- co19/LanguageFeatures/Patterns/matching_object_A01_t01
- co19/LanguageFeatures/Patterns/matching_object_A01_t02
- co19/LanguageFeatures/Patterns/record_A01_t03
- co19/LanguageFeatures/Patterns/record_A01_t06
- co19/LanguageFeatures/Patterns/record_A01_t07
- co19/LanguageFeatures/Patterns/record_A01_t08
- co19/LanguageFeatures/Patterns/record_A01_t09
- language/generic/deep_test
- language/generic_methods/type_expression_test
- language/patterns/object_pattern_inference_test

Change-Id: Ia08ef466f74c3c55a61d4dbf0088e4b43713ee1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307046
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-06-02 16:20:31 +00:00
Johnni Winther 5476e3bd6e [kernel] Rename InterfaceType.className to classReference
+ Name.libraryName -> libraryReference

Change-Id: I25b5022ea87f92fb5837f03d29f1671f0e68261b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304740
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-06-01 06:43:46 +00:00
Ömer Sinan Ağacan 0f49f23be4 [dart2wasm] Add support for testing in Chrome
d8 doesn't have some of the JS and HTML functions we need for event and
micro-task scheduling. In [1] we add mock functions to allow running in
d8, but that means the mock event loop can run differently than the
actual Chrome event loop, so we need to test in Chrome. This CL adds
support for this.

[1]: https://dart-review.googlesource.com/c/sdk/+/305201

New failing tests with the new configuration:

language/nnbd/static_errors/unchecked_use_of_nullable_test/30 broke (RuntimeError -> Pass, expected RuntimeError)
language/regress/regress24935_test/01 broke (RuntimeError -> Pass, expected RuntimeError)
language/unsorted/flatten_test/01 broke (RuntimeError -> Pass, expected RuntimeError)
language/unsorted/flatten_test/05 broke (RuntimeError -> Pass, expected RuntimeError)
language/unsorted/flatten_test/09 broke (RuntimeError -> Pass, expected RuntimeError)
lib/js/export/static_interop_mock/proto_test is new and failed (CompileTimeError, expected Pass)
lib/js/static_interop_test/constants_test is new and failed (CompileTimeError, expected Pass)
lib/js/static_interop_test/futurevaluetype_test is new and failed (CompileTimeError, expected Pass)
lib/js/static_interop_test/supertype_transform_test is new and failed (CompileTimeError, expected Pass)

New passing tests with the new configuration:

co19/Language/Expressions/Function_Invocation/async_generator_invokation_t10 was fixed (Fail -> Pass)
co19/Language/Libraries_and_Scripts/Scripts/top_level_main_t01 was fixed (RuntimeError -> Pass)
co19/Language/Libraries_and_Scripts/Scripts/top_level_main_t06 was fixed (RuntimeError -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A01_t07 was fixed (RuntimeError -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t03 was fixed (Fail -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t07 was fixed (Fail -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t08 was fixed (RuntimeError -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t09 was fixed (RuntimeError -> Pass)
co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A03_t11 was fixed (Fail -> Pass)
co19/LibTest/async/Future/Future.delayed_A01_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Stream/Stream.periodic_A01_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Stream/Stream.periodic_all_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Stream/Stream.periodic_all_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Stream/Stream.periodic_all_t03 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A01_t03 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/StreamController.broadcast_Stream_all_A02_t03 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/stream_all_A01_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/stream_all_A01_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/stream_all_A02_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/stream_all_A02_t02 was fixed (RuntimeError -> Pass)
co19/LibTest/async/StreamController/stream_all_A02_t03 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Timer/Timer.periodic_A01_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/async/Timer/Timer_A01_t01 was fixed (RuntimeError -> Pass)
co19/LibTest/core/Stopwatch/elapsedTicks_A01_t01 was fixed (RuntimeError -> Pass)
corelib/throw_half_surrogate_pair_test/01 was fixed (NonUtf8Output -> RuntimeError)
corelib/throw_half_surrogate_pair_test/02 was fixed (NonUtf8Output -> RuntimeError)
language/async/return_throw_test was fixed (RuntimeError -> Pass)
language/async_star/async_star_await_for_test was fixed (RuntimeError -> Pass)
language/async_star/async_star_test was fixed (RuntimeError -> Pass)
language/async_star/yield_test was fixed (Fail -> Pass)
language/async_star/yieldstar_test was fixed (Fail -> Pass)
language/import/conditional_string_test is new and succeeded (Pass)
language/regress/regress21795_test was fixed (RuntimeError -> Pass)
language/regress/regress23244_test was fixed (RuntimeError -> Pass)
lib/async/multiple_timer_test was fixed (RuntimeError -> Pass)
lib/async/periodic_timer2_test was fixed (RuntimeError -> Pass)
lib/async/periodic_timer3_test was fixed (RuntimeError -> Pass)
lib/async/periodic_timer4_test was fixed (RuntimeError -> Pass)
lib/async/schedule_microtask_test was fixed (RuntimeError -> Pass)
lib/async/slow_consumer2_test succeeded again (Pass -> skipped)
lib/async/stream_timeout_test was fixed (RuntimeError -> skipped)
lib/async/timer_isActive_test was fixed (RuntimeError -> Pass)
lib/async/timer_repeat_test was fixed (RuntimeError -> Pass)
lib/async/timer_test was fixed (RuntimeError -> Pass)

Change-Id: I2c2f837b4a6093a1a9aad357df21a04a6907ab6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305941
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-31 18:06:55 +00:00
Jackson Gardner 4a01368935 Add a flag to ConstConditionalSimplifier for removing asserts.
Change-Id: Ica31e595436181f013565516339ca1b97f6d5303
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306305
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
2023-05-30 21:39:58 +00:00
Ömer Sinan Ağacan 0358d35db0 [dart2wasm] Fix completer type in async functions when the return type is FutureOr
New passing test: language/await/await_test

Change-Id: I44ac5a8d100e6b299cb9ebdc825e1e0562e15ba7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304920
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-24 08:49:29 +00:00
Ömer Sinan Ağacan c7dcbff358 [dart2wasm] Fix a bug in async* desugaring
The desugared code uses `Completer<bool>` values to suspend the `async*`
function, but we can't use a type test and to check if a value is the
`Completer<bool>` value for the suspension or a user-emitted value as
the `async*` function can also yield `Completer<bool>` values. Update
the test from `value is Completer<bool>` to `!isEven`.

Change-Id: I74f54b838e6a2aab942154ec7f3e667e291523e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304880
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-23 21:24:16 +00:00
Srujan Gaddam 0d20f408d7 [pkg:_js_interop_checks] Refactor js_interop_checks
Does the following refactoring:

- Pares down visitor functions and moves larger blocks of logic into
helper functions
- Adds local functions for reporting to reduce the size of code that
reports diagnostics (all the 'report' functions)
- Organizes helper functions based on node type
- Adds static const variables for literals
- Marks variables that can be final as final
- Fixes/adds documentation for helper functions

There are some possible additional cleanups, like moving helper
functions to extensions and separating out state to mixins, but that
isn't necessary for now.

Change-Id: Ieebc1614aa427308d4aa4ef22c7577b05f4f4b4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302900
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-05-23 16:05:08 +00:00
Ömer Sinan Ağacan 9d1dd89768 [dart2wasm] Handle exceptions and returns in async* functions
New passing tests:

- co19/Language/Expressions/Function_Invocation/async_cleanup_t07
- co19/Language/Expressions/Function_Invocation/async_cleanup_t08
- co19/Language/Expressions/Function_Invocation/async_generator_invokation_t05
- co19/Language/Expressions/Function_Invocation/async_generator_invokation_t09
- co19/Language/Statements/Rethrow/execution_t04
- co19/Language/Statements/Return/syntax_t10
- co19/Language/Statements/Return/syntax_t11
- co19/Language/Statements/Return/syntax_t12
- co19/Language/Statements/Return/syntax_t13
- co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_A01_t01
- language/async/return_types_runtime_test
- language/async_star/basic_test
- language/async_star/yield_statement_context_test
- lib/async/stream_from_iterable_test

Change-Id: Id03cc0abe150dadfcd753c4e74a282d46260a1f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304501
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-22 20:31:38 +00:00
Ömer Sinan Ağacan c74387a3a2 [dart2wasm] New async implementation
This CL re-implements the async function compilation without using JSPI
or any other platform features.

This implementation is faster than the JSPI-based one in all benchmarks,
in some cases up to 200x (benchmark results at the end). So we remove
the JSPI-based implementation as there's no point in maintaining a much
slower implementation and supporting two implementations at the same
time (which is tricky because these implementations need different
libraries, all scripts need to support two modes etc.) that also
requires experimental platform features.

# Main changes

- A new pass `AwaitTransformer` transforms `await` expressions to
  top-level statements in form `var <fresh variable> = await <simple
  expr>`, where `<simple expr>` is an expression without `await`.

  After this pass all `await` expressions have the simple continuation
  of "assign the value of the awaited future to this variable and
  continue with the next statement". This simplifies `await`
  compilation.

- A new code generator `AsyncCodeGenerator` (inherits from
  `CodeGenerator`) compiles `async` functions. The `_YieldFinder` class
  is copied from `sync*` code generator but modified to handle `async`
  expressions.

- Mentions to the V8 flag `--experimental-wasm-stack-switching` is
  removed from all scripts and documents.

# Future work

- Control flow handling in `AsyncCodeGenerator` needs to be implemented
  in a similar way in `SyncStarCodeGenerator`. Doing this without
  duplicating a lot of code will require some refactoring.

# New passing tests

- co19/Language/Statements/Yield_and_Yield_Each/Yield/execution_async_A05_t01
- co19/Language/Statements/For/Asynchronous_For_in/execution_A02_t02
- language/regress/regress23996_test
- language/sync_star/dcall_type_test

# Benchmarks

Current implementation:

```
AsyncLiveVars.LiveObj1(RunTime): 1586000.0 us.
AsyncLiveVars.LiveObj2(RunTime): 2114000.0 us.
AsyncLiveVars.LiveObj4(RunTime): 1972500.0 us.
AsyncLiveVars.LiveObj8(RunTime): 2212000.0 us.
AsyncLiveVars.LiveObj16(RunTime): 2238000.0 us.
AsyncLiveVars.LiveInt1(RunTime): 2362000.0 us.
AsyncLiveVars.LiveInt4(RunTime): 2470000.0 us.
AsyncLiveVars.LiveObj2Int2(RunTime): 2575000.0 us.
AsyncLiveVars.LiveObj4Int4(RunTime): 2820000.0 us.
Calls.AwaitAsyncCall(RunTimeRaw): 35676.15658362989 ns.
Calls.AwaitAsyncCallClosureTargetPolymorphic(RunTimeRaw): 38934.108527131786 ns.
Calls.AwaitAsyncCallInstanceTargetPolymorphic(RunTimeRaw): 42617.02127659575 ns.
Calls.AwaitFutureCall(RunTimeRaw): 2832.058906825262 ns.
Calls.AwaitFutureCallClosureTargetPolymorphic(RunTimeRaw): 3665.8125915080527 ns.
Calls.AwaitFutureCallInstanceTargetPolymorphic(RunTimeRaw): 4420.449537241076 ns.
Calls.AwaitFutureOrCall(RunTimeRaw): 3692.7621861152143 ns.
Calls.AwaitFutureOrCallClosureTargetPolymorphic(RunTimeRaw): 4625.346901017576 ns.
Calls.AwaitFutureOrCallInstanceTargetPolymorphic(RunTimeRaw): 4514.6726862302485 ns.
Calls.AwaitFutureOrCallInstanceTargetPolymorphicManyAwaits(RunTimeRaw): 345172.4137931034 ns.
Calls.AwaitForAsyncStarStreamPolymorphic(RunTimeRaw): 697000.0 ns.
Calls.AwaitForAsyncStarStreamPolymorphicManyYields(RunTimeRaw): 704666.6666666666 ns.
Calls.AwaitForManualStreamPolymorphic(RunTimeRaw): 11010.989010989011 ns.
Calls.SyncCall(RunTimeRaw): 0.40275240996973316 ns.
Calls.SyncCallClosureTarget(RunTimeRaw): 0.3989591156672242 ns.
Calls.SyncCallInstanceTargetPolymorphic(RunTimeRaw): 3.2632549336335526 ns.
Calls.IterableSyncStarIterablePolymorphic(RunTimeRaw): 353.3980582524272 ns.
Calls.IterableManualIterablePolymorphic(RunTimeRaw): 332.1161825726141 ns.
Calls.IterableManualIterablePolymorphicManyYields(RunTimeRaw): 354.28067078552516 ns.
```

New implementation:

```
AsyncLiveVars.LiveObj1(RunTime): 11327.683615819209 us.
AsyncLiveVars.LiveObj2(RunTime): 10923.91304347826 us.
AsyncLiveVars.LiveObj4(RunTime): 10956.284153005465 us.
AsyncLiveVars.LiveObj8(RunTime): 11286.516853932584 us.
AsyncLiveVars.LiveObj16(RunTime): 11445.714285714286 us.
AsyncLiveVars.LiveInt1(RunTime): 11016.483516483517 us.
AsyncLiveVars.LiveInt4(RunTime): 11327.683615819209 us.
AsyncLiveVars.LiveObj2Int2(RunTime): 10918.478260869566 us.
AsyncLiveVars.LiveObj4Int4(RunTime): 10737.967914438503 us.
Calls.AwaitAsyncCall(RunTimeRaw): 1082.2510822510822 ns.
Calls.AwaitAsyncCallClosureTargetPolymorphic(RunTimeRaw): 1056.4124234100993 ns.
Calls.AwaitAsyncCallInstanceTargetPolymorphic(RunTimeRaw): 1134.1726210729273 ns.
Calls.AwaitFutureCall(RunTimeRaw): 865.6509695290858 ns.
Calls.AwaitFutureCallClosureTargetPolymorphic(RunTimeRaw): 841.3967185527977 ns.
Calls.AwaitFutureCallInstanceTargetPolymorphic(RunTimeRaw): 839.066957543212 ns.
Calls.AwaitFutureOrCall(RunTimeRaw): 397.9941096871766 ns.
Calls.AwaitFutureOrCallClosureTargetPolymorphic(RunTimeRaw): 406.17384240454913 ns.
Calls.AwaitFutureOrCallInstanceTargetPolymorphic(RunTimeRaw): 393.7472929873607 ns.
Calls.AwaitFutureOrCallInstanceTargetPolymorphicManyAwaits(RunTimeRaw): 1095.0503723171266 ns.
Calls.AwaitForAsyncStarStreamPolymorphic(RunTimeRaw): 6643.426294820717 ns.
Calls.AwaitForAsyncStarStreamPolymorphicManyYields(RunTimeRaw): 7178.750897343863 ns.
Calls.AwaitForManualStreamPolymorphic(RunTimeRaw): 1456.23998835008 ns.
Calls.SyncCall(RunTimeRaw): 0.3919935321067202 ns.
Calls.SyncCallClosureTarget(RunTimeRaw): 0.3906669661780074 ns.
Calls.SyncCallInstanceTargetPolymorphic(RunTimeRaw): 3.1676143112814583 ns.
Calls.IterableSyncStarIterablePolymorphic(RunTimeRaw): 104.4932079414838 ns.
Calls.IterableManualIterablePolymorphic(RunTimeRaw): 104.57516339869281 ns.
Calls.IterableManualIterablePolymorphicManyYields(RunTimeRaw): 116.92487576731949 ns.
```

TEST=ci
CoreLibraryReviewExempt: Added entry-point pragmas.
Change-Id: I02fbd08141f51c00fb37b6fa0304dc25d6afdb71
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301020
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-05-22 08:32:12 +00:00
Srujan Gaddam eb8e3d549a [dart:js_interop] Add new diagnostic reporter so we can avoid transforms
Adds a delegating reporter so we can keep track of whether there are
interop errors. If there are, we do not do the transforms on the JS
backends.

Change-Id: Ib0f36b748443cb7fe8f8bb427692d653557d59fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304261
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-05-18 18:53:03 +00:00
Zach Anderson 1b9198c679 Revert "[dart:js_interop] Disallow ffi and JS interop in the same library"
This reverts commit 1c5d23e8a2.

Reason for revert: https://github.com/flutter/flutter/issues/127027

Original change's description:
> [dart:js_interop] Disallow ffi and JS interop in the same library
>
> dart2wasm can use both dart:ffi and JS interop libraries. To avoid
> confusion around external members, this disallows JS interop from
> being used in the same library as dart:ffi.
>
> Change-Id: I53e0426306be99c43b2bbfc14d65075128f0d5c5
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301200
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: I1fd872e6d0cd679ec9c1842557745647385ec3af
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304100
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-05-17 16:15:36 +00:00
Srujan Gaddam 1c5d23e8a2 [dart:js_interop] Disallow ffi and JS interop in the same library
dart2wasm can use both dart:ffi and JS interop libraries. To avoid
confusion around external members, this disallows JS interop from
being used in the same library as dart:ffi.

Change-Id: I53e0426306be99c43b2bbfc14d65075128f0d5c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301200
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-05-16 22:50:46 +00:00
Ömer Sinan Ağacan 7bbe675971 [dart2wasm] Specify finalizer map concrete type
The map `breakFinalizers` need to have insertion-ordered iteration
otherwise creation of Wasm blocks when compiling try-finally blocks
won't work. Update the map type from `Map` to `LinkedHashMap` to make
this clear.

This doesn't change the concrete map type used as non-constant map
literals are already compiled to `LinkedHashMap`s, just makes the type
more precise for clarity.

Change-Id: Idebffe2f0f75232f5ef41729538ad3d2508c74c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294760
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-12 09:31:28 +00:00
Ömer Sinan Ağacan e20d2d2103 [dart2wasm] Fix completer.future type in for-in lowering
Currently the `InstanceGet` node result type for for
`Completer<bool>.future` is `Future<bool> Function()`, but it should be
`Future<bool>`.

This causes problems in CL 301020 where we generate temporaries for
nested `await` expressions and use the expression type for the types of
those temporaries. Incorrect expression type in `completer.future`
causes a temporary with incorrect type to be generated.

Change-Id: Ib8193c66afee9454a275c00fb958c11fd35cd3eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301382
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-05-04 19:15:28 +00:00
Joshua Litt e82a5a2ff3 [dart2wasm] Move entrypoint into the lib directory.
This CL will make it easier to consume `dart2wasm` as a library. Specifically, users can import `package:dart2wasm/dart2wasm.dart`, and call `main` from Dart libraries.

Change-Id: I9f5d5ab539677af2604df9d4b0e1e2d82db7485f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300780
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-05-03 16:45:32 +00:00
Srujan Gaddam c4d354dc2a Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations"
This reverts commit 4919729f00.

This CL also adds back in logic to handle older package:js versions to avoid
failures in our static checking. It also supports dart:js_interop's @JS
annotation since it can now be used for @staticInterop classes.

CoreLibraryReviewExempt: Reland of backend-specific library changes.
Change-Id: I104653a9a6b2593f6bab658808287e2074c18550
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294130
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-02 15:24:18 +00:00
Joshua Litt 47b7c1f31d [js] Add js_interop_unsafe library.
CoreLibraryReviewExempt: Web only library.
Change-Id: I4d6007e0731ecae81fcc614168baee7d5e662fd8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293743
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-04-27 18:51:49 +00:00
Srujan Gaddam 1d28f8e821 [dart:js_interop/ddc/dart2js] Implement JS types using @staticInterop
Currently, dart:_js_types types are all typedefs in the web backends.
This leads to inconsistent semantics, since you can statically pass
Strings to JSString, for example. You cannot do this in dart2wasm.
In order to ensure consistent semantics, we reify these types using
a custom @staticInterop lowering. They all get erased to their
respective Dart type. When we have inline classes, these types
should be implemented using inline classes.

Note that Interceptor will not work for this use case. The reified
type of JS primitives are Dart types e.g. String, bool, and therefore
can not be casted to Interceptor.

In order to do this, the eraser is refactored and the JS backends use
shared erasure code to either erase/emit types.

Tests are added to make sure you need to go through a conversion or
cast to pass Dart objects to JS types.

CoreLibraryReviewExempt: Backend-specific internal library changes.
Change-Id: I5942be628102919ec167f094cfe10fced606363c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295105
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2023-04-26 15:55:54 +00:00
Johnni Winther 009cbfbeac [kernel] Merge front_end and kernel verifiers
This merges the front_end and kernel verifiers into one Target based
kernel verifier. The RedirectingFactoryBody work-around is moved to
package:kernel to support its verification.

TEST=existing

Change-Id: I0adf4d2c22c4009cf439b3b23fa14192253a2846
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280161
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-04-26 14:14:36 +00:00
Srujan Gaddam 91f2d6a621 [dart:js_interop] InlineExtensionIndex should handle multiple libraries
Since we no longer only do lowerings at the declaration site, the
InlineExtensionIndex class needs to handle libraries besides the
current library. This is because when lowering at the invocation
site, the target might not be in the current library.

Change-Id: Ifcf6cc63ce7e6f86b3408c9830e1244215598bf6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296381
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-04-19 20:18:47 +00:00
Joshua Litt 8158de08b2 [dart2wasm] Cleanup js interop logic a bit more.
Change-Id: Ibb814b3312c877a62351ec6f26412c84380b8359
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294700
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-04-19 16:54:15 +00:00
Ömer Sinan Ağacan b180aa3c55 [dart2wasm] Use identical in switch statements
Currently when `switch` expression is nullable (so the values are boxed)
we currently use `ref.eq` to compare the values.

This doesn't work as expected when one of the values is a constant and
the other one is a runtime-allocated value. Example:

    void test(bool? x) {
      switch (x) {
        case false:
          print('no');
        case true:
          print('yes');
        case null:
          print('maybe');
      }
    }

    bool runtimeTrue = int.parse('1') == 1;

    void main() {
      test(runtimeTrue);
    }

Here the return value of `runtimeTrue` is boxed in the call site of
`test`. In the body of `test` we use globals for constants `true` and
`false`, which are never equal to runtime-allocated values.

We now use `identical` in these cases, which handles `bool`, `String`,
and `num` values as expected and compares the rest using `ref.eq`.

New passing test: co19/LanguageFeatures/Patterns/exhaustiveness_A01_t10

Fixes #52075

Change-Id: Ibbeda7525fd40cfec5ee477493d0d96ac6e139b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295941
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-04-19 07:28:56 +00:00
Jackson Gardner 3015fd34fd [dart2wasm] Allow the user to specify the path of the js runtime file.
Change-Id: Iceb0428f70c77d34daa675e199abf670542babb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295220
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
2023-04-14 16:51:18 +00:00
Aske Simon Christensen d8b53d97ff [dart2wasm] Implement identityHashCode via br_table.
This saves the space for the `_identityHashCode` method in the
dispatch table and allows customizing `identityHashCode` for classes
not in `dart:core`.

Change-Id: I829fb0f53dea1f3baf92e12079b9772ce2ff8c2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292820
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Auto-Submit: Aske Simon Christensen <askesc@google.com>
2023-04-13 16:45:14 +00:00
Joshua Litt ffd89db995 [dart2wasm] Break out visiting / specializing logic for JS interop.
Change-Id: Ib70ae6477bcc676cea6c5c8167bfc1827114fb58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294561
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-04-12 17:06:05 +00:00
Joshua Litt 893645c6b1 [dart2wasm] Create a folder for libraries related to js interop.
Change-Id: I761a3f4383f8d6d05b2f68c3a68e6aa13e93d20d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294400
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-04-11 00:30:48 +00:00
Zach Anderson 4919729f00 Revert "Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations""
This reverts commit 9e1997971e.

Reason for revert: Breaks Dart -> Engine roll?

See:
https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20linux_web_engine/1821/overview
https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20Engine%20Drone/666824/overview

Original change's description:
> Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations"
>
> This is a reland of commit fbe9c21972
>
> This fixes the issue with the duplicate allowPlatformPrivateLibraryAccess.
>
> Original change's description:
> > [pkg:js/dart:js_interop] Move annotations to dart:_js_annotations
> >
> > This moves package:js annotations to the internal library that
> > Flutter has been using already. This gives us a single location
> > for all package:js annotations. We also introduce a @JS annotation
> > in dart:js_interop since we can no longer use dart:_js_annotations
> > to avoid the breaking change in semantics.
> >
> > CoreLibraryReviewExempt: Backend-specific internal library.
> > Change-Id: I9ca55c807d7d192004a6da99f63a72d598fe4f12
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284760
> > Commit-Queue: Srujan Gaddam <srujzs@google.com>
> > Reviewed-by: Samuel Rawlins <srawlins@google.com>
> > Reviewed-by: Johnni Winther <johnniwinther@google.com>
> > Reviewed-by: Joshua Litt <joshualitt@google.com>
>
> CoreLibraryReviewExempt: Relanding.
> Change-Id: I40ff2a00682fccbd7dd44a364b5046aaac0f3bac
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293203
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Samuel Rawlins <srawlins@google.com>

Change-Id: Ide8609575c73d714f3ae4f9ea9ffc74e228fa189
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293962
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2023-04-06 14:43:18 +00:00
Srujan Gaddam 9e1997971e Reland "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations"
This is a reland of commit fbe9c21972

This fixes the issue with the duplicate allowPlatformPrivateLibraryAccess.

Original change's description:
> [pkg:js/dart:js_interop] Move annotations to dart:_js_annotations
>
> This moves package:js annotations to the internal library that
> Flutter has been using already. This gives us a single location
> for all package:js annotations. We also introduce a @JS annotation
> in dart:js_interop since we can no longer use dart:_js_annotations
> to avoid the breaking change in semantics.
>
> CoreLibraryReviewExempt: Backend-specific internal library.
> Change-Id: I9ca55c807d7d192004a6da99f63a72d598fe4f12
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284760
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Joshua Litt <joshualitt@google.com>

CoreLibraryReviewExempt: Relanding.
Change-Id: I40ff2a00682fccbd7dd44a364b5046aaac0f3bac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293203
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-04-05 23:20:15 +00:00
Zach Anderson dc33261641 Revert "[dart2wasm] Fix runtime type tests"
This reverts commit a289c4d848.

Reason for revert: https://github.com/flutter/flutter/issues/124282

Original change's description:
> [dart2wasm] Fix runtime type tests
>
> emitTypeTest optimizes a test like `x is List<T>` where `x :
> Iterable<T>`, i.e. tested-against type is a subtype of the operand's
> static type. In these cases we can check just the class ID of the
> operand without checking the type arguments.
>
> However this optimization cannot be done when the types don't have same
> number of type arguments. Example:
>
>     class H1<T> {}
>
>     bool test(Object o) {
>       return o is H1<num>;
>     }
>
>     void main() {
>       print(test(H1<Object>()));
>     }
>
> Here `H1<num> <: Object`, but we still need to check the type parameter.
>
> This CL checks that the types have the same number of type arguments
> before optimizing the test.
>
> Fixes #51187.
>
> This fix reveals another bug in `static_interop_test`, which is tracked
> in #51200. The test is updated to work around the bug for now.
>
> New passing tests:
>
> - co19/LanguageFeatures/Patterns/matching_cast_A01_t01
> - co19/LanguageFeatures/Patterns/matching_list_A01_t01
> - co19/LanguageFeatures/Patterns/matching_list_A01_t02
> - co19/LanguageFeatures/Patterns/matching_object_A01_t01
> - co19/LanguageFeatures/Patterns/matching_object_A01_t02
> - co19/LanguageFeatures/Patterns/record_A01_t03
> - co19/LanguageFeatures/Patterns/record_A01_t06
> - co19/LanguageFeatures/Patterns/record_A01_t07
> - co19/LanguageFeatures/Patterns/record_A01_t08
> - co19/LanguageFeatures/Patterns/record_A01_t09
> - language/generic/deep_test
> - language/generic_methods/type_expression_test
> - language/patterns/object_pattern_inference_test
>
> Change-Id: Ibd9615666b7f7538c2a3f03fb7f5ebe9b16c3d54
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292881
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Commit-Queue: Ömer Ağacan <omersa@google.com>

Change-Id: Ieb222c086864744d33b77de69882e805981f1953
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293891
Commit-Queue: Zach Anderson <zra@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-04-05 23:13:36 +00:00
Ömer Sinan Ağacan 592c6029b0 [dart2wasm] Remove unused argument to emitTypeTest
Change-Id: Id9ac7552980c3799bc6bfbb12376cdf76466769c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292724
Auto-Submit: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-04-05 16:04:14 +00:00
Ömer Sinan Ağacan a289c4d848 [dart2wasm] Fix runtime type tests
emitTypeTest optimizes a test like `x is List<T>` where `x :
Iterable<T>`, i.e. tested-against type is a subtype of the operand's
static type. In these cases we can check just the class ID of the
operand without checking the type arguments.

However this optimization cannot be done when the types don't have same
number of type arguments. Example:

    class H1<T> {}

    bool test(Object o) {
      return o is H1<num>;
    }

    void main() {
      print(test(H1<Object>()));
    }

Here `H1<num> <: Object`, but we still need to check the type parameter.

This CL checks that the types have the same number of type arguments
before optimizing the test.

Fixes #51187.

This fix reveals another bug in `static_interop_test`, which is tracked
in #51200. The test is updated to work around the bug for now.

New passing tests:

- co19/LanguageFeatures/Patterns/matching_cast_A01_t01
- co19/LanguageFeatures/Patterns/matching_list_A01_t01
- co19/LanguageFeatures/Patterns/matching_list_A01_t02
- co19/LanguageFeatures/Patterns/matching_object_A01_t01
- co19/LanguageFeatures/Patterns/matching_object_A01_t02
- co19/LanguageFeatures/Patterns/record_A01_t03
- co19/LanguageFeatures/Patterns/record_A01_t06
- co19/LanguageFeatures/Patterns/record_A01_t07
- co19/LanguageFeatures/Patterns/record_A01_t08
- co19/LanguageFeatures/Patterns/record_A01_t09
- language/generic/deep_test
- language/generic_methods/type_expression_test
- language/patterns/object_pattern_inference_test

Change-Id: Ibd9615666b7f7538c2a3f03fb7f5ebe9b16c3d54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292881
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-04-05 07:40:39 +00:00
Srujan Gaddam 55e60cb982 Revert "[pkg:js/dart:js_interop] Move annotations to dart:_js_annotations"
This reverts commit fbe9c21972.

Reason for revert: Rebase leads to additional definitions of allowPlatformPrivateLibraryAccess in dart2wasm.

Original change's description:
> [pkg:js/dart:js_interop] Move annotations to dart:_js_annotations
>
> This moves package:js annotations to the internal library that
> Flutter has been using already. This gives us a single location
> for all package:js annotations. We also introduce a @JS annotation
> in dart:js_interop since we can no longer use dart:_js_annotations
> to avoid the breaking change in semantics.
>
> CoreLibraryReviewExempt: Backend-specific internal library.
> Change-Id: I9ca55c807d7d192004a6da99f63a72d598fe4f12
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284760
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Joshua Litt <joshualitt@google.com>

Change-Id: I87c5510f7ec9bc059d4c17a354188222ac7e8cba
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293201
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-04-04 16:41:28 +00:00
Srujan Gaddam fbe9c21972 [pkg:js/dart:js_interop] Move annotations to dart:_js_annotations
This moves package:js annotations to the internal library that
Flutter has been using already. This gives us a single location
for all package:js annotations. We also introduce a @JS annotation
in dart:js_interop since we can no longer use dart:_js_annotations
to avoid the breaking change in semantics.

CoreLibraryReviewExempt: Backend-specific internal library.
Change-Id: I9ca55c807d7d192004a6da99f63a72d598fe4f12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284760
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-04-04 15:55:29 +00:00
Aske Simon Christensen d1d232776a [dart2wasm] Rename the dart:wasm library to dart:_wasm.
This is an internal library not meant to be used in application code.

CoreLibraryReviewExempt: Changes only Wasm specific libraries.
Change-Id: I2f5b463382d35a442e782067ef7d9063183fe5e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292021
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-04-04 11:52:18 +00:00
Ömer Sinan Ağacan 4ecbae0aaf [dart2wasm] Update switch-case compilation
With https://dart-review.googlesource.com/c/sdk/+/289224 the front-end
can now generate switch-case expressions where type of the `switch`
expression is different than the types of expressions in `case`s.

To handle this case we have two options:

1. Compare type of `switch` and `case`s and compile the code to just
   evaluate the switch expressions and the default case.

2. Use reference equality

This CL implements (2) as it's simpler and no correct code will have a
switch-case with differently typed switch and case expressions.

Fixes #51793,

Fixes tests:

- co19/Language/Statements/Switch/execution_t01
- co19/Language/Statements/Switch/type_t01
- co19/Language/Statements/Switch/type_t02

Change-Id: I7eece161249498cf19c9f5245b3898c15a721b60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290063
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-04-03 14:17:49 +00:00