Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the `-O99` flag do?

Tags:

haskell

ghc

The title is a slight joke.

I just discovered today that ghc accepts any optimization level without complaining. I know that -O2 is supposed to be the maximum optimization level, and that there is a proposed -O3 here, but I was just curious what happens when you mistakenly specify an even higher optimization level. Does ghc default to -O2 or does it not optimize at all?

like image 281
Gabriella Gonzalez Avatar asked Feb 17 '26 02:02

Gabriella Gonzalez


1 Answers

It looks like it is clamped to be between 0 and 2 in compiler/main/DynFlags.hs:

updOptLevel :: Int -> DynFlags -> DynFlags
-- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
updOptLevel n dfs
  = dfs2{ optLevel = final_n }
  where
   final_n = max 0 (min 2 n)    -- Clamp to 0 <= n <= 2
   ...
like image 78
ScootyPuff Avatar answered Feb 19 '26 12:02

ScootyPuff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!