This was broken after
https://dart-review.googlesource.com/c/sdk/+/230948, the example would
be
```dart
class A {
m() sync* {
yield* [1];
}
}
```
Inferred type for expression in `yield*` statement is
`List<FutureOr<dynamic>>` after the above CL, while I'd expect it
to be `List<int>`.
The change modified the behaivor while passing the imposed
return type a bit: `InferenceContext.setType` resets the type to `null`
if it's `dynamic`, while the logic that passes the type down explicitly
doesn't do that. My change restores the behavior of resetting the
imposed type to `null` if it's `dynamic`.
Interestingly enough, this is not a problem for function declarations:
`FunctionExpressionResolver.resolve(FunctionExpressionImpl)`
has special clause that resets the imposed type to null. But
for reasons I don't understand `FunctionExpressionResolver` is
used for function declarations but not for method declaration.
Change-Id: I63cfde01f067c25442afed64843861d09c7474a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231702
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
This CL implements `Finalizable` by means of a CFE transform.
The transform is implemented in the existing FFI transform to avoid the
overhead of traversing the AST an extra time. The FFI transform slows
down ~15-30% on Flutter Gallery. For more info see the design doc.
TEST=`dart pkg/vm/test/transformations/ffi_test.dart`
Design doc: go/dart-vm-finalizable
Bug: https://github.com/dart-lang/sdk/issues/47777
Change-Id: I0bf9dead90a61631b7f215dc19fbaa9e40e63c8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227501
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
In general any async function can return X or Future<X>. Though the
future implementation has to do different things depending on which case
we're in. It does so by using a `<obj> is Future<T>` test. This test is very
expensive if many different classes flow into `<obj>`.
Though most functions do not return `Future` objects from async
functions. We can determine that statically by looking if any returned
expression could be a future. If not, we can bypass the `is Future<T>`
test entirely.
Issue https://github.com/dart-lang/sdk/issues/48226
Issue https://github.com/dart-lang/sdk/issues/48235
TEST=pkg/front_end/testcases/general/async_function_returns_future_or.dart
Change-Id: If655bdbdddc214dd7b12be9905b3c788252547d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230662
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
In general this moves in the direction of dealing more with Identifier instances instead of TypeAnnotation instances.
This ended up being a larger refactor than I had hoped, but at a high level it does the following:
- Adds the TypeAnnotationCode/NamedTypeAnnotationCode/FunctionTypeAnnotationCode classes
- Change the TypeResolver api to have a single 'resolve' method, which takes a TypeAnnotationCode argument
- Makes ParameterCode/TypeParameterCode take more structured arguments
- Update the CFE code to be able to resolve NamedTypeAnnotationCode instances instead of TypeAnnotation instances
- Also deletes some unnecessary Code classes.
Note that supporting FunctionTypeAnnotationCode instances looks like it will be some more work in the CFE.
Change-Id: I84712aa1c29634cd0a93d245171b3591f69be927
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231327
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
The java generation for type `(string|Null)[]` was creating `@return one of <code>List<String></code> or <code>ElementList<Null></code>`
see example:
```
@SuppressWarnings({"WeakerAccess", "unused"})
public class UriList extends Response {
public UriList(JsonObject json) {
super(json);
}
/**
* A list of URIs.
*
* @return one of <code>List<String></code> or <code>ElementList<Null></code>
*/
public Object getUris() {
final JsonObject elem = (JsonObject)json.get("uris");
if (elem == null) return null;
if (elem.get("type").getAsString().equals("String")) return new String(elem);
if (elem.get("type").getAsString().equals("Null")) return new Null(elem);
return null;
}
```
My change is the simplest thing I could think of, just making the return type `List<String>` instead and allowing some of the elements to be null. But I'm happy to implement something else if someone has a suggestion for a better type (along with how to get the generate code to produce it)
Closes https://github.com/dart-lang/sdk/pull/48309https://github.com/dart-lang/sdk/pull/48309
TEST=N/A
GitOrigin-RevId: fa9dddad68219e697998c4a011a82d6860f44bfb
Change-Id: I79cf2aedf0672354a2fd28c8962740f6fcea4f4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231740
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Currently we have to do a runtime `as FutureOr<T>` check for the
parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
needed for general cases, for the particular usage in the VM's
async/await transformer, we know that the test is going to suceed.
This CL adds two VM-specific methods on `_Future` that take `dynamic`
and downcast via `unsafeCast<>()` to avoid this rather large runtime
type checking overhead.
Issue https://github.com/dart-lang/sdk/issues/48226
Change after revert: Replace the
assert(value is T || value is Future<T>);
with
assert((value as FutureOr<T>) == value);
The former doesn't allow `null` while the ladder might (depending
on nullability of `T`).
TEST=ci
Change-Id: I2379c625003fea6aa836ac74beb1cd59201b3560
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231704
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This reverts commit 8e0feb9fa9.
Reason for revert: breaks tests in Google3, see b/217919095
Original change's description:
> [vm] Avoid type parameter check of _Future._asyncComplete() when caller knows its safe
>
> Currently we have to do a runtime `as FutureOr<T>` check for the
> parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
> needed for general cases, for the particular usage in the VM's
> async/await transformer, we know that the test is going to suceed.
>
> This CL adds two VM-specific methods on `_Future` that take `dynamic`
> and downcast via `unsafeCast<>()` to avoid this rather large runtime
> type checking overhead.
>
> Issue https://github.com/dart-lang/sdk/issues/48226
>
> TEST=ci
>
> Change-Id: Ieeffae3ac8e2960f849512cf22c51d41cadb1ecf
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230261
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>
TBR=lrn@google.com,vegorov@google.com,kustermann@google.com
Change-Id: I37a07cbb6fb37620e5305dfe1b759b0de1c37653
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231703
Reviewed-by: Ilya Yanok <yanok@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
Currently we have to do a runtime `as FutureOr<T>` check for the
parameter to `_Future<T>.asyncComplete(FutureOr<T> value)`. Although
needed for general cases, for the particular usage in the VM's
async/await transformer, we know that the test is going to suceed.
This CL adds two VM-specific methods on `_Future` that take `dynamic`
and downcast via `unsafeCast<>()` to avoid this rather large runtime
type checking overhead.
Issue https://github.com/dart-lang/sdk/issues/48226
TEST=ci
Change-Id: Ieeffae3ac8e2960f849512cf22c51d41cadb1ecf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230261
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This change adds --source option to kernel compilers (front-end server
and gen_kernel). This option instructs compiler to include extra source
files into compilation even if they are not referenced from main
library.
TEST=Added test cases to pkg/frontend_server/test/frontend_server_test.dart
and pkg/vm/test/kernel_front_end_test.dart
Fixes https://github.com/dart-lang/sdk/issues/48144
Change-Id: If3d71538751e9ccfa8c82a5685d810cf811e021c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231334
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
The `_FutureListener.callback` field is used for multiple purposes
(possibly to save memory by avoiding additional fields) so it cannot
have a specific function type.
This causes the `Function?` typed `_FutureListener.callback` field to be
casted to proper function types such as `T Function(S)`.
=> Those runtime type checks are very expensive.
To avoid introducing more fields we use an `unsafeCast<T>()` for those
casts, since the implementation guarantees they are going to suceed.
Issue https://github.com/dart-lang/sdk/issues/48225
TEST=ci
Change-Id: I6f0cc87600462c8ca5baceeb511ce8a06c61237e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230240
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This adds the initial support for `constructorsOf`, `fieldsOf` and
`methodsOf` in the `ClassIntrospector` implementation. Currently only
source classes are supported.
Change-Id: I586b37b3dc2f93518bc93b908c0468286034b651
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231480
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Run as for instance
```
pkg/front_end/tool/fasta -Dbenchmark=true -Diterations=3 compile pkg/compiler/bin/dart2js.dart
```
This will set benchmarking to true, do 3 iterations and eventually print
the benchmarking data as json. That can then be pasted into the attempted
visualizer.
This is a first stab, and might be replaced by something else down the line.
Change-Id: I8cb3a6bcf8717adf089d25a0fb432cb0b286aaa6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231441
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>