Description
Motivation
The abstract filepath proposal strives to improve filepath handling in Haskell. The original proposal is written down in the GHC wiki and suggested implementing this in base.
Since this would break a lot of real world code, we (CLC and filepath maintainers) decided to implement this in "user-space", as in: only in filepath
(a core library shipped with GHC). That means base will not use these new filepath types for the foreseeable future, but other core-libraries can.
The main benefits compared to type FilePath = String
are:
- it is more efficient and avoids memory fragmentation (uses unpinned 'ShortByteString' under the hood)
- it is more type-safe (newtype over 'ShortByteString')
- avoids round-tripping issues by not converting to String (which is not total and loses the encoding)
- abstracts over unix and windows while keeping the original bytes
Previous discussions
- https://discourse.haskell.org/t/reviving-the-abstract-filepath-proposal-afpp-in-user-space/2344
- https://mail.haskell.org/pipermail/libraries/2021-August/031427.html
- https://groups.google.com/g/haskell-core-libraries/c/WzapcSvvfQM/m/oDhGbf9wCwAJ?pli=1
Previous work
- extending bytestring API wrt
ShortByteString
: Mergeshortbytestring
package back intobytestring
wrt #444 haskell/bytestring#471 - AFPP merged into filepath: https://gitlab.haskell.org/haskell/filepath/-/merge_requests/103
Current state
- a release candidate is available: https://hackage.haskell.org/package/filepath-2.0.0.3/candidate
- extensive test suite: https://gitlab.haskell.org/haskell/filepath/-/tree/master/tests
- benchmarks: https://gitlab.haskell.org/haskell/filepath/-/tree/master/bench
- memory fragmentation stats: https://github.com/hasufell/filepath-debug/blob/master/result.txt
- a companion library that allows file reading/writing is available here: https://github.com/hasufell/file-io
- pending Win32 PR: Add WindwowsString/WindowsFilePath support wrt AFPP haskell/win32#198
- pending unix PR: Add PosixFilePath and friends support (for AFPP) haskell/unix#202
- GHC issue that needs to be solved: https://gitlab.haskell.org/ghc/ghc/-/issues/21738
The code is ready for release, PRs 3. and 4. can be merged in a timely manner (those are the minimum requirements to be able to use it).
Next steps
The idea is to get this release into GHC 9.4 or 9.6 (@Bodigrim I actually forgot which one). Users on older GHC will however be able to upgrade to the newer filepath anyway, because it's not tied to base.
After that, we need to market this new API and request core libraries maintainers to support AFPP (either as additional API or as the main API).
Some dicussions and PRs:
- Add AFPP support haskell/directory#136 (has gone stale)
- Support
AbstractFilePath
haskell/directory#138 - Support
OsString
haskell/process#252 - AbstractFilePath support kowainik/relude#401
- Support
AbstractFilePath
commercialhaskell/path#189
This isn't a formal tech proposal, since the new API has been merged and will be part of the next filepath release. However, migrating the ecosystem can only be a joint effort. I'd imagine the next packages that need adoption are directory and process at least. I can't do all these migrations on my own, unless I intend to burn out.
I'm not sure what exactly I'm asking, but I talked with @david-christiansen during ZuriHac that this needs wider support. So I'm dropping this thread here.
I intend to write a blog post after the release that summarizes the work done, outlines how to use the new API and suggests migration strategies.