Skip to content

Remove ByValueMarshalKindSupport.Unnecessary and move ByValueContentsMarshalKindValidator to analyzers only#125458

Open
Copilot wants to merge 4 commits intomainfrom
copilot/move-byvaluecontentsmarshalkindvalidator
Open

Remove ByValueMarshalKindSupport.Unnecessary and move ByValueContentsMarshalKindValidator to analyzers only#125458
Copilot wants to merge 4 commits intomainfrom
copilot/move-byvaluecontentsmarshalkindvalidator

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

Two cleanup changes to the interop source generation infrastructure:

Move ByValueContentsMarshalKindValidator to analyzer-only usage

ByValueContentsMarshalKindValidator is a validation/diagnostic concern and should not run during code generation. Removed it from DefaultMarshallingGeneratorResolver.Create() and DownlevelLibraryImportGeneratorHelpers.GeneratorResolver, and explicitly wrap the resolver with it at each analyzer call site:

  • LibraryImportDiagnosticsAnalyzer
  • ConvertToLibraryImportAnalyzer
  • DownlevelLibraryImportDiagnosticsAnalyzer
  • ComInterfaceGeneratorDiagnosticsAnalyzer (via static lambda)
  • VtableIndexStubDiagnosticsAnalyzer (via static lambda)
  • ConvertComImportToGeneratedComInterfaceAnalyzer

Remove ByValueMarshalKindSupport.Unnecessary

Unnecessary was never assigned in any active ByValueMarshalKindSupportInfo instance (Default and ArrayParameter descriptors use only Supported, NotSupported, and NotRecommended), making it and its dependents dead code. Removed:

  • ByValueMarshalKindSupport.Unnecessary enum value
  • The Unnecessary switch cases in ByValueContentsMarshalKindValidator and ByValueMarshalKindSupportInfo.GetSupport
  • TypePositionInfo.ByValueMarshalAttributeLocations — only existed to provide attribute source locations for the Unnecessary diagnostic
  • Location tracking in GetByValueContentsMarshalKind (return type simplified from a 3-tuple to just ByValueContentsMarshalKind)
  • SR.InOutAttributes string resource and all 13 xlf translation entries
  • Fixed incorrect XML doc comment on ByValueMarshalKindSupportDescriptor.Default which claimed "[In] is allowed, but unnecessary" when InSupport is actually NotSupported

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 3 commits March 11, 2026 20:47
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
@jkoritzinsky jkoritzinsky marked this pull request as ready for review March 11, 2026 21:54
Copilot AI review requested due to automatic review settings March 11, 2026 21:54
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

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 cleans up the interop source generation pipeline by (1) restricting ByValueContentsMarshalKindValidator to analyzer-only diagnostic collection (so it no longer affects code generation), and (2) removing the unused ByValueMarshalKindSupport.Unnecessary state and all supporting plumbing/resources.

Changes:

  • Removed ByValueMarshalKindSupport.Unnecessary, related switch cases, and the SR.InOutAttributes resource (including localized xlf entries).
  • Simplified TypePositionInfo by removing by-value marshal attribute location tracking and returning only ByValueContentsMarshalKind.
  • Updated analyzer call sites to explicitly wrap marshalling resolvers with ByValueContentsMarshalKindValidator where diagnostics are computed.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs Removes [In]/[Out] attribute location tracking and simplifies marshal-kind extraction.
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs Removes the unused ByValueMarshalKindSupport.Unnecessary enum value.
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DefaultMarshallingGeneratorResolver.cs Stops applying ByValueContentsMarshalKindValidator during resolver creation (codegen path).
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueMarshalKindSupportDescriptor.cs Removes Unnecessary diagnostic construction and fixes the Default descriptor doc comment.
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs Removes handling for the deleted Unnecessary support state.
src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs Wraps the resolver with ByValueContentsMarshalKindValidator for analyzer diagnostics.
src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs Wraps the resolver with ByValueContentsMarshalKindValidator for conversion eligibility diagnostics.
src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportGeneratorHelpers.cs Removes validator wrapping from the shared downlevel generator resolver (codegen path).
src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportDiagnosticsAnalyzer.cs Wraps the downlevel resolver with ByValueContentsMarshalKindValidator for analyzer diagnostics.
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs Wraps resolver factory with ByValueContentsMarshalKindValidator when generating stub diagnostics.
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/VtableIndexStubDiagnosticsAnalyzer.cs Wraps resolver factory with ByValueContentsMarshalKindValidator when generating stub diagnostics.
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs Wraps COM resolver instances with ByValueContentsMarshalKindValidator during conversion checks.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx Removes the InOutAttributes resource entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.cs.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.de.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.es.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.fr.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.it.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ja.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ko.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pl.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pt-BR.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ru.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.tr.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hans.xlf Removes the InOutAttributes localized entry.
src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hant.xlf Removes the InOutAttributes localized entry.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants