Commit Graph

213 Commits

Author SHA1 Message Date
Kilian Schulte 9e8fdef17c Add annotation-based creation location tracking
Closes https://github.com/dart-lang/sdk/pull/63011

GitOrigin-RevId: 926534c2f5d3cd1e9629cf25f6b028ab34c00e64
Change-Id: I88460a060faabeae8f611e88f23b2eb5fc99f21a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491702
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2026-04-28 03:06:03 -07:00
Sigmund Cherem 7f4f8347a9 [dyn_modules,vm] Apply dynamic interface annotator on non-AOT compiles
In order to perform runtime checks on dynamic calls, the JIT runtime
needs to also have access to some pragmas introduced by the annotator.
Primarily we need the `dynamically-callable` and
`implicit-dynamically-callable` pragmas.

For now, this CL allows us to mimic the behavior in JIT by using the
annotator also when doing non-aot kernel compiles. This is not enough to
support JIT in the general case: it doesn't support compiling from
source with the front-end-server or incremental builds. To support those
we will likely need a modular approach (like only annotating explicit
dynamically-callable during kernel compiles and inferring
implicit-dynamically-callable in the VM instead).

Note: this CL doesn't introduce new logic, it mainly moves the existing
logic to also run when building kernel snapshots for JIT.

TEST=existing, in the future additional coverage will be added when
performing runtime checks.

Change-Id: I9b97dd9f029f1d538ee23c0dff73b01dec0d776b
Bug: b/506246406
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497622
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2026-04-24 17:59:27 -07:00
Alexander Markov 8a2deccc9a [vm,dart2bytecode] Reformat pkg/dart2bytecode and pkg/vm
Reformat these packages after the language version was bumped in
https://dart-review.googlesource.com/c/sdk/+/487942

TEST=ci

Change-Id: I6475e4b3d096b3c1f9aded34a5736989222e1689
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489400
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2026-03-20 06:35:41 -07:00
Daco Harkes 1cab2a8617 [record_use] Only record definitions with a package: uri
Record only for definitions in libraries with a `package:` uri.

* Converts all the tests to be in packages.
  * Bonus: This removes the uri-mapping in equality checks.
  * These packages are added to the root pub workspace.
  * For the dart2js tests we need to do some juggling to keep the
    tests files in memory.
* Only support `package:` uris
  * Removed all the `relativizeUri` code for file paths.
  * Start emitting errors on non `package:` uris with a `@RecordUse()`
    annotation.

Unrelated cleanups:

* We no longer support recording const instances in annotations, this
  PR cleans up code in `kernel` and `type_flow`.

TEST=pkg/compiler/test/record_use/record_use_test.dart
TEST=pkg/dart2wasm/test/record_use_test.dart
TEST=pkg/vm/test/transformations/record_use_test.dart

Closes: https://github.com/dart-lang/native/issues/2891
Change-Id: I1bc6905291230375e185930d2c000700ac778f85
Cq-Include-Trybots: luci.dart.try:dart2wasm-asserts-linux-chrome-try,dart2wasm-asserts-minified-linux-d8-try,dart2wasm-linux-chrome-try,dart2wasm-linux-d8-try,dart2wasm-linux-firefox-try,dart2wasm-linux-jscm-chrome-try,dart2wasm-linux-optimized-jsc-try,pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart2js-canary-linux-try,dart2js-hostasserts-linux-d8-try,dart2js-linux-chrome-try,dart2js-linux-firefox-try,dart2js-mac-chrome-try,dart2js-mac-safari-try,dart2js-minified-csp-linux-chrome-try,dart2js-minified-linux-d8-try,dart2js-unit-linux-x64-release-try,dart2js-win-chrome-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478920
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-02-06 09:27:13 -08:00
Ben Konyi 364b36691c Reland "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
This reverts commit c616db31d2.

Reason for revert: Fix landed downstream in Flutter engine: https://github.com/flutter/flutter/pull/180127

Original change's description:
> Revert "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
>
> This reverts commit b5e60be49d.
>
> Reason for revert: broke Flutter web engine tests
>
> Original change's description:
> > [ DDC / CFE ] Add support for allowing imports of unsupported libraries
> >
> > This change adds support for allowing for imports of unsupported
> > platform-specific libraries when the
> > `--include-unsupported-platform-library-stubs` flag is provided to the
> > CFE.
> >
> > This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
> > `TargetFlags`, which `Target`s can use to conditionally return different
> > `DartLibrarySupport` objects with different supported/unsupported
> > library sets.
> >
> > A `checkForUnsupportedDartColonImports` function has been added to
> > `Target` that uses the value of `dartLibrarySupport` to determine if
> > there's any unsupported library imports. This function is called after
> > the various transformation operations provided by the `Target`
> > implementation, meaning the import of an unsupported library specified
> > in `dartLibrarySupport` will now result in a compilation error (this
> > includes `dart:mirrors` imports for VM targets when mirrors are
> > disabled, which was previously handled by the VM itself).
> >
> > Related to https://github.com/dart-lang/sdk/issues/62125
> >
> > TEST=Tests added / modified
> >
> > Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
> > Reviewed-by: Nicholas Shahan <nshahan@google.com>
> > Reviewed-by: Johnni Winther <johnniwinther@google.com>
> > Commit-Queue: Ben Konyi <bkonyi@google.com>
>
> Change-Id: I0b59f00e55a2424f783351abd977eb38409ce01f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469100
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

Change-Id: I1ae2eac675432286aebabea3c1f58caf35a27fbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469240
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-12-19 12:53:22 -08:00
Alexander Markov c616db31d2 Revert "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
This reverts commit b5e60be49d.

Reason for revert: broke Flutter web engine tests

Original change's description:
> [ DDC / CFE ] Add support for allowing imports of unsupported libraries
>
> This change adds support for allowing for imports of unsupported
> platform-specific libraries when the
> `--include-unsupported-platform-library-stubs` flag is provided to the
> CFE.
>
> This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
> `TargetFlags`, which `Target`s can use to conditionally return different
> `DartLibrarySupport` objects with different supported/unsupported
> library sets.
>
> A `checkForUnsupportedDartColonImports` function has been added to
> `Target` that uses the value of `dartLibrarySupport` to determine if
> there's any unsupported library imports. This function is called after
> the various transformation operations provided by the `Target`
> implementation, meaning the import of an unsupported library specified
> in `dartLibrarySupport` will now result in a compilation error (this
> includes `dart:mirrors` imports for VM targets when mirrors are
> disabled, which was previously handled by the VM itself).
>
> Related to https://github.com/dart-lang/sdk/issues/62125
>
> TEST=Tests added / modified
>
> Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

Change-Id: I0b59f00e55a2424f783351abd977eb38409ce01f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469100
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-12-18 09:47:11 -08:00
Ben Konyi b5e60be49d [ DDC / CFE ] Add support for allowing imports of unsupported libraries
This change adds support for allowing for imports of unsupported
platform-specific libraries when the
`--include-unsupported-platform-library-stubs` flag is provided to the
CFE.

This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
`TargetFlags`, which `Target`s can use to conditionally return different
`DartLibrarySupport` objects with different supported/unsupported
library sets.

A `checkForUnsupportedDartColonImports` function has been added to
`Target` that uses the value of `dartLibrarySupport` to determine if
there's any unsupported library imports. This function is called after
the various transformation operations provided by the `Target`
implementation, meaning the import of an unsupported library specified
in `dartLibrarySupport` will now result in a compilation error (this
includes `dart:mirrors` imports for VM targets when mirrors are
disabled, which was previously handled by the VM itself).

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

TEST=Tests added / modified

Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2025-12-17 09:30:38 -08:00
Nate Biggs 2284e74d7e [tfa] Update protobuf treeshaker to handle protobuf messages with mixins.
Dart protobufs allow users to specify a mixin class that will get
applied to a GeneratedMessage subclass's class hierarchy. Internal
programs use these mixins for various purposes. But these classes can
still benefit from tree shaking.

This is controlled by a separate flag because it is technically unsafe
to introduce this treeshaking to a new set of classes. The user must
opt-in to verify these new classes are safe to tree-shake. We already
have an analagous flag for tree shaking in dart2js (and some customers
have turned it on).

TEST=Treeshaker test and testcases updated.

Change-Id: Id613078699af38b7ca36420fb2b41945d645b6a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/462180
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-11-21 00:22:56 -08:00
Alexander Markov 846c5bb4ca [dyn_modules] Compile all libraries mentioned in dynamic_interface.yaml
All libraries exported via dynamic_interface.yaml (except 'dart:'
libraries) are now always compiled, as if they were specified
using --source flag on the gen_kernel / frontend_server command line.

This makes sure that exported libraries would be available for
dynamic modules even if they are not used in the host app.

TEST=pkg/dynamic_modules/test
Fixes b/452833638

Change-Id: I513a75bea76a18a3591613ecd68e7307e66a7c24
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458586
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-10-31 07:27:57 -07:00
Alexander Markov f18866b939 [dyn_modules] Do not elminate exported duplicate mixin applications
It is not safe to eliminate duplicate mixin applications if
they are exposed through dynamic interface (as dynamic modules can
reference such mixin applications or their members).

TEST=pkg/dynamic_modules/test/data/mixin_deduplication

Bug: b/449661748
Change-Id: I56b167d5a4745d03dbf3a41a0ce2e4811a0e0960
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453560
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-10-07 06:08:31 -07:00
Chloe Stefantsova ec92547b99 [model][vm] Add Target flag for Closure Contexts in AST experiment
The flag is enabled in some of the bytecode generator tests.

Part of https://github.com/dart-lang/sdk/issues/61572

TEST=existing

Change-Id: I65f491d90aad3a8d923f1a740012bad0ae8f318a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451280
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-09-25 08:02:49 -07:00
Jens Johansen 3175e427d8 [CFE] Keep const locals by default; expression evaluation can evaluate const locals
Note: Const locals are still off for VM aot and dart2js for the entry
points I've found in an attempt to retain the old behaviour there.
It might be better if those targets could remove such locals in a
whole-world analysis instead.

 * Keep const locals by default (except as noted above). Update the
   verifier to accept that. For the platforms this has increased the
   size by at most 6584 bytes. With this the VM will pass in any const
   locals as it does normal locals, but as the variable is never
   captured it will never pass a const local defined in a method when
   inside a local function in that method.
 * Change the dart scope calculation(s) to return the found variables
   instead of just the types of the found variables.
 * When the incremental compilers expression compilation - via the dart
   scope calculation - finds a const local that it wasn't told about, it
   will pass it on as an extra variable that it knows about, allowing
   for evaluating const locals in the case not covered by the first
   bullet.

With luck this can in future CLs be extended to know about other
variables that we're not told about, allowing to give a message saying
something like
"yes, we know what 'foo' is, but you can't currently use it" as wanted
in for instance https://github.com/dart-lang/sdk/issues/60316 and
https://github.com/dart-lang/sdk/issues/53996.

Tested: Existing tests for existing functionality; new tests for the new
Change-Id: I1ec24350273e6f81574bb2888f6bf46e3b8b1b47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445461
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2025-08-19 04:30:41 -07:00
Paul Berry a0f467f0e9 Rename CFE Severity enum.
The analyzer already has an enum with the same name, but a slightly
different declaration. (The analyzer's enum declares only severities
of `error`, `warning`, and `info`, whereas the CFE's enum also
declares severities of `context`, `ignored`, and `internalProblem`).

I'm currently embarking on an arc of work that I hope will eventually
culminate in unifying the analyzer and CFE diagnostic message
representations (and their severities) into a single set of
classes. Until that unification is complete, both representations will
have to co-exist in the `_fe_analyzer_shared` package. To reduce
confusion during that time period, I would like the classes to have
distinct names.

Since the analyzer's `Severity` enum is exposed through the analyzer
public API, analyzer clients may depend on the name. So it makes sense
to rename the CFE's `Severity` enum.

Tested: standard trybots
Change-Id: I95622950f49b1754267e441e4636e046045629bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442102
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-08-04 14:23:39 -07:00
Paul Berry 111e84b958 Rename CFE DiagnosticMessage class.
The analyzer already has a class with the same name, but a slightly
different purpose. (The analyzer's class represents a single message
associated with a source location, whereas the CFE's class represents
a message along with related context messages).

I'm currently embarking on an arc of work that I hope will eventually
culminate in unifying the analyzer and CFE diagnostic message
representations into a single set of classes. Until that unification
is complete, both representations will have to co-exist in the
`_fe_analyzer_shared` package. To reduce confusion during that time
period, I would like the classes to have distinct names.

Since the analyzer's `DiagnosticMessage` class is exposed through the
analyzer public API, analyzer clients may depend on the name. So it
makes sense to rename the CFE's `DiagnosticMessage` class.

Tested: standard trybots
Change-Id: I6b6948fe9da18c7b6688333fa12ffeea8e81436f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441831
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-08-04 11:20:23 -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
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
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
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
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
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
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
Daco Harkes c5b442251e [pkv/vm] Add package config to --depfile test fix
TEST=pkg/vm/test/kernel_front_end_test.dart

Change-Id: Ic359a9e1ad2caac99df8f73da9474c6757c5932f
Cq-Include-Trybots: luci.dart.try:pkg-win-release-try,pkg-win-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398660
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-12-03 23:12:56 +00:00
Daco Harkes f0f99b36dc [pkv/vm] Add package config to --depfile
Add the package config to the dep file. If the `--packages` argument
is not provided, reports the package config file used by the CFE.

TEST=pkg/vm/test/kernel_front_end_test.dart

Closes: https://github.com/dart-lang/sdk/issues/59637
Change-Id: I30d2d5d5a85b76dd87e76cffe7c2d939d99b3089
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398480
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-12-03 13:53:10 +00:00
Jens Johansen a9469269d7 [kernel] BinaryReader takes Uint8List, not List<int>
In AOT this makes reading faster:

Output from `out/ReleaseX64/dart pkg/front_end/tool/benchmarker.dart --iterations=10 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.1 --snapshot=pkg/front_end/test/kernel_binary_bench.aot.2 --arguments="--warmups=10" --arguments="--iterations=5" --arguments="AstFromBinaryEager" --arguments="out/ReleaseX64/vm_platform_strong.dill"`:

```
msec task-clock:u: -8.6925% +/- 0.5737% (-167.09 +/- 11.03)
page-faults:u: 0.1410% +/- 0.0051% (243.00 +/- 8.71)
cycles:u: -10.2918% +/- 0.6161% (-732576747.50 +/- 43853449.16)
instructions:u: -14.4988% +/- 0.0004% (-1636799813.90 +/- 39902.18)
branch-misses:u: -3.4891% +/- 2.1142% (-1166085.00 +/- 706582.35)
seconds time elapsed: -8.7005% +/- 0.5634% (-0.17 +/- 0.01)
seconds user: -9.9752% +/- 1.5104% (-0.17 +/- 0.03)
```

Stats running manually (run as e.g. `out/ReleaseX64/dart-sdk/bin/dartaotruntime pkg/front_end/test/kernel_binary_bench.aot.1 --warmups=10 --iterations=5 AstFromBinaryEager out/ReleaseX64/vm_platform_strong.dill`):

```
AstFromBinaryEagerCold: -12.5174% +/- 3.10688%
AstFromBinaryEagerWarmup: -8.33675% +/- 2.62433%
AstFromBinaryEager: -10.3432% +/- 3.68375%
```

I don't expect there to be much of a change (if any) in JIT as the actual type was in practise always Uint8List anyway.

TEST=Existing tests.

Change-Id: I86b16ed207343848dee2e376f42598c223bbc48f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393740
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-08 08:23:42 +00:00
Moritz 81daf8e563 Use package:record_use
- Rename resource identifiers in the VM to usage recordings.
- Use package:record_use for serialization.
- Rename and use the experimental flag for this feature.
- Recognize tear-offs and top-level methods as well.

Next steps:

- Add constant instance recording.
- Expose API in package:native_assets_cli's link callback.

TEST=pkg/vm/test/transformations/record_use_test.dart

Change-Id: I8af3625165f78925ae943711245af93a239d1012
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383040
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Moritz Sümmermann <mosum@google.com>
2024-09-12 08:47:53 +00:00
Alexander Markov ad94d963ed [dart2bytecode] Remove the requirement for dynamic module to have 'main'
TEST=DART_CONFIGURATION=DebugX64 out/DebugX64/dart-sdk/bin/dart pkg/dynamic_modules/test/runner/main.dart -r aot --verbose

Change-Id: I8647822982b051b4846dfe4ed7e51a19ef466cf9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384311
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-10 14:37:00 +00:00
Sigmund Cherem 25bc18c3b3 Add support for AOT in dynamic_modules tests
* Introduce steps to execute tests in AOT (using gen-kernel,
  dart2bytecode, and aot compiler)
* Accept using filesystem-scheme to provide dynamic_interfaces.yaml input
* Accept empty dynamic_interfaces.yaml
* Make temporary test changes to get them running:
   * include core types in dynamic_interfaces that we may want to have
     by default
   * rename entrypoint to `main`

Most existing test pass, the two tests that validate that a library
cannot be defined twice fail (expectation is to throw, bytecode ignores
the second definition).

To run locally:
```
./tool/build.py -m release --dart-dynamic-modules create_sdk
DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart-sdk/bin/dart pkg/dynamic_modules/test/runner/main.dart -r aot
```

Tested: CL adds additional test coverage, currently ran manually, integrated in CI in child CL
Change-Id: I4868e765855d9951bff160c18b846aa628f5e0b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383928
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-09-10 04:09:21 +00:00
Jens Johansen 11e1c32467 [CFE] Make file tracking more explicit; step towards hopefully getting rid of CompilerContext.current
TEST=Existing tests.

Change-Id: Ic403670fd0de954fe8827a54c61f7f02ab08fa85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373742
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-07-08 10:46:13 +00:00
Alexander Markov 6ab01427bd [pkg/vm] Consolidate kernel compilation options to an object
TEST=ci

Change-Id: Ic9a8801bff140b1393decde61917e8c61ab1945d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370721
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-06-10 22:56:50 +00:00
Alexander Markov 17e12879fc Dynamic interface yaml file
TEST=pkg/vm/test/transformations/dynamic_interface_annotator_test.dart

Change-Id: Ib620a98b19067c51d913b499274bfed9aaa576f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370065
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-06-10 16:09:54 +00:00
Vyacheslav Egorov 945153584c [dartdev] Add --depfile option to dart compile
I would like to add an option to our BUILD
files to precompile gen_kernel and
compile_platform to speedup iteration cycles
when working on core library changes.

To make this robust I would like to use
depfile to track dependencies and know
when compile_platform should be
recompiled.

TEST=pkg/dartdev/test/commands/compile_test.dart
R=kustermann@google.com

Change-Id: Id674f7353342c8275a8a0c4a70e3f5eaeb7f05d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367023
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-05-23 12:58:29 +00:00
Alexander Markov 9ee25d3ce1 Cleanup unsound mode from pkg/vm, frontend_server and dart2native
TEST=ci

Change-Id: Ica8b8b68f69e8f4a8cd5af3375da4a9ff0947c35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364602
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-04-29 14:18:01 +00:00
Alexander Markov 6d4817b147 Disable --no-sound-null-safety in 'dart compile', front-end server and gen_kernel
Change 'dart compile', front-end server and gen_kernel tools to reject
--no-sound-null-safety option as unsound mode is no longer supported.

TEST=ci

Change-Id: I4f6e87865bf206a27958caee4088272b4e397608
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363340
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-04-18 13:34:17 +00:00
Daco Harkes 2c952516a8 [vm/ffi] Test JIT kernel concatenation with native assets
The kernel_front_end will now allow passing in no Dart main program
when compiling a native-assets file.

The test now tests concatenating the dill files.

(A follow up CL will attempt the same for AOT dills.)

TEST=tests/ffi/native_assets/asset_relative_test.dart

Bug: https://github.com/dart-lang/sdk/issues/55377
Change-Id: Icbc6ab87d0015809f978966914064dbc6ab564a1
Cq-Include-Trybots: dart/try:vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362340
Reviewed-by: Tess Strickland <sstrickl@google.com>
2024-04-11 17:55:26 +00:00
David Morgan 56f2e00fd6 [macros] Skip macro library augmentations when considering input sources.
Add `package:front_end/src/api_prototype/macros.dart` for utilities
related to compiling macros. Export `isMacroLibraryUri`.

Use `isMacroLibraryUri` instead of hard-coding in a few places.

Add TODO about need to handle macro deps to places that are currently
listing sources as deps.

R=jakemac@google.com, johnniwinther@google.com

Change-Id: I5d2473b810afd42f487178f0aad995804da945c4
Tested: Manually tested with Flutter; e2e tests will be added under tests/macro_build.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358700
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
2024-03-21 15:54:19 +00:00
David Morgan f1f188cd96 [macros] Split out modular parts of package:vm into package:vm/modular.
The modular parts in package:vm/modular/** will only depend on

  * package:kernel

  * package:front_end
    => Only for auto-generated error code messages
    => Those error codes can be their own dart_library() in g3

Based on https://dart-review.googlesource.com/c/sdk/+/353980, with
changes:

  * Exclude package:kernel from "no exports" CFE presubmit.
  * Add package:vm/modular to CFE "allowed deps".
  * Fix import in `front_end/tool/perf_common.dart` and various others.

Tested: no code changes, only moves.
Change-Id: I9a44ac6ee05478812a9c8af31f6c4bbcf44b7c42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354221
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-02-27 13:00:17 +00:00
Tess Strickland 57a1168875 [pkg/vm] Create @pragma("vm:platform-const-if", <cond>) annotation
If a static field or getter is annotated with
@pragma("vm:platform-const-if", <cond>) and <cond> const evaluates
to true, then uses of the static field or getter are const evaluated
when a target operating system is available. If <cond> const evaluates
to any other value, then the annotation is ignored.

For example, when runtime-only code is guarded like the following,
using Flutter's kDebugMode constant, then debug mode Flutter programs
can alter the defaultTargetPlatform for testing, but in release mode,
the defaultTargetPlatform getter is const evaluated and code guarded
with defaultTargetPlatform checks can be eliminated if unreachable:

  @pragma("vm:platform-const-if", !kDebugMode)
  TargetPlatform get defaultTargetPlatform {
   ...
   assert(() {
     if (Platform.environment.containsKey('FLUTTER_TEST')) {
       result = TestPlatform.android;
     }
     return true;
   }());
   if (kDebugMode &&
       platform.debugDefaultTargetPlatformOverride != null) {
     result = platform.debugDefaultTargetPlatformOverride;
   }
   ...
  }

TEST=pkg/vm/test/transformations/vm_constant_evaluator

Change-Id: I55b88502a908c56cf42a761dd06741f15c8a23d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333220
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-01-04 14:44:29 +00:00
Tess Strickland 4bedb142d3 Reland "[pkg/vm] Handle switch statements in unreachable code eliminator."
This is a reland of commit 262311772b

When running with sound null safety, reducing a logical expression to
the right hand side if the left hand side is constant and does not short
circuit is valid, as the right hand side is guaranteed not to evaluate
to null.

In other modes, however, the right hand side may evaluate to null.
Thus, in thos modes, we return the original node if the RHS is not a
constant boolean value, so that the operator can perform whatever null
checking is required.

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

Original change's description:
> Reland "[pkg/vm] Handle switch statements in unreachable code eliminator."
>
> This is a reland of commit 92bf76d9e8
>
> In the original CL, the changes to the UCE assumed all
> SwitchStatements were exhaustive. Now if a SwitchStatement isn't
> explicitly or implicitly (via a default case) exhaustive and no case
> matches the tested constant, the SwitchStatement is properly removed.
>
> In addition, if a guaranteed to match case is found, more than one
> cases remain (thus the SwitchStatement is not removed or replaced with
> the single case's body), and the default case is removed, then the
> resulting SwitchStatement is marked as explicitly exhaustive, as this
> serves as a signal to backends that they do not need to handle the
> possibility of no case matching in the absence of a default case.
>
> Original change's description:
> > [pkg/vm] Handle switch statements in unreachable code eliminator.
> >
> > Namely, if the tested expression for a switch statement is constant,
> > then we can remove any constant cases where the constants differ,
> > and if all but a single case is removed, we can replace the switch
> > with the case body.
> >
> > If constant functions are not enabled, then getters annotated with
> > @pragma("vm:platform-const") are still evaluated with the constant
> > function evaluation machinery, but only those and no others (including
> > any functions called within an annotated getter). This way, functions
> > can be annotated with @pragma("vm:platform-const") without having to
> > rewrite them to be a single returned expression.
> >
> > TEST=pkg/vm/test/transformations/unreachable_code_elimination
> >      pkg/vm/test/transformations/vm_constant_evaluator
> >
> > Issue: https://github.com/dart-lang/sdk/issues/50473
> > Issue: https://github.com/dart-lang/sdk/issues/31969
> > Change-Id: Ie290d2f1f469326238d66c3d9631f8e696685ff0
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332760
> > Commit-Queue: Tess Strickland <sstrickl@google.com>
> > Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
> > Reviewed-by: Alexander Markov <alexmarkov@google.com>
>
> TEST=pkg/vm/test/transformations/unreachable_code_elimination
>      pkg/vm/test/transformations/vm_constant_evaluator
>
> Issue: https://github.com/dart-lang/sdk/issues/50473
> Issue: https://github.com/dart-lang/sdk/issues/31969
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try
> Change-Id: I557ca933808012e670e306f2d880221a0d7dd670
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334224
> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

TEST=pkg/vm/test/transformations/unreachable_code_elimination
     pkg/vm/test/transformations/vm_constant_evaluator

Change-Id: Ia51b7c5f3b51f57a6a306551fe74b47e0cba3c23
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335828
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-11-21 18:07:30 +00:00
Moritz a3568286ff Adding the resource-identifier functionality from the compiler to the
vm.

This identifies all calls to static methods annotated with
`@ResourceIdentifier`, collects the constant arguments passed to the
method, and writes the results into a file.

The purpose of this feature is to be able to pass the recorded
information to packages in a post-compilation step, allowing them to
remove or modify assets based on the actual usage in the code prior to
bundling in the final application.

Tested: pkg/vm/test/transformations/resource_identifier_test.dart
Change-Id: I58cb313b66ee23c1d154dcc242547723a1ced359
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329961
Commit-Queue: Moritz Sümmermann <mosum@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2023-11-21 15:05:35 +00:00
Alexander Markov b15e1bf19d [vm] Rename nullSafety to soundNullSafety in pkg/vm
Also:
* Clean up obsolete code for returning null safety from kernel
service.
* Enable sound null safety in TFA unit tests.

TEST=ci

Change-Id: I1e008ed661823e9cb8004670d6b66bef35089a19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334081
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-11-07 14:32:20 +00:00
Devon Carew e2fe203adc [deps] roll package:lints to the latest
Change-Id: I582f956cd4b712203c2f6dd630b4e1384040446d
Tested: analysis clean (this is a lint only related change)
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329400
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2023-10-05 03:36:59 +00:00
Ryan Macnak 4038b4f9df [frontend_server] Forward --keep-class-names-implementing.
Cf. 708f098c4f

TEST=ci
Change-Id: I65b51d5aa93eeb0e41ee276b4288dd231d6dbc87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323424
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-08-31 22:27:45 +00:00
Ryan Macnak 708f098c4f [vm, compiler] Add option to suppress obfuscation of type names for some hierarchy.
This behaves like applying @pragma("vm:keep-name") to the hiearchy.

TEST=ci
Bug: b/285175418
Change-Id: Ibd543d294bebbfbb60f4e5d62d5e83f3aec841e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322582
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-08-25 18:55:32 +00:00
Jens Johansen 9f9da91b84 [kernel] Facilitate faster sorting of additional exports
The "additionalExports" are sorted in production code to give stable
output.
Before this CL it did `toString()` on the canonical names which is
O(n^2) because of continued string concatenation.
This CL changes it to sort on the name, going to the parent if it's the
same. This _does_ change the sorting, but should still be stable.

When compiling via the flutter frontend try bot the time spent on
sorting does from ~45 seconds to ~9 seconds (arguable still a lot, but
much better).

This will also speed up flutter testing because it will spend less time
waiting for the frontend.

TEST=Assuming existing tests.

Change-Id: If350b7c2ce49f00b2924732a7fa7eb51c38c8172
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322280
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-08-24 13:21:38 +00:00
Daco Harkes 40787d84fc [frontend_server] Add support for @Native assets
The VM can read native asset mappings from kernel.

Previous CLs already added support to embed native asset mappings for
one-shot compilation.
This CL adds support for adding native assets mappings to kernel files
created by the frontend_server with the incremental compiler.

The frontend_server accepts a `--native-assets=<uri>` at startup and
accepts a `native-assets <uri>` message on stdin as compilation
command.

The frontend_server caches the compiled native assets library.

When a `reset` command is sent to request a full dill from the
incremental compiler, the native assets mapping is taken from the
cache and added to the final dill file.

Split of DartSDK & flutter_tools prototype to land separately.

TEST=pkg/frontend_server/test/native_assets_test.dart

Bug: https://github.com/dart-lang/sdk/issues/49803
Bug: https://github.com/dart-lang/sdk/issues/50565
Change-Id: I6e15f177564b8a962e81261815e951e7c9525513
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/+/282101
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-02-21 07:29:29 +00:00
Tess Strickland 2c0484c720 [pkg/vm] Initial work on constant operating system fields and getters.
* Add an `targetOS` argument to `pkg/vm`'s `compileToKernel`,
  that contains the target operating system's name.

* Add a new `--target-os` command line argument for all binaries
  that use `compileToKernel` for clients to provide the target
  operating system, if known.

* Add a new`"vm:platform:const"` annotation to certain field and
  getters in the Platform class.

  This annotation is used to annotate static getters and fields with
  initializers where the getter body or field initializer must evaluate
  to a constant value if the target operating system is known. This
  annotation may be used outside the Platform class and in user code.

  For example, this annotation can be used on a static `String` field
  that is initialized with one value if `Platform.isWindows` is true
  and to a different value if `Platform.isWindows` is false.

  Note: If the const functions experimental flag is disabled, then
  any annotated static methods can only contain a single expression
  whose value is returned. If it is enabled, then the static method
  is evaluated as if it is a const function with the special
  handling of annotated static fields and getters above.

* Create a VM constant evaluator that evaluates uses of static getters
  and fields marked with the above annotations when a target operating
  system is provided.

* Use the new VM constant evaluator in the unreachable code elimination
  transformer.

TEST=pkg/vm/test/transformations/platform_use_transformer
     pkg/vm/test/transformations/unreachable_code_elimination

Change-Id: Ie381de70486a767fd7b1d515fd9e6bb58c6bf090
Bug: https://github.com/dart-lang/sdk/issues/31969
Cq-Include-Trybots: luci.dart.try:pkg-linux-release-try
CoreLibraryReviewExempt: Just adding vm-specific annotations.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274386
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-02-10 16:29:50 +00:00
Alexander Markov a9d9b7395b [kernel] Enable sound null safety in TargetFlags by default
TargetFlags.enableNullSafety is set to true by default and
also renamed to TargetFlags.soundNullSafety to better reflect its
meaning.

TEST=ci

Change-Id: I2c2f30c2af6502fd9a96141dc60e4afbf8c524fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280216
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-02-02 14:54:18 +00:00
Josh Soref 77978889eb Spelling
Closes https://github.com/dart-lang/sdk/pull/51143

GitOrigin-RevId: 9e21c99a222d588e4fc95980725a2f8c9784965c
Change-Id: If0870e8936c7649935dce7e23cd783d62aa5610c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279916
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-30 18:29:59 +00:00
Daco Harkes 9a8508ebff [vm/ffi] FfiNative assets
Adds support for `asset: 'asset-id'` in `FfiNative`s.
Symbols in assets are resolved by
1. the provided [asset] (the bulk of this CL),
2. the native resolver set with `Dart_SetFfiNativeResolver` in
   `dart_api.h` (old behavior), and
3. the current process.

Symbols in assets are resolved by the Dart VM through the mapping
provided in the `vm:ffi:native_assets` library:
```
@pragma('vm:ffi:native-assets', {
  "linux_x64": {
    "<asset1>": [
      "absolute",
      "<absolute-path>"
    ],
    "<asset2>": [
      "relative",
      "<relative-path>"
    ],
    "<asset3>": [
      "system",
      "<system-path>"
    ],
    "<asset4>": [
      "process",
    ],
    "<asset5>": [
      "executable",
    ],
  }
})
library;
```

There are 5 asset path types. Symbols resolved in these asset types are
resolved as follows.
A. Absolute paths are dlopened, after which the symbol is looked up.
B. Relative paths are resolved relative to `Platform.script.uri`, and
   dlopened, after which the symbol is looked up.
C. System paths are treated as absolute paths. (But we might explicitly
   try to use `PATH` in the future.)
D. Symbols looked up in Process assets are looked up in the current
   process.
E. Symbols looked up in Executable assets are looked up in the current
   executable.

The native assets mapping can be provided in three ways.

X. In the invocation to `gen_kernel` with the `--native-assets`
   argument. This uses the gen_kernel entry point for compiling
   kernel.
Y. By placing a `native_assets.yaml` next to the
   `package_config.json` used by the isolate group. This works for
   `dart <source file>` and `Isolate.spawnUri(<dart source file>)`.
   This uses the kernel_service entry point for compiling kernel.
Z. By sending a String containing the native assets mapping when
   invoking the kernel_service directly from within the VM. Currently,
   only used for unit tests.

TEST=tests/ffi/native_assets/asset_*_test.dart (X)
TEST=tests/ffi/native_assets/infer_native_assets_yaml_*.dart (Y)
TEST=runtime/vm/ffi/native_assets_test.cc (Z)

The library is synthesized from yaml in pkg:vm as AST.

Design doc: go/dart-native-assets

Bug: https://github.com/dart-lang/sdk/issues/49803
Change-Id: I8bf7000bfcc03b362948efd3baf168838948e6b9
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-mac-debug-arm64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-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-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-precomp-nnbd-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264842
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-01-18 21:08:38 +00:00