Skip to content

[RGen] Convert native values to managed enum values for the delegate execution. #22918

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 2 commits into from
May 28, 2025

Conversation

mandel-macaque
Copy link
Member

There was a bug in the previous implementation in which we were:

  1. Not lowering the enum to its native type correctly.
  2. Not castin the lower type to the managed enum type for the trampoline execution.

This is similar to the issue we had with booleans in which I confused the direction of the conversion. We are doing low -> managed. Managed -> low is needed in other aread of the generation, not in the delegate execution.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…execution.

There was a bug in the previous implementation in which we were:

1. Not lowering the enum to its native type correctly.
2. Not castin the lower type to the managed enum type for the trampoline
   execution.

This is similar to the issue we had with booleans in which I confused
the direction of the conversion. We are doing low -> managed. Managed ->
low is needed in other aread of the generation, not in the delegate
execution.
@mandel-macaque mandel-macaque requested a review from Copilot May 27, 2025 21:15
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 addresses a bug in the enum conversion logic for delegate execution by updating the conversion functions and associated tests.

  • Updates conversion method calls from CastToNative to CastEnumToNative and CastNativeToEnum.
  • Enhances test coverage with new scenarios for native-to-enum conversion.
  • Adds documentation and a new TypeSyntax for UIntPtr to support the updated conversion logic.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryTrampolineTests.cs Updated casting expressions in test cases to use the new conversion patterns.
tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryObjCRuntimeTests.cs Revised tests to validate the newly introduced CastEnumToNative and CastNativeToEnum functions.
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs Replaced CastToNative with CastEnumToNative and CastNativeToEnum, added a helper GetNativeEnumLowLevel, and improved documentation.
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.ObjCRuntime.cs Renamed conversion functions and added methods for casting native representations back to enum types along with updated documentation.
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.KnownTypes.cs Introduced a TypeSyntax entry for System.UIntPtr for consistency with enum conversion logic.
Comments suppressed due to low confidence (1)

src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs:324

  • [nitpick] Confirm that switching from CastToNative to CastNativeToEnum here correctly implements the intended low-to-managed enum conversion for delegate parameters, and that this change does not inadvertently affect other enum handling paths.
=> CastNativeToEnum (parameter)!;

@@ -28,17 +28,17 @@ static partial class BindingSyntaxFactory {
/// <param name="parameter">The parameter whose casting we need to generate. The type info has to be
/// and enum and be marked as native. If it is not, the method returns null</param>
/// <returns>The cast C# expression.</returns>
internal static CastExpressionSyntax? CastToNative (in Parameter parameter)
=> CastToNative (parameter.Name, parameter.Type);
internal static CastExpressionSyntax? CastEnumToNative (in Parameter parameter)
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Update the XML documentation for CastEnumToNative to clearly indicate that this method is intended for enum-specific native conversions, ensuring consistency with its usage throughout the codebase.

Copilot uses AI. Check for mistakes.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #83b056a] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #83b056a] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@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: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #83b056a] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 83b056a49821443c8415e4ea4d7b788080c64106 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: d61595572d18542cd997441ebb0b58fac5e8d05b [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #d615955] 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: d61595572d18542cd997441ebb0b58fac5e8d05b [PR build]

@mandel-macaque mandel-macaque merged commit 48f5299 into main May 28, 2025
40 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/native-to-enum branch May 28, 2025 14:18
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.

None yet

4 participants