Commit Graph

63 Commits

Author SHA1 Message Date
Asger Feldthaus deedd39f04 Revert "Improvements to the kernel tree shaker."
This reverts commit 71efbad90c.

BUG=

Review-Url: https://codereview.chromium.org/2644543004 .
2017-01-19 16:02:48 +01:00
Asger Feldthaus 71efbad90c Improvements to the kernel tree shaker.
- Use strong-mode types for more precise tree shaking.
- Bail out nicely if dart:mirrors is used.
- Run the tree shaker in the VM target.

The initial tree-shaking pass could be combined with the type checking
pass (inserting implicit down casts) but for now they remain separate.

R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2627723003 .
2017-01-19 14:00:31 +01:00
Karl Klose e88a478a7c Handle constructor bodies
Also rewrites untransformed closures (for example those in initializers) to throw an exception.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2639253003 .
2017-01-19 13:32:18 +01:00
Asger Feldthaus a0b35a6c15 Do not emit InvalidStatement in sanitize_for_vm pass
Closes 28424

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

Review-Url: https://codereview.chromium.org/2638303002 .
2017-01-18 10:31:39 +01:00
Karl Klose 8c6a174091 Use List::filled instead of List:: in closure conversion
The redirecting factory List:: is currently removed and replaced with the actual target at the callsites during construction of kernel, but referencing the actual target here would make the transformation platform specific.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2637083002 .
2017-01-17 15:17:11 +01:00
Asger Feldthaus 2fc333c93d Fix dispatch name of covariance-checked calls.
BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2623333005 .
2017-01-16 12:43:38 +01:00
Martin Kustermann 673eb56471 VM: [Kernel] Fix remaining issues with kernel-based async/await implementation
This CL brings us on-par with the VM implementation in terms of tests.

  * Ensure we have saved-try-ctx/exception/stacktrace variables hoisted out for
    try-catch **and** try-finally.

  * Instead of closing the stream controller for 'async*' functions on return we
    do it inside an try-finally block so we get there in terms of normal and
    exceptional exit.

R=vegorov@google.com

Review-Url: https://codereview.chromium.org/2627873002 .
2017-01-11 19:35:02 +01:00
Asger Feldthaus 70a4d169c0 Insert covariance checks in strong mode.
"Covariance checks" are checks on certain parameters, necessary due to
the unsafe covariant subtyping rule for interface types.

The new pass generates a checked entry point for each method with
covariance checks. This entry point checks the parameters whose type
cannot be trusted, and then calls the actual method implementation.

Every typed call is then redirected to the checked entry point if the
interface taget declares any parameters with unsafe types, unless the
receiver is 'this'.

Dynamic calls and covariant overrides are not addressed by this CL,
these are still unchecked.

BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2618393002 .
2017-01-11 16:33:04 +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 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
Jens Johansen 41165b47e3 Fix to closure mock.dart
program.uriToLineStarts is now program.uriToSource.

BUG=
R=karlklose@google.com

Review-Url: https://codereview.chromium.org/2609183002 .
2017-01-04 12:36:46 +01:00
Karl Klose ff99a0ce59 Merge kernel closure conversion into the Dart SDK
This is the result of:
- taking the diff of the branch closure_conversion to master in the kernel
repository
- updating the file paths
- applying the diff to the Dart SDK
- fixing conflicts between the changes to pkg/kernel in the Dart SDK and the master branch in the kernel repository

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2561723003 .
2016-12-15 10:16:22 +01:00
Asger Feldthaus 440813c67b Check that invocations have well-formed targets in kernel verifier.
This also fixes some issues in the frontend and transformers that
generated calls without the correct number of type arguments.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2533793005 .
2016-11-30 08:24:03 +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 084bd8add2 Speed up kernel sanity checks.
Sanity checks now run in a single pass rather than two, and
instead of building a set consisting of all members, it uses
a bit from the transformer flags to remember which members are
not orphaned.

As an additional check, it now checks that members are not
declared more than once.

R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2529973002 .
2016-11-25 12:02:05 +01:00
Asger Feldthaus d056236180 Enable strong-mode for pkg/kernel and fix some strong-mode warnings.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2523673005 .
2016-11-23 16:16:37 +01:00
Asger Feldthaus 5d310431bd Remove closure_conversion.dart from pkg/kernel.
This file is not strong-mode clean, but since a more recent version
of closure conversion still exists in a branch on the kernel github
repo, there is not much point in fixing this version of it.

BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2526793002 .
2016-11-23 15:34:35 +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 7ca4400f5b [kernel] Fix parent pointer issue in async rewriter.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2502943002 .
2016-11-15 14:27:22 +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 35ffad846d [kernel] Erasure fix: Replace type parameters with dynamic instead of Object.
Using Object causes issues in function types.

This fixes an issue for running delta-blue in AOT strong mode.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2492453002 .
2016-11-14 10:10:49 +01:00
Kevin Millikin 8adc4a6286 [kernel] Fix a bug in the async translation of let expressions.
If the body of a let expression contains an await, the translation could
hoist statements that contain references to the let-bound variable out
of its scope.

Instead split by cases on whether the body contains an await.  If so, we
hoist let-bound variables to the statement level.  If not, we produce a
let expression.

BUG=
R=asgerf@google.com

Review URL: https://codereview.chromium.org/2480743002 .
2016-11-04 14:20:12 +01:00
Asger Feldthaus 652b28f604 [kernel] Do not duplicate constructors for named mixin applications.
BUG=
R=jensj@google.com

Review URL: https://codereview.chromium.org/2473223003 .
2016-11-04 13:45:20 +01:00
Kevin Millikin fb4123b566 [kernel] Kernel: Fix a bug with await in finally.
The translation for async and async* functions translates returns into
two statements, where the second one is a return.  The VM's compilation
strategy is to inline the code for all finally blocks immediately before
a return statement.

This causes future completion/stream cancellation to occur before
finally blocks, instead of after as intended.

The solution here is to translate returns into a break from a labeled
block and put a single async/async* return sequence, outside any finally
blocks, after the labeled block.

BUG=
R=asgerf@google.com

Review URL: https://codereview.chromium.org/2476513003 .
2016-11-03 10:44:24 +01:00
Kevin Millikin 5f93106653 [kernel] Support both older and newer implementations of dart:async.
The VM target's continuation transformer uses a class that was originally
named _StreamIteratorImpl and then renamed to _StreamIterator.  If looking
up the old name fails, try the new name.

BUG=
R=jensj@google.com

Review URL: https://codereview.chromium.org/2465163004 .
2016-11-02 09:32:25 +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
Vyacheslav Egorov b33181adbd [kernel] New VM libraries renamed _StreamIteratorImpl into _StreamInterator.
R=kmillikin@google.com
BUG=

Review URL: https://chromereviews.googleplex.com/527977013 .
2016-10-24 13:19:03 +02:00
Jens Johansen 871a8ccfcc [kernel] Create call to noSuchMethod when super call is not correct.
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/521977014 .
2016-10-14 08:18:25 +02:00
Asger Feldthaus 9b25e445ed [kernel] Follow redirecting factories to their effective targets.
Previously, we would generate a stub for a redirecting factory, but
the default parameter values were not correctly forwarded.

This could have been fixed by copying the default parameter values into
the stub, but this conflicts with modular compilation, since the
element model does not expose default parameter values, and we should
not rely on the AST of libraries not part of the current build unit.

Apart from fixing this bug, this is also more aligned with how all the
backends actually work.

R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/513577013 .
2016-10-07 13:34:14 +02:00
Asger Feldthaus d3fdc335a3 [kernel] Update erasure pass to erase type parameters in constants.
Strong mode allows constant expressions to reference type parameters.
This requires constants to be canonicalized at runtime, but it is not
yet determined exactly how this feature will work in future versions
of the language.

For now, we work around it by replacing such types with 'dynamic'.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/516477013 .
2016-10-06 12:58:11 +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 120c8c3998 [kernel] Erase function type parameters to fake strong mode on the VM.
The VM does not support function type parameters at the moment, but we
can erase them at the last minute, to enable testing of other parts of
strong mode.

This also disables error checking in the SDK since the VM's
patch files are not in strong mode.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/518647013 .
2016-10-04 17:28:45 +02:00
Asger Feldthaus 915854ee14 [kernel] Fix parent pointer in async rewriter.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/518607013 .
2016-09-28 11:17:09 +02:00
Asger Feldthaus 4abe5acc14 [kernel] Remove dead code from async rewriter.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/514107013 .
2016-09-27 13:26:52 +02:00
Martin Kustermann 44a70d3534 [kernel] Mixin desugaring: Clone constructors from base classes, rewrite super initializers
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/510377013 .
2016-09-27 12:19:42 +02:00
Kevin Millikin 79743bee75 [kernel] A one-pass version of the await transformation.
By transforming subexpressions from right-to-left, the transformation knows
whether an expression is possibly live across a await when the expression is
translated.

R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/508487014 .
2016-09-27 10:57:49 +02:00
Asger Feldthaus 38a3e37492 [kernel] Tree shaking transformation.
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/508267013 .
2016-09-23 18:21:35 +02:00
Martin Kustermann fd809932d3 [kernel] Add new flutter target, add dart:_builtin to vm/flutter targets, adjust _getMainClosure
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/513757013 .
2016-09-22 13:17:38 +02:00
Asger Feldthaus c3bcd19da6 [kernel] Fix crashes in closure conversion.
CoreTypes should not require that dart:_internal::Context exists.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/507407013 .
2016-09-21 12:19:52 +02:00
Peter von der Ahé 4cb8fa6b49 [kernel] Return invalid declaration, not null.
R=karlklose@google.com

Review URL: https://chromereviews.googleplex.com/509807014 .
2016-09-20 11:30:45 +02:00
Kevin Millikin 4e5e312534 [kernel] Context allocation, variable get, and variable set (non-loop contexts).
Allocate contexts to hold captured variables.  Rewrite captured variable
access to context access.  Outside of a local function, this is a single
indirection through a named context.  Inside a local function it requires
traversing (a statically known number of) parent links.

R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/507717013 .
2016-09-20 09:07:22 +02:00
Asger Feldthaus 1d2bced4e8 [kernel] Allow async transformer to run on already-transformed code.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504977013 .
2016-09-09 14:51:02 +02:00
Asger Feldthaus 1316073b81 [kernel] Apply async transformation when --target=vm.
BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/504897014 .
2016-09-08 15:25:20 +02:00
Asger Feldthaus 54baf5bb21 [kernel] Also resolve super calls in constructor bodies.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/501087013 .
2016-09-07 16:48:45 +02:00
Asger Feldthaus 4ce54bdb64 [kernel] Decompose method invocations into getters with a call.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504757014 .
2016-09-06 16:22:05 +02:00
Asger Feldthaus 062cb17ec4 [kernel] Strong mode: add interface targets and resynthesis of expression types.
The interface target can now be stored on PropertyGet, PropertySet, and
MethodInvocation  If set, we know the concrete target overrides or
implements that member.

All expressions have a method getStaticType for computing its type,
which relies on interface targets for the expressions that have one.

Expressions whose type is a least upper bound have the type stored
explicitly, so the definition of least upper bounds is contained only
in the frontend.

This is a work in progress towards strong mode support, it is still
not complete.

Still missing in the frontend:
- checks from implicit downcasts
- parameter checks from covariant override or covariant generics

Implemented but not part of this CL:
- subtype tests
- IR type checker (for debugging)

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/496717014 .
2016-09-06 11:40:13 +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