1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-08 20:16:39 +00:00
Commit Graph

11202 Commits

Author SHA1 Message Date
Ömer Sinan Ağacan
fbbb836a02 [stable] Fix various dart2wasm async and sync* bugs and missing feats
This cherry-picks commits:

6de879e0f5 - [dart2wasm] Fix exception handling in async functions
7e237a12aa - [dart2wasm] Small refactoring in async code generator
eabb2b3aca - [dart2wasm] Catch JS exceptions in async functions
e44bc22ca3 - [dart2wasm] Fix bug in restoration of `this` in async functions.
350954ae9d - [dart2wasm] Fix `this` restoration code in sync* handling.
8ccb41284a - [dart2wasm] Move type parameter bounds checks & parameter type check logic together with logic setting up variables
e7dde8377e - [dart2wasm] Port VM fix for #52083 (sync*)
3863e78e80 - [dart2wasm] Move yield finder to a shared library
829261e2ba - [dart2wasm] Move async compiler utilities to state_machine library
fab56db71b - [dart2wasm] Move common code generation routines to state_machine, fix sync*

Bugs: #55347, #55457, #51343, #51342
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/368300
Cherry-pick-request: https://github.com/dart-lang/sdk/issues/55847
Change-Id: I0a4186533fbdf4c5727911295ad48696a90f715f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368300
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-05-29 08:01:49 +00:00
Ben Konyi
66b9bf5ef8 [beta] [ Service ] Include drive letter in path when launching DDS snapshot
The previous logic for building the path to dds.dart.snapshot would result
in the Windows drive letter being dropped from the path:

\path\to\dart-sdk\bin\dds.dart.snapshot

This works most of the time since a leading slash is treated as a reference
to the current drive, which often contains the Dart SDK. However, if the SDK
is on a different drive than the current (e.g., in a container with two drives),
the VM will fail to find the snapshot.

This change uses the File(...) APIs from dart:io to build the path rather than
trying to use the Uri class to manually hack together a path.

TEST=N/A, not reproducible without a second Windows drive

Bug: https://github.com/grpc/grpc-dart/issues/697
Change-Id: I71d00b07a98508a780f5aab76417da4aa530f3c4
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/360920
Cherry-pick-request: https://github.com/dart-lang/sdk/issues/55386
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361400
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-04-12 14:45:49 +00:00
Daco Harkes
0bcb0c934d [vm/ffi] Add _Compound _offsetInBytes field
This CL changes compounds (structs, unions, and arrays) to be backed
by a TypedDataBase and an int offset.

Before this CL, the compounds where only backed by a TypedDataBase.
This leads to the following issues:

1. Access to nested structs required code for allocating new typed data
   views or pointers, which the optimizer then had to prevent from
   being allocated after inlining.
2. Runtime branching on whether the TypedDataBase was a Pointer or
   TypedData increased code size and prevented inlining.
   https://github.com/dart-lang/sdk/issues/54892
   This could not be properly optimized if in AOT both typed
   data and pointer were flowing into the same compound.
3. Constructing TypedData views required calculating the length of the
   view.

After this CL, accessing nested compounds will lead to accesses on the
original TypedDataBase with an extra offset.

This removes the polymorphism on TypedData vs Pointer, because the
final int/float/Pointer accesses in nested compounds operate on
TypedDataBase.

Also, it simplifies creating an `offsetBy` accessor, because it will
no longer have to be polymorphic in typed data vs pointer, nor will it
have to calculate the length of the field.

Implementation details:

* The changes in the CFE and patch files are straightforward.
* VM: Struct-by-value returns (or callback params) are initialized
  with an offsetInBytes of 0.
* VM: Struct-by-value arguments (and callback return) need to read out
  the offsetInBytes. Before this CL we were passing in the TypedData
  as tagged value. With this CL we are passing the TypedData as tagged
  value and the offset as unboxed int, from 1 IL input to 2 IL
  inputs. (The alternative would have been to take the compound as
  a tagged value, but that would have prevented optimizations from not
  allocating the compound object in the optimizer.
  The FfiCallInstr is updated to have two definitions for the case
  where we were passing in the TypedData previously.
  The NativeReturnInstr is refactored to be able to take two inputs
  instead of 1. (Note that we don't have VariadicInstr only
  VariadicDefinition in the code base. So the instruction is _not_
  implemented as variadic, rather as having a fixed length of 2.)
* dart2wasm does no longer support nested compounds due to the
  compound implementation only storing a pointer address.
  https://github.com/dart-lang/sdk/issues/55083

Intending to land this after
https://dart-review.googlesource.com/c/sdk/+/353101.

TEST=test/ffi

CoreLibraryReviewExempt: VM and WASM-only implementation change.
Closes: https://github.com/dart-lang/sdk/issues/54892
Bug: https://github.com/dart-lang/sdk/issues/44589
Change-Id: I8749e21094bf8fa2d5ff1e48b6b002c375232eb5
Cq-Include-Trybots: dart-internal/g3.dart-internal.try:g3-cbuild-try
Cq-Include-Trybots: 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-x64-try,vm-aot-win-debug-x64c-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-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/+/354226
Reviewed-by: Tess Strickland <sstrickl@google.com>
2024-03-26 17:14:13 +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
Brian Quinlan
97d8445e5f Revert "[io] Fix a bug where Process.stdin.add exceptions could not be caught"
This reverts commit 9967075787.

Reason for revert: Ignoring `done` is asymmetrical with other IOSinks.

Original change's description:
> [io] Fix a bug where Process.stdin.add exceptions could not be caught
>
> Change-Id: I2383a74bfa6950ab8f8934087fb68218f06dd681
> Bug:https://github.com/dart-lang/sdk/issues/48501
> Tested: Unit test
> CoreLibraryReviewExempt: dart:io only
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351380
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Commit-Queue: Brian Quinlan <bquinlan@google.com>

Bug: https://github.com/dart-lang/sdk/issues/48501
Change-Id: Ib5356c640d4dddc30e561b9d60d93f794a935103
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359680
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2024-03-25 21:03:12 +00:00
Alexander Markov
b771c6f45d [vm/corelib] Remove intermediate _getIndexed/_setIndexed methods from typed data
This change aligns all typed data implementations with Int8 typed data
and allows compiler to recognized and replace typed data access
operations earlier, before method inlining. Consequently, this increases
chances for [] and []= to be inlined. In JIT, this also prevents
non-inlined calls to _getIndexed/_setIndexed as [] and []= are graph
intrinsics which bypass calls to _getIndexed/_setIndexed.

TEST=ci

Change-Id: I95a85963da07fd1c04c06e0af09f76eb15f93353
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359520
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-03-25 20:06:40 +00:00
Srujan Gaddam
47f08fb143 [dart:js_interop] Change several operators back to JSBoolean
Related issues:
https://github.com/dart-lang/sdk/issues/55024
https://github.com/dart-lang/sdk/issues/55267

These operators were initially broken in 3.3 and were exposed
as returning JSBoolean but implemented as returning bool. They
were fixed to return bool in the public API, but we should
prefer to have them return JS types as they're likely to be used
in cases where implicit conversions are not useful.

CoreLibraryReviewExempt: Fixing type mismatch in backend-specific library.
Change-Id: I3b0e60550dcac78918f8399d11238dcfa34982cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359180
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-03-25 17:05:36 +00:00
Alexander Markov
35d8630176 [vm] Make String.codeUnitAt monomorphic
The new implementation of String.codeUnitAt is always inlined and
doesn't depend on the polymorphic inlining of recognized methods.

String.codeUnitAt now has a custom body in the flow graph builder
which  performs non-speculative bounds check and then branches between
OneByteString and TwoByteString. Corresponding graph intrinsic and
native method are removed.

This change also fixes passing of unboxed arguments to runtime
in the slow path of GenericCheckBound instruction in JIT mode
(when shared stubs are not used).

TEST=ci

Change-Id: Iab2805fc752df84c37089165f828e31aca5f043f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359000
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-03-24 14:50:17 +00:00
Tess Strickland
0d3ade255b [vm/compiler] Limit exposure of untagged pointers to managed memory.
After https://dart-review.googlesource.com/c/sdk/+/330600, there were
more chances for the optimizing compiler to introduce or move
GC-triggering instructions like allocations or boxings between the
retrieval of an untagged pointer to GC-moveable memory and its use.

To limit the chance of this happening, this CL removes the explicit
loading of the untagged payload address when building the initial
flow graph in most cases when the array is not known to be an external
array (an external string, an external typed data object, or an FFI
Pointer).

The remaining case is during view allocation, which extracts the
payload address of the base typed data object underlying the view
(which may be GC-movable) to calculate the payload address that should
be stored in the data field of the view object. See
https://github.com/dart-lang/sdk/issues/54884.

During canonicalization of LoadIndexed, StoreIndexed, and MemoryCopy
instructions, if the cid of an array input is an external array
(external string, external typed data object, or Pointer), then a
LoadField instruction that extracts the untagged payload address
is inserted before the instruction and the corresponding input is
rebound to that LoadField instruction.

Once all compiler passes that involve code motion have been performed,
a new pass looks for LoadIndexed, StoreIndexed, or MemoryCopy where
the cid stored in the instruction for the array is a typed data cid.
In these cases, if the array is not an internal typed data object,
then the payload address is extracted. Waiting until this point ensures
that no GC-triggering instructions are inserted between the extraction
of the payload address and the use. (Internal typed data objects are
left as-is because the payload address is inside the object itself
and doesn't require indirection through the data field of the object).

This CL also replaces code conditional on the array cid with code
that is instead conditional on the array element representation in
cases where it makes sense to do so, since this is a less brittle
check than checking the array cid (e.g., checking for kUnboxedInt8
to load, store, or copy an signed byte from an array instead of
listing all possible array cids that store signed bytes).

This CL also fixes an issue with the ARM64 assembler where calling
LoadFromOffset with an Address that has a non-Offset type would
silently generate bad code instead of triggering the ASSERT in
PrepareLargeOffset.

TEST=vm/dart/typed_list_index_checkbound_il_test

Issue: https://github.com/dart-lang/sdk/issues/54710
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-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-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-release-ia32-try
Change-Id: I25b5f314943e9254d3d28986d720a5d47f12feeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352363
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-22 10:12:39 +00:00
Ben Konyi
6eb85949fd [ VM / DDS ] Add --print-dtd-uri flag and launch DTD from the correct snapshot for AOT
This adds support for printing the DTD connection information to stdout
when --print-dtd-uri is passed.

This change also fixes an issue where DDS would fail to spawn an isolate
with the DTD snapshot when DDS was running in AOT mode. This means the
SDK must be shipped with both AppJIT and AOT DTD snapshots, at least
until dartdev is moved to run from AOT.

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

TEST=run_test.dart

Change-Id: I788ef9bfe76297a8d594992a2aac440ed9e2ecac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358541
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Kenzie Davisson <kenzieschmoll@google.com>
2024-03-21 19:50:46 +00:00
Vyacheslav Egorov
df80cf9140 [core] Improve JSON decoding performance
Avoid polymorphic character access by turning _ChunkedJsonParser
into a mixin instead of the base class.

TEST=ci

Change-Id: Id2080724e07d16e96734a80629c8bd8906dc590b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358445
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-03-21 11:10:10 +00:00
Jake Macdonald
25071fc448 revert dart:_macros, going with SDK vendored package
Change-Id: Iaaf80a44cdbd073b01132d04c0426e8acc28341f
Tested: Revert only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358501
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Jacob Richman <jacobr@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
2024-03-21 02:40:58 +00:00
Nate Biggs
53957bf74d [dart2js] Update async* helper to check if stream closed state before re-entering generator body.
If the stream has been closed then re-enter with the appropriate error code.

Bug: #55017
Change-Id: Iadf5d039698a48d402a409b5b42ed268885439d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355040
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-03-20 20:56:44 +00:00
Alexander Markov
17d6ba15b6 [vm] Remove external strings
This change removes support for external strings from the VM along with
Dart_NewExternalLatin1String, Dart_NewExternalUTF16String and
Dart_IsExternalString Dart C API functions.

External strings are not used by the VM nor any known embedder, but
Dart VM was paying the maintenance and performance price for
the external string implementation classes.

TEST=ci

Change-Id: I094cd2d2b7ec0840e9f09e1ca9e5a7acd4e78c28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358760
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-03-20 20:08:13 +00:00
Ömer Sinan Ağacan
44c2e17600 [dart2wasm] Update built-in string imports according to the latest spec
Spec: https://github.com/WebAssembly/js-string-builtins

Change-Id: Idb387e6dd27b203ddca52291c44fb2aa15ee75cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357560
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-19 08:20:59 +00:00
Kenzie Schmoll
408918d6f5 [dds] Start DTD from DevTools server if it is not already started.
Fixes https://github.com/dart-lang/sdk/issues/54937.

Tested: pkg/dartdev test for `dart devtools` command, and new `dtd_test.dart` in pkg/dds.
Change-Id: I530ba2fe4d5809082378b61c282ba7856974e21e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354460
Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Dan Chevalier <danchevalier@google.com>
2024-03-18 21:50:09 +00:00
Brian Quinlan
c771931f6b [doc, io] Document the error behavior for File.openRead/file.openWrite
I recently fixed a bug by adding a `sink.done.ignore()` into library code: https://dart-review.googlesource.com/c/sdk/+/351380

My thinking now is that is a bad idea because it allows errors to pass silently if the sink is not closed or flushed (and the results are awaited!). Instead, we should document this as a general pattern for sinks.

...but that isn't satisfying either. `sink.done.ignore()` really means "I promise that I will handle errors elsewhere" but there is no actual enforcement of that.

Bug:https://github.com/dart-lang/sdk/issues/54707
Change-Id: I92feb43b1b2c57933c2343f4b6d354792cd13d72
CoreLibraryReviewExempt: dart io documentation-only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352442
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-03-14 22:43:32 +00:00
asiva
9f951f7fb5 [VM / vmservice] Run service isolate in sound null safe mode (JIT)
TEST=ci
CoreLibraryReviewExempt: No files in other platforms were changed.
Change-Id: I567dae64226867c2036809739a14c14fdf52077b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357211
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-03-13 17:56:49 +00:00
Ömer Sinan Ağacan
12859761b9 [dart2wasm] Implement _SecureRandom._getBytes
This only changes `_SecureRandom._getBytes` to make the rest of the code
work. Implementation is currently slow: for each random number
generation, it allocates one JS `Uint8Array`, and because we can't
directly read from a JS `Uint8Array` using `dart:js_interop`, a Dart
`Uint8List` wrapper for it. We can optimize separately.

Fixes #55031.

Fixes test lib/math/random_secure_test on browsers. The test keeps
failing in d8 as d8 doesn't define the `crypto` object.

Change-Id: I9d6bbd1bb576c0d0b7206cb2939ee65d987ec297
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356040
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-12 21:26:51 +00:00
Martin Kustermann
bca5e833cb [vm/wasm] Make HashMap<K, V> use non-generic _HashMapEntry object
TEST=ci

Change-Id: Ifef2ef8859a037cd2830182520e6d19cb9b2281e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357142
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-03-12 14:36:38 +00:00
Martin Kustermann
4b9dd9d586 [dart2wasm] Force-inline the List.[] List.[]= operations
Right now the _ListBase.[] looks like this in -O4 mode:

  (func $_ListBase.[] (param $var0 (ref $Object))
                      (param $var1 i64)
                      (result (ref null $#Top))
    local.get $var0
    ref.cast $_ListBase
    struct.get $_ListBase $field4
    local.get $var1
    i32.wrap_i64
    array.get $Array<Object?>
  )

Binaryen doesn't inline this because it thinks its too big. Though we'd
really want reads/writes to fixed length lists to be inlined.

For typed data we already have `@pragma('wasm:prefer-inline')`
annotations so it makes sense to also do this here.

Change-Id: I3e976d98717df6e60e9de133dec37d10cd1b9097
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357140
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-03-12 13:57:29 +00:00
Ben Konyi
d440c020f8 [ Service ] Fix --write-service-info on Windows
Uri.parse(...) interprets the Windows drive letter as a scheme, which
causes File.fromUri(...) to throw an exception when it calls
Uri.toFilePath(). Using the File(...) constructor correctly handles
Windows drive letters.

Partly fixes https://github.com/dart-lang/sdk/issues/55133

TEST=pkg/dartdev/test/command/run_test.dart

Change-Id: Ie8c761289f1126491f4c2266b48922310df5d8da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356261
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
2024-03-11 20:16:08 +00:00
Ben Konyi
d58f6a1ce3 [ DDS ] Create an arg parser for the DDS snapshot
Preparation for shipping DDS as part of the SDK instead of as a Pub
package.

TEST=Existing VM service, DDS, and dartdev tests

Change-Id: I38ec47f4ebf003d3d3c813af40a313403f23280c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356580
Reviewed-by: Derek Xu <derekx@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2024-03-11 19:54:47 +00:00
Lasse R.H. Nielsen
06d6ef38a9 Fix bug in Uri.resolve with IPv6 addresses.
The `resolve`/`resolveUri` operation would take the
`.host` of the URI reference and include it verbatim
in the output. Since the `.host` getter returns IPv6
addresses *without* their `[`...`]` braces, that would
become invalid.

Also make sure to normalize the parts of the URI reference
that are used, if it is not a platform URI.

Fixes #55085

BUG= https://dartbug.com/55085

Change-Id: I3dbc8af953af0974346e38ba3203796647069ea8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355781
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Auto-Submit: Lasse Nielsen <lrn@google.com>
2024-03-11 14:48:24 +00:00
Martin Kustermann
fd954d426f [dart2wasm] Better handling of list/map/set literals
If the literals are

* empty: call function with zero arguments
* non-empty: call function taking `WasmArray<Object?>`

=> This avoids making a call for each element we add.

Reorganize the map/set mixins:

* pull out the `createIndex` into it's own mixin
* make mutable set/map implementations use that mixin
* remove compiler-knowledge about how to create hash mask
  (instead set the hashmask field in `_createIndex()`)

=> Function creating map/set from `WasmArray<Object?>` can create index
=> Allows the above

Outline functions (for now only for list/map/set literal creation
functions):

* Often many call sites use literals with instantiated types
* Make outlined functions that will populate those instantiated types
  and forward the arguments

This turns e.g. `<A, B>{}` (if `A`/`B` are instantiated, e.g. `int`)

  global.get A
  global.get B
  call _WasmDefaultMap._default

into

  call createEmpty<A, B>

  createEmpty<A, B>:
    global.get A
    global.get B
    call _WasmDefaultMap._default


All together this

* reduces flute size by a bit more than 0.5%
* makes some benchmarks faster

Change-Id: I13c7e6060470d74769a3d49816671aceb2cd3aab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356500
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-03-11 13:07:47 +00:00
Derek Xu
f7c2ef5bb8 Account for changes to package:http_profile in _createHttpProfileRequestFromProfileMap
See the changes made to http_client_request_profile.dart in
https://github.com/dart-lang/http/pull/1154/files

TEST=The "using HttpClientRequestProfile.requestData.bodySink" and
"using HttpClientRequestProfile.responseData.bodySink" test cases in
package:http_profile

CoreLibraryReviewExempt: This CL does not include any API changes, only
implementation changes
Change-Id: Ia91ea2e7fb287271d8d7ec2b9f3bff3168d57d6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356560
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-03-08 21:32:15 +00:00
Ömer Sinan Ağacan
dad57a4ced [dart2wasm] Avoid passing int args boxed in JS array implementation
Change-Id: Ic238a7dfc372822f02dcf7aeca3b28332f425862
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336380
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-03-08 10:19:01 +00:00
Daco Harkes
8de00e2137 [vm] Introduce pragma vm:deeply-immutable
This CL introduces a way to mark all instances of a class as deeply
immutable.

In order to statically verify that all instances of a deeply immutable
class are immutable, a deeply immutable classes must have the following
properties:

1. All instance fields must
   1. have a deeply immutable type,
   2. be final, and
   3. be non-late.
2. The class must be `final` or `sealed`. This ensures no
   non-deeply-immutable subtypes are added by external code.
3. All subtypes must be deeply immutable. This ensures 1.1 can be
   trusted.
4. The super type must be deeply immutable (except for Object).

Note that instances of some classes in the VM are deeply immutable
while their class cannot be marked immutable.

* SendPort, Capability, RegExp, and StackTrace are not `final` and
  can be implemented by external code.
* UnmodifiableTypedDataViews do not have a public type. (It was
  recently deprecated.)

See runtime/docs/deeply_immutable.md for more details.

Use case:

This enables attaching a `Dart_FinalizableHandle` to a deeply immutable
object and the deeply immutable object with other isolates in the same
isolate group.

(Note that `NativeFinalizer`s live in an isolate, and not an isolate
group. So this should currently _not_ be used with `NativeFinalizer`s.
See https://github.com/dart-lang/sdk/issues/55062 for making a
`NativeFinalizer.shared(` that would live in an isolate group instead
of in an isolate.)

Implementation details:

Before this CL, the `ImmutableBit` in the object header was only ever
set to true for predefined class ids (and for const objects). After
this CL, the bit can also be set to true for non const instances of
user-defined classes. The object allocation and initialization code has
been changed to deal with this new case. The immutability of a class is
saved in the class state bits. On object allocation and initialization
the immutability bit is read from the class for non-predefined class
ids.

TEST=runtime/tests/vm/dart/isolates/fast_object_copy2_test.dart
TEST=runtime/vm/isolate_reload_test.cc
TEST=tests/lib/isolate/deeply_immutable_*

Bug: https://github.com/dart-lang/sdk/issues/55120
Bug: https://github.com/dart-lang/sdk/issues/54885
Change-Id: Ib97fe589cb4f81673cb928c93e3093838d82132d
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-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
Cq-Include-Trybots: dart-internal/g3.dart-internal.try:g3-cbuild-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354902
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-07 18:33:58 +00:00
Nicholas Shahan
5e03c497e9 [ddc] Cleanup dynamic calls in native_typed_data
Change-Id: I6a3b709addf59fbde09d829efed43028d71ef7d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355620
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-03-06 00:51:15 +00:00
Nicholas Shahan
59ad7082cc [ddc] Cleanup dynamic calls in debugger helper lib
Change-Id: Ie31f398f8c438ebf64700b631dff25d6d01bb1e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355545
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-03-05 20:32:23 +00:00
Ömer Sinan Ağacan
b6bc3e54d0 [dart2wasm] Refactor and optimize dart2wasm hash map/set types
This CL copies and modifies hash map and set base class `_HashBase`
currently shared with the VM, to improve types of the fields.

The Wasm struct for hash map and set objects was previously:

  (type $_HashBase (sub $Object (struct
    (field $field0 i32)
    (field $field1 (mut i32))
    (field $field2 (mut (ref null $Object)))      ;; _index
    (field $field3 (mut i64))
    (field $field4 (mut (ref $Object)))           ;; _data
    (field $field5 (mut i64))
    (field $field6 (mut i64)))))

Now:

  (type $_HashBase (sub $Object (struct
    (field $field0 i32)
    (field $field1 (mut i32))
    (field $field2 (mut (ref $Array<WasmI32>)))   ;; _index
    (field $field3 (mut i64))
    (field $field4 (mut (ref $Array<Object?>)))   ;; _data
    (field $field5 (mut i64))
    (field $field6 (mut i64)))))

_index and _data fields are now non-nullable Wasm arrays. This removes
downcasts and one layer of indirection when accessing the elements. In
addition, when accessing `_index` this eliminates unboxing the integers.

Fixes #54961.

Change-Id: I4e6bd5129c7c57f5716ccb23e46060d73ffca217
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354843
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-03-05 16:00:39 +00:00
MarkZ
210e120fbd [ddc] Creating a hot reload and hot restart test suite.
The hot reload runner currently only supports d8, but I plan to add support for Chrome and VM execution.

Notable changes:
* Creates `package:reload_test` with helpers for running this suite.
* Updates the module loader with D8-specific branches and hooks for hot reload/restart.
* Exposes DDC runtime variables via a `HotReloadTestRuntime` API.
* Ports constant equality hot restart tests from webdev/dwds (validated to fail if either cache-clearing mechanism fails).
* Partially rolls DDC's d8 preamble forward (towards dart2js's).
* Wraps D8's timer implementation with custom timeout logic to better match Chrome's timing semantics when executing with native JS async.

Tests for the framework and matrix updates will be added in an upcoming change.

Change-Id: I2773b29f464cfd0330e4c653c05e117ae150b4a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350021
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-03-05 00:12:18 +00:00
Srujan Gaddam
e1834792c3 [dart:js_interop] Fix comparison operator return types
Fixes https://github.com/dart-lang/sdk/issues/55024

The patch files for these operators return a bool, whereas
the public API returns a JSBoolean. Since there's only one
possible return type, we should make them return bool for
convenience. Boolean conversion is also inexpensive on
dart2wasm, so that shouldn't be an issue.

Also adds helpers to operator_test to make sure any JS values
are converted before they're compared, adding additional type
checking through the conversion.

CoreLibraryReviewExempt: Fixes type mismatch in backend-specific library.
Change-Id: I7ff2e334e817e6e7d7d8d5091a4e5d570a496b03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354702
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-04 21:10:02 +00:00
Lasse R.H. Nielsen
9d933d1281 Retire 3.3 experiments in the 3.4 release.
Tested: No new tests.
Change-Id: Idf19ce8b6743b221841e6cef6b2a80e8ab37860e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354260
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-03-04 16:09:31 +00:00
maBarabas
42ccd79cd1 Fix typo
Closes https://github.com/dart-lang/sdk/pull/55065

GitOrigin-RevId: ac11d63f223361219d5907b106f9672b4fa44b52
Change-Id: I7f8d816491707c86743adca04ef410cd9b60c8cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355200
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2024-03-02 03:48:55 +00:00
Vyacheslav Egorov
ca732aa5ae [vm] Remove dart:cli from dartdoc
R=mit@google.com

CoreLibraryReviewExempt: No functional changes.
Change-Id: Ic8ee88928ceb6457355319e1e411c5421542b840
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355181
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
2024-02-29 13:57:27 +00:00
Vyacheslav Egorov
9e11d79657 [vm] Remove dart:cli waitFor
Closes https://github.com/dart-lang/sdk/issues/52121

Tested: CI
CoreLibraryReviewExempt: Approved breaking change to VM specific code
Change-Id: Icc89017c5a7676c2ae07488692ad8b8b9e131a7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354880
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-02-29 11:18:51 +00:00
Srujan Gaddam
2f7bfc404a [dart:js_interop/_unsafe] Clean up API docs
- Rephrase docs on JS types
- JS -> JavaScript where applicable
- “This” and “that” expanded to refer to the thing
- Add docs to undocumented members
- Rephrase some docs to be clearer and more explicit
- Move warnings to format that dartdoc can display specially
- Add warnings to every single member that should have it
- e.g. -> like
- Makes similar docs consistent
- Removes library declarations per style guide. Regenerates
  expectations to handle the change.

CoreLibraryReviewExempt: Backend-specific library. Docs only.
Change-Id: I246f8c20d594741149766e5a76bb186debf54ded
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352977
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-02-29 04:15:49 +00:00
Nate Bosch
6f5a23f150 Expand docs around error zones
Mention error zones in the docs for `runZoned`. We expect most of these
use cases to be handled by `runZonedGuarded`, but specifying an error
handler on the `ZoneSpecification` can still trigger this behavior.
Expand the phrasing from mentioning that some futures might not complete
to describe the specific reason - errors cannot cross zone boundaries
with different error zones, so specifically Futures which complete as
errors are at risk of not completing in the parent zone.

R=lrn@google.com

CoreLibraryReviewExempt: Doc changes only.
Change-Id: I8759dfb6da48463e0bb33a000943d60a4dd3d5ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348043
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2024-02-29 01:49:08 +00:00
Lasse R.H. Nielsen
1436635d27 Add more information to ParalleWaitError.toString.
Gives the constructor optional parameters for providing
more information that can be used in the `toString` message,
and the `stackTrace` getter.
Makes the `iterable.wait` and `record.wait` extension methods
provide such information, so that the `toString` will always
contain the text of *one* of the errors.

(No issue, problem with logging was brought up in chat.)

Change-Id: I5f9a20ad0af0c64a2e7ff3cdb56f187a5cf5a3ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353080
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-28 20:36:58 +00:00
Lasse R.H. Nielsen
f0aeebd0e7 Make all platforms return null from Error.stackTrace until thrown.
The web platforms used to invent a spurious stack trace when reading
`Error.stackTrace` before the object was thrown.
They now return `null` instead, if there is no underlying JS error object,
matching specified behavior.

Fixed bugs in async error throwing in dart2wasm:
* `throw` in an async function did not set the stack trace on an error.
  Now calls `Error._throw` instead of just a direct Wasm "throw".
* `async*` functions did not capture the stack trace of a throw
  that ended the function body, which means it called
  `StreamController.addError` with only one argument.
  That then resused the stack trace from an `Error` throw instead
  of the correct stack trace.

Added tests.

Change-Id: I1d9fa8d9e18076a7fe28254b60b950866cd550a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354021
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-02-27 23:01:06 +00:00
Martin Kustermann
3c218ecc53 [dart2wasm] Work around V8/Chrome bug that swallows exceptions from rethrows
Issue https://g-issues.chromium.org/issues/327155548

Change-Id: I7babc0bcfad3e4351af08ce3accb61db6260d86b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354227
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2024-02-27 14:00:32 +00:00
Ömer Sinan Ağacan
94e653fe0e [dart2wasm] Implement --omit-bounds-checks flag
Similar to dart2js --trust-primitives, with --omit-bounds-checks
(implied by -O4) we omit bounds checks in standard library list and
typed array indexing methods, such as `operator []` and `[]=`.

For now this flag does not omit range checks in functions like
`setRange` and `setAll`:

- Functions like `setRange` do more work than functions like `[]` and
  `[]=`, and bounds checks are a smaller part of the whole operation.

- For the same reason, and also because they either don't return any
  values or have to return boxed (i.e. `getRange` needs to return an
  `Iterator`), inlining them is not as crucial as inlining an
  `Uint8List.[]` implementation (which avoids boxing when inlined).

Closes #54962.

Tested: dart2wasm change with small refactoring in VM, tested with existing tests.
Change-Id: Idd5f11ee85c7e67ba8de621b305c413e7e7f7ebb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353982
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-02-27 08:07:00 +00:00
Matthew Berry
4bea796167 [js_runtime/js_dev_runtime] Prefer Array.isArray over checking prototype
Closes https://github.com/dart-lang/sdk/pull/54990

GitOrigin-RevId: 9c51a86c10e70c5f92e8b72894f8d3de138cd17b
Change-Id: I4b74f3762ec720b0204331d0945da046be99ba33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353784
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-02-26 20:33:49 +00:00
Martin Kustermann
c625797f8a [dart2wasm] Implement dart:developer in dart2wasm
* We migrate the `dart:developer` implementation of dart2js to
static interop.

* We make dart2wasm use the same implementation as dart2js.

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

Change-Id: I7873edc7e804500c8eca878367d9045c98a1c2e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354101
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-26 11:23:29 +00:00
Konstantin Shcheglov
9018d41706 Macro. Support for TypeAliasDeclaration.
Change-Id: I4b85cfaf154591434729ba9ad5f94a6cfc2d1033
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354060
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2024-02-23 19:55:10 +00:00
Mayank Patke
9fa1c16029 [dart2js] Convert some collections of const ints to enums
Change-Id: Ib1f5c686c97f8f097fa21a435e684af86f2b569c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352975
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-23 19:52:50 +00:00
Jake Macdonald
e00db2dca2 Add package:macros
- Also adds the public exception APIs to dart:_macros which were missing.

Change-Id: If08bcb8bc60b91eaf08a02140c6d310e7c2e51f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2024-02-22 15:20:52 +00:00
Ömer Sinan Ağacan
8dcedd9edb [dart2wasm] Refactor _Closure.operator == to use the new intrinsics
Change-Id: I6f43b41dea7b5d037193deb095ffee3238b5fcb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353265
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-02-22 09:15:33 +00:00
asiva
58098d3414 [VM/Service] - Launch dds from vmservice code instead of dartdev code
Currently the dds process is being launched from dartdev and
this causes problems when the dartdev commands 'run' and 'test'
are implemented by spawning child processes (this is needed
to make dartdev an AOT snapshot).
This CL attempts to lauch dds from the service isolate code.

TEST=ci

Change-Id: Iad00a17473a630659f15a5c73be0f5385ea35bdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350688
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-02-22 06:22:12 +00:00