# UNDF: UNDF-2026-000000079 diff --git a/compiler/GHC/Data/Graph/Ops.hs b/compiler/GHC/Data/Graph/Ops.hs index dc90b9e..16e097a 100644 --- a/compiler/GHC/Data/Graph/Ops.hs +++ b/compiler/GHC/Data/Graph/Ops.hs @@ -571,7 +571,7 @@ scanGraph match graph -- If they don't then throw an error -- validateGraph - :: (Uniquable k, Outputable k, Eq color) + :: (Uniquable k, Outputable k, Uniquable color) => SDoc -- ^ extra debugging info to display on error -> Bool -- ^ whether this graph is supposed to be colored. -> Graph k cls color -- ^ graph to validate @@ -622,7 +622,7 @@ validateGraph doc isColored graph -- | If this node is colored, check that all the nodes which -- conflict with it have different colors. checkNode - :: (Uniquable k, Eq color) + :: (Uniquable k, Uniquable color) => Graph k cls color -> Node k cls color -> Bool -- ^ True if this node is ok @@ -633,8 +633,11 @@ checkNode graph node $ nonDetEltsUniqSet $ nodeConflicts node -- See Note [Unique Determinism and code generation] + -- CWE-407 fix: build a UniqSet of neighbour colors for O(1) lookup. + -- `elem color neighbourColors` is O(deg); UniqSet is O(1) amortized. , neighbourColors <- mapMaybe nodeColor neighbors - , elem color neighbourColors + , let neighbourColorSet = mkUniqSet neighbourColors + , elementOfUniqSet color neighbourColorSet = False | otherwise