Skip to content

Commit 0740444

Browse files
authored
Merge pull request #4273 from commercialhaskell/reduce-template-haskell
Avoid unnecessary recompilations
2 parents 7744739 + 241aa55 commit 0740444

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+798
-408
lines changed

package.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ dependencies:
9393
- project-template
9494
- regex-applicative-text
9595
- resourcet
96-
- retry
96+
- retry >= 0.7
9797
- rio
9898
- semigroups
9999
- split
@@ -231,6 +231,7 @@ library:
231231
- Stack.Sig.Sign
232232
- Stack.Snapshot
233233
- Stack.Solver
234+
- Stack.StoreTH
234235
- Stack.Types.Build
235236
- Stack.Types.BuildPlan
236237
- Stack.Types.CompilerBuild
@@ -258,6 +259,7 @@ library:
258259
- Stack.Upgrade
259260
- Stack.Upload
260261
- Text.PrettyPrint.Leijen.Extended
262+
- System.Permissions
261263
- System.Process.PagerEditor
262264
- System.Terminal
263265
when:

src/Data/Attoparsec/Interpreter.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE CPP #-}
43
{- | This module implements parsing of additional arguments embedded in a
54
comment when stack is invoked as a script interpreter
65
@@ -62,7 +61,6 @@ import Conduit
6261
import Data.Conduit.Attoparsec
6362
import Data.List (intercalate)
6463
import Data.Text (pack)
65-
import Stack.Constants
6664
import Stack.Prelude
6765
import System.FilePath (takeExtension)
6866
import System.IO (stderr, hPutStrLn)
@@ -146,11 +144,7 @@ getInterpreterArgs file = do
146144

147145
decodeError e =
148146
case e of
149-
#if MIN_VERSION_conduit_extra(1,2,0)
150147
ParseError ctxs _ (Position line col _) ->
151-
#else
152-
ParseError ctxs _ (Position line col) ->
153-
#endif
154148
if null ctxs
155149
then "Parse error"
156150
else ("Expecting " ++ intercalate " or " ctxs)

src/Network/HTTP/Download/Verified.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE DeriveDataTypeable #-}
43
{-# LANGUAGE MultiParamTypeClasses #-}
54
{-# LANGUAGE OverloadedStrings #-}
@@ -192,11 +191,7 @@ hashChecksToZipSink req = traverse_ (ZipSink . sinkCheckHash req)
192191
-- 'Control.Retry.recovering' customized for HTTP failures
193192
recoveringHttp :: forall env a. HasRunner env => RetryPolicy -> RIO env a -> RIO env a
194193
recoveringHttp retryPolicy =
195-
#if MIN_VERSION_retry(0,7,0)
196194
helper $ \run -> recovering retryPolicy (handlers run) . const
197-
#else
198-
helper $ \run -> recovering retryPolicy (handlers run)
199-
#endif
200195
where
201196
helper :: (UnliftIO (RIO env) -> IO a -> IO a) -> RIO env a -> RIO env a
202197
helper wrapper action = withUnliftIO $ \run -> wrapper run (unliftIO run action)

src/Stack/Build.hs

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE ConstraintKinds #-}
43
{-# LANGUAGE DeriveDataTypeable #-}
54
{-# LANGUAGE FlexibleContexts #-}
@@ -46,16 +45,9 @@ import Stack.Types.Config
4645
import Stack.Types.NamedComponent
4746
import Stack.Types.Package
4847

49-
import Stack.Types.Compiler (compilerVersionText
50-
#ifdef WINDOWS
51-
,getGhcVersion
52-
#endif
53-
)
48+
import Stack.Types.Compiler (compilerVersionText, getGhcVersion)
5449
import System.FileLock (FileLock, unlockFile)
55-
56-
#ifdef WINDOWS
57-
import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP)
58-
#endif
50+
import System.Terminal (fixCodePage)
5951

6052
-- | Build.
6153
--
@@ -67,7 +59,10 @@ build :: HasEnvConfig env
6759
-> Maybe FileLock
6860
-> BuildOptsCLI
6961
-> RIO env ()
70-
build msetLocalFiles mbuildLk boptsCli = fixCodePage $ do
62+
build msetLocalFiles mbuildLk boptsCli = do
63+
mcp <- view $ configL.to configModifyCodePage
64+
ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion
65+
fixCodePage mcp ghcVersion $ do
7166
bopts <- view buildOptsL
7267
let profiling = boptsLibProfile bopts || boptsExeProfile bopts
7368
let symbols = not (boptsLibStrip bopts || boptsExeStrip bopts)
@@ -282,53 +277,6 @@ loadPackage loc flags ghcOptions = do
282277
}
283278
resolvePackage pkgConfig <$> loadCabalFileImmutable loc
284279

285-
-- | Set the code page for this process as necessary. Only applies to Windows.
286-
-- See: https://github.com/commercialhaskell/stack/issues/738
287-
fixCodePage :: HasEnvConfig env => RIO env a -> RIO env a
288-
#ifdef WINDOWS
289-
fixCodePage inner = do
290-
mcp <- view $ configL.to configModifyCodePage
291-
ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion
292-
if mcp && ghcVersion < mkVersion [7, 10, 3]
293-
then fixCodePage'
294-
-- GHC >=7.10.3 doesn't need this code page hack.
295-
else inner
296-
where
297-
fixCodePage' = do
298-
origCPI <- liftIO getConsoleCP
299-
origCPO <- liftIO getConsoleOutputCP
300-
301-
let setInput = origCPI /= expected
302-
setOutput = origCPO /= expected
303-
fixInput
304-
| setInput = bracket_
305-
(liftIO $ do
306-
setConsoleCP expected)
307-
(liftIO $ setConsoleCP origCPI)
308-
| otherwise = id
309-
fixOutput
310-
| setOutput = bracket_
311-
(liftIO $ do
312-
setConsoleOutputCP expected)
313-
(liftIO $ setConsoleOutputCP origCPO)
314-
| otherwise = id
315-
316-
case (setInput, setOutput) of
317-
(False, False) -> return ()
318-
(True, True) -> warn ""
319-
(True, False) -> warn " input"
320-
(False, True) -> warn " output"
321-
322-
fixInput $ fixOutput inner
323-
expected = 65001 -- UTF-8
324-
warn typ = logInfo $
325-
"Setting" <>
326-
typ <>
327-
" codepage to UTF-8 (65001) to ensure correct output from GHC"
328-
#else
329-
fixCodePage = id
330-
#endif
331-
332280
-- | Query information about the build and print the result to stdout in YAML format.
333281
queryBuildInfo :: HasEnvConfig env
334282
=> [Text] -- ^ selectors

src/Stack/Build/Cache.hs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE NoImplicitPrelude #-}
3-
{-# LANGUAGE DeriveGeneric #-}
42
{-# LANGUAGE MultiParamTypeClasses #-}
5-
{-# LANGUAGE TemplateHaskell #-}
6-
{-# LANGUAGE TupleSections #-}
73
{-# LANGUAGE ConstraintKinds #-}
84
{-# LANGUAGE OverloadedStrings #-}
95
{-# LANGUAGE DataKinds #-}
@@ -39,30 +35,28 @@ import qualified Data.ByteArray as Mem (convert)
3935
import qualified Data.ByteString.Base64.URL as B64URL
4036
import qualified Data.ByteString as B
4137
import qualified Data.ByteString.Char8 as S8
42-
#ifdef mingw32_HOST_OS
4338
import Data.Char (ord)
44-
#endif
4539
import qualified Data.Map as M
4640
import qualified Data.Set as Set
4741
import qualified Data.Store as Store
48-
import Data.Store.VersionTagged
4942
import qualified Data.Text as T
5043
import Path
5144
import Path.IO
45+
import Stack.Constants
5246
import Stack.Constants.Config
47+
import Stack.StoreTH
5348
import Stack.Types.Build
5449
import Stack.Types.Compiler
5550
import Stack.Types.Config
5651
import Stack.Types.GhcPkgId
5752
import Stack.Types.NamedComponent
58-
import Stack.Types.Package
5953
import qualified System.FilePath as FP
6054

6155
-- | Directory containing files to mark an executable as installed
6256
exeInstalledDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m)
6357
=> InstallLocation -> m (Path Abs Dir)
64-
exeInstalledDir Snap = (</> $(mkRelDir "installed-packages")) `liftM` installationRootDeps
65-
exeInstalledDir Local = (</> $(mkRelDir "installed-packages")) `liftM` installationRootLocal
58+
exeInstalledDir Snap = (</> relDirInstalledPackages) `liftM` installationRootDeps
59+
exeInstalledDir Local = (</> relDirInstalledPackages) `liftM` installationRootLocal
6660

6761
-- | Get all of the installed executables
6862
getInstalledExes :: (MonadReader env m, HasEnvConfig env, MonadIO m, MonadThrow m)
@@ -126,17 +120,17 @@ tryGetBuildCache :: HasEnvConfig env
126120
=> Path Abs Dir
127121
-> NamedComponent
128122
-> RIO env (Maybe (Map FilePath FileCacheInfo))
129-
tryGetBuildCache dir component = liftM (fmap buildCacheTimes) . $(versionedDecodeFile buildCacheVC) =<< buildCacheFile dir component
123+
tryGetBuildCache dir component = liftM (fmap buildCacheTimes) . decodeBuildCache =<< buildCacheFile dir component
130124

131125
-- | Try to read the dirtiness cache for the given package directory.
132126
tryGetConfigCache :: HasEnvConfig env
133127
=> Path Abs Dir -> RIO env (Maybe ConfigCache)
134-
tryGetConfigCache dir = $(versionedDecodeFile configCacheVC) =<< configCacheFile dir
128+
tryGetConfigCache dir = decodeConfigCache =<< configCacheFile dir
135129

136130
-- | Try to read the mod time of the cabal file from the last build
137131
tryGetCabalMod :: HasEnvConfig env
138132
=> Path Abs Dir -> RIO env (Maybe ModTime)
139-
tryGetCabalMod dir = $(versionedDecodeFile modTimeVC) =<< configCabalMod dir
133+
tryGetCabalMod dir = decodeModTime =<< configCabalMod dir
140134

141135
-- | Write the dirtiness cache for this package's files.
142136
writeBuildCache :: HasEnvConfig env
@@ -145,7 +139,7 @@ writeBuildCache :: HasEnvConfig env
145139
-> Map FilePath FileCacheInfo -> RIO env ()
146140
writeBuildCache dir component times = do
147141
fp <- buildCacheFile dir component
148-
$(versionedEncodeFile buildCacheVC) fp BuildCache
142+
encodeBuildCache fp BuildCache
149143
{ buildCacheTimes = times
150144
}
151145

@@ -156,7 +150,7 @@ writeConfigCache :: HasEnvConfig env
156150
-> RIO env ()
157151
writeConfigCache dir x = do
158152
fp <- configCacheFile dir
159-
$(versionedEncodeFile configCacheVC) fp x
153+
encodeConfigCache fp x
160154

161155
-- | See 'tryGetCabalMod'
162156
writeCabalMod :: HasEnvConfig env
@@ -165,7 +159,7 @@ writeCabalMod :: HasEnvConfig env
165159
-> RIO env ()
166160
writeCabalMod dir x = do
167161
fp <- configCabalMod dir
168-
$(versionedEncodeFile modTimeVC) fp x
162+
encodeModTime fp x
169163

170164
-- | Delete the caches for the project.
171165
deleteCaches :: (MonadIO m, MonadReader env m, HasEnvConfig env, MonadThrow m)
@@ -195,7 +189,7 @@ tryGetFlagCache :: HasEnvConfig env
195189
-> RIO env (Maybe ConfigCache)
196190
tryGetFlagCache gid = do
197191
fp <- flagCacheFile gid
198-
$(versionedDecodeFile configCacheVC) fp
192+
decodeConfigCache fp
199193

200194
writeFlagCache :: HasEnvConfig env
201195
=> Installed
@@ -204,23 +198,23 @@ writeFlagCache :: HasEnvConfig env
204198
writeFlagCache gid cache = do
205199
file <- flagCacheFile gid
206200
ensureDir (parent file)
207-
$(versionedEncodeFile configCacheVC) file cache
201+
encodeConfigCache file cache
208202

209203
-- | Mark a test suite as having succeeded
210204
setTestSuccess :: HasEnvConfig env
211205
=> Path Abs Dir
212206
-> RIO env ()
213207
setTestSuccess dir = do
214208
fp <- testSuccessFile dir
215-
$(versionedEncodeFile testSuccessVC) fp True
209+
encodeTestSuccess fp True
216210

217211
-- | Mark a test suite as not having succeeded
218212
unsetTestSuccess :: HasEnvConfig env
219213
=> Path Abs Dir
220214
-> RIO env ()
221215
unsetTestSuccess dir = do
222216
fp <- testSuccessFile dir
223-
$(versionedEncodeFile testSuccessVC) fp False
217+
encodeTestSuccess fp False
224218

225219
-- | Check if the test suite already passed
226220
checkTestSuccess :: HasEnvConfig env
@@ -229,7 +223,7 @@ checkTestSuccess :: HasEnvConfig env
229223
checkTestSuccess dir =
230224
liftM
231225
(fromMaybe False)
232-
($(versionedDecodeFile testSuccessVC) =<< testSuccessFile dir)
226+
(decodeTestSuccess =<< testSuccessFile dir)
233227

234228
--------------------------------------
235229
-- Precompiled Cache
@@ -268,7 +262,7 @@ precompiledCacheFile loc copts installedPackageIDs = do
268262
platformRelDir <- platformGhcRelDir
269263
let precompiledDir =
270264
view stackRootL ec
271-
</> $(mkRelDir "precompiled")
265+
</> relDirPrecompiled
272266
</> platformRelDir
273267
</> compiler
274268
</> cabal
@@ -317,7 +311,7 @@ writePrecompiledCache baseConfigOpts loc copts depIDs mghcPkgId sublibs exes = d
317311
name <- parseRelFile $ T.unpack exe
318312
relPath <- stackRootRelative $ bcoSnapInstallRoot baseConfigOpts </> bindirSuffix </> name
319313
return $ toFilePath relPath
320-
$(versionedEncodeFile precompiledCacheVC) file PrecompiledCache
314+
encodePrecompiledCache file PrecompiledCache
321315
{ pcLibrary = mlibpath
322316
, pcSubLibs = sublibpaths
323317
, pcExes = exes'
@@ -337,7 +331,7 @@ readPrecompiledCache :: forall env. HasEnvConfig env
337331
-> RIO env (Maybe PrecompiledCache)
338332
readPrecompiledCache loc copts depIDs = do
339333
file <- precompiledCacheFile loc copts depIDs
340-
mcache <- $(versionedDecodeFile precompiledCacheVC) file
334+
mcache <- decodePrecompiledCache file
341335
maybe (pure Nothing) (fmap Just . mkAbs) mcache
342336
where
343337
-- Since commit ed9ccc08f327bad68dd2d09a1851ce0d055c0422,
@@ -358,8 +352,9 @@ readPrecompiledCache loc copts depIDs = do
358352

359353
-- | Check if a filesystem path is too long.
360354
pathTooLong :: FilePath -> Bool
361-
#ifdef mingw32_HOST_OS
362-
pathTooLong path = utf16StringLength path >= win32MaxPath
355+
pathTooLong
356+
| osIsWindows = \path -> utf16StringLength path >= win32MaxPath
357+
| otherwise = const False
363358
where
364359
win32MaxPath = 260
365360
-- Calculate the length of a string in 16-bit units
@@ -369,6 +364,3 @@ pathTooLong path = utf16StringLength path >= win32MaxPath
369364
where
370365
utf16CharLength c | ord c < 0x10000 = 1
371366
| otherwise = 2
372-
#else
373-
pathTooLong _ = False
374-
#endif

0 commit comments

Comments
 (0)