
Hello devs, I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L...): ``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ``` It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code? Cheers, Cheng

It's a primitive type.
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt....
https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers,
Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module ( https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L... ):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Sorry, maybe I got it wrong. Are you asking if is there any package that
passes ByteArrays via FFI?
On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska
It's a primitive type.
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt.... https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers, Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
wrote: Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module ( https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L... ):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Yes, and specifically, the lifted ByteArray type as described in the
comments, not the unlifted ByteArray# type.
On Fri, Oct 11, 2019 at 4:00 AM Csaba Hruska
Sorry, maybe I got it wrong. Are you asking if is there any package that passes ByteArrays via FFI?
On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska
wrote: It's a primitive type. https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt.... https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers, Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
wrote: Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L...):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Can you do that? I know with the UnliftedFFI you can use ByteArray# and if
you have something like uint8_t*, it will make sure that the pointer lines
up with the payload of the ByteArray#. You could always just wrap it in
Data.Primitive.ByteArray.ByteArray, no? That is to say, I don't think GHC
can do what you're asking.
On Thu, Oct 10, 2019, 4:10 PM Shao, Cheng
Yes, and specifically, the lifted ByteArray type as described in the comments, not the unlifted ByteArray# type.
On Fri, Oct 11, 2019 at 4:00 AM Csaba Hruska
wrote: Sorry, maybe I got it wrong. Are you asking if is there any package that
passes ByteArrays via FFI?
On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska
wrote:
It's a primitive type.
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt....
https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers, Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
wrote: Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L... ):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs
data_con_arg_tys
return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

I just tried this and got an error message: "Unacceptable argument type in
foreign declaration: 'MutableByteArray s' cannot be marshalled in a foreign
call"
I got a similar error message when switching ByteArray# to ByteArray.
On Thu, Oct 10, 2019, 5:28 PM chessai .
Can you do that? I know with the UnliftedFFI you can use ByteArray# and if you have something like uint8_t*, it will make sure that the pointer lines up with the payload of the ByteArray#. You could always just wrap it in Data.Primitive.ByteArray.ByteArray, no? That is to say, I don't think GHC can do what you're asking.
On Thu, Oct 10, 2019, 4:10 PM Shao, Cheng
wrote: Yes, and specifically, the lifted ByteArray type as described in the comments, not the unlifted ByteArray# type.
On Fri, Oct 11, 2019 at 4:00 AM Csaba Hruska
wrote: Sorry, maybe I got it wrong. Are you asking if is there any package
that passes ByteArrays via FFI?
On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska
wrote:
It's a primitive type.
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt....
https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers, Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
wrote: Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (
https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L... ):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs
data_con_arg_tys
return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

I've just manually checked with a `data ByteArray = ByteArray Int Int
ByteArray#` example, indeed GHC doesn't support marshalling it. That
being said, I'm still curious about the meaning of that blob of code
I've just pasted.
On Fri, Oct 11, 2019 at 5:28 AM chessai .
Can you do that? I know with the UnliftedFFI you can use ByteArray# and if you have something like uint8_t*, it will make sure that the pointer lines up with the payload of the ByteArray#. You could always just wrap it in Data.Primitive.ByteArray.ByteArray, no? That is to say, I don't think GHC can do what you're asking.
On Thu, Oct 10, 2019, 4:10 PM Shao, Cheng
wrote: Yes, and specifically, the lifted ByteArray type as described in the comments, not the unlifted ByteArray# type.
On Fri, Oct 11, 2019 at 4:00 AM Csaba Hruska
wrote: Sorry, maybe I got it wrong. Are you asking if is there any package that passes ByteArrays via FFI?
On Thu, Oct 10, 2019 at 8:54 PM Csaba Hruska
wrote: It's a primitive type. https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/prelude/primops.txt.... https://gitlab.haskell.org/ghc/ghc/wikis/commentary/prim-ops
Cheers, Csaba
On Thu, Oct 10, 2019 at 8:16 PM Shao, Cheng
wrote: Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L...):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Doing some archeology they seem to have been removed from ghc/lib/std/PrelArr.lhs in e921b2e307532e0f30eefa88b11a124be592bde4 (1999): data Ix ix => Array ix elt = Array ix ix (Array# elt) -data Ix ix => ByteArray ix = ByteArray ix ix ByteArray# data Ix ix => MutableArray s ix elt = MutableArray ix ix (MutableArray# s elt) -data Ix ix => MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) So it's probably dead code since then. Cheers, Sylvain On 10/10/2019 21:15, Shao, Cheng wrote:
Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L...):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Or better 98668305453ea1158c97c8a2c1a90c108aa3585a (2001): From the commit message: - finally, remove the last vestiges of ByteArray and MutableByteArray from the core libraries. Deprecated implementations will be available in the lang compatibility package. On 11/10/2019 10:32, Sylvain Henry wrote:
But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Doing some archeology they seem to have been removed from ghc/lib/std/PrelArr.lhs in e921b2e307532e0f30eefa88b11a124be592bde4 (1999):
data Ix ix => Array ix elt = Array ix ix (Array# elt) -data Ix ix => ByteArray ix = ByteArray ix ix ByteArray# data Ix ix => MutableArray s ix elt = MutableArray ix ix (MutableArray# s elt) -data Ix ix => MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s)
So it's probably dead code since then.
Cheers, Sylvain
On 10/10/2019 21:15, Shao, Cheng wrote:
Hello devs,
I've been trying to figure out how to pass lifted types as foreign types, then encountered the following code in the `DsCCall` module (https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/deSugar/DsCCall.hs#L...):
``` -- Byte-arrays, both mutable and otherwise; hack warning -- We're looking for values of type ByteArray, MutableByteArray -- data ByteArray ix = ByteArray ix ix ByteArray# -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s) | is_product_type && data_con_arity == 3 && isJust maybe_arg3_tycon && (arg3_tycon == byteArrayPrimTyCon || arg3_tycon == mutableByteArrayPrimTyCon) = do case_bndr <- newSysLocalDs arg_ty vars@[_l_var, _r_var, arr_cts_var] <- newSysLocalsDs data_con_arg_tys return (Var arr_cts_var, \ body -> Case arg case_bndr (exprType body) [(DataAlt data_con,vars,body)] ) ```
It seems we allow a "ByteArray" type as a foreign import argument, if the third field of the datacon is a ByteArray# or MutableByteArray#. But I can't find such a ByteArray type definition in today's common packages. What's the rationale for this piece of code?
Cheers, Cheng _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
participants (4)
-
chessai .
-
Csaba Hruska
-
Shao, Cheng
-
Sylvain Henry