Skip to content

use Uninitialized instead of Null without changing Predef #15127

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

olhotak
Copy link
Contributor

@olhotak olhotak commented May 6, 2022

This is an alternative to #15124 that does not depend on #15123 and in particular doesn't depend on changing Predef. The motivation is to try out Uninitialized in the compiler first before committing to a specific implementation in Predef.

This is a first step towards addressing pain point 1 in #14622. A second step would be to tweak the flow-sensitive analysis with special treatment for vars whose type is not a supertype of Null. Such a var cannot have null written into it, so once we know it's non-null, it can never become null again.

@olhotak olhotak requested a review from noti0na1 May 6, 2022 08:58
@olhotak olhotak force-pushed the add-uninitialized-in-compiler branch from 0ffa4d9 to 59cf2a8 Compare May 6, 2022 08:59
@bishabosha
Copy link
Member

bishabosha commented May 6, 2022

how does this relate to compiletime.uninitialized, could we instead update its meaning under Explicit-nulls? (it seems a mistake to reserve it only for class fields)

Edit: I see now that I guess uninitialised is not meant to be the unique value of a unique type (such as null), but some "default" value within the type it is assigned to

@olhotak olhotak force-pushed the add-uninitialized-in-compiler branch from 59cf2a8 to 5265bd9 Compare May 6, 2022 09:43
@olhotak
Copy link
Contributor Author

olhotak commented May 6, 2022

compiletime.uninitialized is for fields that are not intended to be null ever when read. They are intended to be initialized before they are first read. Their type reflects this: they (can) have a non-null type, so you don't need to handle the possibility that they could be null when reading them.

Uninitialized is a type that is Null when read but non-null for writing: a null cannot be written to such a field. A type such as String | Uninitialized acts like String | Null when reading a field and therefore forces you to consider the case that it could be null.

@olhotak
Copy link
Contributor Author

olhotak commented May 10, 2022

This PR should wait for #14946 to maximize places where Uninitialized can be applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants