Commit Graph

1042 Commits

Author SHA1 Message Date
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
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 4b860db14b [kernel] Reorganize baseline testing.
A single suite of test files is now shared among these configurations,
each with their own expected outputs:
- spec mode
- strong mode
- spec mode w/ type propagation

Although some tests are going to focus on a specific configuration,
for now it seems easier to maintain a single set of tests.

No additional tests have been added in this CL, but the intention
is to start adding more tests.

The baseline tests no longer contain any checked-in dill files.

To simplify dependencies, these tests do not rely on a patched SDK,
which means the async transformer cannot currently be tested with
this framework.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/507347013 .
2016-09-21 12:23:11 +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
Jens Johansen c6d1d01738 [kernel] Fix of saving expression in function body.
Creating a redirecting factory constructor to an abstract class
creates a throw expression directly in function.body.

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/506587013 .
2016-09-21 08:26:35 +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 feded664c0 [kernel] Add bounded substitution operator.
This lets us substitute different values for a type parameter depending
on the variance of its use site. For example:

   (T) => T

can be substituted with [bottom <: T <: num] to get:

  (bottom) => num

which is the best upper bound that doesn't use T.

This generalizes the existing substitution method, since it's
complicated enough that I don't want to maintain two versions of it.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/501577015 .
2016-09-16 15:51:32 +02:00
Asger Feldthaus 8b8a6fda6f [kernel] Fix handling of bottom type in type substitution and unification.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/501577013 .
2016-09-15 15:18:49 +02:00
Peter von der Ahé 78c43f3f7b [kernel] Make targets public.
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/505237014 .
2016-09-14 15:13:16 +02:00
Asger Feldthaus b02cdaccf7 [kernel] Report more errors.
Include up to 100 errors in the output, and print the number
of errors that were truncated.

Also report errors from the SDK and package files.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/506077014 .
2016-09-13 13:16:05 +02:00
Asger Feldthaus 7890404af4 [kernel] Print errors in a nicer format.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/508597013 .
2016-09-13 12:41:22 +02:00
Asger Feldthaus 75c24808ca [kernel] Add support for traversing all member override pairs.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504227013 .
2016-09-13 12:40:11 +02:00
Asger Feldthaus 5711977941 [kernel] Forward scanner and strong mode errors from the analyzer.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/507827013 .
2016-09-13 12:23:51 +02:00
Asger Feldthaus 6ed778c06c [kernel] Pass an object with flags to the target.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/501227015 .
2016-09-09 17:49:34 +02:00
Asger Feldthaus 204a0f9b19 [kernel] Fix unresolved access on class or library prefix.
An unresolved `C.name` would be translate to `this.name` in non-static
contexts.  It is now translated to throw a NoSuchMethodError.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504977014 .
2016-09-09 17:47:31 +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 8ef3abbb09 [kernel] Fix initialization of type parameter bounds on mixin applications.
There was a circularity issue with type parameter bounds being copied
from other classes, while those classes we not yet fully initialized.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/499437013 .
2016-09-09 13:21:29 +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 93299997e3 [kernel] Insert dynamic when type arguments are omitted from redirecting factory.
BUG=
R=kmillikin@google.com

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

Committed: https://github.com/dart-lang/kernel/commit/9d9d61ec4649b159ed3bbe1c2a486d98e7bf07ea
2016-09-08 16:08:43 +02:00
Asger Feldthaus 9a3c54e0e9 [kernel] Revert "Insert dynamic when type arguments are omitted from redirecting factory."
This reverts commit 9d9d61ec4649b159ed3bbe1c2a486d98e7bf07ea.

BUG=

Review URL: https://chromereviews.googleplex.com/502317013 .
2016-09-08 15:35:20 +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 f7fd49e0f1 [kernel] Insert dynamic when type arguments are omitted from redirecting factory.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/500317013 .
2016-09-08 14:24:42 +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
Kevin Millikin 3e8056d8b9 [kernel] Include the library dart:mirrors for target=vm.
Bootstrapping the VM does require dart:mirrors in some modes, and it
will be ignored in the Kernel binary if it is not required by the VM, so
always include it.

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/505697013 .
2016-09-07 16:37:32 +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 e7a10f9424 [kernel] Put the interface target on implied .call invocations.
Example from js_ast:

  class JsBuilder {
  	Node call(x) => ...
  }
  const JsBuilder js = const JsBuilder();

In codegen:
  js("#.#", ...)

Translated to kernel:
  js.call("#.#", ...) // JsBuilder::call as interface target

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/502947013 .
2016-09-07 13:37:25 +02:00
Asger Feldthaus 0613969032 [kernel] Ensure analysis options are also set on the SDK context.
The analyzer keeps a separate AnalysisContext for the SDK, and the
options we set on our own context did not match those on the SDK,
mainly causing issues for strong mode.

Also, the BatchModeState is now used to share the Dart SDK, instead of
using a single instance held in a static variable.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504827013 .
2016-09-07 13:15:58 +02:00
Peter von der Ahé 2aa32c7c54 [kernel] Allow null in super accesses.
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/502937013 .
2016-09-07 11:40:20 +02:00
Asger Feldthaus bb6e93480a [kernel] Copy strong-mode fields in clone visitor.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/504777014 .
2016-09-06 18:41:31 +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 de323e90bd [kernel] Fix interface target for postfix increment in void context.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/496557013 .
2016-09-06 13:43:28 +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
Peter von der Ahé 9b3b4159c9 [kernel] Include 'name' in SuperMethodInvocation.visitChildren.
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/503837013 .
2016-09-05 16:25:34 +02:00
Asger Feldthaus f40abb7e56 [kernel] Do not insert type arguments in super initializer calls
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/502787013 .
2016-09-05 14:19:21 +02:00
Asger Feldthaus 6ac6e2fa96 [kernel] Emit an error, but don't crash, if a target-specific library is missing.
BUG=

Review URL: https://chromereviews.googleplex.com/503797013 .
2016-09-05 13:36:51 +02:00
Kevin Millikin a70332a6c0 [kernel] Add a target-specific list of extra libraries.
Some backend targets require extra libraries that are not used
explicitly by a program (e.g., the Dart VM requires its bootstrap
libraries).  Add a target-specific list of these libraries and ensure
that they are loaded when loading a program from Dart sources.

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/495497014 .
2016-09-01 13:13:41 +02:00
Kevin Millikin f9fffc319f [kernel] Change the annotation Native to ExternalName.
The annotation Native from dart:_internal clashes with a class of the
same name from dart:_js_helper.  Change the one in dart:_internal to
ExternalName instead.

BUG=
R=asgerf@google.com

Review URL: https://chromereviews.googleplex.com/493567015 .
2016-08-31 15:17:27 +02:00
Asger Feldthaus f1422becf5 [kernel] Canonicalize mixin applications within each library.
For example:
  class A extends Foo<int> with Bar<String> {}
  class B extends Foo<int> with Bar<double> {}

becomes:
  class Foo&Bar<S,T> = Foo<S> with Bar<T>;
  class A extends Foo&Bar<int, String> {}
  class B extends Foo&Bar<int, double> {}

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/493197013 .
2016-08-31 09:42:55 +02:00
Asger Feldthaus ca2aaa47b2 [kernel] Make --target default to vm.
BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/498687013 .
2016-08-30 11:26:05 +02:00
Asger Feldthaus 49c32fbc55 [kernel] Fix a bug in the clone visitor.
It would fail to clone a field without an initializer.

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

Review URL: https://chromereviews.googleplex.com/497757013 .
2016-08-30 11:25:25 +02:00