Draft: Better FastString API, Less unpackFS
While working on #22426 (closed) I noticed a lot of code uses unpackFS
only to call some function from the List api and then repack the FastString. A lot of the List API now exists for ShortByteString
so this MR:
- Adds a bunch of
Data.List
-esque functions to FastString. The idea is that future contributors won't need to unpack if we provide the proper API. - Removes or replaces a lot of calls to
unpackFS
in the compiler. Some of these are perfectly sane, such as lazily reading the first character of a FastString, others are pathological. The pathological are the ones I've sought to replace. - Adds a test case of
unsnocFS
since the code is pretty low level and could blow up depending on the payload of the FastString. Ideally we would usequickcheck
for this because its a great property but c'est la vie.
I've tried to find most of the pathological cases but there are more that exist (looking at you StgToCmm.InfoTableProv
). There is a lot of low hanging fruit to be had here.