Opened 7 years ago

Last modified 3 months ago

#4243 new task

Make a proper options parser for the RTS

Reported by: igloo Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 6.13
Keywords: Cc:…, simonmar, osa1
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking: #7535
Related Tickets: #9839 #13308 Differential Rev(s):
Wiki Page:


The RTS options parsing is getting increasingly crufty, and the new rtsOptsEnabled options have made it even worse. We should really have a proper options parser.

Change History (24)

comment:1 Changed 7 years ago by simonmar


comment:2 Changed 7 years ago by igloo

It should also be possible to link against the RTS in such a way that it won't try to parse the RTS arguments at all, e.g. so +RTS would be passed to the program as an argument (as opposed to the RTS failing, as it currently does when given that argument if linked with -no-rtsopts).

comment:3 Changed 7 years ago by igloo

See also #3910.

comment:4 Changed 6 years ago by igloo



comment:5 Changed 5 years ago by igloo

difficulty: Unknown

comment:6 Changed 4 years ago by liyang

Cc:… added

comment:7 Changed 3 years ago by thoughtpolice


Bumping priority down (these tickets haven't been closely followed or fixed in 7.4), and moving out to 7.10 and out of 7.8.3.

comment:8 Changed 3 years ago by thoughtpolice

Priority: highnormal

Actually dropping priority. :)

comment:9 Changed 2 years ago by thomie

Cc: simonmar added

comment:10 Changed 2 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:11 Changed 2 years ago by carlostome

Maybe we should change rts/RtsFlags.c to make use of <getopt.h> because now the option parser is a bit scaring. I think I can do it myself. Any suggestions?

comment:12 Changed 2 years ago by thomie

Make sure that whatever you do also works, and behaves the same, on Windows, Mac, Solaris, FreeBSD. At least in theory. Is getopt.h posix only, or is avaible the way ghc is built on Windows (I don't know). would also need updating?

I noticed Python keeps their own copy of getopt, would that be an option?


"Move our own getopt() implementation to _PyOS_GetOpt(), and use it regardless of whether the system getopt() does what we want. This avoids the hassle with prototypes and externs, and the check to see if the system getopt() does what we want."

comment:13 Changed 2 years ago by thomie

Blocking: 7535 added

comment:14 Changed 2 years ago by carlostome

Owner: set to carlostome

comment:15 Changed 23 months ago by osa1

Cc: osa1 added

What keeps us from implementing RTS arg parser in Haskell?

comment:16 Changed 21 months ago by carlostome

Owner: carlostome deleted

comment:17 Changed 21 months ago by bgamari

osa1, I think for the sake of simplicity it would be best to avoid going down that road. The RTS really just needs to work, even if Haskell-land is broken (e.g. as is often the case when debugging RTS bugs or bringing up new platforms).

comment:18 Changed 21 months ago by thoughtpolice


Milestone renamed

comment:19 Changed 19 months ago by Ben Gamari <ben@…>

In 69822f0c/ghc:

RtsFlags: Refactor some of the deeper switches

This was previously nearly impossible to read; now it's merely

Ideally we would do a more thorough refactoring of the RTS command line
parser (#4243) but this is more effort than I have time for at the

Test Plan: Try using affected RTS flags

Reviewers: simonmar, austin

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #4243

comment:20 Changed 17 months ago by dobenour

Would it be okay to use re2c to generate the RTS options parser? I have a patch that provides a proper options parser using it.

Existing libraries like getopt did not seem suitable, due to the non-standard format of the RTS flags.

comment:21 Changed 17 months ago by simonmar

I'd prefer not to add a dependency on an external tool if possible.

comment:22 Changed 16 months ago by thomie

Milestone: 8.0.1

comment:23 Changed 3 months ago by AndreasK

There seem to be differences for parsing between Windows and Linux #13287 (Treatment of --)

Last edited 3 months ago by AndreasK (previous) (diff)

comment:24 Changed 3 months ago by AndreasK

When parsing arguments to flags ghc treats leading whitespace different depending on the flag.

ghc +RTS '-N 2' -s -RTS --version Here '-N 2' is parsed as -N2 ghc +RTS '-s file' -RTS --version Here '-N 2' is parsed as '\ file', a filename starting with a space.

If this rework ever happens leading spaces in arguments should either be uniformly ignored or treated as errors.

Note: See TracTickets for help on using tickets.