Skip to content

Draft: Better FastString API, Less unpackFS

doyougnu requested to merge doyougnu/ghc:wip/doyougnu/less-unpackFS into master

While working on #22426 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:

  1. 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.
  2. 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.
  3. 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 use quickcheck 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.

Merge request reports