Commit graph

9969 commits

Author SHA1 Message Date
Lasse R.H. Nielsen bdbd3c0602 Make unawaited accept a nullable argument.
The associated `unawaited_futures` lint triggers for expressions
of type `Future?` as well, so we should allow the workaround to
handle such expressions.

This change makes a static function more permissive, and is not expected
to be breaking in any way.
(It does mean that you need Dart 2.15.0 to use the function with
nullable arguments. I've changed the annotation to say `@Since("2.15")`.
That means anyone using a 2.15 SDK should assume that they need a 2.15
SDK to use it, and someone using a 2.14 SDK will not see the argument
as nullable. If anyone uses `@Since` annotations for anything at all.)

Change-Id: Ib2da4b353104cc88a834208a6ebd788ae55b4544
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214406
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-09-27 11:58:16 +00:00
Devon Carew 1d43ec2a99 Add an initial version of a script to validate the code samples in the dart: doc comments.
Change-Id: If74a11ffee8130963c37c9bd8ad74da4211f61d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214307
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-09-26 03:07:11 +00:00
Clement Skau 22652a3b49 [vm/ffi] Privatizes dart:nativewrappers' getNativeField(..)
TEST=Updated dart_api_impl_test.

Change-Id: Ib72667b2a20adc342f724a6eff7d326e2e106257
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214401
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-24 13:13:55 +00:00
Lasse R.H. Nielsen e4f12438a4 Add documentation on Future and Stream showing async programming.
The documentation on `Future` and `Stream` was only showing
the class API, not `async` programming.
Added examples of using `async`, `async*`, `await`, `await for`,
`yield` and `yield*`.

Fixes #47082

Bug: http://dartbug.com/47082
Change-Id: Ib8b4e8642412073e9e6124429d66747c277f89a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212470
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-09-24 13:07:40 +00:00
Lasse R.H. Nielsen 651d6e076b Add null-unsoundness check to print's object.toString() result.
This makes it an *earlier* error if a `toString` method returns `null`
when passed to `print`, possibly a new error if the underlying platform's
print implementation let `null` through.
Returning `null` is something `toString` was never supposed to do,
and with null safety, it's enforced by the type system,
so only pre-null-safety legacy code can actually return `null`.

Makes the error message from `NotNullableError` not assume a parameter,
so it can be used in more places.

Bug: https://github.com/dart-lang/sdk/issues/47196
Change-Id: I7f10156330994d31e44384fa952dd88385e2628d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214043
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2021-09-23 15:36:23 +00:00
Kevin Moore 4d82adb91f dart:html: use Object.hash
Drop custom hash class

Related to https://github.com/dart-lang/sdk/issues/27698

Change-Id: I7f5fb3a642e5ae461a00ed1b5d307adb4ef448df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214181
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2021-09-22 20:47:17 +00:00
Lasse R.H. Nielsen 18f37dd8f3 Add extension name getter on Enum.
We use an extension getter instead of an instance getter because
it doesn't conflict with any potential existing or future enums
which want an element named `name`.
Keeping the namespace for enum elements open is a priority.
We currently only reserve `index` and `values`.

BUG: https://github.com/dart-lang/language/issues/1511

Fixes language issue #1511, which is a long-standing request,
and should replace a number of alternative implementations
which are based on parsing the `toString()`.


This version has two fields on the shared superclass, the index
and private name, and has a separate `toString` for each `enum` class
which hard-codes that enum's class name.

An earlier version had both `"name"` and `"ClassName.name"` as fields
to be able to reuse the same `toString` method on all enum classes,
but that cost too much for JS compiled code.
Even having just `ClassName.` as a field and then combining inside
`toString` requires more code to create the enum instances.
Instead this version hardcodes the `ClassName.` string once
in the `toString` method, which means each enum class has its own
toString (which can *potentially* be tree-shaken then.)

This still tree-shakes slightly worse than the previous implementation
where every enum class had its own `index` and `_name` fields
independent of each other, which could then be tree-shaken independently.
However, the `index` was already made an interface member with the
addition of the `Enum` interface, so code which accesses `.index`
on something of the `Enum` supertype could prevent tree-shaking of
all enum classes' `index` fields.
Likewise any general access to the "name" of an enum would necessarily
do the same for the name.
This CL makes up for some of that by sharing more implementation
between enum classes.

DartVM AOT CodeSize impact: ~0.15% regression on gallery (little less on big g3 app)

TEST= New tests added to enum_test.dart

Change-Id: Id25334e6c987f470f558de3c141d0e3ff542b020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210480
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-22 14:20:16 +00:00
Nate Bosch bcaa2a320c Add fixes for Remaining renames
Add fix definitions and tests for renamed class and top level constants in
`dart:developer` and `dart:io`.

Change-Id: I6851bd61c68fdcff461117fe8f2ab1c3890cb9df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214000
Auto-Submit: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2021-09-21 16:07:30 +00:00
Nicholas Shahan 85a12eac55 [ddc] Fix missing type variable bounds subtype check
When testing the subtype relation between two generic function types,
uninstantiated type variables can appear as an argument or return type
of one function while a concrete type appears in corresponding
position of the other function. A subtype relation can be established
if the bound of the type variable is a subtype of the concrete type.
For example given a type variable T with bound B and a concrete type
C we can say:

T <: C when T <: B <: C holds.

T <: B is true by the definition of interface subtypes `T extends B`.
This change adds a test for B <: C.

Add a new class used only when it appears we may need to test these
subtype relations. The class is used to plumb the bound information
of type variables further into the subtype check algorithm where it
is now tested.

Add a top level variable to index the total number of type arguments
seen during a subtype check through nested function types.

Change-Id: If6aa13e7b758f7fedcb5dbd8e09d366082198e61
Fixes: https://github.com/dart-lang/sdk/issues/38816
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213527
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2021-09-20 23:29:45 +00:00
Nicholas Shahan e8cd9f0c44 [ddc] Refactor _isInterfaceSubtype
Move the method body out of one giant JS foreign function and into
Dart code with small JS foreign function calls inside.

* Removes the confusion around what it actually means when we use
  Dart String interpolation within the JS function template.
* Highlights the operations that actually need the JS foreign
  function.
* Allows for syntax highlighting and automatic formatting of this
  code.
* Allows for IDE "jump to definition" for class members that were
  previously inside the template.

These changes were developed by diffing the compiled output to
ensure the changes were as minimal and inconsequential as possible.
Intentional diffs include:
* Add a required message argument to `dart.assertFailed()`.
* Add local variables for `varianceType`, `typeArg1`, and
  `typeArg2`.

The only other diff was the loop variable incrementing:
`++i` -> `i = i + 1`

Change-Id: I76a1522fa4950f05748f905e1aec32c8b7dd4670
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213526
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2021-09-20 23:06:55 +00:00
Nicholas Shahan cf7d46097b [ddc] Refactor _isSubtype
Move the method body out of one giant JS foreign function and into
Dart code with small JS foreign function calls inside.

* Removes the confusion around what it actually means when we use
  Dart String interpolation within the JS function template.
* Highlights the operations that actually need the JS foreign
  function.
* Allows for syntax highlighting and automatic formatting of this
  code.
* Allows for IDE "jump to definition" for class members that were
  previously inside the template.

These changes were developed by diffing the compiled output to
ensure the changes were as minimal and inconsequential as possible.
The only diffs that appeared beyond the intentional addition of
the `t1Bound` and `t2Bound` local variables were:

* Using the top level variable for a type:
  `dart.nullable(core.Object)` -> `T$.ObjectN()`
* Loop variable incrementing:
  `i++` -> `i = i + 1`

Change-Id: I55fa3fa94b984c67b18a744837843d458231c4d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213525
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2021-09-20 21:28:29 +00:00
Ben Konyi dc58616486 [ Timeline ] Don't try to log async timeline events when Dart stream is
disabled

Related to https://github.com/flutter/flutter/issues/90061

Change-Id: Ic59cf60fe7d861109647be1a6c193fd4b63a211d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213780
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2021-09-17 18:49:21 +00:00
Sushant Chandla 2eb37e56ca Api Docs[core/int.dart]
The unsigned right shift was [implemented](https://github.com/dart-lang/language/issues/478#issuecomment-889181121)

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

GitOrigin-RevId: ec84d6886204a05906c11b6b1ebab023b8b33e38
Change-Id: Iafc195c8df212c8f78330f6ebef230daa6a6d280
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213560
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2021-09-15 22:47:04 +00:00
rnewquist 2917c1cb8f [io/http] Add a HTTP Client parameter on WebSocket.connect to allow a custom HTTP Client for web socket connections.
The WebSocket abstract class was changed to allow an optional parameter called customClient that takes in a HTTPClient and passes it to the WebSocket Implementation.
The WebSocket implementation takes the customClient, checks if its null, if its not null, it uses the customClient in place of the static HTTPClient that the WebSocket Implementation offers.
This custom client does not override the static HTTPClient, so all previous functionality remains the same when the customClient is not present.

TEST=testStaticClientUserAgentStaysTheSame() in web_socket_test.dart in standalone_2/standalone
TEST=new SecurityConfiguration(secure: true).runTests(); in web_socket_error_test.dart and web_socket_test.dart in standalone_2/standalone

Bug: https://github.com/dart-lang/sdk/issues/34284

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

GitOrigin-RevId: 58fed38baa606a8a492d3729190afa5009cc2409
Change-Id: I042b1e3fa7a4effed076c0deeec1f86af0dfe26d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200262
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2021-09-15 18:06:42 +00:00
Clement Skau cd7c9922eb [vm/ffi] Adds FFI transform for Handle -> Pointer.
This will automatically desugar FfiNative calls passing
NativeFieldWrapperClass1 handles to use Pointer when
the underlying native function expects a pointer.
E.g.:

```
class ClassWithNativeField extends NativeFieldWrapperClass1 {}

@FfiNative<IntPtr Function(Pointer<Void>)>('PassAsPointer')
external int passAsPointer(ClassWithNativeField obj);

passAsPointer(ClassWithNativeField());
// Becomes roughly:
// #t0 = PointerClassWithNativeField();
// passAsPointer(Pointer.fromAddress(getNativeField(#t0)));
// reachabilityFence(#t0);
```

TEST=Adds new tests in tests/ffi/ffi_native_test.dart.
Change-Id: I4460f9249803054f12be5d5ff34dbdf7c96567fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213260
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-09-15 12:47:35 +00:00
Riley Porter 0dd3c97147 Optimize js_util callConstructor for 0-4 arguments.
Some usages of `callConstructor` will have unnecessary checks
removed, when checks on the arguments can be elided. The
compilers will optimize further if they can.

Example optimizations: https://paste.googleplex.com/4594240957972480

Change-Id: I0e6e7e4d1268580cbfab84599b1c9da6fc64e7c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213114
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Riley Porter <rileyporter@google.com>
2021-09-13 22:43:10 +00:00
Mayank Patke a6c90f1601 [dart2js] Fix some unnecessary bailouts in inference.
Change-Id: If60fe11871da062c52265d821cbf0d7a1185e643
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209845
Reviewed-by: Stephen Adams <sra@google.com>
2021-09-13 21:59:20 +00:00
Stephen Adams 089bebcae7 Tweak Duration.toString to be more web-friendly
Change-Id: I588e089124d5c2fc62caa19cc2206c81666d6e8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213183
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2021-09-13 18:19:00 +00:00
Clement Skau 7d467e8933 [vm] Adds args_n to FFI resolver.
This makes it more closely mirror the Dart_NativeEntryResolver,
and acts as an extra sanity check that signatures (roughly)
align between the FfiNative decl. and the native function.

TEST=Updated runtime/vm/dart_api_impl_test.cc

Change-Id: I40799dc583ec14db14dc453afed4e2d1eb06fced
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212566
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-09-13 07:57:00 +00:00
Murtaza Raja 7c7f6623a9 typo: patter -> pattern in lib/core/pattern.dart
Closes https://github.com/dart-lang/sdk/pull/47198
https://github.com/dart-lang/sdk/pull/47198

GitOrigin-RevId: 647929b9ed24826261d37f60bd2180d79917e954
Change-Id: Ic857fffa8232e29f8ae5248bc7c4ce9264a090b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213220
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2021-09-12 18:23:08 +00:00
Lasse R.H. Nielsen 64f06ac544 Fix bug in Duration.toString().
The `toString` called `(-this).toString()` recursively
for negative durations.
If instantiated with the minimal integer on native,
that call would recurse infinitely.

The code has been wrong since we removed arbitrary precision integers.

TEST= Add test for regression case, otherwise covered by existing tests.

Change-Id: Ifb58bbc5aee38ef760f9352aede1694b79bae931
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212300
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2021-09-10 14:58:47 +00:00
Nate Bosch 828d1904e5 Rephrase bool getter doc
We want to avoid the "Returns" phrasing for getters.

Change-Id: Ia738c1566f720200a7b65a4ff441e1196129a6f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210286
Auto-Submit: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2021-09-10 14:35:28 +00:00
Jens Johansen 48d8225b17 [VM] [CFE]: Expression compilation inside extension method
This CL handles expression compilation inside extension methods better.
It is now possible to evaluate "this" and other methods defined in the
extension.

https://github.com/dart-lang/sdk/issues/46757

TEST=service tests added.

Change-Id: I3c71eb23117e26b01961f32103f4046f0b537976
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212286
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-09-10 12:02:57 +00:00
Albert Mañosa 67ff459606 fix: typo in Object.hash equality operator docs
Fix doc comments regarding equality operators in the newly added `Object.hash` and `Object.hashAll` methods.

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

GitOrigin-RevId: 4e168df4b4e4ad932e12d8a90f73d724d830a9e3
Change-Id: I4b3902cbece98ee31d977882196f0c8ffc210694
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212868
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
2021-09-09 16:40:33 +00:00
Bruno Leroux ffe3ee691c Call _profileData.finishRequest after request finalisation
Bug : request headers were not captured because finishRequest was
called to early (before headers was fully initialised)
Fixes #47115

TEST=pkg/vm_service/test/get_http_profile_test.dart

Change-Id: I544101c6f37d20e2ddfe7086698c0925f8f5bd09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212561
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2021-09-09 14:16:21 +00:00
Lasse R.H. Nielsen 39a165647a Add compareByIndex helper function to Enum.
Fixes https://github.com/dart-lang/language/issues/1836

Bug: https://github.com/dart-lang/language/issues/1836
Change-Id: I43ef26403a379c795a0bdcdeb470b4818ffb721e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212573
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-09-09 12:02:15 +00:00
Srujan Gaddam f34eef5b91 [dart:html] Migrate python scripts to python 3
Migrates syntax and semantics from python 2.7.

Major changes include:

- filters
- sorting
- print statements
- higher-order functions
- hashing and comparison

and other misc changes. go.sh consistently gives the libraries
in this and the previous commits with these changes.

Change-Id: I66365739887158d8f321015d36e556447da1bcd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211542
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Riley Porter <rileyporter@google.com>
2021-09-08 22:10:53 +00:00
Srujan Gaddam 8100b4de02 [dart:html] Fix implements order for classes
Using a set does not guarantee a consistent order from python 3
onwards, so use a OrderedDict to get a consistent order while
removing any duplicates.

Change-Id: I02d9aae2a82fd119f22b3a5e353b9445ffca963b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211541
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Riley Porter <rileyporter@google.com>
2021-09-08 18:45:02 +00:00
Vyacheslav Egorov d8d7af15ce [vm] Migrate away from native 'name' syntax.
As part of deprecating support for native extensions we are also
migrating away from legacy VM-specific `native 'name'` syntax
towards metadata based encoding which does not require any special
syntax.

This CL is a step 1 in migration:

- introduces support for `@pragma('vm:external-name', 'name')`
which serves as a direct replacement for `native 'name'`;
- all core libraries and tests are migrated to use the annotation;

Once this CL lands and rolls we will edit internal and external embedders
to eliminate uses of the native keyword (step 2) and finally remove
support for native keyword across our parsers (step 3).

TEST=ci

Bug: https://github.com/dart-lang/sdk/issues/28791
Change-Id: Id6dea878db82dd4fd81149243c425b5c5dc6df86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212461
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-08 13:39:34 +00:00
Emmanuel Pellereau 0933086397 Revert "[dart:html] Update Trusted Types APIs"
This reverts commit bda31c2c13.

Reason for revert: Breaks google3 (See b/195948578).

Original change's description:
> [dart:html] Update Trusted Types APIs
>
> Closes b/195948578
>
> Modifies Trusted Types APIs to be compliant with the spec in
> https://w3c.github.io/webappsec-trusted-types/dist/spec/.
>
> Change-Id: I65d52ace12342ce777ab596a9dd2e9a3f74b2f05
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212270
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Riley Porter <rileyporter@google.com>

TBR=sra@google.com,srujzs@google.com,rileyporter@google.com

Change-Id: I6c74fe5bfb1ecb39e01304b882ec306d5cf34442
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212741
Reviewed-by: Emmanuel Pellereau <emmanuelp@google.com>
Reviewed-by: Michal Terepeta <michalt@google.com>
Commit-Queue: Emmanuel Pellereau <emmanuelp@google.com>
2021-09-08 08:35:45 +00:00
Alexander Markov 16e8dc257e [vm] Faster double.floor()/ceil()/truncate() in AOT mode (x64, arm64)
1) double.truncate() now simply calls toInt(), omitting
truncateToDouble() call.

2) double.floor() and ceil() are now intrinsified on arm64 and AOT/x64
and generated using DoubleToInteger instruction.

3) DoubleToInteger instruction is extended to support floor and ceil.
On arm64 DoubleToInteger is implemented using fcvtms and fcvtps
instructions. On x64 DoubleToInteger is implemented using roundsd
under a check if it is supported (with a fallback to a stub and a
runtime call).

AOT/x64:
Before: BenchFloor(RunTime): 318.82148549569655 us.
After:  BenchFloor(RunTime): 133.29430189936687 us.

TEST=ci
Closes https://github.com/dart-lang/sdk/issues/46876
Closes https://github.com/dart-lang/sdk/issues/46650

Change-Id: I16ca18faf97954f8e8e25f0b72a2bbfac5bdc672
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212381
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2021-09-07 19:52:04 +00:00
Srujan Gaddam bda31c2c13 [dart:html] Update Trusted Types APIs
Closes b/195948578

Modifies Trusted Types APIs to be compliant with the spec in
https://w3c.github.io/webappsec-trusted-types/dist/spec/.

Change-Id: I65d52ace12342ce777ab596a9dd2e9a3f74b2f05
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212270
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Riley Porter <rileyporter@google.com>
2021-09-07 18:03:18 +00:00
Daco Harkes 40bbb6dcc2 [vm] Const map, remove invalid assert
Isolates are allowed to race each other to initialize _indexNullable,
the last isolate wins. See
https://dart-review.googlesource.com/c/sdk/+/210726 and
https://dart-review.googlesource.com/c/sdk/+/203765.

These asserts were wrong, because another isolate could have initialized
_indexNullable in between places calling _createIndex and _createIndex
itself.

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

Change-Id: I5d55b9715ef622737a6f70c0b57590076ece3225
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212586
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-09-07 15:47:22 +00:00
Daco Harkes 2b5adb7231 [vm] Implement constant Maps in the VM
This CL changes the frontend to emit map and set constants which are
then processed by the constant reader in the VM.

This CL also introduces support for sending the const maps and sets
in messages between isolates and saving it in snapshots.

TEST=tests/language/const/map_test.dart (et al, for lookups)
TEST=tests/lib/isolate/message3_test.dart (et al, for isolate messages)
TEST=tools/test.py -c dartkp (for consts from clustered snapshot)
TEST=tools/test.py -n app_jitk-linux-debug-x64 (for consts from app
     jit snapshots)
TEST=Building the SDK which uses const Maps in clustered snapshots.

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

Change-Id: I1f8150a8aba8298c4e64d2571dd147743526135a
Cq-Include-Trybots: luci.dart.try:analyzer-nnbd-linux-release-try,app-kernel-linux-debug-x64-try,dart-sdk-linux-try,front-end-nnbd-linux-release-x64-try,pkg-linux-debug-try,vm-canary-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-checked-linux-release-x64-try,vm-kernel-linux-debug-x64c-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-simarm64c-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203765
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-06 06:28:59 +00:00
Daco Harkes e8e9e1d152 [vm] Introduce immutable maps and sets in backend
This CL introduces immutable maps and sets in the VM backend but does
not yet target them from the frontend. The changes are tested by unit
tests constructing these immutable maps and sets.

This CL introduces immutable variants of the hash map and set in
compact_hash.dart and recognizes them in the VM. The immutable ones
use a different mixin with a different recognized method for accessing
members.
* Data list is an immutable list with a different cid. (Otherwise the
  optimizer notices that immutable and mutable lists cannot be equal.)
* Index is a nullable mutable typed data. (Otherwise optimizer removes
  necessary null checks.)
* Index should use a store-release barrier when written to.

Multiple isolates might lazily compute the index for const sets and
maps. This is fine because all identityHashCodes and hashCodes are
guaranteed to be race-free. The later isolates will override the index
pointer with an identical index.

This CL does not introduce support for using these immutable maps and
sets in AOT (clustered_snapshot) and in messages to other isolates
(message_snapshot) because that is harder to test with unit tests. That
will be added in the follow-up CL.

Design doc: go/dart-vm-const-maps

TEST=runtime/vm/object_test.cc

Bug: https://github.com/dart-lang/sdk/issues/45908

Change-Id: I4042179c15e8b37692d3255655351c01c7124991
Cq-Include-Trybots: luci.dart.try:analyzer-nnbd-linux-release-try,app-kernel-linux-debug-x64-try,dart-sdk-linux-try,front-end-nnbd-linux-release-x64-try,pkg-linux-debug-try,vm-canary-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-checked-linux-release-x64-try,vm-kernel-linux-debug-x64c-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-simarm64c-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210860
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-06 06:28:59 +00:00
Srujan Gaddam 07aa93a532 [dart:html] Add js_util import to dart:html
Part of https://dart-review.googlesource.com/c/sdk/+/210100

As classes get migrated to js_util, this import is needed.

Change-Id: Ib455257883257af2e145c222ab903488b22f13f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211540
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2021-09-03 21:53:27 +00:00
Nicholas Shahan 5ea90ee907 [ddc] Enable construtor tearoff lowering
* Update tearoff runtime equality algorithm with newly specified
  requirements.
* Update kernel golden files for the dartdevc target to include
  the static method lowering for constructor tearoffs.
* Avoid adding source maps and debug symbols to the static methods
  created by the CFE lowering.
* Add additional expected non-nullable values detected in the
  nullable inference tests. These correspond to the values that
  appear in the static method return statements.

Measurements taken from large applications show the lowering causes
a code size increase of 2.5%-3.5%. That increase did not appear to
create any measurable difference in initial page load time but if
there turns out to be a regression we can revisit each of the various
lowerings to implement support in DDC at the site where the constructor
is torn off.

Fixes: https://github.com/dart-lang/sdk/issues/46486
Fixes: https://github.com/dart-lang/sdk/issues/46837
Change-Id: I01fa39d4f1d0e937919dd1466bb6a34c91a10e75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206960
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2021-09-03 17:48:58 +00:00
Vyacheslav Egorov bda70c8489 [vm] Remove support for dart-ext: imports
Per breaking change #45451 we are removing support for dart-ext:
style native extensions from the Dart VM.

This CL removes the associated VM code, tests and samples. It also ports
a single test which used dart-ext: import to use FFI instead.

TEST=ci

Bug: https://github.com/dart-lang/sdk/issues/45451
Change-Id: Iae984bce32baf29a950b5de1323939006a217b94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212050
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-02 14:14:35 +00:00
Alexander Markov 307bc3ef2c [vm] Faster double.toInt() in AOT mode
double.toInt() micro-benchmark on AOT/x64:
Before: BenchToInt(RunTime): 438.67258771929824 us.
After:  BenchToInt(RunTime): 118.8603434955726 us.

double.floor() micro-benchmark on AOT/x64:
Before: BenchFloor(RunTime): 537.2132688691916 us.
After:  BenchFloor(RunTime): 321.2052352657781 us.

TEST=ci
Issue https://github.com/dart-lang/sdk/issues/46876
Issue https://github.com/dart-lang/sdk/issues/46650

Change-Id: Id37c827bceb7f374ae5b91b36871ccf0d9e92441
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211620
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-09-01 16:57:59 +00:00
Lasse R.H. Nielsen ed3824a220 Tweaks, refactoring and updates on DoubleLinkedQueue.
It's a badly designed class, but this change makes it slightly better.
(We should consider moving it to package:collection and removing it from
the platform libraries. Eventually.)

The changes decouples the public `DoubleLinkedQueueEntry` class from
the actual queue implementation classes, avoiding the latter having
to share a generic `_Link<DoubleLinkedQueueEntry>` interface
which would force them to do otherwise unnecessary casts.

The public class should have been abstract, but isn't.
It's mainly used as the API of the entries exposed by DoubleLinkedQueue,
but it can also be used by itself to build double-linked lists that are
not part of a Queue, and the class can be extended.
If anyone does either, it should keep working, so it needs to be a concrete,
self-contained class with a generative constructor.

That class is moved to dart:_internal to avoid its private
implementation fields from interfering with the queue implementation classes,
which have similar fields, but can now have them at different types.
That's a hack, but it works.

The internal implementation of the DoubleLinkedQueue and its entries
are updated to better follow current programming idioms, and avoids
having fields on classes which don't need them.

Also fixes #27920
(`clear`ing a list now detaches each entry from the list so later `.contains`
won't give the wrong answer).

And moves queue tests from tests/corelib to tests/lib/collection,
since Queue isn't exposed by `dart:core`.

BUG= https://github.com/dart-lang/sdk/issues/27920

Change-Id: Ia3bb340a75886de160cc0e449947e8e7ee587061
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211265
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-08-31 12:44:39 +00:00
Alexander Markov 28348d650f [vm] Move implementation of dart:math intrinsics to flow graph builder
This change removes duplicated implementations of dart:math intrinsics
from GraphIntrinsifier/AsmIntrinsifier and FlowGraphInliner, and adds
a single implementation in FlowGraphBuilder.

TEST=ci

Change-Id: Ifcf285aba15e1b240144215463cd6b2703a8937c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211481
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2021-08-27 17:42:27 +00:00
Daco Harkes d8093982aa [vm] Cleanup dead code RTE ClassID_getID
This has been dead code since the bytecode interpreter has been removed.

TEST=This removes dead code. Building the SDK tests this code is not
     imported. Running the CQ tests it was not executed.

Change-Id: I75ce3fc2dfccb57d3287db7e716901a8b5a0c20e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211264
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2021-08-27 07:09:26 +00:00
Stephen Adams 5c582f82f0 [dart2js, js_runtime, js_dev_runtime] NaN-safe range checks.
`int` variables can attain NaN values because web int arithmetic
implemented by JavaScript numbers (doubles) is not closed under many
operations. It is possible get NaN using only addition:

    int a = 1, b = -1;
    while (a + a != a) { a += a; b += b; }
    int nan = a + b;

On the VM, a, b and nan are all zero.
On the web, a, b and nan are Infinity, -Infinity and NaN, respectively.

Since NaN can leak into int arithmetic, is it helpful if bounds checks
catch NaN indexes. NaN compares false in any comparison, so a test
of the form

   if (index < 0 || index >= a.length) throw ioore(a, index);

fails to detect a NaN value of `index`.
This is fixed by negating the comparisons, and applying De Morgan's law:

   if (!(index >= 0 && index < a.length)) throw ioore(a, index);

These changes have been applied to JSArray.[], JSArray.[]= and String.[]

For dart2js the change is a little more involved. Primitive indexing is
lowered to code with a HBoundsCheck check instruction. The code generated
for the instruction now uses, e.g. `!(i>=0)` instead of `i<0`.
This leads to a small code size regression.

There is no regression at -O4 since bounds checks are omitted at -O4.

At -O3 (where the regression is largest) the regression is
   0.01% for cm
   0.06% for flutter gallery -- array-heavy diff and layout
   0.21% for Meteor          -- array-heavy code
   0.30% for Box2DOctane     -- array-heavy code

I believe the regression can be largely alleviated by determining if
NaN is impossible at the index check, and if so, reverting to the smaller
code pattern. The analysis could be global, incorporating NaN into the
global abstract value domain, or a much simpler a local dataflow
analysis. Many indexes are loop driven and cannot reach infinity because
they are incremented by a small bump and eventually (even without a loop
guard) the index would stop growing when the increment falls below the
rounding error in O(2^53) iterations.


Change-Id: I23ab1eb779f1d0c9c6655e13d69f65d453db9284
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210321
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2021-08-27 00:37:56 +00:00
Alexander Markov f0d6b8864d [vm] Faster double.floorToDouble/ceilToDouble/truncateToDouble/roundToDouble in AOT mode
This change replaces graph intrinsics and call specializer code for
certain _Double methods with a body created in FlowGraphBuilder.

double.floorToDouble micro-benchmark on AOT/x64:
Before BenchFloorToDouble(RunTime): 642.3240205523442 us.
After: BenchFloorToDouble(RunTime): 268.0320289466631 us.

double.floor micro-benchmark on AOT/x64:
Before BenchFloor(RunTime): 760.7630277672118 us.
After: BenchFloor(RunTime): 537.2132688691916 us.

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/46650
Change-Id: I47f5d8a1bdc0f71965ad1763c7bc46540428c6cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210652
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-08-27 00:33:46 +00:00
suragch a5194c80c2 Correcting misnamed variable in doc comments
Unless I'm missing something, the map that is being referenced here is `x` from the function argument. It looks like calling it `map` was just a typo. Alternatively rename `x` to `map`.

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

GitOrigin-RevId: 940442bfaa1517b33f811488773618e6f2e387d8
Change-Id: I0d24e28edef7f6e941d3247f7d647b22670a35b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211360
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2021-08-26 09:48:31 +00:00
Stephen Adams 7731eea468 [dart2js] Instantiation.== and Instantiation.hashCode
Change-Id: Ic4e9c882b27a6490a913899d74141ff73c4aebab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210981
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2021-08-25 21:07:02 +00:00
Sigurd Meldgaard ae81cd5dab Deprecate top level pub.
Also makes the `pub` shell script (and its .bat counterpart)
forward to a `dart __deprecated_pub` command that implements the
old top-level.

This allows us to get rid of pub.dart.snapshot saving ~15 MB in a
unzipped sdk.

The reason for not forwarding directly to `dart pub` is that the
interface is slightly different (for example there is no `dart pub --version`).


The only new commit in pub is: `3c2ce330 Expose toplevel as a command`


Bug: https://github.com/dart-lang/pub/issues/2736
Change-Id: I6eb08d120c4844b3a12bc29544df6a868cd6fcc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210582
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Jonas Jensen <jonasfj@google.com>
2021-08-24 08:34:58 +00:00
Michael Thomsen 6c5fb84716 Discontinue dart2native (use dart compile)
TEST=Existing tests updated to use dart compile

Change-Id: Ia3478069df2354a3bf057fedae0f1eea9415de95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210241
Commit-Queue: Michael Thomsen <mit@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2021-08-23 20:53:09 +00:00
Martin Kustermann 0201d76154 [vm/concurrency] Remove internal-only "Isolate.spawn() into new group" functionality
This was mainly used as a backup plan which is no longer needed at this
point.

This CL removes internal only functionality that couldn't be used by
end-users.

TEST=ci

Change-Id: Ie0828bda1ba48ee6a5a460ff039267e0549e0060
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210340
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-08-19 15:19:00 +00:00
Alexander Aprelev 386338edd8 [vm/sendport] Do port handler lookup and message dispatch in one dart call.
This improves performance of SendPort.Receive.Nop benchmark with isolate groups enabled on Intel Xeon by ~17%.
This benchmark emphasizes performance of handle message flow.

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

TEST=ci

Change-Id: I3b9be3283047631e8989bb56f90af2b3b007afe8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209642
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-08-18 13:31:43 +00:00