Commit Graph

782 Commits

Author SHA1 Message Date
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
Asger Feldthaus 9c464d2149 [kernel] Type check untyped == calls specially.
A comparison of form x == null does not need an interface target, but
should still have a return type of 'bool'.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2466373002 .
2016-11-02 09:59: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
Asger Feldthaus 37c5809ccc [kernel] Always store the type of a conditional expressions on the node.
Previously, the type of a conditional expression could be omitted if
one of the arms was just a null literal. This was meant to simplify
translation into kernel, but wasn't really worth it in terms of
complexity, and it does not work well for types that carry nullability
information.

BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2465263002 .
2016-11-01 16:04:10 +01:00
Asger Feldthaus ca5bb64dc0 [kernel] Add strong mode type checking pass.
This is a piece of the upcoming strong mode-based type propagation.
The new type propagator will build its inference graph based on the
subtyping constraints found during type checking.

This type checker is not intended to report type errors to end-users.
In its current form, it is quite redundant with the front end's type
checker, but this will not be the case once we augment kernel's type
system.

The internals of "dart:" libraries are not type checked -- they are
simply assumed to satisfy the type annotations on their interfaces.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2465893002 .
2016-11-01 15:43:31 +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 9b3e387f34 [kernel] Add convenience getter to extract the location of an AST node.
TreeNode.location is a getter for use in diagnostics and debugging.

It uses parent pointers to find the enclosing file URI and line ending
table of the node. If the node has no offset stored, it will use that
of the first enclosing parent that has an offset.

BUG=
R=ahe@google.com, jensj@google.com

Review URL: https://codereview.chromium.org/2448873004 .
2016-10-31 11:29:37 +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
Asger Feldthaus becc43a03c [kernel] Add null initializers to fields that have no initializer.
That is, if a field has no declaration-site initializer and at least
one constructor in the class does not initialize it, then we add an
explicit null initializer for it.

BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/527827014 .

Committed: https://github.com/dart-lang/kernel/commit/63c241ee69fb41710b66df106626461539ce0187
2016-10-18 12:55:10 +02:00
Asger Feldthaus d90deb1491 [kernel] Revert "Add null initializers to fields that have no initializer."
This reverts commit 63c241ee69fb41710b66df106626461539ce0187.

BUG=

Review URL: https://codereview.chromium.org/2431623002 .
2016-10-18 12:26:08 +02:00
Asger Feldthaus 8f836aef2e [kernel] Add null initializers to fields that have no initializer.
That is, if a field has no declaration-site initializer and at least
one constructor in the class does not initialize it, then we add an
explicit null initializer for it.

BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/527827014 .
2016-10-18 12:14:33 +02:00
Jens Johansen 1048f55a29 [kernel] Don't emit InvalidExpression on invalid super in binaryexpression
Don't emit invalidexpression on invalid super call --- a correct call will be created later

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/524077013 .
2016-10-14 13:49:51 +02:00
Asger Feldthaus 0b72c538cc [kernel] Update doc comment for TypeParameter.bound.
BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/526987013 .
2016-10-14 13:29:36 +02:00
Peter von der Ahé a61ac3cc41 [kernel] Use Sink<List<int>> instead of IOSink.
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/521257013 .
2016-10-14 12:16:13 +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 cb80b352e2 [kernel] Fix a bug in bounded type substitution.
When visiting a generic function type in contravariant context, the
current variance bit would not be propagated to the inner visitor.

For example,

  (<F>(T,F) => F) => int [bottom <: T <: String]

would erroneously map to:

  (<F>(bottom,F) => F) => int

instead of:

  (<F>(String,F) => F) => int

Generic function types cannot occur in contravariant position
using current Dart syntax, but it could possibly occur as an
intermediate type.

BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/521207013 .
2016-10-13 16:20:33 +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
Asger Feldthaus b0bfbadbc3 [kernel] Support interface members and overrides with duplicate member names.
When a class inherits two abstract members with the same name from
different supertypes, both members are now present the list returned
by ClassHierarchy.getInterfaceMembers. Previously, only one of the
member would be present.

This ensures that all override pairs can be detected, which in turn
is necessary for inserting covariance checks in strong mode.

Another change in this CL is that interface members are built
eagerly instead of on-demand. This makes the ClassHierarchy more
reliable when used for transformation, and easier to benchmark.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/520907013 .
2016-10-10 11:15:56 +02:00
Asger Feldthaus f8b0846bc5 [kernel] Do not compile patched SDK in strong mode when using VM target.
The VM patch files are not strong mode clean, so we're using a hybrid
approach where the SDK is internally unchecked, and is trusted to
satisfy the types on its interface.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/516487014 .
2016-10-07 15:40:46 +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 ad049ce479 [kernel] Ignore fields inserted through error recovery.
Fields without names often arise when the analyzer fails to parse a
union type in a type argument inside a comment. For example:
  Future/*<Foo|Bar>*/ future;

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/519077015 .
2016-10-06 12:59:52 +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 ea2ddd0882 [kernel] Fix canonicalization of mixin classes.
A mixin application C<T1 ... Tm> with D<T1 ... Tn> is canonicalized if
the Ts are distinct, unbound type variables. In all other cases, a new
class is created per mixin application.

Previously, all mixin applications were canonicalized in an overly
general way, causing type checking issues, and excessive duplication of
type parameters.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/511567015 .
2016-10-04 17:45:24 +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 b56d061411 [kernel] Fix the comment on Library.isExternal.
The comment was the result of a bad merge.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/517957015 .
2016-10-04 17:26:10 +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
Asger Feldthaus 91febfc627 [kernel] Insert break or throw at the end of a switch case that may fall through.
BUG=https://github.com/dart-lang/kernel/issues/12
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/510567013 .
2016-09-30 12:25:07 +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 fe5a26f264 [kernel] Treat an arrow body in a void method as void context.
BUG=https://github.com/dart-lang/kernel/issues/31
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/511307014 .
2016-09-29 11:08:28 +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
Asger Feldthaus 77b7770af4 [kernel] Add sanity checks for dangling or out-of-scope references.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/509427013 .
2016-09-27 13:01:09 +02:00
Martin Kustermann 3afc1542e6 [kernel] Add dart:vmservice_io to the libraries to include in the VM target
(The flutter target already includes dart:vmservice_sky.)

R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/512147013 .
2016-09-27 12:20:16 +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
Asger Feldthaus 6fec4ee7a5 [kernel] Fix a bug in DartOptions.
BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/515767013 .
2016-09-23 17:51:00 +02:00
Asger Feldthaus cd60bb203f [kernel] Ensure class type parameters are not referenced from static context.
BUG=https://github.com/dart-lang/kernel/issues/16
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/510207013 .
2016-09-23 16:33:12 +02:00
Asger Feldthaus 795ce44ec7 [kernel] Refactor the frontend classes.
dartk and other command-line tools no longer rely on analyzer classes
like AnalysisContext or DartSdk, and instead use only the interface
defined in loader.dart.

The class AnalyzerLoader has been renamed to DartLoader.

The sharing of state in batch mode is now owned by loader.dart, so
dartk.dart does not deal with DartSdk and package_config.

Repository no longer has a package or SDK path. These concepts are
now specific to the Dart frontend. Consequently, loading a binary
file no longer relies on URI resolution.

The Repository class is now more clearly focused on linking symbolic
names to their IR objects, which for the time being is only
URI-to-library bindings, but should be extended to support linking
class and member references across different files and different
loaders.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/512907013 .
2016-09-23 16:11:41 +02:00
Asger Feldthaus 4edef131a9 [kernel] Add subtyping query.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/515667013 .
2016-09-23 16:05:28 +02:00
Asger Feldthaus a91cae8bb4 [kernel] Remove the ?? operator from the IR and desugar it in the frontend.
Note that this affects the binary format, since a type is no longer
stored on LogicalExpression.

R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/502297014 .
2016-09-23 12:52:00 +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 e5423f6251 [kernel] Read in -D defines and pass them on to the frontend.
This also enables configuration-specific imports when using a newer
version of the analyzer (not currently on pub).

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/515727013 .
2016-09-23 12:28:33 +02:00
Asger Feldthaus 492e65b68e [kernel] Support .packages file.
BUG=https://github.com/dart-lang/kernel/issues/27
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/508267014 .
2016-09-22 14:18:18 +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
Martin Kustermann 99b1be4d09 [kernel] Add support for passing --url-mapping=<scheme>:<name>::<url> to dartk
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/507527013 .
2016-09-22 13:16:08 +02:00
Martin Kustermann a4a3ad3961 [kernel] Use InvalidInitializer() for initializers with compile-time errors
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/508347013 .
2016-09-22 13:05:16 +02:00
Asger Feldthaus c323d3608a [kernel] Set constructor body to an empty statement if its body was omitted.
BUG=https://github.com/dart-lang/kernel/issues/28
R=johnniwinther@google.com

Review URL: https://chromereviews.googleplex.com/512727013 .
2016-09-22 12:15:42 +02:00