Changes between Version 27 and Version 28 of Commentary/PrimOps


Ignore:
Timestamp:
Aug 27, 2013 7:46:24 AM (8 months ago)
Author:
jstolarek
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/PrimOps

    v27 v28  
    55!PrimOps are functions that cannot be implemented in Haskell, and are provided natively by GHC.  For example, adding two {{{Int#}}} values is provided as the !PrimOp {{{+#}}}, and allocating a new mutable array is the !PrimOp {{{newArray#}}}. 
    66 
    7 !PrimOps are made available to Haskell code through the virtual module {{{GHC.Prim.BuiltIn}}}.  This module has no implementation, and its interface never resides on disk: if {{{GHC.Prim.BuiltIn}}} is imported, we use a built-in {{{ModIface}}} value - see {{{ghcPrimIface}}} in [[GhcFile(compiler/iface/LoadIface.lhs)]]. 
     7!PrimOps are made available to Haskell code through the virtual module {{{GHC.Prim}}}.  This module has no implementation, and its interface never resides on disk: if {{{GHC.Prim}}} is imported, we use a built-in {{{ModIface}}} value - see {{{ghcPrimIface}}} in [[GhcFile(compiler/iface/LoadIface.lhs)]]. 
    88 
    99It would also be useful to look at the [wiki:Commentary/Compiler/WiredIn Wired-in and known-key things] wiki page to understand this topic. 
     
    3838   just invokes the compiled ones from {{{GHC.PrimopWrappers}}}. 
    3939 
    40  * {{{libraries/base/GHC/Prim/BuiltIn.hs}}}, a source file containing dummy declarations for 
    41    all the !PrimOps, solely so that Haddock can include documentation for {{{GHC.Prim.BuiltIn}}} 
    42    in its documentation for the {{{base}}} package.  The file {{{GHC/Prim/BuiltIn.hs}}} is never 
     40 * {{{libraries/base/GHC/Prim.hs}}}, a source file containing dummy declarations for 
     41   all the !PrimOps, solely so that Haddock can include documentation for {{{GHC.Prim}}} 
     42   in its documentation for the {{{base}}} package.  The file {{{GHC/Prim.hs}}} is never 
    4343   actually compiled, only processed by Haddock. 
    4444 
     
    8080The future direction is to extend this syntax to allow !PrimOp attributes to be specified. The calling convention for primops and ordinary compiled Haskell functions may be unified in future and at that time it the restriction on using only unlifted types may be lifted. 
    8181 
    82 It has been suggested that we extend this !PrimOp definition and import method to cover all !PrimOps, even inline ones. This would replace the current `primops.txt.pp` system of builtin !PrimOps. The inline !PrimOps would still be defined in the compiler but they would be imported in any module via `foreign import prim` rather than appearing magically to be exported from the `GHC.Prim.BuiltIn` module. Hugs has used a similar system for years (with the syntax `primitive seq :: a -> b -> b`). 
     82It has been suggested that we extend this !PrimOp definition and import method to cover all !PrimOps, even inline ones. This would replace the current `primops.txt.pp` system of builtin !PrimOps. The inline !PrimOps would still be defined in the compiler but they would be imported in any module via `foreign import prim` rather than appearing magically to be exported from the `GHC.Prim` module. Hugs has used a similar system for years (with the syntax `primitive seq :: a -> b -> b`). 
    8383 
    8484== Adding a new !PrimOp == 
     
    144144 
    145145default = nomangle other 
     146