Constant Sets now have their own classes rather than being constructed as a wrapper over a const Map. The new scheme is similar to Maps - using a ConstantStringSet backed by a JavaScript Object 'dictionary' when the elements are all suitable String values, otherwise using a GeneralConstantSet backed by a list of elements that is converted to a lookup map on demand.
Constant Sets and Maps with suitable String keys are backed by a JavaScript Object literal 'dictionary'. The use of the Object literal has been changed so that the property values are no longer the values of the Dart Map, but the position of the key in the order of the entries. The values are provided as a List (Array), so there is an additional indexing operation to access the value on lookup. This does not seem to affect performance.
The advantage of the two-level lookup using the 'dictionary' is that Maps with the same keys (in the same order) can share a 'dictionary'. In order to achieve the advantage, the JavaScript Object is modeled as a first class ConstantValue - JavaScriptObjectConstantValue.
These changes achieve a code size benefit of -0.90% (~130K) on the main unit of a certain large app, and -0.35% for flute/benchmarks/lib/complex.dart
Change-Id: Icad2e6136218486a439e3c5ed0296462e3c3c4e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310020
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Calls to methods annotated with `@pragma('dart2js:resource-identifier')` are tracked, with their primitive constant arguments, through to the `.js` file which contains the call.
- JavaScript annotations are attached to the JavaScript AST node for
the call.
- At the time of `.js` file printing, the JavaScript annotations are
collected and attributed to the file. This allows the construction
of a map from `.js` files to the 'resource identifiers' contained in
the file.
- Alongside the `main.js` file the resource identifiers are emitted in
a file called `main.js.resources.json`. This is controlled by the
`--write-resources` command line option.
- Serialization of JavaScript ASTs now serializes the attached
JavaScript annotations.
- The internal method used to implement deferred library loading is
annotated, to allow analysis of which deferred library parts load
other libraries.
pkg/js_ast was tweaked to make the pkg/js_ast was tweaked to make the
- pkg/js_ast was tweaked to make propagating the JavaScript annotations through the async transforms easier.
TODO:
- Annotate const constructors
- Add golden-style tests
Change-Id: Iea77550e22ee98f81dca61dfd713c09f734583d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284492
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
'Annotations' allow client information to be attached to js_ast nodes.
I will be using this facility to embed resource identifers in the generated JavaScript AST to generate a map from files to the resource identifiers that they contain.
Change-Id: Id9012b303de0d2b3848a635bc34747f8c5101236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281320
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
See patch 2 for failures coming from this new analysis option.
Change-Id: I6bb10c2eb12431f6c503cc817a9c9bb45ba597a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269800
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
It should not be necessary to ever run `pub get` for a package which is
not published. All packages used in the SDK are controlled by a single
package config, so it's not necessary to declare versions or paths for
any packages.
Remove all dependency overrides.
R=devoncarew@google.com
Change-Id: Icb328813b471f35ee4c99995f4e90aac4d8ed438
Tested: Covered by existing static analysis.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244767
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Some JS functionality is only exposed through operators, such as
implicit type conversions and BigInt arithmetic. Other than requiring
some minor additions for the exponentiation (`**`) operator, supporting
these through `dart:js_util` is trivial.
Change-Id: I010674303e4f99b42d43b73095de69b8ddcdeb47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242680
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
These are now enforced in pkg/js_ast so we don't need to worry about
introducing unwanted diffs between the forked versions.
Change-Id: I89efc97f53a433f98e2a06747690ac7a635c388d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239560
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
This will allow more gradual migration of js_ast.
Change-Id: I3e948ad5c79fa9880b7eb3bccd7c15cbf9786e32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238660
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This won't promote for a nullable field `foo`, so use `?.`:
if (foo != null) foo.accept(this);
-->
foo?.accept(this);
Change-Id: I0f3c92803f8756c44a959d17dfe29b12f9db362c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238501
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reduce the number of diffs between pkg/js_ast and
pkg/dev_compiler/lib/src/js_ast
Change-Id: Ic00e1614b23e11118383e954a0ee31365d65ebe6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238388
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
* Add team "groups" in tools/OWNERS_<group name>.
* Add top-level OWNERS as a fallback.
* Add OWNERS for all top-level directories.
* Add OWNERS to all packages.
For additional background information see go/dart-sdk-owners.
TEST=No op until code-owners is enabled.
Bug: b/200915407
Change-Id: I7fe6116cc599c749cd50ca16151d6d6a801d99d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229147
Reviewed-by: Jonas Termansen <sortie@google.com>
`BaseVisitor<R>` has two methods that return `null`, which will not
match the generic return type with NNBD.
The fix is to make the methods abstract, and provide a convenience
specialization `BaseVisitorVoid` with the default methods.
Change-Id: I62cd69c5ed1c912b2804da5044e2cda93d70b878
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224460
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
At the end of codegen, 'trace' the generated JavaScript to the `.cfg`
file, and 'trace' the JavaScript after the generator rewrite when this
happens. This gives an easy way to see the non-final JavaScript from
before the transform. The 'trace' of the JavaScript is a little bit of
an abuse of the `.cfg` file format, but it is convenient to see the
SSA CFG and JavaScript with the same tool.
For this to work, js_ast printing needs to work for pre-finalized
ASTs. Most of this change is implementing `isFinalized` for every AST
node, and printing something indicative of the non-finalized nodes. For
example, unfinalized holders are printed as `Holder"<something>"`.
Change-Id: I30b3f141a876f1dc3539132d65f3aafc722589e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218883
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Formatted with `--fix`, followed by some small manual changes:
- Reflowed some comments to 80 columns.
- Replaced Map/Set constructor calls with {} literals.
- Removed type argument when on both sides of initialization.
Change-Id: I3f5d29dd7e144f96a02efa95db8b40bf63484442
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210940
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Also fixes some minor typos from the initial implementation change.
Change-Id: I6c17ff94009298f6ab4e1d9fbdb88db633ae8aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203285
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
* Adds a couple of arrow function and method tests
* Does not add support for method interpolation (like in DDC).
Change-Id: I73ccbbf2907611dae6f1720f7933e3469d4eb9b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198883
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
- Increase SDK requirements to allow Set literals
- Fix analyzer errors in test
TBR=fishythefish@google.com
Change-Id: I02fa18b6fc280cf74d6f7da7d2d24ff7dca806f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201082
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
The old way was for the JavaScript string literals to be pre-escaped.
This was cumbersome since each place that creates a JavaScript string
literal needs to make a decision about whether escaping is needed and
the kind of escaping (UTF8 or ASCII).
This change moves the responsibility for escaping into the js_ast printer.
The escaped text exists only while printing, which reduces the heap in a
large modular compile link scenario by 220MB, since the unescaped string
is in memory anyway.
There were three kinds of escaping - ASCII, UTF8, and 'legacy', if not
specified. This has been reduced to ASCII (default) and UTF8, chosen by
a printer option.
Change-Id: Ic57d8fb70a213d3518244f1a152cd33e54103259
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200400
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
- js_ast.Name is no longer Comparable
- _NameReference is used on demand rather than for every occurrence.
This saves 50MB in the big link scenario.
- remove unused asVariableUse() method
Change-Id: I37f55044d394b7e047ca88c527641471bc94c641
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198981
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
LiteralExpression used to be the mechanism for 'interpolating' the
`JS` pseudo-function, but that long ago was reimplemented via the
js_ast template feature.
There are a few vestigial uses of LiteralExpression, but as none of
them use the `inputs`, this field is removed.
Change-Id: I4cd7c64766a7d6d9dd2c196c134bbfcb536fd2f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178400
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Emphasize that the operation is going away,
and mark constructor as deprecated.
TEST= Refactoring+deprecation only, covered by existing tests.
Change-Id: I82aa044cd2cf7bf347b624371399f44bda8f4a07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173261
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
The serialization/deserialization is performed in test-mode.
Change-Id: I90f31a6a88dbdf2c38beb9b5409ce3c52557e227
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102740
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>