Commit graph

88731 commits

Author SHA1 Message Date
Nate Biggs 531e356587 [dart2js] Migrate ssa/value_range_analyzer.dart to null safety.
Change-Id: I20d5d55c9a31f87bcb517e8d416ff01a712e0c4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274320
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-12-08 18:12:27 +00:00
Ryan Macnak 0150cddace [vm] Fix call-through-getter runtime handling.
This should look for `dyn:call` instead of `call`. If it was a non-dynamic call, we would hit an invoke-field-dispatcher instead.

TEST=ci
Bug: https://github.com/flutter/flutter/issues/116405
Change-Id: I98c441fec2eb53ab23ac1dd52db3aa4eaa5cbc6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274265
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-12-08 17:48:49 +00:00
Daco Harkes 1d567c888f [vm] Remove use of CastError
`CastError` is replaced by `TypeError`.

Also makes the fields of TypeError nullable. See:
https://github.com/dart-lang/sdk/issues/49279

TEST=build SDK and run default suites.

Bug: https://github.com/dart-lang/sdk/issues/49529
Change-Id: I7e880ff2d8b18c4bffdd7a942efd743244a12734
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274381
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-12-08 17:07:33 +00:00
Aske Simon Christensen 96e2e55300 [dart2wasm] Fix a build error caused by colliding commits
Change-Id: Icc6c22896def0183766bb23dc2ca978fe15430ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274441
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-12-08 15:48:01 +00:00
Danny Tuppeny c53f70509c [dds/dap] Filter private getters from debug views
These will fail unless the current stack frame happens to be in the library that declares them, which results in a lot of exceptions being shown in variable views.

Fixes https://github.com/Dart-Code/Dart-Code/issues/4296.

Change-Id: I5919e391f25a08920dcdf1bf648526d175af00f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274040
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2022-12-08 15:02:04 +00:00
Martin Kustermann cdd0694a92 [gardening] Make qemu configurations get 2x the time
Running tests under qemu simulator are slow. To prevent tests from
flakily going over the timeout limit, we give them 2x the time.

Change-Id: I41f771d5b958d11d073fd9808663b0b9f298ad9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274384
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-12-08 14:08:09 +00:00
Aske Simon Christensen a22e0ac5ea [dart2wasm] Compute correct type for generic function instantiation
Change-Id: I3811e37002ed6ae458600513bff3ac29482a6af3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271104
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-12-08 13:54:57 +00:00
Aske Simon Christensen 8c717be409 [dart2wasm] Emit correct runtime type for tear-offs
The static type of a tear-off is the signature type of the method.
The runtime type is the same with the types of all covariant
parameters replaced by `Object?`.

Change-Id: I9bb36a36ec04e27deab2b31c977fadac515ad561
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273845
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-12-08 13:54:57 +00:00
Aske Simon Christensen ad06d73ace [dart2wasm] Use a flat index space for function type parameters
The current two-level indexing scheme for function type parameters
(depth and index) breaks down in the case of type substitution when
the substituted type is a generic function type, since its internal
type parameter types have been encoded assuming that the function type
had nesting depth zero, but after substitution its nesting depth can
be higher.

Relative indexing schemes such as De Bruijn indices will also not
work, since function type parameter types are constant types, and the
constant infrastructure assumes that the same constant always has the
same representation.

This change introduces a flat indexing scheme where function type
parameters are indexed using a single index which is independent of
the context in which the type parameter type appears. To avoid
collisions in the case of nested generic function types, every function
type has a type parameter offset, which conceptually shifts the
indexing range of its type parameters so it doesn't necessarily start
at zero.

Looking up a function type parameter in its environment thus involves
searching outwards until a function type is found whose type parameter
index range contains the index encoded in the function type parameter
type.

Change-Id: I544056d52711ff829b170f78a7274a93871825a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272361
Reviewed-by: Joshua Litt <joshualitt@google.com>
2022-12-08 13:54:57 +00:00
Aske Simon Christensen f72f2e92d5 [dart2wasm] Re-enable async tests that no longer time out
Issue: https://github.com/dart-lang/sdk/issues/50122

Change-Id: I311c7a709e74381c84cb9c42cceb3d5c9cde4d61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267960
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-12-08 13:43:41 +00:00
Tess Strickland a43d3cb993 [vm/compiler] Use CombineHashes/FinalizeHash methods in intrinsifier.
AsmIntrinsifier::OneByteString_getHashCode now uses the CombineHashes
and FinalizeHash Assembler methods introduced in 49f998dc31.

To avoid having to check for 0 again after masking the result of
FinalizeHash to fit the desired bit size, we create a more general
FinalizeHashForSize that also takes the desired bit size of the result.

The intrinsified versions for ARM/ARM64/RISCV are also modified to
remove the special casing for the empty string, and instead just check
the size of the string against the loop counter at the start of the
loop, similarly to X64/IA32. This is less efficient for the empty
string case, but avoids the need to create a version of FinalizeHash
that elides the zero check.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-debug-simriscv64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-nnbd-linux-debug-simriscv64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-ia32-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-ia32-try,vm-kernel-nnbd-mac-release-arm64-try,vm-kernel-linux-debug-x64c-try
Change-Id: I53db731acb8bf35d16efb55fa2c5a79d8302399f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272800
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-12-08 12:58:28 +00:00
Daco Harkes 3f3c6b4b8c [cfe] Remove FallThroughError reference
I don't believe this is used anywhere, but causes failures once the
class is removed from the core libraries.

Split off from https://dart-review.googlesource.com/c/sdk/+/259041

Bug: https://github.com/dart-lang/sdk/issues/49529
Change-Id: I9a215c981b0359b1d4521df9a330ec263b3b6c04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274382
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-12-08 12:48:24 +00:00
Aske Simon Christensen fd12e2e4ae [benchmark] Test dart2wasm benchmark invocations.
Bug: b/260206997
Change-Id: I49e225d8420fc5b5c0123736d0d8069d4cecd108
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273842
Reviewed-by: Jonas Termansen <sortie@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2022-12-08 11:56:56 +00:00
Aske Simon Christensen b85f0c7524 [dart2wasm] Scripts for compiling and running benchmarks
Change-Id: I01d8653e60c9667aefcbcef7f1871f408a539482
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271721
Reviewed-by: Jonas Termansen <sortie@google.com>
2022-12-08 11:56:56 +00:00
Aske Simon Christensen 8530755608 Update Binaryen to eeb838155dbff2fb6731f1ae5550cbb9494532fe
This version contains a `--closed-world` flag that we want to provide
to `wasm-opt` in the dart2wasm  benchmarking script from the start.

Change-Id: I5f97cd1911dad9946ac17fa25f9b11b0ed48bed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273221
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-12-08 11:56:56 +00:00
Daco Harkes d86c043cbb [vm] Remove FallThroughError code in the VM
Since Dart 2.0 we can never have FallThroughErrors.

The CFE does not synthesize breaks unterminated cases which never
reach the end of the block. For example:
* Call to something that returns never.
* Nested complete switch which returns from every branch.

In these cases we need to construct a correct control flow in the VM,
even though it is dead code. Because the CFE does not make the outer
switch a labelled statement, we cannot find a jump target in the VM.

Therefore, throw something (just not a FallThroughError). This should
never be hit at runtime, because it's dead code.

When the CFE emits synthetic breaks, we can remove this workaround.

TEST=build SDK and run default suites.

Bug: https://github.com/dart-lang/sdk/issues/50595
Change-Id: I595dd3baf7253b0ac4931445bd5b6da49e84cae4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273740
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2022-12-08 11:51:31 +00:00
Ömer Sinan Ağacan 636232628b [dart2wasm] Implement missing features in dynamic invocations
This reimplements dynamic call code generation to add support for type
checking, named parameters (optional and required), and fixes a few
related bugs on the way.

Currently we do not try to be as efficient as possible. The goal with
this patch is to implement it correctly.

Summary of the changes:

- For every dynamic access kind and member name, we generate a new
  "forwarder" function. Dynamic gets, sets, and invocations are compiled
  to calls to the forwarders with the right access kind (invocation,
  get, set) and member name.

  For example, if the program has dynamic invocation of a member "f", we
  create an "invocation forwarder for f". If it has a dynamic get of a
  member "x", we generate "getter forwarder for x".

- Forwarder functions take 4 arguments:

  - Receiver of the invocation, get, or set.

  - A Dart list for type arguments in the invocation. For gets and sets
    the list is empty.

  - A Dart list for positional arguments in the invocation. For gets the
    list is empty. For sets, the list only has one element.

  - A Dart list for named arguments. For gets and sets the list is
    empty. The list has alternating elements of type `Symbol` and
    `Object?`, for the name and value of the named parameters.

- A forwarder function compares receiver class ID with the potential
  targets of the call. When it finds a match, it compares the callee
  "shape" with the parameters passed in the call site.

  As it compares the shapes it adjusts argument lists:

  - Creates default values for missing optional positional and named
    arguments

  - Reorders the named argument list to match order expected by the
    callee

  If it can't find a matching class ID and a member with the right name
  and shape, it calls `noSuchMethod` on the receiver.

  If it finds a matching class ID and a member, it calls the "type
  checker" for the member, passing the original receiver and adjusted
  argument lists.

- A "type checker" implements argument type checking for a member, and
  it's a member of the same class as the member it's checking types
  for. This is to allow accessing class-bound type parameters when
  generating type checking code.

- Type checking is implemented using `_isSubtype` on arguments in the
  lists.

- When type checking is successful a type checker calls the original
  member, passing the arguments as expected by the member.

  If type checking is unsuccessful it throws a type error.

Most of the changes are for generating Wasm functions that compare
shapes, adjusts argument lists, and checks types.

Changes to members:

- `Translator.dynamics` fields is renamed to
  `Translator.dynamicForwarders`

- New field `Translator.dynamicForwarderFunctionType` added for the Wasm
  function type of forwarder and type checker functions.

- Two new code gen utilities added:

  - `Translator.indexList`: generates code that indexes a Dart list

  - `Translator.getListLength`: generates code that gets length of a
    Dart list

- New `Reference` extensions added to get type checker function
  references of members

- New runtime library `named_parameters` implements two helper functions
  for dealing with named argument lists

- The library `dynamic_dispatch` is replaced by `dynamic_forwarders`,
  which consists of two classes:

  - `DynamicForwarders`: maintains mapping from call kind (get, set,
    invocation) and member name to forwarder functions.

  - `Forwarder`: a single forwarder, implements code generation for
    forwarder functions.

- `CodeGenerator` gets 3 new members:

  - `_callForwader` generates call to a forwarder

  - `_generateFieldSetterTypeCheckerMethod` generates code for a type
    checker of a setter function.

  - `_generateProcedureTypeCheckerMethod` generates code for a type
    checker of a method.

Fixes #50367

Change-Id: I2b9d84237c8517bd217166d8acb67e025f0498fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/272261
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2022-12-08 10:45:12 +00:00
Jens Johansen 09a9a89d65 [analyzer] Deduplicate strings in Declaration
This CL removes some duplication of Strings:
 * Most duplication in `relevanceTagsInFile` (`ElementKind.CLASS`, etc)
   when loaded from file.
 * Usage of `()` for `parameters`.
 * Empty string return type.
 * Known type return type.

On the analyzer instance I've measured on (8 folders with analyzer etc
open) this saves:

Before CL: 161851 kb  2158725   _OneByteString dart:core
        1:  154622 kb  2001695   _OneByteString dart:core // removes most practical duplication from relevanceTagsInFile
        2:  153247 kb  1957751   _OneByteString dart:core // Removes () parameters
        3:  152970 kb  1939890   _OneByteString dart:core // Removes empty string return type
        3:  151287 kb  1886063   _OneByteString dart:core // removes void, String, bool, int, Future<void> return type

That's a total of 10,564 kb or 272,662 instances.
This is also ~1.7% of total ram usage.

Change-Id: Ide2ae55ae052d9f8bc382805a204dce48bf2b263
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-12-08 09:48:20 +00:00
Ahmed Ashour 66990edcf5 [analysis_server] fix RemoveDeadCode with forParts
Bug #43511

Change-Id: I82854382928cd29bfc7c646f0c202d28603f8836
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271200
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2022-12-08 06:33:09 +00:00
Srujan Gaddam 293ae7dabe [ddc] Add interop classes for static members
Fixes https://github.com/dart-lang/sdk/issues/46967

Creates classes for non-external factories and static members, and
modifies invocations to point to these members instead. Tear-offs of
interop constructors (external or otherwise) are now supported since
they're just non-external static methods.

Change-Id: Id754fb4bc872051a8df4169aefd4bdc078452fb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270501
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2022-12-08 04:57:50 +00:00
Stephen Adams 49f9a85be2 [dart2js] Clean up migration interface
Change-Id: Ie40716265fce4cdb7ce298d8cbbf6c86fe06c05d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274267
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2022-12-08 04:17:51 +00:00
Brian Wilkerson 8569d24f3e Attempt to fix the windows bot
Change-Id: Id1743f8998c2cb2553b5cfed801e9caef9c1d7c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274264
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2022-12-08 02:20:17 +00:00
Stephen Adams 2dbd64bb29 [dart2js, js_runtime] Make JSNull.== an external method
Change-Id: I5a69b4f085a1d418fe60af7a8726bc713b54a0bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273462
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2022-12-08 02:14:00 +00:00
Brian Wilkerson de36e1cfb7 Enable patterns in server tests
Change-Id: I1d256b4c1c0cc20cb3e46087cd896d0920f82690
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274084
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2022-12-08 02:12:14 +00:00
Konstantin Shcheglov 44b877b55a Create AssignedVariablePatternImpl or DeclaredVariablePatternImpl.
Change-Id: I8009a0b3c46cdaec199a38e2c25a5792ae8cd9e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274266
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-08 01:57:48 +00:00
Jackson Gardner 00ca59a478 [dart2wasm] Support --multi-root and --multi-root-scheme flags.
Change-Id: I111748742677073bb3cf4c1655b69cb21d42f546
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274089
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
2022-12-08 00:59:23 +00:00
Nicholas Shahan 1edc2ecd3f [ddc] Support warnings/errors in weak mode
In the new runtime type system when running with weak null safety,
perform type tests multiple times to produce optional warnings or
errors when a test passes but would fail in sound null safety.
This is the same technique DDC uses with the current type system.

Issue: https://github.com/dart-lang/sdk/issues/48585
Change-Id: Ic1514987a6f4ffeb127a0d2be5ec15b606016212
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266543
Reviewed-by: Mark Zhou <markzipan@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2022-12-08 00:52:18 +00:00
Konstantin Shcheglov fd30c4f269 Report XYZ_FROM_DEFERRED_LIBRARY during constant evaluation.
Change-Id: I3cf2fa1dfcee3d9a2ddc6d506465d26a40181524
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274141
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-08 00:19:34 +00:00
Konstantin Shcheglov fe968d979e Handle Tag.MemberLegacyWithoutTypeArguments, don't write empty type arguments.
Change-Id: I838a046a4dfa7744528e85ceae90efe0403b1ef6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274261
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-07 22:57:58 +00:00
Alexander Markov 66f1dee48c [vm] Runtime type check in await
'await e' should check that e is a Future<flatten(S)>, where S is a
static type of e before awaiting e. If e is not a Future<flatten(S)>,
then 'await e' should await Future.value(e) instead of e. So futures
of incompatible type are not awaited and soundness is not violated.

TEST=tests/language/async/await_type_check_test.dart
(Based on https://dart-review.git.corp.google.com/c/sdk/+/267422.)

Fixes https://github.com/dart-lang/sdk/issues/50529
Part of https://github.com/dart-lang/sdk/issues/49396

Change-Id: Ia418db1be6736710abc9be87d95584c50cbc677e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273002
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-12-07 22:46:22 +00:00
Paul Berry 38cab10852 Patterns parsing: track when variable patterns are in an assignment context.
Variable patterns behave so differently inside a patternAssignment
that we may want to represent them using different AST nodes inside
the analyzer/CFE.  This change adds a boolean flag allowing the
implementation to know what kind of variable pattern it's looking at
when parsing occurs.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I60adf2865bbe24f85b72a79b1360833bf823bd67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273829
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2022-12-07 22:45:40 +00:00
Konstantin Shcheglov aea639bd03 Issue 50604. Fix renaming extension at its declaration.
Bug: https://github.com/dart-lang/sdk/issues/50604
Change-Id: I1c685ea7545ef120e5fc23fe6a507ded8c4f4cb9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274083
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-07 22:38:19 +00:00
Konstantin Shcheglov 356d15a3fc Issue 50603. Fix element kind to EXTENSION in search.getElementDeclarations
Bug: https://github.com/dart-lang/sdk/issues/50603
Change-Id: I22b4d827bc9472544cf3c3aad3473de8050e2f6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274085
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-07 22:37:37 +00:00
Alexander Aprelev efaad34a46 [vm/simd] Recognize TypedData Float64x2 getter/setters
```
import 'dart:typed_data';

@pragma("vm:never-inline")
fetch(l, i) => l[i];

main() {
  const n = 16*1024*1024;
  final l = ByteData(16 * n).buffer.asFloat64x2List();
  for (int i = 0; i < n; i++) {
    fetch(l, i);
  }
  final sw = Stopwatch()..start();
  for (int i = 0; i < n; i++) {
    fetch(l, i);
  }
  print(sw.elapsedMilliseconds);
}
```

on x64
before 1137ms
after 101ms

BUG=https://github.com/dart-lang/sdk/issues/50636
TEST=ci

Change-Id: I90ef8ccfa1161d4d8bb076a3c1a0e3c7d6521289
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274263
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2022-12-07 22:25:25 +00:00
Konstantin Shcheglov bd30de18ba Prepare to publish analyzer 5.3.0 and _fe_analyzer_shared 51.0.0
Bug: https://github.com/dart-lang/sdk/issues/50637
Change-Id: I0ce445af106168fd4af6529e2c55deceb954e559
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274086
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-12-07 22:18:37 +00:00
Konstantin Shcheglov 52be8e0f3e Issue 50496. Add mixin super invoked names to the unlinked signature.
Bug: https://github.com/dart-lang/sdk/issues/50496
Change-Id: I09c6dbc025cecc52e8f0340388bbf2b79ea78057
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273831
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-12-07 22:17:22 +00:00
Paul Berry 0fd211facd Shared analysis testing: Distinguish Var.errorId from variable identity.
The field `Var.errorId` was being used for two purposes:

- For checking error messages.

- To distinguish different variables with the same name when merging
  variables in `||` and cases.

As a result, a lot of variables to be tagged with error IDs even in
tests that weren't generating any errors, which was confusing.

This change creates a new `Var.identity` field which is used for
merging variables in `||` and cases; it defaults to the variable name
but may be overridden in tests where distinguishing variables of the
same name is important.

Change-Id: Ieb587f434520dc484180aaa72658c899a2eb06d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273824
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-12-07 22:10:35 +00:00
Paul Berry 3407cdb6ac Shared analysis: update ifCaseElement API to match ifCase.
This change makes the API for the `ifCaseElement` method similar to
that of `ifCase`, which should make it easier to write flow analysis
unit tests for if-case elements.

Bug: https://github.com/dart-lang/sdk/issues/50419
Change-Id: I64c160f3b6df38b0d337f9b8f9c6c9189e9a13ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274161
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-12-07 22:08:30 +00:00
Paul Berry 759a742c16 Shared analysis: update ifCase API to match if_.
This change makes the API for the `ifCase` method the same as that of
`if_`, which should make it easier to write flow analysis unit tests
for if-case statements.

Bug: https://github.com/dart-lang/sdk/issues/50419
Change-Id: Iea7e0fabba9966eae52c0d28b52d2f8fcea25e46
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273820
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-12-07 22:02:32 +00:00
Kallen Tu 7ff20a67ca [analyzer] Report error when subtyping a sealed class outside of its library.
Change-Id: Iee6c9120d096ed49592ca3d155c81c876ceb5c34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273832
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-12-07 22:00:28 +00:00
Danny Tuppeny df3df89fd9 [analysis_server] Include type in extract-local-variable if always_specify_types is enabled
Fixes https://github.com/Dart-Code/Dart-Code/issues/4177.

Change-Id: I8da492c947466677e84d7892113f0bbfbdacfb87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274240
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-12-07 21:11:47 +00:00
Alexander Aprelev d1a34df210 [benchmarks] Add IsolateRegExp benchmark for regexp passing between isolates.
BUG=https://github.com/dart-lang/sdk/issues/50639
TEST=ci

Change-Id: I81bab7c61ce34d1b3a608a1fb0cc7cfd7a2d8e62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274120
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2022-12-07 20:56:02 +00:00
Konstantin Shcheglov acf7a95410 Split VariablePattern into AssignedVariablePattern and DeclaredVariablePattern.
Change-Id: I19ef3be7edb273eccf5f1afa61985ab24e584f1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274082
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-12-07 20:55:17 +00:00
Mark Zhou d9ea7207e8 [ddc] Wrapping loadLibrary checks in a future to obey eval order rules
These checks are cosmetic right now in DDC, but the load check was happening synchronously rather than after the future returned by loadLibrary completed.

Change-Id: I867779605ddfe4f63b83b47418994e0c5e68572a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274087
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Anna Gringauze <annagrin@google.com>
2022-12-07 20:47:17 +00:00
Martin Kustermann 4be2981c2d [vm/ffi] Ensure there's a single Function object per ffi-callback + exceptional-return combination
Right each `Pointer.fromFunction()` invocation will lead to creation of
a new ffi trampoline function & it's following JITed code. In AOT we
have exactly one ffi trampoline per target/native-signature/exceptional-return
combination.
=> This CL ensures we have only one such function.

Furthermore each `Pointer.fromFunction()` will currently perform 2
runtime calls in JIT: One to create a `Function` object, the other to
JIT that function & register callback metadata.
=> This CL ensures we won't do a runtime call to get a function, instead
   do it at compile-time (as in AOT)

Furthermore we eagerly assign a callback-id to the unique/deduped ffi
trampoline callbacks. Only when the application requests a pointer, do
we populate metadata on the `Thread` object.

This CL doesn't (yet) change the fact that in JIT mode we have
isolate-specific jit trampolines (that will call now shared ffi trampoline
functions).

We also avoid baking in C++ runtime function pointers in generated
code. As a result we can now preserve ffi trampolines across AppJIT
serialization.

As a nice side-effect, we remove 100 lines of code.

TEST=ffi{,_2}/ffi_callback_unique_test

Issue https://github.com/dart-lang/sdk/issues/50611

Change-Id: I458831a47b041a088086f28f825de2a3849f6adc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273420
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2022-12-07 20:47:13 +00:00
Nate Bosch 2f864c0a5d Use async/await for readAsString
The comment mentions that this was a planned refactoring after
--sync-async became the default. Avoid eagerly reading
`StackTrace.current` and switch to an `async` method.

Change-Id: I6a8e9399fa4c282ddbd42eb93f6e19669e75ebc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274260
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
Auto-Submit: Nate Bosch <nbosch@google.com>
2022-12-07 20:39:15 +00:00
Kevin Moore 1b79875bb7 changelog: sort and front-load new lints in 2.19 and 2.18 sections
Some other whitespace tweaks
Dropped a bunch of gratuitous `[]` bits next to links

Change-Id: I32b46138d3ff7df68b8a4dab80b346de20fee73f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274088
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
2022-12-07 20:39:10 +00:00
Danny Tuppeny 092bdb17d3 [analysis_server] Improve Snippet performance with caching and earlier filtering
This shares a cache for mapping Elements to their public LibraryElements across each snippet producer, and also skips snippet producers that produce snippets that won't match any typed prefix.

Change-Id: I6b64b3c55f1030a5eaa7ca1afdcd6c416e4baa08
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273962
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-12-07 20:31:12 +00:00
Sigmund Cherem e8906e65e7 [3.0 alpha][dart2js] No longer infer the null-safety mode from sources.
This prepares dart2js to default to sound null safety in Dart 3.0.

The compiler no longer infers the default mode based on the input
program, instead uses sound null safety unless
'--no-sound-null-safety' is specified.

On a separate change, we expect to remove the option of disabling
null safety.

Note: this change should also be reflected in the CHANGELOG, but
we've currently not included it to redeuce merge conflicts, as we plan
to land multiple 3.0-alpha changes in a short window of time

Change-Id: Id87498cc5976548ec89d1f36c60674b72406950a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270860
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
2022-12-07 04:02:13 +00:00
Martin Kustermann 896675c462 [vm] Always share double/float32x4/float64x2/int32x4 in inter-isolate messages
The JIT support for dynamically unboxing has been removed in [0]. As
such all double/float32x4/float64x2/int32x4 objects are immutable and
can therefore be shared across isolates.

[0] https://dart-review.googlesource.com/c/sdk/+/256211

TEST=ci

Change-Id: Ifd4e7c2444415b2e3b5269d9fbeb6570cc5d6768
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273680
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2022-12-07 00:48:28 +00:00