Skip to content

[6.4🍒][SwiftWarningControl] Honor #if directives in @diagnose attributes#3358

Merged
artemcm merged 2 commits into
swiftlang:release/6.4.xfrom
artemcm:64-DiagnoseIfConfigSupport
Jun 8, 2026
Merged

[6.4🍒][SwiftWarningControl] Honor #if directives in @diagnose attributes#3358
artemcm merged 2 commits into
swiftlang:release/6.4.xfrom
artemcm:64-DiagnoseIfConfigSupport

Conversation

@artemcm

@artemcm artemcm commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick of #3330

  • Explanation: @diagnose attributes wrapped in an #if directives within an attribute list were silently dropped because WithAttributesSyntax.allWarningGroupControls only matched the .attribute case, and WarningControlRegionVisitor walked the raw parsed syntax with no build-configuration awareness.
    This change plumbs ConfiguredRegions through warningGroupControlRegionTree(...) and SyntaxProtocol.warningGroupControl(for:...). The attribute list extraction now descends into IfConfigDecl elements via ConfiguredRegions.activeClause and recurses through nested #ifs. WarningControlRegionVisitor now subclasses ActiveSyntaxAnyVisitor so whole-decl #if clauses contribute regions only when active.
    For the time being, to ease transition with the compiler client code, the existing overloads without a ConfiguredRegions parameter are kept and marked deprecated, they forward to the new entry points using a new public ConfiguredRegions.empty constant, which matches today's behavior of dropping all #if-wrapped attributes.

  • Scope: Affects uses of @diagnose attribute which are contained inside a compilation conditional (#if)

  • Issue: rdar://176454319

  • Original PR: Cherry-pick of [SwiftWarningControl] Honor #if directives in @diagnose attributes #3330

  • Risk: Low, this addition uses the compiler's and this library's proven existing infrastructure to restrict cases where the @diagnose is applied.

  • Testing: Extensive tests verifying new functionality added to the test suite.

  • Reviewers: @rintaro, @DougGregor, @hamishknight

artemcm added 2 commits June 5, 2026 13:04
`@diagnose` attributes wrapped in an `#if` directive within an attribute list were silently dropped because `WithAttributesSyntax.allWarningGroupControls` only matched the `.attribute` case of `AttributeListSyntax.Element`, and `WarningControlRegionVisitor` walked the raw parsed syntax with no build-configuration awareness.

This change plumbs `ConfiguredRegions` through `warningGroupControlRegionTree(...)` and `SyntaxProtocol.warningGroupControl(for:...)`. The attribute-list extraction now descends into `IfConfigDecl` elements via `ConfiguredRegions.activeClause` and recurses through nested `#if`s. `WarningControlRegionVisitor` now subclasses `ActiveSyntaxAnyVisitor` so whole-decl `#if` clauses contribute regions only when active.

For the time being, to ease transition with the compiler client code, the existing overloads without a `ConfiguredRegions` parameter are kept and marked deprecated; they forward to the new entry points using a new public `ConfiguredRegions.empty` constant, which matches today's behavior of dropping all `#if`-wrapped attributes.

Resolves rdar://176454319
@artemcm artemcm requested a review from a team as a code owner June 5, 2026 12:08
@artemcm

artemcm commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@artemcm

artemcm commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@artemcm artemcm merged commit e6a6c8c into swiftlang:release/6.4.x Jun 8, 2026
128 of 143 checks passed
@artemcm artemcm deleted the 64-DiagnoseIfConfigSupport branch June 8, 2026 14:46
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