Commit Graph

1294 Commits

Author SHA1 Message Date
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
Nicholas Shahan bd691da600 [ddc] Add expression eval tests for dot shorthands
Ensures dot shorthands are usable from expression evaluation on the web.

Change-Id: Ia5e5c54f0de0c2237d6d01b4658723f5188bd460
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446500
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-08-22 14:39:05 -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
Nicholas Shahan 39d2b206fa [ddc] Add expression eval tests for local consts
See: https://dart-review.googlesource.com/c/sdk/+/445461
Change-Id: Ic819199a1afe515dcda05aa04fc3e1664a39055b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446001
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-08-20 09:26:00 -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
Nate Biggs 5ce3cd24d2 [ddc] Fix hot reload test runner ternary.
Change-Id: Id08d5bac6d03aaa70f91df7af31b313b767d8729
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439680
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Auto-Submit: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-07-10 09:35:47 -07:00
Nicholas Shahan 559b8552a8 [ddc,frontend_server] Fix expression compilation after recompile
Update the last known good component after a recompile reject back to
the expected state before the recompile.

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

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

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

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

Change-Id: I9c04bd46e56b33dc654d00fb330de29c3c643a5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434522
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2025-06-24 14:14:42 -07:00
Johnni Winther b8b072ed3b [cfe] Update message for undefined access
This updates the message text for undefined access. Instead of saying
that the member is not defined on the "class", it now says on the "type".

Closes #60290

Change-Id: I9387f892e99ba109b9b1d99af25714ab83b5350c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433941
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-06-17 04:03:26 -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
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
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
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
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 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 96c8aff4ce Support stacktrace testing for DDC library bundle
These tests are currently run with the ES6 module format.
This expands and refactors the test suite to also test the
DDC library bundle module format. Refactoring is mostly
limited to better naming and structuring of parameters.

Change-Id: If2a813af1a503e18d74dd4eec57eac4ecc8a3f35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424880
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-04-29 17:11:45 -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
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
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
Siva Annamalai 4c077feda9 Reland "[sdk] Remove some redundant kernel-worker JIT snapshot generation code."
This reverts commit 91a653b4e5.

Reason for revert: The cbuild failure was apparently a flaky test

Original change's description:
> Revert "[sdk] Remove some redundant kernel-worker JIT snapshot generation code."
>
> This reverts commit 0e556f6960.
>
> Reason for revert: cbuild failure on some ads test
>
> Original change's description:
> > [sdk] Remove some redundant kernel-worker JIT snapshot generation code.
> >
> > Change-Id: Ic092633dd6f5eb0dcfdef70472221ddc7951bbbf
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412783
> > Reviewed-by: Srujan Gaddam <srujzs@google.com>
> > Commit-Queue: Siva Annamalai <asiva@google.com>
> > Reviewed-by: Nicholas Shahan <nshahan@google.com>
>
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Change-Id: I7dd273001bf9c016f014c111ba8fe9197c75e52e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414383
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Siva Annamalai <asiva@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Auto-Submit: Siva Annamalai <asiva@google.com>
> Reviewed-by: Srujan Gaddam <srujzs@google.com>

Change-Id: I364af1f8dabd6e3ea121a4db58af54fb2eed4ad7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414880
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-03-12 16:26:09 -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 5d624dc584 [tests] Minor hot reload test suite cleanup.
Removing extraneous configs + reporting less for error summaries.

Change-Id: I874e1217f6ba80e230a031c005cc5039464c513d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414828
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-03-12 10:52:17 -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
Siva Annamalai 91a653b4e5 Revert "[sdk] Remove some redundant kernel-worker JIT snapshot generation code."
This reverts commit 0e556f6960.

Reason for revert: cbuild failure on some ads test

Original change's description:
> [sdk] Remove some redundant kernel-worker JIT snapshot generation code.
>
> Change-Id: Ic092633dd6f5eb0dcfdef70472221ddc7951bbbf
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412783
> Reviewed-by: Srujan Gaddam <srujzs@google.com>
> Commit-Queue: Siva Annamalai <asiva@google.com>
> Reviewed-by: Nicholas Shahan <nshahan@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I7dd273001bf9c016f014c111ba8fe9197c75e52e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414383
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Auto-Submit: Siva Annamalai <asiva@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-03-09 11:51:06 -07:00
asiva 0e556f6960 [sdk] Remove some redundant kernel-worker JIT snapshot generation code.
Change-Id: Ic092633dd6f5eb0dcfdef70472221ddc7951bbbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412783
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-03-07 15:19:49 -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
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
Srujan Gaddam c957483693 [ddc] Initialize and link the necessary library in debugger APIs
Closes https://github.com/dart-lang/sdk/issues/60109

Both getClassMetadata and getClassesInLibrary can be called before
main is called. In order to support this, libraries should be
initialized so that these debugger APIs can inspect them. Similarly,
SDK libraries that are needed before any code can run should be
initialized. In order to support this, they are initialized on the
first initializeAndLinkLibrary call and reinitialized during a
hotRestart (since the libraries are recreated).

Tests are added to evaluate these methods before main is called.
The debugger test helpers are amended to:
- Support breakpoints within the bootstrap script. This is done by
caching the script and querying to see if it has the breakpoint if
the input sources do not.
- Refactor shared test expectation logic.
- Remove an unused method.

Change-Id: I5534d7008436a51243cf51dba01bb8ad06adca69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410602
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-02-20 14:15:06 -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
Nate Biggs 4dd1522635 [ddc] Add tests for '--reload-delta-kernel' and '--reload-last-accepted-kernel' flags.
Change-Id: I643957dcd8cc6611108c9ff67a9610bb19475af4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408924
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-02-10 17:29:21 -08:00
Nicholas Shahan 16960a8638 [tests] Fix tests for changing type parameters
* Handle inconsistencies in the type of a notice in reload reports.
* Update expected error messages when the type parameters of a class
  change.
* Fail reload tests if rejection error was expected but the actual
  error is null.
* Cleanup unused imports in tests.
* Delete change_instance_format7 test because it was split into DDC
  and VM specific versions.

Change-Id: I3b4d6cb3126d7c1fad688c393677e053a005687f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408883
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-02-10 16:26:00 -08:00
Srujan Gaddam 8aa6b413eb [ddc] Update hot reload test suite to use recompile-restart
A new optional suffix to the file names is added: '.restart'.
This allows us to differentiate between hot reload generations
and hot restart generations. All files with the same generation
should either have the suffix or don't. If present, uses the
recompile-request instruction in the frontend server. If not,
uses the recompile instruction. Tests are renamed and a WIP
README is added to document this change.

Change-Id: I2691c5ec0b7336115a76dc0e0369213e74b6ea21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406183
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2025-02-05 14:51:21 -08:00
Johnni Winther 7b9c5d938b [ddc,frontend_server] Remove macro tests
Change-Id: I1227eaed501e0175859e3c7759d88a8b19e8f4d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406964
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
2025-02-03 00:37:19 -08:00
MarkZ 0083128537 [tests] Using git diff over diff for stability in hot reload tests.
Change-Id: Icdbdf4c569fd8ab5de96560722ac62616185a751
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406224
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-01-29 16:17:13 -08:00
Nicholas Shahan 8968e0e2d6 [ddc] Remove unsound null safety option from tests
Change-Id: I1da8a572fc3556b03141a312375fa91bb3a8f358
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386084
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-01-28 09:24:00 -08:00
Nicholas Shahan 4fce27b1f7 [tests] Fix formatting when writing diffs
* Normalize white space around source code strings before producing
  diffs by trimming and appending a single newline character.
* Write an empty line between the source code and diff text in
  generation files.
* Run dart format on all test files.

With these changes you should be able to run the hot reload suite with
`--diff write` and dart format the code multiple times without
introducing changes in the file.

Change-Id: Ifc0b1dd7032bd448f5f6568c5aa3c18dde076c71
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405247
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-01-24 09:07:01 -08:00
Nicholas Shahan dc37a77cf7 [ddc] Add rejection for removed const fields
Reject hot reload requests that remove fields from const classes. This
is consistent with the VM implementation.

Change-Id: I73ff62795abbca62565ee6efd9cb245485d010ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403321
Reviewed-by: Morgan :) <davidmorgan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-01-10 14:46:39 -08:00
Nicholas Shahan f91050ca91 [ddc] Add visitor for hot reload deltas
Initially this visitor will reject reloads (by throwing an Exception).
Future changes will add the ability to record data about the delta to
guide the JavaScript compilation decisions.

- Rejects deltas that delete all const constructors from a class
  (making it non-const).
- Adds ability to test the visitor directly by compiling components
  from source via an in-memory compiler.
- Updates DDC frontend_server compiles to write errors to the output
  stream.

Change-Id: Ib318f42d28367416983266a214f97821a38a2913
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401600
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2025-01-10 10:20:42 -08:00
MarkZ c033dd24af [ddc] Updating tearoffs to be evaluated on access.
Tearoffs are now represented as a closure that resolves an underlying bound context and property on access. `_boundMethod` and RTI getters must also be evaluated late.

Additionally, we now both canonicalize static methods and tag them with their types at class-declaration time (though lazily) - so that late resolved closures have access to their types.

Some tests have been updated to expect simpler errors. DDC traditionally emits slightly different errors that might aid in debugging.

Change-Id: I1f762b8df45e0766d16dbc8688073768c8bfd233
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401321
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2025-01-08 13:40:33 -08:00
MarkZ 3b7eb266a3 [test] Fixing hot reload suite diff checking.
Should resolve flaky cross-platform diffs

Change-Id: Ic496829ea984d049f8fe984e614aaf4fb41c283c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402941
Commit-Queue: Mark Zhou <markzipan@google.com>
Auto-Submit: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2025-01-03 11:46:26 -08:00
Nate Biggs 2616eb2aed [ddc] Use TemporaryId when emitting all kernel VariableDeclaration references.
Some CFE lowerings (e.g. pattern lowerings) result in nested scopes containing VariableDeclarations with the same 'name'. The current DDC transform translates these to the exact same name in JS leading to incorrect semantics.

The `TemporaryId` mechanism automatically renames any variables with the same name that would shadow each other. So we re-use that here to ensure the variables all have a unique name if the CFE hasn't already given them one. If the name is already okay (i.e. not shadowing something else), the name in JS will appear unchanged.

Side note: In a future change perhaps we should rename `TemporaryId`. The general mechanism it implements is more useful than its original intended use.

Fixes: #59613
Change-Id: I708c72528d5df19af48dde01163d375a5588baae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398504
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-12-12 08:56:11 -08:00
Nicholas Shahan 47e3ad7f1f [ddc] Add rejection to hot reload test suite
Allows tests to define generation files that are expected to be
rejected as invalid for hot reload.

Tests generation files now support the extension `.reject.dart` to
signal a rejection is expected. A corresponding rejection error
message should be added to the map in the config.json file.

- Add new rejection logic to the file discovery and config file
  parsing.
- Add new reload receipts that are output by the runtime utils when
  running hot reload tests. These receipts are used to verify that
  each file generation was visited (not necessarily accepted) at
  runtime.

Change-Id: Ifee698f0d6502ecfceba2d5c733a2c88fb5daf7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394564
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-11-28 00:34:31 +00:00
Nicholas Shahan f33192437e [ddc] Cleanup remaining platform cases
- Move platform specific code into various suite runners.
- Move shared DDC code into common superclass.

Change-Id: Ie67e3cad814be8aad0438294a8f566869199eee2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393485
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-11-21 19:25:32 +00:00
Nicholas Shahan b9e7cb6b10 [ddc] Move D8 implementation to D8SuiteRunner
Merge setup, generate bootstrap and run test logic into a single method.

Change-Id: I5e0045c5e84b5a1966bff79bd37b759fe4b789bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393440
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-11-20 23:39:58 +00:00