Skip to content

Compiler codebase chore :: Hash directives around nullness syntax are not needed anymore #18061

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
T-Gro opened this issue Nov 26, 2024 · 6 comments

Comments

@T-Gro
Copy link
Member

T-Gro commented Nov 26, 2024

While the nullness feature was being developed, the previous compiler (LKG = Last Known Good) did not understand nullness syntax ("not null", | null).
Which lead to null-relevant code surrounded in "#if" directives, to make it compile both under the .NET8 compiler as well as the new .NET9 one.

With .NET being out, those should not be needed anymore.
The same would apply to wrapper types created in order to limit the number of "#if" directives, pretty much most of the NullnessShims.fs file and the broad usage of the "MaybeNull" wrapper.

This can be done incrementally.

@github-actions github-actions bot added this to the Backlog milestone Nov 26, 2024
@T-Gro T-Gro changed the title Compiler codebase chore :: Has directives around nullness syntax are not needed anymore Compiler codebase chore :: Hash directives around nullness syntax are not needed anymore Nov 26, 2024
@progressive-galib
Copy link
Contributor

progressive-galib commented Dec 16, 2024

I can do it all i need is is a bit guidance on where these codes are from anyone familiar with the codebase.

@T-Gro
Copy link
Member Author

T-Gro commented Dec 16, 2024

Hello @progressive-galib , I will be happy to assist.

I would first recommend to start with the compiler (FSharp.Compiler.Service.fsproj and projects depending on it) itself, and do FSharp.Core separately later.

In VisualFsharp.sln solution, you search for usages of "NO_CHECKNULLS" directive.
Most of them will be in insolation and can be resolved directly.

There is a single file (which is being referenced from multiple projects) called NullnessShims.fs
https://github.com/dotnet/fsharp/blob/main/src/Compiler/Utilities/NullnessShims.fs

That file uses that directive as well to provide two alternate versions of types/functions.
Ideally, those should be deleted and the respective callsite adjusted.
For example, the type "MaybeNull" should not be needed anymore, as the callsite can move from (e.g.) MaybeNull<string> to vanilla string | null.

I definitely recommend to go with full-text search to find all the places and not rely on "Find references". Reason is, hash directives are branching the code even for tooling and some paths might not be found because of it.

@progressive-galib
Copy link
Contributor

already started

@progressive-galib
Copy link
Contributor

progressive-galib commented Jan 5, 2025

This can be done incrementally.

@T-Gro can i do one file per pr ?

also i am not building locally anymore, you guys have great CI/CD #18201

@T-Gro
Copy link
Member Author

T-Gro commented Jan 6, 2025

This can be done incrementally.

@T-Gro can i do one file per pr ?

also i am not building locally anymore, you guys have great CI/CD #18201

One file might be too small, but any coherent unit of work that makes sense for you will be good.

@T-Gro
Copy link
Member Author

T-Gro commented Jan 6, 2025

You might experience diagnostics in files in the obj folder.
Those are resource artifacts produces by a build task.

The build task is a code generator which is located in the same repository - it is part of the FSharp.Build.fsproj project.
Look e.g. for FSharpEmbedResourceText. The snippets of code generated by it are there as strings.

progressive-galib added a commit to progressive-galib/fsharp that referenced this issue Jan 6, 2025
"#if" directive around nullness removed from src/Compiler/TypedTree/TypedTreePickle.fs and refactored.

Fixes dotnet#18061 (partially)
progressive-galib added a commit to progressive-galib/fsharp that referenced this issue Jan 7, 2025
"#if" directive around nullness removed from src
Related: dotnet#18061 (partially addresses)

- [x] Release notes entry updated: in
    `docs/release-notes/.FSharp.Compiler.Service/9.0.200.md`,
progressive-galib added a commit to progressive-galib/fsharp that referenced this issue Jan 7, 2025
from src/Compiler/Utilities/HashMultiMap.fs and fsi
Related: dotnet#18061 (partially addresses)

<!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->

- [x] Release notes entry updated: in
    `docs/release-notes/.FSharp.Compiler.Service/9.0.200.md`,
psfinaki added a commit that referenced this issue Jan 14, 2025
…nager/DependencyProvider.fs and refactored. (#18207)

* /Compiler/TypedTree/TypedTreePickle.fs refactored.
"#if" directive around nullness removed from src
Related: #18061 (partially addresses)

- [x] Release notes entry updated: in
    `docs/release-notes/.FSharp.Compiler.Service/9.0.200.md`,

* try 2

* refactoring

* .

* .

* lets hope this works

* .

* fantomas tried with a bit of tricks DependencyProvider.fs

* fantomas ignore

* unformat

---------

Co-authored-by: Petr <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

2 participants