Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC Commits: e167d986 by Cheng Shao at 2026-04-24T04:43:56-04:00 compiler: avoid unused temporary `appendFS` operands This patch fixes unused temporary `appendFS` operands in the codebase that are retained in the `FastString` table after concatenation. Rewrite rules are added so that if an operand is `fsLit`/`mkFastString`, the `appendFS` application is rewritten to append the `ShortByteString` operands first. The patch also fixes `sconcat` behavior to align with `mconcat` for the same reason. Fixes #27205. - - - - - b44d4322 by mangoiv at 2026-04-24T04:43:57-04:00 contributing: adjust MR template to be less verbose - MR template only shows text that is relevant for submissiong - MR template was rewritten so it's readable from a user's and reviewer's perspective Resolves #27165 Co-Authored-By: @sheaf - - - - - 2 changed files: - .gitlab/merge_request_templates/Default.md - compiler/GHC/Data/FastString.hs Changes: ===================================== .gitlab/merge_request_templates/Default.md ===================================== @@ -1,43 +1,47 @@ + +<!-- Thank you for your contribution to GHC! -**Please read the checklist below to make sure your contribution fulfills these -expectations. Also please answer the following question in your MR description:** - -**Where is the key part of this patch? That is, what should reviewers look at first?** - -Please take a few moments to address the following points: - - * [ ] if your MR touches `base` (or touches parts of `ghc-internal` used - or re-exported by `base`) more substantially than just amending comments - or documentation, you likely need to raise a - [CLC proposal](https://github.com/haskell/core-libraries-committee#base-package) - before merging it. - * [ ] if your MR may break existing programs (e.g. causes the - compiler to reject programs), please describe the expected breakage and add - the ~"user-facing" label. This will run ghc/head.hackage> to characterise - the effect of your change on Hackage. - * [ ] ensure that your commits are either individually buildable or squashed - * [ ] ensure that your commit messages describe *what they do* - (referring to tickets using `#NNNN` syntax when appropriate) - * [ ] have added source comments describing your change. For larger changes you - likely should add a [Note][notes] and cross-reference it from the relevant - places. - * [ ] add a [testcase to the testsuite][adding test]. - * [ ] updates the users guide if applicable - * [ ] add a changelog entry in `changelog.d/` for user-facing changes (see [changelog guide][changelog]). - If this MR does not need a changelog entry, apply the ~"no-changelog" label. +Please read the checklist below to make sure your contribution fulfills these +expectations. If you have any questions don't hesitate to open your merge request and inquire in a comment. If your patch isn't quite done yet please do add prefix your MR -title with `WIP:`. +title with Draft: + +To make your contribution experience as smooth as possible, also check out +https://gitlab.haskell.org/ghc/ghc/-/wikis/Contributing-a-Patch +--> + +## Changes contained in this patch +<!-- Where is the key part of this patch? That is, what should reviewers look at first? --> + + +## MR Checklist +<!-- Please take a few moments to address the following points: --> + +- [ ] This MR solves the problem described in the following issue: <!-- issue number here (please open a new issue if there isn't one) --> +- [ ] A changelog entry was added in `changelog.d/` for user-facing changes (see [changelog guide][changelog]). + If this MR does not need a changelog entry, the ~"no-changelog" label was applied. +- [ ] This MR does not make any significant changes to `base`, or it has an accompanying [CLC proposal](https://github.com/haskell/core-libraries-committee#base-package). +- [ ] If this MR has the potential to break user programs, the ~"user-facing" label was applied to + test against head.hackage. +- [ ] All commits are either individually buildable or squashed. +- [ ] Commit messages describe *what they do*, referring to tickets using `#NNNNN` syntax. +- [ ] Source comments describing the change were added. For larger changes [notes][notes] and + cross-references from the relevant places were added (as applicable). +- [ ] [Testcases to the testsuite][adding test] were added (as applicable). +- [ ] The users guide was updated (as applicable). +<!-- By default a minimal validation pipeline is run on each merge request, the ~full-ci label can be applied to perform additional validation checks if your MR affects a more unusual configuration. -Once your change is ready please remove the `WIP:` tag and wait for review. If +Once your change is ready please remove the `Draft:` tag and wait for review. If no one has offered a review in a few days then please leave a comment mentioning @triagers and apply the ~"Blocked on Review" label. +--> [notes]: https://gitlab.haskell.org/ghc/ghc/wikis/commentary/coding-style#comments-in... [adding test]: https://gitlab.haskell.org/ghc/ghc/wikis/building/running-tests/adding ===================================== compiler/GHC/Data/FastString.hs ===================================== @@ -139,6 +139,7 @@ import Foreign.C import System.IO import Data.Data import Data.IORef +import qualified Data.List.NonEmpty as NE import Data.Semigroup as Semi import Foreign @@ -232,6 +233,7 @@ instance IsString FastString where instance Semi.Semigroup FastString where (<>) = appendFS + sconcat = concatFS . NE.toList instance Monoid FastString where mempty = nilFS @@ -619,6 +621,42 @@ unpackFS fs = utf8DecodeShortByteString $ fs_sbs fs zEncodeFS :: FastString -> FastZString zEncodeFS fs = fs_zenc fs +-- Sometimes an `appendFS` operand is temporarily constructed, and we +-- should avoid retaining the unused `FastString` operand in the +-- table. The RULES below mitigate the issue by concatenating the +-- `ShortByteString`s instead when an operand is `fsLit` or +-- `mkFastString`, which cover most such `appendFS` use cases. See +-- #27205. + +{-# RULES +"appendFS/fsLit y" forall x y. + appendFS x (fsLit y) = + mkFastStringShortByteString $ + fs_sbs x Semi.<> utf8EncodeShortByteString y + #-} + +{-# RULES +"appendFS/fsLit x" forall x y. + appendFS (fsLit x) y = + mkFastStringShortByteString $ + utf8EncodeShortByteString x Semi.<> fs_sbs y + #-} + +{-# RULES +"appendFS/mkFastString y" forall x y. + appendFS x (mkFastString y) = + mkFastStringShortByteString $ + fs_sbs x Semi.<> utf8EncodeShortByteString y + #-} + +{-# RULES +"appendFS/mkFastString x" forall x y. + appendFS (mkFastString x) y = + mkFastStringShortByteString $ + utf8EncodeShortByteString x Semi.<> fs_sbs y + #-} + +{-# INLINE[1] appendFS #-} appendFS :: FastString -> FastString -> FastString appendFS fs1 fs2 = mkFastStringShortByteString $ (Semi.<>) (fs_sbs fs1) (fs_sbs fs2) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dfc11670c7ea922432bdbb91acd1f17... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dfc11670c7ea922432bdbb91acd1f17... You're receiving this email because of your account on gitlab.haskell.org.