Commit graph

68 commits

Author SHA1 Message Date
Zhivka Gucevska 115232ada2 Add support for finalizer of TryFinally in labeled statements
When a break is encountered in the body of a TryFinally statement to an
enclosing label, the finalizer statement of the TryFinally is executed.

BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2991113002 .
2017-08-03 16:17:17 +02:00
Zhivka Gucevska 72ba4f6c1c Add partial support for TryFinally and TryCatch statements
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2985383002 .
2017-08-03 12:51:39 +02:00
Zhivka Gucevska 5e241d86b2 Add support for 'throw' expression
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2987153002 .
2017-08-03 12:36:03 +02:00
Samir Jindel 454ab91576 Fix duplicate context creation when closures appear in initializers.
Summary:

Previously, when a function parameter was captured both in an initializer and in
the body of a constructor, we would create two contexts: one created in a local
initializer and used by other initializers, and another in the body of the
function. This is incorrect, as it means that changes to the parameter in the
initializer's closure won't be visible in the body.

Now, to work around this problem we re-use the context created for the
initializers in the body of the constructor by moving the body into a new
constructor, and redirecting the original constructor to that one, passing the
context as an additional argument. This dance is necessary because local
initializers aren't visible in the body of a constructor.

Test Plan:

A few of the existing closure conversion tests were changed or fixed by this
revision. We also modify the 'closure_in_initializer.dart' test to hit this case
directly.

R=dmitryas@google.com

Reviewers: dmitryas@google.com
Review-Url: https://codereview.chromium.org/2991853002 .
2017-08-03 11:33:40 +02:00
Zhivka Gucevska 4aab6a4a49 Add support for super initializers in constructor initializer list
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2990943002 .
2017-08-03 09:00:16 +02:00
Zhivka Gucevska 66426a2b1c Add support for initializers in constructor invocation
This adds support for field and local initialziers
for constructor invocation.

BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2986973002 .
2017-08-02 12:57:23 +02:00
Zhivka Gucevska 2331199968 Add support for field initialization in objects
Fields declared as T f = E are now initialized to the value
expression E evaluates to.
Fields without initalizer expression are intialized with null.

BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2985883002 .
2017-07-27 13:47:12 +02:00
Samir Jindel ff0c3936a1 Revert "Revert "Preserve type variables in closure conversion.""
This reverts commit fd4a0c658f.
2017-07-26 13:27:35 +02:00
Samir Jindel fd4a0c658f Revert "Preserve type variables in closure conversion."
This reverts commit 4d7490c609.
2017-07-26 12:44:15 +02:00
Samir Jindel 4d7490c609 Preserve type variables in closure conversion.
Summary:

Previously, we filled in all occurrences of captured type variables with either
"dynamic" or their bound, if they had one.

Now, we add extra type parameters to the top-level function corresponding to the
closure, and pass in the corresponding arguments as type arguments to the
"MakeClosure" operation.

Test Plan:

Updated [type_variables.dart] and added a new test case to it.

R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2989563002 .
2017-07-26 12:43:02 +02:00
Zhivka Gucevska 43cf49a717 Add support for running constructors with new
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2984903002 .
2017-07-25 17:24:15 +02:00
Dmitry Stefantsov 5475240725 Add support for converted closures with explicit contexts to VM
The closure-conversion transformation is not enabled yet.  This commit
only adds the support for it to FlowGraphBuilder and
StreamingFlowGraphBuilder.  More work should be done before enabling the
transformation; most mportantly, the 'platform.dill' file that is used
in the Kernel isolate and is loaded by VM for linking with executed
programs should be separated.  The former should receive a file not
touched by the transformation, and the latter should receive a
transformed one.

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

Review-Url: https://codereview.chromium.org/2891053003 .
2017-07-21 11:45:15 +02:00
Samir Jindel a459f73fac Convert closures in all initializers, and share the context between them.
Summary:

Previously, we only handled `FieldInitializer` and `LocalInitializer`.

Now we handle all initializers.

Previously, we would create separate contexts for each initializers, which was
incorrect because it changes made to an argument from a closure within one
initializer would not be seen by a closure within another.

Now, we create the context in a `LocalInitializer` so all initializers will see
the same copy of the argument variables.

There is still an outstanding issue where variables introduced as local
initializers and later captured by closures in subsequent initializers are not
placed into the context. However, this will at least trigger an assert in the closure conversion pass.

Test Plan:

'closures_initializers/initializers.dart(.expect)' has been updated with very
simple test cases for super and redirecting initializers. The second bug
mentioned (captured local initializers) has not been reproduced yet.

BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2981603002 .
2017-07-14 10:59:17 +02:00
Samir Jindel 4df146dd9a Revert "Fix closure conversion in field and local initializers."
This reverts commit a49dcb6bb1.

Committed: a7d1837d3d
Review-Url: https://codereview.chromium.org/2974673002 .
2017-07-10 10:12:45 +02:00
Samir Jindel a7d1837d3d Revert "Fix closure conversion in field and local initializers."
This reverts commit a49dcb6bb1.

Review-Url: https://codereview.chromium.org/2974673002 .
2017-07-07 18:42:51 +02:00
Samir Jindel a49dcb6bb1 Fix closure conversion in field and local initializers.
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2971293002 .
2017-07-07 17:48:38 +02:00
Dmitry Stefantsov b1e629f078 Add tests for handling closures in LocalInitializers
BUG=https://github.com/dart-lang/sdk/issues/29887
R=sjindel@google.com

Review-Url: https://codereview.chromium.org/2944433002 .
2017-07-06 16:39:25 +02:00
Dmitry Stefantsov 6ebe771a71 Remove unnecessary contexts in closure conversion
R=karlklose@google.com

Review-Url: https://codereview.chromium.org/2939043002 .
2017-06-16 11:01:10 +02:00
Dmitry Stefantsov 5982ace801 Add transformLibraries for closure conversion
Closure conversion can now be run on a part of a program.  It allows
using closure conversion in kernel-isolate.  It comes at a cost of
temporarily sacrificing implementation of tear-offs via closures; VM
mechanism for tear-offs is used for now.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2938773003 .
2017-06-15 14:18:10 +02:00
Dmitry Stefantsov 32eed0892d Update expectations for closure conversion tests
R=karlklose@google.com

Review-Url: https://codereview.chromium.org/2935223003 .
2017-06-14 11:03:46 +02:00
Zhivka Gucevska e68b664383 Add support for execution of constructor body
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2880343002 .
2017-05-18 15:30:22 +02:00
Zhivka Gucevska 614f9207b6 Add support for super constructor invocation
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2881053002 .
2017-05-15 13:58:42 +02:00
Zhivka Gucevska c545954a2a Add tests for initializer list execution in object initialization
BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2883823003 .
2017-05-15 12:14:18 +02:00
Zhivka Gucevska a9ce0c53f7 Add test for initialization of instance fields with initializer expressions
BUG=
R=dmitryas@google.com, kmillikin@google.com

Review-Url: https://codereview.chromium.org/2875023002 .
2017-05-11 13:59:57 +02:00
Zhivka Gucevska 184cc25766 Add initial tests for Kernel interpreter
Add logging in the Interpreter for:
 - StaticInvocationExpression, including calls to print
 - ReturnStatement
 - IfStatement

BUG=
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2841803002 .
2017-05-01 16:12:27 +02:00
Peter von der Ahé 2d9956a93d Move kernel baseline tests to front_end.
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2825063002 .
2017-04-19 10:57:58 +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
Dmitry Stefantsov 42f82d1d21 Add primitive to create closures and use it for closure conversion
A new AST node 'ClosureCreation' is added. It takes a name of a
top-level function, a context, and a closure function type and creates a
closure of the given type. The effect of this closure invocation is the
same as of the invocation of the given top-level function with the
contexts as the first argument.

In order to use 'ClosureCreation', the closure conversion pass now
transforms closures into top-level functions, not closure classes. These
functions receive the context as the first argument.

The type of the expression represented by 'ClosureCreation' is its third
parameter. It its the responsibility of closure conversion pass to
create the correct types for 'ClosureCreation' nodes based on types of
closures transformed into top-level functions.

R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2778223002 .
2017-03-31 14:43:56 +02:00
Asger Feldthaus f396d919ae Remove some additional code that depended on the old type propagation.
BUG=
R=kmillikin@google.com

Review-Url: https://codereview.chromium.org/2781473004 .
2017-03-28 13:51:21 +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 28c43eaeab Fix kernel test case format error.
BUG=
R=asgerf@google.com

Review-Url: https://codereview.chromium.org/2766963002 .
2017-03-22 08:32:36 -07:00
Martin Kustermann ad7d04f76a Regenerate kernel strong-mode baseline files
Review-Url: https://codereview.chromium.org/2769573004 .
2017-03-22 08:58:19 +01: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
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
Jens Johansen 067b377a3c Mark new debugging stuff as flaky as it fails on mac/win/whatnot
BUG=

Review-Url: https://codereview.chromium.org/2732973006 .
2017-03-07 10:34:52 +01:00
Martin Kustermann bd59a9724e Regenerate baseline files for kernel/test/baseline_strong_mode_test
Review-Url: https://codereview.chromium.org/2731483002 .
2017-03-02 11:06:43 +01:00
Karl Klose 5df5395559 closure conversion: Do not set Context.parent if the value is null
R=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2716573002 .
2017-02-28 11:23:00 +01:00
Karl Klose 5a42bf8062 Support closures in initializers
Moved the code to modify the current block with context updates to its own class and added another class for context updates in initializer expressions.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2712473003 .
2017-02-28 11:16:41 +01:00
Karl Klose f12f5bcb15 Add multitest markers to reify test
TBR=dmitryas@google.com

Review-Url: https://codereview.chromium.org/2696283006 .
2017-02-17 14:51:33 +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
Martin Kustermann f99d3c9192 Mark kernel test as slow, regenerate baseline file
Review-Url: https://codereview.chromium.org/2682653002 .
2017-02-07 11:16:24 +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
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 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
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 ddc6af7556 Update kernel testcase baseline.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/2541523002 .
2016-11-30 08:18:55 +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 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