Commit graph

11514 commits

Author SHA1 Message Date
Martin Kustermann c625797f8a [dart2wasm] Implement dart:developer in dart2wasm
* We migrate the `dart:developer` implementation of dart2js to
static interop.

* We make dart2wasm use the same implementation as dart2js.

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

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

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

TEST=ci

Change-Id: Iad00a17473a630659f15a5c73be0f5385ea35bdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350688
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-02-22 06:22:12 +00:00
Ömer Sinan Ağacan 2da70a8d9e [dart2wasm] Improve closure hash codes
Currently hash code for a closure is the hash code of it's runtime type.

This causes a lot hash collisions in some apps and cause performance
issues.

With this patch we now use captured objects in closures when calculating
hash codes.

The hash codes are now:

- For tear-offs:

    mix(receiver hash, closure runtime type hash)

- For instantiations:

    mix(instantiated closure hash,
        hashes of captured types)

  Note that an instantiation can be of a tear-off, in which case
  "instantiated closure hash" will calculate the tear-off hash as above.

- For others (function literals, static functions), the hash is the
  identity hash.

Fixes #54912.

CoreLibraryReviewExempt: Mark private corelib function as entry-point in Wasm
Change-Id: I6a123fdc690237f543bb8bf832f0f8119d013a55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353162
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-02-21 14:44:20 +00:00
Lasse R.H. Nielsen e86b08e5bb Forwards ignore bit to chained-to _Future.
If a target `_Future` is chained to another source `_Future`,
then it's because the target will complete with the same
result as the source future. Instead of keeping both
alive with a listener on the source which completes the target,
instead the target moves all its listeners to be directly on
the source, and keeps a link to the source in case more listeners
are added later.
The idea is that most futures are unreferenced after they have
had their first listener, so the target future has a chance
to be GC'ed.

If the target future has `.ignore()` called, and has no listener,
then the source completing with an error should not cause the
error to be uncaught. Without the optimization, the source would
have had a listener, and the target would ignore the error.

To simulate that, the source now gets a copy of the target's
`_ignoreUnhandledErrors` flag.

This is still not precisely the same as it would be without the
optimization. If *two* target futures are chained to the same source,
and only one of targes has `.ignore()` called, then this
implementation will make the uncaught error not be reported,
where it technically should.

(An alternative would be to *not* use chaining for futures
with `ignore()` called on them. But those are precisely futures
that are likely to be GC'able, because someone has already said
that they don't care if the future complete with errors.)

Fixes #54943

Bug: https://github.com/dart-lang/sdk/issues/54943
Change-Id: I0dbb4919ce2ea612d66539862fa0eb188aab8287
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352908
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-21 13:05:56 +00:00
Jake Macdonald 123e680534 update public macro apis in dart:_macros
Change-Id: Ic27669dee0bbaa96a362e5ecc5fecdd9bb86b693
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353321
Auto-Submit: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-02-21 12:06:09 +00:00
asiva ac39be3eed [VM/Service] Define vmservice entry points only under non product mode
TEST=ci

Change-Id: I2d72d4c786e3725434c552a317da6b50a08646c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353228
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-02-20 22:48:47 +00:00
Nicholas Shahan 3c13e9f273 [ddc] Cleanup dead code from the runtime library
This code is no longer used now that the new runtime types are always
enabled.

Change-Id: I0c7d627199a10e023d5d1afa581812b360e9a0f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344609
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-02-16 22:33:54 +00:00
Brian Quinlan 770f44d4e9 [io] Make it possible to change the line ending output by stdout and stderr.
There is a performance impact in:
`stdout.lineTerminator = "\r\n";`

For small writes (<100 chars), the performance loss is lost in the noise of the `write` system call.

For writes of ~500 chars, the performance is about half of that without line terminator translation. But, on a M2 Mac laptop, ~80M characters can be written per second.

Bug: https://github.com/dart-lang/sdk/issues/53161
Change-Id: Icfa0f981dcf6edb856d8aac5e0e270bc0148d498
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326761
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2024-02-16 20:06:03 +00:00
Vyacheslav Egorov 2280b06202 [vm] Improve detection of handled async errors
Improve the handling of code where the async flow forks:
e.g. for `fut.whenComplete(c.complete)` we might proceed
unwinding through awaiters of `c.future` and forget about the
future returned from `whenComplete`. This happens because
we choose to present result of the unwinding as a single
stack and not a tree. In this situation the error will only
propagate into that future and whether or not the error will be
handled depends on that future alone.

As part of this change also start respecting ignored bit on
futures without listeners.

TEST=pkg/vm_service/test/pause_on_unhandled_async_exceptions7_test.dart

CoreLibraryReviewExempt: Comment only changes to core library
Change-Id: I27b689ab07a725e8faa8d91cf40e88ebc8c441a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352904
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-02-16 12:55:22 +00:00
Vyacheslav Egorov df6fd34f75 [vm] Improve asynchronous unwinding through Stream methods
This CL adds @pragma('vm:awaiter-link') in various places in
Stream implementation to facilitate unwinding and expands
async unwinding logic with more information about
Stream internals.

At the same time be more conservative when checking if an
exception thrown from async method handled: failing to unwind
the stack fully creates situations when we incorrectly report
caught exceptions as uncaught, which frustrates users.

To distinguish stream subscriptions with and without error
handlers we add a state bit. Otherwise, it looks like all
subscriptions have error handlers because if no error
handler is installed we eagerly install error handler forwarding
the error to `Zone.handleUncaughtError`.

Fixes https://github.com/dart-lang/sdk/issues/53334
Fixes https://github.com/dart-lang/sdk/issues/54788
Fixes https://github.com/dart-lang/sdk/issues/47985

TEST=runtime/vm/dart/awaiter_stacks/stream_methods_test.dart,pkg/vm_service/test/pause_on_unhandled_async_exceptions6_test.dart,pkg/vm_service/test/pause_on_unhandled_async_exceptions7_test.dart

CoreLibraryReviewExempt: No behavioral change. Async changes reviewed by lrhn@
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-dwarf-linux-product-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try
Change-Id: Ic51f926867092dd0adbe801b753f57c357c7ace2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322720
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-02-15 23:00:44 +00:00
Derek Xu 628d744391 [dart:developer][VM/Service] Add APIs to dart:developer for recording HTTP profiling information, and for later retrieving that information
The APIs mentioned above are `addHttpClientProfilingData` and
`getHttpClientProfilingData`.

This CL also makes it so that profiling information recorded using
`addHttpClientProfilingData` is included in dart:io service extension
responses.

TEST= pkg/vm_service/test/get_http_profile_test.dart

Change-Id: I892a7a8485369bb92cbb0c086b93498bcec25d5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341440
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-02-15 18:56:08 +00:00
Nicholas Shahan f6ffe00f28 [ddc] Avoid calling addTypeCaches with new types
Some preparation for deleting all the old type system code.

Change-Id: I9319064100ce19a4122612c36781c7e4a71094aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352724
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-02-15 18:28:49 +00:00
Kenzie Schmoll 0cb3fcca48 [developer] Update dart doc for Service.getIsolateId
Change-Id: I487bdd22362c73051d62147bacb5fe35c3f0445b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352500
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Kenzie Davisson <kenzieschmoll@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-02-15 17:48:00 +00:00
Ömer Sinan Ağacan 2bdcfb7035 [dart2wasm] Fix instantiation closure equality
We can't generate a virtual call to `Object.==` in generated code as
`Object.==` may not be added to the dispatch table, even with
`@pragma(wasm:entry-point)`.

Instead this adds a top-level `_runtimeTypeEquals` function that calls
`==` on the `_Type` argument. Effectively this forces adding `_Type.==`
to the dispatch table and calls it virtually.

Fixes #54926.

Change-Id: Ice3306ed00f66c8abedb3ef11b58c15296457eb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352900
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-02-15 17:33:01 +00:00
Parker Lougheed b55ecc907e [sdk/lib] Update SystemHash.smear for improved parameters
The linked README(https://github.com/skeeto/hash-prospector#two-round-functions) has been updated with these parameters that result in a significantly lower bias that other projects have also began adapting.

For context, this function is used internally by `Object.hashAllUnordered`.

Change-Id: I7ca042196bbfdb5abdb28f8d6d9cbca69d21fb2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351920
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2024-02-15 15:06:58 +00:00
Liam Appelbe c3a626f729 [lib] Private API for disabling Isolate.exit().
This is needed to prevent users from closing the platform isolate.

Bug: https://github.com/flutter/flutter/issues/136314
Change-Id: I98ab0a847dad245a1f1d6c16e96f2f4add39a84f
TEST=runtime/vm/isolate_test.cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352760
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2024-02-15 01:18:40 +00:00
Parker Lougheed 885126e51b [sdk/math] Mark Point, Rectangle, and MutableRectangle as legacy
These can't be deprecated for a while, at least not until 'dart:html' itself is.

In the mean time, we can at least discourage usage of it and direct developers to more appropriate, long-term solutions.

Contributes to https://github.com/dart-lang/sdk/issues/54852

CoreLibraryReviewExempt: Documentation only change that directs developers to more specific, performant, or flexible solutions.
Change-Id: I9d099a49909673f8af23eab480fdd225e56bcab2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351961
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-02-14 18:35:17 +00:00
Martin Kustermann 5d664b4bd4 [dart2wasm] Avoid using allowInterop in Promise<->Future conversion
The dart closures for the then/onError callbacks we use on a JS promise
will not flow back into dart. There's therefore no reason to use the
very heavyweight `allowInterop` mechanism.

This makes (after [0]) asynchronous calls to JS from Dart more than 2x
as fast.

This also aligns the `promiseToFuture` implementation with the extension on
`JSPromise` (see sdk/lib/_internal/wasm/lib/js_interop_patch.dart)
modulo the fact that the API doesn't work on interop types but Dart
types and needs therefore the full JS<->Dart conversion.

=> Maybe it would make sense to deprecate `promiseToFuture` / not offer it
in dart2wasm and make users use instead the extension on `JSPromise`
instead?

[0] https://dart-review.googlesource.com/c/sdk/+/352520

Change-Id: Ibc80bf083e7ec817f000257d6995108954060277
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352521
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-14 11:48:15 +00:00
Srujan Gaddam f20cd26533 Update JSExport docs to refer to createJSInteropWrapper
Also cleans up some wording and better explains all the possible
features of the annotation.

CoreLibraryReviewExempt: Docs for backend-specific library.
Change-Id: Id5f3e1ea09d2ceaf9f727eb7885b38319b978dd6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352441
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-02-14 00:36:25 +00:00
Martin Kustermann 385ab26022 [dart2wasm] Use identity hashmap for allowInterop closure map
This significantly speeds up certain operations as it avoids calling
complex closure equality logic in the hashmap operations.

See also [0] regarding us leaking those closures.

[0] https://github.com/dart-lang/sdk/issues/54908

Change-Id: I046063884b88fbe53bc3cb397b0087693c9b928a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352520
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-13 21:49:58 +00:00
Brian Quinlan 9967075787 [io] Fix a bug where Process.stdin.add exceptions could not be caught
Change-Id: I2383a74bfa6950ab8f8934087fb68218f06dd681
Bug:https://github.com/dart-lang/sdk/issues/48501
Tested: Unit test
CoreLibraryReviewExempt: dart:io only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351380
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
2024-02-13 18:26:49 +00:00
Lasse R.H. Nielsen 712df96202 Avoid type checks in Future.wait
CoreLibraryReviewExempt: Bypassing because Wasm-approver is OOO.
Change-Id: I484e900c14f181f56083b6e90a0d1f34546c85e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341504
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-02-13 16:07:12 +00:00
Parker Lougheed 78dbc184b1 [sdk/js_interop] Clean up and add a few minimal API docs
CoreLibraryReviewExempt: Only touches JS core library documentation.
Change-Id: I7d7f0a2b646f95de8340e9e77d8207cd99c9a1b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351940
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2024-02-12 14:44:54 +00:00
Martin Kustermann aadac65a2e [dart2wasm] Faster string equality
There should be no need to use polymorphic `.codeUnitAt()` calls in
the common case: comparing OneByteString with OneByteString, etc

This increases e.g. LongStringCompare.* benchmarks by 600+%

Change-Id: I1b7b2b53f35237d1ddc1c177c01728629a4acf40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352020
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-12 14:06:50 +00:00
Martin Kustermann 790297b812 [dart2wasm] Use WasmArray<>s for string interpolation expressions
* Use `WasmArray<>`s in string interoplation expressions
* Use `WasmArray<>`s in string buffer implementation
* Avoid making OneByteString+JSString imply TwoByteString

This also increases performance significantly, e.g.
JsonObjectRoundTrip & StringBuffer by 40% in -O4 and even more
speedup in -O2

Change-Id: I25485a6c532c3afed7d92943b6de4d1452930606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352000
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-12 14:01:12 +00:00
Daco Harkes ddfc00e773 [vm/ffi] Unify TypedDataBase wrappers
For getting the address of `Struct` fields and `Array` elements
it would be useful to access the `_typedDataBase` field in these
'wrappers' in a unified way.

This CL makes `Array` extend `_Compound`.
Since `Array` is not a `SizedNativeType`, the implements clauses
for `Struct` and `Union` are moved to these classes.

Moreover, any references to 'compound' which only apply to struct or
union are updated.

TEST=test/ffi

Bug: https://github.com/dart-lang/sdk/issues/44589
Bug: https://github.com/dart-lang/sdk/issues/54739
Bug: https://github.com/dart-lang/sdk/issues/41237

CoreLibraryReviewExempt: No API change, only refactoring.
Change-Id: Ib9d8bccd4872df04bcc67731e4052f826ab70af4
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350960
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2024-02-09 21:27:29 +00:00
Mayank Patke c556766395 [dart2js] Expose JS_TRUE and JS_FALSE via dart2js_runtime_metrics.
dart2js already had an external function in foreign_helper called
JS_FALSE. This function is completely opaque until it is lowered to the
constant value `false` in SSA, so one can write `if (JS_FALSE())` in
order to ensure that the guarded code is treated as live and compiled,
but eventually tree-shaken and omitted from SSA and codegen.

This CL adds a JS_TRUE counterpart for completeness, and exposes both
JS_TRUE and JS_FALSE through package:dart2js_runtime_metrics.

Change-Id: I9b375fa37ada1b65fb9183902bb295e05fa6b8c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349704
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-02-09 18:38:55 +00:00
Mayank Patke 85037bf96d [dart2js, ddc] Clean up conditional imports in dart2js_runtime_metrics
This CL:
* adds empty dart:_dart2js_only and dart:_ddc_only libraries for use in
  conditional imports,
* updates pkg/dart2js_runtime_metrics to use the new libraries rather
  than dart:_dart2js_runtime_metrics and dart:js,
* and removes some unnecessary libraries, including VM-specific
  implementations in pkg/dart2js_runtime_metrics and the DDC
  implementation of dart:_dart2js_runtime_metrics.

Change-Id: I9500aa303fa5ad8aba0e1d413f69957c268f3f11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350681
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-02-09 18:38:55 +00:00
Sigmund Cherem 5941ee7560 [dart:html] minor fix to clearWatch.
This is a fix to not include a null assert when it's
possible the value was null.

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

CoreLibraryReviewExempt: bug fix only affecting html library implementation
Change-Id: I26e6ebf3dc2d1ea3f9f458a32f519c5235e6d273
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350982
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-02-08 23:23:20 +00:00
Martin Kustermann 26aa50fdbf [dart2wasm] Fix off-by-one error in List.insert()
Closes https://github.com/dart-lang/sdk/issues/54845

TEST=lib/collection/regress_54845_test

Change-Id: I1af7f59a57c70ef5ec724b089555ebbcbd88a484
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351120
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-02-08 14:05:44 +00:00
Kevin Moore 53056b663e js_interop[_unsafe]: update library documentation
CoreLibraryReviewExempt: just changing web libraries
changekind:NO_CODE_CHANGE
Change-Id: Idc8ab1865f43f33c3ab0824142b38fa715b1579b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350520
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-02-07 01:47:27 +00:00
Stephen Adams 7ef215a4a5 Reapply "[typed_data] Deprecate unmodifiable views"
This change, for Dart 3.4, deprecates the unmodifiable typed data constructors. Users of these constructors can upgrade the use of the constructors to instance method `asUnmodifiableView()`, or pin to Dart 3.3.

See https://github.com/dart-lang/sdk/issues/53785 for context.

CoreLibraryReviewExempt: Reviewed in https://dart-review.googlesource.com/c/sdk/+/321922
Issue: #53785
Change-Id: Icd52f2b6cd05cf3a328c82c197ef44d0b340b171
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332581
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-02-06 23:30:49 +00:00
Derek Xu 60833d9cd9 [VM/Service] Update dart:io service extension spec
The main purpose of these changes is to make sure that the types in
package:http_profile are compatible with the interfaces in the spec.

See runtime/vm/service/service_extension.md and
pkg/vm_service/CHANGELOG.md for the full list of changes.

TEST=pkg/vm_service/test/get_http_profile_test.dart, DevTools tests

CoreLibraryReviewExempt: Only touches sdk/lib/io/network_profiling.dart
to update the version returned by the getVersion dart:io service
extension.
Change-Id: I1b9d0b7d43defbc857a2a8fde003012effd1ee15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341120
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-02-06 19:26:06 +00:00
Polina Cherkasova 166c796179 Implement toChunks and allow optimization.
1. Implement HeapSnapshotGraph.toChunks
2. Add parameter calculateReferrers, to allow to skip calculation of referrers, when they are not needed.

Change-Id: I312f01f1527e6b2bf4c8ddce6017ca6c53c8dd3a
CoreLibraryReviewExempt: minor dart:io documentation change
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348802
Commit-Queue: Polina Cherkasova <polinach@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-02-06 16:55:20 +00:00
Martin Kustermann 1c5e12c212 [dart2wasm] Fix int.parse(<str>) for when <str> is a JSString
The `int.parse()` function would - if radix is provided and not 10 - use
functions that `unsafeCast<StringBase>()`.

=> The string can be a JSString.

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

CoreLibraryReviewExempt: Adding test that should pass on all backends.
Change-Id: Ie6efa5bc545cadce5ea946e2c1d732b2cf94e306
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350303
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-05 22:38:18 +00:00
Martin Kustermann cca3ffd278 [dart2wasm] Ensure we convert Dart string *once* to JS string in regexp matching
Improves the third_party/pkg/crypto/test/sha1_test.dart by 100x

Change-Id: I16f0d75a43acd15642b4a62c9bba97f3479efb03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350322
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-02-05 21:32:29 +00:00
Parker Lougheed 0a0f6915ca [ffi] Add missing changelog entries for dart:ffi
Includes changelog additions and `@Since` version fixes for https://dart-review.googlesource.com/c/sdk/+/349260.

CoreLibraryReviewExempt: No functional change and dart:ffi is only supported by the VM and dart2wasm.
Change-Id: Iad0c4d3686278312715ec5fc5374b3c983b71d1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349765
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-02-05 16:28:04 +00:00
Martin Kustermann 0bc92a4333 [dart2wasm] Remove usage of type category table
The type category table is a O(number-of-classes) sized byte array that
maps from class-id to either a type category (function, record, ...) or
a masqueraded class-id.

* for flute this table takes up around 1 KB.
* this prevents from making concrete class-ids come before all abstract
  class ids

After recent changes the core RTT implementation no longer involves
masqueraded types (i.e. `<obj> is/as <type>` and `<type> <: <type>`
queries don't trigger masquerading functionality)

This CL removes the type category table, the special casing in the
class-id assignment and the compiler support for building the table.

Instead we move the logic to pure dart code, which can use normal `is`
checks to perform its function.

We add one optimization: The compiler will provide the class-id from
which one only non-masqueraded classes come. This makes the masquerading
function have a fast path.

* We use `Wasm{TypedData,String}Base` marker interfaces i
 `dart:_internal` to check for wasm-backed implementations
* We use `-Ddart.wasm.js_compatibility` to provide JSCM mode

We add a test that actually exercises the 2 modes.

Change-Id: I051c35b17878950402a1336df871a686b649f732
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349641
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-02 19:01:49 +00:00
Martin Kustermann 32c22da2b6 [dart2wasm] Record type related cleanups
* avoid allocating _RecordType objects for `<obj> is/as <record-type>`
  => Introduce `Record._checkRecordType()`
  => Use `Record._recordRuntimeType` (which is now not masquerading) for
  other purposes (e.g. verification)

* avoid using masqueraded types for `<obj> is/as <record-type>`
  => Introduce `Record._masqueradedRecordRuntimeType`

Although we introduce 2 extra methods on `Record` that are overriden,
it's O(record-shapes-in-program) and therefore not a big overhead.

=> This will enforce the invariant that the actual type check
   implementation (i.e. for `<obj> is/as <type>` or
   for `<type> <: <type>`) *never* calls back into
   masquerading functionality

=> This in return means we can make the masquerading functionality
   using `<obj> is <type>` checks.

Change-Id: I3e3a0411022042a8e735aaeed396cc8f90d8c9c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349800
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-02-02 11:52:23 +00:00
Johnni Winther fe52b9bfe5 [macros] Add dart:_macros
This adds the dart:_macros library to the SDK and adds support for accessing dart:_macros from package:macros. The library is not used yet.

This change is needed as a prestep to adding the package:macros and using it in the CFE and analyzer, and needs to be rolled in as the checked in sdk before package:macros can be supported.

TEST=ci

Change-Id: Ife3ffd48527e3a196048d2ddf7387b8b7818f3a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348680
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2024-02-02 07:47:59 +00:00
Parker Lougheed df7c3197af [docs/api] Minor adjustments and fixes to api.dart.dev homepage
- Since "Futures", "Streams", and "Zones" are plural and not in code syntax, can make them lowercase to be consistent with the `dart:core` entry in the same list.
- Use the full "platform interopability" term when introducing the libraries, as it might be a newer term for readers.
- Replaces "interoping" term as after searching it seems not common and easily mistaken.
- Fixes spelling of "function"

Change-Id: Ia887b427789a50d70cb47228c677fe2fd03499e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349421
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Marya Belanger <mbelanger@google.com>
2024-02-01 21:41:38 +00:00
Daco Harkes c0c7c1ef49 [vm/ffi] Update inner pointer accesses in IL
FFI loads and stores via structs can have a TypedData as receiver,
so this CL updates those loads to `kMayBeInnerPointer`.

This CL adds an IL test to verify that for `Pointer` loads the untagged
value is treated correctly as `kCannotBeInnerPointer`.
(And adds some prefer-inline pragmas to make some common operations
be inlined to avoid allocating `Pointer` objects.)

This CL updates the load in the FFI closures to use a load-field.
This can also potentially enable not allocating a pointer object when
this closure is inlined.

TEST=tests/ffi/unwrap_typeddata_generated_test.dart
TEST=tests/ffi

CoreLibraryReviewExempt: Only adding some pragmas.
Change-Id: If687e54c676f275cc849b3fed526a13766ab331a
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349241
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-02-01 18:28:53 +00:00
Daco Harkes bf683bacbb Reland "[vm/ffi] Introduce Struct.create and Union.create"
Analyzer fix https://github.com/dart-lang/sdk/issues/54754 has
landed. A new version of package:analyzer and package:dartdoc have
been released. `pub global activate dartdoc` should now work.

Patchset 1 is identical to the original CL.
The only difference is an extra test testing with negative offsets.

=== Original CL description ===

Structs and unions can now be created from an existing typed data
with the new `create` methods.

The typed data argument to these `create` methods is optional. If
the typed data argument is omitted, a new typed data of the right
size will be allocated.

Compound field reads and writes are unchecked. (These are
TypedDataBase loads and stores, rather than TypedData loads and stores.
And Pointers have no byte length.) Therefore the `create` method taking
existing TypedData objects check whether the length in bytes it at
least the size of the compound.

TEST=pkg/analyzer/test/src/diagnostics/creation_of_struct_or_union_test.dart
TEST=pkg/vm/testcases/transformations/ffi/struct_typed_data.dart
TEST=tests/ffi/structs_typed_data_test.dart
TEST=tests/ffi/vmspecific_static_checks_test.dart

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

Change-Id: Id7f30bcd4a6ae55a8298b39c9eadf4e80bc699a9
CoreLibraryReviewExempt: FFI is a VM and WASM only feature.
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349260
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-02-01 18:28:03 +00:00
Martin Kustermann 2b396dd95a [dart2wasm] Fix type substitution bug if records are involved
Fixes https://github.com/dart-lang/sdk/issues/54794

Change-Id: I13b4ae619fad7d7e00f4a17e199b85ebea4e6de7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349680
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-02-01 11:38:58 +00:00
Martin Kustermann 8ea636f9f8 [dart2wasm] Make throw call to helper function that gets stacktrace and throws object
This reduces flute complex compiled with `-O4` by 3.2% (or 41kb)

Change-Id: I46e1e933b5b283a7e502571971802885c1c79372
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349261
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-01-31 08:43:18 +00:00
Marya cce16ed108 Drop dart:html from readme
Closes https://github.com/dart-lang/sdk/pull/54775

GitOrigin-RevId: aeef490725f4bc0b627eaaa980920b8b9dfb5d26
Change-Id: I52c2c64826be2304006e1c27f55abf9a402ca5b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349402
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2024-01-30 22:35:52 +00:00