Skip to content
  • Matthew Craven's avatar
    CorePrep: Rework lowering of BigNat# literals · b56d2761
    Matthew Craven authored and Marge Bot's avatar Marge Bot committed
    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
    b56d2761