Commit graph

286 commits

Author SHA1 Message Date
Johnni Winther f17cf33c6d [kernel] Move Pattern nodes to package:kernel
These AST nodes were so far internal to the CFE, but since we need to
move the pattern lowering to the constant evaluator we need to support them in the AST defined in package:kernel.

TEST=existing

Change-Id: Ie6c5f0f8ad75a866c5d965fdf506bc869ffaf654
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288241
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-03-13 08:43:07 +00:00
Johnni Winther 04e6f4c282 [kernel] Add VariableDeclaration.isSynthesized
This adds an [isSynthesized] flag to the [VariableDeclaration] the
signal when the variable doesn't correspond to a variable in the
source code.

The name of a variable can only be `null` if it is synthesized.

Partially in response to
https://github.com/dart-lang/sdk/issues/51554

TEST=existing

Change-Id: I94591971f11da09d210c8b25a2d05e22ca05dc62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286961
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-03-10 11:13:36 +00:00
Ömer Sinan Ağacan 7b64d76b1d [dart2wasm] Fix const and non-const instantiation closure comparison
Fixes closure equality when one of the closures is const instantiation
and the other one is runtime instantiation.

New passing test: language/closure/identity_equality_tearoff_test

Change-Id: I4583f9823eb484425208c217a2df585c6fb56d70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287462
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-03-10 09:42:29 +00:00
Aske Simon Christensen c19720245c [dart2wasm] Categorize and masquerade runtime types by lookup table
This avoids virtual calls for `runtimeType` (unless the user overrides
it) and `_runtimeType` (since the internal categorization is now done
using the table instead), which saves a huge amount of space in the
global dispatch table.

It also fixes record runtime types, which now use the masqueraded
types for its fields, rather than the (possibly user-overridden)
`runtimeType`.

A masquerade case was missing for `Type`, which has been added.

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

Tested: ci + new test for overridden runtimeType
Change-Id: I1909c665ae78eb07b9c0eb22b6e8836e27495d70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285684
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-03-09 22:08:19 +00:00
Aske Simon Christensen c7432bf694 [dart2wasm] Workarounds to compile and run flute
Change-Id: I9180a2a65d47b11ec5e13d9c003c10b428bc15fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287540
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-03-09 21:10:45 +00:00
Aske Simon Christensen 4733f9b754 [dart2wasm] Fix accesses to type arguments in sync* functions
Fixes the `Iteration` benchmark.

Change-Id: I947c413524a3d55d19f56d0bfbb45dc5125e972a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287467
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-03-08 17:02:22 +00:00
Aske Simon Christensen f288058d6b [dart2wasm] Enable records and patterns in benchmarks
Also omit debug info from the Binaryen output, since we are not using it
for anything and the upcoming code size benchmarks will need it removed
anyway.

Change-Id: I57ddd7c8f1fa8ed725a69ed36e949109742da75d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287466
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-03-08 15:52:13 +00:00
Ömer Sinan Ağacan 979e8dc932 [dart2wasm] Fix instantiation closure equality
The test fails in VM, which is reported as #51660.

Change-Id: Icb0f5493f282aa017980478a038b48dd09c5030c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286933
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-03-08 15:42:26 +00:00
Ömer Sinan Ağacan 0ad9f2ec66 [dart2wasm] Move covariance checks from async inner to wrapper functions
New passing test: language/async/covariant_type_test

Fixes #51601

Change-Id: Id5e807b463db67d0e44842e375d35604e35398cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286462
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-03-08 11:22:51 +00:00
Kevin Moore 252adbc593 Rename pkg/dart2wasm/dart2wasm.md -> README.md
Improve discoverability on Github, etc

Change-Id: I675d06a1b3e8e38e3bc521840b3a0a4eef21291b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287243
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
2023-03-08 07:46:15 +00:00
Michael Thomsen 47b180ea89 Update wasm readme
Change-Id: Ib084c9ed28eabcdf55e1b43c6d6ef2af82e6fe76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286931
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
2023-03-07 21:22:38 +00:00
Alexander Markov 110b0f0eba [tfa,dart2wasm] Create separate class for each record shape in TFA
This allows us to better track all kinds of accesses to record
implementation classes in dart2wasm, which generates separate
record implementation class per record shape.

This change also allows us to remove mutable dispatch targets
which were used to implement dynamic accesses to record fields,
and make tracking of record field types more accurate
(record fields are now versioned per shape).

This is also a step towards inferring actual record types.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/records.dart
TEST=pkg/vm/testcases/transformations/type_flow/transformer/records_dart2wasm.dart
TEST=language/records/simple/dynamic_field_access_test

Issue https://github.com/dart-lang/sdk/issues/49719
Fixes https://github.com/dart-lang/sdk/issues/51363

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: Icba62a7ca8cfd8ddbc7f2b7c38aeabbef5caec4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286950
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-03-07 18:06:42 +00:00
Joshua Litt c36862af90 [js] Specialize optional arguments at call sites.
Change-Id: I59b10242a5d85907c21fc99eaf1eff15b39d7191
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285701
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-03-06 19:59:32 +00:00
Ömer Sinan Ağacan 6a0857952c [dart2wasm] Update type names list type
Change from `List<_StringBase>` to `List<String>`, as that's what
`_getTypeNames` returns.

Change-Id: Ib216796eb0a105e81e45d6217c2a6ddb015129c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286923
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-03-06 10:40:48 +00:00
Ömer Sinan Ağacan 22c45b2e0c [dart2wasm] Implement instantiation closure equality
Changes:

- Instantiation context structs now have a common supertype:
  `#InstantiationClosureContextBase`. This supertype is used to check if
  a closure is an instantiation.

- Generic closure vtables now have one more entry for comparing types in
  instantiation contexts.

- All instantiations with same number of types use the same context
  struct type and the vtable entry for comparing types in contexts.

- `_Closure._equals` checks if closures are instantiations (with a type
  test against `#InstantiationClosureContextBase`), and if they are,
  gets the contexts and calls the function in the vtable for comparing
  the types in the contexts.

Fixes #51030

Change-Id: I680041480963381337dcfa1fbf6c3a77ca564205
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285902
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-03-04 11:55:37 +00:00
Ömer Sinan Ağacan 095317db58 [dart2wasm] Fix canonicalization of concatenations with constants
New passing test: co19/Language/Expressions/Object_Identity/string_t01

Change-Id: I9e7758af30d1b11d136586090b82497c292cb1e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286402
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-03-02 13:30:38 +00:00
Srujan Gaddam 49f85335d5 Revert "[dart:js_interop] Add literal constructors for inline classes"
This reverts commit 1f6d4ae1a8.

Reason for revert: Broke Flutter with dart2wasm

Original change's description:
> [dart:js_interop] Add literal constructors for inline classes
>
> Adds @ObjectLiteral annotation to denote object literal constructors,
> and implements it in all the backends. For dart2js, this involves
> modifying the SSA and for dart2wasm, we create a one-per-shape
> forwarding procedure to a specialized JS method that returns the
> literal. This also modifies @anonymous semantics in dart2wasm to
> be consistent with the other backends.
>
> CoreLibraryReviewExempt: Backend-specific, just adding annotation.
> Change-Id: I4d7a9ea9ed097f4f378709b40f8bd74f02e26b23
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283922
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Joshua Litt <joshualitt@google.com>

Change-Id: Ifce611e1150d8aa275f9e312743bded56a572176
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285342
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-02-24 20:42:14 +00:00
Mayank Patke bff851ce7e [dart2wasm] Refactor ConstConditionalSimplifier and related classes
This will allow them to be used with other compiler backends, including
dart2wasm.

Change-Id: I42182545eeb035af8a3a6e2eba209ba2601a52d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281923
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
2023-02-23 18:54:29 +00:00
Srujan Gaddam 1f6d4ae1a8 [dart:js_interop] Add literal constructors for inline classes
Adds @ObjectLiteral annotation to denote object literal constructors,
and implements it in all the backends. For dart2js, this involves
modifying the SSA and for dart2wasm, we create a one-per-shape
forwarding procedure to a specialized JS method that returns the
literal. This also modifies @anonymous semantics in dart2wasm to
be consistent with the other backends.

CoreLibraryReviewExempt: Backend-specific, just adding annotation.
Change-Id: I4d7a9ea9ed097f4f378709b40f8bd74f02e26b23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283922
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-02-23 01:14:39 +00:00
Ömer Sinan Ağacan b13f03dd4d [dart2wasm] Throw NoSuchMethodError in unimplemented external members
New passing tests:

- co19/Language/Functions/External_Functions/not_connected_to_a_body_t01
- co19/LanguageFeatures/Abstract-external-fields/static_analysis_external_A01_t03
- co19/LanguageFeatures/Abstract-external-fields/static_analysis_external_A02_t04
- co19/LanguageFeatures/Abstract-external-fields/static_analysis_external_A03_t03
- co19/LanguageFeatures/Abstract-external-fields/static_analysis_external_A03_t06
- co19/LanguageFeatures/Abstract-external-fields/static_analysis_external_A05_t03
- language/bool/has_environment_not_new_test
- language/constructor/external_constructor_test
- language/external_abstract_fields/external_fields_test
- lib/math/random_secure_unsupported_test

Change-Id: I74a430af37d3f138387a942ef028639224c312d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284622
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-22 13:35:34 +00:00
Ömer Sinan Ağacan 004b400dfb [dart2wasm] Implement type parameter bound checks
New passing tests:

- language/generic_methods/bounds_test/02
- language/covariant/subtyping_test
- language/covariant/type_parameter_test
- language/records/simple/type_checks_test

Fixes #51358

Change-Id: I6854f71cbfc47106f685a00c36a64330cc0a57f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282660
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-02-21 18:56:16 +00:00
Ömer Sinan Ağacan 4d07dc0199 [dart2wasm] Fix overriding stack traces of re-thrown errors
New passing tests:

- language/stack_trace/rethrow_error_test/none
- language/stack_trace/rethrow_error_test/withtraceparameter

Change-Id: I446bce3a37846157d6b3e056e20a4b89ab03acf1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284181
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-02-21 14:36:04 +00:00
Ömer Sinan Ağacan ff9fd9a2bd [dart2wasm] Fix representation types of classes
When computing representation of a class with implementers, use the
representation of implementers, rather than implementer classes.

New passing test: lib/math/implement_rectangle_test

Fixes #51406

Change-Id: I495353a00e3379e04123a77c270374b82c97a90a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284301
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-21 14:08:31 +00:00
Ömer Ağacan 7c6423cb32 Revert "[kernel] Remove unused RecursiveVisitor type parameter"
This reverts commit a329e05684.

Reason for revert: Broke internal projects

Original change's description:
> [kernel] Remove unused RecursiveVisitor type parameter
>
> TEST=ci
>
> Change-Id: I523282e933b955389c950c1942253d2d66a51f3f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283821
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Ömer Ağacan <omersa@google.com>

TBR=johnniwinther@google.com,omersa@google.com,dart-scoped@luci-project-accounts.iam.gserviceaccount.com

Change-Id: Iad30e34ce0a491711b0daa1991c69de1796f8846
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284023
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-02-18 10:52:39 +00:00
Ömer Sinan Ağacan a329e05684 [kernel] Remove unused RecursiveVisitor type parameter
TEST=ci

Change-Id: I523282e933b955389c950c1942253d2d66a51f3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283821
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-18 07:31:18 +00:00
Joshua Litt 71cffed55c [js_types] Add Helpers to work with JSUndefined and JSNull.
Before we can reify `JSUndefined` and `JSNull` we need to give users a way to detect these values. Once existing users have migrated to these new helpers, then we can start boxing `JSUndefined` and `JSNull` on Dart2Wasm.

There are a few steps here:
1) Land these helpers, but for now they will just preserve the existing semantics.
2) Deploy JS types to Flutter and `package:test`, i.e. everywhere Dart2Wasm's JS interop is currently being used, and use these helpers instead of `null` checks.
3) Switch the semantics of the helpers to stop conflating on all Web backends, while simultaneously boxing `JSNull` and `JSUndefined` on Dart2Wasm.

CoreLibraryReviewExempt: Refactoring web only libraries + some changes to Wasm's internal libraries.
Change-Id: Idb50b28b3087438751557ffd28505c7b536bf78b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282481
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-02-17 18:20:59 +00:00
Aske Simon Christensen f0e41c3a0f [dart2wasm] Use constant lists for type lists with all constant types.
This enables the type parameter bounds and defaults to be constant
lists in most cases.

Change-Id: Ie60c295bc29f4c2781cbf533410f19e8d4ce32c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283860
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-02-17 13:56:39 +00:00
Ömer Sinan Ağacan f9abd48ae5 [dart2wasm] Add type parameter defaults to runtime function types
New passing tests:

- language/function/call_generic_test
- language/generic/function_bounds_test/01
- language/generic/function_bounds_test/03

Fixes #50992

Change-Id: I4f5e94a939661f6afb4dd78d74c5f7b0ef129cc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283022
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-17 11:57:41 +00:00
Aske Simon Christensen 7a63ff2604 [dart2wasm] Fix reversal of break labels crossing finally.
The block starts and ends for the entry points to the finally block
instances corresponding to break paths were emitted in the same order,
causing the jump targets to be reversed.

Change-Id: Ifc8a6b6320ba7341140606c98333f5825d2228ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283042
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-02-15 10:24:08 +00:00
Joshua Litt ff43c6e1f0 [js] Add limited support for operators.
Change-Id: I40f8ea6666272a68afd867c095066de2c6416816
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282620
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-02-14 18:03:42 +00:00
Ömer Sinan Ağacan c5eda0430f [dart2wasm] Implement records
This generates a class for every record shape in the program. Record
shape classes with the same number of fields share the same Wasm struct.

(Shape is number of positional fields + set of names of the named
fields)

Summary of the changes:

- A new kernel pass runs right before TFA and generates record shape
  classes for every record literal and type in the program, one class
  per shape.

  A class for a record shape has the name `Record_N_a_b_...` where `N`
  is the number of positional fields, and `a_b_...` is the `_` separated
  names of the named fields.

  For example, class for a record `(1, a: 'hi', false)` is:

  ```
  @pragma('wasm:entry-point')
  class Record_2_a {
    @pragma('wasm:entry-point')
    final Object? $1;

    @pragma('wasm:entry-point')
    final Object? $2;

    @pragma('wasm:entry-point')
    final Object? a;

    @pragma('wasm:entry-point')
    Record_2_a(this.$1, this.$2, this.a);

    @pragma('wasm:entry-point')
    _Type get _runtimeType =>
      // Uses of `runtimeType` below will be fixed with #51134
      _RecordType(
        const ["a"],
        [$1.runtimeType, $2.runtimeType, a.runtimeType]);

    @pragma('wasm:entry-point')
    Type get runtimeType => _runtimeType;

    @pragma('wasm:entry-point')
    String toString() => "(" + $1 + ", " + $2 + ", " + "a: " + a + ")";

    @pragma('wasm:entry-point')
    bool operator ==(Object other) {
      if (other is! Record_2_a) return false;
      if ($1 != other.$1) return false;
      if ($2 != other.$2) return false;
      if (a != other.a) return false;
      return true;
    }

    @pragma('wasm:entry-point')
    int hashCode => Object.hash(shapeID, $1, $2, a);
  }
  ```

  `shapeID` in `hashCode` is unique to the class. It's not stored in the
  structs, only used in `hashCode` code.

  Field gets in members (`this.$1` etc.) are compiled to `struct.get`s
  as they're single target.

  `toString` currently does not use a buffer. This will be fixed in a
  separate CL.

  `entry-point` pragmas needed because there are no references from the
  program to these classes, but we want to consider them as potential
  targets.

- When generating class infos, we have a special case for records to use
  the same struct for records with the same number of fields.

- Code generator for record expressions get the record shape from the
  record type, and uses the struct type for the record.

- `ProcedureAttributesMetadata` uses in dispatch table needs a special
  case for records. This is becuase as far as TFA concerned there's no
  connection from the program to the record shape class fields, so the
  it considers record shape class fields as not dynamically called.

Fixes #50014.

Change-Id: Ie8338a0917d51984a9e32e755ccdaa2783a8e2ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280461
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-02-13 14:59:09 +00:00
Aske Simon Christensen 54b2602b88 [dart2wasm] Fix switch with only null and default
Fixes https://github.com/dart-lang/sdk/issues/51276

Change-Id: Iae61afb2ee1c66e405222663d1151dbb2f992128
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/282102
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-02-13 14:56:05 +00:00
Srujan Gaddam 2fc8685a4d [dart:js_interop] Add support for external inline and extension instance members
External inline instance members can be lowered the same way as
external extension instance members on interop classes. Similarly,
code is refactored so that external extension members can exist
on inline interop classes and are lowered accordingly.

Change-Id: I341bfeef3f1b74b54a63c963553af9230c4a10c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280621
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-02-11 00:03:57 +00:00
Joshua Litt 13b24aeedd [js_interop] Change conversion functions to be getters.
CoreLibraryReviewExempt: Internal refactoring of a not yet used library.
Change-Id: Iad62b0d4a7fc4df0c710f6ba0dd7c9b21b6a6fef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281868
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-02-10 20:08:53 +00:00
Joshua Litt 130903685d [dart2wasm] Avoid implicitly internalizing WasmExternRef.
CoreLibraryReviewExempt: Wasm only changes.
Change-Id: I0e0a6cddffa1c7f2d7c74779f480dd10bf509c1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279268
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-02-10 16:22:47 +00:00
Srujan Gaddam e6e1040afc [dart:js_interop] Expose dart:_js_interop
Types still need to be sealed, so this library is exposed with a
disclaimer that users should not subtype any types.

CoreLibraryReviewExempt: Backend-specific library for JS and Wasm.
Change-Id: I2ed8b0db6b2de60932a551047c6c9eae4a34ce2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281343
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-02-10 01:41:50 +00:00
Aske Simon Christensen 321f2e9b65 [dart2wasm] Implement sync*
This is an implementation of `sync*` via two main mechanisms:

- The closure context infrastructure is used for preserving local
  state. All local variables in `sync*` functions are implicitly
  captured in the contexts even if they are not captured by a lambda.

- Suspension and resumption of the body is implemented via a state
  machine as a switch in a loop. This allows for an arbitrary control
  flow graph that can be resumed at any point. A subclass of the code
  generator generates control constructs containing any `yield` or
  `yield*` statements as jumps around this CFG while delegating the
  rest of the code generation to the normal member code generator.

This version does not support `switch` or `try` inside a `sync*`
function. Support for these statements will be added later.

Change-Id: Iec8236f64500d823f574aa628ddb0d22fe4ac2d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280166
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-02-09 11:07:01 +00:00
Joshua Litt bd79be0e19 [js] Move allowInterop functions to dart:js_util.
CoreLibraryReviewExempt: Has core library owners approval.
Change-Id: Iea2f2e707c69c9082e158b48b50dcaf4a7b01067
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279740
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-02-08 17:16:20 +00:00
Ömer Sinan Ağacan 73ee6d53a0 [dart2wasm] Attach stack traces to Error subtypes on throw
This implements this part of the language spec (section 17.10):

> If v is an instance of class Error or a subclass thereof, and it is
> the first time that Error object is thrown, the stack trace t is
> stored on v so that it will be returned by the stackTrace getter
> inherited from Error.

New passing tests:

- co19/Language/Expressions/Throw/stack_trace_t01
- co19/LibTest/core/Error/stackTrace_A01_t01
- co19/LibTest/core/IndexError/stackTrace_A01_t01
- corelib/error_stack_trace_test/none
- corelib/error_stack_trace_test/nullThrown
- language/stack_trace/error_runtime_test

Fixes #50608

Change-Id: I1d7df2337cce1be3ecbab0180def5769b8fe3e68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279966
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-08 14:53:36 +00:00
Srujan Gaddam ff01414b8f [dart:_js_interop] Add support for statically resolvable inline class interop members
Amends lowerings on dart2wasm and JS backends to work for external
constructors/factories and static members. Tests members with and
without renaming of members/classes/libraries. Note that this does
not add support for object literal factories yet.

Change-Id: I149bef7249c1a13a31eed9f3510256d407b1d3e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280056
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-02-07 18:47:23 +00:00
Srujan Gaddam d54addb789 [dart2wasm] Handle InlineTypes in visitors
TEST=dart2wasm no longer crashes on inline classes

InlineTypes can be treated as their underlying representation
types instead.

Change-Id: I802de0112f3f62024bc746e30b3db90506a0e159
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280620
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-02-07 18:47:23 +00:00
Ömer Sinan Ağacan 68cf1aa7ac [dart2wasm] Refactor translator type env initialization
Translator type environment is now in sync with the translator class
hierarchy.

Change-Id: I2702df1d3bc14db4b24c6a934eae56b6580f5b8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280320
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-02-02 23:18:58 +00:00
Joshua Litt 99a9f3d516 [js_types] MVP of JS types.
Change-Id: Ic329146a270ff32fc2cdb32febc6f574bc81792f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280131
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-02-02 21:29:01 +00:00
Alexander Markov a9d9b7395b [kernel] Enable sound null safety in TargetFlags by default
TargetFlags.enableNullSafety is set to true by default and
also renamed to TargetFlags.soundNullSafety to better reflect its
meaning.

TEST=ci

Change-Id: I2c2f30c2af6502fd9a96141dc60e4afbf8c524fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280216
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-02-02 14:54:18 +00:00
Aske Simon Christensen a77c447be0 [dart2wasm] Omit type checks in the omit-checks benchmarking config.
The dart2wasm-omit-checks benchmarking config will pass the
`--omit-checks` option to the `compile_benchmark` script.

Detect this option and use it to enable the `--omit-type-checks`
option to dart2wasm.

As we add more options for omitting checks, we can add those to the
dart2wasm commandline we use when given the `--omit-checks` option.

Change-Id: I8aba801935888aa13357d8fd3e2f0c084c4173b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280091
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-02-02 14:01:42 +00:00
Aske Simon Christensen bc31fe4903 [dart2wasm] Enable values to be returned from void functions.
Since Dart `void` can actually carry values, functions with `void`
return type are translated into Wasm functions returning the Dart
object top type instead of an empty output type list.

Only constructors, setters and imports/exports with void return type
are now given empty output type lists in their Wasm signatures. A new
low-level `WasmVoid` type is added to the internal Wasm types for
specifying explicitly that a Wasm function should have an empty list
of outputs.

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

CoreLibraryReviewExempt: Only changes Wasm-specific libraries.
Change-Id: I9562248f94e75a60142fd1af0136183aa288b98b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279971
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-02-02 12:08:30 +00:00
Josh Soref 77978889eb Spelling
Closes https://github.com/dart-lang/sdk/pull/51143

GitOrigin-RevId: 9e21c99a222d588e4fc95980725a2f8c9784965c
Change-Id: If0870e8936c7649935dce7e23cd783d62aa5610c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279916
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-30 18:29:59 +00:00
Ömer Sinan Ağacan 2538a8216b [dart2wasm] Add command-line flag for omitting runtime type checks
The new dart2wasm flag `--omit-type-checks` is similar to dart2js's
`--omit-implicit-checks` and comes with the same caveats: program
semantics is only preserved when it doesn't have any runtime type
errors.

An example benchmark profile:

- Without the flag:
  https://pprof.corp.google.com/user-profile?id=c19135b8eeb8867a3b2ce8ba82d32517

- With the flag:
  https://pprof.corp.google.com/user-profile?id=870a61d7fee3fa6c4dbf4ef95c91ab47

List of checks that we omit with the flags:

- Covariance checks
- `as` checks
- Type checks in dynamic invocations
- Type checks in dynamic closure calls

Change-Id: Ia388e76e7defcdc03dd778e1bccf445388568c87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279965
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-01-30 12:11:35 +00:00
Jackson Gardner 4dff36345e [dart2wasm] Use the asset in @Native annotations to specify the module name.
Change-Id: I5e3644a904917a375486acd47830f311fe19a5ce
Tested: Running unit tests in this repo as well as running against coming web engine changes that use the @Native annotation: https://github.com/flutter/engine/pull/39072
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279479
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-01-28 00:03:07 +00:00
Joshua Litt a64b34d3f3 [dart2wasm] Use static interop to implement regexp helpers.
This CL also adds changes how static interop objects are interpreted at the interop boundary. Previously, static interop objects were dartified / jsified like everything else. Now, they are simply boxed.

With this approach, users can now use `Object` when they want conversions and static interop objects when they don't(assuming these objects originate in JS, Dart objects are always fully converted).

Change-Id: I40b31bfb826e4963a34eaa373574c136e13b9009
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279451
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Joshua Litt <joshualitt@google.com>
2023-01-26 17:03:40 +00:00