Commit Graph

1972 Commits

Author SHA1 Message Date
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 5014aebb8d Avoid a crash when a method overrides a field.
Fixes #30695.

Change-Id: I7935f8d1895e47477ddb1291809efb246c92b913
Reviewed-on: https://dart-review.googlesource.com/5960
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-14 21:44:58 +00:00
Konstantin Shcheglov e0f906068b Resolve to dynamic if the type prefix is not a String.
Currently we implicitly cast the prefix to String and this sometimes
fails, and cause one test in Analyzer resynthesizer fail in checked
mode only.
https://dart-review.googlesource.com/c/sdk/+/5891

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

Bug:
Change-Id: I92993b12f74799defed837c43bda1be734a97787
Reviewed-on: https://dart-review.googlesource.com/5940
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-14 21:07:55 +00:00
Paul Berry 6bf3330e29 Enable a test now that #30034 is fixed
Change-Id: Ie8796e7d66281329917ea5b1cb50278a00325a88
Reviewed-on: https://dart-review.googlesource.com/5890
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-14 20:21:29 +00:00
Paul Berry 872c843040 Suppress type promotion when the promoted type would not be a subtype.
Fixes #30699.

Change-Id: I2b3d93e5dbef208f2266bcae4954bebec19cb1cd
Reviewed-on: https://dart-review.googlesource.com/5887
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-14 20:04:26 +00:00
Konstantin Shcheglov 2ffe920fd0 Don't use absolute path for the test in expectations.
Sorry for spamming.
I messed it up again :-(

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

Bug:
Change-Id: Id9167724b7e711ee006b395284a09bfb25e5b4c9
Reviewed-on: https://dart-review.googlesource.com/5892
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-14 20:01:03 +00:00
Konstantin Shcheglov bee9cc3c42 Revert "Don't use absolute path for the test in expectations."
This reverts commit 047cd9265d.

Reason for revert: Unintentional changes.

Original change's description:
> Don't use absolute path for the test in expectations.
> 
> R=​ahe@google.com, paulberry@google.com, sigmund@google.com
> 
> Bug:
> Change-Id: I5fae0b9c26c9d1766bfe3e53b00d1be3d49aad81
> Reviewed-on: https://dart-review.googlesource.com/5888
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

TBR=paulberry@google.com,ahe@google.com,scheglov@google.com,sigmund@google.com

Change-Id: I1115f49d4a6c66ed8db40b29dc3a4d83b8075c51
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/5900
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2017-09-14 19:57:08 +00:00
Konstantin Shcheglov 047cd9265d Don't use absolute path for the test in expectations.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I5fae0b9c26c9d1766bfe3e53b00d1be3d49aad81
Reviewed-on: https://dart-review.googlesource.com/5888
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2017-09-14 19:53:09 +00:00
Konstantin Shcheglov 84ef57d722 Rename .shaker/.outline to .shaker.expect/.outline.expect and update the message.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I958e7e4a593d5dac2fe0ff6a14852c5587b49672
Reviewed-on: https://dart-review.googlesource.com/5884
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-14 18:17:34 +00:00
Konstantin Shcheglov 57dffcba43 Keep in outlines initializers of constant variables and fields/parameters that might affect constants.
I also changed the way to mark roots for outlines.
Actually for outline purposes we should handle included libraries in
the same way as not included, with only distinction that all of public
nodes are included. So, it is easier to visit them using cycles and
feed into RetainedDataBuilder.

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

Bug:
Change-Id: I0dafad7572388de91f01e72f02599662e86f8759
Reviewed-on: https://dart-review.googlesource.com/5541
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-13 22:09:24 +00:00
Paul Berry ea50970060 In non-strong mode, only infer return types of function expressions, not local functions.
Change-Id: I7e1295f0244e1bd4b8556d49efa2f3b345404ed3
Reviewed-on: https://dart-review.googlesource.com/5502
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-13 21:50:20 +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
Konstantin Shcheglov 2bb1f73406 Include annotations into shaken outputs.
I don't see the "annotations" field for VariableDeclaration, so
annotations for parameters are not included.

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

Bug:
Change-Id: I3d53bf4e277b38e909172cd14f8d9107b4e4ee67
Reviewed-on: https://dart-review.googlesource.com/5296
Reviewed-by: Peter von der Ahé <ahe@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-13 16:44:40 +00:00
Konstantin Shcheglov cb2fba6dbc Serialize and print typedef annotations.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: Icb3a4452603753de645b3fb4280152799f26bb61
Reviewed-on: https://dart-review.googlesource.com/5323
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-13 03:56:49 +00:00
Paul Berry 8f1ca007f2 Fix type inference for const expressions.
The inferred types for const expressions shouldn't refer to type
variables that are in scope, because at runtime those type variables
may take on different values at different times (meaning the const
expression isn't actually const after all).

Test cases are in inference_new, since analyzer implements incorrect
behavior.

Fixes #30677.

Change-Id: I27b9a95a92557ad1ce1c2c0f28d9a760c372d52a
Reviewed-on: https://dart-review.googlesource.com/5298
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-12 21:43:49 +00:00
Konstantin Shcheglov bdb503735d Don't include private nodes into outlines.
Outlines are not "we will resynthesize Analyzer elements from them",
but "what is visible when you import them".


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

Bug:
Change-Id: If42354374e56eca268433ad798245cf605e74d41
Reviewed-on: https://dart-review.googlesource.com/5288
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2017-09-12 20:38:51 +00:00
Konstantin Shcheglov e1d47bd889 Serialize trimmed outlines without damaging Program.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I19b6debeb629b83af071e6a0d4f97b46096d83f5
Reviewed-on: https://dart-review.googlesource.com/5141
Reviewed-by: Paul Berry <paulberry@google.com>
2017-09-12 17:23:20 +00:00
Konstantin Shcheglov b73417173a Transitively mark constructors for super/redirect initializers.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I1addcab62d943ec9c19b46847b9d2fb322b26a3b
Reviewed-on: https://dart-review.googlesource.com/5120
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2017-09-12 03:48:52 +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
Konstantin Shcheglov 6ad5e509f1 Mark nodes for default values of optional parameters.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I63a54705417a9cb07f2172be0282d2129daa0606
Reviewed-on: https://dart-review.googlesource.com/4524
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2017-09-08 22:30:50 +00:00
Paul Berry a734f9908f Store types in auxiliary nodes introduced by desugared property assignments.
Change-Id: If1457f34d80d9b9b560bc678db3fed13bed20fdf
Reviewed-on: https://dart-review.googlesource.com/4601
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-08 21:50:24 +00:00
Paul Berry ce47db6075 Store types in auxiliary nodes introduced by simple desugared assignments.
This CL addresses desugared assignments produced for assignments to
local and static variables.

Change-Id: I1e02745c65ef717a8f6484a0eed35c4ada3b89ac
Reviewed-on: https://dart-review.googlesource.com/4280
Reviewed-by: Peter von der Ahé <ahe@google.com>
2017-09-08 18:11:21 +00:00
Konstantin Shcheglov 8faabf30f4 Export full Class (except private) during outline shaking.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: If8ca2d584600ca060bad6971a0fb02077ccc839a
Reviewed-on: https://dart-review.googlesource.com/4200
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2017-09-07 23:02:12 +00:00
Paul Berry 9ab1a30598 Store types in auxiliary nodes introduced by desugared indexed assignments.
Fixes #30582.

I'll address other kinds of assignments (assignment to a local
variable, static field/setter, or property) in follow up CLs.

Change-Id: I9055e951dc23a4aa1aa19489cf99a832319938c9
Reviewed-on: https://dart-review.googlesource.com/4184
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-07 22:25:45 +00:00
Paul Berry 4d8b18a3b3 Infer return types of local functions appropriately in non-strong mode.
Fixes #30629

Change-Id: I4928521c8b2714167c3cfbd971d2dcb9d3aa79b5
Reviewed-on: https://dart-review.googlesource.com/4141
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-07 20:25:05 +00:00
Konstantin Shcheglov 146590d18a Keep exported nodes during shaking.
R=ahe@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I9475c6582025efa84b0c04d4990ae3b9dc515c03
Reviewed-on: https://dart-review.googlesource.com/3744
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2017-09-07 15:30:24 +00:00
Paul Berry a1f4874a00 Implement type promotion for logical expressions.
This CL implements type promotion logic for both `&&` and `||`;
however, the logic for `||` has no effect, since `_factsWhenFalse`
always returns the current facts.  This is consistent with the current
Dart specification (which only specifies type promotion for `&&`).

Change-Id: I79f608aa33ea0501bb4bba303949330af2da4dda
Reviewed-on: https://dart-review.googlesource.com/3345
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
2017-09-06 17:12:52 +00:00
Paul Berry 068c78e9d7 Change type inference of ?? to match analyzer, prep for future fixes.
Previous to this CL, inference of `??` matched the behavior specified
in the informal spec (https://github.com/dart-lang/sdk/pull/29371),
whereas inference of `?:` matched analyzer behavior.

In the long run, we want the behavior of both `??` and `?:` to match
the spec (note that the spec is still being debated, so this is a
moving target).  But for now, to ease the transition to the new front
end, we want to match analyzer behavior.

With this CL, the inference for `??` is changed to match analyzer
behavior, and a boolean is introduced to make it easy for us to switch
to the behavior specified in the informal spec when it's appropriate
to do so.

Should address the inconsistency pointed out in #30624.

Change-Id: I33d95cd59e4c7e474f3ba27491be87c1bf66d85e
Reviewed-on: https://dart-review.googlesource.com/3421
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-06 15:16:43 +00:00
Paul Berry 4bdad2194d Fix findInterfaceMember when the receiver type is not an InterfaceType.
It is stil permissible to access methods/getters on Object (toString,
==, hashCode, etc.), even if the receiver type is not an
InterfaceType, and we want type inference and kernel annotations to
work correctly.

Change-Id: I311b43c6de31faeefa85bc70636af05c62c4c1fe
Reviewed-on: https://dart-review.googlesource.com/3385
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-05 23:40:17 +00:00
Peter von der Ahé b460a25459 Store actual Reference(s) for additional exports.
R=johnniwinther@google.com, scheglov@google.com

Review-Url: https://codereview.chromium.org/3009953003 .
2017-09-01 16:30:43 +02:00
Konstantin Shcheglov 39b921ecce Transitively include outlines of all public members of Class(es).
R=ahe@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/3004943002 .
2017-08-31 11:35:08 -07:00
Peter von der Ahé f0277b32e8 Revert "Store actual Reference(s) for additional exports."
This reverts commit 234c4a7f49.

Revert "Fix for ScopeBuilder[] - look into setters too."

This reverts commit 7924f4c42f.

Revert "Don't include BuiltinTypeBuilder(s) into additional exports."

This reverts commit e28aac09c4.

The reason for reverting is that the two follow-up commits aren't correct.

R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/3004973002 .
2017-08-31 16:13:50 +02:00
Peter von der Ahé 893b4d4fe9 Add missing copyright on test cases.
Also rename void-methods.dart to void_methods.dart.

R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/3006963002 .
2017-08-31 13:09:20 +02:00
Konstantin Shcheglov 37b301e21a Restructure outline shaker tests.
1. Instead of using a single lib/lib.dart, use a couple of small shared
   libraries, and special libraries for each case we want to test.

2. Give tests meaningful structured names, with "source_*" tests
   testing that we take into account referenced *from* somewhere.
   And "target_*" tests for testing that we include referenced entities.
   And "transitive_*" tests for including complete transitive closure
   of referenced entities.

We don't yet include full transitive closure, this CL is just for
tests and results produced at the moment. Implementation and test
fixes will follow.

We also don't yet take exports into account.

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

Review-Url: https://codereview.chromium.org/3011663002 .
2017-08-30 13:33:27 -07:00
Paul Berry a09896216d Add another runtime check test case.
This test case verifies correct generation of abstract forwarding
stubs.  Since analyzer doesn't contain logic for generating abstract
forwarding stubs, the test is in "runtime_checks_new" so that it won't
be checked against analyzer.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/3009873002 .
2017-08-30 16:23:08 -04: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 234c4a7f49 Store actual Reference(s) for additional exports.
We need this to be able to tree shake outline.
https://github.com/dart-lang/sdk/issues/30448#issuecomment-325434406

R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/3008763002 .
2017-08-30 09:56:21 -07:00
Konstantin Shcheglov 5d07433bb1 Mark types of Constructor parameters and preserve referenced typedefs.
R=ahe@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/3009803002 .
2017-08-29 16:52:51 -07:00
Peter von der Ahé 48503c8720 Don't export unnamed mixins.
Fixes https://github.com/dart-lang/sdk/issues/30553

R=sigmund@google.com

Review-Url: https://codereview.chromium.org/3004703002 .
2017-08-29 16:33:33 +02:00
Peter von der Ahé 6eff945874 Mark top-level error field as static.
Closes https://github.com/dart-lang/sdk/issues/30431

R=sjindel@google.com

Review-Url: https://codereview.chromium.org/2999033002 .
2017-08-29 12:39:00 +02:00
Peter von der Ahé c89fb50056 Fix issues from CL 3009573002.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/3003993002 .
2017-08-28 13:51:52 +02:00
Paul Berry 1cadaf4b80 Add tests demonstrating bugs #30547 and #30552.
R=jmesserly@google.com

Review-Url: https://codereview.chromium.org/3010483002 .
2017-08-26 08:00:07 -07:00
Peter von der Ahé aff5d768d7 Serialize exports scopes.
R=johnniwinther@google.com

Review-Url: https://codereview.chromium.org/3009573002 .
2017-08-25 13:54:13 +02: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