Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Issue 2208233002: Make LUB algorithm aware of non-null types (Closed)

Created:
4 years, 4 months ago by stanm
Modified:
4 years, 4 months ago
Reviewers:
vsm, Leaf, Jennifer Messerly
CC:
reviews_dartlang.org
Base URL:
https://github.com/dart-lang/sdk@nnp
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Make LUB algorithm aware of non-null types In addition to the functional change I added some more tests to test for regressions and for the new behaviour. BUG= R=jmesserly@google.com Committed: https://github.com/dart-lang/sdk/commit/f3f10a6dd6d996dddc3f6d1dfb2410c2c2e86f31

Patch Set 1 #

Total comments: 5

Patch Set 2 : Update LUB #

Patch Set 3 : Optimize return paths #

Patch Set 4 : Outline common functionality #

Patch Set 5 : Rename for clarity #

Total comments: 4

Patch Set 6 : Fix logic bug in isNullableType #

Unified diffs Side-by-side diffs Delta from patch set Stats (+148 lines, -10 lines) Patch
M pkg/analyzer/lib/src/dart/element/type.dart View 1 2 3 4 2 chunks +12 lines, -4 lines 0 comments Download
M pkg/analyzer/lib/src/generated/type_system.dart View 1 2 3 4 5 2 chunks +42 lines, -1 line 0 comments Download
M pkg/analyzer/lib/src/task/strong/checker.dart View 1 2 chunks +10 lines, -4 lines 0 comments Download
M pkg/analyzer/test/src/task/strong/non_null_checker_test.dart View 2 chunks +84 lines, -1 line 0 comments Download

Depends on Patchset:

Messages

Total messages: 19 (5 generated)
stanm
4 years, 4 months ago (2016-08-03 22:25:56 UTC) #2
Jennifer Messerly
+Leaf ... offhand this doesn't feel right to me. I would expect LUB(⊥, x) == ...
4 years, 4 months ago (2016-08-03 22:40:41 UTC) #4
Jennifer Messerly
On 2016/08/03 22:40:41, John Messerly wrote: > +Leaf ... offhand this doesn't feel right to ...
4 years, 4 months ago (2016-08-03 22:42:34 UTC) #5
Leaf
https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/generated/type_system.dart File pkg/analyzer/lib/src/generated/type_system.dart (right): https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/generated/type_system.dart#newcode151 pkg/analyzer/lib/src/generated/type_system.dart:151: if (type1.isBottom && isNonNullableType(type2)) { This depends a bit ...
4 years, 4 months ago (2016-08-03 23:45:07 UTC) #6
stanm
https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/generated/type_system.dart File pkg/analyzer/lib/src/generated/type_system.dart (right): https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/generated/type_system.dart#newcode151 pkg/analyzer/lib/src/generated/type_system.dart:151: if (type1.isBottom && isNonNullableType(type2)) { On 2016/08/03 23:45:07, Leaf ...
4 years, 4 months ago (2016-08-04 00:31:16 UTC) #7
stanm
John: if I go down the path of changing the static type of null, I ...
4 years, 4 months ago (2016-08-04 00:32:42 UTC) #8
stanm
I think I'm happier with the current implementation. PTAL
4 years, 4 months ago (2016-08-04 01:19:07 UTC) #11
Jennifer Messerly
On 2016/08/04 00:32:42, stanm wrote: > John: if I go down the path of changing ...
4 years, 4 months ago (2016-08-04 12:43:46 UTC) #12
Jennifer Messerly
https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart File pkg/analyzer/lib/src/generated/type_system.dart (right): https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart#newcode800 pkg/analyzer/lib/src/generated/type_system.dart:800: return type is FunctionType || is this supposed to ...
4 years, 4 months ago (2016-08-04 12:48:18 UTC) #13
Jennifer Messerly
On 2016/08/04 12:43:46, John Messerly wrote: > On 2016/08/04 00:32:42, stanm wrote: > > John: ...
4 years, 4 months ago (2016-08-04 13:10:49 UTC) #14
Jennifer Messerly
LGTM w/ a fix for the FunctionType issue https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart File pkg/analyzer/lib/src/generated/type_system.dart (right): https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart#newcode800 pkg/analyzer/lib/src/generated/type_system.dart:800: return ...
4 years, 4 months ago (2016-08-04 18:43:41 UTC) #15
stanm
https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart File pkg/analyzer/lib/src/generated/type_system.dart (right): https://codereview.chromium.org/2208233002/diff/80001/pkg/analyzer/lib/src/generated/type_system.dart#newcode800 pkg/analyzer/lib/src/generated/type_system.dart:800: return type is FunctionType || On 2016/08/04 12:48:18, John ...
4 years, 4 months ago (2016-08-04 19:29:18 UTC) #16
stanm
Committed patchset #6 (id:100001) manually as f3f10a6dd6d996dddc3f6d1dfb2410c2c2e86f31 (presubmit successful).
4 years, 4 months ago (2016-08-04 19:33:43 UTC) #18
Leaf
4 years, 4 months ago (2016-08-04 19:40:36 UTC) #19
Message was sent while issue was closed.
lgtm

https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/genera...
File pkg/analyzer/lib/src/generated/type_system.dart (right):

https://codereview.chromium.org/2208233002/diff/1/pkg/analyzer/lib/src/genera...
pkg/analyzer/lib/src/generated/type_system.dart:151: if (type1.isBottom &&
isNonNullableType(type2)) {
On 2016/08/04 00:31:15, stanm wrote:
> On 2016/08/03 23:45:07, Leaf wrote:
> > This depends a bit on exactly what system you are trying to implement, but
my
> > suggestion would be that you start with something like this:
> > 
> > BOT is the true bottom type (uninhabited).  This can't be expressed in Dart,
> but
> > it lets us talk about some things.
> > T? is a nullable T.  It is essentially T or null.
> > T! is a non-nullable T.  It is essentially T, without null if T is nullable.
> > 
> > Obviously, there is some initial set of types which are either nullable or
> > non-nullable.  My guess is that you are implementing a system in which the
> only
> > user visible types are, in fact, that initial set.
> > 
> > Then in Dart:
> > 
> > bottom =def= BOT?
> >   - that is, the Dart bottom type is either BOT (i.e. nothing) or null. 
i.e.,
> > BOT? is inhabited only by null.
> > 
> > then the definition of LUB here falls out.
> > 
> > LUB(S?, T?) = LUB(S, T)? 
> > LUB(S!, T!) = LUB(S, T)!
> > LUB(S?, T!) = LUB(S, T)?
> > LUB(S!, T?) = LUB(S, T)?
> > 
> > You don't have actual syntax for ? and !, I presume, but basically its the
> same
> > thing - you just have an enumerated list of types which are nullable and
> > non-nullable.  This means that you can't necessarily construct the direct
LUB
> as
> > defined above.  For example, if int is your only non-nullable type, and you
> > don't have a way of writing int?, then LUB(bottom, int) is the least type
> which
> > is a supertype of int, but which is nullable.  If num is nullable, then the
> > answer should be num.  Otherwise probably Object.
> > 
> > Let me know if you want to talk this through offline.
> 
> Thanks for the detailed explanation.
> 
> If by 'My guess is that you are implementing a system in which the only user
> visible types are, in fact, that initial set.' you mean that I don't consider
> the case of additional types being added to the system at runtime, then your
> guess is correct.
> 
> I think I just completely ignored the fact we're looking for a **lower** upper
> bound. This is what I intent to do:
> 
> LUB(S?, T?) = LUB(S, T)?
> LUB(S!, T!) = LUB(S, T)!
> LUB(S?, T!) = LUB(S?, LNST(T)?) = LUB(S, LNST(T))?
> LUB(S!, T?) = LUB(LNST(S)?, T?) = LUB(LNST(S), T)?
> 
> where LNST(T)? is the least nullable super type of T. If T? exists for T! then
> LNST(T)? is T?. Otherwise, I need to search the set of all super types of T
and
> return the one that has longest inheritance path to object (borrowed logic
from
> computeLeastUpperBound).
> 
> Do you think that should work?

Looks right to me.  LNST(T)? == LNST(T), I think, but doesn't matter.

Powered by Google App Engine
This is Rietveld 408576698