git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Never rebuild the Prelude. Always rebuild temporary modules in PSCI.
38db2c6Phil Freeman
psc-docs/Main.hs+2−1
@@ -20,6 +20,7 @@ import Control.Monad.Writer
20import Control.Arrow (first)
20import Control.Arrow (first)
21import Data.Function (on)
21import Data.Function (on)
22import Data.List
22import Data.List
23+import Data.Maybe (fromMaybe)
23import Data.Version (showVersion)
24import Data.Version (showVersion)
24import qualified Language.PureScript as P
25import qualified Language.PureScript as P
25import qualified Paths_purescript as Paths
26import qualified Paths_purescript as Paths
@@ -30,7 +31,7 @@ import System.IO (stderr)
30
31
31docgen :: Bool -> [FilePath] -> IO ()
32docgen :: Bool -> [FilePath] -> IO ()
32docgen showHierarchy input = do
33docgen showHierarchy input = do
33− e <- P.parseModulesFromFiles <$> mapM (fmap (first Just) . parseFile) (nub input)
34+ e <- P.parseModulesFromFiles (fromMaybe "") <$> mapM (fmap (first Just) . parseFile) (nub input)
34 case e of
35 case e of
35 Left err -> do
36 Left err -> do
36 U.hPutStr stderr $ show err
37 U.hPutStr stderr $ show err
psc-make/Main.hs+4−4
@@ -38,10 +38,10 @@ data InputOptions = InputOptions
38 , ioInputFiles :: [FilePath]
38 , ioInputFiles :: [FilePath]
39 }
39 }
40
40
41−readInput :: InputOptions -> IO [(Maybe FilePath, String)]
41+readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
42readInput InputOptions{..} = do
42readInput InputOptions{..} = do
43− content <- forM ioInputFiles $ \inputFile -> (Just inputFile, ) <$> U.readFile inputFile
43+ content <- forM ioInputFiles $ \inputFile -> (Right inputFile, ) <$> U.readFile inputFile
44− return $ bool ((Nothing, P.prelude) :) id ioNoPrelude content
44+ return $ bool ((Left P.RebuildNever, P.prelude) :) id ioNoPrelude content
45
45
46newtype Make a = Make { unMake :: ErrorT String IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadError String)
46newtype Make a = Make { unMake :: ErrorT String IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadError String)
47
47
@@ -69,7 +69,7 @@ instance P.MonadMake Make where
69
69
70compile :: [FilePath] -> FilePath -> P.Options P.Make -> Bool -> IO ()
70compile :: [FilePath] -> FilePath -> P.Options P.Make -> Bool -> IO ()
71compile input outputDir opts usePrefix = do
71compile input outputDir opts usePrefix = do
72− modules <- P.parseModulesFromFiles <$> readInput (InputOptions (P.optionsNoPrelude opts) input)
72+ modules <- P.parseModulesFromFiles (either (const "") id) <$> readInput (InputOptions (P.optionsNoPrelude opts) input)
73 case modules of
73 case modules of
74 Left err -> do
74 Left err -> do
75 U.print err
75 U.print err
psc/Main.hs+2−1
@@ -20,6 +20,7 @@ import Control.Applicative
20import Control.Monad.Error
20import Control.Monad.Error
21
21
22import Data.Bool (bool)
22import Data.Bool (bool)
23+import Data.Maybe (fromMaybe)
23import Data.Version (showVersion)
24import Data.Version (showVersion)
24
25
25import System.Console.CmdTheLine
26import System.Console.CmdTheLine
@@ -46,7 +47,7 @@ readInput InputOptions{..}
46
47
47compile :: P.Options P.Compile -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> Bool -> IO ()
48compile :: P.Options P.Compile -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> Bool -> IO ()
48compile opts stdin input output externs usePrefix = do
49compile opts stdin input output externs usePrefix = do
49− modules <- P.parseModulesFromFiles <$> readInput (InputOptions (P.optionsNoPrelude opts) stdin input)
50+ modules <- P.parseModulesFromFiles (fromMaybe "") <$> readInput (InputOptions (P.optionsNoPrelude opts) stdin input)
50 case modules of
51 case modules of
51 Left err -> do
52 Left err -> do
52 U.hPutStr stderr $ show err
53 U.hPutStr stderr $ show err
psci/Main.hs+10−10
@@ -66,7 +66,7 @@ import qualified Language.PureScript.Declarations as D
66data PSCiState = PSCiState
66data PSCiState = PSCiState
67 { psciImportedFilenames :: [FilePath]
67 { psciImportedFilenames :: [FilePath]
68 , psciImportedModuleNames :: [P.ModuleName]
68 , psciImportedModuleNames :: [P.ModuleName]
69− , psciLoadedModules :: [(Maybe FilePath, P.Module)]
69+ , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
70 , psciLetBindings :: [P.Expr -> P.Expr]
70 , psciLetBindings :: [P.Expr -> P.Expr]
71 }
71 }
72
72
@@ -87,7 +87,7 @@ updateImports name st = st { psciImportedModuleNames = name : psciImportedModule
87-- |
87-- |
88-- Updates the state to have more loaded files.
88-- Updates the state to have more loaded files.
89--
89--
90−updateModules :: [(Maybe FilePath, P.Module)] -> PSCiState -> PSCiState
90+updateModules :: [(Either P.RebuildPolicy FilePath, P.Module)] -> PSCiState -> PSCiState
91updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
91updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
92
92
93-- |
93-- |
@@ -130,12 +130,12 @@ loadModule filename = either (Left . show) Right . P.runIndentParser filename P.
130-- |
130-- |
131-- Load all modules, including the Prelude
131-- Load all modules, including the Prelude
132--
132--
133−loadAllModules :: [FilePath] -> IO (Either ParseError [(Maybe FilePath, P.Module)])
133+loadAllModules :: [FilePath] -> IO (Either ParseError [(Either P.RebuildPolicy FilePath, P.Module)])
134loadAllModules files = do
134loadAllModules files = do
135 filesAndContent <- forM files $ \filename -> do
135 filesAndContent <- forM files $ \filename -> do
136 content <- U.readFile filename
136 content <- U.readFile filename
137− return (Just filename, content)
137+ return (Right filename, content)
138− return $ P.parseModulesFromFiles $ (Nothing, P.prelude) : filesAndContent
138+ return $ P.parseModulesFromFiles (either (const "") id) $ (Left P.RebuildNever, P.prelude) : filesAndContent
139
139
140
140
141-- |
141-- |
@@ -303,7 +303,7 @@ handleDeclaration :: P.Expr -> PSCI ()
303handleDeclaration value = do
303handleDeclaration value = do
304 st <- PSCI $ lift get
304 st <- PSCI $ lift get
305 let m = createTemporaryModule True st value
305 let m = createTemporaryModule True st value
306− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
306+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
307 case e of
307 case e of
308 Left err -> PSCI $ outputStrLn err
308 Left err -> PSCI $ outputStrLn err
309 Right _ -> do
309 Right _ -> do
@@ -343,7 +343,7 @@ handleImport :: P.ModuleName -> PSCI ()
343handleImport moduleName = do
343handleImport moduleName = do
344 st <- updateImports moduleName <$> PSCI (lift get)
344 st <- updateImports moduleName <$> PSCI (lift get)
345 let m = createTemporaryModuleForImports st
345 let m = createTemporaryModuleForImports st
346− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
346+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
347 case e of
347 case e of
348 Left err -> PSCI $ outputStrLn err
348 Left err -> PSCI $ outputStrLn err
349 Right _ -> do
349 Right _ -> do
@@ -357,7 +357,7 @@ handleTypeOf :: P.Expr -> PSCI ()
357handleTypeOf value = do
357handleTypeOf value = do
358 st <- PSCI $ lift get
358 st <- PSCI $ lift get
359 let m = createTemporaryModule False st value
359 let m = createTemporaryModule False st value
360− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
360+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
361 case e of
361 case e of
362 Left err -> PSCI $ outputStrLn err
362 Left err -> PSCI $ outputStrLn err
363 Right env' ->
363 Right env' ->
@@ -407,7 +407,7 @@ handleKindOf typ = do
407 st <- PSCI $ lift get
407 st <- PSCI $ lift get
408 let m = createTemporaryModuleForKind st typ
408 let m = createTemporaryModuleForKind st typ
409 mName = P.ModuleName [P.ProperName "$PSCI"]
409 mName = P.ModuleName [P.ProperName "$PSCI"]
410− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
410+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
411 case e of
411 case e of
412 Left err -> PSCI $ outputStrLn err
412 Left err -> PSCI $ outputStrLn err
413 Right env' ->
413 Right env' ->
@@ -453,7 +453,7 @@ handleCommand (LoadFile filePath) = do
453 m <- psciIO $ loadModule absPath
453 m <- psciIO $ loadModule absPath
454 case m of
454 case m of
455 Left err -> PSCI $ outputStrLn err
455 Left err -> PSCI $ outputStrLn err
456− Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Just absPath)) mods))
456+ Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Right absPath)) mods))
457 else
457 else
458 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
458 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
459handleCommand Reset = do
459handleCommand Reset = do
purescript.cabal+1−1
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.6.0
2+version: 0.6.0.1
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
src/Language/PureScript.hs+15−5
@@ -15,7 +15,7 @@
15
15
16{-# LANGUAGE DataKinds, QuasiQuotes, TemplateHaskell #-}
16{-# LANGUAGE DataKinds, QuasiQuotes, TemplateHaskell #-}
17
17
18−module Language.PureScript (module P, compile, compile', MonadMake(..), make, prelude) where
18+module Language.PureScript (module P, compile, compile', RebuildPolicy(..), MonadMake(..), make, prelude) where
19
19
20import Language.PureScript.Types as P
20import Language.PureScript.Types as P
21import Language.PureScript.Kinds as P
21import Language.PureScript.Kinds as P
@@ -133,13 +133,22 @@ class MonadMake m where
133 --
133 --
134 progress :: String -> m ()
134 progress :: String -> m ()
135
135
136+-- |
137+-- Determines when to rebuild a module
138+--
139+data RebuildPolicy
140+ -- | Never rebuild this module
141+ = RebuildNever
142+ -- | Always rebuild this module
143+ | RebuildAlways deriving (Show, Eq, Ord)
144+
136-- |
145-- |
137-- Compiles in "make" mode, compiling each module separately to a js files and an externs file
146-- Compiles in "make" mode, compiling each module separately to a js files and an externs file
138--
147--
139-- If timestamps have not changed, the externs file can be used to provide the module's types without
148-- If timestamps have not changed, the externs file can be used to provide the module's types without
140-- having to typecheck the module again.
149-- having to typecheck the module again.
141--
150--
142−make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options Make -> [(Maybe FilePath, Module)] -> [String] -> m Environment
151+make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options Make -> [(Either RebuildPolicy FilePath, Module)] -> [String] -> m Environment
143make outputDir opts ms prefix = do
152make outputDir opts ms prefix = do
144 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
153 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
145
154
@@ -150,14 +159,15 @@ make outputDir opts ms prefix = do
150
159
151 jsFile = outputDir </> filePath </> "index.js"
160 jsFile = outputDir </> filePath </> "index.js"
152 externsFile = outputDir </> filePath </> "externs.purs"
161 externsFile = outputDir </> filePath </> "externs.purs"
153− inputFile = join $ M.lookup moduleName' filePathMap
162+ inputFile = fromMaybe (error "Module has no filename in 'make'") $ M.lookup moduleName' filePathMap
154
163
155 jsTimestamp <- getTimestamp jsFile
164 jsTimestamp <- getTimestamp jsFile
156 externsTimestamp <- getTimestamp externsFile
165 externsTimestamp <- getTimestamp externsFile
157− inputTimestamp <- join <$> traverse getTimestamp inputFile
166+ inputTimestamp <- traverse getTimestamp inputFile
158
167
159 return $ case (inputTimestamp, jsTimestamp, externsTimestamp) of
168 return $ case (inputTimestamp, jsTimestamp, externsTimestamp) of
160− (Just t1, Just t2, Just t3) | t1 < min t2 t3 -> s
169+ (Right (Just t1), Just t2, Just t3) | t1 < min t2 t3 -> s
170+ (Left RebuildNever, Just _, Just _) -> s
161 _ -> S.insert moduleName' s) S.empty sorted
171 _ -> S.insert moduleName' s) S.empty sorted
162
172
163 marked <- rebuildIfNecessary (reverseDependencies graph) toRebuild sorted
173 marked <- rebuildIfNecessary (reverseDependencies graph) toRebuild sorted
src/Language/PureScript/Parser/Declarations.hs+3−3
@@ -235,10 +235,10 @@ parseModule = do
235-- |
235-- |
236-- Parse a collection of modules
236-- Parse a collection of modules
237--
237--
238−parseModulesFromFiles :: [(Maybe FilePath, String)] -> Either P.ParseError [(Maybe FilePath, Module)]
238+parseModulesFromFiles :: (k -> String) -> [(k, String)] -> Either P.ParseError [(k, Module)]
239−parseModulesFromFiles input =
239+parseModulesFromFiles toFilePath input =
240 fmap collect . forM input $ \(filename, content) -> do
240 fmap collect . forM input $ \(filename, content) -> do
241− ms <- runIndentParser (fromMaybe "" filename) parseModules content
241+ ms <- runIndentParser (toFilePath filename) parseModules content
242 return (filename, ms)
242 return (filename, ms)
243 where
243 where
244 collect :: [(k, [v])] -> [(k, v)]
244 collect :: [(k, [v])] -> [(k, v)]
tests/Main.hs+4−4
@@ -30,20 +30,20 @@ import System.Directory (getCurrentDirectory, getTemporaryDirectory, getDirector
30import Text.Parsec (ParseError)
30import Text.Parsec (ParseError)
31import qualified System.IO.UTF8 as U
31import qualified System.IO.UTF8 as U
32
32
33−readInput :: [FilePath] -> IO [(Maybe FilePath, String)]
33+readInput :: [FilePath] -> IO [(FilePath, String)]
34readInput inputFiles = forM inputFiles $ \inputFile -> do
34readInput inputFiles = forM inputFiles $ \inputFile -> do
35 text <- U.readFile inputFile
35 text <- U.readFile inputFile
36− return (Just inputFile, text)
36+ return (inputFile, text)
37
37
38loadPrelude :: Either String (String, String, P.Environment)
38loadPrelude :: Either String (String, String, P.Environment)
39loadPrelude =
39loadPrelude =
40− case P.parseModulesFromFiles [(Nothing, P.prelude)] of
40+ case P.parseModulesFromFiles id [("", P.prelude)] of
41 Left parseError -> Left (show parseError)
41 Left parseError -> Left (show parseError)
42 Right ms -> P.compile (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }) (map snd ms) []
42 Right ms -> P.compile (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }) (map snd ms) []
43
43
44compile :: P.Options P.Compile -> [FilePath] -> IO (Either String (String, String, P.Environment))
44compile :: P.Options P.Compile -> [FilePath] -> IO (Either String (String, String, P.Environment))
45compile opts inputFiles = do
45compile opts inputFiles = do
46− modules <- P.parseModulesFromFiles <$> readInput inputFiles
46+ modules <- P.parseModulesFromFiles id <$> readInput inputFiles
47 case modules of
47 case modules of
48 Left parseError ->
48 Left parseError ->
49 return (Left $ show parseError)
49 return (Left $ show parseError)