Skip to content

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Oct 21, 2025

This PR contains two changes/commits:

  • Add parsing for an experimental declaration attribute '@warn' for source-level warning group behavior control. This attribute is gated behind an experimental feature SourceWarningControl.

  • Implement support for unified warning group behavior queries per-diagnostic-group:

    • Refactor handling of -Wwarning and -Werror flags, as well as DefaultIgnore diagnostic groups to be captured as a WarningGroupBehaviorRule (as opposed to a prior WarningAsErrorRule) and replace the corresponding diagnostic group ID-indexed bit vectors in DiagnosticEngine with with a dictionary keyed by the diagnostic group ID with values representing behavior specification rules (such as AsError, AsWarning, Ignored).
    • Add the capability to query the SwiftWarningControl SwiftSyntax library for a given warning diagnostic's diagnostic group's emission behavior at the diagnostic's source location, as determined by syntactic @warn controls. (Implemented in ASTGen/WarningGroupBehaviorConfiguration.swift).
    • When emitting a warning belonging to a diagnostic group, the diagnostic engine now supplies the above warning handling rules to the SwiftWarningControl query as global control inputs. This means the same query will take into account both global warning control rules specified on the command-line, as well as source-location-specific containing @warn attribute controls.
      • More-specifically, for a given ExportedSourceFile, the first query of warningGroupBehaviorAtPosition will result in construction of a WarningControlRegionTree data-structure which will be cached in the ExportedSourceFile it belongs to and re-used for future queries.

@artemcm artemcm force-pushed the AddSupportForWarnAttr branch from efeb7d8 to f2090a1 Compare October 21, 2025 15:41
@artemcm artemcm changed the title Add parsing for a declaration attribute '@warn' for source-level warning group behavior control Add support for a declaration attribute '@warn' for source-level warning group behavior control Oct 22, 2025
@artemcm artemcm force-pushed the AddSupportForWarnAttr branch 2 times, most recently from b5ce4d2 to f166258 Compare October 31, 2025 00:32
@artemcm
Copy link
Contributor Author

artemcm commented Oct 31, 2025

@swift-ci test

@artemcm artemcm force-pushed the AddSupportForWarnAttr branch 4 times, most recently from f346cd4 to 213b207 Compare November 1, 2025 01:48
@artemcm artemcm marked this pull request as ready for review November 1, 2025 01:52
@artemcm artemcm force-pushed the AddSupportForWarnAttr branch 2 times, most recently from 09ccd1f to b22b692 Compare November 3, 2025 20:02
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Love this :)


std::optional<StringRef> reasonText = std::nullopt;
if (!reason.getIsEmpty())
reasonText = reason.unbridged();
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to copy this string into the ASTContext?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you.

@artemcm artemcm force-pushed the AddSupportForWarnAttr branch from b22b692 to 693aeae Compare November 7, 2025 22:54
@artemcm
Copy link
Contributor Author

artemcm commented Nov 7, 2025

…nostic

Unified across module-wide configuration flags (`-Wwarning`, `-Werror`, etc.) and syntactic configuration attribute `@warn`.
@artemcm artemcm force-pushed the AddSupportForWarnAttr branch from 693aeae to 72a0e52 Compare November 7, 2025 23:04
@artemcm
Copy link
Contributor Author

artemcm commented Nov 7, 2025

@artemcm artemcm changed the title Add support for a declaration attribute '@warn' for source-level warning group behavior control Add support for a declaration attribute @warn for source-level warning group behavior control Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants