Commit Graph

517 Commits

Author SHA1 Message Date
Paul Berry ba14751f55 Implement override-based inference of instance fields.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2938423003 .
2017-06-17 06:27:27 -07:00
Paul Berry 953399512a Enable top level inference of instance property gets/sets.
To facilitate experimentation, I've left the old code in place, but
disabled it using a const bool `fullTopLevelInference`.  The old code
can be re-enabled by setting this bool to `false`.  Once we are sure
that we want to proceed with this approach, we can remove the old
code.

I believe that with this change, all expressions that can be type
inferred inside a method body can now be type inferred at top level,
provided that there are no circular dependencies.

R=sigmund@google.com

Review-Url: https://codereview.chromium.org/2942153002 .
2017-06-15 20:51:19 -07:00
Paul Berry 44f19d1a60 Lift nearly all top-level type inference restrictions.
This CL lifts all of the restrictions on top level type inference
except for one: the restriction that expressions used for top level
type inference cannot depend on the types of instance getters,
instance setters, or instance fields.  (That restriction will be
lifted in a later CL).

The technique is: to determine the dependencies of an expression,
rather than recurse through the expression applying the rules for what
constitutes an "immediately evident" expression, we simply do a dry
run of the inference algorithm and record what static fields were
accessed.  To avoid recording bogus dependencies on fields whose type
doesn't matter, this dry run skips subexpressions whose type isn't
needed.

To facilitate experimentation, I've left the old code in place, but
disabled it using a const bool `extendedTopLevelInference`.  The old
code can be re-enabled by setting this bool to `false`.  Once we are
sure that we want to proceed with this approach, we can remove the old
code.

Note that this makes the behavior begin to diverge with analyzer
behavior, so I've created a new test directory:
pkg/front_end/testcases/inference_new/, to hold test cases which
aren't expected to match analyzer.  Analyzer is only tested against
the test cases in pkg/front_end/testcases/inference/.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2935323002 .
2017-06-14 20:34:06 -07:00
Paul Berry e03744a740 Fix fasta testcase to avoid a super call to an abstract method.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2941813002 .
2017-06-14 10:55:31 -07:00
Paul Berry 211e578273 Chase imports in analyzer's front_end_inference_test.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2936043002 .
2017-06-13 14:27:54 -07:00
Paul Berry e2c2733556 Add expectations to infer_local_function_return_type.
Previously this test didn't really test anything.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2939523003 .
2017-06-13 13:31:12 -07:00
Paul Berry a1ecb46a4c Fix top level type inference for binary operators.
Multiple changes were required:

- The analyzer's mock SDK had an incorrect return type for
  `num.operator/`.

- We weren't considering the RHS of the binary operators `+`, `-`,
  `*`, and `%` to be an inference dependency (we need to, since the
  special overload rules for int depend on the type of the RHS).

- We weren't executing the overload logic when doing top level type
  inference.

- The logic for deciding what operators are overloaded was incorrect.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2940703002 .
2017-06-13 13:07:00 -07:00
Peter von der Ahé db2e915aac Improve recovery from compile-time errors.
R=danrubel@google.com, paulberry@google.com

Review-Url: https://codereview.chromium.org/2938573002 .
2017-06-13 16:00:15 +02:00
Peter von der Ahé 11f82b12d2 Update golden files.
R=karlklose@google.com

Review-Url: https://codereview.chromium.org/2937683002 .
2017-06-13 10:46:04 +02:00
Peter von der Ahé 5095646191 Apply transformations after comparing to golden files.
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2939533002 .
2017-06-13 09:40:35 +02:00
Peter von der Ahé f559a6d1e9 Throw NSM on unresolved factory redirection.
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2933733002 .
2017-06-13 09:12:20 +02:00
Paul Berry 24bb748bc7 Implement type inference for "not" expressions.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2935763004 .
2017-06-12 17:44:25 -07:00
Paul Berry d4a64e52e7 Add type inference for assignments to this[...]
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2938443003 .
2017-06-12 14:00:59 -07:00
Paul Berry 5d58191948 Add type inference for assignments to super[...]
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2935783003 .
2017-06-12 13:34:38 -07:00
Paul Berry cdb1e858d2 Add type inference for assignments to properties.
This covers explicit property accesses (using both `.` and `?.`) as
well as implicit properties of `this`.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2931363003 .
2017-06-12 11:33:06 -07:00
Peter von der Ahé 043c0096ad Complain about use before declaration.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2924423003 .
2017-06-10 10:12:18 +02:00
Paul Berry 6b65fc22f7 Annotate targets of implicit this property gets/sets in inference tests.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2933663002 .
2017-06-09 17:41:13 -07:00
Paul Berry 8f5bcddc31 Implement type inference for assignments to a static variable.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2933643002 .
2017-06-09 17:36:20 -07:00
Paul Berry ef94f715a9 Add type inference for assignment to local variables.
Also fix some upwards inference cases for assignment to index
expressions.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2928033005 .
2017-06-09 15:13:14 -07:00
Paul Berry 4abff2291b Rework type inference of assignments to index expressions.
The approach from the las CL (try to figure out the structure of the
assignment expression from the desugared result) turned out to be
unsustainably complex.  In this version we keep track of the structure
while doing the desugaring, and then store the result in a wrapper
object the kernel AST.  The wrapper object defers visit methods to the
object it wraps, so when the kernel objects are serialized to disk,
the wrapper disappears.

I also took the liberty of removing the code that inserts types
into the temporary variables and conditional expressions
introduced by desugaring.  I will add this in a later CL if it
proves to be necessary.

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

Review-Url: https://codereview.chromium.org/2927013004 .
2017-06-09 10:48:07 -07:00
Paul Berry 029771d746 Add type inference for complex assignments whose LHS is an index expression.
In later CLs I will expand on this code to handle other kinds of
complex assignments.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2926763003 .
2017-06-08 09:25:24 -07:00
Paul Berry 5c3dd4b11b Change MethodInvocation.interfaceTarget from a Procedure to a Member.
It's possible for the interface target to be a field, e.g.:

    typedef void F();
    class C {
      F f;
    }
    void g(C c) {
      c.f(); // Interface target is C::f
    }

Also, this CL fixes MethodInvocation.getStaticType() in the case where
the interface target is a getter.

R=dmitryas@google.com, kmillikin@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2923653003 .
2017-06-07 09:20:53 -07:00
Peter von der Ahé d6a766bb14 Improve NSM handling.
R=paulberry@google.com

Review-Url: https://codereview.chromium.org/2927613002 .
2017-06-07 09:28:13 +02:00
Paul Berry b18c325f68 Add int.toString() to analyzer mock SDK.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2922383003 .
2017-06-06 13:35:36 -07:00
Paul Berry 49110ba0d6 Fix implementation of fold() in analyzer's mock SDK.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2924853003 .
2017-06-06 13:23:45 -07:00
Paul Berry 7ab22d7ad2 Properly flatten FutureOr types when inferring the type of an async method.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2923733004 .
2017-06-06 13:13:08 -07:00
Paul Berry f7f9d1766f Fix corner cases of type inference with implicit references to .call.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2928613003 .
2017-06-06 13:00:26 -07:00
Paul Berry 32e78868bd Record method invocation targets that are not procedures.
We don't yet store the targets in the kernel representation, since
kernel currently requires method invocation targets to be procedures
(see https://codereview.chromium.org/2923653003/).  But we record the
target that we *would* store in the kernel to instrumentation so that
we can pass tests.

R=ahe@google.com

Review-Url: https://codereview.chromium.org/2920223008 .
2017-06-06 12:27:34 -07:00
Paul Berry 47d50e51a3 Add type inference for this expressions.
R=ahe@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/2925603002 .
2017-06-06 09:54:19 -07:00
Paul Berry b5883633f7 Do not annotate type parameters of instantiated function types.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2925693002 .
2017-06-05 13:26:12 -07:00
Paul Berry 2513c2b93f Adjust expectations for parameterized closures to match front_end behavior.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2925583003 .
2017-06-05 12:51:37 -07:00
Paul Berry 2162b2da9b Improve annotation of type variables in type inference tests.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2918373003 .
2017-06-05 11:47:07 -07:00
Paul Berry 416a860de5 Mark some more type inference tests as passing.
These tests were already working--they just needed expectations files
(and in one case, a `main` method).

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2926433002 .
2017-06-05 10:07:27 -07:00
Paul Berry eefdf15aa1 Perform type inference on default values of optional/named parameters.
R=ahe@google.com

Review-Url: https://codereview.chromium.org/2915763008 .
2017-06-01 21:18:37 -07:00
Paul Berry da869cff4e Fix inference test annotation of named/optional parameters in function types.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2915913004 .
2017-06-01 20:51:29 -07:00
Paul Berry d17f3f3bbd Annotate optional parameter inferred types in front end test cases.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2921533004 .
2017-06-01 20:45:51 -07:00
Paul Berry 349f95f687 Fix a corner case of block closure inference.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2914983003 .
2017-06-01 16:07:59 -07:00
Peter von der Ahé 984b13052d Compute correct return type for factory methods.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2917853002 .
2017-06-01 14:02:05 +02:00
Peter von der Ahé 679cd68453 Update expectations files.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/2921623002 .
2017-06-01 14:01:12 +02:00
Paul Berry 7cdf85da06 Fix a corner case of function type inference.
When an expression function's expression has type `dynamic` (or
`Null`, since `Null` is coerced to `dynamic`), the inferred return
type is taken from the context.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2921583002 .
2017-05-31 21:26:14 -07:00
Paul Berry a122a6409e Add some top level type inference rules for property gets.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2914113002 .
2017-05-31 15:17:16 -07:00
Paul Berry cd5bacbc54 Implement type inference for PropertySet.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2919623002 .
2017-05-31 15:09:28 -07:00
Paul Berry f9c1cab33b Remove some bogus type promotion code.
This code was part of an attempt to prototype some possible extensions
to type promotion to handle `if (x is! Foo)`.  I thought I had
rendered it harmless, but it was having some buggy effects.

Also added a test case demonstrating the problem.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2914093002 .
2017-05-31 13:40:33 -07:00
Paul Berry 26c61e4d22 Implement type inference for PropertyGet.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2921443002 .
2017-05-31 12:26:10 -07:00
Paul Berry 54c57f0015 Remove TODOs from KernelConditionalExpression._inferExpression.
The code is correct as is (at least insofar as it matches analyzer's
behavior).  I've added a new test to verify this, and I've made a
comment on the spec asking for it to be updated to match analyzer's
behavior.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2916633002 .
2017-05-31 10:04:20 -07:00
Paul Berry b89e8cd1a1 Fix inferInvocation for top level inference.
When inferring the type of an invocation for top level inference, if
type parameters are not specified, then it is an error.  So we should
not recurse into subexpressions (even if inferenceNeeded is `true`).
This avoids confusion by making it clear to the user that we don't
take subexpressions into account when doing top level type inference,
even when recovering from type inference errors.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2911323002 .
2017-05-30 14:43:06 -07:00
Paul Berry 6a809aa432 Add type inference logic for "for-in" loops.
R=ahe@google.com

Review-Url: https://codereview.chromium.org/2908973002 .
2017-05-29 07:35:46 -07:00
Paul Berry e4042e5de2 Implement type inference for await expressions in front_end.
This required implementing FutureOr rules in
type_constraint_gatherer.dart.  It also required fixing an incorrect
type in analyzer's mock SDK, which had some follow on effects on
analyzer unit tests.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2904263003 .
2017-05-27 07:30:46 -07:00
Paul Berry 5d69e056d3 Add type inference support for "call" invocations of function expressions.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2911683003 .
2017-05-26 13:34:42 -07:00
Paul Berry d859cc6e4e Add type inference logic for map literals
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2905353002 .
2017-05-26 13:09:53 -07:00