TH: support raw bytes literals (#14741)
authorSylvain Henry <sylvain@haskus.fr>
Fri, 18 Jan 2019 11:30:31 +0000 (12:30 +0100)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Fri, 8 Mar 2019 19:05:10 +0000 (14:05 -0500)
commit224a6b864c6aa0d851fcbf79469e5702b1116dbc
tree888b79e9f177c988d06365d0a218c41878225467
parent5be7ad7861c8d39f60b7101fd8d8e816ff50353a
TH: support raw bytes literals (#14741)

GHC represents String literals as ByteString internally for efficiency
reasons. However, until now it wasn't possible to efficiently create
large string literals with TH (e.g. to embed a file in a binary, cf #14741):
TH code had to unpack the bytes into a [Word8] that GHC then had to re-pack
into a ByteString.

This patch adds the possibility to efficiently create a "string" literal
from raw bytes. We get the following compile times for different sizes
of TH created literals:

|| Size || Before || After  || Gain ||
|| 30K  || 2.307s || 2.299  || 0%   ||
|| 3M   || 3.073s || 2.400s || 21%  ||
|| 30M  || 8.517s || 3.390s || 60%  ||

Ticket #14741 can be fixed if the original code uses this new TH feature.
compiler/basicTypes/Literal.hs
compiler/hsSyn/Convert.hs
libraries/ghci/GHCi/TH/Binary.hs
libraries/template-haskell/Language/Haskell/TH/Lib.hs
libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
libraries/template-haskell/Language/Haskell/TH/Ppr.hs
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
libraries/template-haskell/changelog.md
testsuite/tests/th/T14741.hs [new file with mode: 0644]
testsuite/tests/th/T14741.stdout [new file with mode: 0644]
testsuite/tests/th/all.T