[commit: ghc] wip/nfs-locking: Move decode/encodeModule to Oracles.ModuleFiles. (9c45e4d)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:58:46 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/9c45e4df1b88c2f726c84a651cb45b8e40f5b7c2/ghc

>---------------------------------------------------------------

commit 9c45e4df1b88c2f726c84a651cb45b8e40f5b7c2
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Thu May 5 04:56:09 2016 +0100

    Move decode/encodeModule to Oracles.ModuleFiles.


>---------------------------------------------------------------

9c45e4df1b88c2f726c84a651cb45b8e40f5b7c2
 src/Base.hs                | 18 +-----------------
 src/Oracles/ModuleFiles.hs | 17 ++++++++++++++++-
 src/Rules/Selftest.hs      |  1 +
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/Base.hs b/src/Base.hs
index a26fea1..1fcbae7 100644
--- a/src/Base.hs
+++ b/src/Base.hs
@@ -22,8 +22,7 @@ module Base (
 
     -- * Miscellaneous utilities
     minusOrd, intersectOrd, lookupAll, replaceEq, quote, replaceSeparators,
-    decodeModule, encodeModule, unifyPath, (-/-), versionToInt,
-    matchVersionedFilePath
+    unifyPath, (-/-), versionToInt, matchVersionedFilePath
     ) where
 
 import Control.Applicative
@@ -84,21 +83,6 @@ versionToInt s = major * 1000 + minor * 10 + patch
   where
     [major, minor, patch] = map read . words $ replaceEq '.' ' ' s
 
--- | Given a module name extract the directory and file name, e.g.:
---
--- > decodeModule "Data.Functor.Identity" == ("Data/Functor/", "Identity")
--- > decodeModule "Prelude"               == ("./", "Prelude")
-decodeModule :: String -> (FilePath, String)
-decodeModule = splitFileName . replaceEq '.' '/'
-
--- | Given the directory and file name find the corresponding module name, e.g.:
---
--- > encodeModule "Data/Functor/" "Identity.hs" == "Data.Functor.Identity"
--- > encodeModule "./" "Prelude"                == "Prelude"
--- > uncurry encodeModule (decodeModule name)   == name
-encodeModule :: FilePath -> String -> String
-encodeModule dir file = replaceEq '/' '.' $ dir -/- takeBaseName file
-
 -- | Normalise a path and convert all path separators to @/@, even on Windows.
 unifyPath :: FilePath -> FilePath
 unifyPath = toStandard . normaliseEx
diff --git a/src/Oracles/ModuleFiles.hs b/src/Oracles/ModuleFiles.hs
index 70cf983..652eb9a 100644
--- a/src/Oracles/ModuleFiles.hs
+++ b/src/Oracles/ModuleFiles.hs
@@ -1,6 +1,6 @@
 {-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
 module Oracles.ModuleFiles (
-    findGenerator, haskellSources, moduleFilesOracle
+    decodeModule, encodeModule, findGenerator, haskellSources, moduleFilesOracle
     ) where
 
 import qualified Data.HashMap.Strict as Map
@@ -26,6 +26,21 @@ determineBuilder file = case takeExtension file of
     ".hsc" -> Just Hsc2Hs
     _      -> Nothing
 
+-- | Given a module name extract the directory and file name, e.g.:
+--
+-- > decodeModule "Data.Functor.Identity" == ("Data/Functor/", "Identity")
+-- > decodeModule "Prelude"               == ("./", "Prelude")
+decodeModule :: String -> (FilePath, String)
+decodeModule = splitFileName . replaceEq '.' '/'
+
+-- | Given the directory and file name find the corresponding module name, e.g.:
+--
+-- > encodeModule "Data/Functor/" "Identity.hs" == "Data.Functor.Identity"
+-- > encodeModule "./" "Prelude"                == "Prelude"
+-- > uncurry encodeModule (decodeModule name)   == name
+encodeModule :: FilePath -> String -> String
+encodeModule dir file = replaceEq '/' '.' $ dir -/- takeBaseName file
+
 -- | Find the generator for a given 'Context' and a source file. For example:
 -- findGenerator (Context Stage1 compiler vanilla)
 --               ".build/stage1/compiler/build/Lexer.hs"
diff --git a/src/Rules/Selftest.hs b/src/Rules/Selftest.hs
index f549b0f..8037682 100644
--- a/src/Rules/Selftest.hs
+++ b/src/Rules/Selftest.hs
@@ -6,6 +6,7 @@ import Development.Shake
 import Test.QuickCheck
 
 import Base
+import Oracles.ModuleFiles (decodeModule, encodeModule)
 import Settings.Builders.Ar (chunksOfSize)
 import Way
 



More information about the ghc-commits mailing list