Skip to content

getArgsWithResponseFiles does not filter out RTS options

I discovered this while working on a fix for #15072.

GHC.ResponseFile.getArgsWithResponseFiles is a recent addition to base-4.12. The idea was to have a function which could read command-line arguments supplied via response files, but otherwise would behave exactly like System.Environment.getArgs (see #13896 (closed)). However, these functions return different results when RTS options are supplied.

  1. getArgs does not include RTS options in the list it returns.
  2. getArgsWithResponseFiles includes them.

It's trivial to reproduce this. Consider these files:

-- Bug1.hs
module Main where

import System.Environment ( getArgs )

main :: IO ()
main = do
  args <- getArgs
  putStrLn $ "Args: " ++ show args

and

-- Bug2.hs
module Main where

import GHC.ResponseFile ( getArgsWithResponseFiles )

main :: IO ()
main = do
  args <- getArgsWithResponseFiles
  putStrLn $ "ArgsResp: " ++ show args

And run them with:

$ ghc-8.6.1 -rtsopts Bug1.hs && ghc-8.6.1 -rtsopts Bug2.hs

$ ./Bug1 1 +RTS -H32m -RTS 10 20
Args: ["1","10","20"]

-- 'opts_file' contains the same arguments passed to Bug1, and we 
-- use a '@' to pass it as a response file


$ ./Bug2 @opts_file
ArgsResp: ["1","+RTS","-H32m","-RTS","10","20"]

We should fix getArgsWithResponseFiles to properly handle +RTS ... -RTS and --RTS flags. getArgs relies on the runtime system for this.

Edited by Chaitanya Koparkar
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information