Commit Graph

2072 Commits

Author SHA1 Message Date
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
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
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
Nate Biggs e688981385 [ddc] Fix capture issue with temp names within async scopes.
`needsCapture` will ensure that any variables used within an async scope get included in the 'asyncScope' object that's created for that scope.

The variables used to lower Dart late variables in particular get emitted separately. But they can still be used across async scopes so they need the special capture logic as well.

Bug: https://github.com/dart-lang/sdk/issues/60748
Change-Id: I2486fce41f88f186fd799029c2cc59635f7ad8f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429780
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-05-21 17:49:22 -07:00
Nicholas Shahan 626b91344f [ddc] Delete _emitPropertySet
Move the specific implementation paths into `visitDynamicSet` and
`visitInstanceSet`.

Change-Id: I392f27c76c4f05df3dcfb7ed35ab9c390388f92e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429581
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-05-20 09:44:29 -07:00
Nate Biggs 0ccd9637bb [ddc] Add caching of ground type RTI objects in a module-local type table.
Change-Id: Ifcc8f5da277207bbb228ef30ca47d1ec42a67eb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429180
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-05-19 20:34:40 -07:00
Nate Biggs b528c3fd60 [ddc] Inline code generated type universe lookups.
Change-Id: I6b0e3b8efee3318fffd200ae1a789565926948f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429065
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-05-19 11:13:38 -07:00
Nate Biggs 1326d75d58 [ddc] Add logic to expression compiler to look up variables in async scopes when available.
Bug: https://github.com/flutter/flutter/issues/168641
Change-Id: I1dec222ad8bedcec63656c3d3340d632591b65b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428720
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-05-15 13:50:20 -07:00
Nicholas Shahan a2f785c3b7 [ddc] Update source mapping for static invocations
when they have been rewritten to include hot reload checks. Appears to
fix the issue detected in the dwds test failure.

Issue: https://github.com/dart-lang/webdev/issues/2617.

The new mapping ensures breakpoints applied to the call site in the Dart
source are the call site instead of the the generation check.

Allows the tooling to set a breakpoint on the static method call site,
and then when paused, a step-into will action will advance the program
into the static method.

In the future we will need to reevaluate how we generate code where a
single branch of execution in Dart source produces multiple branches in
JavaScript. I believe right now the tooling will not support creating
breakpoints in both branches even when they both have a mapping to the
same Dart source location.

Change-Id: I1ea0548768d8213dc7eefc332814d3bda7c81535
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427567
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-05-13 13:46:14 -07:00
Nicholas Shahan 2ddf0c64f6 [ddc] Use prototype trick for better chrome performance
After emitting a library, creates a dummy function for each library and
sets the library object as the `.prototype` of the dummy function.

Reverses the performance degradation seen after adding one too many
members to the `dart:_runtime` library in:
https://golem.corp.goog/PerformanceChanges?repository=dart&revision=116131

According to sra@ this serves as a signal to V8 that the members of the
library should get optimized for fast lookup. These golem runs show
performance improvements that support this.

dartdevc performance improvements:
https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddartdevc%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D116273%3BpatchA%3Dnshahan--ddc--WIP-library-as-prototype-optimization-1%3BtargetB%3Ddartdevc%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D116238%3BpatchB%3DNone

dartdevc-canary performance improvements:
https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddartdevc-canary%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D116273%3BpatchA%3Dnshahan--ddc--WIP-library-as-prototype-optimization-1%3BtargetB%3Ddartdevc-canary%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D116238%3BpatchB%3DNone

Change-Id: Ifee464e393609c30eff4ea7c19da511134eccdcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427822
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-05-12 16:41:38 -07:00
Nicholas Shahan b03f3b7b8d [ddc] Reland refactor visitInstanceGetterInvocation()
Moves the remaining special case logic out of `_emitMethodCall()`
simplifying the reasoning about where so hot reload soundness checks
can be added.

The original change exposed a latent soundness bug that allowed for
some dynamic getter invocations to be performed without runtime checks.

This reland adds adds a note about the newly enforced runtime checks to
the CHANGELOG.

Change-Id: I387438b8615e60f73dfc5e3b883b8c6d5a9993da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425942
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-05-02 16:57:28 -07:00
MarkZ 028914a3ef [ddc] Emitting embedder link functions via symbol property.
Fixes errors when top level 'link' members exist.

Change-Id: I0a339298ff9f51f6cd1f6af7c983eeda4a013956
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426002
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-05-02 15:00:17 -07:00
Nicholas Shahan 6127d6cb8f [ddc] Add checks to static invocations in closures
Previously, code in a closure was compiled with the assumption that
invocations known to be statically sound didn't need any runtime checks
to guaranty soundness.

Now, if the code is retained from an earlier compile and executed after
a hot reload, any assumptions regarding soundness may be invalid.

This change transforms what was an invocation expression into a larger
expression that performs additional checks (similar to a dynamic call).

All checks are skipped if the compile generation matches the current hot
reload generation at runtime.

The soundness checks are handled by a new runtime helper method
`hotReloadCorrectnessChecks`. Any argument expressions are hoisted into
let variables to preserve their evaluation order and to ensure they are
only evaluated once. The helper checks for the existence of the
invocation target, the shape of the method signature, and runtime type
of the passed arguments. Mismatches result in an invocation of
`NoSuchMethod`. Any returned value is cast to the expected static type
of the original invocation.

Change-Id: If925f1a9b475d5ac581b2526403ab7c95753ffef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421640
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-05-02 12:52:05 -07:00
Srujan Gaddam 8ac1fbdd07 [ddc] Emit call to register source maps in DDC library bundle format
- Sets the name field in the emitted LibraryBundle node to
to the provided module name. We tried to avoid providing a
module name as the notion doesn't map cleanly to library
bundles, but we need to respect the provided module name.
- Emits a call to set the source map for a given library
bundle url. We don't need the full trackLibraries call so we
don't use it.
- Adds a check to avoid redefining libraries outside of a hot
reload or a hot restart. This was handled in the same code
where we emitted trackLibraries calls in the old compiler
for dynamic modules, but we want this for all code, regardless
of whether dynamic modules is enabled. So, add this check in
the library manager instead.

Change-Id: Ic4e86dbfca2b3eefa99cce44fae0973164ab77a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423620
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-04-29 17:11:45 -07:00
Nicholas Shahan c31a282435 Revert "[ddc] Refactor visitInstanceGetterInvocation()"
This reverts commit 776c0586aa.

Reason for revert: Broke test in google3

Original change's description:
> [ddc] Refactor `visitInstanceGetterInvocation()`
>
> Moves the remaining special case logic out of `_emitMethodCall()`
> simplifying the reasoning about where so hot reload soundness checks
> can be added.
>
> Change-Id: I13e2f451e61f6e067ea689bcc35039cf92946492
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423603
> Reviewed-by: Mark Zhou <markzipan@google.com>
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Nicholas Shahan <nshahan@google.com>

Change-Id: I67d35d085e9b9510547aff8fb16ac0a8ed44d6df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425404
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-04-29 14:16:38 -07:00
Nicholas Shahan be6d2e3a00 [ddc] Cancel futures after a hot restart
Outstanding async code now checks and cancels itself if it was created
in a previous version of the application from before a hot restart
operation. This includes outstanding `Future`s created by calling the
`dart:js_util` helper `promiseToFuture`.

Issue: https://github.com/flutter/flutter/issues/166004
Change-Id: I342bbd2f8eda6b58d2f0fdaf3c00f55f03561b1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423961
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-04-28 23:25:56 -07:00
Nicholas Shahan 776c0586aa [ddc] Refactor visitInstanceGetterInvocation()
Moves the remaining special case logic out of `_emitMethodCall()`
simplifying the reasoning about where so hot reload soundness checks
can be added.

Change-Id: I13e2f451e61f6e067ea689bcc35039cf92946492
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423603
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-04-28 17:42:43 -07:00
Nicholas Shahan 29b6a03388 [ddc] Refactor visitDynamicInvocation()
Create a new helper `_emitArgumentGroups()` used for the calling
conventions where arguments are not passed in a flattened list.

Towards reducing the variety of code that flows through
`_emitMethodCall()` so hot reload soundness checks can be added when
they are appropriate.

Change-Id: I50ef9c4d54d71408d71b76fc2ca0acb73ef2af08
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422367
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-04-28 16:34:10 -07:00
Nicholas Shahan 8fb9578d95 [ddc] Refactor function invocation visitors
`visitFunctionInvocation()` and `visitLocalFunctionInvocation()` now
emit code directly.

Towards reducing the variety of code that flows through
`_emitMethodCall()` so hot reload soundness checks can be added when
they are appropriate.

Change-Id: I11e7fef6a454509a18f570bc2a316e81b9e09f2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422365
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-04-24 14:43:29 -07:00
MarkZ 23cefd8aa9 [ddc] Adding support for hot reloaded super getters.
This removes the 'bind' and 'bindCall' methods in our runtime in favor of extending 'tearoff' to support their behavior. Also introduces 'superTearoff' for invoking torn off super members late.

Change-Id: I52ab797558a225c57cc2c6197c7b1bfa7f05a3c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416763
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2025-04-04 11:17:56 -07:00
Srujan Gaddam 9bc0d51467 [ddc] Compute js_util method regexes only once
sra@ noticed that we're recreating this RegExp every time
and we could just compute it once and store it in a static
field instead.

Change-Id: Iab2875d12295f0dc084aa1f0fb5e649b28c73c3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420165
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-04-03 13:34:17 -07:00
MarkZ e958560965 [ddc] Adding error messages for illegal enum conversions after a hot reload.
Fixes: #60102, #60104
Change-Id: I5b89edffc3aa753d0882c2b9fd6aefd9bfef7175
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416080
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-03-19 10:36:59 -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
Mayank Patke 549639dc6c [dart2js, ddc] Remove LEGACY support from rti.
- Remove support for `JS_GET_FLAG('LEGACY')` from backends
- Remove `kindStar` Rtis
- Remove `Recipe.wrapStar`

Bug: #60327
Change-Id: I2ec9b0afc9f3cd99fc6167600e6d908c9771af1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416101
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-18 19:09:54 -07:00
Mayank Patke 6a2e567859 [dart2js, ddc] Remove PRINT_LEGACY_STARS.
Bug: #60327
Change-Id: I32a9f078e4c2ae5fc3b79b4f549a4357a08818d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416043
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-18 19:09:54 -07:00
Mayank Patke 13b5b8ab37 [dart2js, ddc] Remove support for SNS checks.
Bug: #60327
Change-Id: I38f04fea4e51dcd0fd43dc93ecc7007a0a816f29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416120
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-03-18 19:09:54 -07:00
Mayank Patke 1f8ab5f53b [dart2js, ddc] Remove LEGACY_TYPE_REF.
Bug: #60327
Change-Id: I30017acd7087227e646b230078066208fb27e398
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416060
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-18 19:09:54 -07:00
MarkZ ba90daf304 Reland "[ddc] Overhauling tearoff equality and identity."
This new update adds fixes + tests for cross-module super mixins. Super getters can refer to mixins compiled in other modules, so we need to expose all mixin names to make them accessible from their enclosing library.

This is a reland of commit e4c4d0f839

Original change's description:
> [ddc] Overhauling tearoff equality and identity.
>
> Hot reload requires DDC to update how its tearoffs are represented. Tearoffs obey the following conventions:
> * Instance tearoffs are never identical
> * Tearoffs with the same object target and name have the same hash code (even if they resolve to different functions across hot reloads)
> * Two separate tearoffs of the same member are equal
>
> To support this, tearoff equality must not depend on the bound object and method but a composite of the bound object, torn off member name, and the exact class/object from which the member was torn off.
>
> Notable changes:
> * Methods' immediately bound targets are emitted with member signatures. This is required to determine the bound targets for instance and dynamic tearoffs. Bound targets are identified by `libraryUri:class` strings.
> * `applyMixin` passes in a 'true' bound target. This is because mixin applications' members are considered children of their 'on' class (not the mixed in class) wrt equality/hashCode.
> * `bind` is modified to pass in its 'true' bound object to support mixins' super getters.
> * `tearoff` and `staticTearoff` are modified to accept a bound target string (only required for static tearoffs, as they are bound at tearoff-creation-time).
> * Static tearoffs avoid using their bound object for hashcode and equality, as these libraries may be wrapped in proxy objects.
> * Tearoff equality and hashCode are updated to consider bound object, bound name, and its bound method's immediate target.
> * 'noSuchMethod' and 'toString' methods are always accessed through their extension property during signature lookups.
>
>
> Change-Id: Ica5501b6860c605db50aa945bafb6802a7317511
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406723
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Commit-Queue: Mark Zhou <markzipan@google.com>

Change-Id: I645992030f9106c158426412387ddecafc78e3f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415102
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-03-17 10:34:48 -07:00
Devon Carew 3c973fb292 [lints] address diagnostics related to strict_top_level_inference
Change-Id: I228058202855900f0adba73c1ab04d35180a6e5d
Tested: this is an analyzer diagnostic only change
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414900
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-03-17 08:27:57 -07:00
Nicholas Shahan e36ac5fe1c [ddc] Additional null safety cleanup
* Remove accessing nullability through a library node since they no
  longer differ depending on the language version.
* Cleanup old comments related to legacy types.
* Cleanup dead code in nullable inference of `.toString()` calls.

Change-Id: I099180e7bab4f0f1ea7cf23a6c0fc015ab0413b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415160
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-13 13:32:22 -07:00
Nicholas Shahan 58ba6006a6 Revert "[ddc] Overhauling tearoff equality and identity."
This reverts commit e4c4d0f839.

Reason for revert: Breaks are blocking roll into flutter
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8720592021329723649/+/u/run_test.dart_for_web_canvaskit_tests_shard_and_subshard_0/stdout

Original change's description:
> [ddc] Overhauling tearoff equality and identity.
>
> Hot reload requires DDC to update how its tearoffs are represented. Tearoffs obey the following conventions:
> * Instance tearoffs are never identical
> * Tearoffs with the same object target and name have the same hash code (even if they resolve to different functions across hot reloads)
> * Two separate tearoffs of the same member are equal
>
> To support this, tearoff equality must not depend on the bound object and method but a composite of the bound object, torn off member name, and the exact class/object from which the member was torn off.
>
> Notable changes:
> * Methods' immediately bound targets are emitted with member signatures. This is required to determine the bound targets for instance and dynamic tearoffs. Bound targets are identified by `libraryUri:class` strings.
> * `applyMixin` passes in a 'true' bound target. This is because mixin applications' members are considered children of their 'on' class (not the mixed in class) wrt equality/hashCode.
> * `bind` is modified to pass in its 'true' bound object to support mixins' super getters.
> * `tearoff` and `staticTearoff` are modified to accept a bound target string (only required for static tearoffs, as they are bound at tearoff-creation-time).
> * Static tearoffs avoid using their bound object for hashcode and equality, as these libraries may be wrapped in proxy objects.
> * Tearoff equality and hashCode are updated to consider bound object, bound name, and its bound method's immediate target.
> * 'noSuchMethod' and 'toString' methods are always accessed through their extension property during signature lookups.
>
>
> Change-Id: Ica5501b6860c605db50aa945bafb6802a7317511
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406723
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Commit-Queue: Mark Zhou <markzipan@google.com>

Change-Id: Ic5694976260189f7215dfa3c2318e9a0656f0de6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415100
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-03-12 12:46:38 -07:00
MarkZ e4c4d0f839 [ddc] Overhauling tearoff equality and identity.
Hot reload requires DDC to update how its tearoffs are represented. Tearoffs obey the following conventions:
* Instance tearoffs are never identical
* Tearoffs with the same object target and name have the same hash code (even if they resolve to different functions across hot reloads)
* Two separate tearoffs of the same member are equal

To support this, tearoff equality must not depend on the bound object and method but a composite of the bound object, torn off member name, and the exact class/object from which the member was torn off.

Notable changes:
* Methods' immediately bound targets are emitted with member signatures. This is required to determine the bound targets for instance and dynamic tearoffs. Bound targets are identified by `libraryUri:class` strings.
* `applyMixin` passes in a 'true' bound target. This is because mixin applications' members are considered children of their 'on' class (not the mixed in class) wrt equality/hashCode.
* `bind` is modified to pass in its 'true' bound object to support mixins' super getters.
* `tearoff` and `staticTearoff` are modified to accept a bound target string (only required for static tearoffs, as they are bound at tearoff-creation-time).
* Static tearoffs avoid using their bound object for hashcode and equality, as these libraries may be wrapped in proxy objects.
* Tearoff equality and hashCode are updated to consider bound object, bound name, and its bound method's immediate target.
* 'noSuchMethod' and 'toString' methods are always accessed through their extension property during signature lookups.


Change-Id: Ica5501b6860c605db50aa945bafb6802a7317511
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406723
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-03-11 10:31:19 -07:00
Srujan Gaddam fa4d761f07 [ddc] Align error message with VM when reload is rejected
https://github.com/flutter/flutter/blob/f3d0f5a2ca422b1d8cbfc1c4d67ae288ce22ee47/packages/flutter_tools/lib/src/run_hot.dart#L1669

The above is emitted when a reload is rejected at runtime in
the VM. Since we reject errors at compile-time, we should align
the error messages.

Change-Id: I6687d3efaf87d1dce1c7d21591039cbb5a447ff1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413543
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
2025-03-06 00:37:24 -08:00
Nicholas Shahan 00c99925fc [ddc] Delete unsound null safety from the compiler
Change-Id: I7e8a8b954c706d421bce2e6671619123c6206122
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388746
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-03-05 10:14:08 -08: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
Nicholas Shahan bc21f34991 [ddc] Break compiling with unsound null safety
Change-Id: Ib6f80fc38e355241f1214e7e457b712544645b37
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386081
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-02-28 12:33:17 -08:00
Chloe Stefantsova d8c48032bb [cfe] Remove legacy raw types from CoreTypes
Change-Id: I9d920cc00ce22900429fd38b6c452483438f94d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397161
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-02-28 00:50:40 -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
Nate Biggs 773cf6b1d5 [ddc] Fix issues with duplicate library name aliases.
The attached bug shows an issue users have been encountering where a constructor seems to be undefined. It turns out this is because DDC is trying to read the constructor from the wrong library.

This is happening because both 'package:dio' and a sister package 'package:dio_web_adapter' both contain a library with the same path: 'src/adapter.dart'. 'BrowserHttpClientAdapter' the class they are trying to reference is defined in 'package:dio/src/adapter.dart'. However, due to a naming collision, their import is referencing 'package:dio_web_adapter/src/adapter.dart'.

This naming collision happens because of the logic in '_jsLibraryAlias'. By truncating the start of the import URI (i.e. 'dio/' and 'dio_web_adapter/') the two libraries map to the same alias. This alias is then used to as the key in the AMD module export object and since both libraries are in the same module, only the second one gets exported.

This code may have been written with the assumption that libraries from different packages would always be in different modules (in which case the shortened paths shouldn't collide) but this is not the case. The fix is to use the full import URI including the package name.

In writing the attached modular test I discovered another issue that only affects es6 imports. The ScopedId resolver was not considering NameSpecifier as a declaration point for variables. This lead to a similar name collision since the import alias's name was also being derived from a truncated import URI. In the test, both 'f1/foo.dart' and 'f2/foo.dart' were being imported 'as foo'. Now one is 'as foo' and the other is 'as foo$'.

The first issue affects both AMD and es6 while the second issue only affects es6. The modular tests run with es6 so the new test fails if either of these fixes is not in place.

The new DDC module system is not affected by either issue since it doesn't use NameSpecifiers and it uses the full import URI as a string to register libraries rather than a shortened alias.

Tested on TGP and with a local Flutter application.

Bug: https://github.com/dart-lang/sdk/issues/56498
Change-Id: I5bdb945cfbe615874b40e2fc4ebba31b661cf3b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410260
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-02-18 13:08:50 -08:00
Nicholas Shahan 1ee0894631 [modular_test] Delete support for macro execution
Mostly a revert of https://dart-review.googlesource.com/c/sdk/+/361261.
A straight revert contained merge conflicts that I resolved manually but
I left some of the cleanup or refactoring in place.

Change-Id: I2add9f4951d7c6c2399d8c95f36b1483279eea44
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409401
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2025-02-13 08:30:33 -08:00
Nicholas Shahan b12fedced2 [ddc] Add hot reload rejection for type parameters
Changing the number of type parameters on a class is not supported
in a hot reload.

Issue: https://github.com/dart-lang/sdk/issues/60101
Change-Id: I3e397f26ca80e655dcb3d2807ddefd59c89adddb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409381
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2025-02-12 12:05:54 -08:00
Nicholas Shahan 39c60997ec [ddc] Add initial hot reload metadata
* Demonstrates the ability to generate metadata when inspecting the
  last accepted and delta components.
* Attach the metadata to the component right before compiling with DDC.
* Use the metadata to avoid deoptimizations in the initial compile
  when they are only required to support a hot reload.
  * Deletion of all type rules for classes that extend Object in the
    initial compile. In the future this should be reduced further to
    only the classes that had a hierarchy change in a hot reload.
  * Type checks on the return value of getters used to represent
    fields.

Change-Id: I2812b564bc3f4d72f005d4bd11fa55ec0eb394ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404940
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-02-11 12:04:50 -08:00
Nate Biggs 89af2425f2 [ddc] Append hot restart instruction to hot reload rejection reasons.
By adding this message here, any entrypoint that makes use of this for hot reload (e.g. DartPad, Flutter tools/FE server) will all surface this same message. This probably easier than having each one try to detect errors and append its own message.

Change-Id: I5980d530b66da818e29403cc13407095d8b203dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408380
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-02-07 10:20:53 -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
Johnni Winther c27cec63aa [cfe] Remove macro support
This removes the support running macros in the CFE.

The scanner and package:kernel still have support for the macro modifier. This will be removed in a follow-up.

The metadata expression parser is deliberately left in, since it might serve as the basis for a parser AST.

Change-Id: I06d91eb0fac2e7a71e6afde647b03be3814dbd5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406963
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
2025-02-03 07:13:51 -08:00
Nate Biggs 5855d91ba8 [ddc] Correctly extend type parameters for factory constructors.
RtiTypeEnvironment currently does not support being extended. However it's used for factory constructors which themselves can have generic functions defined in their bodies. This means we have to allow the ability to extend RtiTypeEnvironments as well.

Bug: https://github.com/flutter/flutter/issues/160338
Change-Id: I9b4e79b44f503a4a987e0c38da86fdce81361e4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406344
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-01-30 08:07:30 -08:00