[GHC] #11441: RFC: Inline intermediate languages (Core, STG, Cmm, even StrictCore)

GHC ghc-devs at haskell.org
Sat Jan 16 15:55:02 UTC 2016


#11441: RFC: Inline intermediate languages (Core, STG, Cmm, even StrictCore)
-------------------------------------+-------------------------------------
           Reporter:  Iceland_jack   |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Allow intermediate code inline.

 == Inline ''Core'' ==
 Typeable/WithTypeable:

 > {{{#!hs
 > withTypeable :: TTypeRep a -> (Typeable a => r) -> r
 > }}}
 >
 > Currently, `withTypeable` cannot be written in Haskell, but it is
 straightforward to write in Core. Can we fix this?

 [http://www.seas.upenn.edu/~sweirich/papers/wadlerfest2016.pdf A
 reflection on types] (''2016''):

 > We cannot implement ''withTypeable'' in Haskell source. But we ''can''
 implement it in GHC's statically-typed intermediate language, System FC.
 The definition is simple, roughly like this:
 >
 > {{{#!hs
 > withTypeable tr k = k tr    -- Not quite right
 > }}}
 >
 > Its second argument ''k'' expects a ''Typeable'' dictionary as its value
 argument. But since
 > a ''Typeable'' dictionary is represented by a ''TypeRep'', we can simply
 pass ''tr'' to ''k''.
 > When written in System FC there is a type-safe coercion to move from
 ''TypeRep a'' to ''Typeable a'',
 > but that coercion is erased at runtime. Since the definition can be
 statically type checked,
 > ''withTypeable'' does not form part of the trusted code base.

 == Inline ''Cmm'' ==
 Edkward Kmett writes his own `.cmm`
 [https://github.com/ekmett/concurrent/blob/master/cbits/hashmap.cmm
 hither], [https://github.com/ekmett/concurrent/blob/master/cbits/array.cmm
 yon].

 == Inline ''Strict Core'' ==
 Should [http://research.microsoft.com/en-us/um/people/simonpj/papers
 /strict-core/tacc-hs09.pdf Types are calling conventions] (''2009'') be
 implemented:

 > === '''4.4 The ''`seq`'' function''' ===
 >
 > A nice feature of Strict Core,,ANF,, is that it is possible to give a
 straightforward definition of the primitive ''seq'' function of Haskell:
 > {{{#!hs
 > seq : {a:* -> b:* -> {a} -> {b} -> b}
 >  = { \a:*. \b:*. \x:{a}. \y:{b}. let _:a = x <> in y <> }
 > }}}

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


More information about the ghc-tickets mailing list