Commit Graph

227 Commits

Author SHA1 Message Date
Liam Appelbe 216e3df452 [vm] Handle required params in bytecode mode
Change-Id: I9e6b62969012bf2e0d9fce6bfe894a2367f240c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138664
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-04-24 20:52:27 +00:00
Alexander Markov 8445424db4 [vm/nnbd] Fix marking static fields as late
Only mark static fields with initializers as late in opted-in
libraries (static fields without initializers should be still
pre-initialized with null and not sentinel).

Change-Id: I1371757c383ca53cc6cc798a31395f039b8719d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141341
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-03-27 17:08:52 +00:00
Alexander Markov 8c4909aa8f [vm/nnbd] Mark static fields in opted-in libraries as late
According to the NNBD feature specification, "a toplevel or static
variable with an initializer is evaluated as if it was marked late".
This change actually marks all static fields in opted-in libraries
as late, in order to make sure that the rest of the VM handles
such fields uniformly as late.

Without this change implicit getters for such fields were generated
as late, but type propagation didn't treat these fields as nullable,
so field initialization checks were removed if field has a non-nullable
type.

Change-Id: I95bc096fb1d304b112369428dbb29d346964383f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140767
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2020-03-24 22:22:57 +00:00
Liam Appelbe 318b42572e [vm] Mark member signatures as not reflectable
This fixes some mirrors failures in NNBD legacy mode, since the CFE is
inserting more synthetic functions now, to handle interfacing between
libraries with different NNBD status.

Change-Id: Iad5cb2548ef118f842bf2eadf249d4dca9f38fa7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139740
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-03-19 17:54:19 +00:00
Alexander Markov d850801691 [vm] Cleanup code related to interface calls through fields/getters from TFA and bytecode generator
Since https://dart-review.googlesource.com/c/sdk/+/129702 CFE desugars
interface calls through fields/getters, so there is no need to handle
them in the TFA and bytecode generator.

Note that VM can still see such calls if they are dynamic, so
handling of such calls is not removed entirely from TFA or VM.
Also, VM should support those as long as it supports older kernel
binary versions.

Issue: https://github.com/dart-lang/sdk/issues/34497
Change-Id: Ic49f109b0e9264f0e20a7e1a3b7a46011fa76c86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137700
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-03-03 22:36:23 +00:00
Régis Crelier 5701c4fd3b [VM/nnbd] Remove propagation of library mode to runtime after spec change.
On 1/27/20, the nnbd specification changed weak and strong mode instance checks
to make them behave uniformly across legacy and opted-in libraries.
Therefore, it is not necessary anymore to propagate the library mode in
generated code to the runtime.

Change-Id: I42d3ddc6e9a921899aeac21be6374c7893a6d27c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138111
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2020-03-03 20:30:32 +00:00
Liam Appelbe f5a830a087 [vm] Update late final fields with init to match new spec
Spec was updated here: https://github.com/dart-lang/language/pull/720

Bug: https://github.com/dart-lang/sdk/issues/40204
Change-Id: Id4f5bc9a62d9cf5c0b3e4d12a13b3049cbe07a56
Fixed: https://github.com/dart-lang/sdk/issues/40204
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132408
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2020-01-17 23:51:59 +00:00
Johnni Winther d08f070b28 [cfe] Add canonical way to detect the synthesized redirecting factory field
Change-Id: Ied5ffe786558856c4e63881880cbd19fa0bd6c68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131620
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-14 09:42:45 +00:00
Régis Crelier b92fefdfe9 [VM/nnbd] Pass nnbd mode from compiler via generated code or bytecode to runtime functions performing type checks or type reification.
This continues the work started in https://dart-review.googlesource.com/c/sdk/+/124105
The nnbd mode is now part of the type arguments instantiation cache,
since the resulting vector depends on the mode.

Change-Id: I803c07fa9473024557db8585e87286f16681169a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128307
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2019-12-20 03:26:29 +00:00
Johnni Winther 818ec6db92 [cfe] Implement nnbd-top-merge
+ and use nnbd-top-merge and legacy erasure in hierarchy computation

Change-Id: I4bf06ce8d3c68a9926865ebf84b24b4029828d73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128065
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-12-13 17:19:59 +00:00
Alexander Markov b57e10ad28 [vm/nnbd] Fix nullability of types in inferred types attribute
VM doesn't expect legacy nullability for Null type, so nullability
should be adjusted when writing AOT-specific inferred types attribute in
bytecode.

Change-Id: I58b09c9931f3cce6e70f661f1ba3e7e015e7f739
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127985
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-12-10 22:03:16 +00:00
Samir Jindel 1d4c45d2d0 Re-land "[vm/cfe] Elaborate for-in statements during async transform"
This removes the component of the change which updates the kernel binary
format.

Change-Id: I86dbfe0ea61453bbea6eee200743961d0d0c3814
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127002
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Teagan Strickland <sstrickl@google.com>
2019-12-05 14:06:08 +00:00
Alexander Markov f56b0f6907 [vm/aot/tfa] Whole-program constant propagation
Size:
flutter_gallery total size -2.48% (arm), -2.3% (arm64)
flutter_gallery instructions size -2.91% (arm), -2.77% (arm64)
velocity_tracker_bench total size -7.5% (arm), -7.1% (arm64)

Performance:
SkeletalAnimation +46.02% (Intel Core i5), +37.75% (Intel Xeon), +24.86% (arm), +39.75% (arm64).
FfiMemory.Pointer* +44-64% (x64)
FfiMemory.PointerPointer +436-465% (x64), +443% (arm64).

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

Change-Id: I6221bfa02b165ccc17d4ee8b857bb89212febaff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125936
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-12-04 19:19:29 +00:00
Clement Skau 89e31069e8 Revert "[vm/cfe] Elaborate for-in statements during async transform"
This reverts commit 63333deed6.

Reason for revert: Causes failures on Flutter HHH CI in the "flutter test hostonly_devicelab_tests" step due to kernel binary format version mismatch.

Original change's description:
> [vm/cfe] Elaborate for-in statements during async transform
> 
> This allows us TFA to analyze the iterator calls and we generate much tighter
> code in AOT.
> 
> However, due to the increased inlining opportunities, we end up emitting 0.5%
> more code. Inlining of the _GrowableList iterator specifically also includes the
> concurrent modification check and error handling.
> 
> Calls to get:iterator, moveNext and get:current account for 7.12% of all InstanceCall
> instructions in Flutter Gallery.
> 
> Fixes https://github.com/dart-lang/sdk/issues/39516
> Issue https://github.com/dart-lang/sdk/issues/39566
> Issue https://github.com/dart-lang/sdk/issues/39565
> 
> Change-Id: I8dcc08b7571137e869a16ceea8cc73539eb02a5a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126381
> Commit-Queue: Samir Jindel <sjindel@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

TBR=kustermann@google.com,sjindel@google.com,johnniwinther@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I89b88c3d9f7c743fc340ee73a45c3f57059bcf30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126734
Reviewed-by: Clement Skau <cskau@google.com>
Reviewed-by: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2019-12-03 12:29:35 +00:00
Samir Jindel 63333deed6 [vm/cfe] Elaborate for-in statements during async transform
This allows us TFA to analyze the iterator calls and we generate much tighter
code in AOT.

However, due to the increased inlining opportunities, we end up emitting 0.5%
more code. Inlining of the _GrowableList iterator specifically also includes the
concurrent modification check and error handling.

Calls to get:iterator, moveNext and get:current account for 7.12% of all InstanceCall
instructions in Flutter Gallery.

Fixes https://github.com/dart-lang/sdk/issues/39516
Issue https://github.com/dart-lang/sdk/issues/39566
Issue https://github.com/dart-lang/sdk/issues/39565

Change-Id: I8dcc08b7571137e869a16ceea8cc73539eb02a5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126381
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-11-29 16:42:36 +00:00
Aske Simon Christensen 18f23124ad [cfe] Print nullability on types in messages for opt-in libraries.
This CL changes the message template generator to add an extra
'isNonNullableByDefault' parameter to 'withArguments' for all
messages that include types, thus forcing the reporter to specify
whether the library that the message belongs to is opted in to NNBD.

When the message is formatted, a '?' is added to all nullable types
if the message is reported for an opt-in library.

Change-Id: I4e1861eba48043c570afad3f40bc3dccfd2e5668
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124984
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-25 14:58:45 +00:00
Liam Appelbe 09d22a0509 [vm] Wrap late local var initializers in a closure.
This fixes the case where a late local var initializer allocates
variables or temporaries. It's not clear where they should be
allocated, since the initializer could be called anywhere the late
variable is accessed. So we wrap the initializer in a closure, since
calling a closure only requires a single temporary.

So then we just need to allocate that temp everywhere the late var is
accessed. Since temporaries are associated with specific AST nodes,
we also need to add the ability to swap out the temporaries associated
with a node, so that we can use the getter's temp when the getter
visits the initializer.

This will also reduce code bloat for large initializers.

Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: Ice8c16babc0e56368657088edf1b51b422ee0241
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125762
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-11-21 20:39:36 +00:00
Jens Johansen 2e32972929 [pkg/vm] Remove usage of Library.isExternal
Change-Id: I014184e2324ab0379653cb8c23cb7eed52677aeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124985
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-21 08:36:54 +00:00
Liam Appelbe bde92ca34a [vm] Late modifier for final local variables.
Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: Ia99a3441b4175bb16097766d57133c6d83a0e3f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125542
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-18 23:12:48 +00:00
Martin Kustermann aceeba7567 [vm/async] Encode the yield index -> token position in PcDescriptors.
Right now `Script::yield_positions()` is an array mapping function start
token positions to arrays. Those arrays contain token positions and are
indexed by yield index.
  => This `Script::yield_positions()` is not available in AOT mode.

The fast async stack implementation will need to be able to find out
where an async closure was suspended. It does so by looking at the
":await_jump_var", which contains the yield index. It then needs to
associate the yield index to token position of the yield.

This CL adds an entry into the PcDescriptors for every yield in a
async/async* function and removes `Script::yield_positions()`.
The entry will associate the yield index with the token position.

Flutter gallery total size impact for flutter-release:

  - armv7: +0.016%
  - armv8: +0.045%

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

Change-Id: I0b2ce41e85d8f5d590201bf2fb091578d7379890
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125408
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-18 11:50:13 +00:00
Johnni Winther 4b5589e0cb Reland "[cfe] Use StaticTypeContext for getStaticType" and more"
This relands commits
 "[cfe] Use StaticTypeContext for getStaticType"
 45033c6ad9

 "[cfe] Move caching of thisType to CoreTypes"
 fab25cbe0c

 "[vm/bytecode] Notify static type context when entering/leaving library"
 c9f88ae253

Change-Id: I407d6b0e3b3df503cedc9fcb2c834d835cf083f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125343
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2019-11-16 05:50:58 +00:00
Liam Appelbe 329d0913ca [vm] Late modifier for non-final local variables.
I also added a test for top level late variables (they already worked).

Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: I6720e6476a067c7f8b21a34b87b23ab14fc866a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125224
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-11-15 23:03:16 +00:00
Johnni Winther ef5fb7d3f4 Revert "[cfe] Use StaticTypeContext for getStaticType" and more
This reverts commits
 "[cfe] Use StaticTypeContext for getStaticType"
 45033c6ad9

 "[cfe] Move caching of thisType to CoreTypes"
 fab25cbe0c

 "[vm/bytecode] Notify static type context when entering/leaving library"
 c9f88ae253

Change-Id: I6171f6a74b97f2f4a77a36c242330fc2db94c82f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125341
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
2019-11-14 22:51:43 +00:00
Alexander Markov c9f88ae253 [vm/bytecode] Notify static type context when entering/leaving library
Issue: https://github.com/dart-lang/sdk/issues/39388
Change-Id: I8f9933df46e8667432ebf0167313993e5c2caa72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125230
Reviewed-by: Aart Bik <ajcbik@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-11-14 21:39:28 +00:00
Dmitry Stefantsov fab25cbe0c [cfe] Move caching of thisType to CoreTypes
Closes #38225.

Bug: http://dartbug.com/38225
Change-Id: I0274bc390ca2d098896f578ea7ddf65527d82027
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124325
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-14 16:01:26 +00:00
Johnni Winther 45033c6ad9 [cfe] Use StaticTypeContext for getStaticType
Change Expression.getStaticType to take a StaticTypeContext instead
of a TypeEnvironment.

The StaticTypeContext provides access to the TypeEnvironment and the
current 'this type' as well as determining the nullability state of the
enclosing library.

This change is needed to support nnbd types for getStaticType and also
serves as a step towards supporting caching during static type
computations to avoid repeated computations of the same (complex)
expressions.

Change-Id: Ied974dff7f6f7c3c8f262aa80c8dea5c674662f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124683
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-11-14 09:09:26 +00:00
Liam Appelbe a0bb025024 [vm] Late static final fields
Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: Ic40002ab0e6ded6d525ee5e1c218a589b9406c8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125005
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-13 17:56:08 +00:00
Liam Appelbe 2a9af7d953 [vm] Late modifier for non-final static fields.
Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: I8e6feef2c0ee8021bec2f849e9729516532ca91a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124641
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-12 17:27:39 +00:00
Alexander Markov b4ab28fef1 [vm/bytecode] Do not declare receiver variable in closures
While 'this' variable (receiver) is in scope in closures inside
instance methods, closures do not take it as a parameter and they
shouldn't declare a local variable for receiver unless it's captured.

Fixes https://github.com/dart-lang/sdk/issues/38743
Fixes https://github.com/dart-lang/sdk/issues/39285

Change-Id: Ic5c735fd50457a5fb39acb3ec3590964e4dddba3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124825
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-11-11 21:51:57 +00:00
Alexander Markov fa43799461 [vm/bytecode] Check number of type arguments in non-generic closures
Fixes https://github.com/dart-lang/sdk/issues/39283

Change-Id: I5a5fdf158c6a7ce068be36754ea0487cb754584b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124470
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-11-08 17:16:37 +00:00
Dmitry Stefantsov b4554c1215 [cfe] Make nullability a required parameter for types
Change-Id: Id787291294cafb15cf4ecad4a9db9da4c6066638
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124135
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Auto-Submit: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-07 13:24:47 +00:00
Liam Appelbe c154677699 [vm] Handle trivial initializers for late fields
Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: I9db9d4815ad27f3f97d43a7a9f1fb74f08673528
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124201
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-06 17:46:32 +00:00
Liam Appelbe 1f8ef384d9 [vm] First pieces of late modifier implementation.
This implements the logic for initializing, getting, and setting
non-final instance fields that have initializers. It doesn't address
statics, finals, local variables, or the no-initializer case, and is
only implemented for bytecode.

Bug: https://github.com/dart-lang/sdk/issues/38841
Change-Id: I3b9e2772abdc04e3bfede56d2fcf06738f234cbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122489
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-11-05 19:48:03 +00:00
Jens Johansen f91ef3afd7 [kernel] Deprecate Library.isExternal
We're deprecating kernels Library.isExternal as it wasn't used for
what it was originally intended. It will hopefully go away entirely
soon.

Change-Id: If363c50af5607febae68865875af452c106fff85
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123721
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-11-04 09:24:02 +00:00
Samir Jindel c885bdde1d [vm] DBC is obsolete. Remove dead code.
Change-Id: Ica33af158cca53c8e951e4b2582de83660e8a60d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121851
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-10-27 18:18:29 +00:00
Alexander Markov 7ac22ac28f [vm/bytecode] Omit null stores into context when declaring a captured variable
Change-Id: I35c0de039021dd627e8d2604d37675d24c5ec089
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122481
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-22 21:01:11 +00:00
Alexander Markov 6de2f92033 [vm,bytecode] Allocate objects lazily in bytecode generator
Previously, bytecode generator was allocating a bunch of objects
eagerly when starting bytecode generation for a member. Most of these
objects are maps and lists which are needed only under certain
circumstances. With this change these objects are allocated more lazily,
only when needed.

Also, this CL fixes crash in LinkReader.setOffset when reading/dumping
bytecode.

Change-Id: I11c561e4f00c456e92f42530d3d4e6008b5f5daf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122407
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-22 00:30:32 +00:00
Alexander Markov 73dd5f766a [vm,aot,bytecode] Do not depend on presence of _AsyncAwaitCompleter
In AOT mode tree shaker can remove _AsyncAwaitCompleter class, so
bytecode generator should not crash if it can't find this class in
the core library.

The only use of _AsyncAwaitCompleter in bytecode generator is to
mark _AsyncAwaitCompleter.get:future as non-debuggable.

This change fixes crash when building Flutter engine in
host/release configuration with unreachable code elimination
(https://dart-review.googlesource.com/c/sdk/+/121901).

Change-Id: I7724ef6ae51b2b2039bb113c5c7328956bf6e99d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122167
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-21 17:39:37 +00:00
Alexander Markov 9220890dc7 [vm/bytecode] Do not emit inferred type if unreachable
Closes: https://github.com/dart-lang/sdk/issues/38965

Change-Id: Id74ed952f2f632fe8028a765d0cf717e04830954
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-dartkb-linux-debug-simarm64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-dartkb-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-precomp-mac-release-simarm_x64-try,dart-sdk-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122147
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-10-18 18:29:02 +00:00
Liam Appelbe 45358c5834 [vm] Implementation of NullCheck for bytecode
Bug: https://github.com/dart-lang/sdk/issues/38840
Change-Id: I56af108096355a0486d45f88e795908ce712db4b
Fixes: https://github.com/dart-lang/sdk/issues/38840
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121904
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2019-10-17 19:18:26 +00:00
Alexander Markov 20f9d4d456 [vm,bytecode] Omit initialization of delayed type arguments for non-generic closures
Delayed type arguments are only used by generic closure functions, so
their initialization can be omitted for non-generic closures.

This is the follow-up for 1f58504ee6.

Change-Id: I61b05a4a4e2af4d2d8a543f6eec985a47b811761
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121924
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-17 17:53:50 +00:00
Alexander Markov 4dc1901cdb [vm,bytecode] Write closure attributes separately
There are could be conflicts in inferred types attributes between
function and its closures, so attributes for closures should be
written separately.

Change-Id: Iae395d73fdc2dfcb6b55137176f198f02e9b079b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121907
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-17 17:07:32 +00:00
Alexander Markov 9e2ce9a773 [vm,bytecode] Avoid duplicated initializing StoreFieldTOS
This is the follow-up for 46cef9bfdd.
After that change, VM's optimizer (canonicalization) removes
initializing stores which store null, even if they're overwriting the
result of another initializing store. This causes incorrect behavior
in cases like this:

class A {
  int x = 3;
  A() : x = null {}
}

To accomodate for this change in the VM's optimizer, bytecode generator
should elide duplicate stores, similarly to AST-based flow graph
builder.

Fixes language_2/field_parameter_test in AOT mode with bytecode.

Change-Id: I9b1e25840f639d88bf62dc990f183878ecf1b59b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121649
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-15 18:57:19 +00:00
Alexander Markov 3c3bd8d7c9 [vm,aot,bytecode] Support obfuscation
In order to support obfuscation, string constants are decoupled
from public names in bytecode (names are obfuscated, but string
constants aren't). List of protected names is written in a separate
section in bytecode component.

Obfuscator is extended to support getter and setter
names coming from bytecode.

Change-Id: I8e8d820d1a8b97e32e8ad1b064b827bdb017430b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121261
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-10-14 18:12:29 +00:00
Alexander Markov 8f679ab9f9 [vm,bytecode] Swap == operands in switch cases
For a switch statement

  switch(foo) {
    case c_1: ...
    ...
    case c_N: ...
  }

Bytecode was calling foo.operator==(c_i). This is less efficient than
c_i.operator==(foo), as c_i is a constant with a known actual type
and operator== can be always devirtualized and inlined.

Change-Id: I786ea193de1fa1830854602318e436f601296f5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121405
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-11 21:11:40 +00:00
Alexander Markov 62ee78eeec [vm,bytecode] Generate calls for causal-async-stacks more consistently
In order to support causal-async-stacks, the following synthetic calls
are inserted: _asyncStackTraceHelper, _setAsyncThreadStackTrace and
_clearAsyncThreadStackTrace.

_asyncStackTraceHelper is always generated in the async transformation.
_setAsyncThreadStackTrace and _clearAsyncThreadStackTrace are inserted
during bytecode generation (or in the flow graph builder in case of AST
pipeline). If bytecode generation options are set inconsistently with
--causal-async-stacks VM option, then it was possible that
_asyncStackTraceHelper was generated but other calls were not generated,
causing incorrect (full, non-truncated) async stack traces. This also
causes performance regression as collecting full stack traces takes
much more time.

This change makes generation of all these calls more consistent: if
causal async stacks are disabled during bytecode generation, then all
three calls are omitted. Also, in case these calls were generated and
present in bytecode, but VM option --causal-async-stacks is disabled,
then bytecode flow graph builder turns all these three calls into no-ops.

Change-Id: I93eb1d83c675ee093799bb8e37ca3d60a3c5c19d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120927
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-10-09 22:10:21 +00:00
Alexander Markov 3bb32f6778 [vm/bytecode] Generate complex conditions more efficiently in bytecode
Change-Id: I7cbf3a91dc96843f10af9560a58269badbe31bac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109729
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-09 19:32:54 +00:00
Alexander Markov 2ca6bc29b3 [vm,bytecode] More efficient bytecode for calls through fields/getters
Previously, calls through field/getter were generated as dynamic calls
because InterfaceCall with field/getter target doesn't correctly
represent what such call should do. This results in a quite inefficient
code in AOT mode.

With this change, calls through fields/getters are decomposed into two
calls, while keeping the same order of evaluation.

Change-Id: Ieb33927c1b39d1b4d8eafb7bd542675820474068
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120628
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-10-08 22:27:10 +00:00
Régis Crelier 735d8b7c64 [VM/nnbd] Propagate nnbd flag on Library from kernel to VM and bytecode.
Also fix a few obsolete comments.

Change-Id: Ice4d36abb950575316db02c3dad2b94a505d7e0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120743
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-10-08 22:25:20 +00:00
Alexander Markov ae251757a9 [vm,aot,bytecode] Performance fixes
* AOT call specializer handles devirtualized static calls to integer
  and double operations more efficiently, so direct call metadata
  should be preferred over specialized bytecode instructions.

* Avoid clearing 'inferredTypeMetadata', which contains inferred-type
  metadata for all members. Previously it was cleared after generating
  the first member by mistake.

Change-Id: Ieaa6ad74cc2168c30b0c9865d17b195c49f85744
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120627
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-10-07 23:06:09 +00:00