The interceptors provide a Dart `toString` method that uses the JavaScript `toString` method.
Issue: #53106
Change-Id: I1cf1df9e24fb4fd2d79679f1f014f39f083be7e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319563
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This reverts commit 1948b0a9fe.
Reason for revert: causes `promiseToFuture` to become undefined - b/295129286
Original change's description:
> [analyzer] simplify the libraries.dart file
>
> Change-Id: I86bc196eaddd9a80c02f38c8d947d3c0f4c63394
> CoreLibraryReviewExempt: the sdk_library_metadata/libraries.dart is only used by the analyzer
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317803
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Devon Carew <devoncarew@google.com>
Change-Id: I4810c408b996cefd46c0a40cc36818d34aa86071
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319402
Auto-Submit: Oleh Prypin <oprypin@google.com>
Commit-Queue: Oleh Prypin <oprypin@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
This is mainly used in [1] to allow using unboxed int lists when a
factory type argument is `int`, which then allows inlining unboxed int
list `[]` and `[]=` and storing and loading `int` values unboxed.
This implementation is mostly a copy of VM's transformer with the same
name. However we can't reuse VM's pass as we do different
transformations in [1].
[1]: https://dart-review.googlesource.com/c/sdk/+/318680
Change-Id: I16c06fc2b2edb1a5498807fc5c0fee839c003965
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318921
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Change-Id: I86bc196eaddd9a80c02f38c8d947d3c0f4c63394
CoreLibraryReviewExempt: the sdk_library_metadata/libraries.dart is only used by the analyzer
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317803
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Using setProperty triggers assertInterop, which prevents a Dart
Function from being boxed.
Change-Id: Ifa8a068abb7191ccb1c50f2733e6d85df411c945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317847
Commit-Queue: Joshua Litt <joshualitt@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
- Make Shape class final and more fields final.
- Add minor optimizations to `==`, `.hashCode` and `.toString`.
Cleans up or avoids a few issues I noticed while debugging some performance
regressions when calling Dart Core Object members on record values.
Change-Id: Ida7fdb5c562d03c03330e245e94c80321dc433c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317320
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Flipped the ordering of the equality operation so that the compiler
can see it is being dispatched to a string literal and can generate
a faster check.
Change-Id: I5c2f6b123ebe0f6cb81efba94fe4bf81168bec74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317261
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Sorting is 2-3x faster for a 1024 element list and simple comparison function.
Change-Id: Iecb4dceb7155e430fcc2c0ddef977003d747ab9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315760
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This change is almost trivial. The closure is stored on the callback's
RawReceivePort, not in the VM. So we can basically just remove the CFE
check and it pretty much works. The only problem is that we can't set
function.FfiCallbackTarget anymore, so most of the CL is dealing with
that.
A few places were deciding whether an FFI trampoline was a call or a
callback based on whether function.FfiCallbackTarget() was null. But
now the target will be null for async callbacks. So instead I've added
a new value to the FfiCallbackKind enum (and renamed it), and changed
those checks.
Sync callback closures will be a separate CL, because they're more
complicated.
Bug: https://github.com/dart-lang/sdk/issues/52689
Change-Id: I8e5dfb557362e679f66195b735c3c382e6792840
TEST=async_void_function_callbacks_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316160
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Following the refactoring we started in previous CLs, this splits string
and int patch files into (1) patch files that only patch and don't add
implementation classes (2) files for implementation classes (3) helpers.
Changes:
- `string_patch` is split into `string.dart` and `string_patch.dart`.
- VM's `integers_patch.dart` copied as `int_patch.dart` and updated.
This was needed as `integers_patch` requires VM's library paths in
imports.
We needed to copy this file to be able to optimize based on
dart2wasm's implementation classes. However in this CL we copy the
file as-is and update import paths.
- VM's `string_buffer_patch.dart` copied to be able to use the string
implementation classes from the new library.
`string_buffer_create.dart` is merged ino `string_buffer_patch.dart`.
- `getHash` and `setHash` to set object identity moved to
`object_helper.dart`, to be able to use in string implementations.
- Redundant `new` keywords in copied files removed.
One TODO added in `string_buffer_patch.dart` when allocating a new
string to the buffer:
// _parts = _GrowableList.withCapacity(10)..add(str);
// TODO(omersa): Uncomment the line above after moving list
// implementations to a library.
_parts = [str];
We can enable the old code again after moving list implementations to a
library.
Change-Id: Ice5dba40b3ba894797028987d4b42cb0c0f0c230
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315821
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
The change in [0] has propagated now everywhere, so we can use
`utf8.encode()` instead of the longer `const Utf8Encoder.convert()`.
As the checked-in SDK has been rolled to include [0] we can now rely on
the better return type.
[0] https://github.com/dart-lang/sdk/issues/52801
TEST=ci
CoreLibraryReviewExempt: Minor cleanup.
Change-Id: I2c0144023e03b2c265582d83a7fb9469b02f1570
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313563
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Define debugger runtime API so the debugger can display objects without knowing DDC implementation details.
- Add new DDC debugger runtime API in `debugger.dart`
- Add helpers for getting some type information in new and old type systems
- Add tests
Closes: https://github.com/dart-lang/sdk/issues/52773
Change-Id: I8efa4cacebb0d73ef58b5360979089cba2039379
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311154
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Anna Gringauze <annagrin@google.com>
- Use `array.copy` and `array.fill` when possible.
- Use the Wasm array directly (instead of `[]` and `[]=`) when possible
to avoid redundant bounds checks.
- `_GrowableList.insert` is rewritten to avoid a redundant write when
the element is not added to the end.
- Remove redundant bounds checks when calling `Lists.copy`.
Change-Id: I08d96b56201cbb4ff24ca969b7fde8bcc1315e4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315120
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Several locations in the core SDK contain `!` or `?.` operations that
will become unnecessary once the language feature `inference-update-2`
(which provides field promotion) is enabled. For example, in this
method from the class `_IOOverridesScope`, `_previous` refers to a
private final field, so after field promotion is enabled, the test `if
(_previous != null)` will promote it, and the `!` in
`_previous!.createDirectory` will become unnecessary:
Directory createDirectory(String path) {
if (_createDirectory != null) return _createDirectory!(path);
if (_previous != null) return _previous!.createDirectory(path);
return super.createDirectory(path);
}
Since the SDK is built in a mode where warnings like this result in
build failures, we need to temporarily change the logic into a form
where the same promotion effect is achieved through local variable
type promotion:
Directory createDirectory(String path) {
if (_createDirectory != null) return _createDirectory!(path);
var previous = _previous;
if (previous != null) return previous.createDirectory(path);
return super.createDirectory(path);
}
(Note that `_createDirectory` doesn't need to change, because it is a
non-final field, so it won't undergo promotion).
After `interface-update-2` has been enabled, I will make a follow-up
CL that removes the local variables and simply takes advantage of
field promotion, e.g.:
Directory createDirectory(String path) {
if (_createDirectory != null) return _createDirectory!(path);
if (_previous != null) return _previous.createDirectory(path);
return super.createDirectory(path);
}
Note: in theory it would be possible to do all this in a single step,
by atomically enabling field promotion and changing the SDK in the
same CL. However, I prefer breaking it up into stages like this,
because the act of flipping a langauge flag on tends to have
wide-ranging consequences, so I want the CL that does the flip to be
as small as possible.
Change-Id: I421c7661348bf407093ee64ef7f9dbfc0c04a353
Bug: https://github.com/dart-lang/language/issues/2020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314500
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Because it can, and therefore should.
Also update the methods to use `??` more, which should be
safe now that unsound null safety is no longer a thing.
Avoid chains of override-scopes by inlining the parts of the
outer scope which is not overridden.
Fix two bugs:
* `statSync` was checking whether `_stat` was non-`null`, then
calling `_statSync`.
* `socketConncet` did not pass source port to function.
CoreLibraryReviewExempt: Affects only VM.
Change-Id: I9d4971271305c52948d334f69ae71d750587ed97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314880
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
New typed data implementation that optimizes the common cases.
This uses the best possible representation for the fast case with a
representation like:
class _I32List implements Int32List {
final WasmIntArray<WasmI32> _data;
int operator [](int index) {
// range check
return _data.read(index);
}
void operator []=(int index, int value) {
// range check
_data.writeSigned(index, value);
}
...
}
This gives us the best possible runtime performance in the common cases
of:
- The list is used directly.
- The list is used via a view of the same Wasm element type (e.g. a
`Uint32List` view of a `Int32List`) and with aligned byte offset.
All other classes (`ByteBuffer`, `ByteData`, and view classes)
implemented to be able to support this representation.
Summary of classes:
- One list class per Dart typed data list, with the matching Wasm array
as the buffer (as shown in the example above): `_I8List`, `_U8List`,
`_U8ClampedList`, `_I16List`, `_U16List`, ...
- One list class per Dart typed data list, with mismatching Wasm array
as the buffer. These classes are used when a view is created from a
list, and the original list has a Wasm array with different element
type than the view needs. `_SlowI8List`, `_SlowU8List`, ...
These classes use `ByteData` interface to update the buffer.
- One list class for each of the classes listed above, for immutable
views. `_UnmodifiableI32List`, `_UnmodifiableSlowU64List`, ...
These classes inherit from their modifiable list classes and override
update methods using a mixin.
- One `ByteData` class for each Wasm array type: `_I8ByteData`,
`_I16ByteData`,
...
- One immutable `ByteData` view for each `ByteData` class.
- One `ByteBuffer` class for each Wasm array type: `_I8ByteBuffer`,
`_I16ByteBuffer`, ...
- A single `ByteBuffer` class for the immutable view of a byte buffer.
We don't need one immutable `ByteBuffer` view class per Wasm array
type as `ByteBuffer` API does not provide direct access to the buffer.
Other optimizations:
- `setRange` now uses `array.copy` when possible, which causes a huge
performance win in some benchmarks.
- The new implementation is pure Dart and needs no support or special
cases from the compiler other than the Wasm array type support and
intrinsics like `array.copy`. As a result this removes a bunch of
`entry-point` pragmas and significantly reduces code size in some
cases.
Other changes:
- Patch and implementation files for typed data and SIMD types are split
into separate files. `typed_data_patch.dart` and `simd_patch.dart` now
only contains patched factories. Implementation classes are moved to
`typed_data.dart` and `simd.dart` as libraries `dart:_typed_data` and
`dart:_simd`.
Benchmark results:
This CL significantly improves common cases. New implementation is only
slower than the current implementation when a view uses a Wasm array
type with incompatible element type (for example, `Uint32List` created
from a `Uint64List`).
These cases can still be improved by overriding the relevant `ByteData`
methods. For example, in the example of `Uint32List` view of a
`Uint64List`, by overriding `_I64ByteData.getUint32` to do a single read
then requested bytes don't cross element boundaries in the Wasm array.
These optimizations are left as future work.
Some sample benchmarks:
vector_math matrix_bench before:
Binary size: 133,104 bytes.
MatrixMultiply(RunTime): 201 us.
SIMDMatrixMultiply(RunTime): 3,608 us.
VectorTransform(RunTime): 94 us.
SIMDVectorTransform(RunTime): 833 us.
setViewMatrix(RunTime): 506 us.
aabb2Transform(RunTime): 987 us.
aabb2Rotate(RunTime): 721 us.
aabb3Transform(RunTime): 1,710 us.
aabb3Rotate(RunTime): 1,156 us.
Matrix3.determinant(RunTime): 171 us.
Matrix3.transform(Vector3)(RunTime): 8,550 us.
Matrix3.transform(Vector2)(RunTime): 3924 us.
Matrix3.transposeMultiply(RunTime): 201 us.
vector_math matrix_bench after:
Binary size: 135,198 bytes.
MatrixMultiply(RunTime): 42 us.
SIMDMatrixMultiply(RunTime): 2,068 us.
VectorTransform(RunTime): 12 us.
SIMDVectorTransform(RunTime): 272 us.
setViewMatrix(RunTime): 82 us.
aabb2Transform(RunTime): 167 us.
aabb2Rotate(RunTime): 147 us.
aabb3Transform(RunTime): 194 us.
aabb3Rotate(RunTime): 199 us.
Matrix3.determinant(RunTime): 70 us.
Matrix3.transform(Vector3)(RunTime): 726 us.
Matrix3.transform(Vector2)(RunTime): 504 us.
Matrix3.transposeMultiply(RunTime): 53 us.
FluidMotion before:
Binary size: 121,130 bytes.
FluidMotion(RunTime): 270,625 us.
FluidMotion after:
Binary size: 110,674 bytes.
FluidMotion(RunTime): 71,357 us.
With bound checks omitted (not in this CL), FluidMotion becomes
competitive with `dart2js -O4`:
FluidMotion dart2js -O4:
FluidMotion(RunTime): 47,813 us.
FluidMotion this CL + boud checks omitted:
FluidMotion(RunTime): 51,289 us.
Fixes#52710.
Tested: With existing tests.
Change-Id: I33bf5585c3be5d3919a99af857659cf7d9393df0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312907
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Now that we no longer need to put boxes in `core.dart`, it makes sense to move them out of `core.dart` so that we can patch these classes and their helper functions. This CL moves `BoxedInt` and `BoxedDouble` out of core patch, and moves some of their intrinsics / helpers to side libraries.
Tested: Dart2Wasm internal refactor of patch files.
Change-Id: I1dac95089a8bd9e2c8ee4f467a0d6f2792f9d665
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313900
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
In the new type system, allow native types that have a "peer" on
the Dart side to use that Dart type as their reified type.
This matches the semantics of the old type system for these types.
Change-Id: I62bf6cb1654d33549a6ea2c757e7e65fa81677a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313700
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
The purpose of the wasm_js_compatibility target is to facilitate experiments with a JS compatibility mode for Dart2Wasm. Initially, we're just going to focus on typed data, but this will give us a place to experiment with moving List and String to JS as well.
In addition, someday down the road we hope to experiment with two additional compatibility changes:
1) Exclusively using double for all Dart numbers
2) Allowing undefined to flow as null.
The two major benefits of this approach are:
1) Much faster JS interop
2) To make it easier to bring up Dart2JS applications on Dart2Wasm
The only downside will be access overhead on the Wasm side, but the JS builtins proposal could potentially bring us close to parity with Wasm builtins someday.
Tested: Wasm specific trivial refactor.
Change-Id: I2c09426b6999507c1de6e584e9bc7072a088bda9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313240
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: William Hesse <whesse@google.com>
This is a reland of commit 16fcfe7eae
Original change's description:
> [dart:js_interop] Remove Object.toJS and JSNumber.toDart
>
> Modifies JSBoxedDartObject reified type on JS backends and also
> modifies JSBoxedDartObject.toDart now that a proper box is introduced.
> Also uses a JS symbol in JSBoxedDartObject.toDart for a property
> check so that different Dart apps don't accidentally share Dart
> objects. It's now an error to call this function on non-boxed objects.
>
> Fixes a type issue where creating a new object literal with the JS
> foreign function was resulting in dart2js thinking toJSBox would
> always throw. Changing the typeDescription to PlainJavaScriptObject
> instead of =Object fixes that issue.
>
> CoreLibraryReviewExempt: Backend-specific library.
> Change-Id: I5cfb1f32ff4328fafdf9831b0d8da806c39391d9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309082
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
CoreLibraryReviewExempt: Reland.
Change-Id: If6b190f12bdf840b0259c5739f50d9bdcd27fd47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313600
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
This reverts commit 16fcfe7eae.
Reason for revert: Flutter changes haven't landed to google3 yet.
Original change's description:
> [dart:js_interop] Remove Object.toJS and JSNumber.toDart
>
> Modifies JSBoxedDartObject reified type on JS backends and also
> modifies JSBoxedDartObject.toDart now that a proper box is introduced.
> Also uses a JS symbol in JSBoxedDartObject.toDart for a property
> check so that different Dart apps don't accidentally share Dart
> objects. It's now an error to call this function on non-boxed objects.
>
> Fixes a type issue where creating a new object literal with the JS
> foreign function was resulting in dart2js thinking toJSBox would
> always throw. Changing the typeDescription to PlainJavaScriptObject
> instead of =Object fixes that issue.
>
> CoreLibraryReviewExempt: Backend-specific library.
> Change-Id: I5cfb1f32ff4328fafdf9831b0d8da806c39391d9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309082
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
Change-Id: I469ad04db7b49ffef47a46ccac97e909e4865719
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313580
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Modifies JSBoxedDartObject reified type on JS backends and also
modifies JSBoxedDartObject.toDart now that a proper box is introduced.
Also uses a JS symbol in JSBoxedDartObject.toDart for a property
check so that different Dart apps don't accidentally share Dart
objects. It's now an error to call this function on non-boxed objects.
Fixes a type issue where creating a new object literal with the JS
foreign function was resulting in dart2js thinking toJSBox would
always throw. Changing the typeDescription to PlainJavaScriptObject
instead of =Object fixes that issue.
CoreLibraryReviewExempt: Backend-specific library.
Change-Id: I5cfb1f32ff4328fafdf9831b0d8da806c39391d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309082
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Right now `utf8.encode()` has a static return type of `List<int>`
due to extending `Encoding` (which extends `Codec<String, List<int>>`).
We cannot easily change `Encoding` to extend `Codec<String, Uint8List>`
because that would also change `utf8.decode()` to require `Uint8List`
which would be a breaking change.
So instead we override `utf8.encode()` to have more precise return type.
Some parts of our SDK are run using the checked-in SDK, so it cannot
rely on the changed return type yet (until checked-in SDK is rolled).
So we use `const Utf8Encoder().convert()` as a temporary change, as
that already has `Uint8List` return type.
Issue https://github.com/dart-lang/sdk/issues/52801
TEST=ci
CoreLibraryReviewExempt: More precise return type for existing API
Change-Id: I2861d1f0eb3d292d8e3ec8437c0d441a2d2bd193
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254903
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Currently this throws a Wasm RuntimeError, which is difficult to
recover from.
Change-Id: I747682d6959b19746d6c98f2ea1b3fefd1ed2d03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312891
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
"[dart:html] Move NullWindowException to implementation"
This is a revert of bd3e6fa1a3 and
2b250992f9.
This adds some small code change to avoid a null-assertion being emitted
that would lead to a browser SecurityError.
CoreLibraryReviewExempt: Reland.
Change-Id: Iab52bb728b14fd0b2378b8923b0e1ea8ea930b12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311922
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>