Commit Graph

133 Commits

Author SHA1 Message Date
Kevin Millikin 034501e805 Handle forwarding stubs in mixin application classes
Before: mixin application classes could not have methods of their
own.

After: type inference will sometimes insert forwarding stubs in mixin
application classes.  In the mixin elimination transformation, these
forwarding stubs are replaced with the methods of the mixin class if
they have the same name, but the parameter flags from the forwarding
stub are retained.  The other forwarding stubs are left as methods of
the class.
Change-Id: I5ee89d6b1fc83194df82009c2800b54ce856e8c5
Reviewed-on: https://dart-review.googlesource.com/15887
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kevin Millikin <kmillikin@google.com>
2017-10-24 08:04:18 +00:00
Paul Berry 9aa3a0eec0 Desugar a method invocation into a getter/call when necessary to add an "as" check.
Change-Id: Ic0754a9cfa80a1a91f7c421fb5a1cd55e63e1534
Reviewed-on: https://dart-review.googlesource.com/15762
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-21 11:59:43 +00:00
Paul Berry b8f81c45a5 Standardize on calling synthetic setter parameters '_'.
This has no effect on the generated kernel output; it just affects tests.

Also fix an incorrect type in field_forwarding_stub_explicit_covariant.dart.

Change-Id: Ic89d59a52648dc37a43cb12c4289611daaf422c6
Reviewed-on: https://dart-review.googlesource.com/15647
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-20 19:41:28 +00:00
Paul Berry 270e4c186d Add "as" checks to getter invocations when needed due to return type contravariance.
Change-Id: Ib0151e7f19021c87a08198580dcc6d56425882af
Reviewed-on: https://dart-review.googlesource.com/15221
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-19 19:08:28 +00:00
Paul Berry ca0933c487 Add the appropriate "as" nodes when needed due to return type contravariance.
Also add a test to verify that contravariance is properly handled for
method calls using "if-null" syntax (since this is handled by a
slightly different code path in the front end).

Change-Id: I93ee8b38ff39d78e25cac23ff048fcf69f15b5db
Reviewed-on: https://dart-review.googlesource.com/15000
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-19 16:13:26 +00:00
Paul Berry b51d5035aa Annotate getter accesses with @callKind.
Change-Id: I56453f2824776f4d63de58a09f8ecc5b6f2df8ad
Reviewed-on: https://dart-review.googlesource.com/14622
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-18 17:51:07 +00:00
Paul Berry c2d1260c4a Annotate procedures with contravariant return types.
This will allow the front end to efficiently decide where to insert
"as" checks.

Change-Id: I4776488684acdbf356ed3cb286e8d516d18719e1
Reviewed-on: https://dart-review.googlesource.com/14507
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-17 20:20:40 +00:00
Paul Berry 078da9f5c0 Exchange the order of looping in _computeCovarianceFixes.
The outer loops are now through the arguments of the method to be
fixed, and the inner loops are through the inherited methods.  This
allows us to handle the situation where a forwarding stub is needed
because isGenericCovariantInterface changes from true to false, but
the forwarding stub doesn't need to be concrete, since
isGenericCovariantImpl is inherited from the base class.  (Previously
that situation didn't work because by the time we processed the
inheritance of isGenericCovariantImpl, we had already created a
concrete forwarding stub).

Additional fixes in this CL (necessary to get tests to pass in
meaningful ways):

- Updated InstrumentationValueForForwardingStub to print covariance
  annotations on type parameters.

- Updated _createForwardingStub to copy covariance annotations from
  the target procedure to the procedure being created.

- Moved call_through_this.dart from runtime_checks/ to
  runtime_checks_new/ because the analyzer implementation doesn't
  handle this case correctly.

Change-Id: I984a46826a3a4d8ad1a1ce840269498df049fef0
Reviewed-on: https://dart-review.googlesource.com/13963
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-16 04:07:18 +00:00
Paul Berry 655d3ce665 Account for forwarding nodes when looking up inherited members in InterfaceResolver.
This allows covariance information to propagate properly between
classes and avoids creation of unnecessary forwarding stubs.

Change-Id: Ib55c62adb74d16f94282e752e387634086001946
Reviewed-on: https://dart-review.googlesource.com/12600
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-10 15:55:14 +00:00
Paul Berry 830e68e72d Test whether forwarding stubs handle default arguments correctly (they don't)
This test demonstrates issue #31027.

Change-Id: I2d9e8464b0304e1d41ddc775e8b5ffd37b6e8655
Reviewed-on: https://dart-review.googlesource.com/11141
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-10-06 22:38:46 +00:00
Paul Berry 039f82f7ed Include generic covariance annotations for type parameters in kernel output.
This was inadvertently left out of f94d3950ad.

Change-Id: Ifc3bbd8358322e112bf6b57fc751570d6101c9b6
Reviewed-on: https://dart-review.googlesource.com/11561
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-05 21:40:53 +00:00
Paul Berry 0d931bb75f Take forwarding stubs into account when performing type inference.
Change-Id: I5e6af73ee59458d9324bc48bfb47c06e437cb836
Reviewed-on: https://dart-review.googlesource.com/11644
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-05 21:31:10 +00:00
Paul Berry f94d3950ad Include generic covariance annotations in kernel text output.
Change-Id: I81a7b3ea692e94d7e9bbd8562f1771a7626e0715
Reviewed-on: https://dart-review.googlesource.com/10803
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2017-10-05 05:23:43 +00:00
Paul Berry 7c82b747f8 Actually store forwarding stubs in Class objects.
Change-Id: I3792688a61cdba49b38a8da7f27e9b305fa7a54e
Reviewed-on: https://dart-review.googlesource.com/10704
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-04 17:30:49 +00:00
Peter von der Ahé cda4f284b0 Implement warnings on unresolved this-sends.
Change-Id: Ia9ab202e157102c22b2705d13582d3529288f81e
Reviewed-on: https://dart-review.googlesource.com/8502
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2017-10-04 08:21:32 +00:00
Paul Berry 17a4f66126 Instrument the creation of forwarding stubs.
Change-Id: I98d15cdeaff72da4b6e4b8532689c24f42b6d501
Reviewed-on: https://dart-review.googlesource.com/9860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-09-30 18:27:25 +00:00
Paul Berry 24e1a84fcd Add more tests of forwarding stubs for fields.
Change-Id: I0229fdaadc80dcea6e9977e3af015202352e2e32
Reviewed-on: https://dart-review.googlesource.com/6200
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-15 19:13:27 +00:00
Paul Berry d161b43df7 Fix annotations on forwarding stubs to match new terminology.
Also add a missing test case.

Change-Id: I662e666227fab2ab004869bc126eb1428d9eb9a2
Reviewed-on: https://dart-review.googlesource.com/6180
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-15 17:32:33 +00:00
Paul Berry ccc177b1ce Extend covariance checks to handle fields.
Change-Id: I8f9a7569977f2fe21da3c121903190ee507b4414
Reviewed-on: https://dart-review.googlesource.com/6161
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-15 16:45:42 +00:00
Paul Berry 034a8f37a4 Rework terminology and representation of covariant checks.
Instead of using enums, we use booleans, and we change the terminology
as follows:

FormalSafety.semiSafe     -> isGenericCovariantImpl
InterfaceSafety.semiTyped -> isGenericCovariantInterface

(The enum value FormalSafety.unsafe turned out to be redundant with
isCovariant, so it is no longer needed).

Similarly, the annotations in the front end tests are updated as follows:

@checkFormal=unsafe       -> @covariance=explicit
@checkFormal=semiSafe     -> @covariance=genericImpl
@checkInterface=semiTyped -> @covariance=genericInterface

Change-Id: Iafc0c5d3fc4e7608a2b8c52d8c29f293d9219995
Reviewed-on: https://dart-review.googlesource.com/5540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2017-09-15 15:43:50 +00:00
Paul Berry e386563b46 Fix annotation of call kinds for runtime checks.
A few corner cases weren't being handled correctly by the analyzer
code; some other corner cases weren't being handled correctly by the
front end.

Change-Id: I2b7153a411036541f48019757349b197f9b3bba7
Reviewed-on: https://dart-review.googlesource.com/5328
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-13 17:36:40 +00:00
Paul Berry b20e05ccc6 Simplify logic for computing semiSafe annotations.
Rather than track precisely which types can be passed to each method
parameter through all of the interfaces it implements, and mark them
as semiSafe when they don't match the declared parameter type, it is
simpler to simply make semiSafe an "inherited" version of semiTyped.
The simpler analysis is slightly conservative--it will unnecessarily
mark parameters as semiSafe in a few circumstances, but those
circumstances seem like they will be rare enough that they don't
justify doing extra work.

This allows us to get rid of the extra field additionalIncomingTypes
(which we would otherwise have had to store in the kernel
representation).

In the process, reworked the logic for deciding whether to mark a
parameter as semiSafe or semiTyped so that it uses a type visitor
rather than by substituting and then doing a subtype check; this
should be significantly faster.

Note that in order for semiSafe to be "inherited" in all the right
circumstances, we need to mark it on abstract methods as well as
concrete ones; this is a departure from analyzer behavior, so I've
added a hack to front_end_runtime_check_test to ensure that it
generates the expected annotations.

Change-Id: I53d3718d8fb1979ac8551fe02734ddaf3d6708b8
Reviewed-on: https://dart-review.googlesource.com/5044
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-11 21:57:14 +00:00
Paul Berry a3b9b8b6b5 Implement inheritance of the covariant keyword.
Change-Id: Ifa00459c294e313f562686c612b5668e2e808a2f
Reviewed-on: https://dart-review.googlesource.com/5002
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-11 19:09:08 +00:00
Paul Berry 13502b4e9e Annotate generic method type parameter covariance safety.
This CL extends the computation of unsafe/semiSafe/safe and
semiTyped/typed annotations so that they apply to type parameters of
generic methods as well as ordinary method parameters (previously they
only applied to method parameters).

Change-Id: I5302e1bfe404df5c73656069557b80ca6787b2b4
Reviewed-on: https://dart-review.googlesource.com/4900
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-11 17:24:29 +00:00
Paul Berry 22c80524d9 Implement the necessary logic for marking formals as "unsafe".
Change-Id: I4c40d93da56da18c635cc151e41adc81dfac980d
Reviewed-on: https://dart-review.googlesource.com/4680
Reviewed-by: Peter von der Ahé <ahe@google.com>
2017-09-11 15:36:16 +00:00
Paul Berry c0a5949d95 Rework TypeInferenceEngineImpl.computeFormalSafety()
The old technique had the right effect in a few simple corner cases,
but wasn't correct on theoretical grounds.  The new technique is to
keep track, for every method parameter in every interface, the set of
types which might be passed to that method parameter through base
classes, and then compare those types to the declared method parameter
types.

So for instance, in the code:

    class A<T> {
      foo(List<T> argument) {}
    }
    class B extends A<num> {
      foo(List<num> argument) {}
    }

The set of types that might be passed to B.foo's argument is all
subtypes of List<Object> (since a caller might be invoking foo through
the interface A<Object>).  Since List<Object> is not a subtype of
List<num>, B needs a runtime check.

Change-Id: Iae819e9f8c97ec1cf910fbfacf9bc635fccd9706
Reviewed-on: https://dart-review.googlesource.com/4610
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-09 14:43:26 +00:00
Paul Berry c3ae6bd296 Simplify annotations in runtime check tests.
It turns out that it is easier to calculate whether or not checks are
needed at the site of the declaration of the interface target, not at
the call site.  Accordingly, it makes sense to put the annotations on
the interface target declarations as well.  This lets us get rid of a
clumsy annotation format that referred to arguments by number, in
favor of simply annotating the formal parameters themselves.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/3010613003 .
2017-08-30 11:05:16 -07:00
Konstantin Shcheglov 827075befb Store the covariant keyword flag for parameters and fields into Kernel and resynthesize in analyzer.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/3008463002 .
2017-08-24 07:17:36 -07:00
Paul Berry 913852aaa4 Test some more complex cases of covariant generic parameters.
R=sigmund@google.com

Review-Url: https://codereview.chromium.org/3006463002 .
2017-08-23 15:01:46 -07:00
Paul Berry f6e2676571 Properly annotate the checks needed when invoking function-typed objects.
R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2999403003 .
2017-08-23 13:49:14 -07:00
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