This includes:
* Selecting front-end target.
* Support for multi-root virtual file system.
* Not linking platform into resulting kernel file.
* Specifying input as URI (instead of file path) on command line.
* Automatically converting input script URI to package URI.
* Writing ninja dependencies file.
* Writing package-split kernel binaries.
After this change Fuchsia's compiler.dart will become a small wrapper
over pkg/vm, sharing most logic and even most command line options
with pkg/vm gen_kernel tool.
Also, this CL attempts to share some pieces of code between frontend
server and gen_kernel.
In addition, seperate bytecode generation for package-split binaries
is implemented (needed for https://dart-review.googlesource.com/c/sdk/+/85469).
Corresponding Fuchsia CL: https://fuchsia-review.googlesource.com/c/topaz/+/229964
Change-Id: I12d7b2f6401357b3c9df2e31bc736af5a9dc5fd2
Reviewed-on: https://dart-review.googlesource.com/c/85721
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This is a major revamp of bytecode metadata format. Now bytecode has
its own serialization mechanisms.
This CL adds 'bytecode component' metadata, which contains bytecode
object table and string table. All references from bytecode (constant
pools) to libraries, classes, members, types and strings now have a new
format. References to frequently used objects are represented as indices
in object table, while rarely used objects are written inline.
This allows VM to cache frequently used objects while reading bytecode.
Representation of strings is aligned with VM - string characters are
stored in separate pools of one-byte and two-byte strings. This allows
VM to avoid UTF-8 decoding and extra copying.
Closure declarations are now explicit. Type parameters no longer require
enslosing scopes when reading/writing them.
Benchmarks:
GenKernelKernelReadAllBytecode (Intel Core i5) +29.84%
GenKernelKernelReadAllBytecode (Intel Xeon) +28.74%
Change-Id: I4b80009733a8f8c038264af74f97c4e094b9e311
Reviewed-on: https://dart-review.googlesource.com/c/85469
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
This CL adds context ID operand to AllocateContext, CloneContext,
LoadContextVar and StoreContextVar bytecode instructions.
The context ID will be used to create distinct Slots and disambiguate
accesses to context objects corresponding to different scopes.
Change-Id: I98850ab763017b71c1dcacfccaffc085bd850e00
Reviewed-on: https://dart-review.googlesource.com/c/84681
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Number of AssertBoolean instructions in the 100Mb dynamic trace of
Richards benchmark in pure interpreted mode (platform with bytecode):
Before: 1812005
After: 251451
Change-Id: I9fe9d37499d73ffa7636c9ca5fb9c2c18dbc1397
Reviewed-on: https://dart-review.googlesource.com/c/84643
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Make StoreIntanceField and LoadField instructions use a single uniform
abstraction: Slot (used to be called NativeFieldDesc), which represents
either a real Dart field (i.e. a field that has a corresponding Field object)
or a native VM field that does not have a corresponding Field object.
This refactoring eliminates raw stores/loads that were just using offsets
before - now we always know what kind of slots we are accessing and
this yields better aliasing information.
Change-Id: I2f48332d58258219565bd961764e8cc9dd4d75ce
Reviewed-on: https://dart-review.googlesource.com/c/74582
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
In order to enable OSR, CheckStackOverflow IL instructions are attributed
with a non-zero loop depth. The original loop depth is passed as operand
of CheckStack bytecode instruction.
Change-Id: I771f59ba9f8d071680a3b7156be380e0f606b7b2
Reviewed-on: https://dart-review.googlesource.com/c/84081
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Previously MoveSpecial bytecode instruction used unsigned 8-bit A field
to encode target local variable index. This is too restrictive as we allow
signed 16-bit local variable indices.
After this change MoveSpecial has A_X encoding, with A field used for
special index (0 or 1), and signed 16-bit X field used for target local.
Change-Id: Ib87992e192b2923a39a9968913c39476947d3ea5
Reviewed-on: https://dart-review.googlesource.com/c/81440
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
If we use `_InvocationMirror._withoutType`, the symbol for the member name is created dynamically and escapes obfuscation.
We need to create the member name symbol statically via a `const` constructor.
Change-Id: I11c0f745187f4ef1646be6d5348780f502393043
Reviewed-on: https://dart-review.googlesource.com/c/81264
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
The new argument order matches the runtime call and requires less copying.
Simplify Function::HasCode()
Remove obsolete workaround when updating type test cache.
Change-Id: I57c988f97ee2259a22730f445f336cd2a085959e
Reviewed-on: https://dart-review.googlesource.com/76584
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
If a field is initialized with null (either explicitly or implicitly),
field store can be omitted in bytecode. In such case, bytecode should
still convey the information about this initialization to VM for
field guards to work correctly.
Change-Id: I1fd45b858c3c521b97fa5dbffe0e15b1ea75d92f
Reviewed-on: https://dart-review.googlesource.com/76060
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
These bytecode instructions are added in order to shrink constant pools
and reduce time spent for reading constant pool entries.
Change-Id: I8522f73dc7a6236969ac0422c6cb89b945559b2d
Reviewed-on: https://dart-review.googlesource.com/75125
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL adds support for _dynamic_ calls (which are routed through
dynamic invocation forwarders) to bytecode pipeline.
This allows to skip argument type checks for non-covariant and
non-generic-convarint-impl parameters in bytecode when calling instance
members through known interface targets. In case of dynamic call, dynamic
invocation forwarders perform type checks which are otherwise skipped.
This CL also corrects argument type checks in forwarding stubs.
Forwarding stubs are synthetic methods, introduced by front-end to ensure
type safety if some of the argument type checks are skipped.
The specifics of forwarding stubs is that they should use parameter types
of a *target* of a stub for the argument type checks.
This change unifies how argument type checks are performed in bytecode
and in the VM in JIT mode. This allows to mix bytecode methods with
methods JIT-compiled from kernel AST in more cases.
Change-Id: I3a2720a488c8bbb91de1b189eb36ee8c51684a78
Reviewed-on: https://dart-review.googlesource.com/72543
Reviewed-by: Samir Jindel <sjindel@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
When generating bytecode, kernel AST was modifed to sort optional named
parameters. This has unfortunate side-effect of breaking default
(non-interpreter) mode if it uses platform.dill with bytecode.
Bytecode generator is changed to avoid modifications to kernel AST.
Instead, sorted named parameters are kept on a side.
Fixes https://github.com/dart-lang/sdk/issues/34305
Change-Id: Iba473f09af0af515b2117e39d63363412433d538
Reviewed-on: https://dart-review.googlesource.com/72546
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Native methods access their parameters using indices and expect named
parameters to be in the declaration order.
Bytecode generator always sorts named parameters, which is not valid
in native wrappers.
In this CL, the original order of parameters is saved and used
when pushing arguments in native wrappers.
Change-Id: I3fb60c21a484ccae7478b9e59ca16f8b0cde8fd5
Reviewed-on: https://dart-review.googlesource.com/71884
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Generic closures should take delayed type arguments into account when
initializing type arguments in prologue.
Fixes language_2/instantiate_tearoff_test in bytecode mode.
Change-Id: I0ab07e759f3372ae9143a48f0b8b0fe4fab8a51a
Reviewed-on: https://dart-review.googlesource.com/71432
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Samir Jindel <sjindel@google.com>
If receiver is captured, the variable is duplicated so top-level
members can access receiver as a local variable.
This is more efficient and allows uses of receiver in the prologue of
top-level member, before context is allocated and receiver is copied to
the context.
Change-Id: I5b13f692767c3aa445e558bff2bc3f8fbf016561
Reviewed-on: https://dart-review.googlesource.com/71431
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL adds checking of number of passed function type arguments into
prologue of generic functions in bytecode. If type arguments are not
passed, then default type arguments (instantiated bounds) are used.
This mimics IL generated in StreamingFlowGraphBuilder::BuildDefaultTypeHandling.
In order to implement this check, a new bytecode instruction
JumpIfNotZeroTypeArgs is added to bytecode generator and interpreter.
Fixes language_2/function_apply_generic2_test in bytecode mode.
Change-Id: I70901c16b8bfc5f86623d51fccaf50f8969c587e
Reviewed-on: https://dart-review.googlesource.com/71387
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL adds EntryFixed bytecode instruction in bytecode generator and
interpreter. The new instruction is used instead of Entry in prologues of
closures with fixed arguments in order to check number of arguments.
Fixes language_2/closure_call_wrong_argument_count_test in bytecode mode.
Change-Id: I873166a73c5f33e7faca8739cd6f210370e81b2e
Reviewed-on: https://dart-review.googlesource.com/71231
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Receiver and factory type arguments are implicit parameters which are
copied from original stack locations to a context if captured (along
with explicit parameters).
However, they were copied not only in top-level members, but also in
closures. So sometimes context was corrupted with unrelated values
taken from the stack (as closures do not receive these parameters
on the stack).
This CL removes incorrect copying of implicit parameters in closures.
Change-Id: I8d7d3992595f761f4ab7a1c8d16e0fc823fae22a
Reviewed-on: https://dart-review.googlesource.com/71101
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This optimization reduces number of context allocations and decreases
number of context levels, making access to captured variables more
efficient.
This change reduces number of context levels in synthetic bodies of
sync* methods to 1. This is important for correctness because
_SyncIterable::iterator clones unerlying sync* closure to create a new
Iterator using _Closure._clone(), and _Closure._clone() clones only
1 level of context.
Fixes language_2/syncstar_yield_test in bytecode mode.
Change-Id: I7a783702b024a7454253f7f4423ec4b2e08ef61f
Reviewed-on: https://dart-review.googlesource.com/70984
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Also, if return statement is used inside try/finally, its return value
is saved in a variable to avoid clobbering by statements in finally
block.
This CL fixes language_2/stack_overflow_test in bytecode mode.
Change-Id: If6a3981d9dc8673f6b990aa00200e1ab7298c6ac
Reviewed-on: https://dart-review.googlesource.com/70820
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This constant evaluation is needed as default values of optional parameters
of closures can reference local const variables which are not available in
bytecode, so default value expressions can't be serialized without
enclosing AST.
Fixes test language_2/regress_18435_test in bytecode mode.
Change-Id: I1530c5bae058865de8f40d6f636dd747ba407cc5
Reviewed-on: https://dart-review.googlesource.com/70581
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Fix for failing test language_2/final_field_initialization_order_test.
Bytecode generator was incorrectly omitting field initializer if
constructor also has initializer for that field.
Change-Id: I046231865677e1e59122d4d61b238e52b88003b7
Reviewed-on: https://dart-review.googlesource.com/70140
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Instantiator type arguments are sometimes reused instead of doing
instantiation at run time. VM has a bunch of assertions to verify
that this optimization happened. In case of bytecode pipeline, decision
to reuse instantiator type arguments is done while generating bytecode.
For this optimization to correctly happen, bytecode generator
should be able to construct instantiator type arguments the same way
as VM does at run time. Besides flattening of type arguments of
superclasses, VM shrinks them by overlapping type parameters with
type arguments of a superclass (if they match). This CL implements
such overlapping in bytecode generator.
Also, --overlap_type_arguments VM option is removed, as disabling
of type arguments overlapping would break bytecode pipeline.
Change-Id: Ib276c0e688e0e86b44278d88a5c0af09dd342798
Reviewed-on: https://dart-review.googlesource.com/70060
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Now, instead of generating Symbol constant pool entries, bytecode generator
uses kernel-to-kernel constant evaluator to evaluate symbol literals.
Change-Id: I8dae4e388b6c1e8158ce39da792bb2e1cea2687a
Reviewed-on: https://dart-review.googlesource.com/69900
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
As TypeArguments == null means 'vector of all dynamic', VM uses special
object (Object::empty_type_arguments()) to indicate absence of
_Closure._delayed_type_arguments.
This CL corrects bytecode to use Object::empty_type_arguments() (via new
constant pool entry EmptyTypeArguments) to initialize
_Closure._delayed_type_arguments when allocating a closure.
Change-Id: I9b00bc0606de85c02350c8eef08d8952c3e224ee
Reviewed-on: https://dart-review.googlesource.com/69840
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Number of checked arguments is corrected in ICData objects created when
reading bytecode, both for instance and static calls.
InstanceCall1 and InstanceCall2 bytecode instructions are replaced with
InstanceCall which works for any number of checked arguments. This makes
decision on number of checked arguments internal to VM and it is no longer
exposed to bytecode.
Change-Id: I0bba01eca6347336f3832de863b2ce4715fda04a
Reviewed-on: https://dart-review.googlesource.com/69421
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>