Skip to content

Commit a42fb51

Browse files
committed
Faster implementation
1 parent 564527a commit a42fb51

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

src/Stack/Types/Build.hs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -637,28 +637,45 @@ configureOptsNoDir econfig bco deps isLocal package = concat
637637
, ["--ghc-option=-fhide-source-paths" | hideSourcePaths cv]
638638
]
639639
where
640+
-- This function parses the GHC options that are providing in the
641+
-- stack.yaml file. In order to handle RTS arguments correctly, we need
642+
-- to provide the RTS arguments as a single argument.
640643
processGhcOptions :: [Text] -> [String]
641-
processGhcOptions ("+RTS" : xs) =
644+
processGhcOptions args =
642645
let
643-
(rtsArgs, rest) =
644-
takeRtsArgs xs
646+
(preRtsArgs, mid) =
647+
break ("+RTS" ==) args
648+
(rtsArgs, end) =
649+
break ("-RTS" ==) mid
650+
fullRtsArgs =
651+
case rtsArgs of
652+
[] ->
653+
-- This means that we didn't have any RTS args - no
654+
-- `+RTS` - and therefore no need for a `-RTS`.
655+
[]
656+
_ ->
657+
-- In this case, we have some RTS args. `break`
658+
-- puts the `"-RTS"` string in the `snd` list, so
659+
-- we want to append it on the end of `rtsArgs`
660+
-- here.
661+
--
662+
-- We're not checking that `-RTS` is the first
663+
-- element of `end`. This is because the GHC RTS
664+
-- allows you to omit a trailing -RTS if that's the
665+
-- last of the arguments. This permits a GHC
666+
-- options in stack.yaml that matches what you
667+
-- might pass directly to GHC.
668+
[T.unwords $ rtsArgs ++ ["-RTS"]]
669+
-- We drop the first element from `end`, because it is always
670+
-- either `"-RTS"` (and we don't want that as a separate
671+
-- argument) or the list is empty (and `drop _ [] = []`).
672+
postRtsArgs =
673+
drop 1 end
674+
newArgs =
675+
concat [preRtsArgs, fullRtsArgs, postRtsArgs]
645676
in
646-
("--ghc-options=+RTS " ++ rtsArgs) : processGhcOptions rest
647-
processGhcOptions (x : xs) =
648-
[compilerOptionsCabalFlag wc, T.unpack x] ++ processGhcOptions xs
649-
processGhcOptions [] =
650-
[]
651-
takeRtsArgs :: [Text] -> (String, [Text])
652-
takeRtsArgs ("-RTS" : xs) =
653-
("-RTS", xs)
654-
takeRtsArgs (x : xs) =
655-
let
656-
(other, rest) =
657-
takeRtsArgs xs
658-
in
659-
(T.unpack x ++ " " ++ other, rest)
660-
takeRtsArgs [] =
661-
([], [])
677+
concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) newArgs
678+
662679
wc = view (actualCompilerVersionL.to whichCompiler) econfig
663680
cv = view (actualCompilerVersionL.to getGhcVersion) econfig
664681

stack.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ docker:
88
#repo: fpco/alpine-haskell-stack:8.10.4
99
repo: fpco/alpine-haskell-stack@sha256:1024fe4b3b082a8df64d00e8563b3151220ed90af09604a8f7e1d44040500c30
1010

11-
1211
nix:
1312
# --nix on the command-line to enable.
1413
packages:

test/integration/tests/5180-ghc-rts-flags/files/stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ packages:
33
- .
44

55
ghc-options:
6-
"$locals": +RTS -A128M -RTS
6+
"$locals": -j8 +RTS -s -A128M

0 commit comments

Comments
 (0)