Dynamically check `FsPath` invariants

オープン
#73 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
haskell

調査の方向性

まず FsPath の定義と pull request 72 の設計に関する議論を読んでください。提案されている invariant、unsafeFsPathFromList、fsPathFromList API を既存のパスの挙動と比較し、force と assert のトレードオフを検討してください。動的チェックが妥当かどうかについて合意し、検証済みの構築と escape hatch による構築の挙動をオペレーティングシステム間で一貫する形で定義できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

First suggested in https://github.com/input-output-hk/fs-sim/pull/72#issue-2337874221. FsPath has a number of invariants, and we currently rely on the user to satisfy them. It might be nice to check these invariants dynamically, while also providing an escape hatch for users in case they want to skip the check. For example:

newtype FsPath = UnsafeFsPath { fsPathToList :: [Strict.Text] }
  deriving (Eq, Ord, Generic)
  deriving newtype NFData

invariant :: FsPath -> Bool
invariant (UnsafeFsPath xs) = all p xs
 where p x = -- Paths are monotonic
             x /= ".."
          && -- Paths can not have empty directory/file names
             not (any Strict.null xs)
          && -- There are no path separators in individual names
             not (Text.any (`Text.elem` allPathSeparators) x)

allPathSeparators :: Text
allPathSeparators = Text.pack (Posix.pathSeparators ++ Windows.pathSeparators)

unsafeFsPathFromList :: [Strict.Text] -> FsPath
unsafeFsPathFromList xs = assert (invariant fsp) $ fsp
  where fsp = UnsafeFsPath (force xs)

fsPathFromList :: [Strict.Text] -> Maybe FsPath
fsPathFromList xs
  | invariant fsp = Just fsp
  | otherwise     = Nothing
  where fsp = UnsafeFsPath (force xs)

Note two things in the example above:

  • Both unsafeFsPathFromList and fsPathFromList ensure that the resulting FsPath contains no thunks my using force. Maybe we want to assert instead that the FsPath contains no thunks in unsafeFsPathFromList, and have the user ensure that fact.
  • To ensure similar behaviour across OS distributions, invariant checks do not depend on the underlying OS distribution, hence allPathSeparators.

We should also consider whether this design pattern is overkill: in practice, users are probably unlikely to use non-sensible path names

主要言語
Haskell
スター
2
フォーク
6
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

IntersectMBO/fs-sim のほかの issue

IntersectMBO/fs-sim の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。