Commit Graph

41 Commits

Author SHA1 Message Date
Dmitry Stefantsov bdf6b9505e [cfe] Ask for subtype checking mode explicitly
The interpretation of the subtype check result depends on the mode.  In partial
NNBD mode all type errors that wouldn't be errors in non-NNBD programs should
become warnings.  In full NNBD mode all such errors are errors.  This CL adds
the mode explicitly to the interface of the subtype check as a parameter.

Bug: http://dartbug.com/38673
Change-Id: I14bcdd260618530cfdd8189c01abba7469a16679
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119545
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
2019-10-02 11:30:29 +00:00
Dmitry Stefantsov e034104f04 [cfe] Remove TypeEnvironment.*Type getters
The getters were returning types of undefined nullabilities.  Now the
nullability-aware getters on CoreTypes should be used instead.

Closes #38224.

Bug: http://dartbug.com/38224
Change-Id: I617a0ef8ee17ebd792c2bc1ec6477a5ee469fee1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118570
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
2019-09-25 13:28:28 +00:00
Dmitry Stefantsov c719d02753 [kernel] Add function to compute variance of typedef type parameters
Change-Id: If00727835c0008917f5ce8154b4bffafb0f31630
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/85102
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2019-09-23 15:17:38 +00:00
Dmitry Stefantsov 9505a1b87f [fasta] Add variance field to type parameters
Change-Id: I0c3eda4057b52853c063a682ff15fb17a595db3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/85082
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2019-09-23 15:17:38 +00:00
Johnni Winther ab8e70addd [cfe] Handle implicit extension access inference
Change-Id: Ia46976af37b586a7b88e3ff8465894e6858a6759
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115210
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-09-03 20:10:26 +00:00
Peter von der Ahé 76e3dfe096 Remove TypeEnvironment.legacyMode
Change-Id: I1bcebc66cbf4d3cb749fdc4cec382d936d4107ca
Reviewed-on: https://dart-review.googlesource.com/c/94212
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
2019-02-25 12:17:54 +00:00
Peter von der Ahé ceb998ecc0 Remove unused TargetFlags
Change-Id: I33f1ffaec5bb9a936639424b78393cd187344ff9
Reviewed-on: https://dart-review.googlesource.com/c/94210
Reviewed-by: Kevin Millikin <kmillikin@google.com>
2019-02-25 12:17:54 +00:00
Dmitry Stefantsov 971733a08b [kernel] Add a class to track variance of type parameters
Change-Id: Ib03f5be2a3a4a2e7e81bc573b7865e9cefe75e7e
Reviewed-on: https://dart-review.googlesource.com/c/85080
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2019-02-01 13:14:36 +00:00
Peter von der Ahé f5fd281150 Prevent unsound promoted bounds from being used as arguments
Fixes https://github.com/dart-lang/sdk/issues/35100

Change-Id: I65f73f40d0ea970f0631599e01b177412fc32a40
Reviewed-on: https://dart-review.googlesource.com/c/90390
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2019-01-29 14:46:04 +00:00
Peter von der Ahé e7495724b9 Remove TypeEnvironment.hierarchy
Change-Id: Ia32e2c0beb504e38f8dcb9bae33f4ee9f0e7daca
Reviewed-on: https://dart-review.googlesource.com/c/88825
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
2019-01-10 05:21:24 +00:00
Dmitry Stefantsov dcc9f74a3c [kernel] Make instantiate-to-bound implementation in Kernel private
Change-Id: I04983b1d99a75054dd93ec6e7131eb7f0492540b
Reviewed-on: https://dart-review.googlesource.com/c/84638
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Auto-Submit: Dmitry Stefantsov <dmitryas@google.com>
2018-11-22 11:50:27 +00:00
Dmitry Stefantsov c560ee9399 [fasta] Remove temporary map typedefInstantiations
Change-Id: Ife72d3b9a2b4f150e5d4e3548409fadec1dc3146
Reviewed-on: https://dart-review.googlesource.com/c/82226
Auto-Submit: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
2018-11-01 18:55:04 +00:00
Peter von der Ahé a8291f767d Update package:kernel to use FunctionType.typedefType
Change-Id: I1d427e4fe98eb54749f3a16027badcff945ef962
Reviewed-on: https://dart-review.googlesource.com/c/82200
Auto-Submit: Peter von der Ahé <ahe@google.com>
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
2018-10-31 06:49:09 +00:00
Peter von der Ahé 1546ff6752 Add class TypeArgumentIssue
Change-Id: Ie46fa496c10e8c78182bb3aeeab1836464259f42
Reviewed-on: https://dart-review.googlesource.com/c/81269
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2018-10-25 09:07:26 +00:00
Peter von der Ahé 724573e332 Rename findBoundViolations to findTypeArgumentIssues
Change-Id: I10bf8afa4a7e7656725bdb5bb05aff9a1252bff3
Reviewed-on: https://dart-review.googlesource.com/c/81265
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2018-10-25 09:07:26 +00:00
Peter von der Ahé 94b9d05349 Move bounds checks to own file.
Change-Id: I0954bdb2633c0fae8d760bff05e5be8bbba59c57
Reviewed-on: https://dart-review.googlesource.com/c/81262
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2018-10-25 09:07:26 +00:00
Kevin Millikin 796d628ab6 Improve error reporting from Kernel scripts
* Ensure that we have a .dill file and it has the correct version before
  we start decoding it in dump.dart.

* Throw errors, not strings.  Ensure that they have a useful
  toString().

* Do not print usage except when the command is invoked
  incorrectly (wrong number of arguments).  Once we get into the
  command it's less likely that it's been invoked incorrectly and more
  likely that something else has gone wrong.

  Because these utilities are invoked from other scripts (like the
  fasta command), printing their usage for problems other than
  invoking them correctly doesn't match the way that they were invoked
  and it's confusing.

Change-Id: I7832383594d2b3719a0a7a7392ba4685717a79d2
Reviewed-on: https://dart-review.googlesource.com/c/78206
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2018-10-05 12:19:01 +00:00
Alexander Aprelev c339846594 [kernel] Move util.dart from bin to lib.
bin/util.dart doesn't have main() entry point and that breaks snapshot generation that is
automatically invoked by pub for all dart sources in bin/ folder.

See https://github.com/flutter/flutter/pull/19044\#issuecomment-402241782

Change-Id: Ie91549173536740992ce61d830efdfdc603c5564
Reviewed-on: https://dart-review.googlesource.com/63683
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2018-07-04 00:50:16 +00:00
Kevin Millikin 1abf929476 Fix some uses of deprecated API
Fix all deprecation warnings in the kernel and vm packages.

Change-Id: I44e5b128cc8fbc1360ad4c49ecdf2aa7cfd269d8
Reviewed-on: https://dart-review.googlesource.com/46720
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Kevin Millikin <kmillikin@google.com>
2018-03-15 10:09:23 +00:00
Peter von der Ahé fd19dfe5f5 Remove IncrementalClassHierarchy
Change-Id: Ie141648f8fbc97a025e90cc456265a51c3da0b04
Reviewed-on: https://dart-review.googlesource.com/41823
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
2018-02-16 09:13:46 +00:00
kmillikin b019045393 Front-end implementation of mixin type inference.
Infer missing type arguments to generic mixin classes in mixin
applications based on mixin supertype constraints.  The implementation
directly follows the draft feature specification at
https://dart-review.googlesource.com/c/sdk/+/38940.

Bug: https://github.com/dart-lang/sdk/issues/31984
Change-Id: I7caba037b1b0e73c44f71aaa958f3ff3e8f3c1f0
Reviewed-on: https://dart-review.googlesource.com/40661
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2018-02-14 22:43:24 +00:00
Dmitry Stefantsov da0b6f52ed Add more abstract query methods to ClassHierarchy
Bug:
Change-Id: I7c30059a45ce7b63221fcb52e45bdd07dc1a1e71
Reviewed-on: https://dart-review.googlesource.com/35700
Reviewed-by: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
2018-01-18 15:45:34 +00:00
Peter von der Ahé 4d1adf42d3 Deprecate IncrementalClassHierarchy
See https://github.com/dart-lang/sdk/issues/31842

Change-Id: I019909831a91a4e06138dc3a6bf32f766bca1ae6
Reviewed-on: https://dart-review.googlesource.com/34880
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2018-01-17 13:30:17 +00:00
Paul Berry 27f5e7f9ee Remove ClassHierarchy.forEachCrossOverridePair.
This method is no longer needed, since the front end iterates through
members directly to find cross overrides.

Change-Id: Ibc5180962a097c4d6194dbf4cbd1a0dea15050c2
Reviewed-on: https://dart-review.googlesource.com/13582
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-13 20:28:55 +00:00
Paul Berry d9ca760992 Start writing the infrastructure for creating forwarding stubs.
This CL adds the ability to create a list of "forwarding nodes" for a
source class.  A forwarding node is a data structure that will later
be resolved to either an explicitly declared member in the class or a
superclass, or to a forwarding stub.  The idea is that we will create
the forwarding nodes at the time of outline building, and later,
during type inference, we will resolve each forwarding node as it is
encountered.

The reason we need to defer resolution of the forwarding nodes until
inference is because we may need to use the results of type inference
to determine which member a given forwarding node resolves to.  For
example:

num f() => 1;
class A {
  final x = 1; // Inferred type: int
}
class B {
  final x = f(); // Inferred type: num
}
abstract class C implements A, B {}

We cannot determine at the time of building the outline for C whether
it inherits its x from A or B, because we need the results of type
inference to determine which of the two x's has a more specific type.

Note that some refactoring of ClassHierarchy was necessary in order to
allow the front end to maintain member lists in the same order used
internally by ClassHierarchy.  This will let us avoid unnecessary
redundant sorting of methods.

Change-Id: Iee754957e0ad3b16c4b60608e17a4a7b0006dfb4
Reviewed-on: https://dart-review.googlesource.com/7851
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2017-09-25 20:59:49 +00:00
Paul Berry f1665714a5 Move batch_util.dart into pkg/kernel/lib/.
This will allow tests that use batch_util.dart to be run inside
google3, where package layout conventions are more strictly enforced
(files in test/ cannot import files in bin/ or vice versa).

Change-Id: I046b864bc3b1c4e78b984b0047b7567873146c52
Reviewed-on: https://dart-review.googlesource.com/7340
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-09-22 16:52:07 +00:00
Paul Berry 017a1f4eff Revert "Fix forEachOverridePair in the case where the class in question is abstract."
This reverts commit e81deebfd8.

My reasoning in the above commit was wrong.  Consider the following code:

class A {
  void foo() {}
}
abstract class B extends A {
  void foo([x]);
}
class C extends B {}
main() {
  B b = new C();
  b.foo(42); // BAD: A.foo can't accept arguments.
}

To ensure soundness, this code needs to be disallowed, and the current
mechanism for doing that is to use forEachOverridePair.  Note that
forEachOverridePair is a bit of a misnomer; in addition to yielding
all pairs of methods (M1, M2) for which M1 overrides M2, it also
yields pairs of methods (M1, M2) for which the target class inherits
the concrete implementation M1, and M2 is part of the interface.
Technically this latter case is not an "override" but rather an
"implementation" (thanks to Lasse for pointing out this distinction).
However in both cases we need to do the same compile-time check to
ensure soundness: we need to check that the type of M1 is a subtype of
M2 (unless the check is suppressed by a "covariant" keyword).  Hence
it makes sense for forEachOverridePair to cover both cases.

To ensure that the above example is properly rejected, it is crucial
that some invocation of forEachOverridePair yield the pair (A.foo,
B.foo).  Prior to e81deebfd8,
forEachOverridePair(B) would not yield this pair, but
forEachOverridePair(C) would.  After
e81deebfd8, both calls yield this pair.

When I made e81deebfd8, I failed to
notice that forEachOverridePair(C) would yield the pair, so I thought
there was a problem.  So my "fix" was unnecessary.  And it created a
fresh problem: it meant that the following code would be disallowed:

class A {
  void foo() {}
}
abstract class B extends A {
  void foo([x]);
}
class C extends B {
  void foo([x]) {}
}
main() {
  B b = new C();
  b.foo(42); // OK: C.foo can accept an argument.
}

There is no a priori soundness reason for rejecting this code, and
according to Lasse, it has not yet been decided whether Dart 2.0 will
allow it.

This CL restores the old behavior.  Rather than remove the test case
in e81deebfd8, it modifies it to
demonstrate why the old behavior was correct.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/3004023002 .
2017-08-29 14:46:15 -07:00
Paul Berry e81deebfd8 Fix forEachOverridePair in the case where the class in question is abstract.
ClassHierarchy.forEachOverridePair contains special logic for unusual
cases like this one:

class A {
  void foo() {}
}
class B extends A {
  void foo();
}
main() {
  B b = new B();
  b.foo();
}

In this case, A.foo is considered to override B.foo (contrary to the
usual situation where the derived class method overrides the
superclass method).  The reasoning is that calling foo on a concrete
instance of B will cause A.foo to be executed (as illustrated in
main); therefore A.foo is callable via the interface of B.foo, thus in
a sense A.foo "overrides" B.foo.

The code contained a questionable optimization, however; it only
executed this special logic if the derived class was concrete.
Presuambly the reasoning was that if B were abstract, then a concrete
instance of B could never be created, so this situation could never
arise.

However, there is nothing to stop a concrete class from being derived
from B, e.g.:

class A {
  void foo() {}
}
abstract class B extends A {
  void foo();
}
class C extends B {}
main() {
  B b = new C();
  b.foo();
}

Now, calling foo on a concrete instance of C will cause A.foo to be
executed (as illustrated in main); therefore A.foo is callable via the
interface of B.foo, as before.  So we still need to report this as an
override pair even though B is abstract.

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

Review-Url: https://codereview.chromium.org/2998383002 .
2017-08-28 11:48:59 -07:00
Paul Berry 41dcc04a80 Expose getInterfaceMembers method through ClassHierarchy.
The front end will need to use this method to iterate through the
interface of a class in order to determine when to create forwarding
stubs.

The functionality already exists; this CL merely exposes it and adds
tests.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/3003913002 .
2017-08-25 13:57:01 -07:00
Paul Berry be01632bc0 Fix type inference of getters that "override" setters and vice versa.
Normally getters and setters are considered distinct and unrelated by
the type inference algorithm.  However, if a getter has no declared
type and doesn't override anything, then we fall back on inferring its
type from an inherited setter, and vice versa.

R=sigmund@google.com

Review-Url: https://codereview.chromium.org/2946733003 .
2017-06-20 05:34:31 -07:00
Konstantin Shcheglov bcf179c9fa Add the 'crossGettersSetters' flag to ClassHierarchy.forEachOverridePair().
We need to be able to get 'overrides' of setters with getters and vise
versa to support top-level inference.

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

Review-Url: https://codereview.chromium.org/2941363002 .
2017-06-17 18:32:44 -07:00
Konstantin Shcheglov 5fe793ec4e Use ClassHierarchy.applyChanges() in MixinFullResolution.
So, we let the hierarchy to decide how to react to the changes, and
instance of which class hierarchy to create.

This makes initial compilation with Kernel Driver about 5% faster.

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

Review-Url: https://codereview.chromium.org/2924333002 .
2017-06-08 14:00:51 -07:00
Konstantin Shcheglov 8ec1f95af6 Replace ClassHierarchy.classes with getOrderedClasses().
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2924713002 .
2017-06-05 20:23:13 -07:00
Konstantin Shcheglov 64ce51ce4b Fix the test and implement forEachOverridePair() for IncrementalClassHierarchy.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2920323002 .
2017-06-05 13:11:29 -07:00
Konstantin Shcheglov 5cf61cb0dc Implement getInterfaceMember() for IncrementalClassHierarchy.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2916383003 .
2017-06-03 18:52:00 -07:00
Konstantin Shcheglov 952687a64f Implement getDispatchTarget() in IncrementalClassHierarchy.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2916403002 .
2017-06-02 13:58:26 -07:00
Konstantin Shcheglov 99363d42d0 Implement getClassicLeastUpperBound() in IncrementalClassHierarchy.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2921083002 .
2017-06-02 13:46:58 -07:00
Konstantin Shcheglov c2b5ae00ce Implement getClassAsInstanceOf() and getTypeAsInstanceOf() for IncrementalClassHierarchy.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2915263003 .
2017-06-02 11:54:47 -07:00
Konstantin Shcheglov 4301ce842a Implement IncrementalClassHierarchy.getRankedSuperclasses().
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2916323002 .
2017-06-02 09:15:44 -07:00
Konstantin Shcheglov 65c1f5f8ab Start implementing IncrementalClassHierarchy.
Only getClassDepth() for now.

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

Review-Url: https://codereview.chromium.org/2922533002 .
2017-06-01 15:01:51 -07:00
Paul Berry 29570728a3 Implement Dart 1.0 LUB algorithm (for interface types) in kernel.
Note: I intend to implement the full LUB algorithm (including strong
mode behaviors) in front_end, however this piece of the algorithm
makes sense to be in kernel so that it can take advantage of
_ClassInfo.

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

Review-Url: https://codereview.chromium.org/2848083002 .
2017-05-01 11:25:47 -07:00