Commit graph

11666 commits

Author SHA1 Message Date
Ömer Sinan Ağacan 9fbe418aa3 [dart2wasm] Use unchecked codeUnitAt in int.parse
Change-Id: I60c2a9a56ce9693061054fd72005e52fc6889aab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372901
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-24 13:40:08 +00:00
Nate Biggs 793194e2b9 [dart2js] Add retry suffix to part file multi-loader request URL.
The single loader does the same thing here:
ef59500e6f/sdk/lib/_internal/js_runtime/lib/js_helper.dart (L3257)

This retry token acts as a cache-buster for requests where the download succeeded but the part file was corrupted and failed to initialize. In that case Chrome has to re-download the file, it can't use the cached file.

I just missed passing this parameter when I added the new multiloader.

b/348644880

Change-Id: I26f4bc0da6c7e6fd714f442df8d32b8f10678047
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372700
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Auto-Submit: Nate Biggs <natebiggs@google.com>
2024-06-21 18:56:57 +00:00
Martin Kustermann 5e12a4a79b [dart2wasm] Optimize Dart->JS string conversion by specializing for OneByteString vs TwoByteString
Change-Id: Ia143312dc694a10fdaa778a57631bc98d14d9c7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372484
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-06-21 17:46:30 +00:00
Martin Kustermann 9761ccff6f [dart2wasm] Remove runtime blob to/from js string helpers, use JS<>() instead
This removes the special runtime blob for string conversions, instead we
make 2 functions for conversions use our built-in `JS<>()` support.

This will allow specializing the implementation in a future CL.

Change-Id: I06df25ed805042c0a3e2efb966eaebd1ce67dc0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372660
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-06-21 15:36:29 +00:00
Ömer Sinan Ağacan 844ced8016 [dart2wasm] Move list implementations to their own library
This WasmArray-backed list classes to `dart:_list`, similar to
`dart:_string` and `dart:_typed_data`

This will allow having internally-public list members like unchecked
getters and setters that we will use in the rest of the standard
library.

This CL doesn't add anything new, just renames things.

- `dart.core._ListBase` -> `dart._list.WasmListBase`

  This is to avoid confusion with `dart.core.ListBase` (defined by Dart
  standard library), and also to be consistent with `WasmTypedDataBase`
  and `WasmStringBase`.

- `dart.core._List` -> `dart._list.ModifiableFixedLengthList`

  Similar to the above, to avoid confusion with `dart.core.List`.

- `GrowableList.ofOther` -> `GrowableList.fromIterable`

  `ofOther` sounds like it should make a growable list from another
  growable list, but the type is more general than that. To reflect what
  it actually does we call it `fromIterable`.

Tested: Existing tests.
Change-Id: I24398765e1b0d549fc70b03ba94161479c5fc54c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372622
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-21 14:46:58 +00:00
Alexander Markov 6ca015ab20 [vm] Cleanup obsolete pragma vm:non-nullable-result-type
Since sound null safety, 'vm:non-nullable-result-type' pragma is
no longer useful as the same information is conveyed by a non-nullable
return type.

TEST=ci

Change-Id: Ie6a61aca38cfea47cb005b12ca7f0d7631791024
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372200
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-06-20 20:24:44 +00:00
Parker Lougheed 96eb11f052 Update various flutter.dev links to more stable destinations
Bug: https://github.com/flutter/website/issues/10363
CoreLibraryReviewExempt: Just updating link in API doc.
Change-Id: I6c4dc17206410fa86e88b4630c8056a994e18967
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372381
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Sam Rawlins <srawlins@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
2024-06-20 19:30:02 +00:00
Lasse R.H. Nielsen 705c745e19 Add @Since annotation, correct changelog entry position.
CoreLibraryReviewExempt: Trivial change.
Change-Id: I5c23641ed562efe51c0c7c35517ba75fffdd05ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372503
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-06-20 15:35:56 +00:00
Ömer Sinan Ağacan 7f370d1134 [dart2wasm] Add unchecked string operations extension, use it in libs
Add new string extensions with unchecked `codeUnitAt` and `substring`
methods.

Replace old unchecked functions `oneByteStringCodeUnitAtUnchecked` and
others with the extension methods.

Most of the CL replaces old functions with extensions. New uses are only
introduced in `dart:convert`.

Change-Id: I44151bbc65c0bf4467d88911f8a088bbe1910eaa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372443
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-20 13:55:45 +00:00
Ömer Sinan Ağacan a954aa0200 [dart2wasm] Move JSStringImpl to dart:_string
This moves `JSStringImpl` class from `dart:_js_types` to `dart:_string`.

This allows implementing a common base class with unchecked operations
to all string classes as internal methods (so users won't be able to
call them via `dyanmic`), and extension methods to call these unchecked
methods in libraries like `dart:convert`.

Uses of these methods are introduced in
https://dart-review.googlesource.com/c/sdk/+/372443.

Change-Id: Ie4cfe778654c42d62bc4a90391fe349fa783a42c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372442
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-20 13:08:03 +00:00
Martin Kustermann bfe05d6f36 [dart2wasm] Use WasmI32 (instead of double) as representation of integers across interop boundary
Currently code uses `double` to represent array indices, array lengths
etc. This seems wrong because `double`s can loose precision. This is
also a high overhead.

Understandably one could use `double` and only start to loose precision
with more than 32 bits, but realistically string lenghts, array lengths
cannot exceed 31-bits (i.e. 2 GBs) in practice.

=> Use Wasmi32 to represent array indices, array lengths, bytes loaded
from integer arrays, ...

Change-Id: Ife540622c85118d890a8e487677db56e2ce06f5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372424
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-06-20 09:55:19 +00:00
Lasse R.H. Nielsen a505bbc6a0 Add TypedDataList superinterface on typed data lists.
Adds an interface which implements both `TypedData`
and `List`. That allows abstracting over types that are both
`List` and `TypedData` without losing access to one of the
interfaces.

Tested: typed_data_interface_test.dart
Change-Id: Idbdfc084ea5d2d9a072887973e2e9d29a5fd94ce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371100
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-06-20 08:18:38 +00:00
Alexander Markov b48008ebd0 [vm] Remove unused dart:math and Double native methods
Flow graph builder implementation of certain dart:math and Double
methods is now used unconditionally, so corresponding native
methods are never used and can be removed.

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/371980.

TEST=ci

Change-Id: Ibca2729f70f39af26a899d99724ce62efc3c8dae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372180
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-06-18 21:51:16 +00:00
Ömer Sinan Ağacan 3b5065b49e [dart2wasm] Implement unmodifiable JS byte data
18994e6e46 removed unmodifiable view classes in the standard library
that can make any implementation of `ByteData` and other typed_data
types unmodifiable.

Add a `_immutable` field to `JSDataViewImpl`, implement
`asUnmodifiableView`.

An alternative implementation would be adding a subcalss with overridden
setters. However I think a simple boolean flag check should be better,
as adding a subtype can make call sites polymorphic and prevent direct
calls and inlining.

(We can't do the same in native typed_data types because we allocate
Wasm arrays with different element types for the fastest possible
implementation in the common cases, so we need different `ByteData`
implementations for different Wasm array types.)

Bug: #56014
Change-Id: I674121cff14559128bc2a9deb318a3bc6adf316d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372082
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-18 13:35:50 +00:00
Ömer Sinan Ağacan baa5aa826a [dart2wasm] Remove a duplicated loop in dart:convert
This removes the outer check in `List<int>` element check:

```
if (allowMalformed) {
   ... check code units in `List<int>`, write 0xFF for invalid bytes ...
} else {
   ... check code units in `List<int>`, throw for invalid bytes ...
}
```

and moves the `allowMalformed` check to the inside of the loop, when the
`int` value is negative or more then 255.

`allowMalformed` in UTF8 is used for two things:

1. To allow invalid bytes in `List<int>` argument.
2. To allow invalid UTF-8 encodings.

Both of these will happen rarely, but (1) will almost never happen as
any code that cares about performance will pass a `Uint8List`. So it
makes sense to assume that (1) will hold very rarely, and optimize based
on that.

Change-Id: I3ecec24d29d1cc2ec8f986a87ac3e7d609002d89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372060
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-18 12:35:53 +00:00
Ömer Sinan Ağacan 08ca631673 [dart2wasm] Remove unsafe casts in wasm:_simd
Change-Id: Ie864f441de5a441157c52efeb0e75164bdcf03b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371541
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-06-18 08:29:19 +00:00
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