[Git][ghc/ghc][wip/with-hs-doc-identifiers-determ] determinism: Use a stable sort in WithHsDocIdentifiers binary instance
Matthew Pickering pushed to branch wip/with-hs-doc-identifiers-determ at Glasgow Haskell Compiler / GHC Commits: fa45b63d by Matthew Pickering at 2026-02-04T14:28:34+00:00 determinism: Use a stable sort in WithHsDocIdentifiers binary instance `WithHsDocIdentifiers` is defined as ``` 71 data WithHsDocIdentifiers a pass = WithHsDocIdentifiers 72 { hsDocString :: !a 73 , hsDocIdentifiers :: ![Located (IdP pass)] 74 } ``` This list of names is populated from `rnHsDocIdentifiers`, which calls `lookupGRE`, which calls `lookupOccEnv_AllNameSpaces`, which calls `nonDetEltsUFM` and returns the results in an order depending on uniques. Sorting the list with a stable sort before returning the interface makes the output deterministic and follows the approach taken by other fields in `Docs`. Fixes #26858 - - - - - 4 changed files: - compiler/GHC/Hs/Doc.hs - testsuite/tests/showIface/DocsInHiFile1.stdout - testsuite/tests/showIface/HaddockSpanIssueT24378.stdout - testsuite/tests/showIface/MagicHashInHaddocks.stdout Changes: ===================================== compiler/GHC/Hs/Doc.hs ===================================== @@ -45,6 +45,7 @@ import qualified GHC.Utils.Outputable as O import GHC.Hs.Extension import GHC.Types.Unique.Map import Data.List (sortBy) +import Data.Function import GHC.Hs.DocString @@ -83,7 +84,7 @@ instance Outputable a => Outputable (WithHsDocIdentifiers a pass) where instance Binary a => Binary (WithHsDocIdentifiers a GhcRn) where put_ bh (WithHsDocIdentifiers s ids) = do put_ bh s - put_ bh $ BinLocated <$> ids + put_ bh $ BinLocated <$> (sortBy (stableNameCmp `on` getName) ids) get bh = liftA2 WithHsDocIdentifiers (get bh) (fmap unBinLocated <$> get bh) ===================================== testsuite/tests/showIface/DocsInHiFile1.stdout ===================================== @@ -6,14 +6,14 @@ docs: '<>', ':=:', 'Bool' -} identifiers: + {DocsInHiFile.hs:4:2-3} + GHC.Internal.Base.<> {DocsInHiFile.hs:2:6-9} GHC.Internal.Data.Foldable.elem - {DocsInHiFile.hs:2:6-9} - elem {DocsInHiFile.hs:2:14-18} GHC.Internal.System.IO.print - {DocsInHiFile.hs:4:2-3} - GHC.Internal.Base.<> + {DocsInHiFile.hs:2:6-9} + elem {DocsInHiFile.hs:4:15-18} GHC.Internal.Types.Bool export docs: ===================================== testsuite/tests/showIface/HaddockSpanIssueT24378.stdout ===================================== @@ -6,14 +6,14 @@ docs: '<>', ':=:', 'Bool' -} identifiers: + {HaddockSpanIssueT24378.hs:3:2-3} + GHC.Internal.Base.<> {HaddockSpanIssueT24378.hs:1:6-9} GHC.Internal.Data.Foldable.elem - {HaddockSpanIssueT24378.hs:1:6-9} - elem {HaddockSpanIssueT24378.hs:1:14-18} GHC.Internal.System.IO.print - {HaddockSpanIssueT24378.hs:3:2-3} - GHC.Internal.Base.<> + {HaddockSpanIssueT24378.hs:1:6-9} + elem {HaddockSpanIssueT24378.hs:3:15-18} GHC.Internal.Types.Bool export docs: ===================================== testsuite/tests/showIface/MagicHashInHaddocks.stdout ===================================== @@ -3,10 +3,10 @@ docs: Just text: -- | 'foo#' `Bar##` `*##` identifiers: - {MagicHashInHaddocks.hs:3:7-10} - foo# {MagicHashInHaddocks.hs:3:14-18} Bar## + {MagicHashInHaddocks.hs:3:7-10} + foo# export docs: [] declaration docs: View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fa45b63d896aac6aa3a0e6a84c2771df... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fa45b63d896aac6aa3a0e6a84c2771df... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Matthew Pickering (@mpickering)