-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use helpers in param-nullchecking emit #57615
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
Use helpers in param-nullchecking emit #57615
Conversation
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedThrowMethod.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedThrowIfNullMethod.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenNullCheckedParameterTests.cs
Outdated
Show resolved
Hide resolved
|
I think integration test failures are due to need to ingest newer changes from main into the feature branch. |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullChecking.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullChecking.cs
Show resolved
Hide resolved
|
Done review pass (commit 5). I did not look at test changes. |
|
Done review pass (commit 6). Have not looked at test changes. |
|
@333fred I made the changes to restore the old nullable value type behavior, support pointers and function pointers, and fix adding the synthesized methods to PrivateImplementationDetails. |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullChecking.cs
Show resolved
Hide resolved
|
Test failures look legitimate. Done review pass (commit 9) |
|
Bleh, yes, basically when a type parameter is constrained to some flavor of The first commit e40037f actually attempts to access the HasValue member on the type parameter constrained to nullable value type. This introduced a verification failure that I wasn't expecting: It seems like the code actually executes just fine at least on core. Still it made me a bit wary and since the scenario is so out in left field I pushed 00a2898 which reverts most of its parent and uses the "boxing" code gen in this specific case. edit: debugging the HasValue version a bit more, it seems like we hit this branch in the emitter. It seems like it's not really designed to contend with type parameters constrained to specific value types. We could probably fix the emitter to give |
333fred
left a comment
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.
LGTM (commit 12)
I'm curious why we chose to inline the Refers to: src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullChecking.cs:102 in c345bd5. [](commit_id = c345bd5, deletion_comment = False) |
| IL_000e: nop | ||
| IL_000f: ret | ||
| }"); | ||
| } |
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.
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.
Done
For pointers it didn't feel worthwhile to come up with another pair of helpers (ThrowPointerIfNull, etc.) due to their uncommonness. For nullable value types it seemed like it would require a generic FWIW, I imagine we may evolve this implementation in the future. If the runtime changes to inline methods across assemblies in more scenarios, we might be able to drop the internal helpers and use directly the |
|
roslyn-integration-ci won't pass due to being out of date with main. Merging now. |
Related to #36024
This PR hit a snag related to the fact that the SynthesizedGlobalMethodSymbol has a
nullContainingType, and that PrivateImplementationDetails is pretty emit-layer oriented. We could consider moving the lowering of param-nullchecking into the emit layer instead.