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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
```
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>