-
Notifications
You must be signed in to change notification settings - Fork 549
[Rgen] Provide a factory method to generate AsPointer calls. #23035
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
Conversation
AsPointer is used to ensure that we pass a ref/in/out parameter as a pointer to the native code.
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.
Pull Request Overview
This PR introduces a new AsPointer helper in BindingSyntaxFactory to generate pointer‐casted calls to Unsafe.AsPointer<T>, adds a corresponding Unsafe known type, and covers it with runtime tests.
- Implements
AsPointer(TypeSyntax, ImmutableArray<ArgumentSyntax>)inBindingSyntaxFactory - Registers a
UnsafeTypeSyntaxinBindingSyntaxFactory.KnownTypes - Adds
TestDataAsPointerTestsandAsPointerTeststo validate the generated syntax
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryRuntimeTests.cs | Adds test data and theory for AsPointer syntax generation |
| src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs | Implements the AsPointer method that casts Unsafe.AsPointer |
| src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.KnownTypes.cs | Defines a Unsafe known‐type for the System.Runtime.CompilerServices.Unsafe class |
Comments suppressed due to low confidence (1)
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.cs:210
- [nitpick] Consider adding a unit test for a two-argument call to
AsPointerto ensure commas and spacing are formatted correctly.
internal static ExpressionSyntax AsPointer (TypeSyntax objectType, ImmutableArray<ArgumentSyntax> arguments)
| Assert.Equal (expectedDeclaration, declaration.ToFullString ()); | ||
| } | ||
|
|
||
| class TestDataAsPointerTests : IEnumerable<object []> { |
Copilot
AI
Jun 12, 2025
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.
Mark TestDataAsPointerTests as public so that xUnit can instantiate it via the ClassData attribute (which requires a public parameterless constructor).
| class TestDataAsPointerTests : IEnumerable<object []> { | |
| public class TestDataAsPointerTests : IEnumerable<object []> { |
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.
Bad copilot, this is not accurate
✅ [CI Build #035142e] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #035142e] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commit.NET ( No breaking changes )✅ API diff vs stable.NET ( No breaking changes )ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #035142e] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #035142e] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #035142e] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #035142e] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #035142e] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
🚀 [CI Build #035142e] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 115 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
AsPointer is used to ensure that we pass a ref/in/out parameter as a pointer to the native code.