This CL moves the bounds checking into the TypeBuilder instead of
performing it from the outside on the computed DartType node.
This solves several problems:
1) Errors are now reported on the type in the code instead of the
declaration which holds the type.
2) Checking of type aliases (both function and nonfunction type
aliases) is now handled correctly in all cases. This achieved by
computed the aliased type (containing TypedefType nodes)
internally and performing the checking on this type, and only
convert the type into the unaliased version (without TypedefType
nodes) after checks have been performed. Previously this handled
through the FunctionType.typedefType property for function type
aliases and through and incomplete work-around for nonfunction
type aliases.
3) With 2) FunctionType.typedefType is no longer needed and is
removed.
TEST=general/bounds_*
Change-Id: I7653bca5ccb0ebf4b3553828a298d1ad918ef235
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243722
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
It should not be necessary to ever run `pub get` for a package which is
not published. All packages used in the SDK are controlled by a single
package config, so it's not necessary to declare versions or paths for
any packages.
Remove all dependency overrides.
R=devoncarew@google.com
Change-Id: Icb328813b471f35ee4c99995f4e90aac4d8ed438
Tested: Covered by existing static analysis.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244767
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
This CL changes the IL building for reachability fences to their call
sites. This enables us to catch the field load and tell it to not emit
an initialization check for late fields.
The sentinel value will now flow into the ReachabilityFenceInstr, where
it will be discarded.
TEST=tests/language/vm/regress_49005_test.dart
Closes: https://github.com/dart-lang/sdk/issues/49005
Change-Id: Ic21c9905290925eb83860d8394b13be7dd7592c1
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244628
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This fixes an issue where VM would run the async* generator after a
`yield` / `yield*` even though the subscription may be paused or
cancelled.
Furthermore this fixes an issue where `StackTrace.current` used
in async* generator crashes VM and/or produces truncated stack
trace.
This fixes the following existing tests that were failing before:
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t08
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10
* language/async_star/async_star_cancel_test
* language/async_star/pause_test
New in reland: Allow the generator to to cause cancelling it's own consumer.
This addresses the issue of original revert
-> see https://github.com/flutter/flutter/issues/101514
Issue https://github.com/flutter/flutter/issues/100441
Issue https://github.com/dart-lang/sdk/issues/48695
Issue https://github.com/dart-lang/sdk/issues/34775
TEST=vm/dart{,_2}/causal_stacks/flutter_regress_100441_test
Change-Id: I091b7159d59ea15fc31162b4b6b17260d523d7cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242400
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This change includes kernel-related changes:
* --compact-async option is added to kernel compilers (front-end
server and gen_kernel). This option disables desugaring of async
and await on kernel AST. Note that 'await for' is still desugared.
* File offset of the 'await' is now written for AwaitExpression nodes
in the kernel binaries (will be used for async stack traces).
* Async/async*/sync* functions and AwaitExpression nodes are supported
in TFA.
Design doc: go/compact-async-await.
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/48378
Change-Id: I4233086b7434bc48347f4220645b0be5f9133456
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241842
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Expressions like
List<VariableDeclaration> variables = ...
List<Expression> reads = variables.map((v) => VariableGet(v)).toList()
don't get the intended type argument `<Expression>` through inference,
but instead the type inferred from the return type of the closure, in
this case `<VariableGet>`.
This causes problems when used with the AST which assumes that
expressions are interchangeable wherever they are used, and is likely
the cause of https://github.com/flutter/flutter/issues/102077 .
This CL adds an explicit type argument in these cases.
TEST=general/infer_map
Change-Id: I0bcae21f06c54f290dc20686b0d84c065d8ea04c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241605
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This reverts commit 837ee17b43.
Reason for revert: Please see https://github.com/flutter/flutter/issues/101514
Original change's description:
> [vm] Fix some async* semantics issues: Only run generator if there's active subscription (not paused/cancelled)
>
> This fixes an issue where VM would run the async* generator after a
> `yield` / `yield*` even though the subscription may be paused or
> cancelled.
>
> Furthermore this fixes an issue where `StackTrace.current` used
> in async* generator crashes VM and/or produces truncated stack
> trace.
>
> This fixes the following existing tests that were failing before:
>
> * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t08
> * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09
> * co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10
> * language/async_star/async_star_cancel_test
> * language/async_star/pause_test
>
> Issue https://github.com/flutter/flutter/issues/100441
> Issue https://github.com/dart-lang/sdk/issues/48695
> Issue https://github.com/dart-lang/sdk/issues/34775
>
> TEST=vm/dart{,_2}/causal_stacks/flutter_regress_100441_test
>
> Change-Id: I73f7d0b70937a3e3766b992740fa6fe6e6d57cec
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239421
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: Ic3d9c0508310a33a2aaee67860c0bb2ec83bab4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240506
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
The computation of default values on super parameters requires the
notion of a declared initializer. By adding this as a flag to
VariableDeclarations the implementation can now be normalized across
parameter from source and dill.
TEST=existing
Change-Id: Ic980e68b569e3bdab38d2c7c7e4374e0c931a87b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240403
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This fixes an issue where VM would run the async* generator after a
`yield` / `yield*` even though the subscription may be paused or
cancelled.
Furthermore this fixes an issue where `StackTrace.current` used
in async* generator crashes VM and/or produces truncated stack
trace.
This fixes the following existing tests that were failing before:
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t08
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09
* co19/Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10
* language/async_star/async_star_cancel_test
* language/async_star/pause_test
Issue https://github.com/flutter/flutter/issues/100441
Issue https://github.com/dart-lang/sdk/issues/48695
Issue https://github.com/dart-lang/sdk/issues/34775
TEST=vm/dart{,_2}/causal_stacks/flutter_regress_100441_test
Change-Id: I73f7d0b70937a3e3766b992740fa6fe6e6d57cec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239421
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Adds GlobalFeature(s) and LibraryFeature(s) to provide more direct
and consistent access to features and their state.
TEST=existing
Change-Id: Iceb29e4fafa471e6790f2ce3c2a7108c8ae2c9a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239660
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This is in preparation for including a "futureValueType" for
non-nnbd async functions.
TEST=existing
Change-Id: I15cf5e58623df07fe3c670aa866b7b04805c0f3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238703
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Change-Id: I3b81e1d66c2100b8ed1834815f318cf39a8da305
Tested: This only impacts the analyzer's reporting of diagnostics, so I ran the analyzer over the code and verified that no new diagnostics were being reported.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238983
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This CL implements `NativeFinalizer` in the GC.
`FinalizerEntry`s are extended to track `external_size` and in which
`Heap::Space` the finalizable value is.
On attaching a native finalizer, the external size is added to the
relevant heap. When the finalizable value is promoted from new to old
space, the external size is promoted as well. And when a native
finalizer is run or is detached, the external size is removed from the
relevant heap again.
In contrast to Dart `Finalizer`s, `NativeFinalizer`s are run on isolate
shutdown.
When the `NativeFinalizer`s themselves are collected, the finalizers are
not run. Users should stick the native finalizer in a global variable to
ensure finalization. We will revisit this design when we add send and
exit support, because there is a design space to explore what to do in
that case. This current solution promises the least to users.
In this implementation native finalizers have a Dart entry to clean up
the entries from the `all_entries` field of the finalizer. We should
consider using another data structure that avoids the need for this Dart
entry. See the TODO left in the code.
Bug: https://github.com/dart-lang/sdk/issues/47777
TEST=runtime/tests/vm/dart(_2)/isolates/fast_object_copy_test.dart
TEST=runtime/vm/object_test.cc
TEST=tests/ffi(_2)/vmspecific_native_finalizer_*
Change-Id: I8f594c80c3c344ad83e1f2de10de028eb8456121
Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-ffi-android-debug-arm64c-try,dart-sdk-mac-arm64-try,vm-kernel-mac-release-arm64-try,pkg-mac-release-arm64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-win-debug-x64c-try,vm-kernel-win-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-nnbd-win-release-ia32-try,vm-ffi-android-debug-arm-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,benchmark-linux-try,flutter-frontend-try,pkg-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236320
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
- Fix bad frame walk from assuming kSavedCallerFpSlotFromFp is 0.
- Fix sign of WChar.
- Fix missing sign-extension in some cases of passing uint32.
TEST=qemu
Bug: https://github.com/dart-lang/sdk/issues/48164
Change-Id: Idc1699d473a115153b4b4e6fdc9f84519055de00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238386
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Optional arguments (positional and named) in @FfiNative
annotations are not meaningful, and should result in a
compile-time error.
TEST=tests/ffi/ffi_native_test.dart
Bug: https://github.com/dart-lang/sdk/issues/47169
Change-Id: I8896e6a43f9399b537e6ee7c7a0e2857a370203f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232622
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
This reverts commit ee5837aa7a.
Updated Intellij plugins have been published which support the new
message.
TEST=CQ
Change-Id: I81f6d878f036991a95cc1f58d3102015e77aa609
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237741
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
The FFI use sites transformation generates code accessing some late
final fields of the Array class. By changing these to be getters, the
transformation works both with and without late field lowering.
Tested: ci
Change-Id: Ib30d18e0830f7bb597214701272b1d0a922ac06a
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237363
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
This changes all mixins in the VM's hash map/set implementation to be
declared as mixins and introduces appropriate interfaces needed to
concisely express the prerequisites of the various mixins in the stack.
It also separates most of the implementation of immutable maps and sets
into mixins to enable sharing the implementation with dart2wasm.
Tested: ci + manual testing of dart2wasm
Change-Id: Ife1e7195aba35741629aa4dffedb929b1028a85a
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236180
Reviewed-by: Daco Harkes <dacoharkes@google.com>
These transformations are maintained by the VM team and keeping them
in pkg/kernel would put a burden on the CFE team after code reviews
are tightened to require OWNERS approval.
TEST=ci
Change-Id: I931033ba987d17a2c9c6d80a16dad09bfbaa0572
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234905
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This reverts commit f9147d933e.
TEST=N/A
Change-Id: Idef34b70f1066ddf79d02588dfba7caeec443e7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234325
Reviewed-by: Dan Field <dnfield@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Add `isMimeType` method to `UriData` class, to allow case-insensitive
checking of the MIME type.
Add `isCharset` and `isEncoding` methods to `UriData` class,
to allow case-insensitive and alternative-encoding-name aware checking
of the MIME type "charset" parameter.
Make `UriData.fromString` and `UriData.fromBytes` recognize and omit
a "text/plain" `mimeType` even if it is not all lower-case.
Be case-insensitive in a few cases where we weren't before
(like the `charset` getter not recognizing `CHARSET=utf-8`.)
Fixes#28592
TEST=corelib/data_uri_test.dart updated
BUG= http://dartbug.com/28592
Change-Id: Ia885af69d271856af7fadfe93851e07eff6ddca2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217366
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
This CL
* Makes :async_op only have two parameters: We take advantage
of the fact that errors not only have exception != null but
also stacktrace != null.
* Makes :async_op have no optional parameters. This reduces
code size significantly.
* Removes unused parameter in _awaitHelper calls
* Wrap the then callback instead of the error callback. (needed
to make optional parameters required)
This results in 2% code savings on a big g3 app.
The size of :async_op shrinks on average by 11%
TEST=ci
Change-Id: I38d5fba4ebebc780b48dac5aa6a250d2c7952bfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233362
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
* Add team "groups" in tools/OWNERS_<group name>.
* Add top-level OWNERS as a fallback.
* Add OWNERS for all top-level directories.
* Add OWNERS to all packages.
For additional background information see go/dart-sdk-owners.
TEST=No op until code-owners is enabled.
Bug: b/200915407
Change-Id: I7fe6116cc599c749cd50ca16151d6d6a801d99d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229147
Reviewed-by: Jonas Termansen <sortie@google.com>
This is a reland of e77ea8a17b. I've
undone the change to the name of the platformScript setter, restoring
the previous behavior of accepting anything and casting.
TEST=Existing tests.
Change-Id: I7e36935ef3784035769527dc5624191f38faaa40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232487
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Tighten types to eliminate some dynamic calls from the core libraries.
Also remove some unnecessary abstraction from the json parser.
TEST=Existing tests for the library.
Change-Id: Ieb4cdec5b8c26709b5f70774c392bd373a203113
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231800
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Use `hasScheme` in place of comparing against the empty string, and
`isScheme` to compare against all other schemes.
TEST=No behavior changes.
Change-Id: Ifc9fd13c6cf37933ebd4a754c4b500dedbcb291b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231185
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
This CL implements `Finalizable` by means of a CFE transform.
The transform is implemented in the existing FFI transform to avoid the
overhead of traversing the AST an extra time. The FFI transform slows
down ~15-30% on Flutter Gallery. For more info see the design doc.
TEST=`dart pkg/vm/test/transformations/ffi_test.dart`
Design doc: go/dart-vm-finalizable
Bug: https://github.com/dart-lang/sdk/issues/47777
Change-Id: I0bf9dead90a61631b7f215dc19fbaa9e40e63c8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227501
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
In general any async function can return X or Future<X>. Though the
future implementation has to do different things depending on which case
we're in. It does so by using a `<obj> is Future<T>` test. This test is very
expensive if many different classes flow into `<obj>`.
Though most functions do not return `Future` objects from async
functions. We can determine that statically by looking if any returned
expression could be a future. If not, we can bypass the `is Future<T>`
test entirely.
Issue https://github.com/dart-lang/sdk/issues/48226
Issue https://github.com/dart-lang/sdk/issues/48235
TEST=pkg/front_end/testcases/general/async_function_returns_future_or.dart
Change-Id: If655bdbdddc214dd7b12be9905b3c788252547d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230662
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Currently we have to do a runtime `as FutureOr<T>` check for the
parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
needed for general cases, for the particular usage in the VM's
async/await transformer, we know that the test is going to suceed.
This CL adds two VM-specific methods on `_Future` that take `dynamic`
and downcast via `unsafeCast<>()` to avoid this rather large runtime
type checking overhead.
Issue https://github.com/dart-lang/sdk/issues/48226
Change after revert: Replace the
assert(value is T || value is Future<T>);
with
assert((value as FutureOr<T>) == value);
The former doesn't allow `null` while the ladder might (depending
on nullability of `T`).
TEST=ci
Change-Id: I2379c625003fea6aa836ac74beb1cd59201b3560
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231704
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This reverts commit 8e0feb9fa9.
Reason for revert: breaks tests in Google3, see b/217919095
Original change's description:
> [vm] Avoid type parameter check of _Future._asyncComplete() when caller knows its safe
>
> Currently we have to do a runtime `as FutureOr<T>` check for the
> parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
> needed for general cases, for the particular usage in the VM's
> async/await transformer, we know that the test is going to suceed.
>
> This CL adds two VM-specific methods on `_Future` that take `dynamic`
> and downcast via `unsafeCast<>()` to avoid this rather large runtime
> type checking overhead.
>
> Issue https://github.com/dart-lang/sdk/issues/48226
>
> TEST=ci
>
> Change-Id: Ieeffae3ac8e2960f849512cf22c51d41cadb1ecf
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230261
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>
TBR=lrn@google.com,vegorov@google.com,kustermann@google.com
Change-Id: I37a07cbb6fb37620e5305dfe1b759b0de1c37653
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231703
Reviewed-by: Ilya Yanok <yanok@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
Currently we have to do a runtime `as FutureOr<T>` check for the
parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
needed for general cases, for the particular usage in the VM's
async/await transformer, we know that the test is going to suceed.
This CL adds two VM-specific methods on `_Future` that take `dynamic`
and downcast via `unsafeCast<>()` to avoid this rather large runtime
type checking overhead.
Issue https://github.com/dart-lang/sdk/issues/48226
TEST=ci
Change-Id: Ieeffae3ac8e2960f849512cf22c51d41cadb1ecf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230261
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This change adds --source option to kernel compilers (front-end server
and gen_kernel). This option instructs compiler to include extra source
files into compilation even if they are not referenced from main
library.
TEST=Added test cases to pkg/frontend_server/test/frontend_server_test.dart
and pkg/vm/test/kernel_front_end_test.dart
Fixes https://github.com/dart-lang/sdk/issues/48144
Change-Id: If3d71538751e9ccfa8c82a5685d810cf811e021c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231334
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Duplicates `_CompactIterable` and `_CompactIterator` to
`_CompactIterableImmutable` and `_CompactIteratorImmutable` to prevent
the `_data` field to store both modifiable and unmodifiable lists.
This speeds up iteration by about 20% (more info on the bug).
Does not use mixins for code sharing, because all the fields need to be
in the concrete classes anyway.
Closes: https://github.com/dart-lang/sdk/issues/48280
TEST=existing lib tests
Change-Id: I514d058d02ef3b26b475000daea3afc12f37c566
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-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/+/231243
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
The VM patch files contain many annotations that guide the TFA and the
VM compilation pipeline. Most of these are not relevant to dart2wasm,
and having the TFA look at these when running inside dart2wasm leads to
sub-optimal, and sometimes even unsound, results.
In order to enable sharing of patch files between the VM and dart2wasm,
the annotation parser is given a target flag to control which
annotations it should recognize and how to parse them. The annotation
parser thus becomes an abstraction layer between the concrete
annotations in the patch files and the parsed annotations that the TFA
sees.
Additionally, external members used by dart2wasm don't always have
external names. To support this, the signature shaker must skip all
external members, not just the ones with an external name. This makes no
difference for the VM, since all of its external members either have an
external name or are implemented in a patch file, making them no longer
external.
TEST=ci + upcoming dart2wasm CL
Change-Id: Id425dd1ccc5560721034ae83c8cdc1593801a4e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231102
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Missing:
* Function types.
* Type variables in bounds, like "method<T, S extends T>() {}" and
"method<T extends Foo<T>>() {}"
This is in many ways a follow-up to
https://dart-review.googlesource.com/c/sdk/+/212286
TEST=service and (cfe) expression suite tests added.
Change-Id: I20472b59ed73e9845f073e176d73b2c213f9407a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215760
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Implements a backend targeting RV32GC and RV64GC, based on Linux standardizing around GC. The assembler is written to make it easy to disable usage of C, but because the sizes of some instruction sequences are compile-time constants, an additional build configuration would need to be defined to make use of it.
The assembler and disassembler cover every RV32/64GC instruction. The simulator covers all instructions except accessing CSRs and the floating point state accessible through such, include accrued exceptions and dynamic rounding mode.
Quirks:
- RISC-V is a compare-and-branch architecture, but some existing "architecture-independent" parts of the Dart compiler assume a condition code architecture. To avoid rewriting these parts, we use a peephole in the assembler to map to compare-and-branch. See Assembler::BranchIf. Luckily nothing depended on taking multiple branches on the same condition code set.
- There are no hardware overflow checks, so we must use Hacker's Delight style software checks. Often these are very cheap: if the sign of one operand is known, a single branch is needed.
- The ranges of RISC-V branches and jumps are such that we use 3 levels of generation for forward branches, instead of the 2 levels of near and far branches used on ARM[64]. Nearly all code is handled by the first two levels with 20-bits of range, with enormous regex matchers triggering the third level that uses aupic+jalr to get 32-bits of range.
- For PC-relative calls in AOT, we always generate auipc+jalr pairs with 32-bits of range, so we never generate trampolines.
- Only a subset of registers are available in some compressed instructions, so we assign the most popular uses to these registers. In particular, THR, TMP[2], CODE and PP. This has the effect of assigning CODE and PP to volatile registers in the C calling convention, whereas they are assigned preserved registers on the other architectures. As on ARM64, PP is untagged; this is so short indices can be accessed with a compressed instruction.
- There are no push or pop instructions, so combining pushes and pops is preferred so we can update SP once.
- The C calling convention has a strongly aligned stack, but unlike on ARM64 we don't need to use an alternate stack pointer. The author ensured language was added to the RISC-V psABI making the OS responsible for realigning the stack pointer for signal handlers, allowing Dart to leave the stack pointer misaligned from the C calling convention's point of view until a foreign call.
- We don't bother with the link register tracking done on ARM[64]. Instead we make use of an alternate link register to avoid inline spilling in the write barrier.
Unimplemented:
- non-trivial FFI cases
- Compressed pointers - No intention to implement.
- Unboxed SIMD - We might make use of the V extension registers when the V extension is ratified.
- BigInt intrinsics
TEST=existing tests for IL level, new tests for assembler/disassembler/simulator
Bug: https://github.com/dart-lang/sdk/issues/38587
Bug: https://github.com/dart-lang/sdk/issues/48164
Change-Id: I991d1df4be5bf55efec5371b767b332d37dfa3e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217289
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This CL does two things:
* "Reenable" the skipping of the dart:ffi transformation entirely when
the application does not use dart:ffi. This was originally added in
ad596359a6 but was logically disabled in 4558112105 when dart:core
started depending on it. Here we now ignore (real) dart:* libraries
when looking for dependencies of dart:ffi.
* Find the subset of the just compiled libraries that transitively
depend on dart:ffi and just run the dart:ffi transformation on those
libraries.
For dart2js that doesn't use dart:ffi at all we go from:
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:09.003428: Transformed ffi natives in 51ms.
0:00:09.203442: Transformed ffi annotations in 199ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:09.098175: Transformed ffi natives in 52ms.
0:00:09.296847: Transformed ffi annotations in 198ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:08.854341: Transformed ffi natives in 57ms.
0:00:09.061804: Transformed ffi annotations in 207ms.
```
to
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:09.138651: Skipped ffi transformation in 1ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:09.242590: Skipped ffi transformation in 1ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v pkg/compiler/bin/dart2js.dart | grep -i "ffi"
0:00:09.163885: Skipped ffi transformation in 1ms.
```
When compiling the flutter gallery app that does depend on dart:ffi we go from:
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:16.344955: Transformed ffi natives in 78ms.
0:00:16.777218: Transformed ffi annotations in 432ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:15.994674: Transformed ffi natives in 80ms.
0:00:16.472779: Transformed ffi annotations in 478ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:16.027488: Transformed ffi natives in 81ms.
0:00:16.491362: Transformed ffi annotations in 463ms.
```
to
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:15.991628: Transformed ffi natives in 30ms.
0:00:16.226564: Transformed ffi annotations in 234ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:16.184984: Transformed ffi natives in 29ms.
0:00:16.404439: Transformed ffi annotations in 219ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.6KV5psVGIG/flutter_patched_sdk/platform_strong.dill /tmp/tmp.6KV5psVGIG/gallery/lib/main.dart | grep -i "ffi"
0:00:15.933513: Transformed ffi natives in 27ms.
0:00:16.145640: Transformed ffi annotations in 212ms.
```
TEST=Assuming tests already exists.
Change-Id: Ie13be1924d3439cb710c782af81e1e42cda2a838
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228001
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
When a compact linked hash map is empty, it can add all the entries of
another compact linked hash map by a block-copy.
Adding elements to an empty map occurs with `Map.of(m)` which is
essentially `{}..addAll(m)`.
For AOT it does not make much difference for small maps, but is better
for large maps.
dart-aot-null linux-armv8c
MapCopy.Map.Thing.of.Map.2 3.737% 410.25 395.47
MapCopy.Map.String.of.Map.2 3.858% 400.93 386.03
MapCopy.Map.Thing.of.Map.100 503.4% 2308.06 382.49
MapCopy.Map.String.of.Map.100 543.6% 2297.51 356.96
JIT seems to do well on smaller maps too
dart linux-x64
MapCopy.Map.Thing.of.Map.2 80.22% 2681.76 1488.06
MapCopy.Map.String.of.Map.2 85.56% 2671.52 1439.70
MapCopy.Map.Thing.of.Map.100 777.8% 12859.79 1465.04
MapCopy.Map.String.of.Map.100 867.3% 12829.22 1326.28
Added similar fast path for identity maps, sets, and identity sets.
TEST=existing
Change-Id: Ifa8afc95797bc603113dcc7984c6a6d61af56595
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222249
Reviewed-by: Dan Field <dnfield@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Flutter in google3 uses --delete-tostring-package-uri compiler option
to remove toString methods in package:flutter and dart:ui to reduce
size in release mode.
This has unfortunate effect of removing toString methods from exception
classes which may provide valuable information for investigating
problems seen in the wild.
This change adds a new @pragma('flutter:keep-to-string-in-subtypes')
on classes to keep toString methods on all subtypes of the annotated
classes. This pragma is now used on Exception and Error classes in
dart:core.
TEST=pkg/vm/test/transformations/to_string_transformer_test.dart
Issue: https://github.com/flutter/flutter/issues/61562
Change-Id: Ib739c83cdf6b539208f705ba198e63b8bc54fa61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227920
Reviewed-by: Dan Field <dnfield@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Adds the `ref` setter to the `StructPointer` and `UnionPointer`
extensions, copying a compound structure into native memory.
The FFI use-site transformation transforms invocations of this setter
into an appropriate memcopy call.
Closes https://github.com/dart-lang/sdk/issues/44768
TEST=tests/ffi(_2)/extension_methods_test.dart
Change-Id: I3ef06ad08b8e71e39b05d662e8082fc5d0ad876d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227542
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This CL changes the way dart: libraries are considered supported when
used in conditional imports or bool.fromEnvironment constant using
the "dart.library.*" values.
Library nodes now has an isUnsupported flag which is set according to
the "supported" property in the libraries specification. Furthermore
the Target now supplies a DartLibrarySupport interface that allows
targets to override whether dart: libraries are unsupported.
This allows the JIT/AOT to use the same platform file but still
consider dart:mirrors unsupported in AOT mode, and dart2js to consider
the internal library `dart:_dart2js_runtime_metrics` supported.
Furthermore, the internal handling is changed so that condition imports
and bool.fromEnvironments constants are computed through the same logic
for "dart.library.*" values, avoiding the need for passing these values
through the environment.
TEST=pkg/front_end/testcases/general/supported_libraries/main
Closes https://github.com/dart-lang/sdk/issues/48057
Closes https://github.com/dart-lang/sdk/issues/47814
Closes https://github.com/dart-lang/sdk/issues/47243
Closes https://github.com/dart-lang/sdk/issues/32657
Closes https://github.com/dart-lang/sdk/issues/36460
Change-Id: Ie8f8dff99167de64ced51b71d89918bf0f3bbd13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227020
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Before this CL there was a pattern of looking up size and alignment for
a specific abi by using `size[abi]` and `alignment[abi]`. The problem
being that both are often dynamic map creations, meaning that it created
tons of maps that it looked up a specific value in and threw away.
This CL instead adds handles for getting size and alignment for a
specific abi, skipping the map creation.
On my machine this more than doubles the speed of the ffi transformation
when compiling the flutter gallery app:
Before:
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:17.861255: Transformed ffi annotations in 990ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:18.029886: Transformed ffi annotations in 1055ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:17.807917: Transformed ffi annotations in 1012ms.
```
With this fix:
```
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:17.159482: Transformed ffi annotations in 457ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:17.385509: Transformed ffi annotations in 410ms.
$ out/ReleaseX64/dart pkg/front_end/tool/_fasta/compile.dart -v --target=flutter --platform=/tmp/tmp.aD6a8pEOZW/flutter_patched_sdk/platform_strong.dill /tmp/tmp.aD6a8pEOZW/gallery/lib/main.dart | grep "Transformed ffi annotations"
0:00:17.216748: Transformed ffi annotations in 407ms.
```
TEST=This shouldn't change functionality, assuming tests already exists.
Change-Id: I2013659376e249622d75ebd8b77f2bf70685d4f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226688
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
In order to make sure static types in kernel AST are still correct
after tree shaking, tree shaker needs to insert no-op unsafeCast calls
when removing conditional expressions, as ConditionalExpression nodes
have explicit 'staticType' which may be different from static types of
sub-expressions.
Otherwise we might end up with an untyped function call
(FunctionInvocation with FunctionAccessKind.Function)
performed from a receiver with a known function type.
That would violate VM's assumptions about static type of receiver
being checked by the front-end and trigger assertion in
pkg/vm/lib/transformations/call_site_annotator.dart.
TEST=runtime/tests/vm/dart/untyped_function_invocation_with_known_function_type_test.dart
TEST=pkg/vm/testcases/transformations/type_flow/transformer/null_test_elimination2_nnbd_strong.dart
Change-Id: I6bf201a979d1b71eb48ed04f154adf2b62dac922
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226741
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
For `asyncExpectThrows`, instead of taking a function,
then checking if that function can be called with zero arguments,
and then immediately calling it and checking that it returns a future,
just take the future as argument.
Since synchronus errors from calling the function were not caught
anyway, doing the entire `Future` computation directly shouldn't
change behavior.
Also make `asyncExpectThrows` and `Expect.throws` return the caught error,
so that you can use normal `Expect.something` checks on it afterwards,
instead of doing that in the `check` function.
That basically makes the `check` function unnecessary (but hard to remove
with the existing test corpus using it heavily).
This makes some uses of the `asyncExpectThrows` function slightly more
complicated, those that have no other way to create a future than calling
the argument function anyway, but other uses become simpler
when they can avoid adding the function wrapper.
TEST= Refactoring. If the tests keep running, it's successful.
Change-Id: I983eb65ea4805760339073fabc27f78c57f9a471
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226102
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
There are 2 AOT-specific unit tests which rely on disabled
--use_table_dispatch flag. That flag is enabled everywhere and was
only disabled for the vm unit tests.
These 2 tests are now migrated to the new IL tests infrastructure
and --use_table_dispatch flag is enabled in the vm unit tests.
In order to support testing of IL of closures, IL test infra is
extended with pragma
@pragma('vm:testing:match-inner-flow-graph', 'inner name')
TEST=vm/dart/typed_data_aot_not_inlining_il_test
TEST=vm/dart/typed_data_aot_regress43534_il_test
Change-Id: I900e96136ddedb408ffca05d0c71893c3e12c2c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225325
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL adds support for users defining integers which are mapped to
differing sizes and signedness based on the application binary interface
the Dart VM is running on.
Notable implementation design decisions:
- ABIs are open world, so that adding an ABI to the Dart VM does not
break existing definitions. Thus, we only figure out in the VM that
we're missing a mapping. We throw compile-time errors.
- In AOT, these show up in the precompilation step.
- In JIT, these show up as `_CompileTimeError` at runtime. Note that
these can be caught. So in subsequent compilation steps we need to
ensure that we also throw the same compile-time error.
- We match on the call-sites (streaming_flowgraph_builder) rather than
method bodies (kernel_to_il) of AbiSpecific loads and stores so that
we can compile for the int-size of the call site.
API design decisions:
https://github.com/dart-lang/sdk/issues/42563#issuecomment-981774001
Closes: https://github.com/dart-lang/sdk/issues/42563
TEST=tests/ffi_2/abi_*_test.dart
TEST=tests/ffi/function_*_generated_test.dart
TEST=tests/ffi/vmspecific_static_checks_test.dart
Change-Id: I8c8df36fab939b6fb614c5f1ee8e1bf46b6e9521
Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-nnbd-linux-release-try,app-kernel-linux-debug-x64-try,benchmark-linux-try,dart-sdk-linux-try,front-end-linux-release-x64-try,front-end-nnbd-linux-release-x64-try,pkg-linux-debug-try,vm-canary-linux-debug-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-fuchsia-release-x64-try,vm-kernel-checked-linux-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-linux-debug-x64c-try,vm-kernel-mac-debug-x64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-nnbd-win-debug-x64-try,vm-kernel-nnbd-win-release-ia32-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-android-release-arm64c-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221501
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Generating identity hashes from the runtime no longer calls into Dart. On 32-bit systems, generating identity hashes from Dart now does only one runtime transition.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/47873
Change-Id: Ib21156cb05706f81744eb4e5ccb644f40aa84c96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222326
Reviewed-by: Alexander Markov <alexmarkov@google.com>
This change introduces Rapid Type Analysis (RTA) and uses it to
calculate initial set of allocated classes for Type Flow Analysis (TFA).
As a result, TFA converges much faster and AOT compilation time
improves.
RTA is less precise than TFA, so the set of allocated classes is
larger compared to the one calculated by TFA. However, it has only
marginal effect on the size of resulting AOT snapshots.
Time of AOT compilation step 2 on a large Flutter application
118.652s -> 59.907s (-49.5% / improved by a factor of 1.98x)
Snapshot size on armv8: -0.13%
Flutter gallery snapshot size in release and release-sizeopt modes
armv7 +0.19%, armv8 +0.2%
Just in case, RTA can be disabled using --no-rta option.
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/42442
Issue: b/154155290
Change-Id: Iffbdabe7d486cad2e138f7592bffcb70474ddc34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222500
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
If tree shaker doesn't visit TypeParameterType.promotedBound which
contains the only reference to a particular class it may remove that
class, leaving a dangling reference from promotedBound. After that
kernel AST serialization would crash with "Missing canonical name for
Reference" error.
This change also fixes TypeParameterType.visitChildren.
TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_47878.dart
Fixes https://github.com/dart-lang/sdk/issues/47878
Change-Id: I555261713240bf0be412db27efb68f32cfd8008b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222781
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
During the fix for https://github.com/dart-lang/language/issues/1785,
an explicit `bool` type was added to the variable `nullable` to ensure
that it would properly participate in type promotion while the fix was
still being rolled out. Now that the fix is in place, this explicit
type is no longer needed.
TEST=standard trybots, TAP global presubmit, Golem
Change-Id: Ib81ad436876e576f85c929c205d5831214e6a05a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214821
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
When ABI-specific integers are introduced, their mappings can be
partial. We need to account for this in the transformation and the code
we generate.
In the transformation, all sizes and offsets become nullable.
In the generated code we add `null` constants and a call to check
whether the value is not-null at runtime.
Note that with only this CL we can not generate nulls yet, because all
size and offset mappings are still complete.
TEST=pkg/front_end/testcases/nnbd/ffi*
TEST=tests/ffi*
Bug: https://github.com/dart-lang/sdk/issues/42563
Change-Id: I80d45f3f52001670bc0679a033f7daa22198d55e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221631
Reviewed-by: Ryan Macnak <rmacnak@google.com>
We're going to extend this logic in subsequent CLs, so lets give this
abstraction its own place to live.
TEST=just moving file contents
Change-Id: Ie6b267e77dd3a772bb3bbf0b79b33946ee767b0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221630
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This prepares for returning more that just the component from an
incremental compilation.
TEST=existing
Change-Id: I3ee269083290097f1a92d77d105b607a6a02f1f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221086
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
* Add Canonicalize pass after CSE to erase graph differences between
64-bit and 32-bit platforms. These differences originate from different
treatment of integers (we unbox more eagerly on 64-bit platform) and
consequently affect load forwarding - which generates some redundant[1]
phis on 64-bit platform, but not on 32-bit platform. Adding this pass
also addresses other cases of unpredictable performance when IL changes
can cause CSE not to trigger a Canonicalize inside itself and regress
performance, by inhibiting subsequent optimizations.
* Allow IL tests to check whether the graph was compiled in sound
null safety mode or not - because graphs can have minor differences.
* Use `"$i"` instead of `i.toString()` in the test to allow TFA to
infer non-nullability of fields in non-sound-nullsafety mode.
[1] The definition of redundant phi differs between canonicalization
pass and load forwarding pass. The former unwraps redefinitions and
the latter does not. We are going to address this difference in a
more systematic way when we split input dependencies from control
dependencies.
TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try
Change-Id: Ifbd68fbb7f3b374ecee8ada1b3a4a2249139a108
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220541
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
* Add support for dumping flow graphs in JSON (to make it machine
readable);
* Add support for controlling which functions are dumped through
a pragma annotation:
`@pragma('vm:testing:print-flow-graph'[, "passes filter"])`
* Replace simple matching DSL with programmatic matching
* Support obfuscated builds
Fixes https://github.com/dart-lang/sdk/issues/47340
TEST=vm/dart{,_2}/aot_prefer_equality_comparison_il_test
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: Ie067ba451d311e6019a8c3a88c012231b0c50eb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219240
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
In order to avoid spending too much time analyzing multiple
invocations of huge methods with different combinations of
argument types, the following heuristic is added to type
flow analysis:
- if size of a method summary >= N operations, and
- number of invocations for this method >= M, then
create and use an approximate invocation with raw argument types
for all subsequent invocations (so that we would have to analyze
at most M+1 invocations per huge method).
Constants N = 300 and M = 10 are selected so that size of
Flutter gallery AOT snapshot is not affected, and at the same
time compilation time of example involving huge auto-generated
methods from issue https://github.com/dart-lang/sdk/issues/47546 is
not regressed very much (<10s).
TEST=ci
Issue https://github.com/dart-lang/sdk/issues/47546
Change-Id: I6a452872b13bd32928585fce4431ec1176833e6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219749
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL expands the ABIs in the FFI transform and VM from 3 groups to
18 individual ABIs in preparation of adding ABI-specific integer sizes
and structs.
This increases const lists with offsets in the kernel representation
from 3 to 18 elements. We do not expect significant size increases or
performance regressions from this. The constants are deduplicated in
Dart and the optimizer should optimize indexed lookups in const lists
away. However, landing this separately will enable us to verify that
assumption.
This also moves `Abi` to its own file and makes it an opaque class with
a predefined set of instances so that we do not depend on its internals.
That will enable us to keep `pkg/vm/lib/transformations/ffi/abi.dart`
consistent with the `Abi` abstraction to be introduced in `dart:ffi`
later for specifying ABI-specific integer sizes.
Bug: https://github.com/dart-lang/sdk/issues/42563
Bug: https://github.com/dart-lang/sdk/issues/42816
List of ABIs decided based on what's currently used (as Dart SDK target
platform, or Flutter target platform, or G3 target) and added
windows_arm64 in anticipation of
(https://github.com/flutter/flutter/issues/53120).
Excluded are macos_ia32 (https://github.com/dart-lang/sdk/issues/39810)
because we discontinued support; and windows_arm, fuchsia_arm,
fuchsia_ia32, ios_ia32, and macos_arm because these are
unlikely to be added.
TEST=pkg/front_end/testcases/*.expect
TEST=tests/ffi/*
Change-Id: I437707c18d8667490c063272a5f8a33d846e6061
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-ffi-android-debug-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-ffi-android-debug-arm64c-try,vm-kernel-mac-release-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-android-release-arm64c-try,vm-kernel-precomp-android-release-arm_x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217184
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
It runs tests from the pkg/vm/testcases/transformations/ffi, where I'd
like to add ffi, but non-ffinative tests.
TEST=renames a test
Change-Id: I2c4128fd5ded154ab483b05d9002afdbb3dc33a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217642
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Zero runtime affect to these unpublished packages
Allows using standard tools such as dart test, etc
Also allows better checking of dependency constraints
TEST=no effect on SDK build process
Change-Id: Ic6fbe6ce8f57724a87c058eccad64ce8e7473af1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218180
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
This change replaces a `r as T` with `unsafeCast<T>(r)` to avoid
unnecessary type checking.
It is the responsibility of the native function to return the
expected type.
See discussion on https://dart-review.googlesource.com/c/sdk/+/218101
TEST=Updated expect file.
Change-Id: Ic6f0a642a4ffe60c421b1af1127cc1450dc93eec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218261
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
This change makes the FfiNative closure inherit the nullability
of the associated Dart function.
Example:
@FfiNative<Handle Function()>('MaybeStr')
external String? maybeStr();
Generates a closure of type `() → core::Object?`.
This enables @FfiNatives to return nullable types where they
previously would be forced non-nullable.
TEST=Updated expect file.
Change-Id: I85cf9f2f43749e97ab97779f911789034e6b9ab1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218101
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
This change contains a few small improvements which reduce
time of type flow analysis (AOT compilation step 2):
* Faster construction of _DirectInvocation objects
* Eager approximation of arguments of operator==
* Eager approximation of arguments of identical
Improves time of AOT compilation step 2 (TFA) on a large
Flutter application 137s -> 124s (-9.4%).
Doesn't affect size of Flutter gallery AOT snapshot.
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/42442
Change-Id: I9da0b0e68d1ee8062d86094fb5cdb9462fb7ea6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217741
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
TEST=N/A
Change-Id: I3e3f0cd1d94743fbbe8cfcc5723eb38608be2a8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217503
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Adds explicit types to list literals used in the ffi/native
transform, as the list type inferred will otherwise be too
narrow.
This triggers a problem later on when a different transform
then tries to add a broader typed value into these lists,
triggering a typing error:
`type 'ConstantExpression' is not a subtype of type 'VariableGet'`
TEST=ffi/vmspecific_ffi_native_test
Bug: https://github.com/dart-lang/sdk/issues/47512
Change-Id: Ie3ba10da02083e16e7325b225febdc43b31077f5
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217302
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Auto-Submit: Clement Skau <cskau@google.com>
FFI functions return Handles as Object so we have to add a cast
to get the expected return type. E.g.:
@FfiNative<Handle Function()>(..)
external String getSomeStr();
Will have a synthetic FFI function of type `Object Function()`,
which we need to add a `as String` to.
This CL also refactors the overlapping parts of
`_transformInstanceMethod` and `_transformInstanceFunction` into
two shared functions.
TEST=Updated .expect file.
Change-Id: I0f74d34ee3eef4928f7beb38a1180180c13672ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216286
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Having the transforms in a dedicated folder enables us to add more files
without cluttering the transformations folder itself.
TEST=This only moves files. Bots test whether imports are correct.
Change-Id: Icf1d64b5ec09a7d19915b1cb72464fa67b6cfe15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217180
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This file as not been updated in a long time, and we're not using it
as the ground truth for CFE/analyzer checks.
TEST=This is deleting a markdown file.
Change-Id: I4872223a889407800c2f0d6a6092f7db4200967c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217018
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This CL adds the `Bool` `NativeType` with support for loading/storing
from `Pointer<Bool>`, `Array<Bool>`, and `Struct` and `Union` fields,
and support for passing booleans through FFI calls and callbacks.
The assumption is that `bool` is always treated as `uint8_t` in the
native ABIs. Including: (1) whether there can be garbage in the upper
bytes in CPU registers, (2) stack alignment, and (3) alignment in
compounds.
The conversion from `bool` to `uint8_t` is implemented as follows:
- bool to int: `value ? 1 : 0`
- int to bool: `value != 0`
The conversion is implemented in Dart in patch files for memory loads
and stores (pointer, array, and struct fields) and kernel_to_il for
FFI call and callback arguments and return value.
TEST=runtime/vm/compiler/ffi/native_type_vm_test.cc
TEST=tests/ffi/bool_test.dart
TEST=tests/ffi/function_callbacks_structs_by_value_generated_test.dart
TEST=tests/ffi/function_structs_by_value_generated_test.dart
Closes: https://github.com/dart-lang/sdk/issues/36855
Change-Id: I75d100340ba41771abfb41c598ca92066a89370b
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-ffi-android-debug-arm-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-ffi-android-debug-arm64c-try,vm-kernel-mac-release-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-android-release-arm64c-try,vm-kernel-precomp-android-release-arm_x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216900
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
- Allows FfiNative annotation to be attached to non-static
methods of classes.
- Transforms non-static instance methods to static, adding
wrappers with the receiver as an extra, implicit first paramters.
- Transform all parameters and arguments to Pointer if the object
being passed supports it (i.e. extends NativeFieldWrapperClass1).
- Adds compile time errors for cases where the FfiNative annotation
doesn't align with the annotated function. Taking into account
implicit receivers and converted Pointers.
- Adds complimentary Analyzer checks for the above errors as well.
- Adds tests for the transforms, compile time errors and analyzer
changes.
TEST=Adds new tests for instance methods, analyzer changes.
Change-Id: Idf54430acf2728a650008333b149b254941290ad
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213773
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Previously, TFA used ClosedWorldClassHierarchy from CFE to look for
dispatch targets of invocations, and cached those lookups. However,
doing lookups via ClosedWorldClassHierarchy for the first time is still
slow. Now TFA builds maps of dispatch targets from AST and no longer
uses ClosedWorldClassHierarchy for the lookup.
Improves time of AOT compilation step 2 (TFA) on a large
Flutter application 170s -> 152s (-10.5%).
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/42442
Change-Id: I1a22d298e5b2c0ead57c38ddfbf5ebbd1876732f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215985
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
We can't rely on GC to trigger the finalizer of a given test object,
so the previous liveness test was unreliable.
Instead we add an expect test to verify we generate the necessary
`reachabilityFence(..)`s to ensure liveness.
TEST=Adds expect.
Bug: https://github.com/dart-lang/sdk/issues/47362
Change-Id: Ia57a07522c8b8265b24780f00f3339b50534eb60
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-mac-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215542
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
In Dart 2.15, we're removing "dartfmt" in favor of "dart format", so I'm
going through and fixing all the dangling references to the old name.
TEST=Only changing tools
Change-Id: I83a5c00be925fdb536014a47dff2b488ed9f478b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215186
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Our current unit testing infrastructure does not make it possible to
test AOT compilation pipeline end-to-end, because it does not run TFA
when generating Kernel.
This makes it challenging to write regression tests for certain issues.
Instead we extend test runner with a capability to perform IL matching
when running AOT tests.
runtime/docs/infa/il_tests.md provides details on how to write such tests.
TEST=manually
Change-Id: I6f5220b814f4a5d8c053efacd3711df495dea404
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214961
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
When looking for a dispatch target, also cache not found selectors
to avoid repeated lookups.
Improves time of AOT compilation step 2 (TFA) on a large
Flutter application 189s -> 171s (-9.5%).
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/42442
Change-Id: I21686e1f40a09ef62abf010bfa3670615c108942
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214342
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>