[GHC] #15732: getArgsWithResponseFiles does not filter out RTS options

GHC ghc-devs at haskell.org
Tue Oct 9 19:40:47 UTC 2018


#15732: getArgsWithResponseFiles does not filter out RTS options
-------------------------------------+-------------------------------------
        Reporter:  ckoparkar         |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.8.1
       Component:  libraries/base    |              Version:  8.6.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #13896            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by ckoparkar:

Old description:

> 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).
> 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:
>
> {{{#!sh
> $ 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. Currently, {{{getArgs}}} relies on the
> [http://git.haskell.org/ghc.git/blob/HEAD:/rts/RtsFlags.c#l661 runtime
> system] for filtering out appropriate things.

New description:

 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).
 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:

 {{{#!sh
 $ 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
 [http://git.haskell.org/ghc.git/blob/HEAD:/rts/RtsFlags.c#l661 runtime
 system] for this.

--

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15732#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list