Simon Jakobi pushed to branch wip/sjakobi/T27296-stable-simpl at Glasgow Haskell Compiler / GHC
Commits:
41be6868 by Simon Jakobi at 2026-06-16T12:31:33+02:00
Compare Core dump sort keys on FastStrings, not Strings
sortCoreBindingsForDump built each binder's sort key with getOccString,
i.e. unpackFS of the OccName -- a fresh String -- used both for the
lexical tie-break and for the '$' derived-binder test. For the anonymous
floats this part of the key is forced for every binder (they all share
the noSrcSpan bucket), so the String was allocated and compared
repeatedly.
Operate on the interned FastString directly instead:
* the lexical tie-break uses LexicalFastString, whose Ord is the
deterministic byte-wise lexicalCompareFS;
* the '$' test is an in-place SBS.elem over the FastString's bytes
('$' is ASCII, so byte membership is exact).
The dump ordering is unchanged.
Co-Authored-By: Claude Opus 4.8
- - - - -
1 changed file:
- compiler/GHC/Core/Ppr.hs
Changes:
=====================================
compiler/GHC/Core/Ppr.hs
=====================================
@@ -29,9 +29,10 @@ import GHC.Prelude
import GHC.Core
import GHC.Core.Stats (CoreStats(..), exprStats)
+import GHC.Data.FastString (LexicalFastString(..), fastStringToShortByteString)
import GHC.Types.Fixity (LexicalFixity(..))
import GHC.Types.Literal( Literal, pprLiteral )
-import GHC.Types.Name( getOccString, getSrcSpan, pprInfixName, pprPrefixName )
+import GHC.Types.Name( getOccFS, getSrcSpan, pprInfixName, pprPrefixName )
import GHC.Types.Var
import GHC.Types.Id
import GHC.Types.Id.Info
@@ -51,6 +52,8 @@ import GHC.Types.SrcLoc ( SrcSpan(..), pprUserRealSpan, srcSpanStartCol
import GHC.Types.Tickish
import Data.List ( sortOn )
+import Data.Char ( ord )
+import qualified Data.ByteString.Short as SBS
{-
************************************************************************
@@ -133,7 +136,7 @@ type DumpSortKey =
, Int -- source-span start line
, Int -- source-span start column
, Int -- dollar-rank: 0 = derived ($w/$s) binder, 1 = its origin
- , String -- the OccName string, a lexical tiebreak
+ , LexicalFastString -- the OccName, compared lexically
, RhsKey -- content-based tiebreak (see 'rhsKey')
)
@@ -154,9 +157,9 @@ sortCoreBindingsForDump = sortOn bindKey . map sortRecMembers
bindKey (Rec []) = panic "sortCoreBindingsForDump: empty Rec"
elemKey :: CoreBndr -> CoreExpr -> DumpSortKey
- elemKey b rhs = (bucket, line, col, dollar_rank, s, rhsKey rhs)
+ elemKey b rhs = (bucket, line, col, dollar_rank, LexicalFastString nm, rhsKey rhs)
where
- s = getOccString b
+ nm = getOccFS b
(bucket, line, col) = case getSrcSpan b of
RealSrcSpan rs _ -> (0, srcSpanStartLine rs, srcSpanStartCol rs)
_ -> (1, 0, 0) -- noSrcSpan: sort last
@@ -165,8 +168,10 @@ sortCoreBindingsForDump = sortOn bindKey . map sortRecMembers
-- bar_$sfoo); rank those before their origin within a shared source span,
-- mirroring GHC's default dependency order (the wrapper calls the worker,
-- so the worker comes first).
- dollar_rank | '$' `elem` s = 0
- | otherwise = 1
+ dollar_rank | dollarByte `SBS.elem` fastStringToShortByteString nm = 0
+ | otherwise = 1
+
+ dollarByte = fromIntegral (ord '$')
-- | A content-based tie-break on a binder's right-hand side: see point 4 of
-- Note [Stable Core dump order].
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/41be6868005524a03887baae612d5593...
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/41be6868005524a03887baae612d5593...
You're receiving this email because of your account on gitlab.haskell.org.