Remove ByValueMarshalKindSupport.Unnecessary and move ByValueContentsMarshalKindValidator to analyzers only#125458
Open
Remove ByValueMarshalKindSupport.Unnecessary and move ByValueContentsMarshalKindValidator to analyzers only#125458
Conversation
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
jkoritzinsky
approved these changes
Mar 11, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Contributor
There was a problem hiding this comment.
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 theSR.InOutAttributesresource (including localized xlf entries). - Simplified
TypePositionInfoby removing by-value marshal attribute location tracking and returning onlyByValueContentsMarshalKind. - Updated analyzer call sites to explicitly wrap marshalling resolvers with
ByValueContentsMarshalKindValidatorwhere 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. |
jtschuster
reviewed
Mar 19, 2026
...eropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs
Outdated
Show resolved
Hide resolved
jtschuster
approved these changes
Mar 19, 2026
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
jtschuster
approved these changes
Mar 19, 2026
This was referenced Mar 20, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two cleanup changes to the interop source generation infrastructure:
Move
ByValueContentsMarshalKindValidatorto analyzer-only usageByValueContentsMarshalKindValidatoris a validation/diagnostic concern and should not run during code generation. Removed it fromDefaultMarshallingGeneratorResolver.Create()andDownlevelLibraryImportGeneratorHelpers.GeneratorResolver, and explicitly wrap the resolver with it at each analyzer call site:LibraryImportDiagnosticsAnalyzerConvertToLibraryImportAnalyzerDownlevelLibraryImportDiagnosticsAnalyzerComInterfaceGeneratorDiagnosticsAnalyzer(via static lambda)VtableIndexStubDiagnosticsAnalyzer(via static lambda)ConvertComImportToGeneratedComInterfaceAnalyzerRemove
ByValueMarshalKindSupport.UnnecessaryUnnecessarywas never assigned in any activeByValueMarshalKindSupportInfoinstance (DefaultandArrayParameterdescriptors use onlySupported,NotSupported, andNotRecommended), making it and its dependents dead code. Removed:ByValueMarshalKindSupport.Unnecessaryenum valueUnnecessaryswitch cases inByValueContentsMarshalKindValidatorandByValueMarshalKindSupportInfo.GetSupportTypePositionInfo.ByValueMarshalAttributeLocations— only existed to provide attribute source locations for theUnnecessarydiagnosticGetByValueContentsMarshalKind(return type simplified from a 3-tuple to justByValueContentsMarshalKind)SR.InOutAttributesstring resource and all 13 xlf translation entriesByValueMarshalKindSupportDescriptor.Defaultwhich claimed "[In] is allowed, but unnecessary" whenInSupportis actuallyNotSupported🔒 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.