Commit Graph

970 Commits

Author SHA1 Message Date
Clement Skau 0c0a72e3ae [vm/ffi] Adds unsafeCast to FfiNative return values.
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>
2021-10-27 13:20:47 +00:00
Clement Skau 933055b142 [vm/ffi] Adds nullability to FfiNative closure.
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>
2021-10-27 10:25:38 +00:00
Alexander Markov 53debdc1c3 [vm/aot/tfa] Minor improvements for AOT compilation time
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>
2021-10-26 17:23:21 +00:00
Clement Skau 7a3d38f08d [vm] Types lists in FfiNative transform.
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>
2021-10-20 21:31:32 +00:00
Clement Skau 4522d4b07c [vm/ffi] Adds transforms for FfiNative return type of Handle.
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>
2021-10-20 13:33:11 +00:00
Clement Skau 0cd81027f4 Set correct fileUri on FfiNative fields.
`currentLibrary.fileUri` points to the library file (e.g. ui.dart)
and not the class-containing `part` file (e.g. compositing.dart).
This causes `fileOffset` out-of-bounds and `location` to fail.

Failing stack trace:
Unhandled exception: Crash when compiling null, at character offset null:
RangeError (offset): Invalid value: Not in inclusive range 0..1257: 1543
#0      RangeError.checkValueInInterval (dart:core/errors.dart:282:7)
#1      Source.getLocation (package:kernel/ast.dart:13919:16)
#2      Component.getLocation (package:kernel/ast.dart:13692:31)
#3      _getLocationInComponent (package:kernel/ast.dart:14212:22)
#4      Field._getLocationInEnclosingFile (package:kernel/ast.dart:2363:12)
#5      TreeNode._getLocationInEnclosingFile (package:kernel/ast.dart:206:20)
#6      TreeNode.location (package:kernel/ast.dart:202:12)
#7      _FfiUseSiteTransformer._ensureNativeTypeToDartType (package:vm/transformations/ffi_use_sites.dart:744:35)
[...]

TEST=Existing.
Change-Id: I17b3ab23abcb04aca046509e7cdbb177ed156e54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217186
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-10-19 13:09:46 +00:00
Daco Harkes 0cd586486b [cfe/ffi] Move FFI transforms into folder
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>
2021-10-19 07:25:09 +00:00
Daco Harkes 1868b119e7 [vm/ffi] Cleanup outdated documentation
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>
2021-10-19 05:50:58 +00:00
Daco Harkes 757c2b82ce [vm/ffi] Add Bool
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>
2021-10-18 10:44:11 +00:00
Daco Harkes 4031e6a82c [cfe/ffi] Refactor transform lists into sets and maps
Addressing https://dart-review.googlesource.com/c/sdk/+/216900/3/pkg/vm/lib/transformations/ffi.dart#77

TEST=FFI test suite

Change-Id: I96a88534d452fd727b7cc693cc5d37fd49d06977
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217002
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-10-15 09:23:42 +00:00
Clement Skau 998d5f5a9b [vm/ffi] Adds FFI transform FfiNative instance methods.
- 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>
2021-10-12 10:58:44 +00:00
Alexander Markov 3aaad7817b [vm/aot/tfa] Build cache of dispatch targets in TFA instead of using ClosedWorldClassHierarchy from CFE
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>
2021-10-08 11:02:16 +00:00
Clement Skau d5fada929d [vm/ffi/test] Replaces FfiNative transform test with expect.
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>
2021-10-06 10:40:16 +00:00
Johnni Winther 3aaea30f10 [cfe] Pass references to lowered tear-offs
TEST=existing

Change-Id: I7e2625f87b357ceec45ec2664f7444af38ec0cf1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215402
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-10-05 09:20:41 +00:00
Alexander Markov d78abd0a69 [vm/aot/tfa] Cache negative results of dispatch target lookup
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>
2021-09-24 16:27:45 +00:00
Clement Skau 22652a3b49 [vm/ffi] Privatizes dart:nativewrappers' getNativeField(..)
TEST=Updated dart_api_impl_test.

Change-Id: Ib72667b2a20adc342f724a6eff7d326e2e106257
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214401
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-24 13:13:55 +00:00
Johnni Winther 5b7968346d [kernel] Add Field.fieldReference
This adds a third reference to Field declaration, so that we know have
three references, one for each use case:

1) fieldReference used for initialization; in FieldInitializer and as
   the key in the InstanceConstant.fieldValues map.
2) getterReference used for reading; in InstanceGet, StaticGet and
   SuperPropertyGet
3) setterReference used for writing; in InstanceSet, StaticSet and
   SuperPropertySet

TEST=existing

Change-Id: I223f130e808e7f19a831c1fe5e3a4725d1bcdc3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203770
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-09-24 12:01:08 +00:00
Clement Skau cd7c9922eb [vm/ffi] Adds FFI transform for Handle -> Pointer.
This will automatically desugar FfiNative calls passing
NativeFieldWrapperClass1 handles to use Pointer when
the underlying native function expects a pointer.
E.g.:

```
class ClassWithNativeField extends NativeFieldWrapperClass1 {}

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

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

TEST=Adds new tests in tests/ffi/ffi_native_test.dart.
Change-Id: I4460f9249803054f12be5d5ff34dbdf7c96567fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213260
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-09-15 12:47:35 +00:00
Clement Skau 7d467e8933 [vm] Adds args_n to FFI resolver.
This makes it more closely mirror the Dart_NativeEntryResolver,
and acts as an extra sanity check that signatures (roughly)
align between the FfiNative decl. and the native function.

TEST=Updated runtime/vm/dart_api_impl_test.cc

Change-Id: I40799dc583ec14db14dc453afed4e2d1eb06fced
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212566
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-09-13 07:57:00 +00:00
Alexander Markov 28532bae7a [vm/aot/tfa] Cleanup support for non-constant annotations
This change removes handling of StaticGet and ConstructorInvocation
nodes in annotations. This code became redundant since constant
evaluation was moved into the front-end.

TEST=ci

Change-Id: Idfa16624d28cdf73da09b52aec429d881e43a36e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212871
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-09-10 16:50:27 +00:00
Jens Johansen 48d8225b17 [VM] [CFE]: Expression compilation inside extension method
This CL handles expression compilation inside extension methods better.
It is now possible to evaluate "this" and other methods defined in the
extension.

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

TEST=service tests added.

Change-Id: I3c71eb23117e26b01961f32103f4046f0b537976
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212286
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-09-10 12:02:57 +00:00
Johnni Winther d80cff6b2b [cfe] Rename isCovariant and isGenericCovariantImpl
- to isCovariantByDeclaration and isCovariantByClass, respectively.

This is done to align the terminology with the spec.

TEST=existing

Change-Id: I96b2e5d6e05caca431aad2b54545e928aee034e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213041
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-09-10 11:27:37 +00:00
Paul Berry 706c7e4a58 Revert "Remove explicit bool type hack."
This reverts commit 4a54307a39.

Reason for revert: Broke internal build, golem

Original change's description:
> Remove explicit bool type hack.
>
> 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
> Change-Id: Ied468b17dafa03075fd54c0df915e0a539420697
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212266
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

TBR=paulberry@google.com,alexmarkov@google.com

Change-Id: I748060275968e1a87a78e90d3770b17543549f33
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212783
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-09-08 14:07:25 +00:00
Vyacheslav Egorov d8d7af15ce [vm] Migrate away from native 'name' syntax.
As part of deprecating support for native extensions we are also
migrating away from legacy VM-specific `native 'name'` syntax
towards metadata based encoding which does not require any special
syntax.

This CL is a step 1 in migration:

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

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

TEST=ci

Bug: https://github.com/dart-lang/sdk/issues/28791
Change-Id: Id6dea878db82dd4fd81149243c425b5c5dc6df86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212461
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-08 13:39:34 +00:00
Paul Berry 4a54307a39 Remove explicit bool type hack.
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
Change-Id: Ied468b17dafa03075fd54c0df915e0a539420697
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212266
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-09-08 12:04:13 +00:00
Johnni Winther bc1c71fd9b [cfe] Handle un-inlined fields/locals in eager instantiation constantification
Closes #47108

TEST=existing

Change-Id: I590939161cde1316eede7d828dff5fe6ac2790fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212577
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-09-07 15:14:36 +00:00
Ahmed Ashour f1ded6af56 Remove import dart:core
Fixes #47092

TEST=existing

Change-Id: I3c5c0a1ec5e0426642a5dc70aa9a0391a143ed93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212298
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-09-06 11:57:40 +00:00
Daco Harkes 2b5adb7231 [vm] Implement constant Maps in the VM
This CL changes the frontend to emit map and set constants which are
then processed by the constant reader in the VM.

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

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

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

Change-Id: I1f8150a8aba8298c4e64d2571dd147743526135a
Cq-Include-Trybots: luci.dart.try:analyzer-nnbd-linux-release-try,app-kernel-linux-debug-x64-try,dart-sdk-linux-try,front-end-nnbd-linux-release-x64-try,pkg-linux-debug-try,vm-canary-linux-debug-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-checked-linux-release-x64-try,vm-kernel-linux-debug-x64c-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-simarm64c-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203765
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-06 06:28:59 +00:00
Johnni Winther 93c531f1a0 [cfe] Move force* flags from TargetFlags to TestTargetFlags
TEST=existing

Change-Id: I3db6f5bdd72ca6303766b6524df19e66b1ba1cc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212001
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2021-09-01 13:29:26 +00:00
Konstantin Shcheglov 3d8d29f03c Fix UNNECESSARY_TYPE_CHECK_TRUE in pkg/vm/.
Fixes before https://dart-review.googlesource.com/c/sdk/+/190360

Change-Id: I918189b0077bb4e397b6fb6dd4349960ff8c4560
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211600
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-08-27 20:27:15 +00:00
Paul Berry 1b18e8f5ac Flow analysis: account for initializers of implicitly typed variables.
Previously, initializers of implicitly typed variables did not
contribute to the SSA tracking performed by flow analysis (see
https://github.com/dart-lang/language/issues/1785).  This change fixes
the bug, however the fix is conditioned on the "constructor tearoffs"
language feature to avoid compatibility issues (we don't want someone
to publish a package taking advantage of the fix, without realizing
that it makes their package unusable on older SDKs).

TEST=standard trybots
Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: I1143440c7a9795b059e8f4b84e3f4125cd80732c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211306
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-08-27 15:01:15 +00:00
Alexander Markov 0b1ddaa598 [vm] Enable lowering of typedef constructor tear-offs
TEST=language/typedef/aliased_constructor_tear_off_test
Issue https://github.com/dart-lang/sdk/issues/46231

Change-Id: I10df62d4d170a4ae018a0e943ac6fc37d669d439
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208984
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-08-09 18:06:39 +00:00
Clement Skau bf2691c2fe [VM] Moves FfiNative fields to function parent.
Previously the synthetic field that holds the FfiNative
function pointer was injected into the current library.
This change makes sure we instead add the field to the
relevant parent - Class or Library.

TEST=Added regression test for name collision.

Bug: https://github.com/dart-lang/sdk/issues/43889
Change-Id: Ifbf2d70de00e4748c179fe7d626c495675c2b338
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208502
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2021-08-09 09:13:38 +00:00
Alexander Markov 32914654bd [vm] Treat redirecting factories as ordinary factories
After https://dart-review.googlesource.com/c/sdk/+/208681
it is now possible to use bodies of redirecting factories in the VM
and treat redirecting factories like ordinary factories.

TEST=vm/cc/DartAPI_New
TEST=vm/dart/redirection_type_shuffling_test
TEST=co19/LanguageFeatures/Constructor-tear-offs

Fixes https://github.com/dart-lang/sdk/issues/33041
Fixes https://github.com/dart-lang/sdk/issues/29201
Issue https://github.com/dart-lang/sdk/issues/46231

Change-Id: If410d2913704a33035800144699fd6e8a2570a19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208684
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-08-04 21:50:48 +00:00
Alexander Markov 300a2ea952 [cfe] Create normal bodies for redirecting factories
Replace bogus body created for redirecting factories with a
normal body which calls target factory or constructor and
forwards all arguments. Such a body can be used by back-ends
if they choose to treat redirecting factories as ordinary
factories.

TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/41915
Issue https://github.com/dart-lang/sdk/issues/46231

Change-Id: I62c83bcc9005995e85de049d3d929ca86a75297f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208681
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-08-04 17:51:07 +00:00
Alexander Markov eec08e1864 [vm] Support tear-offs for generative and factory constructors
TEST=co19/LanguageFeatures/Constructor-tear-offs
Issue: https://github.com/dart-lang/sdk/issues/46231
Change-Id: I177d0d77eac32b49d39949d696de8aa9a618cc6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208442
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-07-30 18:50:27 +00:00
Alexander Markov e774f48c0a Migrate pkg/vm to null safety, part 6
This change migrates pkg/vm/testcases to null safety and removes
passing of non-nullable experimental flag in tests.

TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/46620
Change-Id: Ief936dfd13aeb60457100fe6dead0f0fd06fd135
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-07-29 16:06:15 +00:00
Johnni Winther cb3a9b0043 [cfe] Remove old method invocation encoding nodes
TEST=existing

Change-Id: I05ee649ecfa7945e2e0f5e5d09441d8916a9c46e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208185
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-07-28 15:44:04 +00:00
Alexander Markov 45ae00676a Migrate pkg/vm to null safety, part 4
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/46620
Change-Id: I74c45ed1525248447e769cc832366728e7a017fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208020
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2021-07-27 17:52:18 +00:00
Alexander Markov ccd063bda5 Migrate pkg/vm to null safety, part 3
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/46620
Change-Id: I1ab793eec6ffd7e01cee1e6641138e96a4f4d9fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207864
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-07-27 17:50:47 +00:00
Alexander Markov 3a96674d3d Migrate pkg/vm to null safety, part 2
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/46620

Change-Id: I18bab8755bfa937b6de07a738e3f22309240da22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207365
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-07-22 17:30:49 +00:00
Daco Harkes 45899910b3 [cfe/ffi] Fix deeply nested structs in separate files
TEST=pkg/front_end/testcases/incremental/issue_46666.yaml

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

Change-Id: I56134394695f8b93096b03922336d499ccb1372a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207761
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
2021-07-22 12:58:20 +00:00
Alexander Markov 939b7defa8 [vm/aot/tfa] Optimize 'is' tests in TFA
TFA is extended to infer 'always fail' and 'always pass' outcomes
of 'is' tests, and tree shaker is improved to replace 'is' tests
with a constant true/false based on the results of analysis.

Also, tree shaker is improved to remove 'if' statements and
conditional expressions if condition value is known, and simplify
logical operations (&&, || and !) if their operands are known.
The removed parts are not visited during tree shaking to avoid
retaining classes which are only used from removed parts.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/is_test_elimination_nnbd.dart

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

Change-Id: I4086e2b78a1118b866b7f0c3b9c0034b55a8865d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206669
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-07-20 23:47:50 +00:00
Clement Skau 2f0b352e98 [VM] Adds compile-time error for non-static FfiNative
This makes it a compile-time error to add @FfiNative annotation
to any non-static function, such as an instance method.

TEST=tests/ffi/ffi_native_test.dart,pkg/analyzer/test/src/diagnostics/ffi_native_test.dart

Bug: https://github.com/dart-lang/sdk/issues/43889
Change-Id: Ib9ec61345bb47e735ed635c5ceea15ab643f65a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207306
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-07-20 11:54:30 +00:00
Alexander Markov 8e1fbc9ab3 Migrate pkg/vm to null safety, part 1
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/46620

Change-Id: I2ad3f3aac03c8c13d2562a385a5b6636675401f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207362
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-07-20 06:49:20 +00:00
Johnni Winther faed4bacb3 [cfe] Add RedirectingFactoryTearOff(Constant)
+ rename RedirectingFactoryConstructor to RedirectingFactory
+ change encoding of RedirectingFactory to use FunctionNode

TEST=existing

Change-Id: I80778acc215a36ab6b87518824389a293b96f0a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206780
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-07-19 16:46:29 +00:00
Alexander Markov a7e8e1ab15 [vm/aot/tfa] Use BlockExpression instead of Let in tree shaker
When evaluating arguments of an unreachable call tree shaker previously
inserted a sequence of nested Let expressions:

  Let tmp0 = arg0 in Let tmp1 = arg1 in ... in result

Such AST declares unnecessary local variables and may have a deep
nesting (which may potentially cause excessive stack usage and stack
overflow). This change adjusts tree shaker to use BlockExpression
with ExpressionStatements instead of nested Let nodes:

  block {
    arg0;
    arg1;
    ...
  } => result

TEST=existing tests

Change-Id: Ic08fd4f4a18a64f73540b6dc17decbe68e58f55d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206900
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-07-15 16:42:55 +00:00
Clement Skau 21ff598c99 [VM] Adds type to Args list in FfiNative transform.
This fixes an issue during signature shaking of FfiNative calls:
`type 'ConstantExpression' is not a subtype of type 'VariableGet' of 'value'`
Which is triggered by the Arguments list having type List<VariableGet>.

TEST=ffi/ffi_native_test

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: Iafcbca8018dab091b825277ac64a51587c929ea0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206787
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2021-07-14 13:41:52 +00:00
Clement Skau 460e00a6a6 [VM] Adds leaf call option to FfiNative.
This change essentially exposes `asFunction`'s `isLeaf` in
`@FfiNative`, allowing us to declare FFI Natives as leaf calls.

TEST=Adds tests/ffi/ffi_native_test.dart

Bug: https://github.com/dart-lang/sdk/issues/43889
Change-Id: I2a396fae2ab28d21df282f3afb35fa401485ed52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206375
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2021-07-14 09:13:51 +00:00
Alexander Markov 356472e221 [vm/aot/tfa] More precise handling of constructor invocations
Avoid marking class as allocated immediately when building a summary
and visiting ConstructorInvocation node. Instead, mark class as
allocated later when interpreting Call which corresponds to
a constructor invocation. This is more precise if an argument of
the constructor Call is evaluated to an EmptyType (which means
that the constructor invocation is unreachable). Otherwise it is
possible that class is marked as allocated but its constructors
are not used.

Flutter gallery AOT snapshot size:
* release mode -0.36% (both armv7 and armv8)
* release-sizeopt mode -0.39% (both armv7 and armv8)

TEST=existing tests

Change-Id: I51bdf2f1a60dda88bc2c788339ee4d4ab79d8cd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205802
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-07-13 15:59:07 +00:00