Exposes two new methods `hotRestartBegin()` and `hotRestartEnd()` in
the `DartDevEmbedder`. This provides a more customizable loading
of sources across the variety of environments we are supporting.
Change-Id: Id7a35695234f0625fe4de1d67c9d5a8055bad461
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500240
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
The current conditions make it so that every library transitively reachable from a reload target (and therefore included in the DDC output) must be known in the client when `dartDevEmbedder.hotReload` is called.
While this is the case for pages running with DWDS, it's an unnecessary constraint. Some users may only care about reloading a specific subset of known libraries. As is the case in dart-pad when we only need to reload the main library as we know this is the only code that can have changed.
Any new libraries must also registered and initialized as this is new code not yet in the page. This would happen if a new import was added to the code.
Change-Id: I164f59a6931fd809867716c164cb467880806f8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432440
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
It is possible with the way the library manager is written
today that during a hot restart, a previously defined library
may be initialized. Because the manager uses the same map
to store the initializers for the non-hot restart case and
the hot restart case, we may end up using a newer version of
code in an older generation. Instead, this CL adds a pending
map that stores the hot restart initializers so that we can
later add them to the general map of initializers right before
we call main during a hot restart and during synchronous code.
This should avoid that race condition.
Change-Id: Ib40cbe5bec400035276ebd6fca12efed7077a2b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425190
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
- 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>
d8 tests weren't executing code after a hot restart due to several factors:
1) subsequent calls to `main` after a hot restart weren't being added to an event loop.
2) periodic timers, which use `setInterval` weren't updated to check for the hot restart generation.
3) d8's simulated timers run synchronously, which interacts poorly with our async implementation. Periodic timers never cede to the async task that handles changing hot restart generation, so they would run forever whenever an error was thrown.
Changes:
* Added a helper to d8.js that cancels all timers.
* d8 now cancels all timers if an async main registers an error (via a handler on main).
* `setInterval` is now implemented.
* The embedder now accepts a publicly modifiable config object. `capturedMainHandler` and `mainErrorCallback` can be set via this object.
Change-Id: I523752ea69e8fd1f1ec0f6f585a484b670534cfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421680
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
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>
Match the behavior of the ddc module system when running the
applications main method when using the new library bundle format.
This passes an empty JavaScript array to the main method which is
good enough to get the benchmarks that use main method args to run.
The API should be updated in a way that allows you to actually pass
a JavaScript array of Strings when starting the program.
Issue: https://github.com/dart-lang/sdk/issues/35113
Change-Id: I1a9aeb1df7afa5948d7f23517b3ac913aaabb62c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408640
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
When running in an iframe without specific flags, DDC may not have access to `localStorage`. In this context, even trying to access `window.localStorage` can cause an exception in the iframe.
Wrapping the check in a try/catch allows us to safely check for access before using it.
Change-Id: I0c5d3d0ac34a550444c12b52f6519a9446ebfe9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405608
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
This is used in bootstrappers to set a source map provider
within stack_trace_mapper.dart so that stack traces can be
mapped to their Dart equivalent.
Change-Id: If7dd7024cf8928f1b3a127599015107fcbafb2f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405245
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
* Adds tests for the memory filesystem
* Enables hot restart/reload tests
* Adds flags to the hot reload suite
* Makes path resolution logic windows-friendly
* Adds test-reporting logic for trybots to hot reload tests
Change-Id: Ic51a0b8a3c6f8b6de20b58b2ac185dacf444cf47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353788
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
The hot reload runner currently only supports d8, but I plan to add support for Chrome and VM execution.
Notable changes:
* Creates `package:reload_test` with helpers for running this suite.
* Updates the module loader with D8-specific branches and hooks for hot reload/restart.
* Exposes DDC runtime variables via a `HotReloadTestRuntime` API.
* Ports constant equality hot restart tests from webdev/dwds (validated to fail if either cache-clearing mechanism fails).
* Partially rolls DDC's d8 preamble forward (towards dart2js's).
* Wraps D8's timer implementation with custom timeout logic to better match Chrome's timing semantics when executing with native JS async.
Tests for the framework and matrix updates will be added in an upcoming change.
Change-Id: I2773b29f464cfd0330e4c653c05e117ae150b4a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350021
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
This is part of a series of CLs to enable real deferred loading in DDC.
- Creates a new top-level object in dart_library.js for holding the state/API
for deferred loading.
- Only supported in the DDC module system
This also contains a bunch of cleanup/comments for our internal JS Linter. Notably, 'var' is not allowed, so we're attaching our top level namespace objects to `self`.
Change-Id: I230d63f044e85e7d16644525ff79fa9522398c87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289400
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
- Copy the internal version of dart_library.js without any changes.
- Unblocks syncing this file again.
- Update ddb script to use the dart2js preamble for d8 which includes
assignment of a global `self` and the fake event loop for better
error handling.
Change-Id: I01c2ad82fe7c36bb393f9eab897f558daabf6b8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181522
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Just some preliminary formatting to make it easier to see the diffs
when I merge the changes from the version in google3. The diff
algorithm gerrit uses doesn't handle the change in indentation very
well.
Change-Id: I2a4daa50d0051140569d51bea5845a0366ba1dad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180700
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This change makes dart_library.js more resilient so it can run in a
browser or in d8.
This is a necessary step to later enable test.py dartdevk tests in d8.
Change-Id: Ic8e5bbc9f1bbc6707a876208605f4fcaad41cee7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177000
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
- Fixes broken benchmarks in ddc because the benchmarks run in
d8 with the ddc module system can handle conflicting library
names more gracefully than es6.
- In the future we need to update the source of truth for
dart_library.js so we can keep the file in sync.
- Removes the ability for ddb to run with any precompiled sdk.js
from a dart installation. Now you must run a build first and
the sdk.js files from that build will be used. This means the
`--debug` flag no longer changes which sdk.js files are used.
Change-Id: Icaf78956f93ff643d23e68001354ec08c9c28b12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166926
Reviewed-by: Mark Zhou <markzipan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This adds a method to the internal SDK runtime library that can be
called to clear state when a hot restart is desired.
This also refactors some of the logic around ignoring type errors,
as we need to ensure we can clear those caches. Also I noticed a bug
where the result of isSubtypeOf was assumed to be non-null, but this
was not the case. The new structure should make this more clear.
(Note: I think we may be able to remove a lot of the code for ignoring
type errors soon.)
Change-Id: Icf5072ffe21aefd85e9816ffc2fc29f679839bc4
Reviewed-on: https://dart-review.googlesource.com/c/78324
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jenny Messerly <jmesserly@google.com>
This involves a few main pieces:
- Add code to the GN scripts to generate DDC's patched SDK and then
compile it to summaries and JS in the build output directory.
- Add support to the underlying DDC build scripts to support controlling
which files are built where.
- Update test.dart to use the DDC SDK from the build directory.
- Update create_sdk to use the built SDK instead of the checked in one.
- Fix various internal DDC tools to build their own copy of the SDK
(since they can't easily find the one in the build directory because
it's path if config-specific) and use those.
- Delete the checked DDC SDK JS and summaries.
I think I got everything working. The built Dart SDK looks fine -- it's
identical to one built using the old build scripts.
The various tools and DDC's little test runner I *think* work, but there
may be a bug or two in there. I tried the various things I could and it
seems like they work but it's hard to tell since they may be kind of
broken right now anyway.
Bug:
Change-Id: Iea77915a5c1cc8450f60ebfbdf8c725c7ea2f32c
Reviewed-on: https://dart-review.googlesource.com/18144
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>