Skip to content

[typemap] Diagnose unsupported export signatures - #12597

Open
simonrozsival wants to merge 8 commits into
simonrozsival-export-field-parityfrom
simonrozsival-unsupported-export-signatures
Open

[typemap] Diagnose unsupported export signatures#12597
simonrozsival wants to merge 8 commits into
simonrozsival-export-field-parityfrom
simonrozsival-unsupported-export-signatures

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 31, 2026

Copy link
Copy Markdown
Member

Summary

  • reject unsupported [Export]/[ExportField] signatures during trimmable scanning with localized XA4263 before typemap, Java, or ACW-map output
  • preserve supported Java peers/interfaces, primitives, strings, ordinary arrays, enums, collections, and valid scalar [ExportParameter] mappings
  • match Export attributes by full Java.Interop identity and resolve peer/enum/special framework types by assembly identity through forwarders
  • validate exported constructors while preserving constructor identity and scalar adapter dispatch

Final type-identity behavior

Special mappings require canonical framework identity, not just a managed full name:

  • System.IO.Stream: System.Runtime facade or resolved System.Private.CoreLib
  • System.Xml.XmlReader: System.Xml.ReaderWriter facade or resolved System.Private.Xml
  • multi-hop facades such as netstandard → System.Xml.ReaderWriter → System.Private.Xml are accepted through the existing cycle-safe forwarder resolver
  • user assemblies defining the same full names are rejected with XA4263 for method parameter/return, ExportField return, and constructor parameter paths

Tests use minimal metadata assemblies for direct System.Private.Xml, the two-hop facade chain, and a resolved User.Xml assembly containing System.Xml.XmlReader. A separately compiled Android fixture and end-to-end builds retain the user-collision/no-output controls.

Constructor diagnostics ownership

PR #12567 owns XA4260 for generic, byref, pointer, function-pointer, rectangular-array constructor parameters, including nested SZ-array forms. XA4263 owns unresolved managed types and invalid [ExportParameter] kind/type/identity pairs. This PR does not duplicate XA4259/XA4261 analysis.

An isolated composition with the latest #12567 reproduces its remaining follow-up: two XA4263-rejected overloads on the same type with default/missing SuperArgumentsString also receive secondary XA4259 and XA4261. The coordinator will make that analyzer skip XA4263-rejected constructors after rebasing #12567 above this PR.

Validation

  • 802 standalone trimmable tests
  • 27 integration tests, including semantic classfile comparison, javac, peer/enum collisions, and Stream/XmlReader collisions
  • 66 export-signature/runtime-identity and no-output build tests
  • valid llvm-ir CoreCLR, trimmable CoreCLR, and trimmable NativeAOT fixture builds
  • legacy GenerateExportedMembers
  • latest [typemap] Diagnose unsupported constructor shapes #12567 composition: stronger two-overload secondary-diagnostic reproduction and 838 full combined standalone tests
  • git diff --check; every added line at most 180 characters; full-name attribute audit clean

Stacked on #12596. Tracks #12561.

Copilot AI lite review requested due to automatic review settings August 31, 2026 08:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs⚠️ warning: This uses simple-name matching ("ExportAttribute") to detect [Export]. If a user has a…
What changed in this PR

Adds early, localized diagnostics for unsupported [Export] / [ExportField] signature shapes in the trimmable typemap pipeline, so trimmable CoreCLR/NativeAOT fail deterministically (and before emitting typemap/Java/ACW-map outputs) instead of failing later in downstream steps.

Changes:

  • Introduces XA4263 (“unsupported export signature type”) during trimmable scanning, while preserving XA4206 precedence for [Export] on generic declaring types.
  • Tightens managed→JNI descriptor resolution to support “can we map this?” validation (via TryManagedTypeToJniDescriptor) without changing the legacy fallback behavior used for signature generation.
  • Extends unit + integration parity fixtures to cover unsupported shapes and additional supported peer/interface/string-array/stream override cases, and documents XA4263.
File Description
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​TestFixtures/​TestTypes.cs Adds fixture types covering unsupported [Export]/[ExportField] shapes (managed-only types, generics).
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapGeneratorTests.cs Adds generator-level assertions for XA4263/XA4206 and ensures unsupported members aren’t emitted into peers/Java sources.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​ExportSignatureTests.cs Adds focused fixture test ensuring unsupported signatures produce no generated members.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceSemanticParityTests.cs Extends semantic parity coverage for additional supported method shapes (peer/interface/string-array/stream mapping).
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​JavaSourceParityFixture/​JavaSourceParityTypes.cs Adds new exported members used by the semantic parity fixture (peer, listener, string array, stream mapping).
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds build-matrix coverage for unsupported export shapes and expands “no partial outputs” checks to include acw-map.txt.
src/​Xamarin.Android.Build.Tasks/​Tasks/​GenerateTrimmableTypeMap.cs Implements new logger hooks for XA4206 and XA4263 in the MSBuild task.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.resx Adds localized XA4263 message template.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.Designer.cs Adds generated accessor for XA4263 resource.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs Adds export signature validation and refactors managed→JNI mapping into a Try* API for “supported mapping” checks.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​ITrimmableTypeMapLogger.cs Adds logger interface hooks for XA4206 and XA4263.
Documentation/​docs-mobile/​TOC.yml Wires XA4263 doc into the docs TOC.
Documentation/​docs-mobile/​messages/​xa4263.md Adds documentation for XA4263.
Documentation/​docs-mobile/​messages/​index.md Adds XA4263 to the error code index.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

@simonrozsival
simonrozsival force-pushed the simonrozsival-unsupported-export-signatures branch from e40eedf to 7f245c2 Compare September 1, 2026 12:42
@simonrozsival
simonrozsival force-pushed the simonrozsival-unsupported-export-signatures branch 2 times, most recently from 816a31f to b42a478 Compare September 1, 2026 12:54
simonrozsival and others added 8 commits September 1, 2026 15:14
Reject unresolved managed, generic, and function-pointer export signatures during trimmable scanning with localized XA4263 diagnostics before any typemap, Java, or ACW-map output is written. Preserve legacy XA4206 precedence and supported Java mappings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Honor ExportParameter return mappings on exported fields, reject incompatible special mappings before generation, and resolve Java peer descriptors by assembly identity through type forwarders. Add semantic, cross-assembly, and three-runtime regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Require special ExportParameter mappings to target exact scalar Stream or XmlReader types, and match Export, ExportParameter, and ExportField attributes by full Java.Interop identity throughout scanner validation and collection.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Ignore static exported constructors, diagnose unresolved instance constructor parameters without overlapping XA4260 shape ownership, preserve ExportParameter kinds through UCO activation, and resolve enum signatures by assembly identity.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Ignore Export name overrides on metadata constructors, assert UCO dispatch calls the managed constructor rather than a virtual method, and recursively reserve nested structural parameter shapes for XA4260.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Require Stream and XmlReader special export mappings to resolve from their framework assemblies or forwarders, preventing same-full-name user types from receiving framework adapters.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Recognize System.Private.Xml as the canonical XmlReader definition and verify both direct and multi-facade mappings without accepting same-full-name user types.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise the resolved wrong-assembly branch by indexing a user assembly that defines System.Xml.XmlReader instead of relying on a missing assembly reference.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival force-pushed the simonrozsival-unsupported-export-signatures branch from b42a478 to 4cf3eb1 Compare September 1, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants