diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-01-26 20:29:48 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-29 04:05:27 -0500 |
commit | ae8379abb8aa1defc86dc60bece70546d42af177 (patch) | |
tree | 7bf89867b75104631822fb1ab68dd4b7253b4875 /docs/users_guide/compare-flags.py | |
parent | 75accd548d245eda3096a1fa92a0f246a396b81f (diff) | |
download | haskell-ae8379abb8aa1defc86dc60bece70546d42af177.tar.gz |
Ppr: compute length of string literals at compile time (#19266)
SDoc string literals created for example with `text "xyz"` are converted
into `PtrString` (`Addr#` + size in bytes) with a rewrite rule to avoid
allocating a String.
Before this patch, the size in bytes was still computed at runtime. For
every literal, we obtained the following pseudo STG:
x :: Addr#
x = "xzy"#
s :: PtrString
s = \u [] case ffi:strlen [x realWorld#] of
(# _, sz #) -> PtrString [x sz]
But since GHC 9.0, we can use `cstringLength#` instead to get:
x :: Addr#
x = "xzy"#
s :: PtrString
s = PtrString! [x 3#]
Literals become statically known constructor applications. Allocations
seem to decrease a little in perf tests (between -0.1% and -0.7% on CI).
Diffstat (limited to 'docs/users_guide/compare-flags.py')
0 files changed, 0 insertions, 0 deletions