Skip to content

Comments

Move diagnostics from ComInterfaceGenerator and VtableIndexStubGenerator into separate analyzers#124669

Open
Copilot wants to merge 3 commits intomainfrom
copilot/move-diagnostics-out-of-generators
Open

Move diagnostics from ComInterfaceGenerator and VtableIndexStubGenerator into separate analyzers#124669
Copilot wants to merge 3 commits intomainfrom
copilot/move-diagnostics-out-of-generators

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Description

Follows the pattern established in #123780 for LibraryImportGenerator: moves all diagnostic reporting out of ComInterfaceGenerator and VtableIndexStubGenerator and into dedicated DiagnosticAnalyzer classes, giving the IDE better control over when and how diagnostics appear.

Changes

  • New VtableIndexStubDiagnosticsAnalyzer — runs per-method via RegisterSymbolAction on all [VirtualMethodIndex]-attributed methods; re-uses the validation logic (formerly GetDiagnosticIfInvalidMethodForGeneration) and calls the stub generators to collect diagnostics
  • New ComInterfaceGeneratorDiagnosticsAnalyzer — analyzes each [GeneratedComInterface] interface independently in RegisterSymbolAction; uses a ConcurrentDictionary<INamedTypeSymbol, DiagnosticOr<(ComInterfaceInfo, INamedTypeSymbol)>> (created in RegisterCompilationStartAction) for deduplication; builds an ancestor chain per-interface via BuildContextChain to enable cross-interface diagnostics like BaseInterfaceIsNotGenerated without a compilation-end action; vtable indices are not required to be correct since no code is emitted
  • VtableIndexStubGenerator — removed GetDiagnosticIfInvalidMethodForGeneration, all RegisterDiagnostics calls, and RegisterSourceOutput for invalid methods; CalculateStubInformation promoted to internal static
  • ComInterfaceGenerator — removed both RegisterDiagnostics calls; CalculateStubInformation promoted to internal static
  • Tests (CompileFails.cs, ByValueContentsMarshalling.cs, TargetSignatureTests.cs, AddMarshalAsToElementTests.cs) — updated verifier aliases to use ComInterfaceGeneratorDiagnosticsAnalyzer instead of EmptyDiagnosticAnalyzer so existing diagnostic tests continue to pass

Testing

Existing unit tests in ComInterfaceGenerator.Unit.Tests cover the diagnostic scenarios. The test aliases were updated to wire in the new analyzers, so all existing CompileFails, ByValueContentsMarshalling, TargetSignatureTests, and AddMarshalAsToElementTests tests validate the analyzer behavior directly. All 839 tests pass.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 20, 2026
…tor into separate analyzers

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Move diagnostics out of ComInterfaceGenerator and VtableIndexStubGenerator Move diagnostics from ComInterfaceGenerator and VtableIndexStubGenerator into separate analyzers Feb 20, 2026
Copilot AI requested a review from jkoritzinsky February 20, 2026 20:43
Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

@copilot please address this feedback.

…e RegisterSymbolAction

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI requested a review from jkoritzinsky February 20, 2026 23:58
@jkoritzinsky jkoritzinsky marked this pull request as ready for review February 21, 2026 00:13
@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices and removed area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Feb 21, 2026
@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 follows the pattern established in #123780 to move diagnostic generation from source generators (ComInterfaceGenerator and VtableIndexStubGenerator) into dedicated DiagnosticAnalyzer classes. This architectural change gives the IDE better control over when and how diagnostics appear, improving the user experience.

Changes:

  • Created two new diagnostic analyzers (VtableIndexStubDiagnosticsAnalyzer and ComInterfaceGeneratorDiagnosticsAnalyzer) that independently run the same diagnostic logic previously embedded in the generators
  • Removed all diagnostic reporting code from the generators and promoted CalculateStubInformation methods to internal static for reuse by analyzers
  • Updated test infrastructure to wire in the new analyzers instead of EmptyDiagnosticAnalyzer

Reviewed changes

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

Show a summary per file
File Description
VtableIndexStubDiagnosticsAnalyzer.cs New analyzer that validates [VirtualMethodIndex] methods using per-method symbol actions; calls generator's stub calculation to collect diagnostics
ComInterfaceGeneratorDiagnosticsAnalyzer.cs New analyzer that validates [GeneratedComInterface] interfaces with per-interface symbol actions; uses cached interface info and builds ancestor chains to enable cross-interface diagnostics
VtableIndexStubGenerator.cs Removed diagnostic generation code, invalid method filtering, and RegisterDiagnostics calls; promoted CalculateStubInformation to internal static
ComInterfaceGenerator.cs Removed RegisterDiagnostics calls; promoted CalculateStubInformation to internal static
TargetSignatureTests.cs Updated verifier alias from EmptyDiagnosticAnalyzer to ComInterfaceGeneratorDiagnosticsAnalyzer
CompileFails.cs Updated verifier alias from EmptyDiagnosticAnalyzer to ComInterfaceGeneratorDiagnosticsAnalyzer
ByValueContentsMarshalling.cs Updated verifier alias from EmptyDiagnosticAnalyzer to ComInterfaceGeneratorDiagnosticsAnalyzer
AddMarshalAsToElementTests.cs Updated verifier alias from EmptyDiagnosticAnalyzer to ComInterfaceGeneratorDiagnosticsAnalyzer

The changes look clean and consistent with the established pattern from LibraryImportGenerator. The code is well-structured, thread-safe (using ConcurrentDictionary for caching), and maintains the same diagnostic behavior as before.

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.

2 participants