Skip to content

Comments

Move diagnostics out of DownlevelLibraryImportGenerator into a separate analyzer#124670

Open
Copilot wants to merge 3 commits intomainfrom
copilot/move-diagnostics-to-analyzer
Open

Move diagnostics out of DownlevelLibraryImportGenerator into a separate analyzer#124670
Copilot wants to merge 3 commits intomainfrom
copilot/move-diagnostics-to-analyzer

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Mirrors what PR #123780 did for LibraryImportGenerator: extracts all diagnostic reporting from DownlevelLibraryImportGenerator into a dedicated DownlevelLibraryImportDiagnosticsAnalyzer, so generators never emit diagnostics directly.

Description

  • New DownlevelLibraryImportDiagnosticsAnalyzer[DiagnosticAnalyzer] that replicates all diagnostic logic previously inline in the generator:

    • Invalid method signature / containing type validation
    • Unsupported marshalling types and configurations
    • LCIDConversion not supported
    • InvalidStringMarshallingConfiguration
    • CannotForwardToDllImport for non-Utf16 StringMarshalling in downlevel forwarder stubs
    • RequiresAllowUnsafeBlocks (once per compilation, only registered when AllowUnsafe is false to avoid unnecessary callback overhead)
    • Exposes GetDiagnosticIfInvalidMethodForGeneration as internal static for use by the generator
  • DownlevelLibraryImportGenerator simplifications:

    • Dropped Diagnostics field from IncrementalStubGenerationContext
    • Pipeline now returns IncrementalValuesProvider<MemberDeclarationSyntax> (no tuple)
    • CalculateStubInformation and GenerateSource use discarding diagnostics bags
    • PrintForwarderStub no longer reports CannotForwardToDllImport; filtered via DownlevelLibraryImportDiagnosticsAnalyzer.GetDiagnosticIfInvalidMethodForGeneration
    • Removed Comparers.cs (tuple comparer no longer needed)
  • Test update: StringMarshallingForwardingNotSupported_ReportsDiagnostic now uses DownlevelLibraryImportDiagnosticsAnalyzer instead of EmptyDiagnosticAnalyzer


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@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
…lyzer

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Move diagnostics from DownlevelLibraryImportGenerator to analyzer Move diagnostics out of DownlevelLibraryImportGenerator into a separate analyzer Feb 20, 2026
Copilot AI requested a review from jkoritzinsky February 20, 2026 20:34
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

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
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 pull request extracts diagnostic reporting from DownlevelLibraryImportGenerator into a dedicated DownlevelLibraryImportDiagnosticsAnalyzer, mirroring the architectural changes made in PR #123780 for LibraryImportGenerator. This separation follows Roslyn team recommendations that generators should focus on code generation while analyzers handle diagnostics.

Changes:

  • Created new DownlevelLibraryImportDiagnosticsAnalyzer that independently reports all diagnostics previously emitted by the generator
  • Simplified DownlevelLibraryImportGenerator to filter invalid methods using the analyzer's validation logic and generate code using discarding diagnostics bags
  • Removed Comparers.cs as it's no longer needed after eliminating tuple return types from the pipeline
  • Updated test to use DownlevelLibraryImportDiagnosticsAnalyzer instead of EmptyDiagnosticAnalyzer

Reviewed changes

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

File Description
DownlevelLibraryImportDiagnosticsAnalyzer.cs New analyzer that reports all diagnostics for LibraryImport methods in downlevel frameworks, including method signature validation, LCIDConversion unsupported, invalid StringMarshalling configurations, and CannotForwardToDllImport errors
DownlevelLibraryImportGenerator.cs Removed diagnostic reporting; simplified to return MemberDeclarationSyntax directly; filters methods via analyzer's GetDiagnosticIfInvalidMethodForGeneration; uses discarding diagnostics bags internally
Comparers.cs Deleted entire file - no longer needed after removing tuple comparisons from pipeline
Diagnostics.cs Updated StringMarshallingForwardingNotSupported_ReportsDiagnostic test to use DownlevelLibraryImportDiagnosticsAnalyzer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants