[6.4🍒][SwiftWarningControl] Honor #if directives in @diagnose attributes#3358
Merged
artemcm merged 2 commits intoJun 8, 2026
Merged
Conversation
`@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
…@_spi(ExperimentalLanguageFeatures)`
Contributor
Author
|
@swift-ci test |
tbkka
approved these changes
Jun 5, 2026
Contributor
Author
|
@swift-ci please test |
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.
Cherry-pick of #3330
Explanation:
@diagnoseattributes wrapped in an#ifdirectives within an attribute list were silently dropped becauseWithAttributesSyntax.allWarningGroupControlsonly matched the.attributecase, andWarningControlRegionVisitorwalked the raw parsed syntax with no build-configuration awareness.This change plumbs
ConfiguredRegionsthroughwarningGroupControlRegionTree(...)andSyntaxProtocol.warningGroupControl(for:...). The attribute list extraction now descends intoIfConfigDeclelements viaConfiguredRegions.activeClauseand recurses through nested#ifs.WarningControlRegionVisitornow subclassesActiveSyntaxAnyVisitorso whole-decl#ifclauses contribute regions only when active.For the time being, to ease transition with the compiler client code, the existing overloads without a
ConfiguredRegionsparameter are kept and marked deprecated, they forward to the new entry points using a new publicConfiguredRegions.emptyconstant, which matches today's behavior of dropping all#if-wrapped attributes.Scope: Affects uses of
@diagnoseattribute which are contained inside a compilation conditional (#if)Issue: rdar://176454319
Original PR: Cherry-pick of [SwiftWarningControl] Honor
#ifdirectives in@diagnoseattributes #3330Risk: Low, this addition uses the compiler's and this library's proven existing infrastructure to restrict cases where the
@diagnoseis applied.Testing: Extensive tests verifying new functionality added to the test suite.
Reviewers: @rintaro, @DougGregor, @hamishknight