Commit graph

11650 commits

Author SHA1 Message Date
Stephen Adams 26c5de8e96 [wasm] Fix regression in removing Unmodifiable classes
Bug: #56014
Change-Id: I5f9d3e1cb6c123ce50315fdccb90cd9ba4b12761
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371743
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-06-17 17:55:14 +00:00
Srujan Gaddam 7a94b5d9a6 [dart:js_interop] Remove unnecessary casts in patch files
In theory, such casts should be optimized out, but in some
cases, they might not be (DDC or lower optimization flags).
Instead, we should use the primary constructor and
representation field to go between the representation type
and the JS type. Similarly, we do unnecessary casts in
dart2wasm to convert JSValue to the right JS type. We can
avoid those by directly calling the primary constructor.

Change-Id: I8fdac18f6d634b379e70951fe5d3a1ed7ad4bf15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371423
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-06-17 17:30:25 +00:00
Srujan Gaddam 25a9fc0aab [ddc] Move null check to JS foreign function in isDartClass and isDartFunction
The Dart != check lowers to !== in JS. The RTI property doesn't
exist in the JS function, so the result is undefined. However,
undefined !== null returns true, so JS functions are accidentally
treated as Dart functions. This fixes that.

Change-Id: I4c4e0018768c0ac29f4b5ee228c504b7cb0b7232
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369200
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-06-14 20:46:20 +00:00
Ömer Sinan Ağacan 76f6a32432 [dart2wasm] StringBuffer improvements
Use `U16List` instead of `Uint16List` as the character buffer type.
Access the Wasm array directly when writing characters and converting
the final buffer to a String. This avoids bounds checks and uses
`array.copy` when allocating the final string.

Change-Id: I570494e8349adc7a268544544516c9947abc8604
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371681
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-14 13:03:41 +00:00
Martin Kustermann 7078310249 [dart2wasm] Specialize string interpolation expressions for 1/2/3/4 arguments
This affects very common string interpolation expressions where we now
avoid creating arrays and looping over arrays and casting references
when getting things out of arrays.

e.g. `StringBuffer.write()` uses "$obj" in it's implementation
which will benefit from this.

Change-Id: Ie6615e5f76a4a8ccb4ff9aa85c05c7e39eab6f00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371660
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-14 12:33:51 +00:00
Ömer Sinan Ağacan 060d841ec0 [vm] Improve JSON copyCharsToList argument type
The buffer type is always `Uint8List`, improve the type from `List<int>`
to `Uint8List`.

Tested: existing tests
Change-Id: I03ad84a0f1fe1ade8a46719545f3c33eeccd99b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371402
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-14 08:31:19 +00:00
Stephen Adams 18994e6e46 [typed_data] Remove UnmodifiableXXXView classes
In most cases, the (now removed) SDK class was patched so that the constructor redirected to a platform-specific implementation of the unmodifiable view. Uses of the SDK class in the platform code could be rewritten to the more direct use of the implementation class.

The big +/- file changes are from moving the implementation classes from the patch file (typed_data_patch.dart), where they are no longer needed, to the internal file (typed_data.dart).

TEST=ci
Bug: #53785
Change-Id: Iaa7370de25b7fc2d26b24f7733c2892868e593cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370661
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2024-06-13 22:18:29 +00:00
Ömer Sinan Ağacan 1ec4677870 [dart2wasm] More JSON decoding improvements
- Use unchecked reads when reading from `U8List` chunks.

- Use unchecked reads when reading from "transition table" in UTF16 decoder.

- Fix a typo in a comment.

Tested: performance refactoring, covered by existing tests.
Change-Id: I1b90781f2b419188d6a560994159b48faad16075
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371301
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-13 18:49:18 +00:00
Martin Kustermann d150ad8a81 [dart2wasm] Move local constant variable to top-level
The flutter platform file is compiled slightly differently from the way
we compile the normal SDK platform file. This slight difference -
somehow related to how -D environments are used in CFE - results in a
constant `VariableDeclaration` to stay in the kernel in flutter's case
but not in the Dart SDK's case.

(All usages of constant variables / fields will be
`ConstantExpression(<const>)` instead of
`VariableGet(<constant-variable>)`)

That in itself causes the kernel verifier AST visitor (which we call
from `pkg/dart2wasm/lib/compile.dart` in assertion mode enabled) to
report an error.

=> To work around this issue we hoist the only variable affected by this
to top-level.

=> That will allow us to run the dart2wasm compiler in assertions mode
on flutter apps without hitting the verifier problem.

(This has very likely to do with the fact that in flutter's case the
variable must result in an `UnevaluatedConstant` which then at a later
stage gets evaluated whereas in Dart's case we do that eagerly).

There's no easy way to write a test for this, as normal test files will
have an environment and therefore don't result in unevaluated constants
afaik.

Change-Id: I883b91bdc37ede8b45e35a15d0dddc296d9da9ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371340
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-13 13:10:50 +00:00
Mayank Patke ca3e67a3b6 [dart2js] Add --interop-null-assertions.
This CL adds a new --interop-null-assertions flag (cf.
--native-null-assertions) with the goal of validating that JS interop
APIs with non-nullable static return types do not return null values.
This flag is currently disabled by default but is intended to assist in
sound null safety migrations.

In general, we don't guarantee type soundness of package:js interop
since users can write incorrect static types which are not backed by
any runtime checks. However, it is likely that during the null safety
migration, some interop APIs which should have been made nullable
weren't. Therefore, we want to offer some additional (but limited)
checking for this case.

For static invocations of functions with non-nullable return types, we
can simply perform a null check on the result of the call.
For instance methods (which could be invoked virtually/dynamically), we
want to perform a null check on the return value in the callee (the
interceptor method) itself when possible.

It's possible for multiple interop bindings to share the same
interceptor method. We produce a null check in the interceptor method
body if all the methods have non-nullable return types. Otherwise, we
insert checks at callsites when appropriate.

Change-Id: Ifd155d7f8326152b6d57d61199e0b7973c4a1211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369784
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-12 21:28:23 +00:00
Ben Konyi 6b788d2a77 [ Service / DDS ] Re-introduce explicit cast to remove dynamic invocation of operator[]
Fixes failures in type flow analysis tests introduced by https://dart.googlesource.com/sdk/+/cf9623f3d9520bc58b7d3cba146934b69dba1d8f

TEST=pkg/vm/testcases/transformations/type_flow/transformer/bench_vector.dart

Change-Id: I401d12d42a64c64537722ef346dd86b1eff78f84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371140
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
2024-06-12 16:34:17 +00:00
Ömer Sinan Ağacan 75f9312a50 [dart2wasm] Small optimization in JSON number parsing
Use `WasmArray<WasmI8>` for number buffer when decoding numbers.

This saves one allocation when growing the number buffer and on initial
allocation of the buffer, and eliminates one layer of indirection when
writing to the buffer.

Change-Id: Ic210bc13072f0dd34918361a1bee8c7b29ce61cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371064
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-12 10:50:27 +00:00
Martin Kustermann dd92e9a0b4 [dart2wasm] Faster search in RTT supers data structure
If the transitive supers graph contains many classes we use a binary
search instead of a linear search.

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: I1018082e8d27090293b67a2239abfaf279270b9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370860
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-12 10:42:22 +00:00
Ben Konyi cf9623f3d9 [ DDS ] Update DDS launch sites to assume DDS process closes stderr
Removes risk of DDS connection information being split across two stream
events, causing JSON decoding to fail.

Also updates DDS to close stderr, even in the error case.

TEST=Existing service and dartdev tests

Change-Id: I5cceab899aac1fa63bd7578dd658b34096722bd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371000
Reviewed-by: Derek Xu <derekx@google.com>
2024-06-11 18:41:01 +00:00
Ömer Sinan Ağacan 455d85f528 [dart2wasm] Port VM JSON parsing improvements
This ports https://dart-review.googlesource.com/c/sdk/+/365803 to dart2wasm.

Benchmarks: https://golem.corp.goog/Revision?repository=dart&revision=110551&patch=19222

Change-Id: Id4a8e0f44abcde3552c50605d9b329443d43d1d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370821
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-11 16:10:23 +00:00
Ömer Sinan Ağacan efc59ee300 [vm/libs][dart2wasm] Add some missing type arguments to convert_patch List types
Tested: existing tests
Change-Id: Ib19748e947ef9a80852ef80f7726b5d1c987a26e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370920
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-11 15:03:49 +00:00
Ömer Sinan Ağacan e7d3b7820a [dart2wasm] Port VM JSON decoding improvements
This ports https://dart-review.googlesource.com/c/sdk/+/358445 to
dart2wasm.

The only difference from the VM patch is that we use `U8List` instead of
`Uint8List` for the chunk type in `_JsonUtf8Parser`, to avoid parsing
slow dart2wasm `Uint8List` subclasses (`JSUint8ArrayImpl`,
`_SlowU8List`).

Benchmarks: https://golem.corp.goog/Revision?repository=dart&revision=110551&patch=19217

Change-Id: I2af7131e72014587e97bab09e80e920c445b2c32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370820
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-11 13:41:20 +00:00
Brian Quinlan 33563e5cf9 [io,doc]: Point out that exit does not kill child processes.
Bug:https://github.com/dart-lang/sdk/issues/53772
Change-Id: I38d18e97036b5684982a78f44f03634c5b3dceea
CoreLibraryReviewExempt: documentation only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370320
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-06-10 22:58:28 +00:00
Martin Kustermann e7239ff03c [dart2wasm] Specialize is/as checks for interface types
Currently if we have a `<obj> is/as Iterable<T>` check we will

  * allocate a `WasmArray<_Type>` array and put value for `T` in it
  * allocate a `_InterfaceType` object with the array as type arguments
  * call to RTT which is looping over the type arguments array

With this CL we recognize in the compiler if we generate tests against
interface types and specialize the most common cases (0, 1 or 2 type
arguments). This in return will make us

  * call to 0/1/2 specialized RTT isInterfaceSubtype implementation
    which will use unrolled loops to do the checking.

=> We avoid allocation of `_InterfaceType` always
=> We avoid allocation of `WasmArray<_Type>` for length=0/1/2
=> We have faster checking due to unrolled loops.

(It is very unlikely binaryen can achieve the same, as it would
need to do very aggressive inlining & loop unrolling to get to the
same result. If we'd force it to inline then every is/as check
would be very large).

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: Ia99548d514683f678178ea30d07aeb742ae914ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370260
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-10 11:27:51 +00:00
Martin Kustermann 54ab47ec82 [dart2wasm] Refactor RTT type checking implementation
We make the compiler emit a special index (namely 0) into the
canonical type argument substitution table iff no substitution has to be
performed.

This is very common:

    ```
    class List<T> implements Iterable<T> {}
    ```

=> The translation of the type arguments from `List` to those of
   `Iterable` is a NOP and can therefore be skipped.

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: I16ad8d7196656dddeba15801e80c2e23ae0af51b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370242
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-06-10 10:49:58 +00:00
Martin Kustermann d32e2ece05 [dart2wasm] Move StackTrace.current for as checks into shared runtime code
When an implicit or explicit `as` check fails we throw a [TypeError]
exception with a stack trace. Though that stack trace doesn't really
have to have the top-frame being where the check failed, it's fine if
there's an additional frame from the runtime code that actually throws
the exception.

Doing so removes `StackTrace.current` from every `as` check and
therefore reduces size.

Change-Id: Ia34b59ebaa54b8cdcd2dc7b153a1e4e2fe1dd0e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370340
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-10 07:11:05 +00:00
Martin Kustermann 1e607007cd [dart2wasm] Optimize RTT data structures
This CL optimizes the RTT data structures by

* Having a canonical table for substitution arrays
* Stores the (canonical) substitution index to use right next
  to the super class id, thereby
* Removing an indirection when looking up substitutions

See more information in `sdk/lib/_internal/wasm/lib/type.dart`

This reduces
  * `Hello.Compile.Size.wasm.opt` by ~ 4%
  * `FluteComplex.Compile.Size.wasm.opt` by ~0.5%

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: If0a50780a9a604886bd67a08a2f345103f0bcb32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369641
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-08 20:07:36 +00:00
Martin Kustermann 290d7406ae [dart2wasm] Avoid WasmArray<_Type> allocations in interface subtype checking
Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: I2cddd95211f3d831965a1bba45774ad8d72847a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369621
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-05 17:57:49 +00:00
Martin Kustermann 23657ac772 [dart2wasm] Remove dispatch table call in type check implementation if not needed
When checking against a destination type that isn't generic, we can
safely ignore the type arguments of the concrete class (as we only care
whether the object's class has the destination type in its transitive
super type hierarchy).

=> Avoid calling `Object._getTypeArguments(o)` if dst type is non-generic.

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: Ie9c6a3ab2d99acc07546f9d28ca71ac740c4aad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369462
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-04 08:34:48 +00:00
Martin Kustermann ed409e53ff [dart2wasm] Avoid optaining substitutions if dst type is not generic
If we do a type check against a class that isn't generic, then we can
safely ignore all the type arguments - because irrespective of their
values - either the class we test against is in the transitive super
hierarchy of an object's class or not.

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: Ibf6950492d4c33d7eaf55d6ce8389ebfac201b00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369461
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-06-04 06:35:59 +00:00
Jens Johansen ed4b9377d0 [io/socket_read] Fix available bug when limit of aggregated read bytes goes into effect
In 7fa9b814d2
(https://dart-review.googlesource.com/c/sdk/+/369141) a limit was
introduced to prevent OOM.
It however introduced a bug where `available` would be out of sync
(> 0 when it should be 0) causing issues - seemingly an infinite loop
where it continues trying to read even though no data is available - and
e.g. the weekly bot timed out after 12 hours because stuff didn't work.
(I think the issue is `stopRead()` returning false, but isn't sure).

This CL fixes the issue by updating the field before the possible break.

TEST=Hopefully a test will be added in a follow-up.

Change-Id: I722c8868fd7354fc9403e8d2f387914c3fab884a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369243
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-03 11:00:09 +00:00
Martin Kustermann ed36bdd851 [dart2wasm] Make _TypeUniverse a purely abstract class with static methods
There's no need to make an instance of _TypeUniverse and pass around a
`this` reference to method calls as there's no state.

Issue https://github.com/dart-lang/sdk/issues/55516

Change-Id: I522a3ef677d0301c0a5dcd1d83499a99293618a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369242
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-03 07:24:14 +00:00
Vyacheslav Egorov fc4bcab2ef [io] Propagate cancellation in _HttpOutgoing.addStream
If HttpResponse is being closed prematurally (e.g. because client
decided to close its request) we need to propagate cancellation
to the stream which is being piped into the response. Otherwise
we will keep that stream forever hanging around and leak underlying
resources.

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

TEST=tests/standalone/io/regress_55886_test.dart
R=kustermann@google.com

Change-Id: I7c294ed19cc7c350fd101b078bd650ce8a6526a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369061
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-02 20:33:26 +00:00
Alexander Aprelev 7fa9b814d2 [io/socket_read] Limit aggregated read bytes to prevent OOM.
Also use non-copying BytesBuilder.

Fixes https://github.com/dart-lang/sdk/issues/55885
TEST=ci and repro from the github issue

Change-Id: Ida0feff32a3c9ee1e89add3b3696efefdc94fc28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369141
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-05-31 19:39:59 +00:00
Stephen Adams 20316bcc5b Reapply "[js_runtime, js_dev_runtime] Implement microsecond field of DataTime"
Original change: https://dart-review.googlesource.com/c/sdk/+/366963

This reverts commit 72b2883c6f.


[js_runtime, js_dev_runtime] Implement `microsecond` field of `DataTime`

- Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.

- Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.

- The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.

- Both implementations report better errors.

- Fixed VM bug with in-range sentinel.


Issue: https://github.com/dart-lang/sdk/issues/44876
Issue: https://github.com/firebase/flutterfire/issues/12102
Issue: b/342552853
CoreLibraryReviewExempt: Reapply of unchanged code
Change-Id: I7f14b69e412a052ef3fe6b43cc9cf9d96319adb8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368380
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-05-31 15:42:14 +00:00
Ivan Inozemtsev 72b2883c6f Revert "[js_runtime, js_dev_runtime] Implement microsecond field of DataTime"
This reverts commit fb057ea4e0.

Reason for revert: b/342552853

Original change's description:
> [js_runtime, js_dev_runtime] Implement `microsecond` field of `DataTime`
>
> - Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.
>
> - Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.
>
> - The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.
>
> - Both implementations report better errors.
>
> - Fixed VM bug with in-range sentinel.
>
>
> Change-Id: I9156255bdb6ecc195500ae9bc88f91fb315b6297
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366963
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

Change-Id: I58572256a7710df4589bb5e41c7afee295c2388b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368103
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2024-05-27 07:54:14 +00:00
Stephen Adams fb057ea4e0 [js_runtime, js_dev_runtime] Implement microsecond field of DataTime
- Move DateTime implementation for dart2js and DDC into a shared place to reduce duplication.

- Add a _microsecond field to the web DateTime to track microseconds outside of the JavaScript Date.

- The cute dart2js optimization whereby `DateTime.now().millisecondsSinceEpoch` is compiled to `Date.now()` still works.

- Both implementations report better errors.

- Fixed VM bug with in-range sentinel.


Change-Id: I9156255bdb6ecc195500ae9bc88f91fb315b6297
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366963
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-05-22 05:18:52 +00:00
Ömer Sinan Ağacan fab56db71b [dart2wasm] Move common code generation routines to state_machine, fix sync*
This is the last part of the series of patches to implement missing
sync* features and fix bugs.

Move common code generation functions between async and sync* code
generators to the state_machine library, with the name
`StateMachineCodeGenerator`.

This class allows overriding parts that differ between the async and
sync* code generators.

Fixes tests:

- co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_sync_t05
- language/sync_star/generator3_test/test1
- language/sync_star/generator3_test/test2
- language/sync_star/sync_star_exception_iterator_test
- language/sync_star/sync_star_exception_nested_test
- language/sync_star/sync_star_exception_test
- language/sync_star/sync_star_exception_current_test

Fixes #51343.
Fixes #51342.

Change-Id: Ife6eab43b2721b003ebf9bc0f03796748fd5df46
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367041
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-05-21 14:53:58 +00:00
Sam Rawlins 020a59e59c js_interop: replace unsupported [this] comment references with this.
Work towards https://github.com/dart-lang/dartdoc/issues/3761

Sibling CL to https://dart-review.googlesource.com/c/sdk/+/365204

The analyzer has never recognized `[this]` as a valid doc comment
reference (and the `comment_references` lint rule has similarly
reported such reference attempts). dartdoc has its own algorithms
for resolving comment references, which we are dismantling in favor
of a single resolution, provided by the analyzer.

We've also decided against adding support in the analyzer (see
https://github.com/dart-lang/linter/issues/2079), so these
reference attempts should be re-written.

CoreLibraryReviewExempt: Comments only.
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,analyzer-win-release-try,pkg-win-release-try
Change-Id: I38dd476e40e4508fb6bf88c28415ff261bae5f43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366880
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
2024-05-16 19:43:18 +00:00
Ömer Sinan Ağacan e7dde8377e [dart2wasm] Port VM fix for #52083 (sync*)
dart2wasm's sync* runtime library was mostly copied from VM, but we
didn't get the fix for #52083 in 9cf26fc. This ports the fix to
dart2wasm.

This currently doesn't fix any tests as there are other issues with
dart2wasm's sync* implementation, which we are fixing in
https://dart-review.googlesource.com/c/sdk/+/366663.

Change-Id: I9d82d1bbb4c96ccb9bf411a385f4b7ff395a1c19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366671
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-16 11:53:25 +00:00
Vyacheslav Egorov 1e6c9b026f [vm/libs] Improve JsonUtf8Decoder performance.
This CL focuses on improving parsing of white space (between
JSON tokens) and simple strings which don't contain escape
sequences inside.

Improvements are achieved by changing the code to
table driven implementation instead of if-cascade: we
have a 256 element table which stores attributes for characters
(e.g. whether it is a white space or a terminal token for
a simple string) and use this table to make decisions
on whether to advance through characters or stop a loop and
do something else.

We also suppress bounds checks and interrupt checks in tight
loops - in tight loops like this a bound checks can cost
30% in overhead.

This CL brings 28% geomean improvement on benchmarks from the linked issue. (All measurements are done in X64 Product AOT)

Individual measurements are:

| Input JSON | ms/iter | vs HEAD | vs V8 |
| ---------- | ------- | ------- | ----- |
| apache_builds.json | 0.44 | 61.06% | 136.86% |
| canada.json | 31.04 | 96.54% | 187.15% |
| citm_catalog.json | 6.43 | 64.44% | 93.94% |
| github_events.json | 0.23 | 59.02% | 128.86% |
| google_maps_api_compact_response.json | 0.10 | 82.12% | 133.83% |
| google_maps_api_response.json | 0.12 | 68.79% | 140.07% |
| gsoc-2018.json | 9.25 | 44.89% | 147.43% |
| instruments.json | 1.08 | 70.18% | 167.38% |
| marine_ik.json | 21.07 | 88.25% | 142.58% |
| mesh.json | 4.51 | 94.56% | 136.57% |
| mesh.pretty.json | 9.97 | 83.76% | 193.79% |
| numbers.json | 0.57 | 91.88% | 83.37% |
| random.json | 3.79 | 78.32% | 107.18% |
| repeat.json | 0.06 | 71.51% | 118.47% |
| semanticscholar-corpus.json | 37.65 | 54.82% | 57.81% |
| tree-pretty.json | 0.17 | 68.68% | 162.33% |
| twitter_api_compact_response.json | 0.06 | 75.23% | 126.11% |
| twitter_api_response.json | 0.08 | 70.64% | 123.60% |
| twitterescaped.json | 3.88 | 84.66% | 177.94% |
| twitter.json | 3.54 | 73.01% | 105.33% |
| twitter_timeline.json | 0.37 | 81.52% | 271.37% |
| update-center.json | 2.85 | 66.75% | 89.01% |

vs HEAD (geomean): 72.94%
vs V8 (geomean): 130.99%
HEAD vs V8 (geomean): 179.59%

Issue https://github.com/dart-lang/sdk/issues/55522

TEST=covered by co19

Change-Id: Id673118c19250ab7781cc98c7656b972debc60ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365803
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-05-15 09:56:20 +00:00
Alexander Aprelev 480e631727 [io/ssl] Avoid reinitiating racing handshake request.
When other side closes their write socket during us running handhsake, don't repeat handshake. Repeated handshake call results in boringssl secure filter data race between ongoing encryption/decryption sequence and this new handshake call, running concurrently.

Fixes https://github.com/dart-lang/sdk/issues/53136
TEST=secure_session_resume_test on TSAN
CoreLibraryReviewExempt:no user-visible changes to io functionality
Change-Id: I7540b41b15b3a7487a237b6957314e38b078a774
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366401
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-05-14 20:50:33 +00:00
Lasse R.H. Nielsen b06a34fc5a Don't allow completing a _Future with itself.
This never worked. It was silently accepted, at least if the future had no listeners, then any later attempt to use the future would cause a stack overflow or other impossible results.

Moves some `_Future._complete` call out of try-catch.
The `_complete` shouldn't throw (but before this fix it could).
Moving them out of the `try`/`catch` makes such errors be reported
as unhandled, instead of catching them and trying to complete the same
future again with an error, when it's possibly in an inconsistent state.

Fixes #43662.
Based on https://github.com/dart-lang/sdk/issues/43662#issuecomment-2058870247

CoreLibraryReviewExempt: No response.
Bug: http://dartbug.com/43662
Change-Id: I96a4f01bcd5b6cee93bba267299852569a9b905c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363060
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-05-14 15:44:07 +00:00
Sigmund Cherem 3f705f0f7f [dart2js] allow tabs when computing the current script.
For unclear reasons, a JS stack trace sometimes has tabs instead of
spaces. For example, this has been observed when using the VS Code
extension host (NodeJs) in issue #55684.  When that happens, the d8
preamble function to compute the current script fails. While tabs are
not generally present there, this small change can make the logic a bit
more robust and versatile.

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

Change-Id: Id1833a8b550a0ba5c9822e98d9e69ea9abfd6232
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366160
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-05-13 17:08:30 +00:00
Jake Macdonald a8ea744cea Update allowed_experiments.json to enable macros for the json package.
Without this there is no way to enable the experiment for a dependency, so nobody can try out package:json.

Bug: https://github.com/dart-lang/sdk/issues/55688
Change-Id: Id2f10b10dde0eb6d68d0bf76030ff557087ee83b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366041
Reviewed-by: Leaf Petersen <leafp@google.com>
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
2024-05-10 19:23:00 +00:00
Sam Rawlins 6a25f12f40 SDK: replace unsupported [this] comment references with this.
Work towards https://github.com/dart-lang/dartdoc/issues/3761

The analyzer has never recognized `[this]` as a valid doc comment
reference (and the `comment_references` lint rule has similarly
reported such reference attempts). dartdoc has its own algorithms
for resolving comment references, which we are dismantling in favor
of a single resolution, provided by the analyzer.

We've also decided against adding support in the analyzer (see
https://github.com/dart-lang/linter/issues/2079), so these
reference attempts should be re-written.

CoreLibraryReviewExempt: Comments only.
Change-Id: I6cc85115186527820bdd38dcfda8f61e35ae3fe9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365204
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-05-03 15:29:29 +00:00
Brian Quinlan 51ac900e0e [doc, io]: Add a note to indicate the batch file execution behavior on Windows.
Change-Id: I6f61af46e7e9e96282127fea919c8e79948356d4
CoreLibraryReviewExempt: documentation only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364941
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-05-01 22:32:55 +00:00
ChoiYS 97321ebb19 Fix typos
Closes https://github.com/dart-lang/sdk/pull/55585

GitOrigin-RevId: 115e712e6a4ef4bb50eb0f5bc309931472d1ac50
Change-Id: If0d561751a1b888f3a16c59cb9db4c77b564df10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364640
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-30 12:11:00 +00:00
Alexander Markov ac3a99b760 [vm] Optimize double.remainder
Bypass runtime entry and directly call `fmod` from generated code,
similarly to double.operator %.

On a micro-benchmark (from #55479):

JIT
Before: Remainder(RunTime): 1347507.0 us.
After:  Remainder(RunTime): 19465.037735849055 us. (69x faster)

AOT
Before: Remainder(RunTime): 1232950.0 us.
After: Remainder(RunTime): 19465.377358490565 us. (63x faster)

TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/55479

Change-Id: I5b35b15f21da74aa4e2c92d7aa2804dae9efff99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364780
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-04-29 17:47:21 +00:00
Lasse R.H. Nielsen b464fc9037 Reland "Tweak expect.dart library."
This reverts commit cd2c566bcf.

Reason for revert: Updating to not remove field used by Flutter engine.

Original change's description:
> Revert "Tweak `expect.dart` library."
>
> This reverts commit ff5f391c0a.
>
> Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one.
>
> Original change's description:
> > Tweak `expect.dart` library.
> >
> > Make API more consistent for a few methods.
> > Reduce the number of language features used in tests:
> > * Never iterating an iterable, always converting it
> >   using `.toList()` first and iterating using indices
> >   (fx `setEquals`).
> >   Also require a `List` in places where an `Iterable`
> >   wasn't necessary.
> > * Avoid doing complicated computations that are also
> >   used for the error message. Do simple check first,
> >   then recompute to get better error messages
> >   (fx `allDistinct`).
> >
> > Renamed some rarely used members for consistency
> > (`stringContainsInOrder`->`containsInOrder`,
> > where other string-contains functions just start
> > with `contains`, and `containsOneOf` -> `containsAny`
> > to match `Iterable.any` phrasing, and also it accepts
> > if containing at least one, not precisely one.)
> >
> > Removed a function that wasn't used anywhere.
> >
> > Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
> > Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.
> >
> > Deprecates `package:expect/minitest.dart`. It was never intended
> > to be used for new tests, only as a help to convert existing tests
> > written against `package:unit_test`.
> > All existing imports marked as `// ignore: deprecated_member_use`.
> >
> > Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
> > Reviewed-by: Slava Egorov <vegorov@google.com>
> > Reviewed-by: Ömer Ağacan <omersa@google.com>
> > Reviewed-by: Nate Bosch <nbosch@google.com>
> > Reviewed-by: Stephen Adams <sra@google.com>
> > Commit-Queue: Lasse Nielsen <lrn@google.com>
>
> Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>
> Reviewed-by: Leaf Petersen <leafp@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: William Hesse <whesse@google.com>

CoreLibraryReviewExempt: Reland
Change-Id: I53db40edc0733842a008839c3913d51c885e39ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362502
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-26 15:28:26 +00:00
Daco Harkes 4b66657b98 [vm/ffi] address of operator for FFI leaf calls
During FFI leaf calls, the Dart GC will not run. This means that we
can pass pointers into `TypedData` to FFI calls that take `Pointer`
arguments.

After this CL, we have three types of arguments that can flow into
`Pointer` argument in an FFI call:
* `Pointer`.
* `TypedData`: Any typed data including views.
* `_Compound`: A TypedData/Pointer and an offset in bytes.

The is only possible for `@Native external` functions, `asFunction`
does not support passing in `TypedData`. (See related GitHub issues
for discussion. TLDR: FFIgen should generate bindings without config.)

`.address` expressions on `TypedData` and `Array` elements do _not_
introduce bounds checks, even though `TypedData` and `Array` have
bounds information. E.g. `ffiNative(Uint8List(10)[20].address)` does
not throw.

Implementation details:

The CFE analyzes call-sites to `@Native external` functions. If the
arguments are `.address` expressions, it transforms the call site to
pass the compound or `TypedData`. If an additional offset needs to be
applied, the CFE constructs a new `_Compound` with the correct offset
in bytes.

The CFE then also creates a new `@Native external` function which have
`TypedData`s and `_Compound`s parameters. To avoid name clashes, these
functions are postfixed with `#` and `P`, `T`, or `C` for each Pointer
parameter.

TEST=pkg/vm/testcases/transformations/ffi/address_of_*

In the VM, `TypedData` arguments are passed as tagged values, and the
address is loaded inside the `FfiCallInstr`. `_Compound` arguments
turn into two IL definitions, one for the `TypedDataBase` (tagged),
and one for the offset in bytes (unboxed). The address is then loaded
inside the `FfiCallInstr` and the offset in bytes is applied.

Adding the offset in bytes required an extra temp register for ia32.
Also, it uncovered that the temp register in arm32 was conflicting
with the argument registers. However, TMP should suffice instead.

TEST=tests/ffi/address_of_array_generated_test.dart
TEST=tests/ffi/address_of_struct_generated_test.dart
TEST=tests/ffi/address_of_typeddata_generated_test.dart

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

CoreLibraryReviewExempt: VM only, unsupported in dart2wasm
Change-Id: I01fb428cfd6f9096a34689c2819c124a8003cb6b
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-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-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-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/+/360882
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-04-25 10:06:16 +00:00
Ömer Sinan Ağacan 39276e9bd4 [dart2wasm] Simplify libraries.yaml setup:
Move common libraries of wasm and wasm_js_compatibility to wasm_common,
remove wasm_base.

Change-Id: I0293cfd11b58be3d921413fdb2fff7171f0b3d4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364320
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-04-24 08:04:58 +00:00
Ömer Sinan Ağacan bae278ec40 Minor tweaks in Finalizer documentation:
- Fix typos in "Get finalizer callback" -> "Call finalizer callback"
  in documentation of an `attach` call.

- Make it clear that the `detach` parameter of `attach` is not used by
  the finalizer.

- Make it clear what "the same value" means in the `detach` parameter
  documentation.

CoreLibraryReviewExempt: Documentation only
Change-Id: I8c1dc9e5fd6926e5c594c26a50228a044e892974
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364100
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-04-23 13:36:57 +00:00
Tess Strickland 1774314a04 [vm/test] Fix flakiness of vm/dart/use_dwarf_stack_traces_flag_test.
Previously, Internal_randomInstructionsOffsetInsideAllocateObjectStub
assumed the entry point is at the start of the instructions payload when
choosing a random offset into the instructions payload.  However, most
of our architectures have non-zero entry point offsets.

Instead, replace it with two methods, one that returns the start
(inclusive) and one that returns the end (exclusive) of the
AllocateObject stub instructions payload and have the test choose
points inside and outside of that range to test.

TEST=vm/dart/use_dwarf_stack_traces_flag_test

Fixes: https://github.com/dart-lang/sdk/issues/50286
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try
Change-Id: Ia8965c72fbc6f6d2c178778a32f8083923a8b243
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363080
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-04-23 09:45:21 +00:00
Moritz 8bc935cdb3 Fix documentation for sublist of typed_data
Change-Id: I90ece50be57a7a57cc8bc2ef27402d63bfaa71bd
CoreLibraryReviewExempt: Documentation fixes only.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363704
Commit-Queue: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2024-04-22 08:54:02 +00:00