Skip to content

Abstract filepath proposal (request for help) #35

Closed
@hasufell

Description

@hasufell

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:

  1. it is more efficient and avoids memory fragmentation (uses unpinned 'ShortByteString' under the hood)
  2. it is more type-safe (newtype over 'ShortByteString')
  3. avoids round-tripping issues by not converting to String (which is not total and loses the encoding)
  4. abstracts over unix and windows while keeping the original bytes

Previous discussions

Previous work

  1. extending bytestring API wrt ShortByteString: Merge shortbytestring package back into bytestring wrt #444 haskell/bytestring#471
  2. AFPP merged into filepath: https://gitlab.haskell.org/haskell/filepath/-/merge_requests/103

Current state

  1. a release candidate is available: https://hackage.haskell.org/package/filepath-2.0.0.3/candidate
  2. a companion library that allows file reading/writing is available here: https://github.com/hasufell/file-io
  3. pending Win32 PR: Add WindwowsString/WindowsFilePath support wrt AFPP haskell/win32#198
  4. pending unix PR: Add PosixFilePath and friends support (for AFPP) haskell/unix#202
  5. 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:

  1. Add AFPP support haskell/directory#136 (has gone stale)
  2. Support AbstractFilePath haskell/directory#138
  3. Support OsString haskell/process#252
  4. AbstractFilePath support kowainik/relude#401
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions