Commit graph

235 commits

Author SHA1 Message Date
Srujan Gaddam 06ec78851b [dart:js_interop] Add static error for converted functions that contain named params
Like type parameters, these parameters can't be passed from JS and
such functions already do not work as intended as there is no way
to pass named args to a JS function. These named parameters were
being silently ignored in dart2wasm when creating the function
trampoline.

Change-Id: Iebb890de05f8b242e0542c1ec8f2c0582c5232df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368062
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-06-14 19:42:10 +00:00
Ömer Sinan Ağacan 4796b25a30 Reland "[dart2wasm] Check import/export pragmas in user code"
This is a reland of commit 35bc17a0fa

Changes from the original CL is that we now allow packages in
`allowedInteropLibrariesInDart2WasmPackages`.

Original change's description:
> [dart2wasm] Check import/export pragmas in user code
>
> Change-Id: I926d108a4571d685c67d3a174a8e506910cce8f7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369020
> Commit-Queue: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: I69f61ecf246dfdbfcab372c6c2adb2a64f2d0b36
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370900
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-11 13:12:27 +00:00
Martin Kustermann 847c35612a [dart2wasm] Make dart compile wasm compiled apps disable dart.library.ffi
This is a follow-up to [0]. That CL changed dart2wasm's modular
transformer to issue an error if `dart:ffi` is imported.

Users of packages that have specialized code for the VM (which supports
FFI) use conditional imports based on `dart.library.ffi`. We don't want
the VM-specific code to be used for web in dart2wasm (as dart2wasm
doesn't support the entirety of `dart:ffi`).

As a result we're going to make `dart.library.ffi` be false in
coditional imports (as well as in
`const bool.fromEnvironment('dart.library.ffi')`).

[0] https://dart-review.googlesource.com/c/sdk/+/368568

Issue https://github.com/dart-lang/sdk/issues/55948
Issue https://github.com/flutter/flutter/issues/149984

Change-Id: I70a775278ab701d1fd2596521e378cb6364edac2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370580
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-06-11 09:28:40 +00:00
Ömer Sinan Ağacan d56cef5b3b [dart2wasm] Simplify calculateTransitiveImportsOfJsInteropIfUsed
- Don't convert the result to list: we don't need the result as list so
  conversion is not necessary.

- Return empty set instead of null when empty: `null` and empty set
  represents the same thing, using just one value is simpler for the
  downstream as we don't need to check both the null case and whether
  the set is empty.

Change-Id: I925e9bd8962eeb91a4a20ab5b7218a27d263bece
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369021
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-31 16:49:59 +00:00
Ömer Sinan Ağacan dbcf23a5ed [dart2wasm] Disallow dart:ffi in user code
Change-Id: I1d99637e4538a183d8fa567399bfb7c55675e60e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368568
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-31 07:12:21 +00:00
Johnni Winther 310775bd43 [cfe] Remove isNonNullableByDefault argument from messages
Legacy libraries are no longer supported so nullabilities are always
shown in messages.

TEST=existing

Change-Id: Ic1a444c3f5d98baff70a60a2ad0d316d487ea250
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365824
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-05-14 09:32:01 +00:00
Srujan Gaddam 307d739158 [dart:js_interop] Fix lowerings of ExternalDartReferences
Closes https://github.com/dart-lang/sdk/issues/55549
Closes https://github.com/dart-lang/sdk/issues/55340

Fixes several issues around using ExternalDartReferences:
- Better inlining of interop methods is enabled when this
type is used. This also indirectly improves inlining when
using JSAny.
- Adding some missed inlining for setting properties in
general.
- Allows opaque references of Dart functions to be passed
to JS
- Allows type parameters that extend ExternalDartReference
to be used in interop methods.
- Fixes up parent pointers of nodes in transforms.

Change-Id: I8cbd163ee3c1b98e733c35a61e6e83a0787d334c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364580
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-04-26 19:08:13 +00:00
Chloe Stefantsova 8aa400bf5f [analyzer][cfe] Share the implementation of the Variance class
Part of https://github.com/dart-lang/sdk/issues/54902

Change-Id: Ie406b59baf3efdeaac577f5181320b28c5076068
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361781
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2024-04-10 13:08:55 +00:00
Srujan Gaddam 1232260158 [dart:js_interop] Add ExternalDartReference
Closes https://github.com/dart-lang/sdk/issues/55187

Adds a faster way for users to pass opaque Dart values to
JS without the need for boxing like in JSBoxedDartObject.
This does mean, however, that this new type can't be a JS type,
and therefore cannot have interop members declared on it.
Refactors existing code to handle that distinction.

CoreLibraryReviewExempt: Backend-specific library that's been reviewed by both dart2wasm and JS compiler teams.
Change-Id: Ia86f1fe3476512fc0e5f382e05739713b687f092
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358224
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-03-26 15:43:19 +00:00
Srujan Gaddam 7685ec3e0e [dart:js_interop] Better error reporting for invalid external types
Closes https://github.com/dart-lang/sdk/issues/54320

Several improvements to the error reporting:

- Split errors to avoid parametrizing error strings.
- Use one error per member/toJS invocation.
- Highlight the invalid types in the signature.

Extra tests are added to get coverage for things like operators.

Change-Id: I6d8ac3cf0124730e7c2c0dab3a107da5d0263f7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347226
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-15 23:36:22 +00:00
Srujan Gaddam 55df0ca4d6 [dart:js_interop] Fix operator precedence in determining constructor type
Fixes https://github.com/dart-lang/sdk/issues/55107

The lack of parentheses around the ternary operator made the check
invalid when there are members that aren't constructors in the
extension type.

Change-Id: I87ce918c478113f682d3df28f148b7f59d4fd075
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355883
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-06 17:39:29 +00:00
David Morgan 897c89e8bc [CFE] Split files needed by package:vm/modular/... into codes folder.
Fix "no exports" exclude for `api_unstable` to actually work: it was mixing up
the path root.

Tested: no code changes, only moves.
Change-Id: If06a96f0de8fb8b92f331978d457c72deda07cec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354301
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-02-27 15:04:27 +00:00
Martin Kustermann 95a61f6392 Roll flute to new version which removes legacy interop usages
Issue https://github.com/dart-lang/sdk/issues/54908

Change-Id: Ia89ed9a145b33ee7e4a4719df09465fc98f6064c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352906
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-16 13:10:04 +00:00
Sigmund Cherem d82be109a2 [jsinterop] fix lowering of callMethod unchecked calls.
The lowering for external calls works in multiple steps:
- we first expand it into a `js_util.callMethod` call (which uses .apply
  internally)
- which we later refine in to a `js_util._callMethodUncheckedN` call, if
  possible (which calls the member directly)

The second step only happens if we can statically verify the arity of
the method being called and that every argument passed doesn't need a
allow-interop check. The latter is bypassed if we know from the types
that it cannot be a Dart Function.

The new JS interop always satisfies the check, but the second step above
failed to regonize it because it didn't account for extension types. This
CL does the incremental fix to recognize it. Long term, we should
instead change the lowering to use directly the js_interop_unsafe
methods, and tailor the lowering to the new interop.

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

Change-Id: Ieee560e5cd6bd9b6921368477bf8212cae5a1faa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351221
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-02-09 01:59:46 +00:00
Parker Lougheed 4725b282f9 [js_interop_checks] Update SDK constraint to support Dart 3
The package already uses 3.0 features after 3b294fdab2, but the usage wasn't caught due to https://github.com/dart-lang/sdk/issues/54764.

Since all packages that depend on this all require Dart 3 or greater now, we can increase the constraint and start to take advantage of its features. Also avoids a few checks and lookups :)

Change-Id: Iba539b86dc2f0117406b96e60ed8e92ea9ecf220
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349161
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-01-31 01:54:18 +00:00
Srujan Gaddam 3b294fdab2 [dart:js_interop] Add isA helper
Closes https://github.com/dart-lang/sdk/issues/54138

Adds a helper to do better type-checks so that users don't
accidentally using is checks or have to manually do the right
typeof or instanceof checks. In order to do this, there is
some refactoring to make ExportCreator a SharedInteropTransformer
(as it's shared across all backends) so that we can reuse an
existing visitor. In the same class, we remove unnecessary setting
of parent pointers. We should clean up the fileOffsets as well,
but dart2js verifies that those are set, so we keep them as is
for now. Also adds some static errors for edge cases.

CoreLibraryReviewExempt: Helper for web-specific library.
Change-Id: I34d818ada1349b69afd15d170d3fafa0460f65fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347225
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-01-25 18:52:45 +00:00
Srujan Gaddam f04e42be46 [dart:js_interop] Allow dart:html types in external signatures
Closes https://github.com/dart-lang/sdk/issues/54482

This is generally useful for users working around some limitations of
dart:html. While we want to encourage users to use package:web,
dart:html is not available on dart2wasm and users can use dart:html in
other ways already e.g. in an interop extension type, so it doesn't make
sense to disallow this. We also allow type parameters that extend these
types as well.

In order to make this a bit more performant (subtyping checks may be
expensive), code is refactored to cache more readily and separate the
notion of an allowed representation type vs interop extension type. We
also define the notion of a "core" interop type, which will be useful
when we want to efficiently query what interop type users are using
underneath the possible layers of extension types.

A few missing tests around typed_data are added and the error around
invalid types is reworded to include this change and be more consise.

Change-Id: I256b0cce4355d2a21853b0c5bf641166cafc523e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347224
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-01-25 02:10:44 +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
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
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
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
Srujan Gaddam c1ba3cf699 [dart2wasm] Fix handling of generic callbacks in trampoline
Closes https://github.com/dart-lang/sdk/issues/54192

Callbacks were being casted to their static type before being
called. With generic callbacks, we do not know their exact type
at compile time, therefore cannot make that cast. Similarly, a
null check was being done if the static type of the parameter
was potentially non-nullable, whereas it should be done if it's
*not* potentially nullable.

Change-Id: I3d30e901f1ff2ae4c17887564f15368244baeb24
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340390
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-12-12 04:50:13 +00:00
Srujan Gaddam 4f44d2eb22 [dart:js_interop] Fix checking of type parameters in interop APIs
Addresses some comments in https://github.com/dart-lang/sdk/issues/54192

- With the addition of `nonTypeVariableBound`, we no longer need a
recursive checker.
- We also should account for `StructuralParameterTypes`.
- The current checks did not check type parameters for functions
converted via `toJS`, so that is handled as well.
- Functions that declare type parameters cannot be called in JS
correctly, so an error is added when users try to convert them.
- Some errors are reworded/modified.

Change-Id: Ic05220883ec4ad8653963acd901d339426cba6c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339346
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-11 21:03:01 +00:00
Srujan Gaddam b1a7ca77e0 [dart:js_interop] Move JS types to extension types
- Removes @staticInterop JS types declarations in favor of
typedefs (the function types' reified types and the typed data's
reified types have changed to make the type hierarchy work in the
JS backends).
- Adds extension types to dart:js_interop
- Adds a fromInteropObject helper to JSObject to avoid casting to
an extension type
- Deletes now stale tests
- Refactors some dart2wasm @staticInterop declarations since they
can no longer implement JS types
- Updates extension types tests to use the prefix extension_type
instead of inline_class
- Updates comments

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: Ibe04afac9585ddb99fcf6dbaa7f12050d8b876dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332860
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-06 21:59:58 +00:00
Srujan Gaddam ae082ef407 [pkg:js] Remove referenceFromIndex lookup in static interop eraser
This was only ever used to handle modular compiles and is no longer
needed now that we erase in DDC instead.

Change-Id: I44577464c29526d4b4fabb7c65c9f5f693edb02a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335407
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-11-28 01:11:30 +00:00
Robert Nystrom 2ee771a4f6 Remove the legacy "_2" tests. \o/
I also cleaned up a bunch of places that referred to them.

Change-Id: I45f68818c892f8620ea04257885ffa3763374bb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335863
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-11-17 20:17:23 +00:00
Devon Carew 6917656134 [pkg] remove duplicate config from the analysis options files
Change-Id: I149a97bbe260600a3de664b28c4d212dd9adb889
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335862
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2023-11-14 00:37:53 +00:00
Johnni Winther 3082602bf7 [cfe] Handle member access on extension type receivers
This updates the handling of member access on extension type receivers
to use the added `nonTypeVariableBound` and the `hasNonObjectMemberAccess`
properties.

The `nonTypeVariableBound` replaces the `resolveTypeParameterType`,
updated to taking the nullablity into account when going through
type variable bounds.

Change-Id: Ia2eb115c208350cdf011948177b15ebbc984fcac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333540
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-11-06 13:51:05 +00:00
Johnni Winther f87142fdc2 [kernel] Add ExtensionTypeDeclaration.procedures
This adds a list of `Procedure`s to `ExtensionTypeDeclaration`. This is
meant to model representation fields and combined member signatures
computed from inherited non-extension type members.

These are not meant to be handled by the backends. The combined
member signature can be the interface target of an `InstanceInvocation`
expression but will always have a `.memberSignatureOrigin` value from
one of the original class members.

TEST=existing

Change-Id: I87768ed75a3c7126b0a30f8ccf06e46678c56db6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330301
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-10-13 07:42:29 +00:00
Johnni Winther 9a4c9100ae [kernel] Add DartType.extensionTypeErasure
This renames ExtensionType.typeErasure and adds it to DartType. This also fixes the extension type erasure for when extension types are used in the arguments of an extension type.

DartType.extensionTypeErasure can be used by backends to easily
access the type without extension types for any type.

TEST=pkg/kernel/test/extension_type_erasure_test.dart


Change-Id: Ia49d273ed85111e3ae822720860a3e0be5ea0252
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329960
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-10-11 13:51:22 +00:00
Jackson Gardner 2caad4c3cb Expose some APIs for translating between wasm and JS interop types.
Change-Id: Ia0e609bc06b4646949a5b8c4da24f0f8daf27ec8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/327820
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-09-27 21:34:38 +00:00
Chloe Stefantsova de302d7f3b [cfe] Introduce StructuralParameters
This CL introduces StructuralParameter and StructuralParameterType
classes. They are intended to replace TypeParameter and
TypeParameterType respectively where those were used as type
parameters defined by FunctionTypes. Previously, type parameters of
FunctionTypes were represented by TypeParameter objects with the
‘parent’ field set to null. By introducing StructuralParameter and
StructuralParameterType this CL unambiguously separates the two
notions of type parameters.

TEST=existing

Change-Id: Ida3feb7ad96a7b2acef55840eacba9e36bf2a3e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312264
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-09-25 10:44:41 +00:00
Srujan Gaddam 76193718d2 Reland "[dart:js_interop] Re-enable type checks on external APIs"
This is a reland of commit 2a669c571f.

External APIs when using dart:js_interop should only allow
primitives, JS types, and other static interop types. This
was previously checked in a more restrictive mode called
"strict mode" but is not checked everywhere where dart:js_interop
APIs exist.

Change-Id: I1a8d04071a519c4965b266eb2800bcc3c3bb8393
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325961
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-09-18 19:53:40 +00:00
Srujan Gaddam 4efb33e128 [dart:js_interop_unsafe] Rename extensions and make []/[]= take String properties
Strings are the most likely use case of getting and setting
properties, and therefore we should make that easier to use.
This CL also renames the extensions in dart:js_interop_unsafe
to a more relevant name and to avoid conflicts in dart:js_interop.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: Ia8ce6593167c648f9710b47cfe27f80c854be407
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324572
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-09-12 23:11:55 +00:00
Jackson Gardner db214e8c81 Revert "[dart:js_interop] Re-enable type checks on external APIs"
This reverts commit 2a669c571f.

Reason for revert: Failing dart -> Flutter Engine roller. We need to make some changes on the engine side to prepare for re-enabling these checks.

Original change's description:
> [dart:js_interop] Re-enable type checks on external APIs
>
> External APIs when using dart:js_interop should only allow
> primitives, JS types, and other static interop types. This
> was previously checked in a more restrictive mode called
> "strict mode" but is not checked everywhere where dart:js_interop
> APIs exist.
>
> Change-Id: Ic82a3ec0bf6062c25d7f8933e503820a21bc191f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316867
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: I54caf06976e215b2b576cedfc0013ee79c6682f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324902
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-09-11 19:31:20 +00:00
Johnni Winther 4c1a94c0d3 [cfe] Embed tearoff in Extension(Type)MemberDescriptor
This simplifies handle the constructor/member and its corresponding
tearoff as a pair. Also it prepare for supporting tearoff of
extension type constructors and methods with the same name.

TEST=existing

Change-Id: Iea6cbc0250c8df6bd0f825068c1f3e865d938427
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324202
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-09-11 13:35:10 +00:00
Srujan Gaddam fedc687bd3 [dart:js_interop] Add toJSProxyOrRef
Adds a conversion function on List<JSAny?> so that users can
modify the original list and have those changes carry forward
to the array. Creates a proxy object for dart2wasm when the
list is not a JSArrayImpl. This proxy uses handler methods and
the fact that Array methods are generic to provide an Array
interface. Also fixes a small issue in the exporting so that
toJS'd function types have a valid return type.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I00f453aa82dd19f2913820579eb2675b799288d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323446
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-09-07 22:58:22 +00:00
Srujan Gaddam 6f497776e6 Reland "[dart:js_interop] Remove unnecessary custom static interop check"
This is a reland of commit 8193e6a385

The CL is changed to handle the inconsistent patching we have for
extension methods. This CL either checks if the member is non-external
or has the @patch annotation. This accounts for all the members in
dart:js_interop.

Original change's description:
> [dart:js_interop] Remove unnecessary custom static interop check
>
> This was added to prevent accidentally lowering patched members,
> but these members are patched before we see them, so they aren't
> marked external.
>
> Change-Id: Ib8f7c52c38a3f1e28905798a40319f7aa2994328
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322502
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: I129e5a030df1fd55e7292b4b4bd0276cab7bee15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322564
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-09-07 22:58:22 +00:00
Srujan Gaddam 2a669c571f [dart:js_interop] Re-enable type checks on external APIs
External APIs when using dart:js_interop should only allow
primitives, JS types, and other static interop types. This
was previously checked in a more restrictive mode called
"strict mode" but is not checked everywhere where dart:js_interop
APIs exist.

Change-Id: Ic82a3ec0bf6062c25d7f8933e503820a21bc191f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316867
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-09-05 16:05:08 +00:00
Srujan Gaddam b25873f11c [dart2js] Erase static interop type in static invocation
Static invocations of external factories are casted so that the
result, which is a @staticInterop type, can be treated as the erased
type instead. This CL fixes the issue where the type that it was
casted to was never replaced with the erased type.

Change-Id: Ic6eb529349ea2b5c42f91c2740d501d4f81bc38e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323505
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-08-31 09:10:57 +00:00
Srujan Gaddam 9ac045711f Revert "[dart:js_interop] Remove unnecessary custom static interop check"
This reverts commit 8193e6a385.

Reason for revert: Breaks DDC tests.

Original change's description:
> [dart:js_interop] Remove unnecessary custom static interop check
>
> This was added to prevent accidentally lowering patched members,
> but these members are patched before we see them, so they aren't
> marked external.
>
> Change-Id: Ib8f7c52c38a3f1e28905798a40319f7aa2994328
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322502
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: I5f094b507d506d488dc7a6bc74e7b1b6cb5eb2ef
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322581
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2023-08-24 20:13:57 +00:00
Srujan Gaddam 8193e6a385 [dart:js_interop] Remove unnecessary custom static interop check
This was added to prevent accidentally lowering patched members,
but these members are patched before we see them, so they aren't
marked external.

Change-Id: Ib8f7c52c38a3f1e28905798a40319f7aa2994328
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322502
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-08-24 19:59:35 +00:00
Srujan Gaddam a38fb595cf [dart:js_interop] Add JS types for Symbol/BigInt
Adds JSSymbol and JSBigInt and erases to either their respective
interceptor types in the JS backends or JSValue in dart2wasm.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: Ib2c70d22a70c6308733cd170b91eafa8ec3b3aeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321749
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-08-21 21:54:15 +00:00
Johnni Winther caafea0aee [kernel] Rename ExtensionType.instantiatedRepresentationType to typeErasure
To align with the specification.

TEST=existing

Change-Id: I7a9f21473c860b90f051bf9bc3361dfd7786c40c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/320521
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-08-17 08:32:58 +00:00
Srujan Gaddam ad62f6033b [dart:js_interop] Relabel globalJSObject as globalContext and point to object used in static interop lowerings
This is likely more useful than returning globalThis always. It
allows users to workaround issues with lowerings without having
to worry about browser compatibility differences.

CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I01479211fe6b573c845de5b134d36338c40fc10d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319301
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-08-15 20:57:17 +00:00
Srujan Gaddam 66b511fa6c [dart:js_interop] Use compiler-dependent global context
Fixes https://github.com/dart-lang/sdk/issues/52955

Instead of globalThis, dart2js and DDC will now use the same global
context that they did for non-static interop. dart2wasm will
continue to use globalThis.

Change-Id: Iec899fc73ed35c50cd688d9b45b980e94f101c0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318520
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2023-08-15 20:57:17 +00:00
Srujan Gaddam 20c6e55b68 [dart:js_interop] Add tests for extension type factories
Extension type factories are added to the language, so they
should be tested. Also fixes a small issue on detecting
tear-offs.

Change-Id: I8d2b374830e4ac11783d10d3b75221544ee9ef3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318160
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2023-08-15 18:24:43 +00:00
Srujan Gaddam d485ef46ce [dart:js_interop/ddc/dart2wasm] Refactor inline class to extension types
Does several refactorings now that inline class -> extension type:
- InlineExtensionIndex becomes ExtensionIndex
- Comments mentioning inline classes now reference extension types
- Tests are moved to extension types
- Errors now reference extension types instead of inline classes

Change-Id: I26ede8e3aaf6bba5f73847238edeed266fc6a043
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317805
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-08-15 18:24:43 +00:00
Srujan Gaddam 86eb49ac19 [dart:js_interop] Disallow user @staticInterop classes from subtyping most dart:_js_types types
Since user @staticInterop types are erased to JavaScriptObject, they
should only be able to subtype other types that are :> JavaScriptObject,
which are just JSObject and JSAny. Eventually all the other JS types
will move to extension types and we can remove this check.

Change-Id: If56b6770e141238b583937880ca87496780c8fac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316865
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-08-08 19:17:25 +00:00