Skip to content

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Nov 3, 2025

These links establish group inheritance relationships amongst diagnostic groups. This takes form of a new parameter: subGroupLinks: [DiagnosticGroupIdentifier: [DiagnosticGroupIdentifier]] = [:] on both:

  • SyntaxProtocol.warningGroupBehavior
  • SyntaxProtocol.warningGroupControlRegionTree Where the dictionary key is a super-group and dictionary values are its sub-groups.

Upon encountering a warning group control (@warn), its corresponding region is populated with its identifier and behavior, as well as the same corresponding behavior for each of its sub-groups, direct and transitive.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 3, 2025

@swift-ci test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

How large do you envision subGroupLinks to be? Just thinking if it would be more efficient to take the sub group relationships into account when querying for warning controls instead of when populating the tree. Kind of depends on whether you expect to have more queries or more @warn controls.

@artemcm artemcm force-pushed the WarningControl-GroupLinks branch from a797833 to 5b18fb4 Compare November 5, 2025 18:27
@artemcm
Copy link
Contributor Author

artemcm commented Nov 5, 2025

How large do you envision subGroupLinks to be? Just thinking if it would be more efficient to take the sub group relationships into account when querying for warning controls instead of when populating the tree. Kind of depends on whether you expect to have more queries or more @warn controls.

I considered both options and went with this one to take the relationships into account at tree construction: my main reason for this is that I expect the primary client use-case (such as the compiler in swiftlang/swift#85036) to pay the cost of constructing a tree and then run queries against said tree. I do expect there to be a lot of queries against a constructed tree, and it's tricky to predict how many group relationships we will end up with since that concept is still quite new.

Baking these relationships into the constructed tree does also result in simpler query logic on the client side.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 5, 2025

@swift-ci test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Sorry, some of the comments below I should have already brought up in the last review.

let newNode = WarningControlRegionNode(range: range)
for (diagnosticGroupIdentifier, control) in controls {
newNode.addWarningGroupControl(for: diagnosticGroupIdentifier, control: control)
var groups: [DiagnosticGroupIdentifier] = [diagnosticGroupIdentifier]
Copy link
Member

Choose a reason for hiding this comment

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

What if we have the following sub-groups?

A: B, C
B: C

Then we’d report C twice if you have a warning control for A. When using a Set, we need to think about whether we want to guarantee a deterministic output ordering of the diagnostic groups (which I think we should), so we’d need to sort somewhere. So maybe it would be easier to avoid duplicates in an Array.

Also, since the inheritance tree is user-provided, I think we need to think about cycles somewhere. Either make it the responsibility of DiagnosticGroupInheritanceTree to ensure there are no cycles (and throw if there are), or try and find cycles here. I’d prefer the former option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great catch, thank you.
I added code to keep track of already-added groups for a given control to ensure we don't add duplicates to this array.
I also added a cycle check in the initializer of a DiagnosticGroupInheritanceTree and factored it out into a separate file DiagnosticGroupInheritanceTree.swift. It will throw an error if initialized with a subgroup dictionary which contains cycles.

@artemcm artemcm force-pushed the WarningControl-GroupLinks branch 2 times, most recently from e59be92 to 8feabad Compare November 6, 2025 02:26
…ance

This takes form of a new parameter: `groupInheritanceTree: DiagnosticGroupInheritanceTree? = nil` on both:
- `SyntaxProtocol.warningGroupBehavior`
- `SyntaxProtocol.warningGroupControlRegionTree`
Where `DiagnosticGroupInheritanceTree` is a wrapper for a dictionary where the key is a super-group and values are its sub-groups.

Upon encountering a warning group control (`@warn`), its corresponding region is populated with its identifier and behavior, as well as the same corresponding behavior for each of its sub-groups, direct and transitive.
@artemcm artemcm force-pushed the WarningControl-GroupLinks branch from 8feabad to 00891ac Compare November 6, 2025 02:30
@artemcm
Copy link
Contributor Author

artemcm commented Nov 6, 2025

@swift-ci test

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