Skip to content

`Bytes` and `mkBytes` needs to be reconsidered

Ryan alerted me to the dubious nature of Bytes and BytesPrimL in TemplateHaskell.

Bytes contains a ForeignPtr. If someone makes this ForeignPtr in another package then when the user tries to run the splice in their program, surely they will dereference this pointer and it will point to nothing?

The intention behind the API is that the ForeignPtr is created in the same splice (on the host) as the Bytes value but this is not enforced in anyway.

To do this, probably a new effect should be added to Q rather than this stuff with directly manipulating a ForeignPtr.

It also has to be considered how to make Bytes work with Lift. The current instance is wrong for the same reason.

https://github.com/mgsloan/th-orphans/blob/709ed88ffd21e9d1ca97b36fcf0c992acbfe871a/src/Language/Haskell/TH/Instances.hs#L532-L541

Edited by Matthew Pickering
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information