Skip to content

Conversation

@mandel-macaque
Copy link
Contributor

@mandel-macaque mandel-macaque commented May 23, 2025

Update the code generation of rgen to use the 'global::' alias based in the generator configuration. The tests classes have been updated to ensure that if we switch off the use of the alias, the tests do not need to be updated.

mandel-macaque and others added 2 commits May 22, 2025 21:23
Upate the code generation of rgen to use the 'global::' allias based in
the generator configuration. The tests classes have been updated to
ensure that if we switch off the use of the alias, the tests do not need
to be udpdated.
[SupportedOSPlatform ("maccatalyst13.1")]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public virtual partial nfloat LineSpacing
public virtual partial global::CompareGeneratedCode.CompareGeneratedCode.netmodule..nfloat LineSpacing
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is wrong, missing the global using. Will fix it.

@dalexsoto dalexsoto requested a review from Copilot May 23, 2025 01:34
Copy link
Contributor

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 updates the RGen code generator to support toggling the global:: alias for all generated type references via configuration.

  • Introduces a $GLOBAL$ placeholder in test fixtures and a isGlobal flag to replace it at read time
  • Adds StringExtensions.GetIdentifierName and refactors emitters/formatters to build TypeSyntax directly
  • Enhances TypeInfo with init-only properties and conversion helpers for array/non-nullable types

Reviewed Changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/rgen/.../ExpectedAVAudioPcmBufferNoDefaultCtr.cs Switched global:: placeholder for ObjCRuntime calls
tests/rgen/.../ExpectedAVAudioPcmBufferDefaultCtr.cs Updated default ctor to use global:: alias for Foundation types
tests/rgen/.../BindingSourceGeneratorGeneratorTests.cs Adjusted test to expect global:: in class handle
tests/rgen/.../BaseTestDataGenerator.cs Added isGlobal flag and placeholder replacement logic
tests/rgen/.../BaseGeneratorTestClass.cs Added Global(string) helper to prefix with global::
src/rgen/.../Microsoft.Macios.Transformer.csproj Linked Configuration.cs and ArgumentSyntaxExtensions.cs
src/rgen/.../TypeInfoFormatter.cs Refactored identifier building to use GetIdentifierName
src/rgen/.../StringExtensions.cs Added GetIdentifierName extension for qualified names
src/rgen/.../ArgumentSyntaxExtensions.cs Removed unused using and aligned imports
src/rgen/.../EnumEmitter.cs Refactored error-domain emitter to use NSString & Dlfcn
src/rgen/.../ClassEmitter.cs Updated default-ctor emission to use qualified NSObjectFlag
src/rgen/.../BindingSyntaxFactory.cs Changed StaticVariable and invocations to accept TypeSyntax
src/rgen/.../BindingSyntaxFactory.Trampoline.cs Switched pointer/generic calls to use GetIdentifierSyntax
src/rgen/.../BindingSyntaxFactory.Runtime.cs Updated various Get* methods to take TypeSyntax
src/rgen/.../BindingSyntaxFactory.Property.cs Refactored property binding to use GetIdentifierName
src/rgen/.../BindingSyntaxFactory.ObjCRuntime.cs Expanded and reorganized known ObjCRuntime/Foundation types
src/rgen/.../BindingSyntaxFactory.Dlfcn.cs Switched Dlfcn/Libraries fields to use GetIdentifierName
src/rgen/.../DataModel/TypeInfo.cs Made several props init-only; added ToArrayElementType/ToNonNullable
src/rgen/.../Microsoft.Macios.Bindings.Analyzer.csproj Linked Configuration.cs and ArgumentSyntaxExtensions.cs

Comment on lines +13 to +15
return isGlobal
? File.ReadAllText (fullPath).Replace ("$GLOBAL$", "global::")
: File.ReadAllText (fullPath).Replace ("$GLOBAL$", "");
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The code invokes File.ReadAllText twice depending on isGlobal. Consider reading the file into a local variable once and then applying .Replace(...) to avoid duplicate I/O.

Suggested change
return isGlobal
? File.ReadAllText (fullPath).Replace ("$GLOBAL$", "global::")
: File.ReadAllText (fullPath).Replace ("$GLOBAL$", "");
var fileContent = File.ReadAllText(fullPath);
return isGlobal
? fileContent.Replace("$GLOBAL$", "global::")
: fileContent.Replace("$GLOBAL$", "");

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@mandel-macaque mandel-macaque May 23, 2025

Choose a reason for hiding this comment

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

It's an if unary operator, only one branch executes.

return type;
}

public TypeInfo ToArrayElementType ()
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The ToArrayElementType helper resets IsArray and SpecialType but does not update Name or Namespace to the element type. This will lead to incorrect type names downstream. It should also set Name and Namespace based on the element type.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment is incorrect, we do the following:

		if (symbol is IArrayTypeSymbol arraySymbol) {
			// override the name and namespace with the array name
			(Name, Namespace) = GetTypeNameAndNamespace (arraySymbol.ElementType);
			FullyQualifiedName = arraySymbol.ElementType.ToDisplayString ();
			IsArray = true;
			ArrayElementType = arraySymbol.ElementType.SpecialType;
			ArrayElementTypeIsWrapped = arraySymbol.ElementType.IsWrapped ();
			ArrayElementIsINativeObject = arraySymbol.ElementType.IsINativeObject ();
		}

which avoids the issue. Good try.

@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

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

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

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

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

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #4732f46] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 4732f469e4d5e4528d6f5a99f7954e0b692ad5b5 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: c0160ed8845264ed70e1d5210701e15f7c64de4b [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

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

✅ 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: c0160ed8845264ed70e1d5210701e15f7c64de4b [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 #0bfe739] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 0bfe7392e794bb1ff547184bf717a756e4af1d9d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 0bfe7392e794bb1ff547184bf717a756e4af1d9d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 0bfe7392e794bb1ff547184bf717a756e4af1d9d [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 0bfe7392e794bb1ff547184bf717a756e4af1d9d [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: c0160ed8845264ed70e1d5210701e15f7c64de4b [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #0bfe739] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 15 tests failed, 110 tests passed.

Failures

❌ monotouch tests (MacCatalyst)

15 tests failed, 0 tests passed.
Details
  • monotouch-test/Mac Catalyst/Debug: Failed (Test run failed.
    Tests run: 3205 Passed: 3065 Inconclusive: 10 Failed: 1 Ignored: 139)
  • monotouch-test/Mac Catalyst/Debug (ARM64): Failed (Test run failed.
    Tests run: 3205 Passed: 3065 Inconclusive: 10 Failed: 1 Ignored: 139)
  • monotouch-test/Mac Catalyst/Debug (managed static registrar): Failed (Test run failed.
    Tests run: 3202 Passed: 3064 Inconclusive: 10 Failed: 1 Ignored: 137)
  • monotouch-test/Mac Catalyst/Debug (static registrar): Failed (Test run crashed (exit code: 139).
    Test run crashed)
  • monotouch-test/Mac Catalyst/Debug (static registrar, ARM64): Failed (Test run failed.
    Tests run: 3202 Passed: 3064 Inconclusive: 10 Failed: 1 Ignored: 137)
  • monotouch-test/Mac Catalyst/Release (managed static registrar): Failed (Test run failed.
    Tests run: 3202 Passed: 3059 Inconclusive: 10 Failed: 1 Ignored: 142)
  • monotouch-test/Mac Catalyst/Release (managed static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3202 Passed: 3059 Inconclusive: 10 Failed: 1 Ignored: 142)
  • monotouch-test/Mac Catalyst/Release (NativeAOT): Failed (Test run failed.
    Tests run: 3202 Passed: 3047 Inconclusive: 11 Failed: 1 Ignored: 154)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, ARM64): Failed (Test run failed.
    Tests run: 3202 Passed: 3049 Inconclusive: 10 Failed: 1 Ignored: 152)
  • monotouch-test/Mac Catalyst/Release (NativeAOT, x64): Failed (Test run failed.
    Tests run: 3202 Passed: 3056 Inconclusive: 11 Failed: 1 Ignored: 145)
  • monotouch-test/Mac Catalyst/Release (static registrar): Failed (Test run failed.
    Tests run: 3202 Passed: 3058 Inconclusive: 10 Failed: 1 Ignored: 143)
  • monotouch-test/Mac Catalyst/Release (static registrar, all optimizations): Failed (Test run failed.
    Tests run: 3202 Passed: 3059 Inconclusive: 10 Failed: 1 Ignored: 142)
  • monotouch-test/Mac Catalyst/Release (ARM64, LLVM): Failed (Test run failed.
    Tests run: 3202 Passed: 3059 Inconclusive: 10 Failed: 1 Ignored: 142)
  • monotouch-test/Mac Catalyst/Debug (interpreter): Failed (Test run failed.
    Tests run: 3205 Passed: 3062 Inconclusive: 10 Failed: 1 Ignored: 142)
  • monotouch-test/Mac Catalyst/Release (interpreter): Failed (Test run failed.
    Tests run: 3202 Passed: 3056 Inconclusive: 10 Failed: 1 Ignored: 145)

Html Report (VSDrops) Download

Successes

✅ 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 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 10 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 10 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: 0bfe7392e794bb1ff547184bf717a756e4af1d9d [PR build]

@mandel-macaque
Copy link
Contributor Author

Failures are unrelated to code changes.

@mandel-macaque mandel-macaque merged commit 4e6e475 into main May 23, 2025
44 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/global-all-the-things branch May 23, 2025 19:20
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.

4 participants