Skip to content

feat(Cabal, cabal-install): Display -O and -g as numeric levels instead of booleans - #11937

Open
zlonast wants to merge 4 commits into
haskell:masterfrom
zlonast:zlonast/numeric-render
Open

feat(Cabal, cabal-install): Display -O and -g as numeric levels instead of booleans#11937
zlonast wants to merge 4 commits into
haskell:masterfrom
zlonast:zlonast/numeric-render

Conversation

@zlonast

@zlonast zlonast commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

This PR improves the handling of the debug-info and optimization field to ensure consistency between its configuration and CLI representations.

Changes

  • Config default: Updated the serialization logic to represent the default NoDebugInfo value as 0 instead of False in ~/.config/cabal/config.
  • Internal consistency: Aligned the default DebugInfoLevel between pkgHashDebugInfo and the Parsec instance. This resolves potential inconsistencies when processing manually generated configuration files.
  • Parsing fix: Fixed a bug where boolean flags were not being correctly parsed for the debug-info field. The parser now properly handles both boolean and integer inputs.
    -- TODO: [code cleanup] The following is a hack. The "optimization" and
    -- "debug-info" fields are OptArg, and viewAsFieldDescr fails on that.
    -- Instead of a hand-written parser and printer, we should handle this case
    -- properly in the library.

    -- TODO: The following is a temporary fix. The "optimization"
    -- and "debug-info" fields are OptArg, and viewAsFieldDescr
    -- fails on that. Instead of a hand-written hackaged parser
    -- and printer, we should handle this case properly in the
    -- library.

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • Tests have been added. (Ask for help if you don’t know how to write them! Ask for an exemption if tests are too complex for too little coverage!)

@zlonast
zlonast force-pushed the zlonast/numeric-render branch from f9af0be to 0eeaea7 Compare June 7, 2026 17:57
@zlonast zlonast changed the title Numeric render feat(Cabal, cabal-install): Display -O and -g as numeric levels instead of booleans Jun 9, 2026
@zlonast
zlonast force-pushed the zlonast/numeric-render branch from 0eeaea7 to c08916a Compare June 9, 2026 13:08
@zlonast zlonast added attention: needs-review re: code formatting Automated code formatting with Fourmolu or similar type: refactor labels Jun 9, 2026
@zlonast
zlonast force-pushed the zlonast/numeric-render branch 3 times, most recently from 7b61363 to f7abbb6 Compare June 10, 2026 11:04
@zlonast zlonast linked an issue Jun 10, 2026 that may be closed by this pull request
@Mikolaj

Mikolaj commented Jun 11, 2026

Copy link
Copy Markdown
Member

@ffaf1 notices this seems to change the behaviour of cabal (namely, it's output). If so, a different PR template should be used, which asks for a different set of tasks.

Would it be possible to add a test that prints the -O and -g things? Preferably in an early commit, so that it illustrates the modification, showing how it requires a change in the test result.

@zlonast zlonast added the re: config-file Concerning the cabal configuration file and the `--config-file` option label Jun 19, 2026
@zlonast
zlonast force-pushed the zlonast/numeric-render branch 3 times, most recently from 011259e to 5d8b49f Compare June 19, 2026 19:57
@zlonast
zlonast force-pushed the zlonast/numeric-render branch 3 times, most recently from 83a898c to 14c4a11 Compare June 29, 2026 12:09
@Bodigrim

Copy link
Copy Markdown
Collaborator

It seems it needs a rebase now.

@zlonast
zlonast force-pushed the zlonast/numeric-render branch from 14c4a11 to 7552c00 Compare July 12, 2026 10:32
@zlonast

zlonast commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

@Bodigrim yes, I updated it

@Mikolaj add test for prints the -O and -g things

@Mikolaj Mikolaj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't pretend to have read the whole newest diff, but it seems solid overall. Thank you.

Comment thread changelog.d/11937.md

The rendering of certain boolean‑like flags has been changed to use numeric levels:
- For the `-O` (optimisation) flag, `True` or an unspecified value now renders as `1`, while `False` renders as `0`.
- For the `-g` (debug info) flag, `True` or an unspecified value now renders `2`, while `False` renders as `0`.

@philderbeast philderbeast Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this branch (and not on the master branch), there seems to be two conflicting -g options:

$ cabal run cabal-install:exe:cabal -- build --help
...
Usage: cabal build [TARGETS] [FLAGS]
...
Flags for build:
...
 -g, --ghc                      compile with GHC
...
 -g n or -gn, --enable-debug-info=n
                                Emit debug info (n is 0--3, default is 0)
...

Is -g treated differently than -g n or -gn?

@philderbeast philderbeast Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the -g option is re-associated with debug info then this pull request fixes #2056.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simply redefine the flag, and few people will notice, since it doesn't appear in libraries or executables.

Those who do notice will now use the full flag. As I understand it, these are the people who manually enter flags in the console.

Currently, this is mostly LLM, which makes this change even more valuable for them.

Comment thread Cabal/src/Distribution/Types/DebugInfoLevel.hs Outdated
Comment thread cabal-install/src/Distribution/Client/ProjectPlanning.hs Outdated
@zlonast zlonast linked an issue Jul 28, 2026 that may be closed by this pull request
@zlonast
zlonast force-pushed the zlonast/numeric-render branch from 7552c00 to 538ea9e Compare July 28, 2026 13:44
@zlonast zlonast linked an issue Jul 28, 2026 that may be closed by this pull request
@zlonast
zlonast force-pushed the zlonast/numeric-render branch from 538ea9e to 9ac9012 Compare July 28, 2026 14:22
Comment thread changelog.d/11937.md

The rendering of certain boolean‑like flags has been changed to use numeric levels:
- For the `-O` (optimisation) flag, `True` or an unspecified value now renders as `1`, while `False` renders as `0`.
- For the `-g` (debug info) flag, `True` or an unspecified value now renders `2`, while `False` renders as `0`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please mention that the short -g flag was previously associated with --ghc?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the changelog

@zlonast
zlonast force-pushed the zlonast/numeric-render branch from 9ac9012 to e1f64e1 Compare July 28, 2026 14:53
@zlonast
zlonast force-pushed the zlonast/numeric-render branch from e1f64e1 to faa6838 Compare July 28, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attention: needs-review re: code formatting Automated code formatting with Fourmolu or similar re: config-file Concerning the cabal configuration file and the `--config-file` option type: refactor

Projects

None yet

4 participants