[Git][ghc/ghc][wip/T23942] CorePrep: Rework lowering of BigNat# literals

Matthew Craven (@clyring) gitlab at gitlab.haskell.org
Sun Mar 10 03:59:42 UTC 2024



Matthew Craven pushed to branch wip/T23942 at Glasgow Haskell Compiler / GHC


Commits:
6d8f274b by Matthew Craven at 2024-03-09T22:51:50-05:00
CorePrep: Rework lowering of BigNat# literals

Don't use bigNatFromWord#, because that's terrible:
 * We shouldn't have to traverse a linked list at run-time
   to build a BigNat# literal. That's just silly!
 * The static List object we have to create is much larger
   than the actual BigNat#'s contents, bloating code size.
 * We have to read the corresponding interface file,
   which causes un-tracked implicit dependencies. (#23942)

Instead, encode them into the appropriate platform-dependent
sequence of bytes, and generate code that copies these bytes
at run-time from an Addr# literal into a new ByteArray#.
A ByteArray# literal would be the correct thing to generate,
but these are not yet supported; see also #17747.

Somewhat surprisingly, this change results in a slight
reduction in compiler allocations, averaging around 0.5%
on ghc's compiler performance tests, including when compiling
programs that contain no bignum literals to begin with.
The specific cause of this has not been investigated.

Since this lowering no longer reads the interface file for
GHC.Num.BigNat, the reasoning in Note [Depend on GHC.Num.Integer]
is obsoleted.  But the story of un-tracked built-in dependencies
remains complex, and Note [Tracking dependencies on primitives]
now exists to explain this complexity.

Additionally, many empty imports have been modified to refer to
this new note and comply with its guidance.  Several empty imports
necessary for other reasons have also been given brief explanations.

Metric Decrease:
    MultiLayerModulesTH_OneShot

- - - - -


30 changed files:

- compiler/GHC/Builtin/Names.hs
- compiler/GHC/Builtin/PrimOps.hs-boot
- compiler/GHC/Builtin/Types/Prim.hs
- compiler/GHC/Cmm/Dominators.hs
- compiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Data/Word64Map/Strict.hs
- compiler/GHC/Driver/CmdLine.hs
- compiler/GHC/Driver/Config/CoreToStg/Prep.hs
- compiler/GHC/Driver/Config/Diagnostic.hs
- compiler/GHC/Driver/Errors/Ppr.hs
- compiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs-boot
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Platform.hs
- compiler/GHC/StgToJS/Types.hs
- compiler/GHC/Tc/Errors/Hole/Plugin.hs-boot
- compiler/GHC/Tc/Types/LclEnv.hs-boot
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Types/Id.hs-boot
- compiler/GHC/Types/Var.hs-boot
- compiler/GHC/Utils/Containers/Internal/StrictPair.hs
- compiler/ghc.cabal.in
- libraries/base/src/Data/Functor/Product.hs
- libraries/base/src/Data/Functor/Sum.hs
- libraries/base/src/Data/Kind.hs
- libraries/base/src/GHC/ConsoleHandler.hs
- libraries/base/src/GHC/Constants.hs
- libraries/base/src/GHC/IO/Encoding/CodePage.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6d8f274b8677fcf9519d569875145f9f5434d779

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6d8f274b8677fcf9519d569875145f9f5434d779
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240309/fa56285a/attachment.html>


More information about the ghc-commits mailing list