Commit Graph

5840 Commits

Author SHA1 Message Date
Srujan Gaddam 2973f37c9a [dart2js] Skip interop extension type object literal constructors during serialization
Fixes https://github.com/dart-lang/sdk/issues/57008

dart2js was mistakenly assuming the generated procedures for these
constructors are top-level external interop members and accidentally
generating invalid code. We should skip serializing these procedures.
This should be safe since any invocation of these procedures are
transformed in visitStaticInvocation.

Change-Id: If11c718bea8447b60de00b73f328a3cdd5544bda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393001
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-11-01 16:11:30 +00:00
Stephen Adams 9062cf4d75 [dart2js] Improve DominatedUses.replaceWith
When the instruction being replaced has many uses, it is beneficial to update them together, rather than one at a time.

Also:

- Make value_range_analyer output intermediate state for `--dump-ssa`.
- Remove bounds checks all together at end of range analysis.
- Don't add RangeConversion for the length when the length is a constant.

Compiling a method with 5000 assignments of the form `a[N] = N;` is reduced 20x, from 123 seconds to 6 seconds.

Bug: #56919
Change-Id: I9ca7b41ca156ee40b96cfed9e18369662053b3b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390824
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-10-23 00:35:20 +00:00
Stephen Adams b8a3da5c3e [dart2js] Fix constant hashing finalizer
Other instances of this algorithm use '^'.
Using '&' causes a few more hash collisions.

Change-Id: I933565fa2008f2c96337d26e95c82e5db8f615f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388425
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-10-08 18:39:22 +00:00
Kevin Moore 07fd58715c pkg-compiler: drop Pair class, use Record
Change-Id: I19b05ffc6bd8e87e58990a62a21b8a2986fe9f54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382760
Commit-Queue: Nate Biggs <natebiggs@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-07 17:55:44 +00:00
Mayank Patke e1ea58781e [dart2js] Convert side effects flags to enumsets.
Change-Id: I10c5ebe70d3f096a2c2e0cb5af7d69e6e13b9681
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387880
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-04 18:33:09 +00:00
Mayank Patke 03c01908f2 [dart2js] Convert compact flags to enumsets.
Change-Id: I79aba08aafa41fdde57ab0268376bf4f158179df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386827
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-10-04 18:33:09 +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
Mayank Patke 8fda05e2fd [dart2js] Remove redundant clone method from EnumSet.
Change-Id: I5ee35d9d66072a3838113e5686b40b5f7bc1dd02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386605
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-09-24 22:21:38 +00:00
Nate Biggs 755db057ff [dart2js] Fix record FieldGet receiver type update.
We should be updating the receiver record's type regardless of whether or not we have a specific record type.

Bug: https://github.com/dart-lang/sdk/issues/56741
Change-Id: I16ce9f1db96c295566be802211c7280917416924
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386262
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-09-23 19:48:07 +00:00
Nate Biggs 1d392255ef [dart2wasm] Add wasm module test mode.
Adds a mode that puts every library (outside of the SDK) into its own wasm module. Each module is then loaded before the program executes.

This allows us to get better coverage on multi-module logic.

I chose to augment the SDK `_invokeMain` entry point because it allows us to push the user-defined main into a second module ensuring we always have at least 2 modules. The SDK alone is then the main module and all user-code is in deferred modules.

The next step is to make a test configuration for this and decide what frequency to execute it with.

Change-Id: I01bf3a5fee4604a890ef376ebd35113281a36a5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384404
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-09-23 18:56:24 +00:00
Nate Biggs b28913c7e1 [dart2js] Make 'load-priority' pragma pass an arbitrary option string.
Change-Id: I4d9fb69dfb4ec040b0e63893e4ace33c6a5dd454
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384360
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-09-09 19:47:48 +00:00
Mayank Patke 0aee974736 [dart2js] Document/assert that enumset indices must be less than 64
Change-Id: I8b4b1c296fe11044e69221c020a7b1b3abbd9275
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384042
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Auto-Submit: Mayank Patke <fishythefish@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-09-06 20:14:59 +00:00
Mayank Patke 1031795c61 [dart2js] Convert static use flags to enum.
Change-Id: I137c9cbd865fb9944d4d326f5d73f9f09a6e2505
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383900
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-09-06 16:20:37 +00:00
Mayank Patke 15366a10b7 [dart2js] Convert EnumSet to an extension type.
Because the old EnumSet was a wrapper object, some APIs performed
stateful updates. This CL also ensures that callers are now performing
their own state updates, just as if we were manipulating ints directly.

Change-Id: I305cd42b5e0c9395d1d1dac724a108bf083ab0d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379510
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-09-06 16:20:37 +00:00
Stephen Adams 2afecb210b [dart2js] Register legacy classes if instantiated in JS()
This change makes sure that

    JS('JavaScriptFunction', '...', ...)

actually registers `JavaScriptFunction` and its superclass `LegacyJavaScriptObject` as instantiated.

Bug: #56533
Change-Id: I977f149cff97b0a5f42d69f303664f5a70cb401c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381820
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-22 19:44:08 +00:00
Stephen Adams 9162f0f9c9 Reapply "[dart2js] Make more use of kernel's static type"
This reverts commit f9aec1c997.

Change-Id: I731b29714797fbea38da09ed48a0dd4852af986b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379669
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-15 18:58:55 +00:00
Stephen Adams f9aec1c997 Revert "[dart2js] Make more use of kernel's static type"
This reverts commit 1057e5575f.

Reason for revert: Breakage in product test

Original change's description:
> [dart2js] Make more use of kernel's static type
>
> This change helps with one hang-over from Dart 1.
>
> In code like `a[i] == 1`, the type of the indexed element was inferred
> as the element type of `a`. This was great if `a` was a traced List,
> but too general if the provenance of `a` is unknown, since the general
> element type over all lists is 'top'.
>
> Dart 3 gives much better guarantees than Dart 1. We can now rely on
> the front-end inferred type for `a[i]`. To do so, we track the
> abstract value contraint for the type through SSA so that SSA-level
> type propagation can re-apply the constraint.
>
> This removes about 100 interceptor calls from the main unit of some
> large ACX apps.
>
> Change-Id: I6839a6045d9341633c08678affb35fdb2998a96d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379145
> Reviewed-by: Mayank Patke <fishythefish@google.com>
> Commit-Queue: Stephen Adams <sra@google.com>

Change-Id: I5e2b9fde9ffd7d79332fd493649e8f342219c8ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379667
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-08 22:14:38 +00:00
Stephen Adams 1057e5575f [dart2js] Make more use of kernel's static type
This change helps with one hang-over from Dart 1.

In code like `a[i] == 1`, the type of the indexed element was inferred
as the element type of `a`. This was great if `a` was a traced List,
but too general if the provenance of `a` is unknown, since the general
element type over all lists is 'top'.

Dart 3 gives much better guarantees than Dart 1. We can now rely on
the front-end inferred type for `a[i]`. To do so, we track the
abstract value contraint for the type through SSA so that SSA-level
type propagation can re-apply the constraint.

This removes about 100 interceptor calls from the main unit of some
large ACX apps.

Change-Id: I6839a6045d9341633c08678affb35fdb2998a96d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379145
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-08 00:30:48 +00:00
Stephen Adams e28c480e12 [dart2js] Use addUnused method for unused fields in proto shaker
The call to the new method has fewer arguments, which helps code size.

Change-Id: I50668e54bfba07ac34e8db99a748f7d83c6e5be4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378382
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-08-06 21:58:29 +00:00
Mayank Patke ab8e382d26 [dart2js] Add source information to interop null checks
Change-Id: Ib81199030680160e215321f9460d7bac24489763
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378903
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-08-06 20:52:19 +00:00
Srujan Gaddam ae3dbcdfb1 [dart:js_interop] Add toJSCaptureThis
Closes https://github.com/dart-lang/sdk/issues/54381

- Adds an API to capture the this value so that users
can use it in the callback.
- Adds specialized stubs to dart2js similar to what was
done for toJS.
- Adds generic stub to DDC as these stubs don't get
tree-shaken away and toJSCaptureThis is less likely to be
used.
- Modifies dart2wasm lowerings to add this to the JS
function wrapper if calling toJSCaptureThis.

Change-Id: Ic0a7fd768de1dd6b491998e029ff5eb406ee7992
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377160
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-01 01:02:47 +00:00
Stephen Adams 175dc05db3 [dart2js, pkg/vm] Recognize more BuilderInfo methods.
An upcomming change to protobufs adds a few more BuilderInfo methods
that 'define' fields.

TEST=existing

Change-Id: I78be355ea1458a6a0f2619c63e3ff5838b527533
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377742
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-07-29 20:54:38 +00:00
Nate Biggs 629d170962 [dart2js] Fix inference tracing closures through non-method members named 'call'.
Change-Id: I8619343f9d5ff1e64ecc84c549eda400bbce31dc
Fixes: https://github.com/dart-lang/sdk/issues/56293
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376880
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-07-22 17:48:50 +00:00
Mayank Patke 37e351db10 [dart2js] Don't overwrite type in _invokeJsInteropFunction.
Discarding the nullability caused us to assume that interop checks were
always needed below.

Bug: b/353690007
Fixes: b/353690007
Change-Id: I085f98c06d2e91412c5c6e795359eb2df4d84d5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376124
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-07-17 21:53:48 +00:00
Stephen Adams 15792df87e [dart2js] Use indexes for operation names and verbs
Change-Id: Ic954a7e20062aa8bf1c0f622ee9b0656bc563ba5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375024
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-07-15 02:18:52 +00:00
Nate Biggs ae34c07b94 [ddc] Move async_status_codes to shared sdk library.
This will allow DDC and dart2js to share these values for their async systems.

Change-Id: If6eef5de535cdf55e10adca3b2de11c408df4070
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374520
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-07-12 16:05:19 +00:00
Mayank Patke 62b17a59f4 [dart2js] interop null checks: ensure member return type is non-nullable
before adding check in caller

This wasn't needed when the required null checks were keyed on member
entities. Since we now use selectors as keys instead, it's possible for
a selector to be marked as requiring caller-side checks even though not
every associated member requires one.

Change-Id: Ibe4be750e4d3dd02f97e8d27efa29a1c7904e2bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375420
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-07-11 20:38:24 +00:00
Stephen Adams e66a0cbde8 [dart2js] Unmodifiable Array and typed data using flags
- Add SSA HArrayFlags{Check,Get,Set} instructions to check for
  fixed-length and unmodifiable JSArray and JavaScript typed data
  instances.

- Add optimizations to remove redundant checks.

- Added HOutputConstrained interface for instructions that must have
  the input and output in the same JavaScript variable. This
  generalizes some code generation logic already applied to HCheck.

Bug: #53785
Change-Id: I61750dd03aa3a964eed3bc76e1656c5f60f77109
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372002
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-07-10 01:39:58 +00:00
Stephen Adams bd290e8d87 [dart2js] Use representation type of record if available
Change-Id: I48f5d8d3f020e6f9d2b69eea1ad9f1e991a66f6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372861
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-07-09 23:30:49 +00:00
Johnni Winther c17e9c116e [cfe] Clean up backend imports
This updates backend imports to use reexports from api_prototype
or api_unstable.

TEST=existing

Change-Id: I8d9d1c76ef72c709c578acac5497064710ee5579
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373462
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-07-08 11:32:30 +00:00
Mayank Patke b64c64012f [dart2js] Remove asserts in ConstConditionalSimplifier
Fixes: b/349652368
Change-Id: I0d5cad6a55cba6b31d8a352d278daf844db95efb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373328
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-27 19:12:02 +00:00
Johnni Winther 8df57398c9 [cfe] Move src/fasta/ subfolders to src/
Part of removing uses of 'fasta'.

TEST=existing

Change-Id: Ice027678e11b7da8c1a7e756a1e1c8c8284722bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372623
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-06-25 10:05:21 +00:00
Mayank Patke 56851e50e2 [dart2js] Restrict instanceof is-test specializations to non-generic
types when SNS checks are enabled.

Change-Id: I759a4ba77b74f6e0ec7c7ec65ad3ca37ed8410a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372201
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-06-24 20:52:43 +00:00
Stephen Adams 0db3b1215c [dart2js] Use patterns for HIndex simplifications
Change-Id: I8a1e888da1d976ae80effc220a41243ff85ee4f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372001
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-18 23:19:28 +00:00
Mayank Patke d430e7ab55 [dart2js] Remove memberContext from getConstantValue.
Change-Id: I3ed4343c7cd2880414a8e99361d8017ca9f756a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372160
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2024-06-18 18:31:58 +00:00
Stephen Adams 3a91bcb39e [dart2js] SSA - pre-assign variable to reduce phi assignments
Introducing a partial redundancy with a variable with a longer
live-range can reduce the size of the emitted code.

Flute.complex (-O4): -0.377%
cm_shell (-O4): -0.029%

Change-Id: I0d03119b17f4b58d61f277bf8bb0e57d8e7c47c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360360
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-06-17 22:47:57 +00:00
Stephen Adams 77496338dc [dart2js] Constant-fold const record accesses
I noticed that dart2js generated poor code for `(a, b) = (1, 2)`.
This is due to an oversight in not constant-folding record field loads.

Change-Id: Iac110d8c3373d7673c21494fc467f7fcb400de1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371505
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-17 19:47:34 +00:00
Nate Biggs b9b4d616a4 [dart2js] Fix record field get receiver type serialization.
Internal users reported a compiler crash when using sequential compilation. Their change involved adding a class hierarchy in which the constructor of a superclass included a RecordIndexGet. When analyzing the constructor of the subclass we also analyze the body of the super constructors.

In this rare case the member being analyzed does not match the member containing the receiver node. Usually calls act as a layer of indirection that we do not analyze across.

When we then save the type of the receiver, we do so in the context of the wrong member (the subclass constructor rather than the superclass constructor). We just have to be more careful to use the correct context member.

The added test fails prior to this change.

Change-Id: I8b9a3b8a7692b8604d5c37c59b94bb8d46afff75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371580
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-14 19:17:14 +00:00
Mayank Patke bf83cc30ed [dart2js] Convert VariableUse to a sealed class hierarchy.
Change-Id: I28d71d81031e3e6eefc2b4f6decfe375099a1c32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371185
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-13 23:01:34 +00:00
Mayank Patke 0ddba91190 [dart2js] Convert SubclassResult to a sealed class hierarchy.
Change-Id: I151c2f6f72dcecaff6a6976f058940b9ddf97f47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371461
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-13 19:25:28 +00:00
Mayank Patke ad3a1a72fd [dart2js] Convert IsTestSpecialization to sealed class hierarchy.
Change-Id: I08552d4dda928259be56e0b99f9f002baeb4d6b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371240
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2024-06-13 18:21:59 +00:00
Mayank Patke ca3e67a3b6 [dart2js] Add --interop-null-assertions.
This CL adds a new --interop-null-assertions flag (cf.
--native-null-assertions) with the goal of validating that JS interop
APIs with non-nullable static return types do not return null values.
This flag is currently disabled by default but is intended to assist in
sound null safety migrations.

In general, we don't guarantee type soundness of package:js interop
since users can write incorrect static types which are not backed by
any runtime checks. However, it is likely that during the null safety
migration, some interop APIs which should have been made nullable
weren't. Therefore, we want to offer some additional (but limited)
checking for this case.

For static invocations of functions with non-nullable return types, we
can simply perform a null check on the result of the call.
For instance methods (which could be invoked virtually/dynamically), we
want to perform a null check on the return value in the callee (the
interceptor method) itself when possible.

It's possible for multiple interop bindings to share the same
interceptor method. We produce a null check in the interceptor method
body if all the methods have non-nullable return types. Otherwise, we
insert checks at callsites when appropriate.

Change-Id: Ifd155d7f8326152b6d57d61199e0b7973c4a1211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369784
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
2024-06-12 21:28:23 +00:00
Johnni Winther ce12e3c8ac [cfe] Remove isNonNullableByDefault from class hierarchy
Change-Id: Ib5942357578a6481e8038dd090e4a9d9ff49f831
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369022
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-06-03 06:42:54 +00:00
Johnni Winther 1315b3ab72 [kernel] Remove isNonNullableByDefault from checkBounds and instantiateToBounds
Change-Id: Ie1faa72cd1d9eaae65e1fb2fd44bf7a70b94a025
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368641
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2024-05-30 13:51:46 +00:00
Nate Biggs a52acf1ff2 [dart2js] Fix memory regression in closed world due to member/call pattern on wide type hierarchy.
If the enclosing class is a leaf node search for live matches in "canHit". Do this by iterating the class hierarchy starting at the enclosing class of the element and checking the supertype to see if they're included in the constraint set.

Change-Id: If859bbca1d2744303c03ac91d1601a05c61dfc2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367220
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-05-23 21:02:51 +00:00
Stephen Adams cdf35f8782 [dart2js] Simplify access of multiple type variables from same environment
The change adds a new reduction that recognizes the construction of a type environment from components

    HTypeBind(HTypeEval(env, e1), HTypeEval(env, e2))

and replace with an equivalent expression that constructs the same derived type environment directly

    HTypeEval(env, ...e1...e2...)

This change speeds up the benchmarks that iterate `Map.entries` by roughly 10-25%.

---

Type arguments are passed as separate values [1]. This means that the generative constructor factory `MapEntry<K,V>(this.key, this.value)` has four parameters - `MapEntry$(key, value, $K, $V)`. The passed arguments usually come from the same place, perhaps extracted from the type of the current object, `this.$ti._eval("1")` and `this.$ti._eval("2")`.

Inside `MapEntry$`, the type parameters are re-assembled into a type environment:

    $K._eval("@<0>")._bind($V)

which is used to construct the object type

    $K._eval("@<0>")._bind($V)._eval("MapEntry<1,2>")

After inlining:

    $K = this.$ti._eval("1");
    $V = this.$ti._eval("2");
    $K._eval("@<0>")._bind($V)._eval("MapEntry<1,2>")

After GVN, and reducing the adjacent `._eval("1")._eval("@<0>")` to `._eval("@<1>")`:

    t1 = this.$ti
    t1._eval("@<1>")._bind(t1._eval("2"))._eval("MapEntry<1,2>")

The new reduction gives us:

    this.$ti._eval("@<1,2>")._eval("MapEntry<1,2>")

which can be reduced further by combining adjacent HTypeEvals:

    this.$ti._eval("MapEntry<1,2>")


[1]: It would be better to pass the type arguments as a single Rti object to avoid the extract-recombine pattern, but changing the calling convention is a more extensive change. In the meantime, this reduction cleans up the extract-recombine pattern when inlining brings the parts together.

Change-Id: I28801ce5d952d0f4e5ac1d55c252766159dcceef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367240
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-05-23 16:45:00 +00:00
Sam Rawlins 2e53eada36 compiler: replace unsupported [this] comment references with this.
Work towards https://github.com/dart-lang/dartdoc/issues/3761

Sibling CL to https://dart-review.googlesource.com/c/sdk/+/365204

The analyzer has never recognized `[this]` as a valid doc comment
reference (and the `comment_references` lint rule has similarly
reported such reference attempts). dartdoc has its own algorithms
for resolving comment references, which we are dismantling in favor
of a single resolution, provided by the analyzer.

We've also decided against adding support in the analyzer (see
https://github.com/dart-lang/linter/issues/2079), so these
reference attempts should be re-written.

Change-Id: I0a30a34c9f58bd6c98c6b83e607a973c9ba51ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366900
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2024-05-16 20:20:34 +00:00
Johnni Winther ae03b57cbb [cfe] Remove .isNonNullableByDefault from package:kernel
This removes the .isNonNullableByDefault properties and similar from
the AST nodes in package:kernel. NNBD is now always enabled so these
properties are trivial.

TEST=existing

Change-Id: I75ca0551ac4b5910ea63530dd0c9c2e68bd01aff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366320
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-05-15 08:31:38 +00:00
Nate Biggs 6118b2f590 [dart2js] Fix missing offset logic from indexed sink source.
See https://dart-review.googlesource.com/c/sdk/+/363541 for more context.

Change-Id: Iaf681101410a2505376e0522bf1228035c088028
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364080
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-04-24 17:46:39 +00:00
Nate Biggs 8f6dd1ad3a [dart2js] Handle serialization offset address spaces larger than 2^29.
The dart2js binary serialization infrastructure only supports 30 bit integers with the "writeInt" method. The indexing infrastructure uses 1 of the bits to store locality information leaving 29 bits to encode the address space.

The recent dump info changes expanded the address space of some large programs beyond this 2^29 and is causing some serialization issues when trying to generate dump info.

The solution here is to check when an address is above 2^29 and instead encode the offset as a uint32. This will use 5 bytes for these large values (1 for the large offset indicator and 4 for the offset itself). By doing this we expand the address space to 2^32 which is more than enough to support larger programs.

An alternative would be to use some bits from the indicator and encode the rest in a separate 30-bit int. This would allow us to represent an address space closer to 2^60. But we would need to use an extra bit to differentiate the indicator and an actual offset. Which would reduce the base address space to 2^28 causing us to hit the more expensive 5-byte case earlier and increasing total write size. No known program is anywhere near the 2^32 address space size so the larger address space is not necessary.

Change-Id: Icbed2961099842ebf286b36314e8d6fab7389db4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363541
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-04-19 06:03:01 +00:00