refactor(difc): extract tagSet to deduplicate concurrent map logic from Label and Capabilities - #8780
Merged
Merged
Conversation
Closed
7 tasks
…nt map methods
Extract an unexported tagSet struct in internal/difc/tagset.go that holds
the shared map[Tag]struct{} + sync.RWMutex fields and provides common
concurrent mutation/read methods (add, addAll, remove, removeAll, contains,
getAll, clear, count, isEmpty).
Both Label (labels.go) and Capabilities (capabilities.go) now embed tagSet
and delegate their public methods to it. This eliminates ~25 lines of
duplicated mutex-locking logic and ensures any future concurrency fixes or
logging changes need to be made in only one place.
Closes #8772
Copilot
AI
changed the title
[WIP] Refactor duplicate concurrent tag-set methods in capabilities and labels
refactor(difc): extract tagSet to deduplicate concurrent map logic from Label and Capabilities
Jul 6, 2026
lpcox
marked this pull request as ready for review
July 6, 2026 13:14
This was referenced Jul 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors DIFC tag management by extracting the shared concurrent map[Tag]struct{} + sync.RWMutex logic into a single unexported tagSet type, reducing duplication between Label and Capabilities while preserving existing behavior and debug logging.
Changes:
- Added
internal/difc/tagset.gowith a sharedtagSetimplementation covering common set operations (add,addAll,remove,removeAll,contains,getAll,clear,count,isEmpty). - Updated
internal/difc/capabilities.goto embedtagSetand delegate public methods, keeping existing debug logs around operations. - Updated
internal/difc/labels.goto embedtagSetand delegate the basic set methods, while leaving set-algebra methods (Union,Intersect,Clone) intact and still operating via promoted fields.
Show a summary per file
| File | Description |
|---|---|
| internal/difc/tagset.go | Introduces shared concurrent tag-set implementation used by DIFC label/capabilities types. |
| internal/difc/labels.go | Embeds tagSet and delegates basic operations; set-algebra methods continue using promoted fields/locks. |
| internal/difc/capabilities.go | Embeds tagSet and delegates public API while preserving existing debug logging behavior. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Low
This was referenced Jul 6, 2026
Closed
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.
LabelandCapabilitiesboth independently maintained amap[Tag]struct{}+sync.RWMutexwith five nearly-identical methods (Add,AddAll,Remove,Contains,GetTags/GetAll). Any concurrency fix or logging change had to be applied twice.Changes
New
internal/difc/tagset.go: unexportedtagSetstruct withtags map[Tag]struct{}+sync.RWMutexand shared private methods:add,addAll,remove,removeAll,contains,getAll,clear,count,isEmpty.capabilities.go: embedtagSet, delegate all seven public methods; debug logging preserved around the delegates;syncimport removed.labels.go: embedtagSet, delegateAdd/AddAll/Remove/RemoveAll/Contains/GetTags/IsEmpty;Union,Intersect, andCloneare unchanged — they accessl.tags/l.mudirectly via Go field promotion;syncimport removed.The set-algebra methods (
Union,Intersect) that acquire two locks simultaneously are left untouched; field promotion keeps them working without modification.