Skip to content

[RGen] Complete the generation of the Async methods. #23276

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

Open
wants to merge 2 commits into
base: dev/mandel/call-sync-method
Choose a base branch
from

Conversation

mandel-macaque
Copy link
Member

Put all the pieces together to generate the async calls for a method marked as Async.

Put all the pieces together to generate the async calls for a method
marked as Async.
@mandel-macaque mandel-macaque requested a review from Copilot July 8, 2025 22:07
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 replaces stub async methods with TaskCompletionSource-based implementations and updates the generator to emit these bodies automatically.

  • Updates expected test outputs for async methods (CompleteRequestAsync, LoadFromHtmlAsync, LoadFromHtmlNoNameAsync) to use TaskCompletionSource<T> and handle NSError callbacks.
  • Changes ClassEmitter to emit TCS-based method bodies instead of throwing NotImplementedException.
  • Adjusts Method.ToAsync to strip the partial modifier from generated async methods.

Reviewed Changes

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

File Description
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/tvOSExpectedMethodsTests.cs Updated expected tvOS async methods to use TCS implementations
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedMethodsTests.cs Updated expected async methods and added NSError exception handling for HTML loading
src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs Generator now emits TaskCompletionSource creation, sync call invocation, and return of .Task
src/rgen/Microsoft.Macios.Generator/DataModel/Method.Generator.cs Removed partial modifier from async method declarations

var tcsName = Nomenclator.GetTaskCompletionSourceName ();
methodBlock.WriteRaw (
$@"{tcsType.GetIdentifierSyntax ()} {tcsName} = new ();
{ExpressionStatement( ExecuteSyncCall (method))}
Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

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

The generator emits a single callback invocation but does not handle error parameters (e.g., NSError) by calling tcs.SetException. You should detect if the last callback argument is an NSError and emit conditional logic to set the exception when it's non-null.

Suggested change
{ExpressionStatement( ExecuteSyncCall (method))}
{ExpressionStatement( ExecuteSyncCall (method))}
// Check if the last argument is an NSError and handle it
if (callbackArguments.LastOrDefault() is NSError error && error != null)
{{
{tcsName}.SetException(new Exception(error.LocalizedDescription));
}}
else
{{
{tcsName}.SetResult(default);
}}

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.

This comment is wrongs, what is more, tests show that we are exactly generating that code.

@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 #342dec1] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #397f80b] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 397f80b79afa9fff59a4fc3223b6924d50cd6105 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build #342dec1] Tests on macOS M1 - Mac Monterey (12) failed ❌

Failed tests are:

  • dontlink
  • introspection
  • linksdk
  • linkall
  • monotouch-test

Pipeline on Agent
Hash: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [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: 397f80b79afa9fff59a4fc3223b6924d50cd6105 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #342dec1] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

4 tests crashed, 3 tests failed, 112 tests passed.

Failures

❌ dotnettests tests (iOS)

🔥 Failed catastrophically on VSTS: test results - dotnettests_ios (no summary found).

Html Report (VSDrops) Download

❌ dotnettests tests (MacCatalyst)

🔥 Failed catastrophically on VSTS: test results - dotnettests_maccatalyst (no summary found).

Html Report (VSDrops) Download

❌ dotnettests tests (Multiple platforms)

🔥 Failed catastrophically on VSTS: test results - dotnettests_multiple (no summary found).

Html Report (VSDrops) Download

❌ framework tests

🔥 Failed catastrophically on VSTS: test results - framework (no summary found).

Html Report (VSDrops) Download

❌ monotouch tests (iOS)

1 tests failed, 7 tests passed.
  • monotouch-test/iOS - simulator/Release (managed static registrar, all optimizations): Crashed

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

2 tests failed, 6 tests passed.
  • monotouch-test/tvOS - simulator/Debug: Crashed
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): Crashed

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 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 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 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: 342dec1e21536d1fc0ed3d2803c83734b4671ea6 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #397f80b] Build failed (Build packages) 🔥

Build failed for the job 'Build packages' (with job status 'Failed')

Pipeline on Agent
Hash: 397f80b79afa9fff59a4fc3223b6924d50cd6105 [PR build]

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.

2 participants