New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound non-nullable types with incremental migration (NNBD) #110

Open
leafpetersen opened this Issue Nov 28, 2018 · 9 comments

Comments

4 participants
@leafpetersen
Copy link
Member

leafpetersen commented Nov 28, 2018

This is a solution proposal for #71. The proposal will cover both the intended final language design, and the language, tooling, and ecosystem support required for the migration. A roadmap describing the general goals and desired properties of the feature is here. Discussion of specific details of the language design is underway.

All NNBD related issues:

Topic specific discussion issues for resolution:

@leafpetersen leafpetersen self-assigned this Nov 28, 2018

@mit-mit mit-mit added this to Being discussed in Language funnel Nov 29, 2018

@mit-mit mit-mit moved this from Being discussed to Being spec'ed in Language funnel Nov 30, 2018

@leafpetersen

This comment has been minimized.

Copy link
Member Author

leafpetersen commented Nov 30, 2018

I've added a draft of the roadmap for this proposal, linked from the header comment.

@yjbanov

This comment has been minimized.

Copy link

yjbanov commented Dec 8, 2018

@jmesserly I'm not sure how to constructively move the NNBD discussion from #125 here, because the my suggestion is all about linking the two issues. But I'll try:

I suggest that, as a first step, we introduce sound non-nullable types as part of immutable types (#125). This has several advantages:

  • It would be a non-breaking change: immutable types is a new feature so having them NNBD doesn't break any existing code.
  • It could have the biggest performance impact: if non-nullability is implemented such that many highly-used types can be inlined, such as double, int, bool, enum, String, we could significantly improve memory layout efficiency.
  • It would give us a chance to get the syntax and semantics right and educate users before rolling NNBD to the "normal" classes, which does require a bigger migration.
@jmesserly

This comment has been minimized.

Copy link
Member

jmesserly commented Dec 8, 2018

IMO, linking the two proposals would be counterproductive. We are working hard on NNBD, there is a lot of design & planning work going on. There aren't any major open questions on syntax or desired semantics. Linking the two would prevent us from pushing forward on NNBD, because immutable types has a lot of open design questions, and we'd have to delay work on NNBD until that's resolved.

(Also it could be confusing if different parts of the language treat int as having different non-nullability. It would be really nice if int always means non-null, and int? always means mean nullable. The NNBD proposal achieves that.)

@yjbanov

This comment has been minimized.

Copy link

yjbanov commented Dec 8, 2018

That's fine too, it was just an idea. I don't have enough context to know how best to proceed, so if you believe that NNBD and immutables should proceed completely independently, then they should :)

@jmesserly

This comment has been minimized.

Copy link
Member

jmesserly commented Dec 8, 2018

Makes sense :). Yeah, we seem to be gathering a lot of momentum behind Leaf's proposal. It's really exciting! I think we'll be able to apply the many lessons of Strong Mode to NNBD, to make the migration as easy & rewarding as possible. (e.g. ideally it's non-breaking for code that isn't migrated. Until you turn on NNBD, you don't break. Once you turn it on, you have to fix some errors, but you gain some degree of null safety, even if everything else isn't migrated yet. Once everything in an app is migrated, then it has sound null safety. It's pretty neat.)

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 11, 2018

Update handleType event to take questionMark token
... which in this CL will always null.
This is the first step when adding NNDB support as outlined in
dart-lang/language#110

Change-Id: If3810bcaf1b73e70924f09d619e2a84e7d5ba8d6
Reviewed-on: https://dart-review.googlesource.com/c/86860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 11, 2018

add asNonNullable() to existing type infos
This adds code to ignore trailing `?` in `as` and `is` expressions
because the trailing `?` may be part of the larger expression.
At the moment, this change is a no-op, but will become active
when a subsequent CL lands support for nullable types as part of
dart-lang/language#110

Change-Id: I829d6aee0f11957ca9b5e143000005031649449f
Reviewed-on: https://dart-review.googlesource.com/c/86960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 11, 2018

Add support for parsing simple nullable types
... as part of adding NNBD as outlined in
dart-lang/language#110

This only supports parsing simple nullable types
such as int? and List<int>? while subsequent CLs
will add support for parsing more complex types.

Change-Id: I3cc5c65d20bf3732a39cab0e823b2f7332342866
Reviewed-on: https://dart-review.googlesource.com/c/86961
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 12, 2018

Update endFunctionType event to take questionMark token
... which in this CL will always null.
This is another step when adding NNDB support as outlined in
dart-lang/language#110

Change-Id: I3974fcb885c63be4af9d1007258383f3f8191ae0
Reviewed-on: https://dart-review.googlesource.com/c/87080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 12, 2018

Add support for simple nullable type return value in generalized func…
…tion type

This only supports nullable return values of the form

<identifier> '?' 'Function' '(' ...

This is an increment CL in the ongoing effort to add nullable type support
as outlined in dart-lang/language#110

Change-Id: I42febae9f88f7e4d8b05907988deab97c7a7425c
Reviewed-on: https://dart-review.googlesource.com/c/87081
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 13, 2018

Add support for prefixed nullable type
This adds support for nullable types of the form

<identifier> '.' <identifier> '?'

and

<identifier> '.' <identifier> '?' 'Function' '(' ...

This is an increment CL in the ongoing effort to add nullable type support
as outlined in dart-lang/language#110

Change-Id: I526aecbe64bacbd442cea0b4c52d36ff23b0443b
Reviewed-on: https://dart-review.googlesource.com/c/87083
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 14, 2018

Revert "Add support for prefixed nullable type"
This reverts commit 7720689.

Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();)

Original change's description:
> Add support for prefixed nullable type
> 
> This adds support for nullable types of the form
> 
> <identifier> '.' <identifier> '?'
> 
> and
> 
> <identifier> '.' <identifier> '?' 'Function' '(' ...
> 
> This is an increment CL in the ongoing effort to add nullable type support
> as outlined in dart-lang/language#110
> 
> Change-Id: I526aecbe64bacbd442cea0b4c52d36ff23b0443b
> Reviewed-on: https://dart-review.googlesource.com/c/87083
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Dan Rubel <danrubel@google.com>

TBR=brianwilkerson@google.com,danrubel@google.com

Change-Id: Ib5e74b4aad239f561a33eae9d95dffa2693037f7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/87282
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 14, 2018

Revert support for simple nullable type return value in generalized f…
…unction type

This reverts commit 11d081d

Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();)

Original change's description:
> Add support for simple nullable type return value in generalized function type
>
> This only supports nullable return values of the form
>
> <identifier> '?' 'Function' '(' ...
>
> This is an increment CL in the ongoing effort to add nullable type support
> as outlined in dart-lang/language#110

Change-Id: I99bce29619d4e448193e3c81fa86a982791b1f77
Reviewed-on: https://dart-review.googlesource.com/c/87283
Reviewed-by: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 14, 2018

Revert support for parsing simple nullable types
This reverts commit bc8c7cf

Reason for revert: Breaks parsing less common conditionals (e.g. b ? c = true : g();)

Original change's description:
> Add support for parsing simple nullable types
>
> ... as part of adding NNBD as outlined in
> dart-lang/language#110
>
> This only supports parsing simple nullable types
> such as int? and List<int>? while subsequent CLs
> will add support for parsing more complex types.

Change-Id: I49a21a85dca19241e3b23ed5c9fb6084e70f2000
Reviewed-on: https://dart-review.googlesource.com/c/87284
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
@leafpetersen

This comment has been minimized.

Copy link
Member Author

leafpetersen commented Dec 17, 2018

I've updated the header with some sub-issues for discussing specific topics.

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 18, 2018

Add support for parsing simple nullable types
... as part of adding NNBD as outlined in
dart-lang/language#110

This only supports parsing simple nullable types
such as int? and List<int>? while subsequent CLs
will add support for parsing more complex types.

Change-Id: I144858946cb115755af437299899c2631105bf8c
Reviewed-on: https://dart-review.googlesource.com/c/87501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 18, 2018

Revert "Add support for parsing simple nullable types"
This reverts commit c5fd11b.

Reason for revert: Conditional expression lookahead may modify the token stream

Original change's description:
> Add support for parsing simple nullable types
> 
> ... as part of adding NNBD as outlined in
> dart-lang/language#110
> 
> This only supports parsing simple nullable types
> such as int? and List<int>? while subsequent CLs
> will add support for parsing more complex types.
> 
> Change-Id: I144858946cb115755af437299899c2631105bf8c
> Reviewed-on: https://dart-review.googlesource.com/c/87501
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Dan Rubel <danrubel@google.com>

TBR=brianwilkerson@google.com,danrubel@google.com

Change-Id: Ie1f47e7384ff51159aa2ebeb21561455b8e6287f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/87620
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 18, 2018

Update AstBuilder to build AST with nullable types
... as part of adding NNBD as outlined in
dart-lang/language#110

This CL updates the parser to recognize two specialized comments at the
beginning of a library of the form '//@NNBD' and '//@NNBD*' for use
by the analyzer to aid developers when converting their libraries
to be non-nullable by default.

In addition, the AstBuilder now populates the generated analyzer AST
with nullable type information.

Change-Id: I80d221dd138973aa32f05bde631245d9ac6ee10f
Reviewed-on: https://dart-review.googlesource.com/c/87540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Dec 21, 2018

Add support for parsing simple nullable types
... as part of adding NNBD as outlined in
dart-lang/language#110

This only supports parsing simple nullable types
such as int? and List<int>? while subsequent CLs
will add support for parsing more complex types.

Due to current parser limitations, it also only supports
nullable types in a limited number of statements such as

T? t;
if (x is String?) {}

In addition, address comments in
* https://dart-review.googlesource.com/c/sdk/+/87880
* https://dart-review.googlesource.com/c/sdk/+/87881

Change-Id: Ife4afadc0b72906fc0c4e9b1977ad838041c2a84
Reviewed-on: https://dart-review.googlesource.com/c/87920
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
@leafpetersen

This comment has been minimized.

Copy link
Member Author

leafpetersen commented Dec 22, 2018

Added links to two new discussion issues in the header comment.

@leafpetersen leafpetersen added the nnbd label Jan 23, 2019

@leafpetersen

This comment has been minimized.

Copy link
Member Author

leafpetersen commented Jan 23, 2019

Added a discussion link to the header for removing implicit casts.

@mraleph mraleph referenced this issue Jan 24, 2019

Closed

Non-nullable type annotation syntax #27231

1 of 7 tasks complete
@leafpetersen

This comment has been minimized.

Copy link
Member Author

leafpetersen commented Jan 29, 2019

Added a discussion link to the header about a non-null assertion operator.

@mit-mit mit-mit changed the title Sound non-nullable types with incremental migration Sound non-nullable types with incremental migration (NNBD) Feb 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment