[GHC] #7933: JavaScript Cmm backend

GHC cvs-ghc at haskell.org
Mon May 27 11:34:17 CEST 2013


#7933: JavaScript Cmm backend
---------------------------------+------------------------------------------
    Reporter:  bosu              |       Owner:                  
        Type:  feature request   |      Status:  patch           
    Priority:  normal            |   Milestone:                  
   Component:  Compiler          |     Version:  7.6.3           
    Keywords:                    |          Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown    
  Difficulty:  Unknown           |    Testcase:                  
   Blockedby:                    |    Blocking:                  
     Related:                    |  
---------------------------------+------------------------------------------
Changes (by simonpj):

  * difficulty:  => Unknown


Old description:

> I'd like to RFC on the attached patch implementing JavaScript Cmm backend
> for GHC.
>
> It adds -fjavascript compilation option. Calling ghc -fjavascript
> produces JS in the output file.
> Otherwise the ghc binary should be fully functional as a native compiler.
> Thus -fjavascript is
> similar to -fllvm in spirit.
>
> The patch adds HscJavaScript constructor to HscTarget. It is used to
> dispatch code output to
> the new JsCodeGen module.
>
> Generated JavaScript code relies on the built-in JS garbage collection.
> JsTransforms module
> disables GHC Hp and Sp overflow checks.
>
> As JavaScript has no pointers, we emulate them using JS closures
> containing arrays and indices.
> To distinguish between pointers and scalars we run Hoopl heuristics in
> PointerMarker module.
>
> As in native world, the generated JS object files are to be linked. In
> order to do this, there is
> another project, tentatively called Josh[1]. Josh is regular cabalized
> Haskell binary which links
> JS object files using function maps provided by GHC.
>
> The JavaScript RTS has rts/*.cmm compiled to JavaScript almost as is. In
> addition there is a
> handful of handwritten JS code residing in Josh distribution[2].
>
> ghc-prim[3], integer-gmp[4] and base[5] are compiled with small changes.
> Those changes seem to
> be orthogonal to the GHC patch.
>
> For bootstrap process please see Josh README at github. Josh also
> includes several tests which
> work on 32-bit Debian Wheezy.
>
> Generated code is in order of 2 MB uncompressed and un-minified. Most of
> it is in RTS. It
> compresses very well though (to 150Kb approx). Plenty of low-hanging
> fruit optimizations are
> possible.
>
> There are plenty caveats to the current patch. It works on 32 bits only.
> Math is fishy and
> Integer support is nonexistant. Lots of tests should be imported from
> GHC, GHCJS, Fay.
> No Handle based IO works at the moment. No performance tests were done.
>
> Despite its shortcomings, the patch is fairly non-invasive, IMHO. It
> should be noted, that the
> same approach could work for other GC based platforms (e.g. Java, C#).
>
> I'd like to continue working towards merging the patch into GHC, if
> possible.
> Could GHC committers provide any guidance of what should be done in order
> to merge it?
>
> [1] https://github.com/bosu/josh
> [2] https://github.com/bosu/josh/blob/master/etc/ptr.js
> [3] https://github.com/bosu/ghc-prim
> [4] https://github.com/bosu/integer-gmp
> [5] https://github.com/bosu/base

New description:

 I'd like to RFC on the attached patch implementing !JavaScript Cmm backend
 for GHC.

 It adds `-fjavascript` compilation option. Calling `ghc -fjavascript`
 produces JS in the output file.
 Otherwise the ghc binary should be fully functional as a native compiler.
 Thus `-fjavascript` is
 similar to `-fllvm` in spirit.

 The patch adds `HscJavaScript` constructor to `HscTarget`. It is used to
 dispatch code output to
 the new `JsCodeGen` module.

 Generated !JavaScript code relies on the built-in JS garbage collection.
 `JsTransforms` module
 disables GHC Hp and Sp overflow checks.

 As !JavaScript has no pointers, we emulate them using JS closures
 containing arrays and indices.
 To distinguish between pointers and scalars we run Hoopl heuristics in
 `PointerMarker` module.

 As in native world, the generated JS object files are to be linked. In
 order to do this, there is
 another project, tentatively called Josh[1]. Josh is regular cabalized
 Haskell binary which links
 JS object files using function maps provided by GHC.

 The !JavaScript RTS has `rts/*.cmm` compiled to !JavaScript almost as is.
 In addition there is a
 handful of handwritten JS code residing in Josh distribution[2].

 ghc-prim[3], integer-gmp[4] and base[5] are compiled with small changes.
 Those changes seem to
 be orthogonal to the GHC patch.

 For bootstrap process please see Josh README at github. Josh also includes
 several tests which
 work on 32-bit Debian Wheezy.

 Generated code is in order of 2 MB uncompressed and un-minified. Most of
 it is in RTS. It
 compresses very well though (to 150Kb approx). Plenty of low-hanging fruit
 optimizations are
 possible.

 There are plenty caveats to the current patch.
  * It works on 32 bits only. Math is fishy and Integer support is
 nonexistant.
  * Lots of tests should be imported from GHC, GHCJS, Fay.
  * No Handle based IO works at the moment.
  * No performance tests were done.

 Despite its shortcomings, the patch is fairly non-invasive, IMHO. It
 should be noted, that the
 same approach could work for other GC based platforms (e.g. Java, C#).

 I'd like to continue working towards merging the patch into GHC, if
 possible.
 Could GHC committers provide any guidance of what should be done in order
 to merge it?

  * [1] https://github.com/bosu/josh
  * [2] https://github.com/bosu/josh/blob/master/etc/ptr.js
  * [3] https://github.com/bosu/ghc-prim
  * [4] https://github.com/bosu/integer-gmp
  * [5] https://github.com/bosu/base

--

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



More information about the ghc-tickets mailing list