Skip to content

Confusing -O1 in build profile #6221

Open

Description

@sjakobi
$ cabal build
Resolving dependencies...
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
 - bsb-http-chunked-0.0.0.4 (lib) (first run)

What does the -O1 in the Build profile: line mean? The ghc-options for my library component include -O2, and the verbose log shows that ghc is invoked with -O2 too.

Activity

  1. 23Skidoo commented on Sep 1, 2019

    @23Skidoo
    Member

    It means that the local packages in the project are configured with -O1. However, as you correctly notice, this can be overridden on per-component basis in ghc-options.

  2. sjakobi commented on Sep 1, 2019

    @sjakobi
    MemberAuthor

    Ah, thanks! In my case there weren't any other local packages that could be configured with -O1.

    I first noticed it while benchmarking where it caused me much doubt about the validity of the numbers I was seeing.

    What's the motivation for outputting this default(?) setting, especially when it doesn't apply / is overridden?

  3. phadej commented on Sep 1, 2019

    @phadej
    Collaborator
  4. sjakobi commented on Sep 1, 2019

    @sjakobi
    MemberAuthor

    The motivation is that we consider ghc-options: -O2 (any -O flag) to be at the very least questionable practice.

    Interesting! Was there some kind of discussion that I could read?

    Configuring the optimization level like this seems useful. Reporting -O1, when the actual optimization level applied is different, still seems confusing to me. Maybe cabal should also report the overrides then…

  5. jberryman commented on Jan 22, 2020

    @jberryman

    I guess I'm not following the back and forth here.

    It means that the local packages in the project are configured with -O1.

    I have a project where I have a cabal.project.local that looks like:

    package our-project
      optimization: 0
      documentation: false
    

    and a .cabal file like:

    name:                our-project
    library
       ...
    executable our-project
      ...
    
    • When I do a new-build I see Build profile: -w ghc-8.6.5 -O1
    • If I move optimization: 0 to the top-level I see ``Build profile: -w ghc-8.6.5 -O0`
    • In both cases it looks like the library and executable in my project are built without optimizations (as intended)

    So I'm not sure what "Build profile" is supposed to mean, and not sure if what it's reporting is correct, and not sure if I'm using my cabal.project.local file correctly

    Related to #5353

  6. phadej commented on Jan 22, 2020

    @phadej
    Collaborator
  7. tomjaguarpaw commented on Sep 26, 2021

    @tomjaguarpaw
    Member

    What does the -O1 in the Build profile: line mean? The ghc-options for my library component include -O2, and the verbose log shows that ghc is invoked with -O2 too.

    FYI I have also just experienced puzzlement at this.

  8. fgaz commented on Sep 26, 2021

    @fgaz
    Member

    I think it's the "global" optimization level, ie. the top-level optimization: in cabal.project.

  9. jneira commented on Sep 26, 2021

    @jneira
    Member

    and what about include that useful info in the message, something like Top level build profile...

  10. fgaz commented on Sep 26, 2021

    @fgaz
    Member

    @sjakobi @jberryman @tomjaguarpaw is @jneira's proposal enough to clarify the meaning of that message? If not, any suggestions?

  11. tomjaguarpaw commented on Sep 26, 2021

    @tomjaguarpaw
    Member

    Well, it would certainly be better (and give something more substantial to Duck Duck Go for when confused).

  12. sjakobi commented on Sep 27, 2021

    @sjakobi
    MemberAuthor

    is @jneira's proposal enough to clarify the meaning of that message? If not, any suggestions?

    I don't have a better proposal. However I just noticed that the term "build profile" doesn't appear to be documented. My suggestion would be to fix that, or alternatively to use a different term if that one is better established and documented.

  13. 15 remaining items

  14. mouse07410 commented on Sep 5, 2022

    @mouse07410
    Collaborator

    Cabal-3.8.1.0.

    Could you explain why Cabal reports -O1 even when ~/.cabal/config has ghc-options: -O2 and optimization: 2? Nothing in the local project settings explicitly configures optimization level, leaving it to the global default.

    Leaving alone whether -O2 is (or is not) a good idea.

    P.S. Thankfully, Cabal reports the GHC version correctly.

  15. fgaz commented on Sep 6, 2022

    @fgaz
    Member

    @mouse07410 what optimization level do you actually get when building the project? Is the message incorrect or is optimization from ~/.cabal/config not picked up at all? If it's the latter, could you open a new ticket about that?

  16. mouse07410 commented on Sep 6, 2022

    @mouse07410
    Collaborator

    @fgaz hard to say, because Cabal logging does not work either (see #8456). ;-)

    But, based on the captured console output, -O2 does get passed to the GHC invocation. Presumably, from ghc-options: -O2, rather than from optimization: 2...?

    It is unclear from the docs, whether I need just one of these (and if so - which one), or both: optimization: 2 and ghc-options: -O2. And it's unclear even if optimization: 2 is valid - but Cabal-3.8.1.0 did not complain about this value, so it must be acceptable...?

  17. ulysses4ever commented on Sep 8, 2022

    @ulysses4ever
    Collaborator

    @mouse07410 did you read the doc? It suggests that optimization is meant to be more abstract setting. E.g. it can apply to (imaginary) Haskell compilers other than GHC, as well as, to GCC.
    https://cabal.readthedocs.io/en/3.8/cabal-project.html#cfg-field-optimization

  18. mouse07410 commented on Sep 8, 2022

    @mouse07410
    Collaborator

    The doc says that it "builds with optimization" and passes -O2 to the C compiler.

    Did it mean that GHC will also use -O2, or do I need to utilize ghc-options: -O2 in addition?

    P.S. Docs IMHO do lack in the areas of clarity and comprehensiveness.

  19. ulysses4ever commented on Sep 8, 2022

    @ulysses4ever
    Collaborator

    @mouse07410 you don't need ghc-options if you use optimization. For the docs: fully agree, and a contribution improving thereof would be very welcome!

  20. ulysses4ever commented on Sep 8, 2022

    @ulysses4ever
    Collaborator

    That is not to say that the Build profile business is good — it is not. My guess would be that it prints the message before it reads the config (where you have optimization: 2). Arguably, this could be a separate ticket, because it most certainly will require something more clever than simply changing the (still very confusing!) message.

  21. mouse07410 commented on Sep 9, 2022

    @mouse07410
    Collaborator

    My guess would be that it prints the message before it reads the config (where you have optimization: 2). . . it most certainly will require something more clever than simply changing the (still very confusing!) message

    Admitting my lack of expertise here - why should it be any more complicated than printing the message after reading the config (when Cabal learns what GHC compiler is requested, and what options to pass to it)...?

  22. ulysses4ever commented on Sep 9, 2022

    @ulysses4ever
    Collaborator

    @mouse07410 Very simply, because finding and changing a string is easier than moving the string, if you don’t know where to move exactly. Cabal’s code base is significant (after tests) it’s ~500 .hs files with ~100K SLOC (w/o spaces or comments).

    And that’s assuming that my guess is right, which it may not be.

  23. added
    re: user experience
    on Nov 21, 2022
  24. added a commit that references this issue on Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions