[GHC] #9718: Avoid TidyPgm predicting what CorePrep will do

GHC ghc-devs at haskell.org
Fri Oct 5 17:21:50 UTC 2018


#9718: Avoid TidyPgm predicting what CorePrep will do
-------------------------------------+-------------------------------------
        Reporter:  simonpj           |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.8.3
      Resolution:                    |             Keywords:  CodeGen, CAFs
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by osa1):

 I started working on this. A few notes:

 - We want to be able to change CAFFY-ness and arity information not only
 in
   Core, but also in STG. #15038 happened because CAFFY-ness was changed in
 STG.
   In Phab:D4717 (for #15113) we change CAFs in CoreToStg.

 - I think to update an iface file after STG we could update the old
 `ModIface`
   (used to generate the initial file) and pass it to `hscMaybeWriteIface`
 when
   we're done with transformations (right before starting to generate Cmm).
 So
   the only extra thing we keep in memory would be the `ModIface`.

   Alternatively I think we could implement a `ModIfaceUpdate` type that
   represents changes in `Name`s in an existing interface file. Then
   `updateIface` function would read the iface file, apply the updates to
 the
   in-memory representation, then write it again. This trades performance
 for
   residency (although peak memory may stay the same).

 - `ModIface` is currently not suitable for updates. The field that holds
 iface
   definitions has type `[(Fingerprint,IfaceDecl)]`, which is hard to
 update
   (need to search the entire list to find the `IfaceDecl` for a given
 `Name`.

 - Similarly, id details of a `IfaceDecls` is also hard to update. The
 relevant
   types are:

   {{{
   data IfaceIdInfo
     = NoInfo                      -- When writing interface file without
 -O
     | HasInfo [IfaceInfoItem]     -- Has info, and here it is

   data IfaceInfoItem
     = HsArity         Arity
     | HsStrictness    StrictSig
     | HsInline        InlinePragma
     | HsUnfold        Bool             -- True <=> isStrongLoopBreaker is
 true
                       IfaceUnfolding   -- See Note [Expose recursive
 functions]
     | HsNoCafRefs
     | HsLevity                         -- Present <=> never levity
 polymorphic
   }}}

   So to update caf refs we need to filter the whole list. To update the
 arity we
   need to drop any existing `HsArity` info items and cons a new one.

   Depending on how large these lists are perhaps this isn't as big of a
 problem
   as the previous item though.

 - I'm assuming that `idName` of a top-level STG binder is the `Name` used
 in
   `IfaceDecl` for the declaration, so we don't need to generate a map from
 STG
   binders to `IfaceDecl` names. In my testing I found this to be true, but
 I
   only tried tiny programs so far.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9718#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list