diff options
author | Ben Gamari <ben@smart-cactus.org> | 2019-11-19 11:43:30 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-12-02 09:25:00 -0500 |
commit | c7c0e771ad75701edaec7e7d2c987e3ddf4d33e8 (patch) | |
tree | acf34199133f4430cd23cbe83148dac3e1cafb8a /compiler/prelude | |
parent | 3a96a0b6db6a32457ae2f91bb711c2481c767656 (diff) | |
download | haskell-wip/T17424b.tar.gz |
Make BCO# liftedwip/T17424b
In #17424 Simon PJ noted that there is a potentially unsafe occurrence
of unsafeCoerce#, coercing from an unlifted to lifted type. However,
nowhere in the compiler do we assume that a BCO# is not a thunk.
Moreover, in the case of a CAF the result returned by `createBCO` *will*
be a thunk (as noted in [Updatable CAF BCOs]). Consequently it seems
better to rather make BCO# a lifted type and rename it to BCO.
Diffstat (limited to 'compiler/prelude')
-rw-r--r-- | compiler/prelude/TysPrim.hs | 7 | ||||
-rw-r--r-- | compiler/prelude/primops.txt.pp | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/compiler/prelude/TysPrim.hs b/compiler/prelude/TysPrim.hs index 79a30482b0..a023c430fe 100644 --- a/compiler/prelude/TysPrim.hs +++ b/compiler/prelude/TysPrim.hs @@ -239,7 +239,7 @@ tVarPrimTyConName = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPr stablePtrPrimTyConName = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon compactPrimTyConName = mkPrimTc (fsLit "Compact#") compactPrimTyConKey compactPrimTyCon -bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon +bcoPrimTyConName = mkPrimTc (fsLit "BCO") bcoPrimTyConKey bcoPrimTyCon weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon @@ -1052,10 +1052,13 @@ compactPrimTy = mkTyConTy compactPrimTyCon ************************************************************************ -} +-- Unlike most other primitive types, BCO is lifted. This is because in +-- general a BCO may be a thunk for the reasons given in Note [Updatable CAF +-- BCOs] in GHCi.CreateBCO. bcoPrimTy :: Type bcoPrimTy = mkTyConTy bcoPrimTyCon bcoPrimTyCon :: TyCon -bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName UnliftedRep +bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName LiftedRep {- ************************************************************************ diff --git a/compiler/prelude/primops.txt.pp b/compiler/prelude/primops.txt.pp index 076854b4d2..080b7f9b6c 100644 --- a/compiler/prelude/primops.txt.pp +++ b/compiler/prelude/primops.txt.pp @@ -3242,7 +3242,7 @@ section "Bytecode operations" contain a list of instructions and data needed by these instructions.} ------------------------------------------------------------------------ -primtype BCO# +primtype BCO { Primitive bytecode type. } primop AddrToAnyOp "addrToAny#" GenPrimOp @@ -3267,14 +3267,14 @@ primop AnyToAddrOp "anyToAddr#" GenPrimOp code_size = 0 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp - BCO# -> (# a #) + BCO -> (# a #) { Wrap a BCO in a {\tt AP_UPD} thunk which will be updated with the value of the BCO when evaluated. } with out_of_line = True primop NewBCOOp "newBCO#" GenPrimOp - ByteArray# -> ByteArray# -> Array# a -> Int# -> ByteArray# -> State# s -> (# State# s, BCO# #) + ByteArray# -> ByteArray# -> Array# a -> Int# -> ByteArray# -> State# s -> (# State# s, BCO #) { {\tt newBCO\# instrs lits ptrs arity bitmap} creates a new bytecode object. The resulting object encodes a function of the given arity with the instructions encoded in {\tt instrs}, and a static reference table usage bitmap given by |