Hassan Al-Awwadi pushed to branch wip/haanss/depdir at Glasgow Haskell Compiler / GHC
Commits:
-
b8746ad6
by Hassan Al-Awwadi at 2025-07-09T16:05:24+02:00
-
1bbd9943
by Hassan Al-Awwadi at 2025-07-09T16:20:23+02:00
-
d12c1e73
by Hassan Al-Awwadi at 2025-07-09T17:00:04+02:00
9 changed files:
- compiler/GHC/Tc/Gen/Splice.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs
- libraries/ghci/GHCi/Message.hs
- libraries/template-haskell/Language/Haskell/TH/Syntax.hs
- testsuite/tests/interface-stability/template-haskell-exports.stdout
- testsuite/tests/th/Makefile
- testsuite/tests/th/TH_Depends_Dir.hs
- testsuite/tests/th/TH_Depends_Dir.stdout
- testsuite/tests/th/TH_Depends_External_Dir.hs โ testsuite/tests/th/TH_Depends_Dir_External.hs
Changes:
| ... | ... | @@ -169,7 +169,7 @@ import GHC.Parser.HaddockLex (lexHsDoc) |
| 169 | 169 | import GHC.Parser (parseIdentifier)
|
| 170 | 170 | import GHC.Rename.Doc (rnHsDoc)
|
| 171 | 171 | |
| 172 | - |
|
| 172 | +import System.Directory(listDirectory)
|
|
| 173 | 173 | |
| 174 | 174 | {-
|
| 175 | 175 | Note [Template Haskell state diagram]
|
| ... | ... | @@ -1524,6 +1524,13 @@ instance TH.Quasi TcM where |
| 1524 | 1524 | ref <- fmap tcg_dependent_dirs getGblEnv
|
| 1525 | 1525 | dep_dirs <- readTcRef ref
|
| 1526 | 1526 | writeTcRef ref (dp:dep_dirs)
|
| 1527 | + -- listDirectory does not return an absolute path, so
|
|
| 1528 | + -- we need to prepend the directory path to make the
|
|
| 1529 | + -- the contents absolute.
|
|
| 1530 | + contents <- liftIO $ listDirectory dp
|
|
| 1531 | + let path_prefix = dp ++ "\\"
|
|
| 1532 | + let abs_contents = map (path_prefix ++) contents
|
|
| 1533 | + return abs_contents
|
|
| 1527 | 1534 | |
| 1528 | 1535 | qAddTempFile suffix = do
|
| 1529 | 1536 | dflags <- getDynFlags
|
| ... | ... | @@ -136,7 +136,7 @@ class (MonadIO m, MonadFail m) => Quasi m where |
| 136 | 136 | qAddDependentFile :: FilePath -> m ()
|
| 137 | 137 | |
| 138 | 138 | -- | See 'addDependentDirectory'.
|
| 139 | - qAddDependentDirectory :: FilePath -> m ()
|
|
| 139 | + qAddDependentDirectory :: FilePath -> m [FilePath]
|
|
| 140 | 140 | |
| 141 | 141 | -- | See 'addTempFile'.
|
| 142 | 142 | qAddTempFile :: String -> m FilePath
|
| ... | ... | @@ -836,9 +836,26 @@ getPackageRoot = Q qGetPackageRoot |
| 836 | 836 | --
|
| 837 | 837 | -- * ghc -M does not know about these dependencies - it does not execute TH.
|
| 838 | 838 | --
|
| 839 | --- * The dependency is shallow, just a hash of its direct contents
|
|
| 840 | -addDependentDirectory :: FilePath -> Q ()
|
|
| 841 | -addDependentDirectory dp = Q (qAddDependentDirectory dp)
|
|
| 839 | +-- * The dependency is shallow, just a hash of its direct contents. It returns
|
|
| 840 | +-- a list of the contents (absolute paths), files and subdirectories both, so
|
|
| 841 | +-- you can manually depend on (a subset of) those, if you wish.
|
|
| 842 | +addDependentDirectory :: FilePath -> Q [FilePath]
|
|
| 843 | +addDependentDirectory dp = Q (qAddDependentDirectory dp)
|
|
| 844 | + |
|
| 845 | +-- | Record external directories that runIO is using (dependent upon).
|
|
| 846 | +-- The compiler can then recognize that it should re-compile the Haskell file
|
|
| 847 | +-- when a directory changes.
|
|
| 848 | +--
|
|
| 849 | +-- Expects an absolute directory path.
|
|
| 850 | +--
|
|
| 851 | +-- Notes:
|
|
| 852 | +--
|
|
| 853 | +-- * ghc -M does not know about these dependencies - it does not execute TH.
|
|
| 854 | +--
|
|
| 855 | +-- * The dependency is shallow, just a hash of its direct contents.
|
|
| 856 | +-- See 'addDependentDirectory' for a version that returns the contents.
|
|
| 857 | +addDependentDirectory_ :: FilePath -> Q ()
|
|
| 858 | +addDependentDirectory_ dp = addDependentDirectory dp >> pure ()
|
|
| 842 | 859 | |
| 843 | 860 | -- | Record external files that runIO is using (dependent upon).
|
| 844 | 861 | -- The compiler can then recognize that it should re-compile the Haskell file
|
| ... | ... | @@ -291,7 +291,7 @@ data THMessage a where |
| 291 | 291 | |
| 292 | 292 | GetPackageRoot :: THMessage (THResult FilePath)
|
| 293 | 293 | AddDependentFile :: FilePath -> THMessage (THResult ())
|
| 294 | - AddDependentDirectory :: FilePath -> THMessage (THResult ())
|
|
| 294 | + AddDependentDirectory :: FilePath -> THMessage (THResult [FilePath])
|
|
| 295 | 295 | AddTempFile :: String -> THMessage (THResult FilePath)
|
| 296 | 296 | AddModFinalizer :: RemoteRef (TH.Q ()) -> THMessage (THResult ())
|
| 297 | 297 | AddCorePlugin :: String -> THMessage (THResult ())
|
| ... | ... | @@ -33,6 +33,7 @@ module Language.Haskell.TH.Syntax ( |
| 33 | 33 | addCorePlugin,
|
| 34 | 34 | addDependentFile,
|
| 35 | 35 | addDependentDirectory,
|
| 36 | + addDependentDirectory_,
|
|
| 36 | 37 | addForeignFile,
|
| 37 | 38 | addForeignFilePath,
|
| 38 | 39 | addForeignSource,
|
| ... | ... | @@ -1715,7 +1715,7 @@ module Language.Haskell.TH.Syntax where |
| 1715 | 1715 | qRunIO :: forall a. GHC.Internal.Types.IO a -> m a
|
| 1716 | 1716 | qGetPackageRoot :: m GHC.Internal.IO.FilePath
|
| 1717 | 1717 | qAddDependentFile :: GHC.Internal.IO.FilePath -> m ()
|
| 1718 | - qAddDependentDirectory :: GHC.Internal.IO.FilePath -> m ()
|
|
| 1718 | + qAddDependentDirectory :: GHC.Internal.IO.FilePath -> m [GHC.Internal.IO.FilePath]
|
|
| 1719 | 1719 | qAddTempFile :: GHC.Internal.Base.String -> m GHC.Internal.IO.FilePath
|
| 1720 | 1720 | qAddTopDecls :: [Dec] -> m ()
|
| 1721 | 1721 | qAddForeignFilePath :: ForeignSrcLang -> GHC.Internal.Base.String -> m ()
|
| ... | ... | @@ -1780,7 +1780,8 @@ module Language.Haskell.TH.Syntax where |
| 1780 | 1780 | type VarStrictType :: *
|
| 1781 | 1781 | type VarStrictType = VarBangType
|
| 1782 | 1782 | addCorePlugin :: GHC.Internal.Base.String -> Q ()
|
| 1783 | - addDependentDirectory :: GHC.Internal.IO.FilePath -> Q ()
|
|
| 1783 | + addDependentDirectory :: GHC.Internal.IO.FilePath -> Q [GHC.Internal.IO.FilePath]
|
|
| 1784 | + addDependentDirectory_ :: GHC.Internal.IO.FilePath -> Q ()
|
|
| 1784 | 1785 | addDependentFile :: GHC.Internal.IO.FilePath -> Q ()
|
| 1785 | 1786 | addForeignFile :: ForeignSrcLang -> GHC.Internal.Base.String -> Q ()
|
| 1786 | 1787 | addForeignFilePath :: ForeignSrcLang -> GHC.Internal.IO.FilePath -> Q ()
|
| ... | ... | @@ -46,9 +46,9 @@ TH_Depends: |
| 46 | 46 | .PHONY: TH_Depends_Dir
|
| 47 | 47 | TH_Depends_Dir:
|
| 48 | 48 | rm -rf TH_Depends_external
|
| 49 | - $(RM) TH_Depends TH_Depends.exe
|
|
| 50 | - $(RM) TH_Depends.o TH_Depends.hi
|
|
| 51 | - $(RM) TH_Depends_External.o TH_Depends_External.hi
|
|
| 49 | + $(RM) TH_Depends_Dir TH_Depends_Dir.exe
|
|
| 50 | + $(RM) TH_Depends_Dir.o TH_Depends_Dir.hi
|
|
| 51 | + $(RM) TH_Depends_Dir_External.o TH_Depends_Dir_External.hi
|
|
| 52 | 52 | |
| 53 | 53 | mkdir TH_Depends_external
|
| 54 | 54 | '$(TEST_HC)' $(TEST_HC_OPTS) $(ghcThWayFlags) --make -v0 TH_Depends_Dir
|
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | |
| 4 | 4 | module Main where
|
| 5 | 5 | |
| 6 | -import TH_Depends_External (checkDirectoryContent)
|
|
| 6 | +import TH_Depends_Dir_External (checkDirectoryContent)
|
|
| 7 | 7 | |
| 8 | 8 | main :: IO ()
|
| 9 | -main = putStrLn $checkDirectoryContent |
|
| 9 | +main = putStrLn $checkDirectoryContent |
|
| \ No newline at end of file |
| 1 | 1 | no files?
|
| 2 | - |
|
| 3 | 2 | yes files! |
| \ No newline at end of file |
| 1 | 1 | |
| 2 | -module TH_Depends_External where
|
|
| 2 | +module TH_Depends_Dir_External where
|
|
| 3 | 3 | |
| 4 | 4 | import Language.Haskell.TH.Syntax
|
| 5 | 5 | import Language.Haskell.TH.Lib
|
| 6 | 6 | import System.Directory (listDirectory)
|
| 7 | -import Control.Monad.IO.Class (liftIO)
|
|
| 8 | 7 | |
| 9 | 8 | checkDirectoryContent :: Q Exp
|
| 10 | 9 | checkDirectoryContent = do
|
| 11 | - let externalDependency = "TH_Depends_external"
|
|
| 12 | - qAddDependentDirectory externalDependency
|
|
| 13 | - files <- liftIO $ listDirectory externalDependency
|
|
| 14 | - |
|
| 15 | - let s = case files
|
|
| 16 | - [] -> "no files?"
|
|
| 17 | - _ -> "yes files!"
|
|
| 10 | + qAddDependentDirectory "TH_Depends_external"
|
|
| 11 | + l <- qRunIO $ listDirectory "TH_Depends_external"
|
|
| 12 | + let s = case l of
|
|
| 13 | + [] -> "no files?"
|
|
| 14 | + _ -> "yes files!"
|
|
| 18 | 15 | stringE s |
| \ No newline at end of file |