Commit Graph

47 Commits

Author SHA1 Message Date
Dmitry Stefantsov 42f82d1d21 Add primitive to create closures and use it for closure conversion
A new AST node 'ClosureCreation' is added. It takes a name of a
top-level function, a context, and a closure function type and creates a
closure of the given type. The effect of this closure invocation is the
same as of the invocation of the given top-level function with the
contexts as the first argument.

In order to use 'ClosureCreation', the closure conversion pass now
transforms closures into top-level functions, not closure classes. These
functions receive the context as the first argument.

The type of the expression represented by 'ClosureCreation' is its third
parameter. It its the responsibility of closure conversion pass to
create the correct types for 'ClosureCreation' nodes based on types of
closures transformed into top-level functions.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2778223002 .
2017-03-31 14:43:56 +02:00
Asger Feldthaus a3402df15c [Kernel] Remove code from the old type propagation.
BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2780513004 .
2017-03-28 12:43:22 +02:00
Dmitry Stefantsov 9ab86da19c Add Vector type to Kernel
There are four operations that work on Vectors: Vector creation, looking
up an item in a Vector, assigning a value to an item in a Vector, and
copying a Vector. The first three operations are allowed to only use
integer literals as number operands (length for Vector creation, index
for item lookup and assignment). Corresponding AST nodes are created for
these operations.

Vectors are used to represent contexts in Closure Conversion. The parent
context is stored as item 0 in its children contexts. The "golden" tests
for this transformation are adjusted accordingly.

The support for Vectors is added to ast-to-text, ast-to-binary, and
binary-to-ast transformations.

R=asgerf@google.com, kmillikin@google.com

Review-Url: https://codereview.chromium.org/2767773004 .
2017-03-27 15:52:32 +02:00
Asger Feldthaus 8bfc4b47c0 Implement canonical name scheme in kernel.
This adds a class CanonicalName that can represent a library, class,
or member.  All references now go through a Reference object, which is
linked to both the AST node and its CanonicalName, so either can be
created first.

dartk now accepts multiple input files:
- If multiple dart files are given, they are all compiled.
- If multiple binaries are given, they are linked together.
Mixed dart and binary input is not supported by dartk.

dartk now has a flag --include-sdk which includes the entire SDK in
the output.  This is so the SDK can be compiled alone and then linked.

Example of compiling separately and then linking:
  dartk foo.dart -o foo.dill
  dartk main.dart -o main.dill
  dartk --include-sdk -o sdk.dill
  dartk main.dill foo.dill sdk.dill --target=vm --link -o program.dill

dartk still has incredibly slow cold start due to the analyzer loading
the dart sdk, so this does not actually speed things up at the moment.

BUG=
R=ahe@google.com, kmillikin@google.com, kustermann@google.com, sigmund@google.com

Review-Url: https://codereview.chromium.org/2665723002 .
2017-02-23 14:12:10 +01:00
Jens Johansen 48d057bdc3 Fix ast_to_text output to pass tests.
Previous commit (86d788e699) broke kernel tests.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2701313006 .
2017-02-22 12:51:29 +01:00
Jens Johansen 86d788e699 [Kernel] replace function debuggable originalAsyncMarker
Previously a functions debuggable field was set to false in the async transformation (and because it wasn't done yet, not in async* and sync* transformation, though it should have been). Now instead, set the original async status and set debuggable on the c++ side equivalently.

Also, on the c++ side, set a functions modifier to async etc if they were originally async etc.

BUG=
R=asgerf@google.com, kmillikin@google.com, kustermann@google.com

Review-Url: https://codereview.chromium.org/2697193008 .
2017-02-22 12:12:54 +01:00
Asger Feldthaus fd6018d2ab Add IR nodes needed for deferred loading.
BUG=
R=sra@google.com

Review-Url: https://codereview.chromium.org/2659343002 .
2017-02-13 14:31:24 +01:00
Peter von der Ahé 3d4ae561f8 Print <Null> instead of crashing.
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2617973002 .
2017-01-31 11:07:13 +01:00
Peter von der Ahé caa67601ba Print 'await' when for is async.
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2527253002 .
2017-01-31 11:07:12 +01:00
Asger Feldthaus 8dd2b15951 Insert implicit downcasts in kernel strong mode.
This is implemented as a separate pass, although going forward
I would like the new frontend to insert these checks.

R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2619193003 .
2017-01-11 13:47:40 +01:00
Jens Johansen 98e96e2a29 Initialize boolean to fix checked mode error.
Vvoid 'boolean expression must not be null' error in checked mode.

BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2619983002 .
2017-01-10 10:41:08 +01:00
Jens Johansen 3f55b8e2b7 Non-format-changing kernel offset changes
Updates to kernel that sets more offsets (and introduces end offests
and 'debuggability') - but doesn't necessarily persist them,
i.e. the format doesn't change and no C++ changes are neccessary yet.

This is step #1 in introducing these things, next step(s) will be
persisting the new stuff and using it on the C++ side.

R=asgerf@google.com, kmillikin@google.com

Committed: https://github.com/dart-lang/sdk/commit/5edca8c4d3733f319ab2d328aa28ceb286a30904

Reopening as I reverted the change as it broke package:compiler.

Review-Url: https://codereview.chromium.org/2610133002 .
2017-01-10 09:16:19 +01:00
Jens Johansen 5215ec6ef2 Revert "Non-format-changing kernel offset changes"
The commit breaks package:compiler.

This reverts commit 5edca8c4d3.

BUG=

Review-Url: https://codereview.chromium.org/2614663007 .
2017-01-05 14:19:23 +01:00
Jens Johansen 5edca8c4d3 Non-format-changing kernel offset changes
Updates to kernel that sets more offsets (and introduces end offests
and 'debuggability') - but doesn't necessarily persist them,
i.e. the format doesn't change and no C++ changes are neccessary yet.

This is step #1 in introducing these things, next step(s) will be
persisting the new stuff and using it on the C++ side.

R=asgerf@google.com, kmillikin@google.com

Review-Url: https://codereview.chromium.org/2610133002 .
2017-01-05 13:25:46 +01:00
Asger Feldthaus 8f12489839 Add --verify-ir flag to dartk and test.py.
This replaces the old --sanity-check flag from dartk. Some files have
been renamed to avoid the wording "sanity check".

Compared to --sanity-check, the following checks have been added:
- variables are not referenced out of scope
- variables are not redeclared
- class type parameters are not referenced from static context

A unit test has been added to check that the verifier rejects certain
invalid ASTs.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2531873002 .
2016-11-28 12:21:19 +01:00
Asger Feldthaus acc8975cab [kernel] Store named parameters in sorted lists instead of using maps.
FunctionType now has a List<NamedType> which must be sorted by name.
Previously, named parameters were stored in a Map<String, DartType>.

FunctionNode still has a List<VariableDeclaration>, but this list must
now be sorted by name.

BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2502343002 .
2016-11-16 15:16:24 +01:00
Asger Feldthaus e63a33717e [kernel] Fix some strong mode issues.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2464843002 .
2016-11-14 10:23:37 +01:00
Asger Feldthaus f6c3ebe4ee [kernel] Fix a bug in printing of string literals with escape sequences.
BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2500453002 .
2016-11-11 12:22:29 +01:00
Kevin Millikin a6bba9520b [kernel] Remove BlockExpression from the Kernel language.
BlockExpression allowed statements to appear in an expression context.
It is unsafe for its original use case, allowing 'yield' to appear as an
expression, because the VM's yield implementation does not work when
there are live expression intermediate values.

Eliminate it by changing the async ExpressionLifter to return a
transformed expression and emit statements into a given list as a side
effect.  This requires implementing the transformation for all
statements to account for how they may contain a nested expression.

BUG=
R=asgerf@google.com

Review URL: https://codereview.chromium.org/2460373002 .
2016-11-01 14:13:30 +01:00
Asger Feldthaus f764b34682 [kernel] Introduce Substitution class and Supertype class.
Type annotations in the supertype clauses of a class are now Supertypes
instead of InterfaceTypes. In the current version, the two classes
contain the same information, but they are about to diverge in the
following ways:

- An InterfaceType may be nullable, whereas a supertype cannot.

- An InterfaceType may represent the exact class, a subclass, or
  a subtype of the given class.

- The type arguments to an interface type represent bounds, whereas
  the arguments to a supertype are always exact.

We also introduce a class Substitution that represents an operator
that replaces type parameters with types, depending on the variance
of their use site.

A substitution can be applied to a DartType or a Supertype, and can
be generated independently of how it will be applied.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2439043002 .
2016-10-24 16:21:52 +02:00
Asger Feldthaus 5f31eff8bd [kernel] Type parameter bounds default to Object instead of dynamic.
This also affects the textual output in most cases, since the bound
is now shown explicitly.

BUG=
R=jensj@google.com

Review URL: https://chromereviews.googleplex.com/526827013 .
2016-10-11 15:21:48 +02:00
Kevin Millikin 466c43c8e0 [kernel] Only produce 'top-level' block expressions from async.
Block expressions are expressions and so can be arbitrarily nested.
They can contain statements, including yield statements.  The VM's
implementation of yield assumes that it can only occur when there are no
live intermediate values.  It is not generally safe to allow
yield-containing block expressions to appear as arbitrary
subexpressions.

As a first step toward eliminating block expressions, this change
flattens the ones produced by the async transformation so that they can
only occur as the children of statements.

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/517457014 .
2016-10-06 08:15:44 +02:00
Asger Feldthaus 564970c10e [kernel] Refactor frontend to allow modular compilation.
The concept of a binary library file no longer exists.

A kernel file can contain any number of libraries, and some of these
libraries can be "external".  To reference a class or member from
another build, the class or member must be declared in an external
library.

Members in an external library contain all their type information,
but have no body.

Classes in an external library have their hierarchy information
present, but are not guaranteed to contain all their actual members.

The idea is that references themselves don't really cross module
boundaries, but rather refer to a local definition whose body is
contributed from elsewhere, much like 'external' members in Dart.

A modular backend such as DDC should be able to compile from one of
these kernel files without needing to load auxiliary information from
summaries or other kernel files.

For whole program transformations or backends, a linking step, which
is not yet implemented, must merge classes and members in external
libraries based on their name.

External libraries share the same IR and binary format as ordinary
libraries.  Transformations that affect the interface for a member
or class should transform the external libraries alongside with the
internal ones, ideally without needing to treat them any different.

R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/516847013 .
2016-10-04 13:30:46 +02:00
Jens Johansen 43b8443f0d [kernel] Dill source file and source position inclusion
For now the focus is on getting stacktraces to look right.
What that basically means is to include source positions for throws,
calls (in many forms).

Includes source file uri for libraries, field, classes and methods.
Methods and fields for instance needs it because of top-level
procedures that might be included via 'parts'.

Corresponding kernel-sdk change in review at
https://chromereviews.googleplex.com/516617014

R=asgerf@google.com, kasperl@google.com

Review URL: https://chromereviews.googleplex.com/509247013 .
2016-09-29 11:26:40 +02:00
Asger Feldthaus e3dac4b11c [kernel] Support both implicit and explicit getters and setters for fields.
Fields getters and setters should be implicit whenever possible
to ensure JS compilers can easily control how they are generated.

However, it is still useful to be able to take control of the getter
or setter in the IR.  We should just refrain from doing so for common
cases, where it can have significant code size impact in JS.

We can use this to insert checked setters for fields that override
a setter with an incompatible type, or whose type references a type
variable.

There are two changes to facilitate this:

- Fields have two flags indicating if the implicit getter and/or
  setter should be generated.  If not set, there can be an explicit
  getter/setter for it in the same class.

- Interface targets that reference a field now go through one
  level of indirection. This lets us update interface targets in
  the IR, which is necessary for redirecting calls to an explicit
  getter or setter.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504357013 .
2016-09-23 12:34:06 +02:00
Asger Feldthaus 700db55970 [kernel] Minor fixes to the AST printer.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/514717014 .
2016-09-21 19:03:52 +02:00
Asger Feldthaus 245e0c0649 [kernel] Remove spurious whitespace around type parameter bounds.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/502307013 .
2016-09-09 13:21:07 +02:00
Asger Feldthaus 60d24a5491 [kernel] Include interface targets in the textual output.
Calls are now printed as follows:

Dynamic calls: receiver.name
Interface calls: receiver.{target}
Direct calls: receiver.{=target}
Dynamic super calls: super.name
Super interfaces calls: super.{target}

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/502957013 .
2016-09-07 14:45:34 +02:00
Asger Feldthaus 760baa3b55 [kernel] Make mixin and super resolution a transformation.
This makes super calls name-based (no target) and add direct calls with
both receiver and explicit target.

Super call resolution translates the name-based super calls into direct
calls after they have been cloned into the mixin application.

For JS backends, it should suffice to clone mixed-in methods that
contain super calls, but that transformation is not part of this CL.

This also adds a --target option to dartk designating the target to
which the kernel IR should be specialized.  The new transformation
is run when --target=vm.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/486537013 .
2016-08-24 16:46:50 +02:00
Asger Feldthaus 551889c3fb [kernel] Remove NormalClass, MixinClass and use just Class.
We need the ability to efficiently transform a mixin application class
into a regular class, and the separation was obstructing it.  It also
simplifies the IR a bit, although it no longer enforces the invariant
that mixin applications cannot contain fields and procedures.

The binary format is unchanged, so the separation still shows up in
there.  This ensures the CL can land without any changes to the SDK.

BUG=
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/488407013 .
2016-08-22 12:35:18 +02:00
Paul Berry 9e90f404a1 [kernel] Fix analyzer warnings and hints
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/488937014 .
2016-08-16 07:33:48 -07:00
Asger Feldthaus 4c82d6853e [kernel] Support metadata annotations on classes and members.
BUG=
R=jensj@google.com, kustermann@google.com, vegorov@google.com

Review URL: https://chromereviews.googleplex.com/481447014 .
2016-08-09 16:32:23 +02:00
Martin Kustermann c7fa95d117 [kernel] Add new [InferredValue] ast node, annotate return types, variables, fields
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/485197013 .
2016-08-09 12:53:42 +02:00
Asger Feldthaus 9885189b09 [kernel] Nullability tracking and API for type propagation.
This adds a notion of bitmasks to the constraint system,
which will be propagated by the solver, and joined using
bitwise OR.  The solver does not care what the bits mean.

These bits propagate nullability and other values that we
care to preserve when a good base class could not be found.

This also adds an interface in front of type propagation
that exposes the inferred types in an accessible manner.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/483887013 .
2016-08-04 13:32:45 +02:00
Martin Kustermann 439447c41a [kernel] Add AsyncMarker.SyncCoroutine
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/464127013 .
2016-08-02 12:14:50 +02:00
Martin Kustermann 6afbf59b56 [kernel] Attempt to make printing of [BlockExpression]s nicer
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/458577016 .
2016-08-02 12:14:50 +02:00
Vyacheslav Egorov 6fc00fe8cf [kernel] Add the first version of async transformer.
This transformer is responsible for lifting subexpression into temporary variables preserved across yield points.

To maintain AST validity I introduced an expression that can contain a block of statements inside called BlockExpression.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/458577014 .
2016-08-02 12:14:50 +02:00
Asger Feldthaus f5093e39b7 [kernel] Include labels in the textual representation.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/475297014 .
2016-07-25 15:18:53 +02:00
Martin Kustermann 1d0f534832 [kernel] Revert "Implement binary format implementation for BlockExpression"
This accidentally landed on master branch.
2016-07-08 09:22:36 +02:00
Martin Kustermann 4acb4446fd [kernel] Implement binary format implementation for BlockExpression
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/462427014 .
2016-07-08 09:18:01 +02:00
Asger Feldthaus f13be3e4bc [kernel] Add LocalInitializer and move super calls last in initializer lists.
LocalInitializer lets us to bind temporaries to variables in the
initializer list.  We use it to ensure the arguments to super() are
evaluated at the right time.

accessors.dart and the new file super_calls.dart have been moved into
a folder "frontend" for frontend helpers that operate on Kernel IR.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/457457013 .
2016-06-28 14:27:01 +02:00
Asger Feldthaus bd76a94541 [kernel] Test type propagation by comparing the output against a gold file.
This should help reviewers see how a change in type propagation affects
the current output.

There are currently only 3 tests with gold files.  We can add more tests
ongoing as more features are implemented.

The expected outputs contains a lot of wrong types because the backing
type propagation is not complete.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/440487013 .
2016-06-08 13:06:17 +02:00
Asger Feldthaus 49746d5092 [kernel] Remove ProcudureKind.IndexGetter and IndexSetter.
They are now ProcedureKind.Operator.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/433267013 .
2016-05-27 11:27:19 +02:00
Asger Feldthaus 9e4e37a4ae [kernel] Add more convenience methods and tweak the behavior of toString().
Also contains a bugfix for a missing visitor call.

BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/438627013 .
2016-05-25 13:56:43 +02:00
Asger Feldthaus 77d0b4b244 [kernel] Support member resolution in class hierarchy.
Review URL: https://chromereviews.googleplex.com/417107013 .
2016-05-09 14:12:40 +02:00
Asger Feldthaus a117d3f8f7 [kernel] Add 'const' modifier to StaticInvocation.
This is to distinguish constant calls to an external constant factory.

This changes the binary format.
2016-04-28 12:58:42 +02:00
Asger Feldthaus 811a47d430 [kernel] Initial implementation of Dart Kernel.
Contains:
- Command-line tool
- Kernel AST
- Binary serialization
- Printing as text
- Frontend based on analyzer
- Class hierarchy and type algebra
2016-04-26 10:39:15 +02:00