Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,391
    • Issues 4,391
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 376
    • Merge Requests 376
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9719

Closed
Open
Opened Oct 24, 2014 by Herbert Valerio Riedel@hvr🕺Maintainer

Improve `mkInteger` interface

mkInteger is the current operation provided by the Integer libraries to construct (large) integer values. The current type-signature is

mkInteger :: Bool   -- sign-bit
          -> [Int]  -- absolute value in 31 bit chunks, least significant first
          -> Integer

A somewhat pathological example of why this representation is not so nice is the following simple CAF

c :: Integer
c = 0xf000000000000000

that (this is for a 64bit arch!) gets compiled into the following STG:

==================== STG syntax: ====================
sat_sJQ :: GHC.Types.Int
[LclId, Str=DmdType] =
    NO_CCS GHC.Types.I#! [3];
sat_sJR :: [GHC.Types.Int]
[LclId, Str=DmdType] =
    NO_CCS :! [sat_sJQ GHC.Types.[]];
sat_sJP :: GHC.Types.Int
[LclId, Str=DmdType] =
    NO_CCS GHC.Types.I#! [1610612736];
sat_sJS :: [GHC.Types.Int]
[LclId, Str=DmdType] =
    NO_CCS :! [sat_sJP sat_sJR];
sat_sJO :: GHC.Types.Int
[LclId, Str=DmdType] =
    NO_CCS GHC.Types.I#! [0];
sat_sJT :: [GHC.Types.Int]
[LclId, Str=DmdType] =
    NO_CCS :! [sat_sJO sat_sJS];
Foo.c :: GHC.Integer.Type.Integer
[GblId, Str=DmdType] =
    \u srt:SRT:[0Y :-> GHC.Integer.Type.mkInteger, sJT :-> sat_sJT] []
        GHC.Integer.Type.mkInteger GHC.Types.True sat_sJT;

Moreover, determining how much space to allocate for the resulting Integer is a bit work as it for one, you need to traverse the list twice, and then you can't simply derive the exact allocation amount by the list-length alone due to the odd 31-bit chunks.

Instead a more "natural" mkInteger would be desirable, possibly in the style of unpackCString#, in terms of a packed/unboxed vector of machine-word-sized chunks. A better mkInteger could then take a ByteArray# or a Addr# + length instead, e.g.

mkInteger :: Int#    -- signum(n) = sign of encoded Integer 
                     -- abs(n)    = number of machine-word sized chunks
          -> Addr#   -- pointer to start of machine-word sized chunks, 
                     -- least-significant chunk first
          -> Integer
Edited Mar 09, 2019 by Herbert Valerio Riedel
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#9719