-
Notifications
You must be signed in to change notification settings - Fork 789
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
[RFC FS-1060] Nullness checking #15181
Conversation
* enablement * enablement * fix build * fix build * fantomas * selective adoption
Feature nullness :: Subsume nullness for contravariant type parameters (such as the one in IEqualityComparer<in T>)
A non-binding question: do you see any opportunities here for further feature optimization, performance-wise? If you do, it might be interesting to submit some benchmark along the way. This was often done when doing big features (but obviously it doesn't have to apply everywhere). |
Not at this point for sure. We should merge it as soon as we can so we can contribute fixes before November |
So I was mostly following the RFC to find any inconsistencies with expected behavior and things look generally well. A few points (so far):
let getLength (x: string | null) = x.Length Also, the text is not the best IMO. Consider inspiring by C#, like "Dereference of a possibly null reference".
let len (str: string | null) =
match str with
| null -> -1
| NonNull s -> s.Length // binds a non-null result ...produces this: One - a UX improvement would be to be exact: Two - since this basically says "hey this is redundant", I would expect to not have the second warning, since if I remove NonNull, I stop getting it. Stay tuned! |
fsharp/src/Compiler/Checking/ConstraintSolver.fs Line 2616 in 972fa34
Code opting in into nullness indeed gets a different behavior, since the semantics for "does type allow nulls" have changed, and diagnostics take a different form. The last example, |
Good for spotting this, thumbs up. I created new issues to cover for them. Created to cover these, can be again taken independently |
It is a compile-time feature without runtime impact. For the compilation times, the e2e build tests under different configurations remained the same as far as I can see (comparing this branch, which does not apply checknulls, and its sibling PR which does). |
No that makes, it was more about optimization potential in the implementation details. I am totally fine with not adding benchmarks here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more notes.
vsintegration/tests/UnitTests/LegacyLanguageService/Tests.LanguageService.QuickInfo.fs
Outdated
Show resolved
Hide resolved
I intend to merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played a lot of with the feature, IMO this definitely passes all the smoke tests, as per other things - see comments.
What would be amazing is to actually update the RFC because it has some TBDs and some inconsistencies, both internal ones (e.g. withNull
function) and w.r.t. implementation (e.g. obj | null
support). Splitting the helper RFCs will be also benefecial.
Let's
@vzarytovskii it's all green now, I fixed the trimming checks. As for the issues, I'd prefer force-merging it with unresolved comments so that @T-Gro can later make sense of them. |
It’s fantastic how you are bringing F# forward! 🎉 |
Continuation of #5790 and #6804
This is a prototype implementation of RFC FS-1060 nullable reference types
See tests\adhoc\nullness for testing and samples including baselines of outputs from
/langversion:preview
/langversion:preview /checknulls
TODO:
string | null
and: not null
(@T-Gro )Import+Export
TODOs (to test and adjust if needed)System.Collections.Generic.List<string | null>
)The types 'System.String (...)' and 'System.String (...)' do not have compatible nullability.
which is wrong - either the nullability aren't shown for some reason or the types should be considered compatibleTesting:
To be moved to RFC and resolved, then tested here:
if x then null else ""
andif x then "" else null