Skip to content

[typemap] Diagnose unsupported constructor shapes - #12567

Open
simonrozsival wants to merge 49 commits into
simonrozsival-unsupported-export-signaturesfrom
simonrozsival-constructor-signature-diagnostics
Open

[typemap] Diagnose unsupported constructor shapes#12567
simonrozsival wants to merge 49 commits into
simonrozsival-unsupported-export-signaturesfrom
simonrozsival-constructor-signature-diagnostics

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 28, 2026

Copy link
Copy Markdown
Member

Summary

  • add localized XA4259-XA4262 diagnostics for constructor collisions, unsupported shapes, missing Java base constructors, and invalid ordinary SuperArgumentsString parameter references
  • collect independent constructor and reserved-Java-name diagnostics before returning without outputs
  • match implicit derived constructors to registered base constructors by computed JNI signature
  • preserve XA4263 suppression and valid Export plus Register/JniConstructorSignature metadata regardless of attribute order
  • use full managed type identity for primitives, activation discovery, overload comparison, and JNI descriptor resolution
  • conservatively validate SuperArgumentsString: tokenize literals/comments and defer any expression containing Java lambda (->) or method-reference (::) syntax entirely to javac; retain XA4262 for ordinary bare/call/arithmetic pN references
  • deduplicate XA4259 per peer/JNI signature and assert complete measured legacy constructor collections
  • preserve legacy framework-constructor compatibility and stop before partial Java/typemap output

Validation

  • standalone trimmable typemap suite: 870/870
  • trimmable typemap integration suite: 41/41
  • conservative lambda/method-reference javac matrix: 42/42
  • combined llvm-ir/trimmable CoreCLR/trimmable NativeAOT diagnostic and no-output matrices: 60/60
  • trimmable successful-build baseline: 3 passed, 1 unsupported configuration skipped
  • final independent high-confidence review: clean
  • git diff --check; acceptance commit adds 33 lines (within 180)

Part of #12561

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

Review tier: Lite
Findings: 1 High severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Low severity tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Scanner/​ConstructorDetectionTests.cs — 💡 suggestion — ScanPeer opens and reads both fixture assemblies from disk on every test invocation.…
High severity src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs — ❌ error — Base-constructor compatibility for non-explicit constructors is currently checked via…
What changed in this PR

Adds first-class constructor-shape validation to the trimmable typemap pipeline, surfacing new localized XA4259–XA4262 diagnostics and ensuring generation stops before emitting partial Java/type-map output when constructors are not representable or are ambiguous.

Changes:

  • Introduces constructor diagnostics (collision, unsupported parameter shapes, missing compatible base ctor, invalid SuperArgumentsString) and wires them into the generator/Build.Tasks logger with localized resources.
  • Expands test coverage with new “invalid constructor” fixture assembly and adds focused unit/integration/build tests to validate diagnostics and “no partial output” behavior.
  • Documents new error codes (XA4259–XA4262) and adds them to the docs index/TOC.
File Description
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​TestFixtures/​StubAttributes.cs Extends stub ExportAttribute to support ctor usage and SuperArgumentsString for scanner tests.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Scanner/​ConstructorDetectionTests.cs Adds targeted tests for new constructor diagnostics and representable/explicit cases.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj Adds a new fixture project and copies its output alongside existing fixtures.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​InvalidConstructorFixtures/​InvalidConstructors.cs New fixture types that intentionally trigger (or avoid) constructor diagnostics.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​InvalidConstructorFixtures/​InvalidConstructorFixtures.csproj New fixture assembly project (unsafe enabled) used as scanner/generator input.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapGeneratorTests.cs Verifies generator logs coded errors and returns no partial outputs when ctor diagnostics exist.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​UserTypesFixture/​UserTypesFixture.csproj Enables unsafe to support new user fixture types using pointers/function pointers.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​UserTypesFixture/​UserTypes.cs Adds user fixture types mirroring ctor-collision/unrepresentable/super-args scenarios.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​ScannerRunner.cs Adds legacy constructor extraction to support ctor parity tests.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​ScannerComparisonTests.cs Excludes ctor-diagnostic fixtures from legacy↔new marshal-method parity comparisons.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/​ConstructorParityTests.cs New integration tests that pin legacy behavior around ctor collisions/unrepresentable ctors/super args.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds a build-level regression ensuring XA4259 fails before any partial typemap Java is written.
src/​Xamarin.Android.Build.Tasks/​Tasks/​GenerateTrimmableTypeMap.cs Implements new logger hooks for XA4259–XA4262 in the MSBuild task.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.resx Adds localized strings for XA4259–XA4262.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.Designer.cs Updates generated resource accessors for XA4259–XA4262.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​TrimmableTypeMapGenerator.cs Validates constructor diagnostics early and returns no generated outputs on failure.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerScanner.cs Computes ctor diagnostics during scanning, including signature collapse, parameter-shape validation, base-ctor compatibility, and SuperArgumentsString validation.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaPeerInfo.cs Adds ConstructorDiagnostics model plus diagnostic kind/info types.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​ITrimmableTypeMapLogger.cs Extends logger interface with ctor diagnostic logging hooks.
Documentation/​docs-mobile/​TOC.yml Adds entries for XA4259–XA4262 docs.
Documentation/​docs-mobile/​messages/​xa4259.md New documentation page for XA4259.
Documentation/​docs-mobile/​messages/​xa4260.md New documentation page for XA4260.
Documentation/​docs-mobile/​messages/​xa4261.md New documentation page for XA4261.
Documentation/​docs-mobile/​messages/​xa4262.md New documentation page for XA4262.
Documentation/​docs-mobile/​messages/​index.md Adds XA4259–XA4262 to the message index listing.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

Comment thread src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs Outdated
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch from e03c49d to c385503 Compare August 31, 2026 14:46
@simonrozsival
simonrozsival changed the base branch from main to simonrozsival-unsupported-export-signatures August 31, 2026 14:46
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch 2 times, most recently from 765d233 to 8936f2a Compare September 1, 2026 12:50
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch 2 times, most recently from 9d75936 to 7854663 Compare September 1, 2026 13:15
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch from 7854663 to 8b98f5f Compare September 1, 2026 13:33
simonrozsival and others added 6 commits September 1, 2026 15:48
Match legacy XA4205 and XA4208 validation in the trimmable scanner, before invalid field members can reach generated typemap or Java outputs. Extend semantic, build, and device coverage for valid static and instance ExportField behavior and classify legacy-unsupported field names.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Prove that parameter-count validation takes precedence over void-return validation for an initializer violating both rules, matching measured llvm-ir behavior across trimmable CoreCLR and NativeAOT without partial outputs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Match legacy XA4207 precedence for ExportField methods declared on generic types before parameter-count or void-return validation, and reject them before typemap or Java outputs are written.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Ignore unrelated attributes that share the ExportFieldAttribute simple name by matching the Java.Interop namespace consistently during validation, field collection, and marshal-method registration.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove duplicated scanner fixtures and keep focused build/runtime parity coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch from 8b98f5f to 3ea14be Compare September 1, 2026 13:54
simonrozsival and others added 3 commits September 1, 2026 17:15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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>
simonrozsival and others added 23 commits September 1, 2026 17:15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival force-pushed the simonrozsival-constructor-signature-diagnostics branch from 3ea14be to 663a4ab Compare September 1, 2026 15:16
simonrozsival and others added 4 commits September 3, 2026 12:17
Use each assembly index's signature provider, pass the type handle to peer detection, and remove the unmatched class brace.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reuse the constructor fixture scan results across tests instead of reopening and rescanning the same assemblies for each invocation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve conflicts between the refreshed base branch and constructor-shape diagnostics while preserving both validation paths and their test coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Import System.Text for Encoding and include all constructor fixture projects in the solution so Release builds produce the DLLs copied by the test project.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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