Skip to content

[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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

mandel-macaque
Copy link
Member

AsPointer is used to ensure that we pass a ref/in/out parameter as a pointer to the native code.

AsPointer is used to ensure that we pass a ref/in/out parameter as a
pointer to the native code.
@mandel-macaque mandel-macaque requested a review from Copilot June 12, 2025 21:47
Copy link
Contributor

@Copilot Copilot AI left a 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>) in BindingSyntaxFactory
  • Registers a Unsafe TypeSyntax in BindingSyntaxFactory.KnownTypes
  • Adds TestDataAsPointerTests and AsPointerTests to 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 AsPointer to ensure commas and spacing are formatted correctly.
internal static ExpressionSyntax AsPointer (TypeSyntax objectType, ImmutableArray<ArgumentSyntax> arguments)

@@ -899,6 +899,38 @@ void AsRefTests (TypeSyntax objectType, ImmutableArray<ArgumentSyntax> arguments
Assert.Equal (expectedDeclaration, declaration.ToFullString ());
}

class TestDataAsPointerTests : IEnumerable<object []> {
Copy link
Preview

Copilot AI Jun 12, 2025

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).

Suggested change
class TestDataAsPointerTests : IEnumerable<object []> {
public class TestDataAsPointerTests : IEnumerable<object []> {

Copilot uses AI. Check for mistakes.

Copy link
Member Author

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

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #035142e] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #035142e] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

✅ API diff vs stable

.NET ( No breaking changes )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #035142e] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #035142e] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #035142e] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #035142e] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #035142e] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [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
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 035142eaaf74350b38ed6db187b2b29909d4fc70 [PR build]

@mandel-macaque mandel-macaque merged commit 31e05dd into main Jun 13, 2025
44 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/aspointer-factory branch June 13, 2025 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants