Commit Graph

1361 Commits

Author SHA1 Message Date
Nicholas Shahan 559b8552a8 [ddc,frontend_server] Fix expression compilation after recompile
Update the last known good component after a recompile reject back to
the expected state before the recompile.

Adds tests for expression compilation after recompile accept and
recompile reject cases with `--target=dartdevc`. Similar to existing
tests for the VM.

Removes calls to `_generator.accept()` and
`component.computeCanonicalNames()` from `compileExpressionToJs()`.
These were added very early in the prototype implementation and it is no
longer clear why they would be needed.

Added some additional test cases for expression compilation involving
import resolution because the change that originally added the
`component.computeCanonicalNames()` call implies it was needed for that
reason. See: https://dart-review.googlesource.com/c/sdk/+/138010

TEST=pkg/frontend_server/test/frontend_server_test.dart,pkg/dev_compiler/test/expression_compiler/expression_compiler_test.dart

Change-Id: I9c04bd46e56b33dc654d00fb330de29c3c643a5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434522
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-06-24 14:14:42 -07:00
Moritz 34e41ddb27 [record_use] Record instances in calls
So that calls with const instances as arguments can be recorded.

Tested: pkg/vm/testcases/transformations/record_use/*
Change-Id: I918e7486b2772bb6d014abb9f01f4347e24ac0b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436300
Commit-Queue: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2025-06-23 06:02:59 -07:00
Ryan Macnak ab4f9351b1 Rename vm_platform_strong.dill to vm_platform.dill.
The name has always been annoying because it did not add strong typing. And now there aren't variants of the VM platform to distinguish.

Leave a copy at the old name to not immediately break illegal uses.

TEST=ci
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,flutter-frontend-try,flutter-linux-try
Change-Id: Ie76fa7f16940aa1ba8d582eb5197f0ae55dc8938
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429828
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-16 18:33:38 -07:00
Chloe Stefantsova 39810ffbe4 [cfe] Cleanup interface of subtype queries
Under the hood, there is no difference between
`isSubtypeWhenUsingNullabilities` and
`isSubtypeWhenIgnoringNullabilities` by now. This CL makes the
corresponding renames and removals in the CFE and its clients.

TEST=existing

Change-Id: I22060c29834179c30ba62562aa254146b1d7530d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433480
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-06-13 02:02:54 -07:00
Alexander Markov d2252b1fd6 [dyn_modules] Add option to dump detailed dynamic interface
Front-end server and gen_kernel tools now take

--dump-detailed-dynamic-interface=foo.json

option which can be used along with --dynamic-interface when
AOT-compiling application with exposed dynamic interface.

This option dumps dynamic interface broken down to members
and classes as JSON.

TEST=pkg/vm/test/transformations/dynamic_interface_annotator_test.dart
Fixes b/420811696

Change-Id: Id1b15521f47a4869fefd40e835044584fbfb5274
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431901
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-30 07:53:45 -07:00
Daco Harkes 66a2833aa0 [native assets] Avoid library name clash
TEST=tests/lib/mirrors/bad_argument_types_test.dart

Closes: https://github.com/dart-lang/sdk/issues/60778
Change-Id: I9d3e7b0ea70c65489a6b6dd1263e4b2ca72c61d3
Cq-Include-Trybots: luci.dart.try:vm-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430480
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
2025-05-22 09:56:25 -07:00
Alexander Markov b083c9ac87 [dyn_modules] Handle implicit uses from const constructors and field initializers of const classes
When const constructor is exposed through a dynamic interface,
dynamic module can create constants with that const constructor and
it can reference everything used in that constructor including default
values of parameters and field initializers. So dynamic interface
annotator should visit bodies of const constructors and add all
references to implicit uses.

Annotator should also visit initializers of instance fields of
classes which can be used in a constant (as they participate in
the constant evaluation too). Kernel trim tool should not remove such
field initializers.

TEST=pkg/dynamic_modules/test/data/const_constructor
Fixes b/418928636

Change-Id: Ie216f3a4257fe5a905b83af8c60dfe8a5b774ecf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430002
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-22 06:39:25 -07:00
Ivan Inozemtsev 4cdb3f2c3a Shims generation improvement
- When return type is not directly supported and just a Dart_Handle,
  automatically create persistent handles
- Change `Dart_LoadLibrary` to `Dart_LookupLibrary`
- switch from iostream to cstdio, I have no idea why, but it doesn't
  work for me in emulators and it's not a big difference.

TEST=ci,manual
Change-Id: I9b6539c7f16e81af9e8a9ab3995d6040bac64a1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429962
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
2025-05-22 04:33:22 -07:00
Alexander Markov 0f42d66b6f [dyn_modules] Fix overriding of a method declared in a mixin
Mixin transformation copies members of a mixin into a mixin
application class. Copied members should still behave similarly to
original members in terms of overriding.

When validating a dynamic module, overriding a copy of mixin
member should be allowed if original member can be overridden.

When annotating AST with dynamic interface pragmas, can-be-overridden
pragmas should apply to all copies of mixin members.

TEST=pkg/dynamic_modules/test/data/override_mixin_method
Fixes b/418681054

Change-Id: I038ff2133ef6f0c288a47cec7300c6ac4b23cbab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429423
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-05-20 06:25:00 -07:00
Alexander Markov 02c465b580 [tfa,dyn_modules] Avoid adding abstract classes to the set of allocated classes
When constructor is annotated with an entry point pragma (including
pragmas coming from dynamic interface annotator), its enclosing class
should not be marked as allocated if it is abstract.

TEST=pkg/dynamic_modules with assertions enabled

Bug: https://github.com/dart-lang/sdk/issues/60743
Change-Id: I6bc5cd64ba4b74b12ad74917df5249f4671f1576
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428921
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-16 12:16:10 -07:00
Chloe Stefantsova 1f26ddfee2 [ffi] Account for position variance in converting native types
This CL introduces variance-dependent treatment of the `Handle` native
type when converting native types to Dart types. Since `Handle` can
represent any object, it should match any type. To achive that in
cases when `Handle` appears as the subtype in the subtype checks, it's
converted to `Never` in covariant positions and to `Object?` in
covariant ones.

TEST=existing

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

Change-Id: Ie16a210491ada80d21f4d0f1c0fa3b3804881ede
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426880
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-15 22:53:41 -07:00
Alexander Markov d039e2865b [tfa,aot,dart2wasm] More precise intersection of a wide cone type with an empty cone type
When cone type has a large number of allocated subtypes, TFA uses
symbolic wide cone type as a faster approximation to speed up
the analysis.

Intersection of wide cone type C1+ with cone type C2+ when
there is no subtyping relation between C1 and C2 results in
approximate type C1+. As a result, analysis may fail to determine
that certain type test will never succeed.

This change improves precision of cone and wide cone intersections
and unions in case cone type has an empty specialization
(no allocated subtypes).

TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_60733.dart
Fixes https://github.com/dart-lang/sdk/issues/60733

Change-Id: I51287d38a9e5f3c0ce88dab358d0825843a0de03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428840
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-15 15:37:25 -07:00
Alexander Aprelev 50e0e0d99d [vm/shared] Introduce NativeCallable.isolateGroupShared
This method allows for synchronous execution of dart callbacks from native code. The execution happens on dart mutator thread, from which dart code can only access isolate-group variables - those which are tagged with .

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841
Change-Id: Ia1a6b01327be493f003f1eea82e558bb6b147dd3
CoreLibraryReviewExempt: only internal library change
TEST=isolate_group_shared_callback_test
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422920
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-06 13:28:44 -07:00
Moritz 7a83c82b4f [record_use] Don't record locations for usages and other refactorings
In preparation of a merge with the Dart2Js format in a follow up PR.

- Treat default values as passed arguments - `foo(4)` is the same as
  `foo()` for all intents and purposes for a `foo([int i = 4])`.
- Add signatures to lookup, as dart2js forgets them during
  compilation.
- Encode non-constant arguments as `null`, while a `null` passed as an
  argument is a `NullConstant`.

Tested:pkg/vm/test/transformations/record_use_test.dart
Change-Id: Ifd2597d8d1b979627fa45fd4736a762031c17216
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415620
Commit-Queue: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Moritz Sümmermann <mosum@google.com>
2025-04-28 06:12:00 -07:00
Alexander Markov 6156dd6e59 [dynamic modules] Respect dyn-module:language-impl:* pragmas during dynamic module validation
Dynamic module validation now accepts reference to classes and members
from 'dart:*' libraries if they are annotated with
dyn-module:language-impl:* pragmas. This matches the behavior of
dynamic interface annotator.

This is a follow-up to
https://dart-review.googlesource.com/c/sdk/+/418663.

Also, when checking for possible dynamic overrides in TFA,
treat _enumToString from dart:core as a public name because
front-end desugars enums into classes which override
private _enumToString method in a different library.

TEST=pkg/dynamic_modules/test/data/enum
Fixes b/395992622

Change-Id: I45ed9855f806224a510fa4e56962607de3371eb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423820
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-04-23 07:43:02 -07:00
Chloe Stefantsova 669bcef1a6 [model] Introduce isErroneous flag on Members in Kernel
The flag is used to signal known issues with members, so that the
verifier could skip on checking assumptions for well-formed programs.

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

TEST=existing

Change-Id: I7cf1983035d26105ccfe2e7a844a9ba3108bfda2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420760
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-04-23 01:15:43 -07:00
Daco Harkes 7427e655f6 Revert "[ffi] Remove deprecated Pointer.elementAt"
This reverts commit 789302053e.

Reason for revert: This breaks flutter engine

```
../../../../../../../.pub-cache/hosted/pub.dev/posix-6.0.1/lib/src/util/conversions.dart:32:32: Error: The method 'elementAt' isn't defined for the class 'Pointer<Pointer<Int8>>'.
 - 'Pointer' is from 'dart:ffi'.
 - 'Int8' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'elementAt'.
    final _value = cStringList.elementAt(count).value;
```

```
ui 0.0.0
├── archive 4.0.3
│   ├── posix 6.0.1
│   │   ├── ffi 2.1.4
│   │   ├── meta...
│   │   └── path...
```

Reverting while we remove uses upstream.

https://github.com/onepub-dev/dart_posix/pull/17

Original change's description:
> [ffi] Remove deprecated `Pointer.elementAt`
>
> Bug: https://github.com/dart-lang/sdk/issues/54250
>
> TEST=tests/ffi
>
> CoreLibraryReviewExempt: Removing deprecated member after 1+ year.
> Change-Id: I2234f28126e0788860a54cbe6aa82bc76b49c8d8
> Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421740
> Reviewed-by: Hossein Yousefi <yousefi@google.com>
> Commit-Queue: Daco Harkes <dacoharkes@google.com>

Bug: https://github.com/dart-lang/sdk/issues/54250
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Change-Id: I9cd3d4800840bf28182225824b82c469eb957087
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422460
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-04-15 08:11:57 -07:00
Daco Harkes 789302053e [ffi] Remove deprecated Pointer.elementAt
Bug: https://github.com/dart-lang/sdk/issues/54250

TEST=tests/ffi

CoreLibraryReviewExempt: Removing deprecated member after 1+ year.
Change-Id: I2234f28126e0788860a54cbe6aa82bc76b49c8d8
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421740
Reviewed-by: Hossein Yousefi <yousefi@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2025-04-10 11:14:02 -07:00
Martin Kustermann e40980cb3d [tfa] Fix bug in TFA transformation of unused fields
When a TFA eliminates a field it moves it's initializer to a
`LocalInitializer` of the constructor. After [0] the
`VariableDeclaration` of the local initializer will get the type of the
field.

Though that CL didn't ensure TFA also visits the type of the
`VariableDeclaration`. This can lead to a situation where the type
refers to a class that TFA has tree shaken, which causes dangling
references in the AST.

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

Issue https://github.com/flutter/flutter/issues/166124
Issue b/406692736

TEST=pkg/vm/testcases/transformations/type_flow/transformer/write_only_field

Change-Id: Ieb8f5c4daedd314c613617218da898059bb6941a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419542
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-04-01 04:22:37 -07:00
Alexander Markov 733ca506c1 [dynamic modules] Add pragmas to core library classes and members used to implement language features
This change adds pragmas which can be used in dart:* libraries to
specify classes and members which are used by the compiler
to implement certain language features. Compiler can insert
references to those classes and members when desugaring language
constructs, so dynamic module code can use these classes and members
implicitly even if they are private.

Previously, we required to specify these members in the
dynamic_interface.yaml before dynamic modules could use them.
However, this is cumbersome and error-prone.

Now, the following pragmas are recognized:

@pragma('dyn-module:language-impl:extendable')
@pragma('dyn-module:language-impl:can-be-overridden')
@pragma('dyn-module:language-impl:callable')

If dynamic interface yaml file is specified during compilation,
then classes/members annotated with these pragmas are treated as if
they are used in corresponding sections of dynamic_interface.yaml.

If dynamic interface yaml file is not specified, these pragmas
are ignored.

Bug: b/395992622

TEST=existing
CoreLibraryReviewExempt: no API changes, only adding pragmas.
Change-Id: I6606467fc5e5264a2565d7eb8e8baccc2eebea84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418663
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-03-31 11:33:50 -07:00
Michael Goderbauer c326065c3f [vm/ffi] Exposes an iterable Array.elements
For the arrays of the Int/Uint/Float/Double types this has been
implemented straight in the ffi_patch.dart file and `elements` returns a
typed-data list view on the original data backing the array.

The Bool and Pointer arrays return helper classes from their `elements`
getter. These helper classes implement the `List` interface utilizing
the `operator []` implementation of the underlying arrays. This is also
implemented directly in the ffi_patch.dart file.

The `elements` getter for array arrays is rewritten in the CFE
(use_sites.dart) to instantiate a helper class to which the size of a
single element of the array is passed (this information is not available
in ffi_patch.dart, hence the rewrite in the CFE). The helper class
implements the `List` interface and performs some pointer arithmetic
with the provided element size to implement its methods.

The `elements` getters for struct and union arrays are also rewritten in
the CFE to instantiate a helper class to which a constructor tearoff for
instantiating the underlying struct/union type is passed. The helper
class also implements the `List` interface and uses the provided
constructor tearoff to create instantiated structs/unions of the
elements in the list.

Last, but not least, the `elements` getter for abi-specific integer
arrays is also rewritten in the CFI to instantiate a helper class to
which a closure is provided to load abi specific integers from the
underlying array data structure.

TEST=tests/ffi/array_compound_elements_test.dart
TEST=tests/ffi/array_primitive_elements_generated_test.dart
CoreLibraryReviewExempt: Dart VM only.
Bug: https://github.com/dart-lang/sdk/issues/45508
Change-Id: I211a42174057c39632c6a363d4e8e6fa8e94e801
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414821
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2025-03-20 06:38:27 -07:00
Tess Strickland acd16c6aa7 [pkg/vm] Add tool for generating DartEngine shims from entry points.
This is an initial cut of a tool for automatically creating shims for
C/C++ programs using the entry point annotations in Dart code. The tool
has two required arguments:

* the .dill file containing the kernel representation of the Dart code
* the base path of the header and implementation files to create

With a base path of 'dir/name', the header file is created as
'dir/name.h' and the implementation file is created as 'dir/name.cc'.
In addition, 'dir/name.h' is used as a basis for creating a
#ifndef/#define/#endif header guard around the header contents.


The created shims are specific to a single package, either

* a user-specified package, provided via '-p'/'--package', or
* the package of the main method

If the user does not specify a package and there is no main method
in the .dill file, the tool fails.


Each shim takes the following arguments in order when applicable:

* the isolate in which to perform the requested operation,
* the instantiated type of the generic class (for invoking, setting, or
  getting constructors, static methods, and static fields)
* the instance (for invoking, getting, or setting instance methods and
  fields)
* the type arguments (for retrieving nullable or non-nullable
  instantiated types of a generic class)
* the arguments (for invoking, setting, or getting constructors,
  methods, and fields)


The generated shims:

* cache the package library, types for non-generic classes, and
  types for generic classes instantiated with default type arguments.
  The cached persistent handles are cleared if any of the methods
  are called with a different isolate from the one used to populate
  the cache.
* automatically handle conversions between C int64_t <=> Dart int
  and C double <=> Dart double.


By default, shims are not created for allocation or initializing
uninitialized instances. To create such shims, use the '-u' command
line argument.


Currently, shims are not created for methods that take optional
or named arguments. To report an error if a shim cannot be created
for any entry points, use the '-e' command line argument.

TEST=tests/standalone/embedder_samples_test

Change-Id: Ibdf3b52d900ba98038528178485f295c5868ac9d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410500
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-03-20 03:53:10 -07:00
Alexander Markov 1b6f89d284 [vm, tfa] Fix tree-shaking of late final fields with initializers
TFA tree shaker removes initializers of fields which cannot be accessed
but retained due to an entry point pragma / dynamic interface.

For late final fields with initializers that changes semantics as
late final fields without initializers have an implicit setter.
Such setter is not accounted in the kernel AST
(Field.setterReference == null and Field.hasSetter == false) and
it doesn't get an assigned selector id, which causes a crash in
dispatch table generator.

The change fixes this bug by retaining initializers for late final
fields. The initializer code is still replaced with
throw "Attempt to execute code removed by Dart AOT compiler (TFA)".

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

Bug: b/404559785
Change-Id: Id998a715ea75a4768414997ce66bcdd1d4f19189
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416720
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-03-19 12:31:02 -07:00
Ömer Ağacan cf9f45f1d4 [dart2wasm] Copy VM's map and set factory transformers
Transform factory calls to default map and set classes to the
constructor calls to the classes to improve kernel.

Also remove some redundant null checks in VM's transformer.

`source_map_simple_optimized_test.dart` is updated: with improved kernel
wasm-opt now eliminates the `testMain` function, so the stack trace
doesn't mention it.

Fixes https://github.com/dart-lang/sdk/issues/60343.
Tested: minor refactoring in VM doesn't need testing. Wasm tested with
existing tests.
Change-Id: Ie448d1374ff0e1b278859f22bc250899e0e4cfd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416640
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-03-19 08:10:16 -07:00
Alexander Markov 2ac7957077 [vm, dynamic_modules] Support extensions and extension types in dynamic interface annotator
TEST=pkg/vm/test/transformations/dynamic_interface_annotator_test.dart

Bug: b/404399018
Change-Id: I9b4baafc0c75b62f4fe15cb1191f0e31669a8538
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416340
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-03-19 06:30:48 -07:00
Johnni Winther 06d938046f [kernel] Remove NonNullableByDefaultCompiledMode
and TargetFlags.soundNullSafety

TEST=existing

Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-19 01:37:07 -07:00
Martin Kustermann 4474e81545 [tfa] Use field type as type of temporary variable when removing fields in TFA
When a field gets never read TFA may remove the field entirely. The
initializer of the field may still need to be executed as it may have
side-effects. The initializer is then moved to a `LocalInitializer` with
a unused variable.

Currently this variable is typed `dynamic` but could be strenghtened to
be the type of the field, which this CL does.

The usage of `dynamic` can have problems for some backends that have
types that aren't part of the Dart object hierarchy (e.g. a
`WasmArray`). Those types cannot flow into top types as they are not
real Dart objects. By typing the `LocalInitializer` variable the same as
the field type, we avoid assigning such foreign, no-Dart objects to
variables of Dart top-type.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/write_only_field.dart.expect

Change-Id: Idd4bf944afad83ceb1850f478e7a9d9cd47bf00d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415201
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-03-13 06:52:00 -07:00
Johnni Winther 0060b0f665 [cfe] Remove nnbd mode
TEST=existing

Change-Id: I30bbadb74e81c7f4aaa444d1e2f6f5ffc2005d4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412881
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-03-04 01:46:51 -08:00
Jens Johansen 2fff7d83e8 [CFE/VM] Make IncrementalCompilerResult classHierarchy, coreTypes non-nullable; always use latest
This also fixes a potential leak on missing .accept call where using the
non-latest coreTypes in the VM causes us to hold on to old libraries.

Tested: CI
Change-Id: I3a4a25dab83de0d5113b9f08ec745ac181c24b9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411580
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-02-26 00:43:19 -08:00
Daco Harkes 23cde7f4b8 [pkg/vm] Format pkg/vm with new style
TEST=reformatting only

Change-Id: I310e2568661e919a2c8354e01e19d18f7109f54c
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399261
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-14 07:18:29 -08:00
Nate Biggs a4a4ca8a41 [dart2wasm] Dynamic modules
Missing from this implementation:
- Closure/dynamic calls with differing signatures
- Overrides with extra optional parameters
- Records with same shape defined in different dynamic modules
- Avoiding running TFA on dynamic module.
- Recompilation of only updateable functions from main module.
- Persist wasm def types from main module.

Testing is currently done locally via the dynamic_modules package test suite:
dart pkg/dynamic_modules/test/runner/main.dart --runtime=dart2wasm

Immediately after this lands we can introduce a new step to one of the wasm test matrix configurations that runs the above test suite (the VM has a similar configuration).

Change-Id: I3386d84be11b773842d45f4268a62a54c47e352b
Tested: Tested via new tests in dynamic_modules package. Tests run locally but will add to existing config.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397721
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-02-11 13:59:46 -08:00
Alexander Markov dd4f341e15 [dart2bytecode] Add API to invoke dart2bytecode programmatically
TEST=ci
Bug: b/394206952
Change-Id: Icd606c83bfed335e45498fceed6add784c465826
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407820
Reviewed-by: Jia Hao Goh <jiahaog@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-06 08:44:12 -08:00
Johnni Winther 7c22f942aa [_fe_analyzer_shared] Remove macro tests and helpers
These are no longer used.

TEST=removed

Change-Id: Ibf5b2de9d1b550c21873b48111161366deb2ddc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407980
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
2025-02-05 03:59:31 -08:00
Tess Strickland 1ac77f57dd [vm] Align entry point verification and the precompiler.
For entry-point pragma annotations, most of the time they are
used with either no argument or with an argument that evaluates
to either

* false to denote the annotation should not take effect, or
* null or true to denote the annotation should take effect.

However, the user can also specify that only part of the operations
on a member should be accessed from native code by using a string
argument that is either 'call', 'set', or 'get'.

The entry point verification in Invoke/InvokeGetter/InvokeSetter
assumes that for getters and setters, the only valid string argument
is 'get' or 'set', respectively. This is because those methods are
called via `Dart_GetField`[0] and `Dart_SetField`, respectively, as if
they were the getter or setter of a defined field.

However, the precompiler previously assumed that the string
argument 'call' was the only string argument that meant the link
to a function's code object should be saved. Similarly, it assumed the
string argument 'get' for functions meant that their implicit closure
function should be saved, which ends up including getters. Furthermore,
it did not do anything with setters annotated with the string argument
'set'. This means that the code link would not be saved for getters or
setters that were annotated with the string argument expected by the
entry point verifier.

This CL aligns the precompiler to match the expectations of other
parts of the codebase. It also changes TFA to report an error
if a getter or setter is marked with the string argument 'call'.

[0] `Dart_Invoke` can be called with the name of a getter that
returns a closure, but doing so is semantically equivalent to
calling `Dart_GetField` followed by `Dart_InvokeClosure`.

TEST=vm/dart/entrypoint_verification_test

Fixes: https://github.com/dart-lang/sdk/issues/59920
Change-Id: Ia2768bbaf9058bb14a1cdfb331eb85fa082a0e90
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-product-x64-try,vm-aot-mac-product-arm64-try,vm-aot-obfuscate-linux-release-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404823
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-01-24 03:21:22 -08:00
Alexander Markov 11ea496dd8 [vm,dart2wasm,tfa] Handle 'Never' static type as unreachable in TFA
When building a data flow summary, break control and data flow after
invocations with static result type 'Never', expressing that code after
such invocation is unreachable.

TEST=pkg/vm/testcases/transformations/type_flow/summary_collector/control_flow.dart

Issue: https://github.com/dart-lang/sdk/issues/59941
Change-Id: I2e5acd861e4192bae231d356aeacf921a14766f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405443
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-01-23 11:41:00 -08:00
Ömer Sinan Ağacan 9b4b3693ba [tfa] Propagate double constants
Similar to propagating `int` and `String` constants and literals,
propagate `double` constants and literals when they're not nan or
plus/minus zero.

Tested: updated existing test file with more cases
Change-Id: I1324a6804418710516c40c0744f0c5f417b92e83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405000
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-01-20 00:39:59 -08:00
Ömer Sinan Ağacan 8f94144924 [tfa] Propagate int and string constants in conditionals
When comparing a value against a literal or constant:

    if (x == literal) { ... }
    if (x == constant) { ... }

Allow propagating the value if the LHS type is `int` or `String`, as
those types don't have identity.

Previously we would propagate the values if the RHS is a literal (not
constant). Constants would only be propagated if the LHS type does not
override `operator ==`. Because `int` and `String` don't have identity,
they can be propagated when they're constants even though they override
`operator ==`.

Tested: Added new TFA transformer test.
Change-Id: I3c150ffae39bfbc06992f666ffec7bab1d1c52d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403987
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-01-20 00:26:12 -08:00
Ömer Sinan Ağacan 78ce85a7fe [dart2wasm,tfa] Don't infer class of string values in comparisons
In dart2wasm, when a comparison like `x == "hello"` is true, we can't
assume that the class of `x` is the same as the class of `"hello"`:

- If `x` is received from JS, it will be `JSStringImpl`.
- If it's a substring of a `TwoByteString`, it will be `TwoByteString`.
- Otherwise it will be `OneByteString`.

Update `Target` with the new method

```
bool get canInferStringClassAfterEqualityComparison => true;
```

to allow TFA to *not* infer classes of string values after comparisons.

Override the method to return `false` in dart2wasm's `Target`
implementation.

Fixes #59901.
Tested: web/wasm/issue_59901_test
Change-Id: I1a6c8deaf27c54240dd4e821dbd8160914502ad7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404562
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2025-01-16 03:24:39 -08:00
Alexander Markov 9e8e8e5fca [vm,dynamic_modules] Support members which are overridden implictly (transitively) by a dynamic module
Consider the following situation: member M1 is overridden by another
member M2; M2 is overridden in a dynamic module.

Members which can be overridden in a dynamic module (such as M2)
should be specified as 'can-be-overridden' in the dynamic interface.
Members which are overridden implicitly/transitively (such as M1)
are not required to be mentioned in the dynamic interface.
However, when determining possible targets for a call with
interface target M1, compiler should treat it as potentially
overridden in a dynamic module.

This change adds such handling to the VM/AOT. Dynamic interface
annotator now marks members such as M1 with
'dyn-module:can-be-overridden-implicitly' pragma, and
VM/AOT takes both can-be-overridden and can-be-overridden-implicitly
into account.

This change also simplifies handling of implicitly extenable classes
in the VM/AOT - now VM handles both extendable and implicitly-extendable
pragmas (from dynamic interface annotator) instead of recalculating
implicitly extendable classes on its own.

TEST=pkg/vm/test/transformations/dynamic_interface_annotator_test.dart
TEST=dynamic_modules_suite/implicitly_extendable

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

Change-Id: Id4570cc86303f8e45a061d696e9bca0d0b2b4b81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403951
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-01-15 08:13:52 -08:00
Alexander Markov 048df9d706 [vm] Fix tree-shaking of mixin applications when mixin has a member with entry point pragma
Cloned static members of mixins are not used (dead code) and usually
tree shaken in AOT mode. However, if static member is annotated with
@pragma('vm:entry-point'), its clone in the mixin application is
also retained. If such mixin application is not used, tree shaker
drops its supertypes which removes the link from mixin application to
the original mixin. As a result, gen_snapshot crashes when trying
to access original mixin in order to print qualified name of the member.

The first part of the fix is to avoid cloning static members into
mixin applications, which would allow tree shaker to remove unused
mixin applications entirely. This change also reduces size of
the non-AOT kernel binaries.

However, instance members of mixins are cloned
and they could be annotated with entry point pragmas too.

The second part of the fix is to clear isEliminatedMixin flag
in tree shaker when dropping supertypes.

TEST=pkg/front_end/testcases/general/mixin_with_static_member.dart
TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter160030.dart

Fixes https://github.com/flutter/flutter/issues/160030

Change-Id: I1b36c4a7f64a4530c8b4799ec785f1077ce65de6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403963
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-01-13 07:30:16 -08:00
Nate Biggs 92ef752810 [dynamic-modules] Add pragma annotating implicitly extendable types.
All supertypes of classes marked as "dyn-module:extendable" are technically also extendable in dynamic modules since subtyping is transitive.

Also skip marking 'final' classes as dynamic module extendable.

Change-Id: I124eae56b78b98aba8712158fda87bbc8e652ed3
Tested: Ran tests for dynamic interface annotator.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403960
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-01-09 14:42:41 -08:00
Alexander Markov 742850f9cc [vm/aot,dart2wasm,tfa] Infer null after comparison with null only if value is potentially nullable
Previously, TFA was building a summary for the comparison
'v == null' assuming type of 'v' is Null on the true branch.

As a result, after joining data flow Null contaminates value of 'v'
further down:

v0 = ...
t1 = IsNull(v0)         // Condition
t2 = Null               // On true branch
t3 = NarrowNotNull(v0)  // On false branch
v1 = Join(t2, t3)       // This value is nullable even if v0 was not.
...
use(v1)

This change adds a condition to the Null value so it is evaluated to
Empty type if original value turns out to be non-nullable:

t1 = IsNull(v0)
t2 = Move(Null) {t1}    // Empty if t1 is false.
t3 = NarrowNotNull(v0)
v1 = Join(t2, t3)


TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_59845.dart
Fixes https://github.com/dart-lang/sdk/issues/59845

Change-Id: I0f78e31f9eaf6507cc78e393de2fc12a9cf29f4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403200
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-01-08 07:20:01 -08:00
Chloe Stefantsova 3393befc99 [cfe] Remove constructors for alpha renaming
In this CL methods StructuralParameterType.forAlphaRenaming,
StructuralParameterType.forAlphaRenamingFromTypeParameter,
TypeParameterType.forAlphaRenaming, and
TypeParameterType.forAlphaRenamingFromStructuralParameter are removed,
and their call sites are replaced with invocations of other
constructors of StructuralParameterType and TypeParameterType. The
reason for this change is call sites having more information for
correct computing of type nullabilities.

In addition to the primary update, the following related changes are
made in this CL.

* Method StructuralParameterType.computeDefaultNullabilityForLibrary
  is renamed into StructuralParameterType.computeDefaultNullability,
  and TypeParameterType.computeDefaultNullabilityForLibrary is renamed
  into TypeParameterType.computeDefaultNullability. The parameter
  `library` is removed from both methods, since it's no longer needed.
* The static methods named `computeNullabilityFromBound` are removed
  from `StructuralParameterType` and `TypeParameterType` and
  re-introduced as instance members in classes `StructuralParameter`
  and `TestParameter` respectively

TEST=existing

Change-Id: I26cccf17ccc9bda1e8b750196f427325b544a7ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402820
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-01-07 01:16:48 -08:00
Halil Durmus 1a8afa6bbf [vm/ffi] Allow omitting native types for @Native functions
This change simplifies working with `@Native`-annotated functions by allowing the native type to be omitted when it can be inferred from the Dart function's signature. While this was previously supported for `@Native` fields, it now applies to functions as well.

Before this change, you needed to specify the native type explicitly:
```
@Native<Void Function(Pointer)>()
external void free(Pointer p);
```

After this change, the native type can now be omitted if it's clear from the Dart signature:
```
@Native()
external void free(Pointer p);
```

TEST=tests/ffi/native_assets/*

CoreLibraryReviewExempt: VM only
Closes: https://github.com/dart-lang/sdk/issues/54810
Change-Id: Ied5407fcd2f49d85284cb7817f0c8cad2a73626b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400840
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-12-20 02:05:40 -08:00
Halil Durmus 466fa5593d [vm/ffi] Add refWithFinalizer methods to StructPointer and UnionPointer
TEST=tests/ffi/extension_methods_test.dart

CoreLibraryReviewExempt: VM only
Closes: https://github.com/dart-lang/sdk/issues/56796
Change-Id: I29af1e6b61b5a07887f00b3a924f1b354ffb0bbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399600
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-12-19 14:07:50 -08:00
Alexander Aprelev 4093bdaf5a [vm] Change try-catch IL representation.
Previously catch blocks were hanging off the function entry blocks being effectively an alternative entry-point into the function. Now catch blocks are hanging off the try-entry blocks.
  Previously all the variables that are used in the catch block and beyond were declared as parameters to catch block. Now only those that have their definitions not dominating catch entry will become parameters (for example, if a variable is assigned in the try-block, it becomes a parameter to catch block).
  During OSR, if OSR target entry point is inside some try-blocks, then all of corresponding try-entry/catch-blocks are pulled up to the OSR entry forming a chain that ends with a jump to the OSR target entry.

TEST=vm/dart/trycatch*, ci
Change-Id: Iae20c6548d5d65c63be6d7a53c1b0d2adac7ac31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356311
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-12-18 09:30:10 -08:00
Alexander Markov 8c1fa6d05b [tfa,aot,dart2wasm] Allow tree-shaking of extension type members independently of their tear-offs
ExtensionTypeMemberDescriptor.memberReference and
ExtensionMemberDescriptor.memberReference are now nullable.

TFA-based tree shaker can now set them to null when extension type
member is not used and removed but corresponding lowered tear-off is
still used and retained.

Front-end never sets them to null and requires non-null memberReferences
when consuming kernel.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter155624.dart
Fixes https://github.com/flutter/flutter/issues/155624

Change-Id: I71f98c02f4659ff72a8c1d7fc6c578e8b8e26d82
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-12-18 06:10:31 -08:00
Alexander Markov a6b0fced83 [tfa,aot,dart2wasm] Retain libraries which only have extensions and extension types
Previously, TFA-based tree shaker did not retain libraries if they have
extensions and extension types which are still used.
As a result, kernel files were incomplete and certain tools, such as
Flutter const finder failed to read kernel files after tree shaking.

This change fixes tree shaker to retain libraries when they have used
extensions and extension types.

TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter160137.dart
Fixes https://github.com/flutter/flutter/issues/160137

Change-Id: Iac6f3a13323d053dfab2230367dcafa2550484db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401481
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-12-18 05:15:39 -08:00
Ömer Sinan Ağacan dbee089237 [dart2wasm] Devirtualize closure calls based on TFA direct-call metadata
Use the TFA direct-call metadata to directly call a closure in function
invocations.

Closes #55231.

Tested: existing tests cover the new code paths, but I also added a new
test.
Change-Id: Ib5f26b10efd77570e256196b4bfb07e6bef800c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397260
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-12-11 10:46:20 +00:00
Halil Durmus bb483f34a3 [vm/ffi] Allow configuring the variable dimension of variable-length arrays
TEST=tests/ffi/*

CoreLibraryReviewExempt: VM only
Closes: https://github.com/dart-lang/sdk/issues/52366
Change-Id: I545a323f48d955b591cedf2dae7106d9004242e2
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398621
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-12-09 22:02:56 +00:00