Commit Graph

2517 Commits

Author SHA1 Message Date
Jonas Finnemann Jensen bc8929e7c6 Skip Version: ${Platform.version} comment when dart:io is unavailable
In an ideal world, we'd have access to the version of the current Dart SDK,
but other means when compiling for web. But at the moment we don't.

It should probably just be in the _compilation environment_ as suggested in
https://dartbug.com/54785

But until such time, I suggest we just opt to not include the version comment,
when `dart:io` is unavailable.

We could also go through all of dev_compiler and wrap all references to `Platform`
from `dart:io`. But I need this to make a clientside dartpad work. And I think
this is sufficient (if not I'll come back asking for more).

In an ideal world, we would also add tests to ensure that `Platform` isn't used.
But in the future, I plan to build and test the dartpad compilation environment
inside the sdk repository, thus, new usage of `Platform` will then break those tests.

Change-Id: I952c1794c43169c12f3e8099ad0773e5e59c6206
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481560
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Jonas Jensen <jonasfj@google.com>
2026-02-19 11:16:40 -08:00
FMorschel aeadcbbca8 [linter, DAS] Makes use_null_aware_elements to report on cascade elements
Fixes: https://github.com/dart-lang/sdk/issues/62660
Change-Id: I8daee991353cae128ea84cf8d71ee430a884f550
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480560
Reviewed-by: Nate Biggs <natebiggs@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2026-02-16 23:32:59 -08:00
Nicholas Shahan e7d8b99bb6 [ddc] Use LibraryBundleCompiler in expression eval
When the canary and ddc modules flags are passed together use the
expression compiler worker uses the LibraryBundleCompiler to compile
the expression to be evaluated. This ensures the compiler JavaScript
matches the expected format and representation of the compiled library.

Change-Id: I4667522a6640707265a3f38770a17fd696c840f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/479400
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2026-02-10 16:58:36 -08:00
Nicholas Shahan 5fd3ccd4d0 [ddc] Fix sourcemap for field initializers
New source locations were added for field initializers to support
upcoming primary constructor work.
See: https://dart-review.googlesource.com/c/sdk/+/468780

This change ensures the initializer assignment statements we add to
the constructor body are fully mapped.

Without this change the new initializer assignment wasn't getting a
mapping so it continued from whatever appeared before it.

Change-Id: Id6ba0619e49e4a517ea36ffa728cf0c1502a14e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469300
Auto-Submit: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-12-21 15:08:42 -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
Ben Konyi df3e4046b4 [ SDK ] Add js_dev_runtime stubs for dart:ffi
This will allow for developer tooling to still compile applications with
`dart:ffi` imports for web targets.

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

CoreLibraryReviewExempt: Not changing implementations, just adding stubs
Change-Id: I7347dc81c8bffe0becaf4b1d002d6aca2de60244
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464960
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-12-17 09:26:12 -08:00
Slava Egorov b3857af0e5 Bump core to 58b0a108b4d1310465e8482d6629357891df1cb1
Changes:
```
> git log --format="%C(auto) %h %s" 5c3e2c3..58b0a10
 https://dart.googlesource.com/core.git/+/58b0a108 Make it possible to add default subcommand (925)
 https://dart.googlesource.com/core.git/+/e43ff949 feat(collection): Replace quickSort with pdqsort for performance and robustness (922)
 https://dart.googlesource.com/core.git/+/f2efaaf3 Bump actions/checkout from 5.0.0 to 6.0.0 in the github-actions group (924)
 https://dart.googlesource.com/core.git/+/33b52327 Add `separated`, `separatedList` and `separate` to iterables and lists. (919)
 https://dart.googlesource.com/core.git/+/20ed9668 Add use_null_aware_elements to recommended (923)
 https://dart.googlesource.com/core.git/+/e6c3810c [crypto] remove the -wip to release new version (921)
 https://dart.googlesource.com/core.git/+/f7a786ac Bump actions/stale from 10.0.0 to 10.1.0 in the github-actions group (920)
 https://dart.googlesource.com/core.git/+/018e1dc7 fix(crypto): update conditional import for js interop library (915)
 https://dart.googlesource.com/core.git/+/9fefb52b Make Int64 default constructor non-const in native mode (916)
 https://dart.googlesource.com/core.git/+/f00841de Bump the github-actions group with 2 updates (914)
 https://dart.googlesource.com/core.git/+/7fee9c06 Fix `Int64.operator ==` (911)
 https://dart.googlesource.com/core.git/+/a4dc8738 Implement `Int64` as a wrapper for `int` when targeting native and Wasm (905)
 https://dart.googlesource.com/core.git/+/1aa58ef5 [fixnum] update the min. required dart sdk (907)
 https://dart.googlesource.com/core.git/+/60f2b5d3 Run fixnum tests with dart2wasm (906)

```
Diff: https://dart.googlesource.com/core.git/+/5c3e2c38df268be2347f3aad30ced0147dd012bb..58b0a108b4d1310465e8482d6629357891df1cb1/

Change-Id: Ibde49f27d1d26b8fc1aad3fd7df3efd924796b33
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467361
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-12-12 00:42:31 -08:00
Nicholas Shahan a49b6c3cc0 [ddc] Add size metrics to library bundle output
Embeds the size of the original Dart source files and the output
JavaScript files into an argument of the `defineLibrary()` method.

Following changes will add the usages of these values to the embedder.

Change-Id: Ibbfaa9f559248f391df6a733a0f8621f3e9edd83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467420
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-12-10 14:42:52 -08:00
Nicholas Shahan bc3a70cdc8 [ddc] Format and cleanup comments in the embedder
* Preparation for merging this file with the internal version.
* Fixes lint violations and consistency issues in the docs and formatting.

Change-Id: Ib563a3bb834509de819895ea99483fab7d0e4bb1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465485
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-12-02 10:53:30 -08:00
Johnni Winther 2352407600 [kernel] Remove unused Target.instantiateNoSuchMethodError
TEST=existing

Change-Id: I38c4f97116f36c4cae079439367afc746415205c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464683
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-11-27 01:56:08 -08:00
Nicholas Shahan c2c5357a25 [front_end] Add option for expanded invalidation
In this mode when an edit only touches the body of a mixin
(not the public API) libraries that apply the mixin will also
be invalidated.

Add mixin invalidation test.

Issue: https://github.com/dart-lang/sdk/issues/61864
Change-Id: Id4dde67364dcef958ae1e0e0bbf124cec389f5f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459343
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-11-14 08:53:51 -08:00
Johnni Winther baf4639de7 [kernel] Add *InternalNodeMixin visitor mixins
This adds mixins for visitors that implement handling of internal nodes. These nodes are replaced during constant evaluation and should there not be handle by backends.

TEST=existing

Change-Id: Iec76af357c11fd54e97a4db82c7aa52e31ba9dd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456680
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-10-27 15:02:28 -07:00
Nicholas Shahan 1c0c66f680 [ddc] Remove lib/ directories from source maps
Given the existing assumptions that original source files will be
served in a directory structure similar to layout defined by the
package_config.json but without `lib/` directories this change
attempts to detect when a source map contains sources from multiple
lib directories and clean them up from the relative paths.

The strategy used relies on passing a package_config.json as a signal
to detect when sources come from different packages.

Fixes: https://github.com/dart-lang/webdev/issues/1692
Issue: https://github.com/dart-lang/sdk/issues/40251

Change-Id: I6b82b33bae485d74fc61ef118dbe9ffddafab9a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456500
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-10-22 17:04:33 -07:00
Chloe Stefantsova a478a4418c [cfe] Add experimental visitor mixins and experimental type
This CL reduces the noise of future CFE experiments in the
backends. Whenever new nodes will be added as an experiment, the
related exception-throwing implementations will be added to the
mixins, eliminating the need to add the visit methods to the backend
code directly. The experimental type addresses a similar issue in
exhaustive switch statements and expressions.

TEST=existing

Change-Id: I1a021e11a159a992500c42287cbe6ef027bf54a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455080
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-10-17 02:16:25 -07:00
Mayank Patke 5c2fec9eac [ddc] Add line terminators to .map, .metadata, and .symbols
Standard utilities like `cat` expect files to be newline-terminated, so
this change lets these files play nicely in build rules, for example.

Change-Id: I6a6a6964b32dce7d2d73a402fa4eb2842b296621
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454540
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2025-10-13 19:17:50 -07:00
Nicholas Shahan cff9ab2c8e [ddc] Add hot reload checks in aysnc bodies
Treats async code like function expressions when adding extra
checks for correctness after a hot reload. This is intended to handle
the cases where code that was statically sound and enqueued before the
reload actually runs after a reload when the soundness may no longer
be valid.

Change-Id: I42cd010175126748937d7df830875bc5b850a565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444368
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-09-30 15:06:34 -07:00
Nicholas Shahan 3f2801d63f [ddc] Avoid revisiting sub-expressions on chained invocations
Similar to https://dart-review.googlesource.com/c/sdk/+/445540 this
avoids compilation timeouts by avoiding recompiling the receiver in long
chains of invocations.

Guards all of the soundness checking behind a single generation check.
This was already true for nested calls but not for chains of invocations.

This also resolves a correctness issue where sub expressions of the
receiver in chained calls would be evaluated multiple times at runtime.

Change-Id: Iaf192a639e90d77995da55c7fa9c248e7bb93491
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450183
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-09-22 14:25:22 -07:00
Nicholas Shahan 9ed1efe74a [ddc] Use typed ArgResults helper methods
Change-Id: I906c3cc5d9b80b5d6818cf0af779cc2de56d4db7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449364
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-09-12 16:30:39 -07:00
Jens Johansen e9a99cd479 [DDC] Expression evaluation: Translate script uri if it is a package uri
Turns out we'll sometimes be given the script uri as a package uri,
so we have to support that.
To further complicate things we're not necessarily given a package
config to translate from so we need to use the kernel component as a
backup.

Change-Id: I06ceb136b0b03164aaf7412d5332ae9c4c3338c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447220
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-08-28 01:32:40 -07:00
Simon Binder afa127b1c6 Support renaming fields for JS object literals
This respects the `@JS()` annotation on parameters of external
factories in JS extension types to customize the keys of created object
literals.

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

Change-Id: Idebeee922d2080356fd7449f639ecd2ae9ee5fc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445840
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-08-26 13:17:30 -07:00
Jens Johansen abfa152cfc [kernel/DDC] DDC shouldn't crash when trying to translate line/column to offset for expresion compilation
Follow-up to https://dart-review.googlesource.com/c/sdk/+/446042.

Change-Id: Icfbaa763a6d6089a74f62088602c07c478520741
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446420
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-08-24 23:50:07 -07:00
Nate Biggs e6f188b3fa [ddc] Avoid revisiting subexpressions during hot reload invocation rewriting.
In extreme cases with deeply nested invocations in closures, this can lead to an exponential recursive call pattern.

For example: https://github.com/spebbe/dartz/blob/8bf79e746d11e6a66c868027e5e1a25fdd270f45/lib/src/either.dart#L108

Moves all nested checks onto a single branch so that there is a single branch with no checks when the generation is the same, and another branch with all the necessary checks when the generation is different.

Bug: https://github.com/flutter/flutter/issues/173700
Change-Id: I3167a96e3ead67fd1d5c763ef2a7309d82c1a7c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445540
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-08-22 20:48:35 -07:00
Jens Johansen a79b7c6c35 [kernel/CFE/DDC] Remove old DartScopeBuilder; use new one
Change-Id: I4805c47958e2d4fbc19acbdada23cad014c3a747
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446042
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2025-08-21 23:14:41 -07:00
Srujan Gaddam 3b39c2637b [ddc] Separate _emitObjectLiteral out from _emitArgumentList
Currently _emitArgumentList handles arguments for Dart
members, JS interop members, and object literal constructors.
It requires an Arguments node, which we end up synthesizing,
which messes with parent pointers erroneously. We also have
to separate out the arguments and do additional checks later
to detect whether the arguments passed correspond to an
object literal constructor.

Instead, we should create the resulting expression directly
in a helper method. A map is passed so that the names of
arguments can be easily changed when we handle @JS renaming
on object literal constructors. Lastly, we need to avoid
wrapping the values with assertInterop in the case where the
constructor is from a dart:js_interop interface. That library
only statically allows Functions to be passed if they're
externalized, in which case we shouldn't tell users to wrap
the Function with allowInterop (which doesn't exist anyways in
dart:js_interop).

Change-Id: If6fdc706e80837ab2b698cca704ffd9f08aed28a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446184
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-08-21 15:25:57 -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
Paul Berry 7ac80be476 [front end] Remove type argument from class Code.
This type argument was never used. Removing it should make it easier
to make changes to the front end error message logic (and associated
code generator), which I intend to do as part of a long term plan to
make the analyzer and front end error reporting systems more
consistent, and eventually merge them.

Change-Id: I994cd2a74c5fd77df192f6a1f2dde46ba8a31883
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442723
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-07-30 12:38:27 -07:00
Nicholas Shahan eb4619d139 [ddc] Add hot reload checks for instance methods
Handles errors and type changes on a hot reload when call sites
that were statically valid are retained and run after the reload.

Change-Id: I8bebbd7bc7acc97f55ff930e8f456f99146fbf21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440082
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-07-28 16:16:06 -07:00
Nicholas Shahan 41ff6c38a6 [ddc] Refactor visitInstanceInvocation
This is in preparation to handle extra hot reload checks various
instance method invocations.

Change-Id: I9aaa9a29ec76c44466ce4b384a42ca980e7d8ca6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440081
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2025-07-28 16:16:06 -07:00
Nicholas Shahan b9d83b91d7 [ddc] Share some helpers methods
Moves helpers from local functions and instance methods in the compiler
to static extensions on kernel nodes. These can be shared between the
old and new compilers.

Change-Id: Ifc2b5fe8945753823d7671171673c6c7add1e8cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439806
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-07-28 16:16:06 -07:00
Nicholas Shahan 14bb2be360 [ddc] Optimize building type environments at runtime
* Avoids retrieving the instance type in more cases. In static class
  methods (including constructor tear offs)
  `dart_rti.instanceType(this)` was being used as the base of the
  environment binding. In these cases the result was the reified type
  of the JavaScript function. This worked as long as the base type of
  the binding is ignored, but it was not intuitive and had to fall
  through all the other cases before settling on that result.

* Avoids parsing a recipe for the `dynamic` every time when we already
  can have it available in our type table.

Compiled code examples:
Building the type `A<R, S>` from function type parameters `R` and `S`:

Now:
  `T.dynamic()[_bind](R)[_bind](S)[_eval]("A<1,2>")`
Previously:
  `dart_rti.instanceType(this)[_bind](R)[_bind](S)[_eval]("A<1,2>")`

Building the type `B<R>` from function type parameters `R`:

Now:
  `R[_eval]("B<0>")`
Previously:
  `dart_rti.instanceType(this)[_bind](R)[_eval]("B<N+1>")`
   where N is the number of type arguments of the enclosing class.

``
Change-Id: I213666edd7c6427f0d42d958541e53a798e8877c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439460
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-07-10 13:08:45 -07:00
Chloe Stefantsova 433c0998d0 [cfe] Remove Nullability.legacy
TEST=existing

Change-Id: Id924e4ef64ddabc1986cb885f558382ff139b481
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436620
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-07-02 23:50:12 -07:00
Nicholas Shahan 113df82c9f [ddc] Add validation to instance setter calls
Ensures soundness for instance setter calls after a hot reload.

Issue: https://github.com/dart-lang/sdk/issues/60100
Issue: https://github.com/dart-lang/sdk/issues/60112
Change-Id: Ie6736d002752076e5526bd37ae9f103040ed8cdd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437124
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-06-30 17:46:09 -07:00
Nicholas Shahan 884a48c988 [ddc] Delete macro options and cli arguments
Change-Id: I83bd63f707758e82ac23a80b7442d57746f6b125
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436941
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-06-25 15:21:55 -07:00
MarkZ 3d22f36b74 [ddc] Fixing cross module private name symbols redefining each other when used as function default values.
Fixes #60968

Change-Id: I0686da16b182f8a42e5fa0b55ced918671bdedca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436001
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-06-20 14:40:47 -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
Nate Biggs 31dc969da2 [ddc] Test DartPad-like hot reload workflow.
Refactors the hot reload test suite to support non-FE server based hot reload. Similar to DartPad it uses a DDC process running in '--persistent_worker' mode and sends bazel requests for each reload.

I call this "stateless" mode because the compilation process itself is not maintaining any state. The necessary metadata is passed from one compilation to the other via a delta dill. This differs from the "stateful" mode where the FE server persists a kernel AST in memory from one compilation to the next.

Disregarding the browsers there are effectively 3 run modes now:
- web stateful
- web stateless (new)
- vm stateful

One key difference between the "stateless" and "stateful" modes is the output format of the JS files. In stateful mode DDC emits a file per library being re-compiled. In stateless mode DDC is emitting a single file with all the libraries.

DartPad's workflow is slightly simpler than what's seen in the stateless mode here. It only supports editing a single library so we skip processing any metadata. To simulate this I've added the special 'main_only' which passes a single library for each reload generation. I've verified that this would fail if not for the change recently made to ddc_module_loader.js.

Change-Id: If05da6dbeded4dd20e9e6d9dfaed52151541a19b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434340
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-06-12 17:18:30 -07:00
MarkZ 40bf581c79 [ddc] Adding extraDdcOptions forwarder to frontend server.
Change-Id: Ie2ee13b6089f4f24957e9865d6c2fd7296ed7c30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433261
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-06-12 14:43:52 -07:00
Nicholas Shahan 9cdc4a1963 [ddc] Reformat pkg/dev_compiler
Something seems wrong with the previous formatting. This change formats
with language version 3.8 again.

Change-Id: I077d635d815fa82ddf1153122ee3082787e1dd73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433301
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2025-06-06 09:14:23 -07:00
MarkZ bbc99947c9 [ddc] Rolling internal dart_library.js into the external module loader.
Change-Id: If25fd9ac78d795d16b7edca507df0b806a0ebf39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433262
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-06-06 07:20:10 -07:00
Nicholas Shahan 60d418034a [ddc] Bump language version to 3.8
* Reformat pkg/dev_compiler.
* Re-flow some comments to keep them within 80 characters.

Change-Id: I0849ce113ecf3dce4a2b4405c2b09a17dee4df76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433081
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-06-05 10:40:57 -07:00
Nicholas Shahan 6697075645 [ddc] Fix spelling typos
Change-Id: Iafcf14be1fd3032381b4ced2610230538100ce52
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433080
Reviewed-by: Mark Zhou <markzipan@google.com>
2025-06-05 10:40:57 -07:00
Nate Biggs f7068a415e [ddc] Relax conditions on allowed defineLibrary calls during hot reload.
The current conditions make it so that every library transitively reachable from a reload target (and therefore included in the DDC output) must be known in the client when `dartDevEmbedder.hotReload` is called.

While this is the case for pages running with DWDS, it's an unnecessary constraint. Some users may only care about reloading a specific subset of known libraries. As is the case in dart-pad when we only need to reload the main library as we know this is the only code that can have changed.

Any new libraries must also registered and initialized as this is new code not yet in the page. This would happen if a new import was added to the code.

Change-Id: I164f59a6931fd809867716c164cb467880806f8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432440
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-06-03 12:02:03 -07:00
Nicholas Shahan 44e0d326a7 [ddc] Fix expression evaluation with wildcards
When wildcard method arguments should be removed from the scope before
attempting to evaluate an expression. Otherwise their names are invalid
and cause a Dart compile time error.

Add tests for all forms of wildcards in expression evaluation.

Change-Id: I21a7676a1495383926552a1039789f7d29256a67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431951
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-06-02 16:09:51 -07:00
Nicholas Shahan 1806e4ce65 [ddc] Use direct cast methods for primitive casts
The `_as` methods for primitive types are designed to be called from
both the `_as` selector and directly from generated code.

For the primitive types that are known at compile time and cannot change
via linking or hot reload, we can generate direct calls.

Adapted from https://dart-review.googlesource.com/c/sdk/+/420380

In addition to the base change:
* Remove `int` cast helpers from DDC only code in favor of the
  versions from dart:_rti.
* Moves existing optimizations from `visitAsExpression` to `_emitCast`
  to apply them consistently.

Change-Id: I13d24e3756400f2358556812728db17bc73f544a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427040
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2025-05-28 10:07:26 -07:00
MarkZ b4ac0a183b Adding support for non-hot-reloadable packages in DDC.
These packages can be specified with the `non-hot-reloadable-package` flag and will be compiled without their members being properly hot reloadable. In exchange, we can perform additional optimizations (such as avoiding levels of indirection/checks in anticipation of their being updated).

This additionally overhauls our memory compiler to use the incremental compiler for proper state-passing hot reload testing + adds tests for this functionality.

Change-Id: Ief65896410f32655f064bd15728703629faa4051
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428343
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-05-23 17:37:20 -07:00
Nicholas Shahan f4c87f2ae8 [ddc] Add hot reload checks to instance getter accesses
Checks the compile and current hot reload generations. If they are not
equal the value is checked to have a getter of the expected name and
if so it gets called. If not, `.noSuchMethod` is invoked instead.

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

Change-Id: Ib80582b45f87f2ab41b943e0f263167b38601e0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429066
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-05-22 13:27:31 -07:00