[DllImportGenerator] Don't generate a full stub body when the body does nothing#60601
Conversation
…ed stub would be a no-op wrapper around an inner DllImport.
…c for blittable scenarios as well since we now turn a GeneratedDllImport into a DllImport when the stub would do nothing,.
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs
Show resolved
Hide resolved
…rshaller for the basic forwarder scenario.
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
This is great. I need this for the "unsupported framework" fallback. I have it all set up except the forwarder to DllImport logic.
|
Crossgen2 considers Boolean and Char as billitable types: should they match? |
|
In this case, crossgen2 is incorrect. Bool and Char are not blittable in the current system (which is the whole reason blittable != unmanaged) |
|
Ah right. The test was added as part of addressing #46653 (comment), which suggests crossgen2 case is different ( |
|
Perhaps we can split IsBlittable and RequiresSpecialMarshalling methods in crossgen2 to avoid confusion. cc @MichalStrehovsky. |
It doesn't. The unit test just uses a weird base class library where Bool and Char have no fields: If you zoom into IsBlittableType implementation: You can see why we would end up saying the struct is blittable if there's no fields. Maybe the code in MarshalUtils should check for primitive types first, but as things are now I think it kind of works for real core libraries. I think we would see bugs if it didn't work. |
|
We definitely would definitely see bugs if this was broken in real scenarios. I was very confused about how it was broken. |
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
Outdated
Show resolved
Hide resolved
…nerator.UnitTests/Compiles.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
Show resolved
Hide resolved
...teropServices/tests/DllImportGenerator.UnitTests/ConvertToGeneratedDllImportAnalyzerTests.cs
Show resolved
Hide resolved
… a stub to be generated.
…nsky/runtime into dllimportgen-blittable-in-place
Generate the partial function as a DllImport when a full-body generated stub would be a no-op wrapper around an inner DllImport.
Fixes #60596