TFA is extended to infer 'always fail' and 'always pass' outcomes
of 'is' tests, and tree shaker is improved to replace 'is' tests
with a constant true/false based on the results of analysis.
Also, tree shaker is improved to remove 'if' statements and
conditional expressions if condition value is known, and simplify
logical operations (&&, || and !) if their operands are known.
The removed parts are not visited during tree shaking to avoid
retaining classes which are only used from removed parts.
TEST=pkg/vm/testcases/transformations/type_flow/transformer/is_test_elimination_nnbd.dart
Fixes https://github.com/dart-lang/sdk/issues/41238
Fixes https://github.com/dart-lang/sdk/issues/46533
Change-Id: I4086e2b78a1118b866b7f0c3b9c0034b55a8865d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206669
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
When evaluating arguments of an unreachable call tree shaker previously
inserted a sequence of nested Let expressions:
Let tmp0 = arg0 in Let tmp1 = arg1 in ... in result
Such AST declares unnecessary local variables and may have a deep
nesting (which may potentially cause excessive stack usage and stack
overflow). This change adjusts tree shaker to use BlockExpression
with ExpressionStatements instead of nested Let nodes:
block {
arg0;
arg1;
...
} => result
TEST=existing tests
Change-Id: Ic08fd4f4a18a64f73540b6dc17decbe68e58f55d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206900
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This fixes an issue during signature shaking of FfiNative calls:
`type 'ConstantExpression' is not a subtype of type 'VariableGet' of 'value'`
Which is triggered by the Arguments list having type List<VariableGet>.
TEST=ffi/ffi_native_test
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: Iafcbca8018dab091b825277ac64a51587c929ea0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206787
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
Avoid marking class as allocated immediately when building a summary
and visiting ConstructorInvocation node. Instead, mark class as
allocated later when interpreting Call which corresponds to
a constructor invocation. This is more precise if an argument of
the constructor Call is evaluated to an EmptyType (which means
that the constructor invocation is unreachable). Otherwise it is
possible that class is marked as allocated but its constructors
are not used.
Flutter gallery AOT snapshot size:
* release mode -0.36% (both armv7 and armv8)
* release-sizeopt mode -0.39% (both armv7 and armv8)
TEST=existing tests
Change-Id: I51bdf2f1a60dda88bc2c788339ee4d4ab79d8cd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205802
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Changes the naming format for synthetic variables used for
@FfiNatives.
The name was based on the native function, but since multiple
FfiNatives can reference the same native function, this can
result in name clashes.
Instead the name is now based on the name of the associated
function, which cannot have a name clashing with another function
by the same name.
TEST=CQ
Change-Id: Id829ff3f207ab11e83f3194b8410f4be297623c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206374
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
In order to simplify removal of instance fields with initializers which
may have side effects, such field initializers are moved to constructor
initializer lists before type flow analysis.
In case of multiple generative non-redirecting constructors AST of
field initializers is cloned. Moving and cloning of initializers is
performed before the analysis to avoid maintaining and spreading
inferred TFA information attached to AST nodes.
TEST=pkg/vm/testcases/transformations/type_flow/transformer/instance_fields_with_initializers_nnbd.dart
Fixes https://github.com/dart-lang/sdk/issues/46402
Change-Id: I4dc9c44c441ece5792f0748789ece117a2814581
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204943
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
We are seeing CI flakes in webdev when using expression_compiler_worker
in tests involving expression evaluation, for example, see linux tests
for dwds in the following PR:
https://github.com/dart-lang/webdev/pull/1343
The logs show that HttpFileSystemEntity.exists fails due to a broken
pipe, which we suspect is due to http client closed too early.
This change is an attempt to fix the problem by
- logging exceptions thrown in expression compiler worker
- awaiting for the request to be read before closing http client in
HttpFileSystemEntity.
TEST=pkg/dev_compiler/test/expression_compiler/asset_file_system_test.dart
See investigation of the CI issue in:
https://github.com/dart-lang/webdev/issues/1345
Closes: https://github.com/dart-lang/sdk/issues/46388
Change-Id: Iaf98f08e8ebb618bf8365bd497f01ae685f0d3f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203841
Commit-Queue: Anna Gringauze <annagrin@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Call site attributes metadata is used to pass receiver static type
from kernel AST to the VM. In certain cases, call site metadata is
superseded by the new invocation nodes. This change revises how call
site attributes metadata is generated in call site annotator and
used in the VM for the new invocation nodes.
* When building flow graph for FunctionInvocation,
the decision to generate unchecked calls is now done by
looking only at the function access kind, without taking static
receiver type into account. Call site annotator now verifies that
static receiver type matches function access kind for
FunctionInvocation nodes to make sure nothing is lost during this
transition. Also, flow graph builder asserts that
function access kind is either Function or FunctionType.
* Call site metadata is no longer generated for LocalFunctionInvocation
and FunctionInvocation nodes, as it is no longer used by the VM.
* Call site annotator now verifies that InstanceInvocation nodes
cannot be used for unchecked closure calls. Flow graph builder no
longer recognizes unchecked closure calls for InstanceInvocation
and DynamicInvocation nodes.
* When generating flow graph for DynamicInvocation and DynamicSet,
call site metadata is no longer taken into account (metadata is not
generated by call site annotator for these nodes).
Also, 'this' receiver is not recognized for DynamicInvocation and
DynamicSet nodes as it may potentially violate dynamic call semantics.
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/45340
Change-Id: Ia8c5e547965ac8d7a17908d4be4bd048e5cfb23f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203668
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Adds support for marking external functions as @FfiNative's,
which will be called using fast FFI calls.
Resolution happens by calling out to a new embedder provided
Dart_FfiNativeResolver which the embedder can specify via
Dart_SetFfiNativeResolver.
TEST=vm/cc/DartAPI_FfiNativeResolver
Bug: https://github.com/dart-lang/sdk/issues/43889
Change-Id: I3cfff360b05314499a81444b90f4ea0a1b937b0b
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170092
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Apparently it is possible for annotations to contain InvalidExpression
AST nodes, not just ConstantExpression
(see https://github.com/flutter/flutter/issues/83466#issuecomment-856697378).
This change improves robustness of TFA by ignoring (and cleaning) all
annotations which are not ConstantExpression, instead of crashing on
them.
TEST=none
(I wasn't able to reproduce the problem and replicate the situation
where front-end generates InvalidExpression nodes.)
Change-Id: I1dbd55515f1e861488f6cc46eea50a2ef31ab564
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203283
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL adds FFI leaf calls by adding `lookupFunction(.., isLeaf)`
and `_asFunctionInternal(.., isLeaf)`, which generate FFI leaf calls.
These calls skip a lot of the usual frame building and generated <->
native transition overhead.
`benchmark/FfiCall/` shows a 1.1x - 4.3x speed-up between the regular
FFI calls and their leaf call counterparts (JIT, x64, release).
TEST=Adds `tests/ffi{,_2}/vmspecific_leaf_call_test.dart`. Tested FFI tests.
Closes: https://github.com/dart-lang/sdk/issues/36707
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-release-arm64-try,vm-ffi-android-release-arm-try,vm-ffi-android-product-arm64-try,vm-ffi-android-product-arm-try,vm-ffi-android-debug-arm64-try,vm-ffi-android-debug-arm-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-release-x64-try,vm-kernel-mac-debug-x64-try,vm-kernel-precomp-nnbd-mac-release-simarm64-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try
Bug: https://github.com/dart-lang/sdk/issues/36707
Change-Id: Id8824f36b0006bf09951207bd004356fe6e9f46e
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179768
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
https://dart-review.googlesource.com/c/sdk/+/198281 introduced support
for incremental compilation to the FfiTransform. This included reading
fields from already transformed structs and unions.
However, fields which already had been transformed are indistinguishable
from user-defined getters.
So instead of re-reading the information from the fields, for already
transformed structs, we read the information from the
`vm:ffi:struct-fields` pragma on the struct class.
Closes: https://github.com/dart-lang/sdk/issues/46004
TEST=tests/ffi/regress_46004_test.dart
TEST=pkg/front_end/testcases/incremental/regress_46004.yaml
Change-Id: Iebffda037913e71349bba9685dc16e2f478a0e7b
Cq-Include-Trybots: luci.dart.try:vm-kernel-win-debug-x64-try,front-end-nnbd-linux-release-x64-try,front-end-linux-release-x64-try,vm-ffi-android-debug-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try
Fixed: 46004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200640
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
This change adds toString transformation to gen_kernel and
frontend_server tools in Dart SDK.
The implementation and tests are derived from
pkg/frontend_server/lib/src/to_string_transformer.dart and
https://github.com/flutter/engine/tree/master/flutter_frontend_server/test.
In addition to _KeepToString in dart:ui, toString transformation
now supports @pragma('flutter:keep-to-string') to exclude
certain toString methods from the transformation without depending
on dart:ui.
pkg/frontend_server/lib/src/to_string_transformer.dart is not
cleaned up in this change yet as it is still used by Flutter
engine. Cleanup will be done after Flutter engine is cleaned up,
after it is switched to the implementation of toString transformer
added in this change.
This is also a step towards a unified kernel compiler
(https://github.com/dart-lang/sdk/issues/39126).
TEST=pkg/vm/test/transformations/to_string_transformer_test.dart
Issue: https://github.com/dart-lang/sdk/issues/46022
Issue: https://github.com/dart-lang/sdk/issues/39126
Change-Id: Icbfd3fa193d54f1fc6b2d7fa0bace82b3704f91f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200525
Reviewed-by: Dan Field <dnfield@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Previously, certain fields of Typedef kernel AST nodes
were omitted from visitChildren(), transformChildren() and
transformOrRemoveChildren() and were not properly visited.
Also, the following related problems are fixed in this CL:
* parents of VariableDeclaration nodes in Typedef were not properly set;
* verifier didn't account for VariableDeclaration nodes in Typedefs.
TEST=existing tests
Change-Id: I4f9cb694ad9cacc9c20fe66e8a49f73f547ca245
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96964
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Previously, annotations were not traced by global type flow analysis
(in order to avoid retaining classes which are only used in
annotations). Annotations were only traced during tree shaking
and references from such constants were treated much like
references from types. This handling of constants in annotations
conflicts with removal of fields, as tree shaker needs to know
which fields are retained upfront to be independent of the visiting
order. In a certain corner case (field was replaced with a getter
but was still used in a constant in annotation) that caused incorrect
AST and crash during serialization of AST.
In order to fix that, this change adds proper tracing through
annotations on members, classes and libraries, as if annotation
constants were used in the executable code. That also means
that annotation classes will be retained as allocated.
In order to compensate for that, a new pass is added before the global
analysis to clean all annotations except @ExternalName, @pragma
(used by the VM) and @TagNumber (used by protobuf tree shaking).
TEST=runtime/tests/vm/dart/regress_45968_test.dart
Fixes https://github.com/dart-lang/sdk/issues/45968
Change-Id: I998e4f7ec7da7b74e1738fc21b354a4ec9f0c071
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199200
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This change is a pure refactoring. It extracts 3 duplicated code
snippets into helper methods. This is needed to reduce number of
places where PropertyGet and MethodInvocation nodes are created, as
these nodes are going to be replaced with InstanceGet and
InstanceInvocation nodes soon.
Issue: https://github.com/dart-lang/sdk/issues/45340
Change-Id: I694805a3761fd389ac8ee005d12ffb9bb9543ea7
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198581
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
The compounds transformation converting fields into getters and setters
now retains the annotations on the getters so that they can be read
during recompilation.
This splits up `_replaceFields` into `_findFields` and `_replaceFields`.
`_findFields` works for both transformed and non-transformed compounds.
This splits up `_compoundClassDependencies` out from
`_checkFieldAnnotations`. The former is run on all compounds
transitively reached from the compounds being compiled, the latter only
on the compounds being (re)compiled.
`manualVisitInTopologicalOrder` now visits compounds from all libraries,
not just the ones in the libraries being (re)compiled. It is responsible
for filling the `compoundCache` in topological order. And, this CL
introduces the `InvalidNativeTypeCfe` to support processing compounds
with invalid fields, which might be nested later in other compounds.
Bug: https://github.com/dart-lang/sdk/issues/45899
TEST=pkg/front_end/testcases/incremental/crash_05.yaml
TEST=tests/ffi(_2)/*
Change-Id: I07a2214fd460f4d5e6a84df81e8b140dd80401dc
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try
Fixed: 45899
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198281
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>