Commit Graph

264 Commits

Author SHA1 Message Date
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
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 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 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 7389397bce [kernel] Disable shared batch mode state.
Sharing the AnalysisContext causes test flakiness when two test cases
share the same 'part' file.

The performance impact is actually surprisingly small.

BUG=
R=kmillikin@google.com

Review URL: https://chromereviews.googleplex.com/500717013 .
2016-08-30 11:15:52 +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 4ff550edc1 [kernel] Share local variable map between environments.
Fixes an issue with captured variables not being shared between
nested functions.

BUG=https://github.com/dart-lang/kernel/issues/24
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/492317013 .
2016-08-23 10:32:38 +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
Asger Feldthaus f98e1d5894 [kernel] Track baseclasses in type propagation.
There is a new lattice point for each class, representing the values
that are subclasses of it.

To ensure that subclassing information is valued higher than subtype
information, we exploit that the ordering of lattice points determines
how the join operation chooses between ambiguous upper bounds.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/488627013 .
2016-08-10 12:50:44 +02:00
Asger Feldthaus b77af073b9 [kernel] Handle classes with a 'call' field or getter.
There is a new 'call handler' meta field in the constraint system,
unfolding any number of 'call' properties on the callee until a
function value is found.

Every method invocation must now load this field to ensure the actual
function is invoked.  This adds quite a bit of overhead, but in strong
mode we should be able to avoid the extra load in practice.

BUG=
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/485117015 .
2016-08-09 12:34:59 +02:00
Asger Feldthaus a9fd5f8b07 [kernel] Add transformation to dynamically verify results of type propagation.
It currently only checks function parameters, and uses an
imperfect check for exactness and subclassing.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/486697013 .
2016-08-05 11:41:05 +02:00
Asger Feldthaus 43e846dc68 [kernel] Ensure all allocated values come with a non-zero bitmask.
Allocation of a value and bitmask input are two different constraints
in the constraint system.  However, for all values other than 'null',
there should be exactly one bitmask input and one allocation constraint.

The bitmask input was omitted in some cases in the handling of
externals, which is fixed in this CL.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/481187013 .
2016-08-05 11:36:24 +02:00
Asger Feldthaus f3b8057f9e [kernel] Fix analyzer warnings and remove unused code.
BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/483967014 .
2016-08-05 11:33:58 +02:00
Asger Feldthaus d5c43b7050 [kernel] Do not use default 'null' value for fields initialized by constructor.
BUG=
R=kustermann@google.com, vegorov@google.com

Review URL: https://chromereviews.googleplex.com/480257013 .
2016-08-04 15:31:31 +02:00
Asger Feldthaus 8ca58e848e [kernel] Handle null being returned when falling over the end of a method.
BUG=
R=kasperl@google.com, kustermann@google.com

Review URL: https://chromereviews.googleplex.com/484727013 .
2016-08-04 15:24:53 +02:00
Asger Feldthaus 6af9572777 [kernel] Handle default parameter values in type propagation.
BUG=
R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/480247013 .
2016-08-04 15:04:57 +02:00
Asger Feldthaus d3361263a1 [kernel] Properly handle arity ranges in more cases.
The constraint fields that model parameters encode the arity of the
call, in order to weed out dataflow from calls with arity mismatch.
But not all the code had been written do follow this strategy.

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

Review URL: https://chromereviews.googleplex.com/479107013 .
2016-08-04 14:52:57 +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
Asger Feldthaus 2295ad8c35 [kernel] Type propagation: Class hierarchy specialization and more.
Instance members are now cloned for every class that inherits it.

The constraint system now explicitly requires all values to be
created using `newValue()`.

There is now a notion of "unions" for representing sets of values.
For class values, unions correspond to types.  For function values,
unions are based on overriding and method names.

The solver's internal map of type (Value,Field) -> Value denoting
the value of a given field has been removed.

The builder must instead register store and load locations for
every valid (Value,Field) pair.  Dynamic stores assign into the
store location, and dynamic loads take the value from the load
location.
Final fields have no store location, so they cannot be polluted
by dynamic stores.

R=vegorov@google.com

Review URL: https://chromereviews.googleplex.com/455987013 .
2016-08-02 18:22:54 +02:00
Asger Feldthaus 2432655e48 [kernel] Add support for batch mode in dartk.
Also forwards errors reported by the analyzer for use
in testing.

BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/476727013 .
2016-07-22 17:42:32 +02:00
Asger Feldthaus 241a79e11b [kernel] Preserve leading BOMs during deserialization.
BUG=#21
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/467567013 .
2016-07-20 14:10:22 +02:00
Asger Feldthaus 10d54d7a61 [kernel] Change the default binary file extension to .dill
BUG=
R=kustermann@google.com

Review URL: https://chromereviews.googleplex.com/475637013 .
2016-07-19 17:52:33 +02:00
Asger Feldthaus 1abc2c897c [kernel] Fix some broken tests and benchmarks.
The tests and benchmarks did not use AnalyzerRepository and the test
expectations for type propagation were not updated after a change to
the frontend.

BUG=
R=ahe@google.com

Review URL: https://chromereviews.googleplex.com/462127013 .
2016-07-01 13:10:00 +02:00
Asger Feldthaus ab59e37155 [kernel] Canonicalize loads and stores in type propagation.
BUG=
R=kasperl@google.com

Review URL: https://chromereviews.googleplex.com/444557013 .
2016-06-14 17:35:01 +02:00
Asger Feldthaus d1f8edf534 [kernel] Fix handling of static setter invocation in type propagation builder.
BUG=
R=kasperl@google.com

Review URL: https://chromereviews.googleplex.com/449907013 .
2016-06-13 16:04:38 +02:00
Asger Feldthaus b18ed0d0ec [kernel] Reorganize some files in the test folder.
Moves type_propagation_dump.dart => type_propagation/dump.dart

Also renames baseline_test_clean to clean_baseline to avoid obstructing
tab completion of baseline_test.

BUG=
R=kasperl@google.com

Review URL: https://chromereviews.googleplex.com/449897013 .
2016-06-13 13:04:52 +02:00
Asger Feldthaus ed8b41704f [kernel] Add option to only print type inference graph for some members.
BUG=
R=kasperl@google.com

Review URL: https://chromereviews.googleplex.com/442527013 .
2016-06-13 12:53:47 +02:00