Commit graph

11053 commits

Author SHA1 Message Date
Martin Kustermann 338fd6501b [dart2wasm] Make _RecordType use WasmArray<>s instead of List<>s
Change-Id: I063d35209dbd5a66fbcf591ccb6a04d5139afa26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341901
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-12-19 07:43:17 +00:00
James Lin 48ac398f11 Fix Directory.current setter compatibility with IOOverrides
The `Directory.current` setter has a `dynamic` parameter so that it
can accept either `String` or `Directory` arguments. (This is
asymmetric with the getter, which always returns a `Directory`.)

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

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

Bug: https://github.com/dart-lang/sdk/issues/52140
Change-Id: I3c5bba6b442b314c798bd7949dfeb5eb6251dc6e
CoreLibraryReviewExempt: No API changes and VM-only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336604
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: James Lin <jamesdlin@gmail.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2023-12-18 20:23:21 +00:00
Derek Xu ba0835f5e2 Revert "[ DDS ] Fix DDS AOT snapshot build rules"
This reverts commit 0a393f1b69.

Reason for revert: breaks dartdev on Windows

Original change's description:
> [ DDS ] Fix DDS AOT snapshot build rules
>
> dds_aot.dart.snapshot was not being generated for runtime build targets,
> and dds.dart.snapshot was being built regardless of whether or not we
> were building for an IA32 target.
>
> This change also adds a check for IA32 in 'dart run' so the "Could not
> find dds_aot.dart.snapshot. Have you built the full Dart SDK?" message
> isn't printed when we fall back to using dds.dart.snapshot.
>
> This change also reverts 2cc08595a6, which
> failed to fix the issue it was attempting to fix.
>
> TEST=pkg/vm_service tests
>
> Change-Id: Ic990082c25b0d022093ad66600332dfb2878709f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341760
> Reviewed-by: Siva Annamalai <asiva@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

Change-Id: I479a026184fc1fe27926d1ab0d7d3221dec3130e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342440
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-12-18 17:13:59 +00:00
Ben Konyi 0a393f1b69 [ DDS ] Fix DDS AOT snapshot build rules
dds_aot.dart.snapshot was not being generated for runtime build targets,
and dds.dart.snapshot was being built regardless of whether or not we
were building for an IA32 target.

This change also adds a check for IA32 in 'dart run' so the "Could not
find dds_aot.dart.snapshot. Have you built the full Dart SDK?" message
isn't printed when we fall back to using dds.dart.snapshot.

This change also reverts 2cc08595a6, which
failed to fix the issue it was attempting to fix.

TEST=pkg/vm_service tests

Change-Id: Ic990082c25b0d022093ad66600332dfb2878709f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341760
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2023-12-15 19:05:59 +00:00
Alexander Markov dcdfcc2b8d Reland "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit 1800039c2a.

The changes fd2e9b9f1a and
c20f9eaf6f are relanded as is.

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

TEST=ci

CoreLibraryReviewExempt: Implementation change only.
Issue: https://github.com/dart-lang/sdk/issues/54172
Issue: https://github.com/dart-lang/sdk/issues/39692
Change-Id: I1a2324768502e5ffbce328127938c0d3c96c38ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341642
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-12-15 15:25:29 +00:00
Simon Binder 150e61a662 [vm/ffi] Support @Native fields
Allow annotating top-level or static fields with `@Native` to create
fields backed by native memory.
By using the `_addressOf` operator implemented in the VM, these fields
can be implemented in the CFE by replacing them with accessors looking
up the pointer and then using existing methods to load and store the
value.

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

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

CoreLibraryReviewExempt: VM & dart2wasm only feature
Change-Id: I61dccc88076723d6a6ba02d7fd848b18e4caf780
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338020
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-12-15 11:20:23 +00:00
Shikhar Soni efb60eac59 [ffi]: Add extension operator methods(+,-) for pointer arithmetic
Closes [#54250](https://github.com/dart-lang/sdk/issues/54250).

TEST=test/ffi

Change-Id: I2299e019b6c0b0db74662e4f9439feac46bc9b40
CoreLibraryReviewExempt: FFI only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341420
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Shikhar <shikharish05@gmail.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-12-14 11:42:38 +00:00
Daco Harkes 593a3d3c2c [vm/ffi] Document API handle scopes on Handle
Bug: https://github.com/dart-lang/sdk/issues/54263
CoreLibraryReviewExempt: Doc updated of VM-only feature.
Change-Id: Ie9c643ca6028b86239099932112a88ff59d123df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341461
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-12-14 10:16:30 +00:00
Alexander Markov 1800039c2a Revert "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit fd2e9b9f1a.

Revert "[vm/ffi] Cleanup FFI call trampolines"

This reverts commit c20f9eaf6f.

Reason: https://github.com/flutter/flutter/issues/140074
TEST=ci
CoreLibraryReviewExempt: Implementation change only.
Change-Id: Ib193d8f015fc66461fe3cc90550a92e1ba65f236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341620
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-12-14 01:14:58 +00:00
Nicholas Shahan fbcae44b96 [ddc] Update dynamic NSM errors to match
Makes the error messages consistent between stable and canary mode.

Change-Id: I2e7e0b78e2f81dedd24b6ef7cdd034dfe0c4b6a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341390
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2023-12-14 00:51:50 +00:00
Ömer Sinan Ağacan d794b26a6a [dart2wasm] Simplify bool return types in two imports
JS bool type can be returned as `i32`, which avoids boxing.

Change-Id: I491b1da58a740bd992099fc6ee40eca1f38811c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341481
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-12-13 13:12:20 +00:00
Alexander Markov fd2e9b9f1a [vm/ffi] Express FFI call closures explicitly in AST
Instead of implicitly creating closures for FFI
asFunction/lookupFunction APIs in the VM, now they are explicitly expressed in the kernel AST. That makes it possible to analyze
them in TFA.

FFI calls from Dart code into native are now performed in the following way:

```
  block {
    Pointer #ffiTarget0 = target;
    @pragma('vm:ffi:call-closure', _FfiCall<Int32 Function(Int32)>(isLeaf: false))
    #ffiClosure0(int arg1) {
      _nativeEffect(arg1);
      return _ffiCall<int>(#ffiTarget0);
    }
  } =>#ffiClosure0;
```

_ffiCall method is recognized by the VM and its call is replaced
directly with FFI calling sequence. _ffiCall uses closure
parameters implicitly. No extra trampolines are generated for FFI calls.

TEST=existing
Fixes https://github.com/dart-lang/sdk/issues/54172
Issue https://github.com/dart-lang/sdk/issues/39692

CoreLibraryReviewExempt: Implementation change only.
Change-Id: I92b3ff7391470686151ad0807e2cdbbf1a69d256
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339662
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-12-12 18:34:39 +00:00
Olzhas Suleimen aca875dfea [io] Use _addConnection instead _add in _HttpParser
This is a cleanup and minor performance tweak that should not change any semantics.

Closes https://github.com/dart-lang/sdk/pull/54255

GitOrigin-RevId: b9a9c6d341eb3e422fc3ec4a008fdbe2b89ade07
Change-Id: Id9f9ef2c1e8f49f5c10cbff5864f020f5e78cfee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340200
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2023-12-12 18:25:19 +00:00
Ryan Macnak 1256db2277 [build] Python 3.12 compatibility.
Bug: https://github.com/dart-lang/sdk/issues/54306
Change-Id: I974e5e70c6c1cbb87343139a26052996d8df858f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341023
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-12-12 18:19:35 +00:00
Martin Kustermann bdefe5fa7e Move Wasm{Object,Int,Float}Array -> WasmArray, use extensions on WasmArray for static dispatc0h
The dart2wasm compiler treats wasm arrays of objects/ints/floats pretty
much the same, there's no reason to have complicated class hierarchy and
different kinds of wasm array classes.

Also: We rely on all operations on wasm arrays (and other built-in
types) to be handled on the call site. Wasm arrays are not dart objects,
don't support virtual dispatch. So we make operations operating on the
wasm types extensions.

This also makes now loads and stores into the wasm arrays simple `[]` and
`[]=` operations. We still have special extensions for reading/writing
to integer/double arrays that not only read/write but also
sign-extend/zero-extend and operate on Dart's `int` / `double`.

The compiler will allow `WasmArray<X>(length)` for types `X` that have
default-value in wasm arrays (nullable / integer / double types) and
have another `WasmArray<X>.filled(length, X)` for non-nullable reference
types.

Overall this reduces LOCs and simplifies things

Change-Id: I885bed3dfd1c602dc7b0747c69927d464376383d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340881
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-12-12 17:05:49 +00:00
Sergey G. Grekhov 0334fea865 [doc/async] Change StreamController.broadcast() doc according to the current behavior
Bug: #29403
Change-Id: I9ef53b3c4e039bdc84d4cdfa9e306efb6eb0ffba
CoreLibraryReviewExempt: Documentation-only change
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340860
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-12-12 13:08:56 +00:00
Sergey G. Grekhov 911f7edc5f [doc/async] Change Stream.asyncMap doc according to the current behavior
Bug: #29615
Change-Id: I74309b9a488999bc73efa4c0a2310261da74c879
CoreLibraryReviewExempt: Documentation-only change
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340402
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-12-12 11:10:55 +00:00
Srujan Gaddam e6a313568c [dart:js_interop] Add generics to JSArray and JSPromise
In order to support this, adds necessary changes to conversion
functions (including cast-lists) and makes JSArrayImpl a generic
type.

CoreLibraryReviewExempt: Backend-specific library changes.
Change-Id: I58bcfb67ef21c90be5e25735757d780aac52dc23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337923
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-12-12 04:50:13 +00:00
Brian Quinlan f494e771a2 [doc/io] Add a strong caution against using HttpClient and HttpRequest directly.
CoreLibraryReviewExempt: documentation-only change
Bug:https://github.com/dart-lang/sdk/issues/52023
Change-Id: I9d4b4bde676f2c85acb95e872fdaf7b5a92c6de5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340283
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2023-12-12 00:45:45 +00:00
Martin Kustermann 72f6db9261 Use WasmObjectArray instead of List in RTT metadata
This reduces flute's complex.dart slightly

  complex.wasm 1596131 -> 1563506 (-2%)
  complex.wasm.unopt 3562573 -> 3535797 (-0.7%)

And makes the code probably slightly faster

Change-Id: Id35f2b156d39b6e77b62240a83f78914999bb744
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340565
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-12-11 12:24:04 +00:00
Nate Biggs f057c39255 [dart2js] Add dartDeferredLibraryMultiLoader API to js_helper.
This will allow users who are implementing their own deferred loading mechanism
to batch all the loads for a specific library. Today in order to do batching users have to gather the URIs passed to the `dartDeferedLibraryLoader` hook in a list and schedule (e.g. via setTimeout) a load for some future task.

The need to schedule a task has been shown to cause delays in IPL. But loading each part file individually can also be very expensive. So this allows for a compromise where bundling can be done synchronously per loaded library.

Adds ~8kB to unminified main files and ~2.5kB to minified main files.

Bug: https://github.com/dart-lang/sdk/issues/54202
Change-Id: I623643b03920988cda8b0f8b297944be35ffa606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340480
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2023-12-08 21:10:48 +00:00
Martin Kustermann e0485a4fc0 Make _FunctionType fields use WasmObjectArray instead of List
This reduces flute's complex.dart slightly

  complex.wasm: 1601793  -> 1596131 (-0.35%)
  complex.wasm.unopt: 3570856 -> 3562573 (-0.23%)

And makes the code probably slightly faster

Change-Id: I5b5cb8f95509930ce23c7d4bc0385740ad9f429b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340562
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-12-08 18:48:00 +00:00
Ömer Sinan Ağacan 7cceaebd49 [dart2wasm] Start using WebAssembly.String imports
Refactor `JSStringImpl` to use the js-string-builtins API[1].

When the module `WebAssembly.String` is not available we define a
"polyfill" with the previous imports, so this change is backwards
compatible.

Also updates some of the methods to use avoid multiple `this.length`
calls (which do an FFI call), and use unchecked getters when possible.

A new library `dart:_error_utils` is introduced for faster range and
index checks when the length (or max value) is known to be positive
(e.g. when it's the length of a string).

For now only `JSStringImpl` and `operator []` and `operator []=` of
`JSArrayImpl` are updated to use the new range and index checks. Rest of
the libraries will be updated separately.

[1]: https://github.com/WebAssembly/js-string-builtins

CoreLibraryReviewExempt: dart2wasm specific library change.
Change-Id: I9436def0cfe59c631f6f4e15ea06cc18a47a738e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335043
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-12-08 10:04:41 +00:00
Alexander Markov fe2ea6a55f [vm] Add minimal support for mirrors of extension type members
Support extension type members in dart:mirrors similarly to extensions.
Add MethodMirror.isExtensionTypeMember and VariableMirror.isExtensionTypeMember.

TEST=tests/lib/mirrors/method_mirror_extension_test.dart
Fixes https://github.com/dart-lang/sdk/issues/54266

CoreLibraryReviewExempt: VM-only dart:mirrors API change
Change-Id: I9c1c22118ee52e98d5013c881eb6ad5686df656e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340284
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-12-07 21:48:50 +00:00
Parker Lougheed 0cc7b25fbf [sdk] Fix broken markdown in future.dart dartdoc
The unclosed code block isn't useful and causes GitHub to improperly highlight the rest of the file.

CoreLibraryReviewExempt: Just fixing Markdown rendering error. No code change.
Change-Id: I2d1e1fa494deb80caa15f846ded6d822bdaf6e7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340360
Reviewed-by: Marya Belanger <mbelanger@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Marya Belanger <mbelanger@google.com>
2023-12-07 17:34:14 +00:00
Aske Simon Christensen e0ccd5341d [dart2wasm] Cache the length of JS typed arrays and ByteData
This improves most benchmarks in the TypedData suite by more than 2x
and TypedDataCopy.ByteSwap by 1.5x.

Change-Id: Icf611471b4edffeedaefe9480a25724ce6571d8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340420
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-12-07 11:23:28 +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
Aske Simon Christensen d58f1ec00f [dart2wasm] Dispatch type checks to avoid creating runtime type
Change-Id: I4ae9ffa7fa030e0a893178b8061f568e69a7bd79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336903
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-12-06 10:04:01 +00:00
Simon Binder a44a524bb0 [vm/ffi]: Add Native.addressOf
This adds the `Native.addressOf` function, which takes a constant tear-
off of a method annotated with `@Native` as a parameter and returns a
pointer to the underlying C function.

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

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

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

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-kernel-precomp-linux-release-x64-try
CoreLibraryReviewExempt: VM & dart2wasm only feature
Change-Id: Ic8e3a390146dffd44c95578f975a4472db79a0ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333920
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-12-05 13:10:36 +00:00
Tess Strickland 7ffb8574ee [vm] Ensure element type is checked for typed data setRange calls.
In c93f924c82, the separate setRange definitions in _TypedIntListMixin,
_TypedDoubleListMixin, _Float32x4ListMixin, _Float64x2ListMixin, and
_Int32x4ListMixin were replaced with a single definition in
_TypedListBase. In doing so, the signature was changed: now the `from`
argument is just an Iterable, instead of the more specific
Iterable<int>/Iterable<double>/etc in the original definitions.

setRange calls two helper methods, _fastSetRange, when from is also a
_TypedListBase whose elements are the same size, and _slowSetRange, for
all other cases.

In _slowSetRange, various casts and checks ensure that the setRange
method was called with a compatible element type, but _fastSetRange only
checks the _size_ of the element type, not the element type itself,
before doing a memory move between the two _TypedListBase objects. That
means via upcasting, elements can be copied from an argument with an
incompatible element type to the receiver, which would have resulted in
a TypeError being thrown before.

Change the unified setRange definition to _setRange and recreate the old
separate setRange definitions with the more specific signatures, with
the separate definitions delegating to _setRange.

TEST=vm/dart/regress_53945

Fixes: https://github.com/dart-lang/sdk/issues/53945
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try
Change-Id: If7eef0b2e07c63aaf776de7b26b1c2cc8c57607d
Fixed: 53945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334201
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-12-04 16:20:50 +00:00
Ömer Sinan Ağacan fc4b352f2d [dart2wasm] Use unsigned comparison in list bounds checks
In typed data classes we've found that this optimization in bounds
checks can be quite significant. This does the same optimizations in
List classes.

Change-Id: Ia6e80d5aafa621398ed7b7175be8794838e82b89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337725
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-12-04 09:58:17 +00:00
Ömer Sinan Ağacan 3f3e4264e2 [dart2wasm] Use browser decoder when possible in non-JSCM mode
- Move `TextDecoder` code to decode JS `Uint8Array`s as UTF-8 to its own
  module `dart:_js_string_convert`.

- Use the module in default mode (non-JSCM) `dart:convert` when decoding
  JS `Uint8Array`s.

Change-Id: I6921b2a99c37ec8920ab79482228ede777bf2b4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338520
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-12-01 09:36:41 +00:00
Vyacheslav Egorov 6249b7ed34 [vm/compiler] Clean up typed data stores
Implementation of stores and their inlinings had some
stuff left over their since Dart 1:

* No need to insert null-checks (in sound null-safety mode).
* Since Dart 2 there is no need to insert (speculative)
cid checks. Inputs are guaranteed to be a value of a
supported implementation type. Inserting narrow speculative
checks for Smis is actually leads to worse code in JIT.
* There is no need to convert incomming integer values to
smaller representation - the store will take care of it. This was
left over from Dart 1 times when incomming integer could be _Bigint.

TEST=existing tests

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-release-arm64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv64-try,vm-aot-android-release-arm_x64-try,vm-aot-android-release-arm64c-try
Change-Id: I72cdaaecc524f1dccc63825df4f7b71241ab47a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338600
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-11-29 09:26:14 +00:00
Ömer Sinan Ağacan f67b219f0f [dart2wasm] Return JS string in StackTrace.current
Avoid copying JS string to Dart.

The test co19/LibTest/convert/Latin1Codec_A01_t01 throws a lot of
exceptions. Before this patch it runs in d8 in 4.1s, after it runs in
1.5s.

Change-Id: I1b9bf06876d63e92c93a03cdbf14587e369978ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338400
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-11-29 08:32:08 +00:00
Ömer Sinan Ağacan 0e0dd31f7e [dart2wasm] Fix stack trace to string conversion on Firefox
Change-Id: I602200cd0b4f0e4836b4ef1dbd6ffbe3953b4849
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338000
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-11-27 15:35:27 +00:00
Erik Ernst efe3d00dcd Adjust internal hash_map libraries to match updated UP
SDK issue #54002 is a breaking change request about a change to the
rules about the type function `UP`. This CL serves as a preparation
for landing the tool changes that are the topic of #54002. It changes
a few conditional expressions such that one branch gets an explicit
type based on an `as` expression, which means that the code has the
same semantics as before the change, but now it will compile without
errors both before and after the change in #54002 has been landed.

Change-Id: Iddc99c1c184c1f36744d089c15c5cf29aea699df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337780
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-11-23 12:34:07 +00:00
Ömer Sinan Ağacan cba120dbac Remove Utf8Decoder._convertIntercepted hook
Fixes #54018.

Tested: existing tests.
Change-Id: I0d0cbc414a239bfc00c023ac8b9313c6f413ba83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337540
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-11-23 12:25:26 +00:00
Ömer Sinan Ağacan bf733de31d [dart2wasm] Store the backing array in fixed-size list iterator
Store the Wasm array instead of the List to remove one layer of
indirection when accessing the next element.

We can't do the same in growable list iterator as we need to check
whether the list's length has changed, to be able to throw
`ConcurrentModificationError`.

Change-Id: Iac0fd43dc0c0d249973301903dd34c46fff440f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337721
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-11-23 11:22:20 +00:00
Daco Harkes 47357d8535 Reland "[vm/ffi] Optimize @Native calls"
Original change in patchset 1.

The reland contains a fix for handles. The objects passed in handles
must live on the stack (or in the heap) so that that memory location
can be used as a handle.

This CL introduces a new allocation policy `RequiresRegister` which
forces constants to be spilled to the stack during register
allocation.
Note: Parameters to FfiCall instructions are currently not used in a
way that can make the parameters assigned to registers. So only
constants are treated currently. If we have a way to reproduce params
being assigned to registers, then we can force spilling for
non-consts as well in the register allocator.

Original change's description:
> [vm/ffi] Optimize `@Native` calls
>
> This CL removes static fields for storing the `@Native`'s function
> addresses. Instead, the function addresses are stored in the object
> pool for all archs except for ia32. ia32 has no AOT and no AppJit
> snapshots, so the addresses are directly embedded in the code.
>
> This CL removes the closure wrapping for `@Native`s. Instead of
> `pointer.asFunctionInternal()()` where `asFunction` returns a closure
> which contains the trampoline, the function is compiled to a body
> which contains the trampoline `Native()`. This is possible for
> `@Native`s because the dylib and symbol names are known statically.
>
> Doing the compilation in kernel_to_il instead of a CFE transform
> enables supporting static linking later. (The alternative would have
> been to transform in the cfe to a `@pragma('vm:cachable-idempotent')`
> instead of constructing the IL in kernel_to_il.
>
> To enable running resolution in ia32 in kernel_to_il.cc, the
> resolution function has been made available via
> `runtime/lib/ffi_dynamic_library.h`.
>
> Because the new calls are simply static calls, the TFA can figure
> out const arguments flowing to these calls. This leads to constant
> locations in the parameters to FfiCalls. So, this CL also introduces
> logic to move constants into `NativeLocation`s.

TEST=tests/ffi/vmspecific_ffi_native_handles_test.dart
TEST=tests/ffi/function_*_native_(leaf_)test.dart
TEST=pkg/vm/testcases/transformations/ffi/ffinative_compound_return.dart

Closes: https://github.com/dart-lang/sdk/issues/47625
CoreLibraryReviewExempt: Internal FFI implementation changes
Change-Id: Ia1401b335524dcbf50c663a8770d9a02802923df
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333841
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-11-22 16:13:42 +00:00
Stephen Adams 3f2432f36c [js_runtime] Utf8 - reuse buffer to avoid creating many small buffers
Allocating typed data on Chrome is surprisingly expensive
(e.g. https://bugs.chromium.org/p/v8/issues/detail?id=9199).  This
makes it worthwhile to keep a buffer around for reuse rather than
allocating a new one for each conversion that requires copying.

Change-Id: I8b2823f487cd8b869fc8b22f309490475c7c010d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337462
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2023-11-21 22:40:10 +00:00
Ömer Sinan Ağacan 7f5cba2e53 [dart2wasm] Stop using Utf8Decoder._convertIntercepted
Issue: #54018.

Change-Id: Ic8ee663f45acc3ae0300cdd3f1cbb9132110c6f3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337481
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2023-11-21 11:18:12 +00:00
Ömer Sinan Ağacan dd8952f575 [dart2wasm] Avoid bounds check in some dart:convert functions
Also improves `codeUnitAt` bounds checks by using unsigned comparisons.

`package:characters` benchmarks before:

    Index Iteration: 23316 gc/ms
    String Iteration: 15329 cu/ms
    String Reversing: 6974.1 cu/ms
    String Replacing: 222.88 changes/ms

After:

    Index Iteration: 29729 gc/ms
    String Iteration: 17923 cu/ms
    String Reversing: 7270.9 cu/ms
    String Replacing: 236.28 changes/ms

Change-Id: I36832206b99ba9704e6e5863028d7eaa76412c3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337181
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2023-11-21 10:51:50 +00:00
Stephen Adams 00dc14d6d6 [js_runtime/js_dev_runtime] Stop using Utf8Decoder._convertIntercepted.
- Share Utf8Decoder patch between DDC and dart2js
- Don't use the `_convertIntercepted` hook
- Provide improved `_Utf8Decoder.{convertSingle,convertChunked}` methods that copy the input if not a Uint8Array, and use a TextDecoder if available

Issue: #54018
Issue: b/308643579

Change-Id: I6a37f77280e4e1a97086874dd3b03f1a20552938
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335660
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-11-21 00:01:46 +00:00
Daco Harkes df4ef72c01 [vm/ffi] Remove deprecated FfiNative
TEST=pkg/analyzer/test/
TEST=CI build with class removed from `dart:ffi`

Closes: https://github.com/dart-lang/sdk/issues/53923
CoreLibraryReviewExempt: VM & dart2wasm only.
Change-Id: I45a39b623754f9f1b65cac55ea9adae390199f5d
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm64c-try,analyzer-analysis-server-linux-try,analyzer-mac-release-try,dart-sdk-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336960
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-11-20 13:16:28 +00:00
Olzhas Suleimen 5918e012cc Fix close drain error callback.
Closes https://github.com/dart-lang/sdk/pull/54020

GitOrigin-RevId: c9791a23035d980665dba73927d2a5bed2be861b
Change-Id: Id70d6d42f2460fa6c853fb334167a67d00f8ef8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335506
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-11-20 08:03:39 +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
Tess Strickland 904354f108 [vm/compiler] Convert index checks in TypedData methods to CheckBound.
Create a _typedDataIndexCheck abstraction for the conditional throwing
of IndexError in TypedData indexing operations. Recognize that
abstraction in the inliner and replace it with the equivalent CheckBound
instruction.

Do the same for byte offset checking in ByteData operations.

TEST=vm/dart/typed_list_index_checkbound

Change-Id: Ia6c4a3b7ae4667af69aa5bf214d4f187557dac06
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-linux-debug-x64-try,vm-eager-optimization-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330800
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-11-17 15:35:42 +00:00
Lasse R.H. Nielsen a1783a9c34 String.fromCharCodes allows start and end after end of iterable.
The current `String.fromCharCodes` behavior, throwing if `start`
or `end` is larger than the length of the `charCodes` iterable,
is inconsistent with the argument being an `Iterable<int>`,
which the user is not expected to know the length of.

Most other operations that accepts or produces an `Iterable` and
restricts it to a range, will allow the range to exceed the length
of the iterable, acting like `.take(end).skip(start)`, just without
needing to create wrappers that hide the original value.

(`List.setRange` is another exception, and should probably be fixed
by allowing the range to be partially filled, since it's too hard
to change it to require a `List` argument.)

Fixes #50253, #53937

Tested: Added to `corelib/string_fromcharcodes_test.dart`
Bug: https://dartbug.com/53937, https://dartbug.com/50253, https://dartbug.com/23282
Change-Id: Ie19c5fa8e715ea1c58c9c77c247f2a563654c1aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333921
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2023-11-17 13:34:22 +00:00
Lasse R.H. Nielsen 5543293a16 Reland "Expire 3.0.0 experiment flags."
This is a reland of commit 6f29e7fce4

Original change's description:
> Expire 3.0.0 experiment flags.
>
> TEST=Existing tests covers.
> Change-Id: I161eefdc28c74f63ba1ee926800a01eea03d9930
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331960
> Commit-Queue: Lasse Nielsen <lrn@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>

TEST=Existing tests covers.
Change-Id: I384e77744c74774a250be413358a7fa176117167
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332684
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-11-17 13:10:01 +00:00
Aske Simon Christensen 4b880aec60 [dart2wasm] Avoid using _Closure as a type
`_Closure` is the implementation class for function objects. When used
as a type, it translated to the same Wasm type as the `Function` type,
but in the type system it missed the special property of `Function`
that it is a supertype of all functions. Instead, it was translated
into an interface type, leading to incorrect type check results.

Thus, we must always use the `Function` type when referring to any
function.

The problem was hidden by the type check specialization for simple
interface type checks and exposed by `--verify-type-checks`.

Change-Id: I384d35506c0c8cd932ba789e977f8257e684b8d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336423
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2023-11-16 15:04:58 +00:00