Commit Graph

90 Commits

Author SHA1 Message Date
Paul Berry e8e8359cdf Add local type inference logic for integer literals.
This CL introduces Fasta's first type inference rule, and hooks it up
to all the necessary testing infrastructure.  The rule is that a local
variable whose initializer is an integer literal should have an
inferred type of int.

Only variables occurring at top level within a method are inferred (we
don't yet recurse inside sub-blocks).

Additional type inference rules will be added in follow-up CLs.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2828693003 .
2017-04-20 03:36:19 -07:00
Peter von der Ahé 433575f618 Remove kernel baseline tests.
In CL 2824203002 the associated test cases are moved to pkg/front_end which uses pkg/testing to replace what's implemented in these tests.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2824203002 .
2017-04-19 10:22:25 +02:00
Dmitry Stefantsov cd501b2db3 Switch to Fasta in "golden" tests of closure conversion
R=ahe@google.com

Review-Url: https://codereview.chromium.org/2808443002 .
2017-04-07 14:21:04 +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
Jacob Richman d1fa3c67af Run dartfmt on kernel package
BUG=
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2747113004 .
2017-03-17 08:21:52 -07:00
Paul Berry 685045d619 Start unraveling circularities between analyzer and front_end/kernel.
This CL moves many of the files from
pkg/front_end/lib/src/fasta/analyzer/ to pkg/analyzer/lib/src/fasta/.
It also moves two files from pkg/kernel/lib/analyzer/ to
pkg/analyzer/lib/src/kernel/.

This reduces the amount of circularity between analyzer and
front_end/kernel so that there are no files in front_end or kernel
which are both dependend upon by analyzer and depend upon analyzer.  I
will clean up the remaining circularities in future CLs.

There should be no functional change.

R=ahe@google.com, asgerf@google.com, kmillikin@google.com, scheglov@google.com, sigmund@google.com

Review-Url: https://codereview.chromium.org/2756593004 .
2017-03-17 05:56:06 -07:00
Dmitry Stefantsov 1ec9c97924 Srong-mode tests for generic methods
(`tests/language_strong/generic_methods_*`) are reused as 'golden' tests
for 'reify' transformation.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2756693002 .
2017-03-17 12:51:35 +01:00
Dmitry Stefantsov b87a479c2b Pass type arguments as a list in generic methods invocations
All generic methods are equipped with one extra named parameter for
passing type arguments as a list of type values.

Additinally, this change forces strong mode usage for 'dartk' in
'reified_dart'. Strong mode is required for loader to not strip away
type arguments from generic methods. In future, a command line argument
may be implemented for that (e.g. --generic-methods), if generic method
support will land before the strong mode.

R=karlklose@google.com

Review-Url: https://codereview.chromium.org/2713163002 .
2017-03-16 10:47:11 +01: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
Dmitry Stefantsov d5e2fcb430 Merge the work on Generic Types Reification from 'dart-lang/reify' repo
This CL adds the work done at https://github.com/dart-lang/reify to SDK.
The commit that is used for the merge is
a2066a68374d49de92ff75f5e1ffc36335fd9451 (Nov 23, 2016). The code is
adjusted to respect the changes of the kernel package in SDK since that
commit.

The reify transformation is run by specifying 'vmreify' target to
'dartk'. The transformation requires its runtime library to present in
the program being transformed. The library is found in its default
location in SDK checkout if 'dartk' is run from its default location in
SDK checkout. To preserve the library in the output, TreeShaker is
disabled in 'vmreify' target.

The "golden" set of tests is also copied from 'dart-lang/reify'
repository, and the appropriate test suite is defined for it.

The bash script 'bin/reified_dart' from 'dart-lang/reify' is rewritten
as Dart script 'pkg/kernel/bin/reified_dart.dart'. It requires path to
'dartk' and path to SDK. Those are taken from their default locations in
SDK if 'reified_dart.dart' is run from its default location in SDK.

The added files were formatted using 'dartfmt' with default settings.
Additionally, the files were checked with 'dartanalyzer --strong'. The
necessary changes were made to fix the error messages. There are some
'hint' and 'error' messages left for some .dart files from the added
test cases, but they reflect intentional errors or conventions in those
files.

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

Review-Url: https://codereview.chromium.org/2697873007 .
2017-02-17 14:19:29 +01:00
Asger Feldthaus 6108988ba2 Update closure conversion test suite after changes to Target
BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2674573003 .
2017-02-02 14:30:36 +01:00
Kevin Millikin 0b554a437f Fix a bug in the Kernel testing framework
We obviously should not try to add to an unmodifiable list.

R=asgerf@google.com
BUG=

Review-Url: https://codereview.chromium.org/2677433002 .
2017-02-02 14:19:02 +01:00
Kevin Millikin f9cd5274f5 Fix Kernel tests
Splitting transformations into modular and global ones needs to be
implemented in the tests.

BUG=
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2672713003 .
2017-02-02 14:11:52 +01:00
Asger Feldthaus b07ab608e9 Run tree shaking in strong-mode baseline tests.
This test now asserts that the string literal "unused" does not occur
in the output in addition to checking the expected output.

R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2645733004 .
2017-01-23 10:38:53 +01:00
Asger Feldthaus e6793f76ee 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

Committed: https://github.com/dart-lang/sdk/commit/71efbad90c07bece4010162b77d3b51e79b0a34d
Review-Url: https://codereview.chromium.org/2627723003 .
2017-01-20 10:52:27 +01:00
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
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 2e718613aa Add 'self_check' runtime for running self-checking unit tests
Some of the kernel unit tests can now be run using:

  tools/test.py -cdartk -rself_check language co19

This will search the pkg/ folder for files matching *_self_check.dart
and run each program with the compiled output as argument. If there is
no compiler, the test case itself is given as argument. These testers
are always run in batch-mode.

This type of test has no expected output, but is intended to check
itself by testing that certain invariants are not violated while
processing the given data set.

The 'self_check' runtime is not specifically tied to kernel,
although only kernel is using it at the moment.

There is also a new option --skip-compilation which skips the
compiler step.  It doesn't interact nicely with the status files,
but can still be useful for a quick offline test.

Current limitations:
- All self-check tests are treated as the same test case. If one fails,
  the remaining self-check testers don't run for that input.
- There is no way to run a subset of the self-check tests, or filter
  them based on what compiler was used.
- Tests that are expected to fail in the compiler show up as
  errors when skipping compilation.

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

Review-Url: https://codereview.chromium.org/2549793002 .
2016-12-15 13:07:03 +01:00
Karl Klose d55e9b1c80 Add file missing from previous commit
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2577013002 .
2016-12-15 10:36:45 +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 bb92055c47 Re-enable kernel unit tests on platforms where they are supported.
Some of them use dart:io and/or bigints so they have been disabled
on browsers and JS command-line tests.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2548833002 .
2016-12-05 11:35:41 +01:00
Asger Feldthaus 709c1e0b75 Store library paths relative to a given application root folder.
In kernel, library import URIs now support an "app" scheme as an
alternative to the "file" scheme, representing a path relative to
the application root.

dartk takes an --app-root flag giving the application root. If none
is given, file URIs are used instead.

The intention is that kernel binaries should not carry irrelevant
path information, such as the path to the home directory of the
user who compiled a given file.

It is not the intention that end-users should see an app URI.
Import paths are currently not shown to users at all, and if we need
to do this, they should be translated to file paths first.

In theory we could stick to file URIs with relative paths, but the Uri
class from dart:core makes this difficult, as certain operations on it
assume that file paths should be absolute.

Source mapping URIs are not yet affected by this change.

R=kmillikin@google.com

Committed: https://github.com/dart-lang/sdk/commit/60adb852ad706ecf9424c77d47fa05583d543def

Review URL: https://codereview.chromium.org/2532053005 .

Reverted: https://github.com/dart-lang/sdk/commit/bb540416f27c39d75ee7f243899939fc37a2cd03
2016-11-30 10:39:48 +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 5d26d67342 Revert "Update kernel baseline tests."
This reverts commit b771d61499.

BUG=

Review URL: https://codereview.chromium.org/2540713002 .
2016-11-29 15:01:09 +01:00
Asger Feldthaus 640061d62e Add more checks to kernel verifier.
We now check that classes and type parameters are not redeclared.

The verify_test also verifies that its test harness has no errors,
as this would make all the other tests useless.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2539743002 .
2016-11-29 13:04:43 +01:00
Asger Feldthaus b771d61499 Update kernel baseline tests.
These tests are currently disabled on the buildbots, but we should
keep them up-to-date so we can re-enable them soon.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2533773004 .
2016-11-29 12:58:31 +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 f13881ac08 Fix the pubspec and warnings in pkg/kernel.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2530543002 .
2016-11-23 14:36:22 +01:00
Asger Feldthaus ac21874a21 Disable kernel unit tests.
They are causing issues on dartium and dart2js_jsshell.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2528623002 .
2016-11-23 14:12:54 +01:00
Asger Feldthaus 2eb09d26e3 [kernel] Update and disable some kernel unit tests.
This is in preparation of merging into the SDK repository.
2016-11-23 12:14:59 +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 df36c0b63e [kernel] Remove unnecessary indexing passes from serialization.
Computing the index for variables, labels, and switch cases is now
done on-the-fly instead of as separate passes.

BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/2507723002 .
2016-11-16 15:13:27 +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 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
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 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 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
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 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 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
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 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