-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[DllImportGenerator] Don't generate a full stub body when the body does nothing #60601
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
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/MarshalUtilsTests.cs Lines 25 to 56 in ba01c59
Lines 54 to 69 in b201a16
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: runtime/src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/CoreTestAssembly/Platform.cs Lines 34 to 35 in ba01c59
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