Commit Graph

1972 Commits

Author SHA1 Message Date
Paul Berry 6e842b3c11 Start implementing logic for determining when formal parameters need type checks.
We haven't quite figured out how we want to store the need for these
type checks in the kernel representation, and I'm hoping that my
coding work can help inform that decision.  So for the moment the
annotation is simply stored in the front_end wrapper
(KernelVariableDeclaration).  This is enough to get simple tests to
pass.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/3000353002 .
2017-08-23 10:17:54 -07:00
Paul Berry 53553e8f61 Beef up the covariant generic parameter tear off test case
This reflects some discussion that happened during the review of how
tear offs should be handled; it should help us remember to test a few
additional corner cases.

R=danrubel@google.com

Review-Url: https://codereview.chromium.org/2995383002 .
2017-08-22 16:01:14 -07:00
Paul Berry 247f20b581 Begin writing tests of the runtime checks needed for Dart 2.0 soundness.
The tests in this CL illustrate the major use cases where runtime
checks are required.  They are not exhaustive.  In a later CL I will
copy over some of analyzer's internal unit tests, which are much more
thorough.

So far these tests only pass when tested via analyzer, since analyzer
currently is the only platform that does the necessary analysis to
figure out which checks are needed.  In follow up CLs I will begin
introducing code into front_end to determine which checks are needed,
and to record this information in the kernel representation.

R=danrubel@google.com, sigmund@google.com

Review-Url: https://codereview.chromium.org/3002893002 .
2017-08-20 22:28:36 -07:00
Samir Jindel 1f2844c992 [kernel] Allow arrow_function test to pass.
BUG=
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/3000073002 .
2017-08-16 18:08:14 +02:00
Dan Rubel aefd73b8d3 new handleInvalidTopLevelDeclaration event in fasta parser
This adds a new event for better fasta parser recovery
when the parser detects an invalid character at the top level.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2985703002 .
2017-08-16 09:36:24 -04:00
Peter von der Ahé 07cf2557ed Implement type variables on local function declarations and expressions.
Closes https://github.com/dart-lang/sdk/issues/29798

R=danrubel@google.com

Review-Url: https://codereview.chromium.org/2994973002 .
2017-08-15 11:21:01 +02:00
Paul Berry 2e90786091 Implement type inference for named function expressions.
Named function expressions are not legal in Dart, but they are
accepted by the Fasta parser and BodyBuilder for error recovery
purposes, so the type inference engine needs to support them.

R=ahe@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2993883002 .
2017-08-08 10:02:19 -07:00
Paul Berry 41170b0a15 When reordering constructor initializers, use correct types for temp vars.
In strong mode, when a call to a super-initializer is reordered, we
can use the static type of the super-initializer arguments to set the
types of the temporary variables that we use to do the reordering.
This is desirable because it might help avoid unnecessary casts.

In non-strong mode, we use `dynamic` for the temporary variables, to
replicate Dart 1.0 behavior.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2993193002 .
2017-08-07 13:55:40 -07:00
Paul Berry ae4cbb50af Use "bool" as the downward inference context for assert conditions.
This addresses the type inference part of #30326.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2997513002 .
2017-08-07 10:36:51 -07:00
Paul Berry 1b9ba53fb6 Implement type inference for asserts in constructor initializers.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2995553002 .
2017-08-04 17:55:11 -07:00
Paul Berry 1b03375d62 Implement type inference for super initializers.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2992263002 .
2017-08-03 19:39:13 -07:00
Paul Berry 867d682ff5 Test type inference for field initializers using "this." syntax.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2986403002 .
2017-08-03 14:32:06 -07:00
Paul Berry 57d71479e1 Perform type inference on constructor field initializer expressions.
Fixes #30251

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2994533002 .
2017-08-03 13:54:36 -07:00
danrubel 5909efe401 Fix scanning of unterminated strings
This fixes
* lineStart tracking when synthetic strings added
* token charOffset when scanning UTF-8 stream

These changes prevent the crashes mentioned in
#29976 and #29982.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2984713002 .
2017-08-01 17:31:07 -04:00
Konstantin Shcheglov f9424908a5 Issue 30034. Parse annotations for typedef(s) and resynthesize from Kernel in analyzer.
R=ahe@google.com, brianwilkerson@google.com, sigmund@google.com
BUG= https://github.com/dart-lang/sdk/issues/30034

Review-Url: https://codereview.chromium.org/2987983004 .
2017-08-01 10:08:34 -07:00
Paul Berry c057f091c2 Implement AstBuilder integration for method/function invocations.
This is tricky because there isn't a clean correspondence between
analyzer's AST (which reflects user syntax) and kernel representation.
For example:

  f(args);

could be a call to a static function f, a method f in the current
class, or an invocation of a function-typed object stored in a
variable called f.  ResolutionStorer operates on the kernel
representation, so it sees the difference, but ResolutionApplier
operates on the analyzer AST, so it does not.  So we go to some extra
work to make sure a type is stored for f, regardless of whether f is a
function, method, or a variable.  This requires some re-ordering logic
in ResolutionStorer, since the inferred type of f is not known until
after the args have been visited.

The implementation is not complete; currently the type that we store
in the first two cases is `dynamic` because the type inference
mechanism doesn't preserve enough information to allow us to determine
the correct type; this will be remidied in a future CL.

A similar situation occurs for:

  x.m(args);

which could be a call to a method m in the object x, or an invocation
of a function-typed object returned by the getter m in the object x.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2984013002 .
2017-07-21 10:47:25 -07:00
Paul Berry cc97126aed Implement AstBuilder integration for parenthesized expressions.
The type inference engine doesn't even see parenthesized expressions
as a separate entity, since parentheses don't have any semantics.  So
we just copy the static type from the enclosed expression.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2982323003 .
2017-07-20 13:49:20 -07:00
Paul Berry f1efb202d1 Implement AstBuilder integration for instance creation expressions.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2982323002 .
2017-07-20 12:52:10 -07:00
Paul Berry a93aee1a08 Further integration of front end type inference into analyzer.
This CL propagates types from top level variable declarations into
analyzer ASTs.

This required adding a finishFields method to parser listeners (and a
corresponding method DietListener.listenerFinishFields which calls
it); this allows AnalyzerDietListener to thread the types through from
the BodyBuilder to the AstBuilder.  This is similar to what we were
already doing for methods.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2987503003 .
2017-07-19 23:00:52 -07:00
Konstantin Shcheglov 58b3421f5c Issue 30179. Infer return type of static setters to 'void'.
R=ahe@google.com, paulberry@google.com, sigmund@google.com
BUG= https://github.com/dart-lang/sdk/issues/30179

Review-Url: https://codereview.chromium.org/2977303002 .
2017-07-17 16:24:21 -07:00
Peter von der Ahé efccdf7b1b Update expectations.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2976283002 .
2017-07-17 14:00:17 +02:00
Peter von der Ahé c50abfb1c4 Revert unrelated expectation changes.
This reverts a small fraction of ebb3dea075.

R=johnniwinther@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2981873002 .
2017-07-17 12:11:05 +02:00
Paul Berry 368055944c Reenable commented-out test.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2977973002 .
2017-07-14 10:11:09 -07:00
Peter von der Ahé 18a41eba08 Report messages instead of just printing.
R=sigmund@google.com

Review-Url: https://codereview.chromium.org/2977013002 .
2017-07-14 14:07:44 +02:00
Paul Berry df91c79078 Further integration of front end type inference into analyzer.
This CL propagates types for simple variable declarations into analyzer ASTs.

Note that for a variable declaration like `int x` we need to store two
pieces of information: the element pointed to by `int`, and the type
of `x`.  This CL handles the latter.  The former will wait until we
have enough of the element model built that we have an element to
point to.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2980053002 .
2017-07-13 14:42:05 -07:00
Konstantin Shcheglov ebb3dea075 Set 'isSyntheticDefault' for default constructors.
R=ahe@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2981783002 .
2017-07-13 14:06:11 -07:00
Paul Berry 04ad043f49 Remove code associated with the old "kompile" functionality.
This code is no longer needed because we no longer run the front end
in "kompile" mode.

Also remove the old expectations files used by the "kompile" tests.

I will remove more code in future CLs.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2980883003 .
2017-07-13 12:18:44 -07:00
Paul Berry c9b42f6a41 Remove the "kompile" mode of running the front end.
This mode was needed in the early days of the front end when we were
contemplating the idea of building the analyzer AST representation of
code first, and then converting it to kernel.  Now that we build
kernel directly, it is no longer needed.

Further CLs will follow to remove code that is no longer used after
this change.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2980013002 .
2017-07-13 10:52:55 -07:00
Paul Berry b87556e00d Start copying resolution/inference data from front end to analyzer ASTs.
This CL lays the groundwork for integrating the front end with
analyzer by creating a mechanism to copy resolution and type inference
information (produced by the front end's type inference engine) into
analyzer ASTs (produced by AstBuilder).

The general technique is to parse each function twice: once with
BodyBuilder as a listener and once with AstBuilder as a listener.  The
BodyBuilder generates a kernel representation of the function, but
this isn't used; instead, type inference and resolution information is
captured using ResolutionStorer (which is a TypeInferenceListener).
Later, this information is applied to the analyzer AST generated by
AstBuilder using ResolutionApplier (which is an analyzer AST visitor).

At the moment the intermediate data exchanged between ResolutionStorer
and ResolutionApplier is simply a list of types (one for each
subexpression, in a post-order traversal of the program syntax).  For
debugging and validation purposes, this is augmented with a list of
file offsets, so that if the ResolutionStorer and ResolutionApplier
get out of sync we can diagnose the problem easily.

In later CLs, more data will need to be exchanged between
ResolutionStorer and ResolutionApplier (e.g. a list of elements to
which identifiers are resolved).

This CL doesn't tackle the problem of translating between the kernel
and analyzer representation of types; for now we simply map each type
to `dynamic`.  This is sufficient for early development, since it is
still enough to let us verify that ResolutionStorer and
ResolutionApplier stay in sync.

R=ahe@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2981693002 .
2017-07-13 08:55:29 -07:00
Peter von der Ahé 99d637f581 Improve parsing of function expressions.
Fixes #29937
Fixes #29978
Fixes #29979

R=danrubel@google.com

Review-Url: https://codereview.chromium.org/2968093003 .
2017-07-11 10:35:59 +02:00
Paul Berry b38e4d9a70 Create more synthetic kernel objects.
This CL creates synthetic kernel objects for two additional
BodyBuilder corner cases:

- The synthetic "throw" expression created when code attempts to
  construct an abstract class.

- The "throw" expression created when code attempts to assign to a
  read-only expression.

With this change, we now create a KernelComplexAssignment object for
all assignments; this has allowed me to streamline the code for
creating assignments slightly.

R=ahe@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2972873002 .
2017-07-06 13:51:36 -07:00
Paul Berry d8a6cfa4c1 Fix greatest/least closure computation when there are multiple ?s.
Also add both a unit test and a strong mode inference test case.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2965123002 .
2017-07-06 12:13:07 -07:00
Paul Berry 6c769b39c9 Fix inference test expectations for generic function types.
The analyzer-based test code was incorrectly using typeArguments when
it should have been using typeFormals.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2965023002 .
2017-07-05 06:13:30 -07:00
Peter von der Ahé 6bb89e4fbf Use type variables on Typedef correctly.
R=johnniwinther@google.com, paulberry@google.com

Review-Url: https://codereview.chromium.org/2967923002 .
2017-07-05 13:12:27 +02:00
Peter von der Ahé 3fd7bd1bdc Implement type variables on generalized function types.
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2964013002 .
2017-07-04 13:29:23 +02:00
Erik Corry 955a4b6e71 VM: Reland Inline instance object hash code into object header on 64bit.
Inline instance object hash code into object header on 64 bit.

64 bit objects have 32 bits of free space in the header word.
This is used for the hash code in string objects. We take it
for the default hash code on all objects that don't override
the hashCode getter.

This is both faster and a memory reduction. Eg it makes the
MegaHashCode part of the Megamorphic benchmark 6 times faster.

This is a reland of https://codereview.chromium.org/2954453002/
which fixes an issue that made script snapshots generated on
64 bit platforms incompatible with 32 bit VMs.

BUG=
R=vegorov@google.com

Review-Url: https://codereview.chromium.org/2965723002 .
2017-07-03 09:26:46 +02:00
Paul Berry d0a8b78576 Minor fixes to for-loop type inference
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2966603002 .
2017-06-29 14:35:12 -07:00
Paul Berry 1e9c0d9722 Update expectations now that #30000 is fixed.
Test inference/unresolved_super now passes; it just needed an
expectation file.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2965513002 .
2017-06-29 10:44:56 -07:00
Peter von der Ahé ba84f801f4 Change how unresolved super sends are handled.
The mixin transformer is now responsible for adding no-such-method calls.

Fixes https://github.com/dart-lang/sdk/issues/30000

R=paulberry@google.com, sigmund@google.com

Review-Url: https://codereview.chromium.org/2963763002 .
2017-06-29 12:21:49 +02:00
Paul Berry 0958e40357 Adjust return types of spec-mode function expressions to match VM.
R=scheglov@google.com

The spec is unclear about what is supposed to happen here (see
https://github.com/dart-lang/sdk/issues/30044).  Matching the VM
behavior allows us to pass the existing tests.
Review-Url: https://codereview.chromium.org/2958363002 .
2017-06-28 14:36:00 -07:00
Paul Berry 0efe02372b In non-strong mode, don't infer the type of for-in loop variables.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2960003003 .
2017-06-28 12:43:05 -07:00
Paul Berry c99f11cf80 More fixes for missing interface targets when not in strong mode.
In my previous CL, I only addressed method invocation targets.  This
CL addresses getter and setter interface targets.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2963833002 .
2017-06-28 12:20:56 -07:00
Paul Berry 37a5c124ee Fix for missing interface targets when not in strong mode.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2959213002 .
2017-06-28 11:23:01 -07:00
Paul Berry 919d7965b7 Annotate remaining type inference failures with issue numbers.
R=ahe@google.com

Review-Url: https://codereview.chromium.org/2958993005 .
2017-06-28 09:24:56 -07:00
Paul Berry 9994caf4e2 Add type inference of annotations.
Note that some locations where annotations can occur are not yet
supported by kernel and/or fasta, so there are some test failures.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2963703002 .
2017-06-28 05:30:23 -07:00
Paul Berry 474d5e5d7f Test of type inference when super calls are unresolved.
See https://github.com/dart-lang/sdk/issues/30000 for an illustration
of why this is necessary.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2958113002 .
2017-06-27 14:10:05 -07:00
Paul Berry 12186bb40b Add a test to verify that variables declared in for-loops can be type promoted.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2960723003 .
2017-06-27 08:29:52 -07:00
Paul Berry 2f7c6d61f5 Add type inference for break and continue statements.
Note that no actual type inference needs to be performed, but we still
need to implement the _inferStatement() methods so that we can get rid
of the hack in KernelTypeInferrer.inferStatement.  Also, we need to
call into the listener so that once this logic is hooked into
AstBuilder, analyzer will stay in sync with type inference.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2962583002 .
2017-06-26 14:51:07 -07:00
Paul Berry 93ab0f107e Implement type inference for symbol literals.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2958813002 .
2017-06-26 14:28:48 -07:00
Erik Corry 3c543bb210 Revert "VM: Reland Inline instance object hash code into object header on 64bit."
This reverts commit 8378b8fdbf due to
mysterious crashes on 32 bit ARM with the Flutter Gallery app.

R=aam@google.com
BUG=

Review-Url: https://codereview.chromium.org/2962543002 .
2017-06-26 23:06:09 +02:00