[bgen] Support BindAs parameters in protocols - #26195
Conversation
Allow parameter-level BindAs in Protocol and Model definitions while continuing to reject property and return-value usage. Preserve the native OriginalType through generated metadata and messaging signatures, resolve BindAs metadata through protocol interface maps in the static and managed registrars, and emit managed parameter types in DynamicDependency and XML documentation IDs. Add generator, registrar callback, diagnostic, documentation, and XML documentation coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b96fb7cb-f82d-4cd4-9b60-a7f899f3b42d
Move generalized parameter-level BindAs support for Protocol and Model definitions to #26195, which targets main as requested during review. Temporarily defer the protection-class searchable-items delegate callback and restore its targeted xtro todo entries until the feature flows from main to xcode27.0. Keep the CoreSpotlight compatibility fixes that hide incorrectly shipped APIs with Obsolete and EditorBrowsable attributes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b96fb7cb-f82d-4cd4-9b60-a7f899f3b42d
There was a problem hiding this comment.
Pull request overview
This PR extends the binding generator (bgen) and both registrars to support parameter-level [BindAs] inside [Protocol] / [Model] definitions (while continuing to reject [BindAs] on protocol/model properties and return values). It also updates diagnostics, documentation, and adds/updates test coverage (including XML doc “golden” expectations) to validate the new behavior.
Changes:
- Allow
[BindAs]on protocol/model parameters and propagate the metadata correctly through generator + registrars (including mapped protocol/interface methods). - Adjust marshalling/doc-id generation to use the correct managed vs native parameter types where appropriate (trimming dependencies + XML doc IDs).
- Add bindings-test + bgen test coverage and update user-facing docs/error messages to reflect the new constraints.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/dotnet-linker/Steps/ManagedRegistrarStep.cs | Resolves parameter [BindAs] via mapped protocol interface methods for the managed registrar step. |
| src/ObjCRuntime/Registrar.cs | Resolves parameter [BindAs] via mapped protocol interface methods in the runtime registrar. |
| src/bgen/Generator.cs | Permits protocol/model parameter [BindAs], preserves OriginalType, and uses managed types for doc IDs/trimming metadata. |
| src/bgen/Models/MarshalInfo.cs | Uses BindAsAttribute.OriginalType when determining marshaling type info (native signature preservation). |
| src/bgen/DocumentationManager.cs | Adds an optional parameter-type provider to compute doc IDs using managed parameter types. |
| src/ObjCRuntime/BindAsAttribute.cs | Updates inline docs to describe parameter support in protocol/model definitions. |
| src/Resources.resx | Updates BI1050 message to match the new restriction (properties/return values only). |
| src/Resources.Designer.cs | Regenerates BI1050 designer comment to match updated resource string. |
| tests/bindings-test/ApiDefinition.cs | Adds a protocol/model method using parameter-level [BindAs] for runtime validation. |
| tests/bindings-test/ProtocolTest.cs | Adds a test that invokes the exported selector and asserts correct BindAs conversion in protocol implementation. |
| tests/bindings-test/Messaging.cs | Adds an objc_msgSend P/Invoke variant returning void used by the new protocol BindAs test. |
| tests/bgen/tests/bindastests.cs | Adds bgen test coverage for parameter [BindAs] inside [Protocol]/[Model]. |
| tests/bgen/tests/xmldocs.cs | Adds protocol method with parameter [BindAs] to exercise XML doc ID/type generation. |
| tests/bgen/tests/ExpectedXmlDocs.iOS.xml | Updates XML-doc golden output for BindAs-parameter doc IDs (iOS). |
| tests/bgen/tests/ExpectedXmlDocs.tvOS.xml | Updates XML-doc golden output for BindAs-parameter doc IDs (tvOS). |
| tests/bgen/tests/ExpectedXmlDocs.macOS.xml | Updates XML-doc golden output for BindAs-parameter doc IDs (macOS). |
| tests/bgen/tests/ExpectedXmlDocs.MacCatalyst.xml | Updates XML-doc golden output for BindAs-parameter doc IDs (Mac Catalyst). |
| tests/bgen/ErrorTests.cs | Updates BI1050 expected error text to match new restriction wording. |
| docs/website/generator-errors.md | Updates BI1050 documentation to match new restriction wording. |
| docs/website/binding_types_reference_guide.md | Updates BindAs docs to describe protocol/model parameter support and continued restrictions. |
| docs/website/binding_objc_libs.md | Updates BindAs docs to describe protocol/model parameter support and continued restrictions. |
| docs/api/ObjCRuntime/BindAsAttribute.xml | Adds API doc note clarifying protocol/model parameter-only support. |
Files not reviewed (1)
- src/Resources.Designer.cs: Generated file
Reuse the per-type protocol method map during normal registrar validation instead of rebuilding it for every parameter. Late signature evaluation prepares at most one local map per method, including null results. Thread one local map through each managed-registrar type without adding persistent runtime caches, and skip lookups for properties, constructors, and categories. Add native callback coverage for a protocol method with multiple BindAs parameters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b96fb7cb-f82d-4cd4-9b60-a7f899f3b42d
|
Addressed the interface-map performance feedback in 6f41033 without adding persistent runtime caches. Normal registration reuses its existing per-type map, late evaluation builds at most one local map per method, and the managed registrar threads one local map through each type. Added a two-parameter native callback test; both callback tests pass under dynamic, static, and managed-static registrars on Xcode 27. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Update the tvOS and Mac Catalyst MonoVM interpreter preserved API baselines generated by CI for the protocol method-map reuse changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b96fb7cb-f82d-4cd4-9b60-a7f899f3b42d
|
Updated the CI-generated tvOS and Mac Catalyst MonoVM interpreter preserved-API baselines in 86a3eeb. Both failed legs were app-size expectation drift from the registrar method-map changes; published NUnit results contained no functional test failures. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Update the iOS MonoVM interpreter preserved API baseline generated by CI for the protocol method-map reuse changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b96fb7cb-f82d-4cd4-9b60-a7f899f3b42d
|
Added the CI-generated iOS MonoVM interpreter preserved-API baseline in 6d7b84e. This completes the app-size updates for all three affected platforms: iOS, tvOS, and Mac Catalyst. |
This comment has been minimized.
This comment has been minimized.
|
/azp run xamarin-macios-sim-pr-tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/azp run xamarin-macios-sim-pr-tests |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
|
/azp run xamarin-macios-sim-pr-tests |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
✅ Applied expected app size files from gist. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
@copilot resolve the merge conflicts in this pull request |
Resolve conflicts in TVOS and iOS MonoVM interpreter preservedapis expected files by accepting the updated content from main. Co-authored-by: dalexsoto <204671+dalexsoto@users.noreply.github.com>
Resolved the merge conflicts in b283d7d. The conflicts were in |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: e9e228af-33c5-4ac3-ac5e-f8839d48f8bc
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #9c5f427] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 203 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
## Summary - Bind `CSSearchableIndexDelegate.searchableItemsForIdentifiers:protectionClass:searchableItemsHandler:` on iOS 27.0, macOS 27.0, and Mac Catalyst 27.0. - Reuse the existing searchable-items completion handler and preserve the native non-null contract. - Remove the resolved iOS, macOS, and Mac Catalyst CoreSpotlight xtro todo files. ## Temporary API shape The native `NSFileProtectionType` parameter is temporarily exposed as `NSString` because bgen still rejects parameter-level `[BindAs]` inside protocol/model definitions. Issue #26273 tracks changing it to `[BindAs (typeof (NSFileProtectionType))] NSString` before Xcode 27 GA, after #26195 lands. ## Validation - `make world` - Clean xtro generation/classification: sanity passed for all platforms - Clean cecil suite: passed - iOS 27 introspection: 44 passed, 0 failed - tvOS 27 introspection: 43 passed, 0 failed - macOS introspection: 32 passed, 0 failed, 2 host-version-gated - Mac Catalyst introspection: 39 passed, 0 failed, 4 expected ignores - Clean filtered `AppSizeTest`: 0 failed; 16 skipped because app-size baselines are disabled for beta Xcode Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2883e233-aebe-4ada-932d-21a971c895e5
Summary
[BindAs]in[Protocol]and[Model]definitions while continuing to reject properties and return valuesOriginalTypemetadata and messaging signatures, and resolve parameter attributes through mapped protocol methods in both registrarsContext
This support was extracted from #26158 at @rolfbjarne’s request so that the generalized bgen/registrar feature lands in
mainindependently of the Xcode 27 CoreSpotlight bindings. The deferred CoreSpotlight callback will be added after this change flows toxcode27.0.Validation
make worldwithNO_XCODE=1for the platform-independentmainfeature