Commit Graph

2406 Commits

Author SHA1 Message Date
Nate Biggs 46bd9f351a [ddc] Handle optional/defaulted parameters when created scoped parameter renames for sync* transform.
This was missed in the original implementation of the sync* transformer because prior to my recent change, ScopedIds couldn't end up within a DestructuredVariable.

Change-Id: I2733ce1e01edb50659634347204bac1769269615
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401080
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-12-16 10:01:23 -08:00
Nate Biggs 2f46eaaf0c [ddc] Fix async rewrite ignoring new ScopedId variables.
The async rewriter was ignoring these variables since they were only used for non-user variables that didn't need to be captured. Now that we use these ScopedIds for user variables we need to capture some of them. "userDefined" specifies if the variable should be captured.

Change-Id: I2dbb86e1834982b59883a3d107612ee8f8e2284a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400662
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-12-13 11:10:26 -08:00
Nate Biggs 5c1510de6b [ddc] Rename TemporaryId to ScopedId.
Change-Id: I7bcf2484769dc187b3d3e14286fde2c9023a73c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400661
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-12-13 11:10:26 -08:00
Nate Biggs 8791205c4b [ddc] Remove print from expression compiler.
Change-Id: I14d1428310b3075ed43c492ead2bd20f734ff974
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400480
Auto-Submit: Nate Biggs <natebiggs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2024-12-12 16:41:03 -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
Jessy Yameogo ed8e22ff10 fixed bug, 'dartDeveloperLibrary()._extensions.keys' is not a function
Change-Id: I95a59575e3dfebf4e44008d171226994bb63ccba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399784
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Jessy Yameogo <yjessy@google.com>
2024-12-10 20:24:54 +00:00
MarkZ ebf9df9cb1 [ddc] Avoid overriding LegacyJavaScriptObject type rules across link phases.
This prevents libraries from accidentally clobbering LegacyJavaScriptObject rules when linking.

Change-Id: Ia7465013633a34907ca6ab9d1d5bfcdf99ffa13c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395161
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-11-27 00:35:50 +00:00
MarkZ bacbbf83c1 [ddc] Adding RTI subtype cache clearing.
This is required when a hot reload causes changes to the subtype hierarchy.

This change also adds RTI operations for clearing subtype caches and deleting type rules.

The DDC Embedder also now accesses the RTI library to clear subtype caches on hot reload.

See: #57049

Change-Id: I50a43ce342f23060bc28a3654c2da37c362492b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394040
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-11-26 19:33:37 +00:00
Nate Biggs d621ed9782 [ddc] Fix handling of continues in switch statements with labeled continues.
Tested with test case outlined in bug below. This should be tested via Lasse's tests when he lands them.

For slightly more context we compile code like this:
do {
  switch (y) {
    case 1:
      continue L1;
    L1:
    case 2:
      continue;
  }
} while (x);

into something like this:
do {
  while (true) {
    var labelState = y;
    switch (labelState) {
      case 1:
        labelState = 2;
      case 2:
        continue; // <-- This now only continues the while (true).
    }
  }
} while (x);

Bug: https://github.com/dart-lang/sdk/issues/59593
Change-Id: I9b343fd918e48cb44b65e90eab39d70fca4758d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397105
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-11-22 22:18:41 +00:00
Srujan Gaddam a7e4d59d2d [ddc] Fix passing module format to ExpressionCompiler
The DDC library bundle format is a combination of the DDC
format and canary, so therefore check that's the case, and if
so, pass the library bundle format.

Change-Id: I067d2b020e75b703a30fbe7d5f8dc2d31cd4878c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396420
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-11-20 20:29:57 +00:00
MarkZ 7d7d9ab943 [ddc] Extending static fields to perform type checks on first access.
Type changes across hot reloads need to be performed even if the underlying value has already been initialized.
To avoid extraneous type checks, getters replace themselves with a direct access on their value store on first access.

Also updates our builder to support get/set as property descriptor functions.

Adds some extra conditions that will be cleaned up when pragma support is added (#57049).

Change-Id: I44f4a9e1a6fd8a49aca5e629fb21348170a9d80f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393041
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-11-19 23:17:05 +00:00
Nate Biggs 9468f60aac [dart2js, ddc] Fix nested exception handling.
In the flattened control flow state machine generated for dart2js and ddc async functions, there is a single error state variable per function. However, functions can have nested error handling that may try to access stacked errors separately. When we enter a nested try/catch we should avoid clobbering the outer exception as the outer handler may need it later.

To fix this we maintain a stack of errors that we 'push' to when we enter a new try/catch and which we 'pop' from at the end of executing that try/catch.

Fixes: https://github.com/dart-lang/sdk/issues/57046
Change-Id: Ib96a44ab4152f6f9e444f2ee959ec9aa252800f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395580
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-11-15 23:20:00 +00:00
Jens Johansen a9469269d7 [kernel] BinaryReader takes Uint8List, not List<int>
In AOT this makes reading faster:

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

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

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

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

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

TEST=Existing tests.

Change-Id: I86b16ed207343848dee2e376f42598c223bbc48f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393740
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-08 08:23:42 +00:00
Srujan Gaddam 22833d51da [ddc, test_runner] Add stackTrace debugger helper to dartDevEmbedder and clean up test_runner
Adds a stackTrace helper that returns a stringified StackTrace for
an arbitrary error. Removes importLibrary references in test_runner
now that we have that and removes some calls that didn't do anything
(addAsyncCallback, removeAsyncCallback, and startRootIsolate).

addAsyncCallback and removeAsyncCallback are also removed from the
runtime. Calling these were removed in https://github.com/dart-lang/sdk/commit/8bd3690ab06c3eda2f4996ca60b94fdcc9f76105
so this is just finishing up the clean-up.

Change-Id: I9dacc2b3fd3e27468061d6e59a3207eecdb7cac8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393800
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2024-11-07 03:40:54 +00:00
Srujan Gaddam e94de78d2b [ddc] Remove statements from the Fun returned by buildFunctionWithImports
This list of statements is intended to support additional
statements that need to be emitted to handle imports/exports.
For the incremental case, no non-import statements exist
and can be safely omitted from the body. We should be
intentional about including these if needed later to avoid
accidentally including unnecessary statements.

Change-Id: I726bb9e980d43c1edd1d0bda2d9be897586638ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393163
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-11-06 20:42:13 +00:00
Srujan Gaddam 65ce9ed581 Add debugger runtime APIs and add/modify tests
- Exposes a minimum set of APIs that are needed by DWDS
a single class Debugger.
- Renames some APIs and modifies the signature to better
align with what's happening and what DWDS actually uses.
Similarly, modifies the internal APIs to handle the new format.
- Modifies expression evaluation test suite to handle the
new module format correctly.
- Modifies LibraryBundleCompiler to emit the right export name.
- Adds/adapts existing tests for the runtime debugger APIs.

With this, all tests within pkg/dev_compiler/test/expression_compiler
pass with the new module format with the exception of two tests within
expression_compiler_e2e_ddc_null_safe_test, which will be fixed
in a future CL.

Change-Id: I296496441ea421ecb57bed3b2e90b92365fef510
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391308
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-11-01 22:09:30 +00:00
Nicholas Shahan 7d00c54b23 [ddc] Enforce unnecessary_breaks lint
Ignore violations in the js_ast sub-directory to avoid unnecessary diffs
with the original package.

Change-Id: Iac8c942e5e2446b8433e2073b546c28e42a8f5cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392700
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-10-30 21:10:38 +00:00
MarkZ d53711d88b [ddc] Reconciling d8 and Chrome timing differences in hot reload suite.
Appending a script to the DOM in Chrome causes microtasks to fire. This change makes the `hotRestart` pathway async and inserts an async callback at the hot restart boundary for d8.

Change-Id: Ib05e9e496b6313d861fb5cb691a5894beed62a6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389224
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-10-28 23:11:43 +00:00
MarkZ 933d630e42 [ddc] Cleaning up unused fields and functions
Removes:
* Unused SDK-specific field emission logic
* after-class-def items, which used to hold lazily emitted classes
* deferred supertypes/classes, which are no longer needed after the new class representation

Change-Id: Ibdaa8d32aecc42c25749cc6a2290ce0bfd4662f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391488
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-10-28 18:17:00 +00:00
MarkZ a5f734592c [ddc] Updating representation for virtual and lazy fields.
This restructures all fields as accessor/value-store pairs, providing a level of indirection required for hot reload.

Major updates include:
- All fields (top-level, lazy, virtual, etc.) now have a value store (represented as a private top-level symbol). The value store is initialized on first access for the initializer.
- Lazy value stores are prefixed with '_#v_' to indicate that they are not replaced on a hot reload.
- `declareClass` and `declareTopLevelProperties` are introduced to append classes/members to libraries. These functions extend the 'original' entity/class with fields introduced by a properties object, ignoring the special lazy value stores mentioned above.
- `defineLazy` is replaced with the above operations.
- Virtual/instance fields are still initialized by inside their constructor on first load (so their getter forwards to its value store). On hot reload, however, uninitialized fields are lazily initialized.
- Final fields now use a sentinel value to check for late initialization errors during the initialization loop.
- The JS AST is extended to support class properties.

Change-Id: I5cc3548477d83897273f3b993b304a804754ec0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386971
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-10-28 18:17:00 +00:00
Nicholas Shahan 368cb645e5 [ddc] Enable sound null safety by default
In the expression compiler worker. It appears all uses manually
pass the flag and this is just preparation to remove it in the
future.

Change-Id: Iad0edfbcab28194b4ffcb520db89943c6239753b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388745
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-10-09 15:50:31 +00:00
Nicholas Shahan ebd0b2ee16 [ddc] Merge the command libraries into one
Copy all of compiler/shared_command.dart into command/command.dart

Change-Id: Id8fb363b2800fe5fd60fae75f7dc557b33a806ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388051
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-10-08 16:51:12 +00:00
Nicholas Shahan b4d5272d99 [ddc] Move command.dart library
From: lib/src/kernel/command.dart
To: lib/src/command/command.dart

This is a step towards organizing the code from shared_command.dart and
eventually deleting it.

Change-Id: I1ca9fcfd3d7d74511957d516c01544f4a68e4e89
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388050
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-10-08 00:47:01 +00:00
Nicholas Shahan 45b1612064 [ddc] Delete generic class table
The generic class table is no longer used since changing to the
new representation for generic classes.

Change-Id: I836e0ee9e4b291dab68397554adbbd1a67376b9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388740
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-10-08 00:08:18 +00:00
Nicholas Shahan 085deb8bc4 [ddc] Create new result.dart library
This is a step towards organizing the code from shared_command.dart and
eventually deleting it.

- Move `CompilerResult` from shared_command.dart.

Change-Id: Ibe4b8bbd5c6deb2558392255f3818773fa4ea80e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388049
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-07 22:54:09 +00:00
Nicholas Shahan 807660f323 [ddc] Create new options.dart library
This is a step towards organizing the code from shared_command.dart and
eventually deleting it.

- Move `SharedCompilerOptions` and rename to `Options` from
shared_command.dart along with helpers.

Change-Id: Ic9edfb47fc2425a28b1e948d94fad96a2f594108
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388048
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-10-07 21:21:30 +00:00
Nicholas Shahan 9b7f5a0af6 [ddc] Create new arguments.dart library
This is a step towards organizing the code from shared_command.dart and
eventually deleting it.

- Move `ParsedArguments` and helpers from shared_command.dart.

Change-Id: I10a05f9595e5421b6d5498e2fd1138d0acfd5e35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388047
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-10-07 19:27:19 +00:00
Nicholas Shahan 95d13a89fa [ddc] Compile SDK as a bundle of libraries
Cleanup temporary code paths in the stable version of compiler.dart.

Change-Id: I4b60d90345bf8653060772789f55e16fb5db60d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385185
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-04 20:08:57 +00:00
Nicholas Shahan d2de06a574 [ddc] Move hierarchy operations to link method
This also includes operations that require a linked hierarchy to
be in place before they are executed.

Change-Id: Idc83d81fe7b27d2137a2102bb155a9a1026b7049
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385184
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-10-04 20:08:57 +00:00
Nicholas Shahan 28806cb806 [ddc] Synthesize dartx as a library
Collect all extension symbols across all "dart:" libraries and
create the dartx library to contain them all.

Change-Id: I334d6e11a1767929bfb8ad5ebf31276b9785d09e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385183
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-04 20:08:57 +00:00
Devon Carew 1f8aea0c81 Bump lints to a97011b4b031b1df94765dbacd7d92b0b765c8b9
Changes:
```
> git log --format="%C(auto) %h %s" af68bf0..a97011b
 https://dart.googlesource.com/lints.git/+/a97011b add unintended_html_in_doc_comment; rev to 5.1.0 (211)

```

Diff: https://dart.googlesource.com/lints.git/+/af68bf0cbad88002a2ae19ee8db37b64eb120c32..a97011b4b031b1df94765dbacd7d92b0b765c8b9/
Change-Id: I998d73f5f72e94d5f2922b0751d31620a837555e
Tested: analysis only change
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387601
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2024-09-30 21:48:03 +00:00
Sigmund Cherem 00b11411d6 [ddc] support library cycles in the new module format.
We'd like to properly support cases like:

```
a.dart:
  import 'b.dart';
  class A extends B {}
  class C {}

b.dart:
  import 'a.dart'
  class B extends C {}
```

Here both A and B will request a reference to the other during
linking.

We break the cycle by storing libraries in the map after they are
initialized, but before we recursively link them. Now an access to a
library proxy has different guarantees:
* during linking, it guarantees to return an intialized library.
* during program execution, it guarantees to return a linked
  library.

Aside from this change, this CL does a minor change to the logic on
`hotReloadEnd` to not change the state of the `libraries` array on a
hot-reload. This change is technically not necessary, but may help us
more clearly track the invariants of the library map: the new logic
keeps updates to the map monotonic over time.

Change-Id: Id2aafa3d94c6bff32b7ddb326f883f978bff6bf0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385324
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-09-27 18:07:48 +00:00
Nicholas Shahan 32d2b5373f [ddc] Delete defineLazy with legacy semantics
This is no longer used since support for legacy code < 2.12
has been dropped.

Change-Id: Id0e67445407c9b110218625d8e3a7ad5230d75cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386966
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-09-27 16:16:21 +00:00
Parker Lougheed a736410b90 [ddc] Migrate away from Map.from and Set.from
Improve the nearby usages of the resulting types as well.

Change-Id: I29907dd3050efd005070a11c3a99a6807ae65793
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386830
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-09-26 19:55:08 +00:00
Nicholas Shahan 39bcea7e76 [ddc] Cleanup use of dart library name
Avoid hard coded uses of the name for the SDK runtime library. This
unblocks a more consistent name/rename logic for all dart libraries
when they are imported.

Change-Id: I4599006569ecae81a0526686467e06da9b335fc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385188
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-09-25 21:49:39 +00:00
Jens Johansen 3dce89fbe0 [scanner] Don't give the Utf8 scanner a 0-terminated byte sequence
Not having to do the read-allocate-copy dance for files to add a 0-byte
at the end results in these changes when using the CFE to compile
(a fixed version of) the CFE:

```
msec task-clock:u: -1.7356% +/- 0.2164% (-73.16 +/- 9.12)
page-faults:u: -2.6957% +/- 0.0111% (-2914.83 +/- 12.00)
cycles:u: -1.7128% +/- 0.2223% (-297927979.70 +/- 38660477.01)
instructions:u: -1.6814% +/- 0.0002% (-361315766.86 +/- 36853.71)
branch-misses:u: -3.3289% +/- 0.9669% (-2153126.00 +/- 625370.97)
seconds time elapsed: -1.7372% +/- 0.2154% (-0.07 +/- 0.01)
seconds user: -1.5998% +/- 0.2740% (-0.06 +/- 0.01)
seconds sys: -4.1451% +/- 2.9801% (-0.01 +/- 0.01)
Scavenge(   new space) goes from 62 to 61
```

TEST=Existing test coverage.

Change-Id: I8e182bcee39839f6ed1e658c30c85c40ecf0b259
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385722
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2024-09-25 08:33:48 +00:00
Nicholas Shahan d4c9263fde [ddc] Cleanup changes to JSArray prototype
The old runtime type system required prototype manipulations to
correctly capture a type that contained an embedded type argument.
This was achieved by assigning the prototype of the array in the
JSArray factories and connecting the prototype chain so JSArray
"extended" the native JavaScript Array.

In the new runtime type system these special case operations are
not needed.

Remove the error state for `JS_CLASS_REF()` for interface types
with type arguments. The class definitions are now defined outside
of closures so they can be referenced just like classes without
type arguments.

Update debugger API to manually identify the library for JSArray and
remove unnecessary accesses of `.length` via JavaScript.

Cleanup skipped test cases for the old runtime type system.

Change-Id: I57ab0c968ec06437dad0e081f6334268e99dbc69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385102
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-13 22:47:15 +00:00
Nicholas Shahan 6cec0a02bb [ddc] Create types for normalization once
Create these types in the SDK module. Previously they were created
in every module but they are cached in the RTI library on creation
for use later.

Change-Id: Ic9bef3d7b43935be79a55b74672e68c1dd89a33d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384942
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-09-13 15:49:21 +00:00
Sigmund Cherem 25bc18c3b3 Add support for AOT in dynamic_modules tests
* Introduce steps to execute tests in AOT (using gen-kernel,
  dart2bytecode, and aot compiler)
* Accept using filesystem-scheme to provide dynamic_interfaces.yaml input
* Accept empty dynamic_interfaces.yaml
* Make temporary test changes to get them running:
   * include core types in dynamic_interfaces that we may want to have
     by default
   * rename entrypoint to `main`

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

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

Tested: CL adds additional test coverage, currently ran manually, integrated in CI in child CL
Change-Id: I4868e765855d9951bff160c18b846aa628f5e0b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383928
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-09-10 04:09:21 +00:00
Sigmund Cherem 9c91f31c10 DDC implementation of experimental dynamic modules.
In particular,

* Provides a DDC implementation for dynamic modules, where the download
  and instantiation of the module is delegated to the embedder of the
  program.

* Exposes an embedding API to allow embedders to define the loading logic.

* Adds a flag to compile code as a dynamic module. This includes
  generating an entrypoint trampoline and checks to validate that a
  dynamic module doesn't stump over previously defined libraries.

* Adds test coverage for DDC under `pkg/dynamic_modules/test/`.

Test suite can be run by executing:
```
DART_CONFIGURATION=ReleaseX64 out/ReleaseX64/dart-sdk/bin/dart \
    pkg/dynamic_modules/test/runner/main.dart -t ddc
```

Once we provide integration of test configuration results to that test
runner, we will add it as part of the test matrix.


Change-Id: I626b5fefe9a27546cc6d1630d17e812544a711c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379748
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-09-10 00:55:02 +00:00
MarkZ 6db84ef903 [ddc] Adding hot reload test with DDC's new module system.
Change-Id: I55c0b4d3c74654c192b6e664120778b057aa7161
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383820
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-09-09 23:16:48 +00:00
Nicholas Shahan ec0445ae79 [ddc] Add hot restart to new ddc module format
Add a simple implementation that throws out all libraries and runs the
main method again which triggers all libraries to be initialized with
fresh values.

Move the hot reload tests to the ddc canary test configuration
since that is where the support works at this time.

Update frontend server to use the use the new version of the DDC
LibraryCompiler when the emit library bundle option is true.

Change-Id: I6eba613106672536ef8bfcb0ff0a55749e2fb63c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381902
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2024-09-09 17:58:56 +00:00
Nicholas Shahan 2f09d05758 [ddc] Move simple class extends to link method
Allows classes with simple "extends" hierarchies and no type
arguments to be linked across library boundaries.

Change-Id: I02c75a8c0000498dd0f8458429f782810ca3e628
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380209
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-09-04 14:53:10 +00:00
Nicholas Shahan 3cc6105316 [ddc] Add empty link methods to new ddc module format
The link methods will contain all operations required to link class
hierarchies across library boundaries.

Change-Id: Iaa2bc566e17d215fd8bd9a20e6fc668679a2b58c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380208
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
2024-08-30 22:53:32 +00:00
Nicholas Shahan c958bcc4cc [ddc] Use import URI to name a library
Import URIs are normalized by the CFE and should be globally unique in
the program. They serve as a good identifier to name a library in the
new "ddc" module format.

Change-Id: I9e255221bcffba52ad80138a4672d0490b7cbacd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381781
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-08-30 22:53:32 +00:00
Nicholas Shahan 49f630c53b [ddc] Introduce a hot reload variant of "ddc" modules
These new modules are only used when compiling with the `--canary`,
`--modules=ddc` and no other module formats.

This new flavor of the module system treats the output .js files as
a bundle of one or more Dart libraries.

In this change the Dart SDK module is still compiled with it's
libraries mixed together but exports them individually. Ideally this
is temporary and eventually they can be compiled in isolation as
well.

All other modules are compiled in isolation so class hierarchies many
may be broken until proper cross library linking is implemented in a
followup change.

Change-Id: I27e58a445476198bd8613bb63c57cb96c0d5bc55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379261
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-08-20 20:14:36 +00:00
Nicholas Shahan 8aa1812082 [ddc] Create fork of compiler.dart
The fork (compiler_new.dart) will contain changes to compile libraries
in isolation even within the same module. It will eventually replace
compiler.dart.

Change-Id: I8b1c99895a6618ae6f8e8ed5173886e82ce6364b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379260
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-08-19 23:10:16 +00:00
Paul Berry 22656a40d3 Remove unreachable default clauses from module_builder.dart.
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(https://github.com/dart-lang/sdk/issues/54575). To avoid a bot
failure when the fix lands, this unreachable default clause needs to
be removed.

Bug: https://github.com/dart-lang/sdk/issues/54575
Change-Id: Iba0d32cf28f716f790c68a88b209420871845db8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380963
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2024-08-19 17:15:32 +00:00
MarkZ f6028e821a Reland "[ddc] Overhauling DDC's generic class representation."
This is a reland of commit e7658520bb

Fixes in the reland + context:
Type parameters emitted in implicit type checks on covariant mixin forwarding stubs may reference type arguments in anonymous classes. We reduce this to their mixin's implementing subclass to avoid generating RTI rules for anonymous classes.

Previous implementations would 'translate' type parameters to that of their mixed in type, but that strategy fails if the implementing subtype  shuffles the order of type arguments relative to its mixed in type (demonstrated in the test - though not actually relevant in the Flutter break).

Original change's description:
> [ddc] Overhauling DDC's generic class representation.
>
> Prior to this change, DDC represented generic classes as closures over type parameters (with type arguments provided at runtime), which tightly coupled generic class definitions with their types and concrete instantiation.
>
> This rewrite decouples this representation, letting us 1) bind type information late and 2) separate generic class definitions from their instantiation.
>
> Notable changes:
> - Generic classes are now declared at top level (rather than within in closures).
> - RTIs are now passed to generic class constructors at runtime (except for JS Interop classes). Only the instantiated class's RTI is required (and it's retained up the type hierarchy).
> - Type signature resolvers are now lambdas that accept a type environment RTI at runtime. While signatures are still attached early, their instances' RTIs are now needed at runtime.
> - Generic classes, constructors, and factories are now evaluated in a 'Class' type environment.
> - An `RtiTypeEnvironment` is introduced to represent lookups on an RTI type environment bound to a parameter. These are used when evaluating type signatures and at constructor/factory bodies.
> - Type recipes now emit Class type parameters with names - but continue to emit method type parameters with de Bruijn indices. This is because indices aren't stable across subtypes.
> - Certain debugger functions now require instances (e.g.,`getClassMetadata`).
> - Adds a special flag for non-external JS interop factory constructors to emit 'true' types (versus 'any').
>
> Change-Id: I7cbeaaf666dd4f9bd5e3ef22a1163a659fc0ee48
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365863
> Reviewed-by: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Kallen Tu <kallentu@google.com>
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Mark Zhou <markzipan@google.com>

Change-Id: I9b6f69b7150631f28442675c4230e093e3b821d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379511
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-08-13 18:15:38 +00:00
Devon Carew 89532d54ed [deps] rev package:lints to capture the unnecessary_library_name addition
Change-Id: I6ca4b0cef189248eac4d0898e8549424f2d889bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380180
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2024-08-13 17:04:13 +00:00